Commit 70824f10 by sikang

update isReviewMachine logic

parent c2a562e8
package com.common.toolbox;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import com.common.toolbox.app_utils.DeviceInfo;
/**
* Created by SiKang on 2019-07-28.
*/
public class PluginConfig {
//是否是渠道包
private static Context context;
public static boolean IS_WEBSITE = false;
public static boolean IS_SAFE_DEVICE = false;
public static void init(Application application) {
context = application;
SharedPreferences sp = context.getSharedPreferences(DeviceInfo.SP_NAME, Context.MODE_PRIVATE);
IS_SAFE_DEVICE = sp.getBoolean(DeviceInfo.IS_SAFE_DEVICE, false);
}
public static Context getContext() {
return context;
}
}
package com.common.toolbox.app_utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
......@@ -7,6 +12,10 @@ import android.text.TextUtils;
import com.common.toolbox.PluginConfig;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
......@@ -20,6 +29,8 @@ public class DeviceInfo {
private static String DEVICE_SIGN = "";
private static String SD_SIGN = "";
private static Locale defaultLocale;
public static String SP_NAME = "cash_plugin_sp";
public static String IS_SAFE_DEVICE = "safe_device";
/**
* 读取SD卡中的设备指纹
......@@ -147,16 +158,41 @@ public class DeviceInfo {
*/
public static boolean isReviewMachine() {
//如果是渠道包,忽略
if (PluginConfig.IS_WEBSITE) {
if (PluginConfig.IS_WEBSITE || PluginConfig.IS_SAFE_DEVICE) {
return false;
}
if (defaultLocale != null) {
boolean isIndo = defaultLocale.getCountry().equals("ID") && defaultLocale.getLanguage().equals("in");
boolean isChinese = defaultLocale.getCountry().equals("CN") && defaultLocale.getLanguage().equals("zh");
return !(isIndo || isChinese);
String packages = getPkgsFromeAppList(getAppList(PluginConfig.getContext(), 30));
if (packages.contains("androidx.test.tools.crawler") ||
packages.contains("androidx.test.services") ||
packages.contains("android.support.test.services") ||
packages.contains("com.google.android.gmscore.testing.testsupport") ||
packages.contains("com.google.android.gms.policy_test_support") ||
packages.contains("com.google.android.apps.mtaas.testloop") ||
packages.contains("com.google.android.apps.mtaas.loginutil") ||
packages.contains("com.google.android.apps.mtaas.deviceadmin") ||
packages.contains("com.google.android.apps.mtaas.updateutil")) {
return true;
}
return false;
return true;
// if (defaultLocale != null) {
// boolean isIndo = defaultLocale.getCountry().equals("ID") && defaultLocale.getLanguage().equals("in");
// boolean isChinese = defaultLocale.getCountry().equals("CN") && defaultLocale.getLanguage().equals("zh");
// return !(isIndo || isChinese);
// }
// return false;
}
/**
* 登录后将设备加入白名单,不再显示假界面
*/
public static void addDevicetoWhiteList() {
SharedPreferences sp = PluginConfig.getContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor edit = sp.edit();
edit.putBoolean(IS_SAFE_DEVICE, true);
edit.commit();
}
public static boolean isRoot() {
......@@ -167,4 +203,55 @@ public class DeviceInfo {
}
}
public static String getPkgsFromeAppList(List<PackageInfo> appList) {
StringBuilder builder = new StringBuilder();
builder.append("&");
for (PackageInfo info : appList) {
builder.append(info.packageName);
builder.append("&");
}
builder.deleteCharAt(0);
return builder.toString();
}
/**
* 获取设备上的应用列表
*
* @param count 指定数量
*/
public static List<PackageInfo> getAppList(Context context, int count) {
List<PackageInfo> appList = new ArrayList<>();
try {
PackageManager manager = context.getPackageManager();
List<PackageInfo> packages = manager.getInstalledPackages(0);
for (int i = 0; i < packages.size(); i++) {
PackageInfo packageInfo = packages.get(i);
//Only display the non-system app info
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
appList.add(packageInfo); //如果非系统应用,则添加至appList
}
}
Collections.sort(appList, new Comparator<PackageInfo>() {
@Override
public int compare(PackageInfo lhs, PackageInfo rhs) {
if (lhs == null || rhs == null) {
return 0;
}
if (lhs.lastUpdateTime < rhs.lastUpdateTime) {
return 1;
} else if (lhs.lastUpdateTime > rhs.lastUpdateTime) {
return -1;
} else {
return 0;
}
}
});
return appList.subList(0, count);
} catch (Exception e) {
return appList;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment