Commit 98696c53 by sikang

remove SD appList

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