Skip to content

Commit f06e725

Browse files
committed
Delete classloaderutil
1 parent 3f604e9 commit f06e725

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.os.IBinder;
77
import android.os.Message;
88

9-
import com.plugin.util.ClassLoaderUtil;
109
import com.plugin.util.LogUtil;
1110
import com.plugin.util.RefInvoker;
1211

@@ -85,7 +84,7 @@ private static Result beforeCreateService(Message msg) {
8584
String serviceName = PluginIntentResolver.hackServiceName(msg.obj);
8685

8786
if (serviceName != null) {
88-
ClassLoaderUtil.hackHostClassLoaderIfNeeded();
87+
PluginInjector.hackHostClassLoaderIfNeeded();
8988
}
9089
Result result = new Result();
9190
result.serviceName = serviceName;

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.plugin.content.PluginProviderInfo;
2424
import com.plugin.core.annotation.AnnotationProcessor;
2525
import com.plugin.core.annotation.FragmentContainer;
26-
import com.plugin.util.ClassLoaderUtil;
2726
import com.plugin.util.LogUtil;
2827
import com.plugin.util.RefInvoker;
2928
import com.plugin.util.ResourceUtil;
@@ -102,7 +101,7 @@ static void installContentProviders(Context context, Collection<PluginProviderIn
102101
LogUtil.d("安装插件ContentProvider", pluginProviderInfos.size());
103102
Object activityThread = PluginInjector.getActivityThread();
104103
if (activityThread != null) {
105-
ClassLoaderUtil.hackHostClassLoaderIfNeeded();
104+
PluginInjector.hackHostClassLoaderIfNeeded();
106105
List<ProviderInfo> providers = new ArrayList<ProviderInfo>();
107106
for (PluginProviderInfo pluginProviderInfo : pluginProviderInfos) {
108107
ProviderInfo p = new ProviderInfo();
@@ -366,4 +365,20 @@ static void replaceContext(Object manager, Context context) {
366365
RefInvoker.setFieldObject(manager, manager.getClass().getName(), "mContext", context);
367366
}
368367
}
368+
369+
/**
370+
* 如果插件中不包含service、receiver和contentprovider,是不需要替换classloader的
371+
*/
372+
public static void hackHostClassLoaderIfNeeded() {
373+
Object mLoadedApk = RefInvoker.getFieldObject(PluginLoader.getApplicatoin(), Application.class.getName(),
374+
"mLoadedApk");
375+
ClassLoader originalLoader = (ClassLoader) RefInvoker.getFieldObject(mLoadedApk, "android.app.LoadedApk",
376+
"mClassLoader");
377+
if (!(originalLoader instanceof HostClassLoader)) {
378+
HostClassLoader newLoader = new HostClassLoader("", PluginLoader.getApplicatoin()
379+
.getCacheDir().getAbsolutePath(),
380+
PluginLoader.getApplicatoin().getCacheDir().getAbsolutePath(), originalLoader);
381+
RefInvoker.setFieldObject(mLoadedApk, "android.app.LoadedApk", "mClassLoader", newLoader);
382+
}
383+
}
369384
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.plugin.content.PluginActivityInfo;
1010
import com.plugin.content.PluginDescriptor;
1111
import com.plugin.content.PluginReceiverIntent;
12-
import com.plugin.util.ClassLoaderUtil;
1312
import com.plugin.util.LogUtil;
1413
import com.plugin.util.RefInvoker;
1514

@@ -23,7 +22,7 @@ public class PluginIntentResolver {
2322
public static void resolveService(Intent service) {
2423
ArrayList<String> classNameList = PluginLoader.matchPlugin(service, PluginDescriptor.SERVICE);
2524
if (classNameList != null && classNameList.size() > 0) {
26-
ClassLoaderUtil.hackHostClassLoaderIfNeeded();
25+
PluginInjector.hackHostClassLoaderIfNeeded();
2726
String stubServiceName = PluginStubBinding.bindStubService(classNameList.get(0));
2827
if (stubServiceName != null) {
2928
service.setComponent(new ComponentName(PluginLoader.getApplicatoin().getPackageName(), stubServiceName));
@@ -37,7 +36,7 @@ public static ArrayList<Intent> resolveReceiver(final Intent intent) {
3736
ArrayList<Intent> result = new ArrayList<Intent>();
3837
ArrayList<String> classNameList = PluginLoader.matchPlugin(intent, PluginDescriptor.BROADCAST);
3938
if (classNameList != null && classNameList.size() > 0) {
40-
ClassLoaderUtil.hackHostClassLoaderIfNeeded();
39+
PluginInjector.hackHostClassLoaderIfNeeded();
4140

4241
for(String className: classNameList) {
4342
Intent newIntent = new Intent(intent);

PluginCore/src/com/plugin/util/ClassLoaderUtil.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)