forked from M66B/XPrivacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequirements.java
442 lines (406 loc) · 17.2 KB
/
Requirements.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
package biz.bokhorst.xprivacy;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InterfaceAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.location.GpsStatus;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.os.Build;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
public class Requirements {
private static String[] cIncompatible = new String[] { "com.lbe.security" };
@SuppressWarnings("unchecked")
public static void check(final ActivityBase context) {
// Check Android version
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(R.string.app_name);
alertDialogBuilder.setMessage(R.string.app_wrongandroid);
alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent androidIntent = new Intent(Intent.ACTION_VIEW);
androidIntent.setData(Uri.parse("https://github.com/M66B/XPrivacy#installation"));
context.startActivity(androidIntent);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
// Check if XPrivacy is enabled
if (Util.isXposedEnabled()) {
// Check privacy client
try {
if (PrivacyService.checkClient()) {
List<String> listError = (List<String>) PrivacyService.getClient().check();
if (listError.size() > 0)
sendSupportInfo(TextUtils.join("\r\n", listError), context);
}
} catch (Throwable ex) {
sendSupportInfo(ex.toString(), context);
}
} else {
// @formatter:off
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(R.string.app_name);
alertDialogBuilder.setMessage(R.string.app_notenabled);
alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent xInstallerIntent = new Intent("de.robv.android.xposed.installer.OPEN_SECTION")
.setPackage("de.robv.android.xposed.installer")
.putExtra("section", "modules")
.putExtra("module", context.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(xInstallerIntent);
}
});
// @formatter:on
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
// Check pro enabler
Version version = Util.getProEnablerVersion(context);
if (version != null && !Util.isValidProEnablerVersion(version)) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(R.string.app_name);
alertDialogBuilder.setMessage(R.string.app_wrongenabler);
alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent storeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="
+ context.getPackageName() + ".pro"));
context.startActivity(storeIntent);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
// Check incompatible apps
checkCompatibility(context);
// Check activity thread
try {
Class<?> clazz = Class.forName("android.app.ActivityThread", false, null);
try {
clazz.getDeclaredMethod("unscheduleGcIdler");
} catch (NoSuchMethodException ex) {
reportClass(clazz, context);
}
} catch (ClassNotFoundException ex) {
sendSupportInfo(ex.toString(), context);
}
// Check activity thread receiver data
try {
Class<?> clazz = Class.forName("android.app.ActivityThread$ReceiverData", false, null);
if (!checkField(clazz, "intent"))
reportClass(clazz, context);
} catch (ClassNotFoundException ex) {
try {
reportClass(Class.forName("android.app.ActivityThread", false, null), context);
} catch (ClassNotFoundException exex) {
sendSupportInfo(exex.toString(), context);
}
}
// Check file utils
try {
Class<?> clazz = Class.forName("android.os.FileUtils", false, null);
try {
clazz.getDeclaredMethod("setPermissions", String.class, int.class, int.class, int.class);
} catch (NoSuchMethodException ex) {
reportClass(clazz, context);
}
} catch (ClassNotFoundException ex) {
sendSupportInfo(ex.toString(), context);
}
// Check interface address
if (!checkField(InterfaceAddress.class, "address") || !checkField(InterfaceAddress.class, "broadcastAddress")
|| (PrivacyService.getClient() != null && PrivacyManager.getDefacedProp(0, "InetAddress") == null))
reportClass(InterfaceAddress.class, context);
// Check package manager service
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
try {
Class<?> clazz = Class.forName("com.android.server.pm.PackageManagerService", false, null);
try {
try {
clazz.getDeclaredMethod("getPackageUid", String.class, int.class);
} catch (NoSuchMethodException ignored) {
clazz.getDeclaredMethod("getPackageUid", String.class);
}
} catch (NoSuchMethodException ex) {
reportClass(clazz, context);
}
} catch (ClassNotFoundException ex) {
sendSupportInfo(ex.toString(), context);
}
// Check GPS status
if (!checkField(GpsStatus.class, "mSatellites"))
reportClass(GpsStatus.class, context);
// Check service manager
try {
Class<?> clazz = Class.forName("android.os.ServiceManager", false, null);
try {
// @formatter:off
// public static void addService(String name, IBinder service)
// public static void addService(String name, IBinder service, boolean allowIsolated)
// public static String[] listServices()
// public static IBinder checkService(String name)
// @formatter:on
Method listServices = clazz.getDeclaredMethod("listServices");
Method getService = clazz.getDeclaredMethod("getService", String.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
clazz.getDeclaredMethod("addService", String.class, IBinder.class, boolean.class);
else
clazz.getDeclaredMethod("addService", String.class, IBinder.class);
// Get services
Map<String, String> mapService = new HashMap<String, String>();
String[] services = (String[]) listServices.invoke(null);
if (services != null)
for (String service : services)
if (service != null) {
IBinder binder = (IBinder) getService.invoke(null, service);
String descriptor = (binder == null ? null : binder.getInterfaceDescriptor());
mapService.put(service, descriptor);
}
if (mapService.size() > 0) {
// Check services
int i = 0;
List<String> listMissing = new ArrayList<String>();
for (String name : XBinder.cServiceName) {
String descriptor = XBinder.cServiceDescriptor.get(i++);
if (descriptor != null && !XBinder.cServiceOptional.contains(name)) {
// Check name
boolean checkDescriptor = false;
if (name.equals("telephony.registry")) {
if (mapService.containsKey(name))
checkDescriptor = true;
else if (!mapService.containsKey("telephony.msim.registry"))
listMissing.add(name);
} else if (name.equals("telephony.msim.registry")) {
if (mapService.containsKey(name))
checkDescriptor = true;
else if (!mapService.containsKey("telephony.registry"))
listMissing.add(name);
} else if (name.equals("bluetooth")) {
if (mapService.containsKey(name))
checkDescriptor = true;
else if (!mapService.containsKey("bluetooth_manager"))
listMissing.add(name);
} else if (name.equals("bluetooth_manager")) {
if (mapService.containsKey(name))
checkDescriptor = true;
else if (!mapService.containsKey("bluetooth"))
listMissing.add(name);
} else {
if (mapService.containsKey(name))
checkDescriptor = true;
else
listMissing.add(name);
}
// Check descriptor
if (checkDescriptor) {
String d = mapService.get(name);
if (d != null && !d.equals(descriptor))
listMissing.add(descriptor);
}
}
}
// Check result
if (listMissing.size() > 0) {
List<String> listService = new ArrayList<String>();
for (String service : mapService.keySet())
listService.add(String.format("%s: %s", service, mapService.get(service)));
sendSupportInfo("Missing:\r\n" + TextUtils.join("\r\n", listMissing) + "\r\n\r\nAvailable:\r\n"
+ TextUtils.join("\r\n", listService), context);
}
}
} catch (NoSuchMethodException ex) {
reportClass(clazz, context);
} catch (Throwable ex) {
Util.bug(null, ex);
}
} catch (ClassNotFoundException ex) {
sendSupportInfo(ex.toString(), context);
}
// Check wifi info
if (!checkField(WifiInfo.class, "mSupplicantState") || !checkField(WifiInfo.class, "mBSSID")
|| !checkField(WifiInfo.class, "mIpAddress") || !checkField(WifiInfo.class, "mMacAddress")
|| !(checkField(WifiInfo.class, "mSSID") || checkField(WifiInfo.class, "mWifiSsid")))
reportClass(WifiInfo.class, context);
// Check mWifiSsid.octets
if (checkField(WifiInfo.class, "mWifiSsid"))
try {
Class<?> clazz = Class.forName("android.net.wifi.WifiSsid", false, null);
try {
clazz.getDeclaredMethod("createFromAsciiEncoded", String.class);
} catch (NoSuchMethodException ex) {
reportClass(clazz, context);
}
} catch (ClassNotFoundException ex) {
sendSupportInfo(ex.toString(), context);
}
// Check Inet4Address/ANY
try {
Inet4Address.class.getDeclaredField("ANY");
} catch (Throwable ex) {
reportClass(Inet4Address.class, context);
}
// Check context services
checkService(context, Context.ACCOUNT_SERVICE,
new String[] { "android.accounts.AccountManager", "com.intel.arkham.ExtendAccountManager" /* Asus */,
"android.privacy.surrogate.PrivacyAccountManager" /* PDroid */});
checkService(context, Context.ACTIVITY_SERVICE, new String[] { "android.app.ActivityManager",
"android.app.ActivityManagerEx" });
checkService(context, Context.CLIPBOARD_SERVICE, new String[] { "android.content.ClipboardManager" });
checkService(context, Context.CONNECTIVITY_SERVICE, new String[] { "android.net.ConnectivityManager",
"android.net.ConnectivityManagerEx", "android.net.MultiSimConnectivityManager",
"android.privacy.surrogate.PrivacyConnectivityManager" /* PDroid */});
checkService(context, Context.LOCATION_SERVICE,
new String[] { "android.location.LocationManager", "android.location.ZTEPrivacyLocationManager",
"android.privacy.surrogate.PrivacyLocationManager" /* PDroid */});
Class<?> serviceClass = context.getPackageManager().getClass();
if (!"android.app.ApplicationPackageManager".equals(serviceClass.getName())
&& !"amazon.content.pm.AmazonPackageManagerImpl".equals(serviceClass.getName()))
reportClass(serviceClass, context);
checkService(context, Context.SENSOR_SERVICE, new String[] { "android.hardware.SensorManager",
"android.hardware.SystemSensorManager" });
checkService(context, Context.TELEPHONY_SERVICE, new String[] { "android.telephony.TelephonyManager",
"android.telephony.MSimTelephonyManager", "android.telephony.MultiSimTelephonyManager",
"android.telephony.ZTEPrivacyTelephonyManager", "android.telephony.ZTEPrivacyMSimTelephonyManager",
"com.motorola.android.telephony.MotoTelephonyManager",
"android.privacy.surrogate.PrivacyTelephonyManager" /* PDroid */});
checkService(context, Context.WINDOW_SERVICE, new String[] { "android.view.WindowManagerImpl",
"android.view.Window$LocalWindowManager", "amazon.view.AmazonWindowManagerImpl" });
checkService(context, Context.WIFI_SERVICE, new String[] { "android.net.wifi.WifiManager",
"com.amazon.net.AmazonWifiManager", "com.amazon.android.service.AmazonWifiManager",
"android.privacy.surrogate.PrivacyWifiManager" /* PDroid */});
}
public static void checkService(ActivityBase context, String name, String[] className) {
Object service = context.getSystemService(name);
if (service == null)
sendSupportInfo("Service missing name=" + name, context);
else if (!Arrays.asList(className).contains(service.getClass().getName()))
reportClass(service.getClass(), context);
}
public static void checkCompatibility(ActivityBase context) {
for (String packageName : cIncompatible)
try {
ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
if (appInfo.enabled) {
String name = context.getPackageManager().getApplicationLabel(appInfo).toString();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(R.string.app_name);
alertDialogBuilder.setMessage(String.format(context.getString(R.string.app_incompatible), name));
alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
} catch (NameNotFoundException ex) {
}
}
private static boolean checkField(Class<?> clazz, String fieldName) {
try {
clazz.getDeclaredField(fieldName);
return true;
} catch (NoSuchFieldException ex) {
return false;
}
}
private static void reportClass(Class<?> clazz, ActivityBase context) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("Incompatible %s", clazz.getName()));
sb.append("\r\n");
sb.append("\r\n");
for (Constructor<?> constructor : clazz.getConstructors()) {
sb.append(constructor.toString());
sb.append("\r\n");
}
sb.append("\r\n");
for (Method method : clazz.getDeclaredMethods()) {
sb.append(method.toString());
sb.append("\r\n");
}
sb.append("\r\n");
for (Field field : clazz.getDeclaredFields()) {
sb.append(field.toString());
sb.append("\r\n");
}
sb.append("\r\n");
sendSupportInfo(sb.toString(), context);
}
public static void sendSupportInfo(final String text, final ActivityBase context) {
Util.log(null, Log.WARN, text);
if (Util.hasValidFingerPrint(context) && !"Genymotion".equals(Build.MANUFACTURER)) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle(R.string.app_name);
alertDialogBuilder.setMessage(R.string.msg_support_info);
alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int _which) {
String ourVersion = Util.getSelfVersionName(context);
StringBuilder sb = new StringBuilder(text);
sb.insert(0, "\r\n");
sb.insert(0, String.format("Id: %s\r\n", Build.ID));
sb.insert(0, String.format("Display: %s\r\n", Build.DISPLAY));
sb.insert(0, String.format("Host: %s\r\n", Build.HOST));
sb.insert(0, String.format("Device: %s\r\n", Build.DEVICE));
sb.insert(0, String.format("Product: %s\r\n", Build.PRODUCT));
sb.insert(0, String.format("Model: %s\r\n", Build.MODEL));
sb.insert(0, String.format("Manufacturer: %s\r\n", Build.MANUFACTURER));
sb.insert(0, String.format("Brand: %s\r\n", Build.BRAND));
sb.insert(0, "\r\n");
sb.insert(0, String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE,
Build.VERSION.SDK_INT));
sb.insert(0, String.format("XPrivacy: %s\r\n", ourVersion));
Intent sendEmail = new Intent(Intent.ACTION_SEND);
sendEmail.setType("message/rfc822");
sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
sendEmail.putExtra(Intent.EXTRA_SUBJECT, "XPrivacy " + ourVersion + "/"
+ Build.VERSION.RELEASE + " support info");
sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString());
try {
context.startActivity(sendEmail);
} catch (Throwable ex) {
Util.bug(null, ex);
}
}
});
alertDialogBuilder.setNegativeButton(context.getString(android.R.string.cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
}