Contains various methods for information about the current app. For historical reasons, this class is in the android.app package. It can't be moved without breaking compatibility with existing modules.
| 29 | * without breaking compatibility with existing modules. |
| 30 | */ |
| 31 | @Keep public final class AndroidAppHelper { |
| 32 | private AndroidAppHelper() {} |
| 33 | |
| 34 | private static final Class<?> CLASS_RESOURCES_KEY; |
| 35 | |
| 36 | private static final boolean HAS_IS_THEMEABLE; |
| 37 | private static final boolean HAS_THEME_CONFIG_PARAMETER; |
| 38 | |
| 39 | static { |
| 40 | // Dreamland changed: remove unreachable condition |
| 41 | // CLASS_RESOURCES_KEY = (Build.VERSION.SDK_INT < 19) ? |
| 42 | // findClass("android.app.ActivityThread$ResourcesKey", null) |
| 43 | // : findClass("android.content.res.ResourcesKey", null); |
| 44 | |
| 45 | CLASS_RESOURCES_KEY = findClass("android.content.res.ResourcesKey", null); |
| 46 | |
| 47 | HAS_IS_THEMEABLE = findFieldIfExists(CLASS_RESOURCES_KEY, "mIsThemeable") != null; |
| 48 | HAS_THEME_CONFIG_PARAMETER = HAS_IS_THEMEABLE |
| 49 | && findMethodExactIfExists("android.app.ResourcesManager", null, "getThemeConfig") != null; |
| 50 | } |
| 51 | |
| 52 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| 53 | private static Map<Object, WeakReference> getResourcesMap(ActivityThread activityThread) { |
| 54 | // Dreamland changed: remove unreachable condition |
| 55 | Object resourcesManager = getObjectField(activityThread, "mResourcesManager"); |
| 56 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| 57 | return (Map) getObjectField(resourcesManager, "mResourceImpls"); |
| 58 | } else { |
| 59 | // } else if (Build.VERSION.SDK_INT >= 19) { |
| 60 | return (Map) getObjectField(resourcesManager, "mActiveResources"); |
| 61 | // } else { |
| 62 | // return (Map) getObjectField(activityThread, "mActiveResources"); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // Dreamland changed: remove unreachable methods |
| 67 | // /* For SDK 15 & 16 */ |
| 68 | // private static Object createResourcesKey(String resDir, float scale) { |
| 69 | // try { |
| 70 | // if (HAS_IS_THEMEABLE) |
| 71 | // return newInstance(CLASS_RESOURCES_KEY, resDir, scale, false); |
| 72 | // else |
| 73 | // return newInstance(CLASS_RESOURCES_KEY, resDir, scale); |
| 74 | // } catch (Throwable t) { |
| 75 | // XposedBridge.log(t); |
| 76 | // return null; |
| 77 | // } |
| 78 | // } |
| 79 | // |
| 80 | /* For SDK 17 & 18 & 23 */ |
| 81 | // Dreamland changed: inline arguments |
| 82 | private static Object createResourcesKeyM(String resDir, float scale) { |
| 83 | try { |
| 84 | if (HAS_THEME_CONFIG_PARAMETER) |
| 85 | return newInstance(CLASS_RESOURCES_KEY, resDir, Display.DEFAULT_DISPLAY, null, scale, false, null); |
| 86 | else if (HAS_IS_THEMEABLE) |
| 87 | return newInstance(CLASS_RESOURCES_KEY, resDir, Display.DEFAULT_DISPLAY, null, scale, false); |
| 88 | else |