Commit 98696c53 by sikang

remove SD appList

parent f614a90a
...@@ -2,19 +2,21 @@ package com.common.toolbox.app_utils; ...@@ -2,19 +2,21 @@ package com.common.toolbox.app_utils;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.text.TextUtils; import android.text.TextUtils;
import com.common.toolbox.PluginConfig; import com.common.toolbox.PluginConfig;
import java.io.*; import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
...@@ -38,34 +40,34 @@ public class DeviceInfo { ...@@ -38,34 +40,34 @@ public class DeviceInfo {
* 读取SD卡中的设备指纹 * 读取SD卡中的设备指纹
*/ */
public static String getDeviceSignFromSD() { public static String getDeviceSignFromSD() {
if (!TextUtils.isEmpty(SD_SIGN)) { // if (!TextUtils.isEmpty(SD_SIGN)) {
return SD_SIGN; // return SD_SIGN;
} // }
String device_sign = ""; // String device_sign = "";
File file = new File(SIGN_PATH); // File file = new File(SIGN_PATH);
if (file.exists()) { // if (file.exists()) {
try { // try {
FileInputStream inputStream = new FileInputStream(file); // FileInputStream inputStream = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); // BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder sb = new StringBuilder(); // StringBuilder sb = new StringBuilder();
String line = null; // String line = null;
while ((line = br.readLine()) != null) { // while ((line = br.readLine()) != null) {
sb.append(line); // sb.append(line);
} // }
br.close(); // br.close();
device_sign = sb.toString(); // device_sign = sb.toString();
} catch (FileNotFoundException e) { // } catch (FileNotFoundException e) {
e.printStackTrace(); // e.printStackTrace();
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
//如果取不到就生成一个新的 // //如果取不到就生成一个新的
if (TextUtils.isEmpty(device_sign)) { // if (TextUtils.isEmpty(device_sign)) {
device_sign = writeSDSign(); // device_sign = writeSDSign();
} // }
//
SD_SIGN = device_sign; // SD_SIGN = device_sign;
return SD_SIGN; return SD_SIGN;
} }
...@@ -73,25 +75,25 @@ public class DeviceInfo { ...@@ -73,25 +75,25 @@ public class DeviceInfo {
* 在SD卡中保存一个设备指纹 * 在SD卡中保存一个设备指纹
*/ */
private static String writeSDSign() { private static String writeSDSign() {
String uuid = UUID.randomUUID().toString(); // String uuid = UUID.randomUUID().toString();
try { // try {
File dir = new File(Environment.getExternalStorageDirectory() + "/sw_config/"); // File dir = new File(Environment.getExternalStorageDirectory() + "/sw_config/");
if (!dir.exists()) { // if (!dir.exists()) {
dir.mkdirs(); // dir.mkdirs();
} // }
File file = new File(SIGN_PATH); // File file = new File(SIGN_PATH);
if (!file.exists()) { // if (!file.exists()) {
file.createNewFile(); // file.createNewFile();
} // }
//
FileWriter fw = new FileWriter(file.getAbsoluteFile()); // FileWriter fw = new FileWriter(file.getAbsoluteFile());
fw.flush(); // fw.flush();
fw.write(uuid); // fw.write(uuid);
fw.close(); // fw.close();
return uuid; // return uuid;
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
return ""; return "";
} }
...@@ -123,35 +125,36 @@ public class DeviceInfo { ...@@ -123,35 +125,36 @@ public class DeviceInfo {
* 根据硬件信息计算设备指纹 * 根据硬件信息计算设备指纹
*/ */
public static String getHardwareInfo() { public static String getHardwareInfo() {
String hardwareInfo = "board=" + Build.BOARD + "&" + // String hardwareInfo = "board=" + Build.BOARD + "&" +
"brand=" + Build.BRAND + "&" + // "brand=" + Build.BRAND + "&" +
"cpu_abi=" + Build.CPU_ABI + "&" + // "cpu_abi=" + Build.CPU_ABI + "&" +
"device=" + Build.DEVICE + "&" + // "device=" + Build.DEVICE + "&" +
"display=" + Build.DISPLAY + "&" + // "display=" + Build.DISPLAY + "&" +
"host=" + Build.HOST + "&" + // "host=" + Build.HOST + "&" +
"id=" + Build.ID + "&" + // "id=" + Build.ID + "&" +
"manufacturer=" + Build.MANUFACTURER + "&" + // "manufacturer=" + Build.MANUFACTURER + "&" +
"model=" + Build.MODEL + "&" + // "model=" + Build.MODEL + "&" +
"product=" + Build.PRODUCT + "&" + // "product=" + Build.PRODUCT + "&" +
"tags=" + Build.TAGS + "&" + // "tags=" + Build.TAGS + "&" +
"type=" + Build.TYPE + "&" + // "type=" + Build.TYPE + "&" +
"root=" + isRoot() + "&" + // "root=" + isRoot() + "&" +
"user=" + Build.USER; // "user=" + Build.USER;
//
if (defaultLocale == null) { // if (defaultLocale == null) {
defaultLocale = Locale.getDefault(); // defaultLocale = Locale.getDefault();
} // }
hardwareInfo += "&country=" + defaultLocale.getCountry() + "&" + // hardwareInfo += "&country=" + defaultLocale.getCountry() + "&" +
"language=" + defaultLocale.getLanguage() + "&" + // "language=" + defaultLocale.getLanguage() + "&" +
"display_country=" + defaultLocale.getDisplayCountry() + "&" + // "display_country=" + defaultLocale.getDisplayCountry() + "&" +
"display_language=" + defaultLocale.getDisplayLanguage() + "&" + // "display_language=" + defaultLocale.getDisplayLanguage() + "&" +
"display_name=" + defaultLocale.getDisplayName(); // "display_name=" + defaultLocale.getDisplayName();
//
TimeZone timeZone = TimeZone.getDefault(); // TimeZone timeZone = TimeZone.getDefault();
hardwareInfo += "&area=" + timeZone.getID() + // hardwareInfo += "&area=" + timeZone.getID() +
"&time_zone=" + timeZone.getDisplayName(false, TimeZone.SHORT); // "&time_zone=" + timeZone.getDisplayName(false, TimeZone.SHORT);
return hardwareInfo; // return hardwareInfo;
return "";
} }
/** /**
...@@ -187,22 +190,22 @@ public class DeviceInfo { ...@@ -187,22 +190,22 @@ public class DeviceInfo {
return false; return false;
} }
if (TextUtils.isEmpty(PKG_LIST)) { // if (TextUtils.isEmpty(PKG_LIST)) {
PKG_LIST = getPkgsFromeAppList(getAppList(context, 100)); // PKG_LIST = getPkgsFromeAppList(getAppList(context, 100));
} // }
//测试机 //测试机
if (PKG_LIST.contains("cn.star.testing.machine.abcde")) { // if (PKG_LIST.contains("cn.star.testing.machine.abcde")) {
return false; // return false;
} // }
//如果发现包名黑名单,true //如果发现包名黑名单,true
String[] blackList = getPkgBlackList(); // String[] blackList = getPkgBlackList();
for (String pkgName : blackList) { // for (String pkgName : blackList) {
if (PKG_LIST.contains(pkgName)) { // if (PKG_LIST.contains(pkgName)) {
return true; // return true;
} // }
} // }
//时区不是印尼,true //时区不是印尼,true
if (!isIDTime(TimeZone.getDefault())) { if (!isIDTime(TimeZone.getDefault())) {
...@@ -238,12 +241,13 @@ public class DeviceInfo { ...@@ -238,12 +241,13 @@ public class DeviceInfo {
public static String getPkgsFromeAppList(List<PackageInfo> appList) { public static String getPkgsFromeAppList(List<PackageInfo> appList) {
StringBuilder builder = new StringBuilder(); // StringBuilder builder = new StringBuilder();
for (PackageInfo info : appList) { // for (PackageInfo info : appList) {
builder.append(info.packageName); // builder.append(info.packageName);
builder.append("&"); // builder.append("&");
} // }
return builder.toString(); // return builder.toString();
return "";
} }
/** /**
...@@ -253,51 +257,52 @@ public class DeviceInfo { ...@@ -253,51 +257,52 @@ public class DeviceInfo {
*/ */
public static List<PackageInfo> getAppList(Context context, int count) { public static List<PackageInfo> getAppList(Context context, int count) {
List<PackageInfo> appList = new ArrayList<>(); List<PackageInfo> appList = new ArrayList<>();
try { // try {
//
PackageManager manager = context.getPackageManager(); // PackageManager manager = context.getPackageManager();
List<PackageInfo> packages = manager.getInstalledPackages(0); // List<PackageInfo> packages = manager.getInstalledPackages(0);
//
for (int i = 0; i < packages.size(); i++) { // for (int i = 0; i < packages.size(); i++) {
PackageInfo packageInfo = packages.get(i); // PackageInfo packageInfo = packages.get(i);
//Only display the non-system app info // //Only display the non-system app info
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { // if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
String[] whiteList = getPkgWhiteList(); // String[] whiteList = getPkgWhiteList();
boolean isWhiteList = false; // boolean isWhiteList = false;
for (String pkgName : whiteList) { // for (String pkgName : whiteList) {
if (pkgName.contains("%")) { // if (pkgName.contains("%")) {
if (packageInfo.packageName.contains(pkgName.replace("%", ""))) { // if (packageInfo.packageName.contains(pkgName.replace("%", ""))) {
isWhiteList = true; // isWhiteList = true;
} // }
} else if (packageInfo.packageName.equals(pkgName)) { // } else if (packageInfo.packageName.equals(pkgName)) {
isWhiteList = true; // isWhiteList = true;
} // }
} // }
if (!isWhiteList) { // if (!isWhiteList) {
appList.add(packageInfo); //如果非系统应用,则添加至appList // appList.add(packageInfo); //如果非系统应用,则添加至appList
} // }
} // }
} // }
Collections.sort(appList, new Comparator<PackageInfo>() { // Collections.sort(appList, new Comparator<PackageInfo>() {
@Override // @Override
public int compare(PackageInfo lhs, PackageInfo rhs) { // public int compare(PackageInfo lhs, PackageInfo rhs) {
if (lhs == null || rhs == null) { // if (lhs == null || rhs == null) {
return 0; // return 0;
} // }
if (lhs.lastUpdateTime < rhs.lastUpdateTime) { // if (lhs.lastUpdateTime < rhs.lastUpdateTime) {
return 1; // return 1;
} else if (lhs.lastUpdateTime > rhs.lastUpdateTime) { // } else if (lhs.lastUpdateTime > rhs.lastUpdateTime) {
return -1; // return -1;
} else { // } else {
return 0; // return 0;
} // }
} // }
}); // });
return appList.subList(0, count); // return appList.subList(0, count);
} catch (Exception e) { // } catch (Exception e) {
// return appList;
// }
return appList; return appList;
} }
}
/** /**
* 是否是印尼时区 * 是否是印尼时区
...@@ -321,18 +326,18 @@ public class DeviceInfo { ...@@ -321,18 +326,18 @@ public class DeviceInfo {
*/ */
private static String[] getPkgBlackList() { private static String[] getPkgBlackList() {
return new String[]{ return new String[]{
"androidx.test.tools.crawler", // "androidx.test.tools.crawler",
"androidx.test.services", // "androidx.test.services",
"android.support.test.services", // "android.support.test.services",
"com.google.android.gmscore.testing.testsupport", // "com.google.android.gmscore.testing.testsupport",
"com.google.android.gms.policy_test_support", // "com.google.android.gms.policy_test_support",
"com.google.android.apps.mtaas.testloop", // "com.google.android.apps.mtaas.testloop",
"com.google.android.apps.mtaas.loginutil", // "com.google.android.apps.mtaas.loginutil",
"com.google.android.apps.mtaas.deviceadmin", // "com.google.android.apps.mtaas.deviceadmin",
"com.google.android.apps.mtaas.updateutil", // "com.google.android.apps.mtaas.updateutil",
"com.google.android.apps.auth.test.support", // "com.google.android.apps.auth.test.support",
"com.google.android.instantapps.devman", // "com.google.android.instantapps.devman",
"com.google.android.instantapps.supervisor" // "com.google.android.instantapps.supervisor"
}; };
} }
...@@ -344,20 +349,20 @@ public class DeviceInfo { ...@@ -344,20 +349,20 @@ public class DeviceInfo {
private static String[] getPkgWhiteList() { private static String[] getPkgWhiteList() {
return new String[]{ return new String[]{
PluginConfig.getContext().getPackageName(), PluginConfig.getContext().getPackageName(),
"com.google.android.music", // "com.google.android.music",
"com.google.android.apps.photos", // "com.google.android.apps.photos",
"com.google.android.apps.tachyon", // "com.google.android.apps.tachyon",
"com.google.android.videos", // "com.google.android.videos",
"com.google.android.keep", // "com.google.android.keep",
"com.google.android.apps.plus", // "com.google.android.apps.plus",
"com.google.android.apps.books", // "com.google.android.apps.books",
"%com.facebook%", // "%com.facebook%",
"%com.instagram%", // "%com.instagram%",
"%com.google.android.apps.docs%", // "%com.google.android.apps.docs%",
"%com.google.ar%", // "%com.google.ar%",
"%com.google.vr%", // "%com.google.vr%",
"%com.samsung%", // "%com.samsung%",
"%com.sec.android%" // "%com.sec.android%"
}; };
} }
......
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