mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-15 12:51:17 +08:00
Merge pull request #169
* 修复 隐藏网速单位 & 随便精简了下代码 * Update SettingsActivity.kt
This commit is contained in:
@@ -8,9 +8,9 @@ import java.util.List;
|
||||
|
||||
public class ShellUtils {
|
||||
|
||||
public static final String COMMAND_SU = "su";
|
||||
public static final String COMMAND_SH = "sh";
|
||||
public static final String COMMAND_EXIT = "exit\n";
|
||||
public static final String COMMAND_SU = "su";
|
||||
public static final String COMMAND_SH = "sh";
|
||||
public static final String COMMAND_EXIT = "exit\n";
|
||||
public static final String COMMAND_LINE_END = "\n";
|
||||
|
||||
private ShellUtils() {
|
||||
@@ -30,31 +30,31 @@ public class ShellUtils {
|
||||
* execute shell command, default return result msg
|
||||
*
|
||||
* @param command command
|
||||
* @param isRoot whether need to run with root
|
||||
* @param isRoot whether need to run with root
|
||||
* @return
|
||||
* @see ShellUtils#execCommand(String[], boolean, boolean)
|
||||
*/
|
||||
public static CommandResult execCommand(String command, boolean isRoot) {
|
||||
return execCommand(new String[] {command}, isRoot, true);
|
||||
return execCommand(new String[]{command}, isRoot, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* execute shell commands, default return result msg
|
||||
*
|
||||
* @param commands command activity_wifi
|
||||
* @param isRoot whether need to run with root
|
||||
* @param isRoot whether need to run with root
|
||||
* @return
|
||||
* @see ShellUtils#execCommand(String[], boolean, boolean)
|
||||
*/
|
||||
public static CommandResult execCommand(List<String> commands, boolean isRoot) {
|
||||
return execCommand(commands == null ? null : commands.toArray(new String[] {}), isRoot, true);
|
||||
return execCommand(commands == null ? null : commands.toArray(new String[]{}), isRoot, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* execute shell commands, default return result msg
|
||||
*
|
||||
* @param commands command array
|
||||
* @param isRoot whether need to run with root
|
||||
* @param isRoot whether need to run with root
|
||||
* @return
|
||||
* @see ShellUtils#execCommand(String[], boolean, boolean)
|
||||
*/
|
||||
@@ -65,40 +65,40 @@ public class ShellUtils {
|
||||
/**
|
||||
* execute shell command
|
||||
*
|
||||
* @param command command
|
||||
* @param isRoot whether need to run with root
|
||||
* @param command command
|
||||
* @param isRoot whether need to run with root
|
||||
* @param isNeedResultMsg whether need result msg
|
||||
* @return
|
||||
* @see ShellUtils#execCommand(String[], boolean, boolean)
|
||||
*/
|
||||
public static CommandResult execCommand(String command, boolean isRoot, boolean isNeedResultMsg) {
|
||||
return execCommand(new String[] {command}, isRoot, isNeedResultMsg);
|
||||
return execCommand(new String[]{command}, isRoot, isNeedResultMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* execute shell commands
|
||||
*
|
||||
* @param commands command activity_wifi
|
||||
* @param isRoot whether need to run with root
|
||||
* @param commands command activity_wifi
|
||||
* @param isRoot whether need to run with root
|
||||
* @param isNeedResultMsg whether need result msg
|
||||
* @return
|
||||
* @see ShellUtils#execCommand(String[], boolean, boolean)
|
||||
*/
|
||||
public static CommandResult execCommand(List<String> commands, boolean isRoot, boolean isNeedResultMsg) {
|
||||
return execCommand(commands == null ? null : commands.toArray(new String[] {}), isRoot, isNeedResultMsg);
|
||||
return execCommand(commands == null ? null : commands.toArray(new String[]{}), isRoot, isNeedResultMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* execute shell commands
|
||||
*
|
||||
* @param commands command array
|
||||
* @param isRoot whether need to run with root
|
||||
* @param commands command array
|
||||
* @param isRoot whether need to run with root
|
||||
* @param isNeedResultMsg whether need result msg
|
||||
* @return <ul>
|
||||
* <li>if isNeedResultMsg is false, {@link CommandResult#successMsg} is null and
|
||||
* {@link CommandResult#errorMsg} is null.</li>
|
||||
* <li>if {@link CommandResult#result} is -1, there maybe some excepiton.</li>
|
||||
* </ul>
|
||||
* <li>if isNeedResultMsg is false, {@link CommandResult#successMsg} is null and
|
||||
* {@link CommandResult#errorMsg} is null.</li>
|
||||
* <li>if {@link CommandResult#result} is -1, there maybe some excepiton.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static CommandResult execCommand(String[] commands, boolean isRoot, boolean isNeedResultMsg) {
|
||||
int result = -1;
|
||||
@@ -184,11 +184,17 @@ public class ShellUtils {
|
||||
*/
|
||||
public static class CommandResult {
|
||||
|
||||
/** result of command **/
|
||||
public int result;
|
||||
/** success message of command result **/
|
||||
/**
|
||||
* result of command
|
||||
**/
|
||||
public int result;
|
||||
/**
|
||||
* success message of command result
|
||||
**/
|
||||
public String successMsg;
|
||||
/** error message of command result **/
|
||||
/**
|
||||
* error message of command result
|
||||
**/
|
||||
public String errorMsg;
|
||||
|
||||
public CommandResult(int result) {
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package com.lt2333.simplicitytools.util
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
|
||||
object SystemProperties {
|
||||
@SuppressLint("PrivateApi")
|
||||
operator fun get(context: Context, key: String?): String? {
|
||||
var ret = ""
|
||||
try {
|
||||
val cl = context.classLoader
|
||||
val SystemProperties = cl.loadClass("android.os.SystemProperties")
|
||||
val systemProperties = cl.loadClass("android.os.SystemProperties")
|
||||
//参数类型
|
||||
val paramTypes: Array<Class<*>?> = arrayOfNulls(1)
|
||||
paramTypes[0] = String::class.java
|
||||
val get = SystemProperties.getMethod("get", *paramTypes)
|
||||
val get = systemProperties.getMethod("get", *paramTypes)
|
||||
//参数
|
||||
val params = arrayOfNulls<Any>(1)
|
||||
params[0] = key
|
||||
ret = get.invoke(SystemProperties, *params) as String
|
||||
ret = get.invoke(systemProperties, *params) as String
|
||||
} catch (iAE: IllegalArgumentException) {
|
||||
throw iAE
|
||||
} catch (e: Exception) {
|
||||
@@ -23,4 +25,5 @@ object SystemProperties {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ object XSPUtils {
|
||||
}
|
||||
return prefs.getBoolean(key, defValue)
|
||||
}
|
||||
|
||||
fun getInt(key: String, defValue: Int): Int {
|
||||
if (prefs.hasFileChanged()) {
|
||||
prefs.reload()
|
||||
@@ -34,7 +35,12 @@ object XSPUtils {
|
||||
}
|
||||
}
|
||||
|
||||
inline fun hasEnable(key: String, default: Boolean = false, noinline extraCondition: (() -> Boolean)? = null, crossinline block: () -> Unit) {
|
||||
inline fun hasEnable(
|
||||
key: String,
|
||||
default: Boolean = false,
|
||||
noinline extraCondition: (() -> Boolean)? = null,
|
||||
crossinline block: () -> Unit
|
||||
) {
|
||||
val conditionResult = if (extraCondition != null) extraCondition() else true
|
||||
if (XSPUtils.getBoolean(key, default) && conditionResult) {
|
||||
block()
|
||||
|
||||
@@ -5,20 +5,26 @@ import com.github.kyuubiran.ezxhelper.utils.Log.logexIfThrow
|
||||
import com.lt2333.simplicitytools.util.xposed.base.AppRegister
|
||||
import de.robv.android.xposed.IXposedHookLoadPackage
|
||||
import de.robv.android.xposed.IXposedHookZygoteInit
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||
|
||||
abstract class EasyXposedInit: IXposedHookLoadPackage, IXposedHookZygoteInit {
|
||||
abstract class EasyXposedInit : IXposedHookLoadPackage, IXposedHookZygoteInit {
|
||||
|
||||
private lateinit var packageParam: XC_LoadPackage.LoadPackageParam
|
||||
abstract val registeredApp: List<AppRegister>
|
||||
private val TAG = "WooBox"
|
||||
|
||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam?) {
|
||||
|
||||
packageParam = lpparam!!
|
||||
registeredApp.forEach { app ->
|
||||
if (app.packageName == lpparam.packageName && (lpparam.processName in app.processName || app.processName.isEmpty())) {
|
||||
EzXHelperInit.initHandleLoadPackage(lpparam)
|
||||
EzXHelperInit.setLogTag(app.logTag)
|
||||
EzXHelperInit.setToastTag(app.logTag)
|
||||
if (app.packageName == lpparam.packageName) {
|
||||
EzXHelperInit.apply {
|
||||
setLogXp(true)
|
||||
setLogTag(TAG)
|
||||
setToastTag(TAG)
|
||||
initHandleLoadPackage(lpparam)
|
||||
}
|
||||
runCatching { app.handleLoadPackage(lpparam) }.logexIfThrow("Failed call handleLoadPackage, package: ${app.packageName}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
package com.lt2333.simplicitytools.util.xposed.base
|
||||
|
||||
import com.github.kyuubiran.ezxhelper.utils.Log
|
||||
import com.github.kyuubiran.ezxhelper.utils.Log.logexIfThrow
|
||||
import de.robv.android.xposed.IXposedHookInitPackageResources
|
||||
import de.robv.android.xposed.IXposedHookLoadPackage
|
||||
import de.robv.android.xposed.callbacks.XC_InitPackageResources
|
||||
import de.robv.android.xposed.XposedBridge
|
||||
import de.robv.android.xposed.callbacks.XC_LoadPackage
|
||||
|
||||
abstract class AppRegister: IXposedHookLoadPackage {
|
||||
|
||||
abstract val packageName: String
|
||||
abstract val processName: List<String>
|
||||
abstract val logTag: String
|
||||
|
||||
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {}
|
||||
|
||||
protected fun autoInitHooks(lpparam: XC_LoadPackage.LoadPackageParam, vararg hook: HookRegister) {
|
||||
hook.forEach {
|
||||
hook.also {
|
||||
XposedBridge.log("WooBox: Try to Hook [$packageName]")
|
||||
}.forEach {
|
||||
runCatching {
|
||||
if (it.isInit) return@forEach
|
||||
it.setLoadPackageParam(lpparam)
|
||||
it.init()
|
||||
it.isInit = true
|
||||
Log.i("Inited hook: ${it.javaClass.simpleName}")
|
||||
}.logexIfThrow("Failed init hook: ${it.javaClass.simpleName}")
|
||||
}.logexIfThrow("Failed to Hook [$packageName]")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user