Skip to content

Commit 30a2435

Browse files
committed
Add systemservice proxy
1 parent f06e725 commit 30a2435

File tree

5 files changed

+149
-40
lines changed

5 files changed

+149
-40
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.plugin.core;
22

3+
import android.app.ActivityManager;
4+
import android.app.NotificationManager;
35
import android.content.Context;
46
import android.content.SharedPreferences;
57
import android.content.pm.ApplicationInfo;
@@ -12,12 +14,15 @@
1214

1315
import com.plugin.content.PluginDescriptor;
1416
import com.plugin.core.localservice.LocalServiceManager;
17+
import com.plugin.core.systemservice.AndroidAppIActivityManager;
18+
import com.plugin.core.systemservice.AndroidAppINotificationManager;
1519
import com.plugin.core.systemservice.PackageManagerCompat;
1620
import com.plugin.core.systemservice.PluginPackageManager;
1721
import com.plugin.util.LogUtil;
1822
import com.plugin.util.RefInvoker;
1923

2024
import java.io.File;
25+
import java.util.HashSet;
2126

2227
public class PluginContextTheme extends PluginBaseContextWrapper {
2328
private int mThemeResource;
@@ -29,6 +34,8 @@ public class PluginContextTheme extends PluginBaseContextWrapper {
2934

3035
protected final PluginDescriptor mPluginDescriptor;
3136

37+
final static HashSet<String> sServiceCache = new HashSet<String>(5);
38+
3239
public PluginContextTheme(PluginDescriptor pluginDescriptor, Context base, Resources resources, ClassLoader classLoader) {
3340
super(base);
3441
mPluginDescriptor = pluginDescriptor;
@@ -95,6 +102,18 @@ public Object getSystemService(String name) {
95102

96103
Object service = getBaseContext().getSystemService(name);
97104

105+
if (service != null && !sServiceCache.contains(name)) {
106+
if (NOTIFICATION_SERVICE.equals(name)) {
107+
AndroidAppINotificationManager.installProxy((NotificationManager)service);
108+
sServiceCache.add(name);
109+
} else if (ACTIVITY_SERVICE.equals(name)) {
110+
AndroidAppIActivityManager.installProxy((ActivityManager) service);
111+
sServiceCache.add(name);
112+
} else if (ALARM_SERVICE.equals(name)) {
113+
114+
}
115+
}
116+
98117
if (service == null) {
99118

100119
if ("package_manager".equals(name)) {
@@ -110,7 +129,6 @@ public Object getSystemService(String name) {
110129

111130
@Override
112131
public PackageManager getPackageManager() {
113-
//return new PluginPackageManager(new PackageManagerCompat(getPackageManager()));
114132
return super.getPackageManager();
115133
}
116134

PluginCore/src/com/plugin/core/proxy/ProxyUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class ProxyUtil {
1010

11-
public static Object asInterface(Object target, MethodDelegate delegate) {
11+
public static Object createProxy(Object target, MethodDelegate delegate) {
1212
Class<?> clazz = target.getClass();
1313
List<Class<?>> interfaces = getAllInterfaces(clazz);
1414
Class[] ifs = interfaces != null && interfaces.size() > 0 ? interfaces.toArray(new Class[interfaces.size()]) : new Class[0];
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.plugin.core.systemservice;
2+
3+
import android.app.ActivityManager;
4+
import android.app.NotificationManager;
5+
import android.os.Debug;
6+
import android.os.RemoteException;
7+
import android.os.UserHandle;
8+
9+
import com.plugin.core.proxy.MethodDelegate;
10+
import com.plugin.core.proxy.MethodProxy;
11+
import com.plugin.core.proxy.ProxyUtil;
12+
import com.plugin.util.LogUtil;
13+
import com.plugin.util.RefInvoker;
14+
15+
import java.lang.reflect.Method;
16+
import java.util.List;
17+
18+
/**
19+
* Created by cailiming on 16/1/15.
20+
*/
21+
public class AndroidAppIActivityManager extends MethodProxy {
22+
23+
private AndroidAppIActivityManager() {
24+
}
25+
26+
public static void installProxy(ActivityManager manager) {
27+
Object androidAppIActivityManagerStubProxy = RefInvoker.invokeStaticMethod("android.app.ActivityManagerNative", "getDefault", (Class[])null, (Object[])null);
28+
Object androidAppIActivityManagerStubProxyProxy = ProxyUtil.createProxy(androidAppIActivityManagerStubProxy, new AndroidAppIActivityManager());
29+
RefInvoker.setStaticOjbect("android.app.ActivityManagerNative", "gDefault", androidAppIActivityManagerStubProxyProxy);
30+
}
31+
32+
static {
33+
sMethods.put("getRunningAppProcesses", new getRunningAppProcesses());
34+
sMethods.put("killBackgroundProcesses", new killBackgroundProcesses());
35+
sMethods.put("getRunningServices", new getRunningServices());
36+
}
37+
38+
//public List<RunningAppProcessInfo> getRunningAppProcesses()
39+
public static class getRunningAppProcesses extends MethodDelegate {
40+
@Override
41+
public boolean beforeInvoke(Object target, Method method, Object[] args) {
42+
LogUtil.e("beforeInvoke", method.getName());
43+
//TODO
44+
return super.beforeInvoke(target, method, args);
45+
}
46+
}
47+
48+
//public void killBackgroundProcesses(String packageName)
49+
public static class killBackgroundProcesses extends MethodDelegate {
50+
@Override
51+
public boolean beforeInvoke(Object target, Method method, Object[] args) {
52+
LogUtil.e("beforeInvoke", method.getName());
53+
//TODO
54+
return super.beforeInvoke(target, method, args);
55+
}
56+
}
57+
58+
//public List<RunningServiceInfo> getRunningServices(int maxNum)
59+
public static class getRunningServices extends MethodDelegate {
60+
@Override
61+
public boolean beforeInvoke(Object target, Method method, Object[] args) {
62+
LogUtil.e("beforeInvoke", method.getName());
63+
//TODO
64+
return super.beforeInvoke(target, method, args);
65+
}
66+
}
67+
68+
69+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.plugin.core.systemservice;
2+
3+
import android.app.NotificationManager;
4+
5+
import com.plugin.core.proxy.MethodDelegate;
6+
import com.plugin.core.proxy.MethodProxy;
7+
import com.plugin.core.proxy.ProxyUtil;
8+
import com.plugin.util.LogUtil;
9+
import com.plugin.util.RefInvoker;
10+
11+
import java.lang.reflect.Method;
12+
13+
/**
14+
* Created by cailiming on 16/1/15.
15+
*/
16+
public class AndroidAppINotificationManager extends MethodProxy {
17+
18+
private AndroidAppINotificationManager() {
19+
}
20+
21+
public static void installProxy(NotificationManager manager) {
22+
Object androidAppINotificationStubProxy = RefInvoker.invokeStaticMethod(NotificationManager.class.getName(), "getService", (Class[])null, (Object[])null);
23+
Object androidAppINotificationStubProxyProxy = ProxyUtil.createProxy(androidAppINotificationStubProxy, new AndroidAppINotificationManager());
24+
RefInvoker.setStaticOjbect(NotificationManager.class.getName(), "sService", androidAppINotificationStubProxyProxy);
25+
}
26+
27+
static {
28+
sMethods.put("enqueueNotification", new enqueueNotification());
29+
sMethods.put("enqueueNotificationWithTag", new enqueueNotificationWithTag());
30+
sMethods.put("enqueueNotificationWithTagPriority", new enqueueNotificationWithTagPriority());
31+
}
32+
33+
public static class enqueueNotification extends MethodDelegate {
34+
@Override
35+
public boolean beforeInvoke(Object target, Method method, Object[] args) {
36+
LogUtil.e("beforeInvoke", method.getName());
37+
//TODO
38+
return super.beforeInvoke(target, method, args);
39+
}
40+
}
41+
42+
public static class enqueueNotificationWithTag extends MethodDelegate {
43+
@Override
44+
public boolean beforeInvoke(Object target, Method method, Object[] args) {
45+
LogUtil.e("beforeInvoke", method.getName());
46+
//TODO
47+
return super.beforeInvoke(target, method, args);
48+
}
49+
}
50+
51+
public static class enqueueNotificationWithTagPriority extends MethodDelegate {
52+
@Override
53+
public boolean beforeInvoke(Object target, Method method, Object[] args) {
54+
LogUtil.e("beforeInvoke", method.getName());
55+
//TODO
56+
return super.beforeInvoke(target, method, args);
57+
}
58+
}
59+
60+
}

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

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

0 commit comments

Comments
 (0)