Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevtinge committed Nov 5, 2023
2 parents 5243d7f + c5b5ac4 commit 50d7252
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
Original file line number Diff line number Diff line change
@@ -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
);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -91,7 +89,7 @@ public void beforeHookedMethod(MethodHookParam param) throws Throwable {
try {
this.before(param);
} catch (Throwable t) {
//logE("BeforeHook", t);
// logE("BeforeHook", t);
}
}

Expand All @@ -100,7 +98,7 @@ public void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
this.after(param);
} catch (Throwable t) {
//logE("AfterHook", t);
// logE("AfterHook", t);
}
}
}
Expand All @@ -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");
}
}

Expand All @@ -125,15 +123,15 @@ 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);
}
}

public XC_MethodHook.Unhook findAndHookMethodUseUnhook(String className, ClassLoader classLoader, String methodName, Object... parameterTypesAndCallback) {
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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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);
}
}

Expand All @@ -200,15 +198,15 @@ 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);
}
}

public static void hookAllMethods(Class<?> hookClass, String methodName, MethodHook callback) {
try {
XposedBridge.hookAllMethods(hookClass, methodName, callback);
} catch (Throwable t) {
//logE("HookAllMethods", hookClass + " is " + methodName + " abnormal: " + t);
// logE("HookAllMethods", hookClass + " is " + methodName + " abnormal: " + t);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -251,15 +249,15 @@ 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);
}
}

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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -297,21 +295,21 @@ 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);
}
}

public void checkLast(String setObject, Object fieldName, Object value, Object last) {
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);
}
}
}

0 comments on commit 50d7252

Please sign in to comment.