Skip to content

Commit

Permalink
[skp]opt: rootExecCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevtinge committed Dec 17, 2024
1 parent 9555dd2 commit f6363a5
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import static com.sevtinge.hyperceiler.utils.Helpers.getPackageVersionCode;
import static com.sevtinge.hyperceiler.utils.Helpers.getPackageVersionName;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.rootExecCmd;

import android.content.Context;

Expand Down Expand Up @@ -240,7 +240,7 @@ public static void deleteAllCache(Context context) {
executor.submit(() -> {
for (String folderName : folderNames) {
String folderPath = "/data/data/" + folderName + MMKV_PATH;
safeExecCommandWithRoot("rm -rf " + folderPath);
rootExecCmd("rm -rf " + folderPath);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object NewFlashLight : TileUtils() {
if (lastFlash != -1) lastFlash = -1
isHook = isFlashLightEnabled(mContext)
if (isHook) {
if (ShellUtils.safeExecCommandWithRoot("settings get system flash_light_brightness") == "null") ShellUtils.safeExecCommandWithRoot("settings put system flash_light_brightness 0")
if (ShellUtils.rootExecCmd("settings get system flash_light_brightness") == "null") ShellUtils.rootExecCmd("settings put system flash_light_brightness 0")
val b = getFlashBrightness(mContext)
if (b != null) {
val mObject = restore(b)
Expand Down Expand Up @@ -371,14 +371,14 @@ object NewFlashLight : TileUtils() {
private fun setPermission(paths: String) {
try {
val checkCommand = "test -e $paths && echo exists || echo not_found"
val result = ShellUtils.safeExecCommandWithRoot(checkCommand)
val result = ShellUtils.rootExecCmd(checkCommand)
if (result.contains("not_found")) {
logE(TAG, lpparam.packageName, "SetPermission: Path $paths does not exist")
return
}

val chmodCommand = "chmod 777 $paths"
val chmodResult = ShellUtils.safeExecCommandWithRoot(chmodCommand)
val chmodResult = ShellUtils.rootExecCmd(chmodCommand)

if (chmodResult.isEmpty()) {
logI(TAG, lpparam.packageName, "SetPermission: Successfully set permissions for $paths")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter;

import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.rootExecCmd;

import android.content.ComponentName;
import android.content.Context;
Expand Down Expand Up @@ -65,16 +65,16 @@ public int customRes() {

@Override
public void tileCheck(MethodHookParam param, String tileName) {
param.setResult(!Objects.equals(safeExecCommandWithRoot("ls /dev/snd/pcm*"), ""));
param.setResult(!Objects.equals(rootExecCmd("ls /dev/snd/pcm*"), ""));
}

@Override
public void tileClick(MethodHookParam param, String tileName) {
if (isInSnowLeopardMode) {
safeExecCommandWithRoot("kill $(pidof android.hardware.audio.service_64) && chmod 660 /dev/snd/pcm*");
rootExecCmd("kill $(pidof android.hardware.audio.service_64) && chmod 660 /dev/snd/pcm*");
isInSnowLeopardMode = false;
} else {
safeExecCommandWithRoot("kill $(pidof android.hardware.audio.service_64) && chmod 000 /dev/snd/pcm*");
rootExecCmd("kill $(pidof android.hardware.audio.service_64) && chmod 000 /dev/snd/pcm*");
isInSnowLeopardMode = true;
}
XposedHelpers.callMethod(param.thisObject, "refreshState");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter;

import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.rootExecCmd;

import android.content.BroadcastReceiver;
import android.content.Context;
Expand Down Expand Up @@ -163,11 +163,11 @@ public void tileClick(MethodHookParam param, String tileName) {
try {
if (shell) {
/*if (!isCustomSunshineMode) {
currentScreenBrightness = Integer.parseInt(safeExecCommandWithRoot("cat /sys/class/backlight/panel0-backlight/brightness"));
safeExecCommandWithRoot("echo " + setScreenBrightness + " > /sys/class/backlight/panel0-backlight/brightness");
currentScreenBrightness = Integer.parseInt(rootExecCmd("cat /sys/class/backlight/panel0-backlight/brightness"));
rootExecCmd("echo " + setScreenBrightness + " > /sys/class/backlight/panel0-backlight/brightness");
isCustomSunshineMode = true;
} else {
safeExecCommandWithRoot("echo " + currentScreenBrightness + " > /sys/class/backlight/panel0-backlight/brightness");
rootExecCmd("echo " + currentScreenBrightness + " > /sys/class/backlight/panel0-backlight/brightness");
isCustomSunshineMode = false;
}*/
if (lastSunlight == 0 || Integer.parseInt(readAndWrit(null, false)) != pathSunlight) {
Expand Down Expand Up @@ -419,7 +419,7 @@ public static String readAndWrit(String writ, boolean need) {
if (writ != null) {
try {
if (shell) {
safeExecCommandWithRoot("echo " + writ + " > /sys/class/backlight/panel0-backlight/brightness");
rootExecCmd("echo " + writ + " > /sys/class/backlight/panel0-backlight/brightness");
} else {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(path, false))) {
writer.write(writ);
Expand All @@ -431,7 +431,7 @@ public static String readAndWrit(String writ, boolean need) {
}
try {
if (shell) {
builder.append(safeExecCommandWithRoot("cat /sys/class/backlight/panel0-backlight/brightness"));
builder.append(rootExecCmd("cat /sys/class/backlight/panel0-backlight/brightness"));
} else {
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
String line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static com.sevtinge.hyperceiler.BuildConfig.APPLICATION_ID;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.getCurrentUserId;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.getWhoAmI;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.rootExecCmd;

import android.annotation.SuppressLint;
import android.content.Context;
Expand Down Expand Up @@ -107,7 +107,7 @@ private void getScope() {
DatabaseHelper dbHelper = null;

try {
safeExecCommandWithRoot("mkdir -p /data/local/tmp/HyperCeiler/cache/ && cp -r /data/adb/lspd/config /data/local/tmp/HyperCeiler/cache/ && chmod -R 777 /data/local/tmp/HyperCeiler/cache/config");
rootExecCmd("mkdir -p /data/local/tmp/HyperCeiler/cache/ && cp -r /data/adb/lspd/config /data/local/tmp/HyperCeiler/cache/ && chmod -R 777 /data/local/tmp/HyperCeiler/cache/config");
dbHelper = new DatabaseHelper(this.getContext(), "/data/local/tmp/HyperCeiler/cache/config/modules_config.db");
} catch (Exception ignore) {
isScopeGetFailed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.getWhoAmI;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreAndroidVersion;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.rootExecCmd;

import android.content.Intent;
import android.os.Bundle;
Expand Down Expand Up @@ -127,7 +127,7 @@ public void initPrefs() {
handler = new Handler();

try {
mMaxBrightness = Integer.parseInt(safeExecCommandWithRoot("cat /sys/class/backlight/panel0-backlight/max_brightness"));
mMaxBrightness = Integer.parseInt(rootExecCmd("cat /sys/class/backlight/panel0-backlight/max_brightness"));
} catch (Exception ignore) {}

mExpandNotification.setOnPreferenceClickListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.sevtinge.hyperceiler.ui.fragment.main.settings.development;

import static com.sevtinge.hyperceiler.utils.log.LogManager.fixLsposedLogService;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.rootExecCmd;

import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -68,7 +68,7 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
showInDialog(new DevelopmentKillFragment.EditDialogCallback() {
@Override
public void onInputReceived(String command) {
showOutDialog(safeExecCommandWithRoot(command));
showOutDialog(rootExecCmd(command));
}
});
case "prefs_key_development_delete_all_dexkit_cache" ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ fun getBrand(): String = android.os.Build.BRAND
fun getManufacturer(): String = android.os.Build.MANUFACTURER
fun getModDevice(): String = getProp("ro.product.mod_device")
fun getCharacteristics(): String = getProp("ro.build.characteristics")
fun getSerial(): String = safeExecCommandWithRoot("getprop ro.serialno").replace("\n", "")
fun getCpuId(): String = removeLeadingZeros(safeExecCommandWithRoot("getprop ro.boot.cpuid"))
fun getSerial(): String = rootExecCmd("getprop ro.serialno").replace("\n", "")
fun getCpuId(): String = removeLeadingZeros(rootExecCmd("getprop ro.boot.cpuid"))

fun getDensityDpi(): Int =
(EzXHelper.appContext.resources.displayMetrics.widthPixels / EzXHelper.appContext.resources.displayMetrics.density).toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fun getHost(): String = Build.HOST
fun getBuilder(): String = getProp("ro.build.user")
fun getBaseOs(): String = if (getProp("ro.build.version.base_os") != "") getProp("ro.build.version.base_os") else "null"
fun getRomAuthor(): String = getProp("ro.rom.author") + getProp("ro.romid")
fun getWhoAmI(): String = safeExecCommandWithRoot("whoami")
fun getWhoAmI(): String = rootExecCmd("whoami")
fun getCurrentUserId(): Int = Process.myUserHandle().hashCode()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import static com.sevtinge.hyperceiler.utils.devicesdk.DeviceSDKKt.getSerial;
import static com.sevtinge.hyperceiler.utils.prefs.PrefsUtils.mPrefsMap;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;
import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.rootExecCmd;

import android.util.Log;

Expand Down Expand Up @@ -61,7 +61,7 @@ public static String logLevelDesc() {

public static boolean isLoggerAlive() {
try {
String modulesOutput = safeExecCommandWithRoot("ls /data/adb/modules/");
String modulesOutput = rootExecCmd("ls /data/adb/modules/");
String[] moduleLines = modulesOutput.split("\n");
boolean lsposedFound = false;
for (String line : moduleLines) {
Expand All @@ -71,7 +71,7 @@ public static boolean isLoggerAlive() {
}
}
if (lsposedFound) {
String output = safeExecCommandWithRoot("ls /data/adb/lspd/log/");
String output = rootExecCmd("ls /data/adb/lspd/log/");
String[] lines = output.split("\n");
List<String> logFiles = new ArrayList<>();
for (String line : lines) {
Expand All @@ -83,9 +83,9 @@ public static boolean isLoggerAlive() {
if (logFiles.size() == 1) {
String fileName = logFiles.get(0);
String filePath = "/data/adb/lspd/log/" + fileName;
String grepOutput = safeExecCommandWithRoot("grep -q 'HyperCeiler' " + filePath + " && echo 'FOUND' || echo 'EMPTY'");
String grepOutput = rootExecCmd("grep -q 'HyperCeiler' " + filePath + " && echo 'FOUND' || echo 'EMPTY'");
if (grepOutput.trim().equals("EMPTY")) {
grepOutput = safeExecCommandWithRoot("grep -q 'hyperceiler' " + filePath + " && echo 'FOUND' || echo 'EMPTY'");
grepOutput = rootExecCmd("grep -q 'hyperceiler' " + filePath + " && echo 'FOUND' || echo 'EMPTY'");
if (grepOutput.trim().equals("EMPTY")) {
LOGGER_CHECKER_ERR_CODE = "EMPTY_XPOSED_LOG_FILE";
return false;
Expand Down Expand Up @@ -141,8 +141,8 @@ public static boolean isLoggerAlive() {

public static String fixLsposedLogService() {
try {
safeExecCommandWithRoot("resetprop -n persist.log.tag.LSPosed V");
safeExecCommandWithRoot("resetprop -n persist.log.tag.LSPosed-Bridge V");
rootExecCmd("resetprop -n persist.log.tag.LSPosed V");
rootExecCmd("resetprop -n persist.log.tag.LSPosed-Bridge V");
return "SUCCESS";
} catch (Exception e) {
return e.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public CommandResult(int result, String successMsg, String errorMsg) {
}
}

public static String safeExecCommandWithRoot(String cmd) {
public static String rootExecCmd(String cmd) {
if (!isSafeCommand(cmd)) return "Cannot exec this command: Dangerous operation";
StringBuilder result = new StringBuilder();
ProcessBuilder pb = new ProcessBuilder("su");
Expand Down

0 comments on commit f6363a5

Please sign in to comment.