Skip to content

Commit 09a0982

Browse files
committed
增强PluginContextTheme
1 parent b1986a9 commit 09a0982

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.plugin.core;
22

3+
import com.plugin.core.ui.stub.PluginStubReceiver;
4+
import com.plugin.core.ui.stub.PluginStubService;
5+
import com.plugin.util.LogUtil;
36
import com.plugin.util.RefInvoker;
47

8+
import android.content.ComponentName;
59
import android.content.Context;
610
import android.content.ContextWrapper;
11+
import android.content.Intent;
712
import android.content.res.AssetManager;
813
import android.content.res.Resources;
914
import android.view.LayoutInflater;
@@ -89,5 +94,42 @@ private void initializeTheme() {
8994
}
9095
mTheme.applyStyle(mThemeResource, true);
9196
}
97+
98+
@Override
99+
public void sendBroadcast(Intent intent) {
100+
LogUtil.d("sendBroadcast", intent.toUri(0));
101+
Intent realIntent = intent;
102+
if (PluginDispatcher.hackClassLoadForReceiverIfNeeded(intent)) {
103+
realIntent = new Intent();
104+
realIntent.setClass(PluginLoader.getApplicatoin(), PluginStubReceiver.class);
105+
realIntent.putExtra(PluginDispatcher.RECEIVER_ID_IN_PLUGIN, intent);
106+
}
107+
super.sendBroadcast(realIntent);
108+
}
109+
110+
@Override
111+
public ComponentName startService(Intent service) {
112+
LogUtil.d("startService", service.toUri(0));
113+
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(service)) {
114+
service.setClass(PluginLoader.getApplicatoin(), PluginStubService.class);
115+
}
116+
return super.startService(service);
117+
}
118+
119+
@Override
120+
public void startActivity(Intent intent) {
121+
LogUtil.d("startActivity", intent.toUri(0));
122+
PluginInstrumentionWrapper.resloveIntent(intent);
123+
super.startActivity(intent);
124+
}
125+
126+
// @Override
127+
// public Context getApplicationContext() {
128+
// if (getBaseContext() instanceof Activity) {
129+
// return super.getApplicationContext();
130+
// } else {
131+
// return this;
132+
// }
133+
// }
92134
}
93135

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static void sendBroadcast(Context context, Intent intent) {
111111
* @param intent
112112
* @return
113113
*/
114-
private static boolean hackClassLoadForServiceIfNeeded(Intent intent) {
114+
/*package*/ static boolean hackClassLoadForServiceIfNeeded(Intent intent) {
115115
String targetClassName = PluginLoader.isMatchPlugin(intent);
116116
if (targetClassName != null) {
117117
Object mLoadedApk = RefInvoker.getFieldObject(PluginLoader.getApplicatoin(), Application.class.getName(), "mLoadedApk");
@@ -132,7 +132,7 @@ private static boolean hackClassLoadForServiceIfNeeded(Intent intent) {
132132
return false;
133133
}
134134

135-
private static boolean hackClassLoadForReceiverIfNeeded(Intent intent) {
135+
/*package*/ static boolean hackClassLoadForReceiverIfNeeded(Intent intent) {
136136
//如果在插件中发现了匹配intent的receiver项目,替换掉ClassLoader
137137
//不需要在这里记录目标className,className将在Intent中传递
138138
if (PluginLoader.isMatchPlugin(intent) != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public ActivityResult execStartActivity(
292292
return (ActivityResult)result;
293293
}
294294

295-
private static void resloveIntent(Intent intent) {
295+
/*package*/ static void resloveIntent(Intent intent) {
296296
//如果在插件中发现Intent的匹配项,记下匹配的插件Activity的ClassName
297297
String className = PluginLoader.isMatchPlugin(intent);
298298
if (className != null) {

0 commit comments

Comments
 (0)