-
Notifications
You must be signed in to change notification settings - Fork 8
/
PreventRunning.java
161 lines (137 loc) · 5.12 KB
/
PreventRunning.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package me.piebridge.prevent.framework;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageParser;
import android.net.Uri;
import java.util.Set;
import com.android.server.am.PreventRunningHook;
import me.piebridge.prevent.BuildConfig;
import me.piebridge.prevent.framework.util.BroadcastFilterUtils;
import me.piebridge.prevent.framework.util.LogcatUtils;
import me.piebridge.prevent.framework.util.SafeActionUtils;
/**
* Created by thom on 15/10/27.
*/
public class PreventRunning implements PreventRunningHook {
private final ThreadLocal<String> mSender;
public PreventRunning() {
mSender = new ThreadLocal<String>();
PreventLog.i("prevent running " + BuildConfig.VERSION_NAME);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
SystemHook.setClassLoader(classLoader);
LogcatUtils.logcat(LogcatUtils.BOOT, "*:v");
}
@Override
public void setSender(String sender) {
if (SystemHook.isSupported()) {
mSender.set(sender);
}
}
@Override
public void onBroadcastIntent(Intent intent) {
if (SystemHook.isSupported()) {
String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
SafeActionUtils.updateWidget(intent.getComponent(), true);
} else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
SafeActionUtils.updateWidget(intent.getComponent(), false);
}
}
}
@Override
public void onCleanUpRemovedTask(String packageName) {
if (SystemHook.isSupported()) {
ActivityManagerServiceHook.onCleanUpRemovedTask(packageName);
}
}
@Override
public void onStartHomeActivity(String packageName) {
if (SystemHook.isSupported()) {
SystemHook.onStartHomeActivity(packageName);
}
}
@Override
public void onMoveActivityTaskToBack(String packageName) {
if (SystemHook.isSupported()) {
SystemHook.onMoveActivityToBack(packageName);
}
}
@Override
public void onAppDied(Object processRecord) {
if (SystemHook.isSupported()) {
SystemHook.onAppDied(processRecord);
}
}
@Override
public void onLaunchActivity(Object activityRecord) {
if (SystemHook.isSupported()) {
SystemHook.onLaunchActivity(activityRecord);
}
}
@Override
public void onResumeActivity(Object activityRecord) {
if (SystemHook.isSupported()) {
SystemHook.onResumeActivity(activityRecord);
}
}
@Override
public void onUserLeavingActivity(Object activityRecord) {
if (SystemHook.isSupported()) {
SystemHook.onUserLeavingActivity(activityRecord);
}
}
@Override
public void onDestroyActivity(Object activityRecord) {
if (SystemHook.isSupported()) {
SystemHook.onDestroyActivity(activityRecord);
}
}
@Override
public boolean isExcludingStopped(String action) {
return !SystemHook.isSupported() || !SafeActionUtils.isSafeAction(action);
}
@Override
public boolean hookStartProcessLocked(Context context, ApplicationInfo info, String hostingType, ComponentName hostingName) {
return !SystemHook.isSupported() || ActivityManagerServiceHook.hookStartProcessLocked(context, info, hostingType, hostingName, mSender.get());
}
@Override
public int match(int match, Object filter, String action, String type, String scheme, Uri data, Set<String> categories) {
if (SystemHook.isSupported() && IntentFilterHook.canHook(match)) {
IntentFilterMatchResult result;
if (filter instanceof PackageParser.ActivityIntentInfo) {
result = IntentFilterHook.hookActivityIntentInfo((PackageParser.ActivityIntentInfo) filter, mSender.get(), action);
} else if (filter instanceof PackageParser.ServiceIntentInfo) {
result = IntentFilterHook.hookServiceIntentInfo((PackageParser.ServiceIntentInfo) filter, mSender.get(), action);
} else if (BroadcastFilterUtils.isBroadcastFilter(filter)) {
result = IntentFilterHook.hookBroadcastFilter(filter, action, data, categories);
} else {
result = IntentFilterMatchResult.NONE;
}
if (!result.isNone()) {
return result.getResult();
}
}
return match;
}
@Override
public void setVersion(int version) {
PreventLog.d("bridge version: " + version);
SystemHook.setVersion(version);
}
@Override
public void setMethod(String method) {
PreventLog.d("bridge method: " + method);
SystemHook.setMethod(method);
}
@Override
public boolean hookBindService(Intent service) {
return true;
}
@Override
public boolean hookStartService(Intent service) {
return true;
}
}