From b67a1030f83bd251cfda0f435f9f033c233cdd93 Mon Sep 17 00:00:00 2001 From: DrDisagree Date: Tue, 10 Oct 2023 18:28:41 +0600 Subject: [PATCH] Handle crash if class does not exist --- .../iconify/xposed/mods/Miscellaneous.java | 59 ++++----- .../iconify/xposed/mods/QSBlackTheme.java | 114 +++++++++--------- .../iconify/xposed/mods/QSFluidTheme.java | 32 ++--- 3 files changed, 107 insertions(+), 98 deletions(-) diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/Miscellaneous.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/Miscellaneous.java index a61a3192a..b4ada8ac1 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/Miscellaneous.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/Miscellaneous.java @@ -12,6 +12,7 @@ import static com.drdisagree.iconify.config.XPrefs.Xprefs; import static com.drdisagree.iconify.xposed.HookRes.resparams; import static de.robv.android.xposed.XposedBridge.hookAllMethods; +import static de.robv.android.xposed.XposedBridge.log; import static de.robv.android.xposed.XposedHelpers.callMethod; import static de.robv.android.xposed.XposedHelpers.findClass; import static de.robv.android.xposed.XposedHelpers.findClassIfExists; @@ -180,43 +181,47 @@ protected void afterHookedMethod(MethodHookParam param) { fixedStatusIconsA12(); hideLockscreenCarrierOrStatusbar(); - Class MobileSignalController = findClass(SYSTEMUI_PACKAGE + ".statusbar.connectivity.MobileSignalController", lpparam.classLoader); - final boolean[] alwaysShowDataRatIcon = {false}; - final boolean[] mDataDisabledIcon = {false}; + try { + Class MobileSignalController = findClass(SYSTEMUI_PACKAGE + ".statusbar.connectivity.MobileSignalController", lpparam.classLoader); + final boolean[] alwaysShowDataRatIcon = {false}; + final boolean[] mDataDisabledIcon = {false}; - hookAllMethods(MobileSignalController, "updateTelephony", new XC_MethodHook() { - @Override - protected void beforeHookedMethod(MethodHookParam param) { - if (MobileSignalControllerParam == null) - MobileSignalControllerParam = param.thisObject; + hookAllMethods(MobileSignalController, "updateTelephony", new XC_MethodHook() { + @Override + protected void beforeHookedMethod(MethodHookParam param) { + if (MobileSignalControllerParam == null) + MobileSignalControllerParam = param.thisObject; - if (!hideDataDisabledIcon) return; + if (!hideDataDisabledIcon) return; - alwaysShowDataRatIcon[0] = (boolean) getObjectField(getObjectField(param.thisObject, "mConfig"), "alwaysShowDataRatIcon"); - setObjectField(getObjectField(param.thisObject, "mConfig"), "alwaysShowDataRatIcon", false); + alwaysShowDataRatIcon[0] = (boolean) getObjectField(getObjectField(param.thisObject, "mConfig"), "alwaysShowDataRatIcon"); + setObjectField(getObjectField(param.thisObject, "mConfig"), "alwaysShowDataRatIcon", false); - try { - mDataDisabledIcon[0] = (boolean) getObjectField(param.thisObject, "mDataDisabledIcon"); - setObjectField(param.thisObject, "mDataDisabledIcon", false); - } catch (Throwable ignored) { + try { + mDataDisabledIcon[0] = (boolean) getObjectField(param.thisObject, "mDataDisabledIcon"); + setObjectField(param.thisObject, "mDataDisabledIcon", false); + } catch (Throwable ignored) { + } } - } - @Override - protected void afterHookedMethod(MethodHookParam param) { - if (MobileSignalControllerParam == null) - MobileSignalControllerParam = param.thisObject; + @Override + protected void afterHookedMethod(MethodHookParam param) { + if (MobileSignalControllerParam == null) + MobileSignalControllerParam = param.thisObject; - if (!hideDataDisabledIcon) return; + if (!hideDataDisabledIcon) return; - setObjectField(getObjectField(param.thisObject, "mConfig"), "alwaysShowDataRatIcon", alwaysShowDataRatIcon[0]); + setObjectField(getObjectField(param.thisObject, "mConfig"), "alwaysShowDataRatIcon", alwaysShowDataRatIcon[0]); - try { - setObjectField(param.thisObject, "mDataDisabledIcon", mDataDisabledIcon[0]); - } catch (Throwable ignored) { + try { + setObjectField(param.thisObject, "mDataDisabledIcon", mDataDisabledIcon[0]); + } catch (Throwable ignored) { + } } - } - }); + }); + } catch (Throwable ignored) { + log(TAG + "Not a crash... MobileSignalController class not found."); + } } private void hideQSCarrierGroup() { diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/QSBlackTheme.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/QSBlackTheme.java index 94b864b12..7fa156c92 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/QSBlackTheme.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/QSBlackTheme.java @@ -94,7 +94,7 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) { Class QuickStatusBarHeaderClass = findClass(SYSTEMUI_PACKAGE + ".qs.QuickStatusBarHeader", lpparam.classLoader); Class BrightnessControllerClass = findClass(SYSTEMUI_PACKAGE + ".settings.brightness.BrightnessController", lpparam.classLoader); Class BrightnessMirrorControllerClass = findClass(SYSTEMUI_PACKAGE + ".statusbar.policy.BrightnessMirrorController", lpparam.classLoader); - Class BrightnessSliderControllerClass = findClass(SYSTEMUI_PACKAGE + ".settings.brightness.BrightnessSliderController", lpparam.classLoader); + Class BrightnessSliderControllerClass = findClassIfExists(SYSTEMUI_PACKAGE + ".settings.brightness.BrightnessSliderController", lpparam.classLoader); hookAllConstructors(QSPanelControllerClass, new XC_MethodHook() { @Override @@ -219,22 +219,26 @@ protected void afterHookedMethod(MethodHookParam param) { } }); - hookAllConstructors(BrightnessSliderControllerClass, new XC_MethodHook() { - @Override - protected void afterHookedMethod(MethodHookParam param) { - if (!blackQSHeaderEnabled) return; + if (BrightnessSliderControllerClass != null) { + hookAllConstructors(BrightnessSliderControllerClass, new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) { + if (!blackQSHeaderEnabled) return; - try { - ((ImageView) getObjectField(param.thisObject, "mIcon")).setImageTintList(ColorStateList.valueOf(colorText)); - } catch (Throwable throwable) { try { - ((ImageView) getObjectField(param.thisObject, "mIconView")).setImageTintList(ColorStateList.valueOf(colorText)); - } catch (Throwable throwable1) { - log(TAG + throwable1); + ((ImageView) getObjectField(param.thisObject, "mIcon")).setImageTintList(ColorStateList.valueOf(colorText)); + } catch (Throwable throwable) { + try { + ((ImageView) getObjectField(param.thisObject, "mIconView")).setImageTintList(ColorStateList.valueOf(colorText)); + } catch (Throwable throwable1) { + log(TAG + throwable1); + } } } - } - }); + }); + } else { + log(TAG + "Not a crash... BrightnessSliderController class not found."); + } hookAllMethods(BrightnessMirrorControllerClass, "updateIcon", new XC_MethodHook() { @Override @@ -431,36 +435,34 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { for (Object constant : constants) { String enumVal = constant.toString(); switch (enumVal) { - case "KEYGUARD": - hookAllMethods(constant.getClass(), "prepare", new XC_MethodHook() { - @Override - protected void afterHookedMethod(MethodHookParam param) throws Throwable { - if (!blackQSHeaderEnabled) return; - boolean mClipQsScrim = (boolean) getObjectField(param.thisObject, "mClipQsScrim"); - if (mClipQsScrim) { - Object mScrimBehind = getObjectField(param.thisObject, "mScrimBehind"); - int mTintColor = getIntField(mScrimBehind, "mTintColor"); - if (mTintColor != Color.BLACK) { - setObjectField(mScrimBehind, "mTintColor", Color.BLACK); - callMethod(mScrimBehind, "updateColorWithTint", false); + case "KEYGUARD" -> + hookAllMethods(constant.getClass(), "prepare", new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + if (!blackQSHeaderEnabled) return; + boolean mClipQsScrim = (boolean) getObjectField(param.thisObject, "mClipQsScrim"); + if (mClipQsScrim) { + Object mScrimBehind = getObjectField(param.thisObject, "mScrimBehind"); + int mTintColor = getIntField(mScrimBehind, "mTintColor"); + if (mTintColor != Color.BLACK) { + setObjectField(mScrimBehind, "mTintColor", Color.BLACK); + callMethod(mScrimBehind, "updateColorWithTint", false); + } + + callMethod(mScrimBehind, "setViewAlpha", 1f); } - - callMethod(mScrimBehind, "setViewAlpha", 1f); } - } - }); - break; - case "BOUNCER": - hookAllMethods(constant.getClass(), "prepare", new XC_MethodHook() { - @Override - protected void afterHookedMethod(MethodHookParam param) throws Throwable { - if (!blackQSHeaderEnabled) return; + }); + case "BOUNCER" -> + hookAllMethods(constant.getClass(), "prepare", new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + if (!blackQSHeaderEnabled) return; - setObjectField(param.thisObject, "mBehindTint", Color.BLACK); - } - }); - break; - case "SHADE_LOCKED": + setObjectField(param.thisObject, "mBehindTint", Color.BLACK); + } + }); + case "SHADE_LOCKED" -> { hookAllMethods(constant.getClass(), "prepare", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { @@ -487,26 +489,24 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable { param.setResult(Color.BLACK); } }); - break; - - case "UNLOCKED": - hookAllMethods(constant.getClass(), "prepare", new XC_MethodHook() { - @Override - protected void afterHookedMethod(MethodHookParam param) throws Throwable { - if (!blackQSHeaderEnabled) return; + } + case "UNLOCKED" -> + hookAllMethods(constant.getClass(), "prepare", new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + if (!blackQSHeaderEnabled) return; - setObjectField(param.thisObject, "mBehindTint", Color.BLACK); + setObjectField(param.thisObject, "mBehindTint", Color.BLACK); - Object mScrimBehind = getObjectField(param.thisObject, "mScrimBehind"); - int mTintColor = getIntField(mScrimBehind, "mTintColor"); - if (mTintColor != Color.BLACK) { - setObjectField(mScrimBehind, "mTintColor", Color.BLACK); - callMethod(mScrimBehind, "updateColorWithTint", false); + Object mScrimBehind = getObjectField(param.thisObject, "mScrimBehind"); + int mTintColor = getIntField(mScrimBehind, "mTintColor"); + if (mTintColor != Color.BLACK) { + setObjectField(mScrimBehind, "mTintColor", Color.BLACK); + callMethod(mScrimBehind, "updateColorWithTint", false); + } + callMethod(mScrimBehind, "setViewAlpha", 1f); } - callMethod(mScrimBehind, "setViewAlpha", 1f); - } - }); - break; + }); } } } catch (Throwable throwable) { diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/QSFluidTheme.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/QSFluidTheme.java index 4b91baccb..b9b2ddd2d 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/QSFluidTheme.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/QSFluidTheme.java @@ -104,7 +104,7 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) { Class BrightnessSliderViewClass = findClass(SYSTEMUI_PACKAGE + ".settings.brightness.BrightnessSliderView", lpparam.classLoader); Class BrightnessControllerClass = findClass(SYSTEMUI_PACKAGE + ".settings.brightness.BrightnessController", lpparam.classLoader); Class BrightnessMirrorControllerClass = findClass(SYSTEMUI_PACKAGE + ".statusbar.policy.BrightnessMirrorController", lpparam.classLoader); - Class BrightnessSliderControllerClass = findClass(SYSTEMUI_PACKAGE + ".settings.brightness.BrightnessSliderController", lpparam.classLoader); + Class BrightnessSliderControllerClass = findClassIfExists(SYSTEMUI_PACKAGE + ".settings.brightness.BrightnessSliderController", lpparam.classLoader); Class ActivatableNotificationViewClass = findClass(SYSTEMUI_PACKAGE + ".statusbar.notification.row.ActivatableNotificationView", lpparam.classLoader); // Initialize resources and colors @@ -286,23 +286,27 @@ protected void afterHookedMethod(MethodHookParam param) { } }); - hookAllConstructors(BrightnessSliderControllerClass, new XC_MethodHook() { - @Override - protected void afterHookedMethod(MethodHookParam param) { - if (!fluidQsThemeEnabled) return; + if (BrightnessSliderControllerClass != null) { + hookAllConstructors(BrightnessSliderControllerClass, new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) { + if (!fluidQsThemeEnabled) return; - try { - ((ImageView) getObjectField(param.thisObject, "mIcon")).setImageTintList(ColorStateList.valueOf(colorActive[0])); - ((ImageView) getObjectField(param.thisObject, "mIcon")).setBackgroundTintList(ColorStateList.valueOf(colorActiveAlpha[0])); - } catch (Throwable throwable) { try { - ((ImageView) getObjectField(param.thisObject, "mIconView")).setImageTintList(ColorStateList.valueOf(colorActive[0])); - ((ImageView) getObjectField(param.thisObject, "mIconView")).setBackgroundTintList(ColorStateList.valueOf(colorActiveAlpha[0])); - } catch (Throwable ignored) { + ((ImageView) getObjectField(param.thisObject, "mIcon")).setImageTintList(ColorStateList.valueOf(colorActive[0])); + ((ImageView) getObjectField(param.thisObject, "mIcon")).setBackgroundTintList(ColorStateList.valueOf(colorActiveAlpha[0])); + } catch (Throwable throwable) { + try { + ((ImageView) getObjectField(param.thisObject, "mIconView")).setImageTintList(ColorStateList.valueOf(colorActive[0])); + ((ImageView) getObjectField(param.thisObject, "mIconView")).setBackgroundTintList(ColorStateList.valueOf(colorActiveAlpha[0])); + } catch (Throwable ignored) { + } } } - } - }); + }); + } else { + log(TAG + "Not a crash... BrightnessSliderController class not found."); + } hookAllMethods(BrightnessMirrorControllerClass, "updateIcon", new XC_MethodHook() { @Override