diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/app/SystemUI.java b/app/src/main/java/com/sevtinge/hyperceiler/module/app/SystemUI.java index 2eb48124aa..21f50517cd 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/app/SystemUI.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/app/SystemUI.java @@ -139,7 +139,7 @@ public void handleLoadPackage() { initHook(NetworkSpeedWidth.INSTANCE, mPrefsMap.getInt("system_ui_statusbar_network_speed_fixedcontent_width", 10) > 10); } initHook(NetworkSpeedStyle.INSTANCE); - initHook(NetworkSpeedSpacing.INSTANCE, mPrefsMap.getInt("system_ui_statusbar_network_speed_update_spacing", 3) != 3); + initHook(new NetworkSpeedSpacing(), mPrefsMap.getInt("system_ui_statusbar_network_speed_update_spacing", 3) != 3); initHook(new NetworkSpeedSec(), mPrefsMap.getBoolean("system_ui_statusbar_network_speed_sec_unit")); initHook(StatusBarNoNetSpeedSep.INSTANCE, mPrefsMap.getBoolean("system_ui_status_bar_no_netspeed_separator")); diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/network/NetworkSpeedSpacing.java b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/network/NetworkSpeedSpacing.java new file mode 100644 index 0000000000..d5b1d9000f --- /dev/null +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/network/NetworkSpeedSpacing.java @@ -0,0 +1,120 @@ +package com.sevtinge.hyperceiler.module.hook.systemui.statusbar.network; + +import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isAndroidR; +import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreAndroidVersion; + +import android.os.Build; +import android.os.Message; + +import com.sevtinge.hyperceiler.module.base.BaseHook; + +import de.robv.android.xposed.XposedHelpers; + +public class NetworkSpeedSpacing extends BaseHook { + public boolean handler; + + @Override + public void init() { + if (isMoreAndroidVersion(Build.VERSION_CODES.S)) { + try { + findClass("com.android.systemui.statusbar.policy.NetworkSpeedController").getDeclaredMethod("postUpdateNetworkSpeedDelay", long.class); + findAndHookMethod("com.android.systemui.statusbar.policy.NetworkSpeedController", + "postUpdateNetworkSpeedDelay", long.class, new MethodHook() { + @Override + protected void before(MethodHookParam param) { + long originInterval = (long) param.args[0]; + if (originInterval == 4000L) { + originInterval = mPrefsMap.getInt( + "system_ui_statusbar_network_speed_update_spacing", + 4 + ) * 1000L; + param.args[0] = originInterval; + } + } + } + ); + } catch (NoSuchMethodException e) { + findAndHookMethod("com.android.systemui.statusbar.policy.NetworkSpeedController$4", + "handleMessage", Message.class, new MethodHook() { + /* @Override + protected void before(MethodHookParam param) { + Message message = (Message) param.args[0]; + // Object handleMessage = XposedHelpers.getObjectField(param.thisObject, "this$0"); + switch (message.what) { + case 100001, 100002 -> { + handler = true; + logE(TAG, "handleMessage before: " + handler); + } + } + }*/ + + @Override + protected void after(MethodHookParam param) { + Message message = (Message) param.args[0]; + Object handleMessage = XposedHelpers.getObjectField(param.thisObject, "this$0"); + Object mBgHandler = XposedHelpers.getObjectField(handleMessage, "mBgHandler"); + switch (message.what) { + /* case 100001: + boolean z = (boolean) XposedHelpers.getObjectField(XposedHelpers.getObjectField(handleMessage, + "mNetworkSpeedState"), "visible"); + logE(TAG, "100001: " + z + " :" + mBgHandler); + handleMessage(mBgHandler, z); + case 100002: + boolean z2 = (boolean) XposedHelpers.getObjectField(XposedHelpers.getObjectField(handleMessage, + "mNetworkSpeedState"), "visible"); + logE(TAG, "100002: " + z2 + " :" + mBgHandler); + handleMessage(mBgHandler, z2);*/ + case 200001: + handleMessage(mBgHandler, true); + // logE(TAG, "200001: " + mBgHandler); + } + } + } + ); + + /*findAndHookMethod("android.os.Handler", + "sendEmptyMessageDelayed", int.class, long.class, + new MethodHook() { + @Override + protected void before(MethodHookParam param) { + if (handler) { + param.setResult(true); + logE(TAG, "sendEmptyMessageDelayed im run"); + handler = false; + } + } + } + );*/ + } + } + + if (isAndroidR()) { + findAndHookMethod("com.android.systemui.statusbar.NetworkSpeedController", + "postUpdateNetworkSpeedDelay", long.class, new MethodHook() { + @Override + protected void before(MethodHookParam param) { + long originInterval = (long) param.args[0]; + if (originInterval != 0L) { + originInterval = mPrefsMap.getInt( + "system_ui_statusbar_network_speed_update_spacing", + 4 + ) * 1000L; + param.args[0] = originInterval; + } + } + } + ); + } + } + + public void handleMessage(Object mBgHandler, boolean z) { + XposedHelpers.callMethod(mBgHandler, "removeMessages", 200001); + if (z) { + XposedHelpers.callMethod(mBgHandler, "sendEmptyMessageDelayed", 200001, + mPrefsMap.getInt("system_ui_statusbar_network_speed_update_spacing", + 4 + ) * 1000L + ); + } + } +} diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/network/NetworkSpeedSpacing.kt b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/network/NetworkSpeedSpacing.kt deleted file mode 100644 index 03a8fde346..0000000000 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/statusbar/network/NetworkSpeedSpacing.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.sevtinge.hyperceiler.module.hook.systemui.statusbar.network - -import android.os.Build -import com.sevtinge.hyperceiler.module.base.BaseHook - -object NetworkSpeedSpacing : BaseHook() { - override fun init() { - // 网速更新间隔 - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { // Android12+ 可用 - findAndHookMethod( - "com.android.systemui.statusbar.policy.NetworkSpeedController", lpparam.classLoader, - "postUpdateNetworkSpeedDelay", - Long::class.javaPrimitiveType, - object : MethodHook() { - override fun before(param: MethodHookParam) { - val originInterval = param.args[0] as Long - if (originInterval == 4000L) { - val newInterval = - mPrefsMap.getInt( - "system_ui_statusbar_network_speed_update_spacing", - 4 - ) * 1000L - param.args[0] = newInterval - } - } - } - ) - } - - if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) { // Android11 可用 - findAndHookMethod( - "com.android.systemui.statusbar.NetworkSpeedController", lpparam.classLoader, - "postUpdateNetworkSpeedDelay", - Long::class.javaPrimitiveType, - object : MethodHook() { - override fun before(param: MethodHookParam) { - val originInterval = param.args[0] as Long - if (originInterval != 0L) { - val intervalTime = - mPrefsMap.getInt( - "system_ui_statusbar_network_speed_update_spacing", - 4 - ) * 1000L - param.args[0] = intervalTime - } - } - } - ) - } - } -} diff --git a/app/src/main/java/com/sevtinge/hyperceiler/utils/hook/HookUtils.java b/app/src/main/java/com/sevtinge/hyperceiler/utils/hook/HookUtils.java index fa777c16b8..7946652c73 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/utils/hook/HookUtils.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/utils/hook/HookUtils.java @@ -1,7 +1,5 @@ package com.sevtinge.hyperceiler.utils.hook; -import static com.sevtinge.hyperceiler.utils.log.AndroidLogUtils.LogI; - import com.sevtinge.hyperceiler.utils.log.XposedLogUtils; import java.lang.reflect.Field; @@ -31,7 +29,7 @@ public Class findClassIfExists(String className) { try { return findClass(className); } catch (XposedHelpers.ClassNotFoundError e) { - //logE("findClassIfExists", "find " + className + " is Null: " + e); + // logE("findClassIfExists", "find " + className + " is Null: " + e); return null; } } @@ -40,7 +38,7 @@ public Class findClassIfExists(String newClassName, String oldClassName) { try { return findClass(findClassIfExists(newClassName) != null ? newClassName : oldClassName); } catch (XposedHelpers.ClassNotFoundError e) { - //logE("findClassIfExists", "find " + newClassName + " and " + oldClassName + " is Null: " + e); + // logE("findClassIfExists", "find " + newClassName + " and " + oldClassName + " is Null: " + e); return null; } } @@ -49,7 +47,7 @@ public Class findClassIfExists(String className, ClassLoader classLoader) { try { return findClass(className, classLoader); } catch (XposedHelpers.ClassNotFoundError e) { - //logE("findClassIfExists", "find " + className + " is Null: " + e); + // logE("findClassIfExists", "find " + className + " is Null: " + e); return null; } } @@ -91,7 +89,7 @@ public void beforeHookedMethod(MethodHookParam param) throws Throwable { try { this.before(param); } catch (Throwable t) { - //logE("BeforeHook", t); + // logE("BeforeHook", t); } } @@ -100,7 +98,7 @@ public void afterHookedMethod(MethodHookParam param) throws Throwable { try { this.after(param); } catch (Throwable t) { - //logE("AfterHook", t); + // logE("AfterHook", t); } } } @@ -109,7 +107,7 @@ public void hookMethod(Method method, MethodHook callback) { try { XposedBridge.hookMethod(method, callback); } catch (Throwable t) { - //logE("hookMethod", "Failed to hook " + method.getName() + " method"); + // logE("hookMethod", "Failed to hook " + method.getName() + " method"); } } @@ -125,7 +123,7 @@ public static void findAndHookMethod(String className, ClassLoader classLoader, try { XposedHelpers.findAndHookMethod(className, classLoader, methodName, parameterTypesAndCallback); } catch (Throwable t) { - //logE("findAndHookMethod", "Failed to hook " + methodName + " method in " + className); + // logE("findAndHookMethod", "Failed to hook " + methodName + " method in " + className); } } @@ -133,7 +131,7 @@ public XC_MethodHook.Unhook findAndHookMethodUseUnhook(String className, ClassLo try { return XposedHelpers.findAndHookMethod(className, classLoader, methodName, parameterTypesAndCallback); } catch (Throwable t) { - //logE("findAndHookMethodUseUnhook", "Failed to hook " + methodName + " method in " + className); + // logE("findAndHookMethodUseUnhook", "Failed to hook " + methodName + " method in " + className); return null; } } @@ -142,7 +140,7 @@ public XC_MethodHook.Unhook findAndHookMethodUseUnhook(Class clazz, String me try { return XposedHelpers.findAndHookMethod(clazz, methodName, parameterTypesAndCallback); } catch (Throwable t) { - //logE("findAndHookMethodUseUnhook", "Failed to hook " + methodName + " method in " + clazz.getCanonicalName()); + // logE("findAndHookMethodUseUnhook", "Failed to hook " + methodName + " method in " + clazz.getCanonicalName()); return null; } } @@ -152,7 +150,7 @@ public boolean findAndHookMethodSilently(String className, String methodName, Ob findAndHookMethod(className, methodName, parameterTypesAndCallback); return true; } catch (Throwable t) { - //logE("findAndHookMethodSilently", className + methodName + " is null: " + t); + // logE("findAndHookMethodSilently", className + methodName + " is null: " + t); return false; } } @@ -162,7 +160,7 @@ public boolean findAndHookMethodSilently(String className, ClassLoader classLoad XposedHelpers.findAndHookMethod(className, classLoader, methodName, parameterTypesAndCallback); return true; } catch (Throwable t) { - //logE("findAndHookMethodSilently", className + methodName + " is null: " + t); + // logE("findAndHookMethodSilently", className + methodName + " is null: " + t); return false; } } @@ -172,7 +170,7 @@ public boolean findAndHookMethodSilently(Class clazz, String methodName, Obje findAndHookMethod(clazz, methodName, parameterTypesAndCallback); return true; } catch (Throwable t) { - //logE("findAndHookMethodSilently", clazz + methodName + " is null: " + t); + // logE("findAndHookMethodSilently", clazz + methodName + " is null: " + t); return false; } } @@ -189,7 +187,7 @@ public void findAndHookConstructor(String className, ClassLoader classLoader, Ob try { XposedHelpers.findAndHookConstructor(className, classLoader, parameterTypesAndCallback); } catch (Throwable t) { - LogI("findAndHookConstructor", "Failed to hook constructor in " + className + " Error: " + t); + // LogI("findAndHookConstructor", "Failed to hook constructor in " + className + " Error: " + t); } } @@ -200,7 +198,7 @@ public void hookAllMethods(String className, String methodName, MethodHook callb XposedBridge.hookAllMethods(hookClass, methodName, callback); } } catch (Throwable t) { - //logE("HookAllMethods", className + " is " + methodName + " abnormal: " + t); + // logE("HookAllMethods", className + " is " + methodName + " abnormal: " + t); } } @@ -208,7 +206,7 @@ public static void hookAllMethods(Class hookClass, String methodName, MethodH try { XposedBridge.hookAllMethods(hookClass, methodName, callback); } catch (Throwable t) { - //logE("HookAllMethods", hookClass + " is " + methodName + " abnormal: " + t); + // logE("HookAllMethods", hookClass + " is " + methodName + " abnormal: " + t); } } @@ -219,7 +217,7 @@ public static void hookAllMethods(String className, ClassLoader classLoader, Str XposedBridge.hookAllMethods(hookClass, methodName, callback); } } catch (Throwable t) { - //logE("hookAllMethods", className + " is abnormal", t); + // logE("hookAllMethods", className + " is abnormal", t); } } @@ -251,7 +249,7 @@ public void hookAllConstructors(String className, MethodHook callback) { XposedBridge.hookAllConstructors(hookClass, callback); } } catch (Throwable t) { - //logE("hookAllConstructors", className + " is abnormal: " + t); + // logE("hookAllConstructors", className + " is abnormal: " + t); } } @@ -259,7 +257,7 @@ public void hookAllConstructors(Class hookClass, MethodHook callback) { try { XposedBridge.hookAllConstructors(hookClass, callback); } catch (Throwable t) { - //logE("hookAllConstructors", hookClass + " is abnormal: " + t); + // logE("hookAllConstructors", hookClass + " is abnormal: " + t); } } @@ -270,7 +268,7 @@ public void hookAllConstructors(String className, ClassLoader classLoader, Metho XposedBridge.hookAllConstructors(hookClass, callback); } } catch (Throwable t) { - //logE("hookAllConstructors", className + " is abnormal", t); + // logE("hookAllConstructors", className + " is abnormal", t); } } @@ -297,13 +295,13 @@ public void setDeclaredField(XC_MethodHook.MethodHookParam param, String iNeedSt Object result = setString.get(param.thisObject); checkLast("getDeclaredField", iNeedString, iNeedTo, result); } catch (IllegalAccessException e) { - //logE("IllegalAccessException to: " + iNeedString + " need to: " + iNeedTo + " code: " + e); + // logE("IllegalAccessException to: " + iNeedString + " need to: " + iNeedTo + " code: " + e); } } catch (NoSuchFieldException e) { - //logE("No such the: " + iNeedString + " code: " + e); + // logE("No such the: " + iNeedString + " code: " + e); } } else { - //logE("Param is null Field: " + iNeedString + " to: " + iNeedTo); + // logE("Param is null Field: " + iNeedString + " to: " + iNeedTo); } } @@ -311,7 +309,7 @@ public void checkLast(String setObject, Object fieldName, Object value, Object l if (value.equals(last)) { logI(setObject + " Success! set " + fieldName + " to " + value); } else { - //logE(setObject + " Failed! set " + fieldName + " to " + value + " hope: " + value + " but: " + last); + // logE(setObject + " Failed! set " + fieldName + " to " + value + " hope: " + value + " but: " + last); } } }