1
1
package com .plugin .core .systemservice ;
2
2
3
3
import android .app .ActivityManager ;
4
+ import android .content .Intent ;
4
5
6
+ import com .plugin .content .PluginDescriptor ;
5
7
import com .plugin .core .proxy .MethodDelegate ;
6
8
import com .plugin .core .proxy .MethodProxy ;
7
9
import com .plugin .core .proxy .ProxyUtil ;
8
10
import com .plugin .util .LogUtil ;
11
+ import com .plugin .util .NotificationHelper ;
9
12
import com .plugin .util .RefInvoker ;
10
13
11
14
import java .lang .reflect .Method ;
@@ -19,15 +22,24 @@ private AndroidAppIActivityManager() {
19
22
}
20
23
21
24
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 ("安装完成" );
25
36
}
26
37
27
38
static {
28
39
sMethods .put ("getRunningAppProcesses" , new getRunningAppProcesses ());
29
40
sMethods .put ("killBackgroundProcesses" , new killBackgroundProcesses ());
30
- sMethods .put ("getRunningServices" , new getRunningServices ());
41
+ sMethods .put ("getServices" , new getServices ());
42
+ sMethods .put ("getIntentSender" , new getIntentSender ());
31
43
}
32
44
33
45
//public List<RunningAppProcessInfo> getRunningAppProcesses()
@@ -51,7 +63,7 @@ public Object beforeInvoke(Object target, Method method, Object[] args) {
51
63
}
52
64
53
65
//public List<RunningServiceInfo> getRunningServices(int maxNum)
54
- public static class getRunningServices extends MethodDelegate {
66
+ public static class getServices extends MethodDelegate {
55
67
@ Override
56
68
public Object beforeInvoke (Object target , Method method , Object [] args ) {
57
69
LogUtil .e ("beforeInvoke" , method .getName ());
@@ -60,5 +72,37 @@ public Object beforeInvoke(Object target, Method method, Object[] args) {
60
72
}
61
73
}
62
74
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 ;
63
81
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
+ }
64
108
}
0 commit comments