Skip to content

Commit

Permalink
[优化] hyper设备上的磁贴功能,日志优化 [修复] 部分安卓版本磁贴不显示的问题 [修复] hyper上PluginHelper类C…
Browse files Browse the repository at this point in the history
…lassLoader获取失败的问题 (#13)

* [优化] 底层代码修改 [修正] 磁贴在部分设备无法使用的bug

Signed-off-by: HChenX <[email protected]>

* [优化] 字符串

Signed-off-by: HChenX <[email protected]>

* [优化] hyper设备上的磁贴功能,日志优化 [修复] 部分安卓版本磁贴不显示的问题 [修复] hyper上PluginHelper类ClassLoader获取失败的问题

Signed-off-by: HChenX <[email protected]>

---------

Signed-off-by: HChenX <[email protected]>
  • Loading branch information
HChenX authored Oct 31, 2023
1 parent dcc829b commit b950f13
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String[] customTileProvider() {
TileProvider[0] = "screenLockTileProvider";
TileProvider[1] = "createTileInternal";
TileProvider[2] = "interceptCreateTile";
TileProvider[2] = "createTile";
TileProvider[3] = "createTile";
return TileProvider;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isAndroidT;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isAndroidU;

import android.content.pm.ApplicationInfo;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.module.hook.systemui.NotificationVolumeSeparateSlider;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.BluetoothTileStyle;
Expand All @@ -14,7 +12,7 @@ public class PluginHelper extends BaseHook {

private static ClassLoader pluginLoader = null;

private static ApplicationInfo appInfo = null;
// private static ApplicationInfo appInfo = null;

@Override
public void init() {
Expand All @@ -23,61 +21,75 @@ public void init() {
? "com.android.systemui.shared.plugins.PluginInstance$Factory"
: "com.android.systemui.shared.plugins.PluginManagerImpl";
hookAllMethods(pluginLoaderClass, "getClassLoader", new MethodHook() {
private boolean isHooked = false;
private boolean isHooked = false;
private boolean run = false;

@Override
protected void after(MethodHookParam param) {
appInfo = (ApplicationInfo) param.args[0];
if (appInfo != null) {
if ("miui.systemui.plugin".equals(appInfo.packageName) && !isHooked) {
// appInfo = (ApplicationInfo) param.args[0];
// if (appInfo != null) {"miui.systemui.plugin".equals(appInfo.packageName) &&
if (!isHooked) {
if (pluginLoader == null) {
pluginLoader = (ClassLoader) param.getResult();
}
if (pluginLoader.toString().contains("MIUISystemUIPlugin")) {
isHooked = true;
if (pluginLoader == null) {
pluginLoader = (ClassLoader) param.getResult();
}
// logD("pluginLoader: " + pluginLoader);
run = true;
setClassLoader(pluginLoader);
} else {
if (!isHooked)
logD("appInfo is not miui.systemui.plugin is: " + appInfo.packageName + " isHooked: " + isHooked);
logW("PluginHelper", "im not get ClassLoader: " + pluginLoader);
}
// logD("pluginLoader: " + pluginLoader);
// setClassLoader(pluginLoader);
// logE("PluginHelper", "im get ClassLoader: " + pluginLoader);
} else {
logE(TAG, "appInfo is null");
if (!run)
logW("get classloader miui.systemui.plugin error");
}
// } else {
// logE(TAG, "appInfo is null");
// }
}
}
);
} else {
hookAllMethods("com.android.systemui.shared.plugins.PluginInstance$Factory",
"create", new MethodHook() {
@Override
protected void before(MethodHookParam param) {
appInfo = (ApplicationInfo) param.args[1];
}
}
);
// hookAllMethods("com.android.systemui.shared.plugins.PluginInstance$Factory",
// "create", new MethodHook() {
// @Override
// protected void before(MethodHookParam param) {
// appInfo = (ApplicationInfo) param.args[1];
// }
// }
// );

findAndHookMethod("com.android.systemui.shared.plugins.PluginInstance$Factory$$ExternalSyntheticLambda0",
"get", new MethodHook() {
private boolean isHooked = false;
private boolean run = false;

@Override
protected void after(MethodHookParam param) {
Object pathClassLoader = param.getResult();
if (appInfo != null) {
if ("miui.systemui.plugin".equals(appInfo.packageName) && !isHooked) {
// if (appInfo != null) {
if (!isHooked) {
if (pluginLoader == null) {
pluginLoader = (ClassLoader) pathClassLoader;
}
if (pluginLoader.toString().contains("MIUISystemUIPlugin")) {
isHooked = true;
if (pluginLoader == null) {
pluginLoader = (ClassLoader) pathClassLoader;
}
// logD("AU pluginLoader: " + pluginLoader);
run = true;
setClassLoader(pluginLoader);
} else {
if (!isHooked)
logD("AU appInfo is not miui.systemui.plugin is: " + appInfo.packageName + " isHooked: " + isHooked);
logW("PluginHelper", "im not get ClassLoader: " + pluginLoader);
}
// logD("AU pluginLoader: " + pluginLoader);
} else {
logE(TAG, "AU appInfo is null");
if (!run)
logW("Au get classloader miui.systemui.plugin error");
}
// } else {
// logE(TAG, "AU appInfo is null");
// }
}
}
);
Expand Down
42 changes: 36 additions & 6 deletions app/src/main/java/com/sevtinge/hyperceiler/utils/TileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.util.ArrayMap;
import android.view.View;
import android.widget.Switch;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt;

import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
import de.robv.android.xposed.XposedHelpers;
Expand All @@ -34,7 +35,7 @@ public void init() {
SystemUiHook(); // 不需要覆写
tileAllName(mQSFactory); // 不需要覆写
showStateMessage(myTile);
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
if (SystemSDKKt.isAndroidU()) {
tileAllName14(mQSFactory);
}
try {
Expand Down Expand Up @@ -233,7 +234,7 @@ public boolean needAfter() {
private void SystemUiHook() {
String custom = customName();
if (needCustom()) {
if (custom.equals("")) {
if ("".equals(custom)) {
logE(TAG, "com.android.systemui", "Error custom:" + custom);
return;
}
Expand Down Expand Up @@ -337,8 +338,37 @@ private void showStateMessage(Class<?> myTile) {
findAndHookMethod(myTile, "handleShowStateMessage", new MethodHook() {
@Override
protected void before(MethodHookParam param) {
XposedHelpers.callMethod(param.thisObject, "showStateMessage",
XposedHelpers.callMethod(param.thisObject, "getStateMessage"));
try {
XposedHelpers.callMethod(param.thisObject, "showStateMessage",
XposedHelpers.callMethod(param.thisObject, "getStateMessage"));
} catch (Throwable t) {
// try {
// @SuppressLint("PrivateApi") Class<?> QSTileImpl = Class.forName("com.android.systemui.qs.tileimpl.QSTileImpl");
// Method handleShowStateMessage = QSTileImpl.getDeclaredMethod("handleShowStateMessage");
// handleShowStateMessage.invoke(null);
// } catch (ReflectiveOperationException e) {
// logE("showStateMessage", " Find class or call method error: " + e);
// }
String string;
Object o = XposedHelpers.getObjectField(param.thisObject, "mState");
int i = (int) XposedHelpers.getObjectField(o, "state");
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
if (i != 1) {
if (i != 2) {
string = null;
} else {
string = context.getResources().getString(mResHook.addResource("quick_settings_state_change_message_on_my",
R.string.quick_settings_state_change_message_on_my),
XposedHelpers.callMethod(param.thisObject, "getTileLabel"));
}
} else {
string = context.getResources().getString(mResHook.addResource("quick_settings_state_change_message_off_my",
R.string.quick_settings_state_change_message_off_my),
XposedHelpers.callMethod(param.thisObject, "getTileLabel"));
}
XposedHelpers.callMethod(param.thisObject, "showStateMessage", string);
}
// XposedHelpers.callMethod(param.thisObject, "getTileLabel");
param.setResult(null);
}
}
Expand All @@ -359,7 +389,7 @@ private void tileName(Class<?> myTile) {
if (needCustom()) {
int customValue = customValue();
String custom = customName();
if (customValue == -1 || custom.equals("")) {
if (customValue == -1 || "".equals(custom)) {
logE(TAG, "com.android.systemui", "Error customValue:" + customValue);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public static void logI(String msg) {
XposedBridge.log("[HyperCeiler][I]: " + msg);
}

public static void logI(String tag, String msg) {
if (!isDebugVersion) return;
if (isDisableDetailLog) return;
XposedBridge.log("[HyperCeiler][I][" + tag + "]: " + msg);
}

public static void logI(String tag, String pkg, String msg) {
if (!isDebugVersion) return;
if (isDisableDetailLog) return;
Expand Down Expand Up @@ -57,19 +63,13 @@ public static void logW(String tag, String pkg, Throwable log) {
public static void logW(String tag, String pkg, String msg, Exception exp) {
if (isReleaseVersion) return;
if (isDisableDetailLog) return;
XposedBridge.log("[HyperCeiler][W][" + pkg + "][" + tag + "]: " + msg + ", by" + exp);
XposedBridge.log("[HyperCeiler][W][" + pkg + "][" + tag + "]: " + msg + ", by: " + exp);
}

public static void logW(String tag, String pkg, String msg, Throwable log) {
if (isReleaseVersion) return;
if (isDisableDetailLog) return;
XposedBridge.log("[HyperCeiler][W][" + pkg + "][" + tag + "]: " + msg + ", by" + log);
}

public static void logI(String tag, String msg) {
if (!isDebugVersion) return;
if (isDisableDetailLog) return;
XposedBridge.log("[HyperCeiler][I][" + tag + "]: " + msg);
XposedBridge.log("[HyperCeiler][W][" + pkg + "][" + tag + "]: " + msg + ", by: " + log);
}

public static void logW(String tag, String msg) {
Expand All @@ -87,7 +87,7 @@ public static void logW(String tag, Throwable log) {
public static void logW(String tag, String msg, Exception exp) {
if (isReleaseVersion) return;
if (isDisableDetailLog) return;
XposedBridge.log("[HyperCeiler][W][" + tag + "]: " + msg + ", by" + exp);
XposedBridge.log("[HyperCeiler][W][" + tag + "]: " + msg + ", by: " + exp);
}

public static void logE(String tag, String msg) {
Expand Down Expand Up @@ -115,11 +115,11 @@ public static void logE(String tag, String pkg, Exception exp) {
}

public static void logE(String tag, String pkg, String msg, Throwable log) {
XposedBridge.log("[HyperCeiler][E][" + pkg + "][" + tag + "]: " + msg + ", by" + log);
XposedBridge.log("[HyperCeiler][E][" + pkg + "][" + tag + "]: " + msg + ", by: " + log);
}

public static void logE(String tag, String pkg, String msg, Exception exp) {
XposedBridge.log("[HyperCeiler][E][" + pkg + "][" + tag + "]: " + msg + ", by" + exp);
XposedBridge.log("[HyperCeiler][E][" + pkg + "][" + tag + "]: " + msg + ", by: " + exp);
}

public static void logD(String msg) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@
<string name="system_ui_controlcenter_magnet_title">磁贴</string>
<string name="system_ui_control_center_notification_blur_title">通知</string>
<string name="system_control_center_qs_detail_bg">卡片背景透明度</string>
<string name="quick_settings_state_change_message_on_my">%1$s已开启</string>
<string name="quick_settings_state_change_message_off_my">%1$s已关闭</string>
<string name="system_control_center_5g_tile">5G 网络开关</string>
<string name="system_control_center_5g_toggle_label">5G网络</string>
<string name="system_control_center_sunshine_mode">阳光模式</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@
<string name="system_ui_controlcenter_magnet_title">Magnet</string>
<string name="system_ui_control_center_notification_blur_title">Notification</string>
<string name="system_control_center_qs_detail_bg">Card background transparency</string>
<string name="quick_settings_state_change_message_on_my">%1$s is on</string>
<string name="quick_settings_state_change_message_off_my">%1$s is off</string>
<string name="system_control_center_5g_tile">5G network switch</string>
<string name="system_control_center_5g_toggle_label">5G Network</string>
<string name="system_control_center_sunshine_mode">Sunshine Mode</string>
Expand Down

0 comments on commit b950f13

Please sign in to comment.