Skip to content

Commit 4cbcd10

Browse files
committed
Simplify isThemeable checks using the new APIs
1 parent 468b5ca commit 4cbcd10

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

app/src/main/java/android/app/AndroidAppHelper.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import de.robv.android.xposed.XposedBridge;
1616

1717
import static de.robv.android.xposed.XposedHelpers.findClass;
18-
import static de.robv.android.xposed.XposedHelpers.findField;
19-
import static de.robv.android.xposed.XposedHelpers.findMethodExact;
18+
import static de.robv.android.xposed.XposedHelpers.findFieldIfExists;
19+
import static de.robv.android.xposed.XposedHelpers.findMethodExactIfExists;
2020
import static de.robv.android.xposed.XposedHelpers.getObjectField;
2121
import static de.robv.android.xposed.XposedHelpers.newInstance;
2222

@@ -30,28 +30,17 @@ public final class AndroidAppHelper {
3030
private AndroidAppHelper() {}
3131

3232
private static final Class<?> CLASS_RESOURCES_KEY;
33-
private static boolean HAS_IS_THEMEABLE = false;
34-
private static boolean HAS_THEME_CONFIG_PARAMETER = false;
33+
private static final boolean HAS_IS_THEMEABLE;
34+
private static final boolean HAS_THEME_CONFIG_PARAMETER;
3535

3636
static {
3737
CLASS_RESOURCES_KEY = (Build.VERSION.SDK_INT < 19) ?
3838
findClass("android.app.ActivityThread$ResourcesKey", null)
3939
: findClass("android.content.res.ResourcesKey", null);
4040

41-
try {
42-
// T-Mobile theming engine (CyanogenMod etc.)
43-
findField(CLASS_RESOURCES_KEY, "mIsThemeable");
44-
HAS_IS_THEMEABLE = true;
45-
} catch (NoSuchFieldError ignored) {
46-
} catch (Throwable t) { XposedBridge.log(t); }
47-
48-
if (HAS_IS_THEMEABLE && Build.VERSION.SDK_INT >= 21) {
49-
try {
50-
findMethodExact("android.app.ResourcesManager", null, "getThemeConfig");
51-
HAS_THEME_CONFIG_PARAMETER = true;
52-
} catch (NoSuchMethodError ignored) {
53-
} catch (Throwable t) { XposedBridge.log(t); }
54-
}
41+
HAS_IS_THEMEABLE = findFieldIfExists(CLASS_RESOURCES_KEY, "mIsThemeable") != null;
42+
HAS_THEME_CONFIG_PARAMETER = HAS_IS_THEMEABLE && Build.VERSION.SDK_INT >= 21
43+
&& findMethodExactIfExists("android.app.ResourcesManager", null, "getThemeConfig") != null;
5544
}
5645

5746
@SuppressWarnings({ "unchecked", "rawtypes" })

0 commit comments

Comments
 (0)