Skip to content

Commit ee95154

Browse files
committed
update LoadedApk
1 parent abc9462 commit ee95154

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

PluginCore/src/com/plugin/core/PluginLoader.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,15 @@ static void ensurePluginInited(PluginDescriptor pluginDescriptor) {
486486
pluginDescriptor.setPluginContext(pluginContext);
487487
pluginDescriptor.setPluginClassLoader(pluginClassLoader);
488488

489+
callPluginApplicationOnCreate(pluginDescriptor);
490+
489491
try {
490-
ActivityThread.installPackageInfo(getApplicatoin(), pluginDescriptor.getPackageName());
492+
ActivityThread.installPackageInfo(getApplicatoin(), pluginDescriptor.getPackageName(), pluginDescriptor);
491493
} catch (ClassNotFoundException e) {
492494
e.printStackTrace();
493495
}
494496

495-
callPluginApplicationOnCreate(pluginDescriptor);
497+
changeListener.onPluginStarted(pluginDescriptor.getPackageName());
496498

497499
LogUtil.e("初始化插件" + pluginDescriptor.getPackageName() + "完成");
498500
}
@@ -525,7 +527,6 @@ private static void callPluginApplicationOnCreate(PluginDescriptor pluginDescrip
525527
application.onCreate();
526528
}
527529

528-
changeListener.onPluginStarted(pluginDescriptor.getPackageName());
529530
}
530531

531532
public static boolean isInstalled(String pluginId, String pluginVersion) {

PluginCore/src/com/plugin/core/app/ActivityThread.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public synchronized static Object currentActivityThread() {
5454
}
5555

5656
public static Object getResCompatibilityInfo() {
57+
//貌似没啥用
5758
Object mBoundApplication = RefInvoker.getFieldObject(currentActivityThread(), android_app_ActivityThread, "mBoundApplication");
5859
Object compatInfo = RefInvoker.getFieldObject(mBoundApplication, android_app_ActivityThread_AppBindData, "compatInfo");
5960
return compatInfo;
@@ -166,7 +167,7 @@ public static void wrapInstrumentation() {
166167
// 42 parent = baseParent;
167168
// 43 }
168169
//
169-
public static void installPackageInfo(Context hostContext, String pluginId) throws ClassNotFoundException {
170+
public static void installPackageInfo(Context hostContext, String pluginId, PluginDescriptor pluginDescriptor) throws ClassNotFoundException {
170171
enableLog();
171172
Object applicationLoaders = RefInvoker.invokeStaticMethod("android.app.ApplicationLoaders", "getDefault", (Class[]) null, (Object[]) null);
172173
Map mLoaders = (Map)RefInvoker.getFieldObject(applicationLoaders, "android.app.ApplicationLoaders", "mLoaders");
@@ -181,6 +182,15 @@ public static void installPackageInfo(Context hostContext, String pluginId) thro
181182
Object pluginLoadedApk = RefInvoker.invokeMethod(currentActivityThread(), android_app_ActivityThread, "getPackageInfoNoCheck",
182183
new Class[]{ApplicationInfo.class, Class.forName("android.content.res.CompatibilityInfo")},
183184
new Object[]{info, compatibilityInfo});
185+
if (pluginLoadedApk != null) {
186+
Class loadedAPKClass = pluginLoadedApk.getClass();
187+
RefInvoker.setFieldObject(pluginLoadedApk, loadedAPKClass, "mApplication", pluginDescriptor.getPluginApplication());
188+
RefInvoker.setFieldObject(pluginLoadedApk, loadedAPKClass, "mResources", pluginDescriptor.getPluginContext().getResources());
189+
//TODO
190+
//RefInvoker.setFieldObject(pluginLoadedApk, loadedAPKClass, "mLibDir", );
191+
//RefInvoker.setFieldObject(pluginLoadedApk, loadedAPKClass, "mDataDirFile", );
192+
//RefInvoker.setFieldObject(pluginLoadedApk, loadedAPKClass, "mDataDir", );
193+
}
184194
//再还原
185195
Thread.currentThread().setContextClassLoader(classLoader);
186196
} catch (PackageManager.NameNotFoundException e) {

0 commit comments

Comments
 (0)