Fix resource hook on ZUI (#1691)

This commit is contained in:
LoveSy 2022-02-14 20:02:24 +08:00 committed by GitHub
parent 142c308261
commit f8198488aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 5 deletions

View File

@ -22,6 +22,7 @@ package de.robv.android.xposed;
import static de.robv.android.xposed.XposedHelpers.setObjectField; import static de.robv.android.xposed.XposedHelpers.setObjectField;
import android.app.ActivityThread;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.util.Log; import android.util.Log;
@ -96,10 +97,27 @@ public final class XposedBridge {
Class<?> resClass = res.getClass(); Class<?> resClass = res.getClass();
Class<?> taClass = TypedArray.class; Class<?> taClass = TypedArray.class;
try { try {
TypedArray ta = res.obtainTypedArray(res.getIdentifier( try {
"preloaded_drawables", "array", "android")); TypedArray ta = res.obtainTypedArray(res.getIdentifier(
taClass = ta.getClass(); "preloaded_drawables", "array", "android"));
ta.recycle(); taClass = ta.getClass();
ta.recycle();
} catch (NullPointerException npe) {
// For ZUI devices, the creation of TypedArray needs to check the configuration
// from ActivityThread.currentActivityThread. However, we do not have a valid
// ActivityThread for now and the call will throw an NPE. Luckily they check the
// nullability of the result configuration. So we hereby set a dummy
// ActivityThread to bypass such a situation.
XposedHelpers.setStaticObjectField(ActivityThread.class, "sCurrentActivityThread", new ActivityThread());
try {
TypedArray ta = res.obtainTypedArray(res.getIdentifier(
"preloaded_drawables", "array", "android"));
taClass = ta.getClass();
ta.recycle();
} finally {
XposedHelpers.setStaticObjectField(ActivityThread.class, "sCurrentActivityThread", null);
}
}
} catch (Resources.NotFoundException nfe) { } catch (Resources.NotFoundException nfe) {
XposedBridge.log(nfe); XposedBridge.log(nfe);
} }
@ -152,7 +170,7 @@ public final class XposedBridge {
* Deoptimize a method to avoid callee being inlined. * Deoptimize a method to avoid callee being inlined.
* *
* @param deoptimizedMethod The method to deoptmize. Generally it should be a caller of a method * @param deoptimizedMethod The method to deoptmize. Generally it should be a caller of a method
* that is inlined. * that is inlined.
*/ */
public static void deoptimizeMethod(Member deoptimizedMethod) { public static void deoptimizeMethod(Member deoptimizedMethod) {
if (!(deoptimizedMethod instanceof Executable)) { if (!(deoptimizedMethod instanceof Executable)) {