Refine xresources
This commit is contained in:
parent
5b4e13727e
commit
7afdf55eec
|
|
@ -91,34 +91,17 @@ public class XResources extends XposedResources {
|
||||||
private static final WeakHashMap<XmlResourceParser, XMLInstanceDetails> sXmlInstanceDetails = new WeakHashMap<>();
|
private static final WeakHashMap<XmlResourceParser, XMLInstanceDetails> sXmlInstanceDetails = new WeakHashMap<>();
|
||||||
|
|
||||||
private static final String EXTRA_XML_INSTANCE_DETAILS = "xmlInstanceDetails";
|
private static final String EXTRA_XML_INSTANCE_DETAILS = "xmlInstanceDetails";
|
||||||
private static final ThreadLocal<LinkedList<MethodHookParam>> sIncludedLayouts = new ThreadLocal<LinkedList<MethodHookParam>>() {
|
private static final ThreadLocal<LinkedList<MethodHookParam>> sIncludedLayouts = ThreadLocal.withInitial(() -> new LinkedList<>());
|
||||||
@Override
|
|
||||||
protected LinkedList<MethodHookParam> initialValue() {
|
|
||||||
return new LinkedList<>();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final HashMap<String, Long> sResDirLastModified = new HashMap<>();
|
private static final HashMap<String, Long> sResDirLastModified = new HashMap<>();
|
||||||
private static final HashMap<String, String> sResDirPackageNames = new HashMap<>();
|
private static final HashMap<String, String> sResDirPackageNames = new HashMap<>();
|
||||||
private static ThreadLocal<Object> sLatestResKey = null;
|
private static ThreadLocal<Object> sLatestResKey = null;
|
||||||
|
|
||||||
private boolean mIsObjectInited;
|
|
||||||
private String mResDir;
|
private String mResDir;
|
||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
|
|
||||||
public XResources(ClassLoader classLoader) {
|
public XResources(ClassLoader classLoader, String resDir) {
|
||||||
super(classLoader);
|
super(classLoader);
|
||||||
}
|
|
||||||
|
|
||||||
/** Dummy, will never be called (objects are transferred to this class only). */
|
|
||||||
// private XResources() {
|
|
||||||
// throw new UnsupportedOperationException();
|
|
||||||
// }
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
public void initObject(String resDir) {
|
|
||||||
if (mIsObjectInited)
|
|
||||||
throw new IllegalStateException("Object has already been initialized");
|
|
||||||
|
|
||||||
this.mResDir = resDir;
|
this.mResDir = resDir;
|
||||||
this.mPackageName = getPackageName(resDir);
|
this.mPackageName = getPackageName(resDir);
|
||||||
|
|
@ -128,10 +111,13 @@ public class XResources extends XposedResources {
|
||||||
mReplacementsCache = sReplacementsCacheMap.computeIfAbsent(resDir, k -> new byte[128]);
|
mReplacementsCache = sReplacementsCacheMap.computeIfAbsent(resDir, k -> new byte[128]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mIsObjectInited = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Dummy, will never be called (objects are transferred to this class only). */
|
||||||
|
// private XResources() {
|
||||||
|
// throw new UnsupportedOperationException();
|
||||||
|
// }
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public boolean isFirstLoad() {
|
public boolean isFirstLoad() {
|
||||||
synchronized (sReplacements) {
|
synchronized (sReplacements) {
|
||||||
|
|
|
||||||
|
|
@ -183,9 +183,8 @@ public final class XposedInit {
|
||||||
|
|
||||||
// Replace system resources
|
// Replace system resources
|
||||||
XResources systemRes = new XResources(
|
XResources systemRes = new XResources(
|
||||||
(ClassLoader) XposedHelpers.getObjectField(Resources.getSystem(), "mClassLoader"));
|
(ClassLoader) XposedHelpers.getObjectField(Resources.getSystem(), "mClassLoader"), null);
|
||||||
HiddenApiBridge.Resources_setImpl(systemRes, (ResourcesImpl) XposedHelpers.getObjectField(Resources.getSystem(), "mResourcesImpl"));
|
HiddenApiBridge.Resources_setImpl(systemRes, (ResourcesImpl) XposedHelpers.getObjectField(Resources.getSystem(), "mResourcesImpl"));
|
||||||
systemRes.initObject(null);
|
|
||||||
setStaticObjectField(Resources.class, "mSystem", systemRes);
|
setStaticObjectField(Resources.class, "mSystem", systemRes);
|
||||||
|
|
||||||
XResources.init(latestResKey);
|
XResources.init(latestResKey);
|
||||||
|
|
@ -199,9 +198,8 @@ public final class XposedInit {
|
||||||
|
|
||||||
// Replace the returned resources with our subclass.
|
// Replace the returned resources with our subclass.
|
||||||
var newRes = new XResources(
|
var newRes = new XResources(
|
||||||
(ClassLoader) XposedHelpers.getObjectField(param.getResult(), "mClassLoader"));
|
(ClassLoader) XposedHelpers.getObjectField(param.getResult(), "mClassLoader"), resDir);
|
||||||
HiddenApiBridge.Resources_setImpl(newRes, (ResourcesImpl) XposedHelpers.getObjectField(param.getResult(), "mResourcesImpl"));
|
HiddenApiBridge.Resources_setImpl(newRes, (ResourcesImpl) XposedHelpers.getObjectField(param.getResult(), "mResourcesImpl"));
|
||||||
newRes.initObject(resDir);
|
|
||||||
|
|
||||||
// Invoke handleInitPackageResources().
|
// Invoke handleInitPackageResources().
|
||||||
if (newRes.isFirstLoad()) {
|
if (newRes.isFirstLoad()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue