Skip to content

Commit 6b6de20

Browse files
committed
Update SystemService Proxy
1 parent 73b1178 commit 6b6de20

File tree

5 files changed

+53
-754
lines changed

5 files changed

+53
-754
lines changed

PluginCore/src/com/plugin/core/systemservice/AndroidAppIActivityManager.java

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

33
import android.app.ActivityManager;
4+
import android.content.Intent;
45

6+
import com.plugin.content.PluginDescriptor;
57
import com.plugin.core.proxy.MethodDelegate;
68
import com.plugin.core.proxy.MethodProxy;
79
import com.plugin.core.proxy.ProxyUtil;
810
import com.plugin.util.LogUtil;
11+
import com.plugin.util.NotificationHelper;
912
import com.plugin.util.RefInvoker;
1013

1114
import java.lang.reflect.Method;
@@ -19,15 +22,24 @@ private AndroidAppIActivityManager() {
1922
}
2023

2124
public static void installProxy(ActivityManager manager) {
22-
Object androidAppIActivityManagerStubProxy = RefInvoker.invokeStaticMethod("android.app.ActivityManagerNative", "getDefault", (Class[])null, (Object[])null);
23-
Object androidAppIActivityManagerStubProxyProxy = ProxyUtil.createProxy(androidAppIActivityManagerStubProxy, new AndroidAppIActivityManager());
24-
RefInvoker.setStaticOjbect("android.app.ActivityManagerNative", "gDefault", androidAppIActivityManagerStubProxyProxy);
25+
LogUtil.d("安装ActivityManagerProxy");
26+
Object androidAppActivityManagerProxy = RefInvoker.invokeStaticMethod("android.app.ActivityManagerNative", "getDefault", (Class[])null, (Object[])null);
27+
Object androidAppIActivityManagerStubProxyProxy = ProxyUtil.createProxy(androidAppActivityManagerProxy, new AndroidAppIActivityManager());
28+
Object singleton = RefInvoker.getStaticFieldObject("android.app.ActivityManagerNative", "gDefault");
29+
//如果是IActivityManager
30+
if (singleton.getClass().isAssignableFrom(androidAppIActivityManagerStubProxyProxy.getClass())) {
31+
RefInvoker.setStaticOjbect("android.app.ActivityManagerNative", "gDefault", androidAppIActivityManagerStubProxyProxy);
32+
} else {//否则是包装过的单例
33+
RefInvoker.setFieldObject(singleton, "android.util.Singleton", "mInstance", androidAppIActivityManagerStubProxyProxy);
34+
}
35+
LogUtil.d("安装完成");
2536
}
2637

2738
static {
2839
sMethods.put("getRunningAppProcesses", new getRunningAppProcesses());
2940
sMethods.put("killBackgroundProcesses", new killBackgroundProcesses());
30-
sMethods.put("getRunningServices", new getRunningServices());
41+
sMethods.put("getServices", new getServices());
42+
sMethods.put("getIntentSender", new getIntentSender());
3143
}
3244

3345
//public List<RunningAppProcessInfo> getRunningAppProcesses()
@@ -51,7 +63,7 @@ public Object beforeInvoke(Object target, Method method, Object[] args) {
5163
}
5264

5365
//public List<RunningServiceInfo> getRunningServices(int maxNum)
54-
public static class getRunningServices extends MethodDelegate {
66+
public static class getServices extends MethodDelegate {
5567
@Override
5668
public Object beforeInvoke(Object target, Method method, Object[] args) {
5769
LogUtil.e("beforeInvoke", method.getName());
@@ -60,5 +72,37 @@ public Object beforeInvoke(Object target, Method method, Object[] args) {
6072
}
6173
}
6274

75+
public static class getIntentSender extends MethodDelegate {
76+
77+
public static final int INTENT_SENDER_BROADCAST = 1;
78+
public static final int INTENT_SENDER_ACTIVITY = 2;
79+
public static final int INTENT_SENDER_ACTIVITY_RESULT = 3;
80+
public static final int INTENT_SENDER_SERVICE = 4;
6381

82+
@Override
83+
public Object beforeInvoke(Object target, Method method, Object[] args) {
84+
LogUtil.e("beforeInvoke", method.getName());
85+
int type = (int)args[0];
86+
if (type != INTENT_SENDER_ACTIVITY_RESULT) {
87+
for (int i = 0; i < args.length; i++) {
88+
if (args[i] != null && args[i].getClass().isAssignableFrom(Intent[].class)) {
89+
Intent[] intents = (Intent[])args[i];
90+
if (type == INTENT_SENDER_BROADCAST) {
91+
type = PluginDescriptor.BROADCAST;
92+
} else if (type == INTENT_SENDER_ACTIVITY) {
93+
type = PluginDescriptor.ACTIVITY;
94+
} else if (type == INTENT_SENDER_SERVICE) {
95+
type = PluginDescriptor.SERVICE;
96+
}
97+
for(int j = 0; j < intents.length; j++) {
98+
intents[j] = NotificationHelper.resolveNotificationIntent(intents[j], type);
99+
}
100+
break;
101+
}
102+
}
103+
}
104+
105+
return super.beforeInvoke(target, method, args);
106+
}
107+
}
64108
}

PluginCore/src/com/plugin/core/systemservice/AndroidAppINotificationManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ private AndroidAppINotificationManager() {
1919
}
2020

2121
public static void installProxy(NotificationManager manager) {
22+
LogUtil.d("安装NotificationManagerProxy");
2223
Object androidAppINotificationStubProxy = RefInvoker.invokeStaticMethod(NotificationManager.class.getName(), "getService", (Class[])null, (Object[])null);
2324
Object androidAppINotificationStubProxyProxy = ProxyUtil.createProxy(androidAppINotificationStubProxy, new AndroidAppINotificationManager());
2425
RefInvoker.setStaticOjbect(NotificationManager.class.getName(), "sService", androidAppINotificationStubProxyProxy);
26+
LogUtil.d("安装完成");
2527
}
2628

2729
static {

PluginCore/src/com/plugin/core/systemservice/AndroidAppIPackageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
public class AndroidAppIPackageManager extends MethodProxy {
3838

3939
public static void installProxy(PackageManager manager) {
40+
LogUtil.d("安装PackageManagerProxy");
4041
Object androidAppIPackageManagerStubProxy = RefInvoker.getStaticFieldObject("android.app.ActivityThread", "sPackageManager");
4142
Object androidAppIPackageManagerStubProxyProxy = ProxyUtil.createProxy(androidAppIPackageManagerStubProxy, new AndroidAppIPackageManager());
4243
RefInvoker.setStaticOjbect("android.app.ActivityThread", "sPackageManager", androidAppIPackageManagerStubProxyProxy);
4344
RefInvoker.setFieldObject(manager, "android.app.ApplicationPackageManager", "mPM", androidAppIPackageManagerStubProxyProxy);
45+
LogUtil.d("安装完成");
4446
}
4547

4648
static {

0 commit comments

Comments
 (0)