Commit db6c1e31 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent c2d3d0db
...@@ -98,15 +98,15 @@ class DeviceInfo private constructor() { ...@@ -98,15 +98,15 @@ class DeviceInfo private constructor() {
var needSingleSim = false var needSingleSim = false
// 卡1 // 卡1
val simStateBySlotIdx1 = val simStateBySlotIdx1 =
SimUtils.getSimStateBySlotIdx(MintsApplication.getContext(), 0) SimUtils.getSimStateBySlotIdx(MintsApplication.getContext(), 0)
// 卡2 // 卡2
val simStateBySlotIdx2 = val simStateBySlotIdx2 =
SimUtils.getSimStateBySlotIdx(MintsApplication.getContext(), 1) SimUtils.getSimStateBySlotIdx(MintsApplication.getContext(), 1)
if (simStateBySlotIdx1) { if (simStateBySlotIdx1) {
val providersName1 = val providersName1 =
SimUtils.getSimOperatorName2(MintsApplication.getContext(), 0) SimUtils.getSimOperatorName2(MintsApplication.getContext(), 0)
if (TextUtils.equals(providersName1, "unknown")) { if (TextUtils.equals(providersName1, "unknown")) {
needSingleSim = true needSingleSim = true
...@@ -120,7 +120,7 @@ class DeviceInfo private constructor() { ...@@ -120,7 +120,7 @@ class DeviceInfo private constructor() {
if (simStateBySlotIdx2) { if (simStateBySlotIdx2) {
val providersName2 = val providersName2 =
SimUtils.getSimOperatorName2(MintsApplication.getContext(), 1) SimUtils.getSimOperatorName2(MintsApplication.getContext(), 1)
if (TextUtils.equals(providersName2, "unknown") && !needSingleSim) { if (TextUtils.equals(providersName2, "unknown") && !needSingleSim) {
sb.append(SimUtils.getSimOperatorNameBySingle(MintsApplication.getContext()) + " ") sb.append(SimUtils.getSimOperatorNameBySingle(MintsApplication.getContext()) + " ")
...@@ -185,7 +185,7 @@ class DeviceInfo private constructor() { ...@@ -185,7 +185,7 @@ class DeviceInfo private constructor() {
*/ */
val iMSI: String val iMSI: String
get() = (mContext get() = (mContext
?.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).subscriberId ?.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).subscriberId
/** /**
* get device's IMEI * get device's IMEI
...@@ -197,7 +197,7 @@ class DeviceInfo private constructor() { ...@@ -197,7 +197,7 @@ class DeviceInfo private constructor() {
var imei = "" var imei = ""
try { try {
imei = imei =
(mContext!!.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).deviceId (mContext!!.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).deviceId
} catch (e: Exception) { } catch (e: Exception) {
} }
return imei return imei
...@@ -247,7 +247,7 @@ class DeviceInfo private constructor() { ...@@ -247,7 +247,7 @@ class DeviceInfo private constructor() {
val isWifi: Boolean val isWifi: Boolean
get() { get() {
val connectivityManager = mContext val connectivityManager = mContext
?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager ?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetInfo = connectivityManager.activeNetworkInfo val activeNetInfo = connectivityManager.activeNetworkInfo
return (activeNetInfo != null return (activeNetInfo != null
&& activeNetInfo.type == ConnectivityManager.TYPE_WIFI) && activeNetInfo.type == ConnectivityManager.TYPE_WIFI)
...@@ -263,7 +263,7 @@ class DeviceInfo private constructor() { ...@@ -263,7 +263,7 @@ class DeviceInfo private constructor() {
var versionName = "1.0.0" var versionName = "1.0.0"
try { try {
versionName = mContext!!.packageManager.getPackageInfo( versionName = mContext!!.packageManager.getPackageInfo(
mContext!!.packageName, 0 mContext!!.packageName, 0
).versionName ).versionName
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace() e.printStackTrace()
...@@ -337,7 +337,7 @@ class DeviceInfo private constructor() { ...@@ -337,7 +337,7 @@ class DeviceInfo private constructor() {
var versionCode = "0" var versionCode = "0"
try { try {
versionCode = mContext!!.packageManager.getPackageInfo( versionCode = mContext!!.packageManager.getPackageInfo(
mContext!!.packageName, 0 mContext!!.packageName, 0
).versionCode.toString() ).versionCode.toString()
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace() e.printStackTrace()
...@@ -372,7 +372,7 @@ class DeviceInfo private constructor() { ...@@ -372,7 +372,7 @@ class DeviceInfo private constructor() {
return null return null
} }
val wifi = mContext!! val wifi = mContext!!
.getSystemService(Context.WIFI_SERVICE) as WifiManager .getSystemService(Context.WIFI_SERVICE) as WifiManager
val info = wifi.connectionInfo val info = wifi.connectionInfo
return info.macAddress return info.macAddress
} }
...@@ -388,7 +388,7 @@ class DeviceInfo private constructor() { ...@@ -388,7 +388,7 @@ class DeviceInfo private constructor() {
return null return null
} }
val wifi = mContext!! val wifi = mContext!!
.getSystemService(Context.WIFI_SERVICE) as WifiManager .getSystemService(Context.WIFI_SERVICE) as WifiManager
val info = wifi.connectionInfo val info = wifi.connectionInfo
return info.ssid return info.ssid
} }
...@@ -412,7 +412,7 @@ class DeviceInfo private constructor() { ...@@ -412,7 +412,7 @@ class DeviceInfo private constructor() {
return null return null
} }
val wifi = mContext!! val wifi = mContext!!
.getSystemService(Context.WIFI_SERVICE) as WifiManager .getSystemService(Context.WIFI_SERVICE) as WifiManager
val info = wifi.connectionInfo val info = wifi.connectionInfo
return info.bssid return info.bssid
} }
...@@ -427,14 +427,14 @@ class DeviceInfo private constructor() { ...@@ -427,14 +427,14 @@ class DeviceInfo private constructor() {
var sign_bool = false var sign_bool = false
try { try {
val packageInfo = mContext!!.packageManager val packageInfo = mContext!!.packageManager
.getPackageInfo(mContext!!.packageName, PackageManager.GET_SIGNATURES) .getPackageInfo(mContext!!.packageName, PackageManager.GET_SIGNATURES)
val signs = packageInfo.signatures val signs = packageInfo.signatures
if (signs != null && signs.size != 0) { if (signs != null && signs.size != 0) {
for (i in signs.indices) { for (i in signs.indices) {
val str = val str =
Integer.toHexString(signs[i].toCharsString().hashCode()) Integer.toHexString(signs[i].toCharsString().hashCode())
if (mContext!!.getString(R.string.app_sign) if (mContext!!.getString(R.string.app_sign)
.equals(str, ignoreCase = true) .equals(str, ignoreCase = true)
) sign_bool = true ) sign_bool = true
} }
} }
...@@ -455,9 +455,9 @@ class DeviceInfo private constructor() { ...@@ -455,9 +455,9 @@ class DeviceInfo private constructor() {
val cl = Class.forName("android.os.SystemProperties") val cl = Class.forName("android.os.SystemProperties")
val invoker = cl.newInstance() val invoker = cl.newInstance()
val m = cl.getMethod( val m = cl.getMethod(
"get", *arrayOf<Class<*>>( "get", *arrayOf<Class<*>>(
String::class.java, String::class.java String::class.java, String::class.java
) )
) )
m.invoke(invoker, *arrayOf<Any>("gsm.version.baseband", "no message")) m.invoke(invoker, *arrayOf<Any>("gsm.version.baseband", "no message"))
} catch (e: Exception) { } catch (e: Exception) {
...@@ -474,15 +474,15 @@ class DeviceInfo private constructor() { ...@@ -474,15 +474,15 @@ class DeviceInfo private constructor() {
*/ */
fun getApsInfo(context: Context): String { fun getApsInfo(context: Context): String {
val wifiManager = val wifiManager =
context.getSystemService(Context.WIFI_SERVICE) as WifiManager context.getSystemService(Context.WIFI_SERVICE) as WifiManager
val apsInfo: MutableList<String> = val apsInfo: MutableList<String> =
ArrayList() ArrayList()
val sbAps = StringBuffer() val sbAps = StringBuffer()
// //有些手机getScanResults 需要定位权限 // //有些手机getScanResults 需要定位权限
try { try {
val scanResults = val scanResults =
wifiManager.scanResults wifiManager.scanResults
for (i in scanResults.indices) { for (i in scanResults.indices) {
apsInfo.add(scanResults[i].SSID.toString()) apsInfo.add(scanResults[i].SSID.toString())
if (i == scanResults.size - 1) { if (i == scanResults.size - 1) {
...@@ -505,7 +505,7 @@ class DeviceInfo private constructor() { ...@@ -505,7 +505,7 @@ class DeviceInfo private constructor() {
*/ */
fun getCellInfo(context: Context): Array<String> { fun getCellInfo(context: Context): Array<String> {
val mTelephonyManager = val mTelephonyManager =
context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
// 返回值MCC + MNC // 返回值MCC + MNC
val cellInfo = arrayOf("", "") val cellInfo = arrayOf("", "")
val operator = mTelephonyManager.networkOperator val operator = mTelephonyManager.networkOperator
...@@ -524,15 +524,15 @@ class DeviceInfo private constructor() { ...@@ -524,15 +524,15 @@ class DeviceInfo private constructor() {
*/ */
fun getAPPInstalled(context: Context): String { fun getAPPInstalled(context: Context): String {
val listItems: MutableList<String?> = val listItems: MutableList<String?> =
ArrayList() ArrayList()
val installTime: MutableMap<Long, String> = val installTime: MutableMap<Long, String> =
HashMap() HashMap()
val time: MutableList<Long> = ArrayList() val time: MutableList<Long> = ArrayList()
// 获取系统内的所有程序信息 // 获取系统内的所有程序信息
val mainintent = Intent(Intent.ACTION_MAIN, null) val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER) mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo = val packageinfo =
context.packageManager.getInstalledPackages(0) context.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo? = null var pinfo: PackageInfo? = null
val count = packageinfo.size val count = packageinfo.size
for (i in 0 until count) { for (i in 0 until count) {
...@@ -544,12 +544,12 @@ class DeviceInfo private constructor() { ...@@ -544,12 +544,12 @@ class DeviceInfo private constructor() {
//非系统程序 //非系统程序
time.add(pinfo.firstInstallTime) time.add(pinfo.firstInstallTime)
installTime[pinfo.firstInstallTime] = installTime[pinfo.firstInstallTime] =
pinfo.applicationInfo.loadLabel(context.packageManager) as String pinfo.applicationInfo.loadLabel(context.packageManager) as String
} }
} }
Collections.sort( Collections.sort(
time, time,
Collections.reverseOrder() Collections.reverseOrder()
) //降序 ) //降序
val size = if (time.size >= 10) 10 else time.size val size = if (time.size >= 10) 10 else time.size
for (i in 0 until size) { for (i in 0 until size) {
...@@ -577,7 +577,7 @@ class DeviceInfo private constructor() { ...@@ -577,7 +577,7 @@ class DeviceInfo private constructor() {
val mainintent = Intent(Intent.ACTION_MAIN, null) val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER) mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo = val packageinfo =
mContext!!.packageManager.getInstalledPackages(0) mContext!!.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo? = null var pinfo: PackageInfo? = null
val count = packageinfo.size val count = packageinfo.size
for (i in 0 until count) { for (i in 0 until count) {
...@@ -591,10 +591,10 @@ class DeviceInfo private constructor() { ...@@ -591,10 +591,10 @@ class DeviceInfo private constructor() {
appMap["appName"] = appInfo.loadLabel(mContext!!.packageManager) as String appMap["appName"] = appInfo.loadLabel(mContext!!.packageManager) as String
appMap["appPkg"] = pinfo.packageName appMap["appPkg"] = pinfo.packageName
if (TextUtils.equals( if (TextUtils.equals(
Constant.MINTS_APP_NAME, Constant.MINTS_APP_NAME,
appInfo.loadLabel(mContext!!.packageManager) as String appInfo.loadLabel(mContext!!.packageManager) as String
) && ) &&
TextUtils.equals(pinfo.packageName, Constant.MINTS_PKG_NAME) TextUtils.equals(pinfo.packageName, Constant.MINTS_PKG_NAME)
) { ) {
continue continue
} }
...@@ -617,7 +617,7 @@ class DeviceInfo private constructor() { ...@@ -617,7 +617,7 @@ class DeviceInfo private constructor() {
val mainintent = Intent(Intent.ACTION_MAIN, null) val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER) mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo = val packageinfo =
mContext!!.packageManager.getInstalledPackages(0) mContext!!.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo? = null var pinfo: PackageInfo? = null
val count = packageinfo.size val count = packageinfo.size
for (i in 0 until count) { for (i in 0 until count) {
...@@ -628,10 +628,10 @@ class DeviceInfo private constructor() { ...@@ -628,10 +628,10 @@ class DeviceInfo private constructor() {
} else { } else {
//非系统程序 //非系统程序
if (TextUtils.equals( if (TextUtils.equals(
Constant.MINTS_APP_NAME, Constant.MINTS_APP_NAME,
appInfo.loadLabel(mContext!!.packageManager) as String appInfo.loadLabel(mContext!!.packageManager) as String
) && ) &&
TextUtils.equals(pinfo.packageName, Constant.MINTS_PKG_NAME) TextUtils.equals(pinfo.packageName, Constant.MINTS_PKG_NAME)
) { ) {
continue continue
} }
...@@ -655,7 +655,7 @@ class DeviceInfo private constructor() { ...@@ -655,7 +655,7 @@ class DeviceInfo private constructor() {
val mainintent = Intent(Intent.ACTION_MAIN, null) val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER) mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo = val packageinfo =
mContext!!.packageManager.getInstalledPackages(0) mContext!!.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo? = null var pinfo: PackageInfo? = null
val count = packageinfo.size val count = packageinfo.size
for (i in 0 until count) { for (i in 0 until count) {
...@@ -666,10 +666,10 @@ class DeviceInfo private constructor() { ...@@ -666,10 +666,10 @@ class DeviceInfo private constructor() {
} else { } else {
//非系统程序 //非系统程序
if (TextUtils.equals( if (TextUtils.equals(
Constant.MINTS_APP_NAME, Constant.MINTS_APP_NAME,
appInfo.loadLabel(mContext!!.packageManager) as String appInfo.loadLabel(mContext!!.packageManager) as String
) && ) &&
TextUtils.equals(pinfo.packageName, Constant.MINTS_PKG_NAME) TextUtils.equals(pinfo.packageName, Constant.MINTS_PKG_NAME)
) { ) {
continue continue
} }
...@@ -697,7 +697,7 @@ class DeviceInfo private constructor() { ...@@ -697,7 +697,7 @@ class DeviceInfo private constructor() {
val mainintent = Intent(Intent.ACTION_MAIN, null) val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER) mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo = val packageinfo =
mContext!!.packageManager.getInstalledPackages(0) mContext!!.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo? = null var pinfo: PackageInfo? = null
val count = packageinfo.size val count = packageinfo.size
for (i in 0 until count) { for (i in 0 until count) {
...@@ -708,9 +708,9 @@ class DeviceInfo private constructor() { ...@@ -708,9 +708,9 @@ class DeviceInfo private constructor() {
} else { } else {
//非系统程序 //非系统程序
if (TextUtils.equals( if (TextUtils.equals(
name, name,
appInfo.loadLabel(mContext!!.packageManager) as String appInfo.loadLabel(mContext!!.packageManager) as String
) )
) { ) {
pkg = pinfo.packageName pkg = pinfo.packageName
break break
...@@ -734,7 +734,7 @@ class DeviceInfo private constructor() { ...@@ -734,7 +734,7 @@ class DeviceInfo private constructor() {
val mainintent = Intent(Intent.ACTION_MAIN, null) val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER) mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo = val packageinfo =
mContext!!.packageManager.getInstalledPackages(0) mContext!!.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo? = null var pinfo: PackageInfo? = null
val count = packageinfo.size val count = packageinfo.size
for (i in 0 until count) { for (i in 0 until count) {
...@@ -763,7 +763,7 @@ class DeviceInfo private constructor() { ...@@ -763,7 +763,7 @@ class DeviceInfo private constructor() {
val androidId: String val androidId: String
get() { get() {
val androidId = Settings.Secure.getString( val androidId = Settings.Secure.getString(
mContext!!.contentResolver, Settings.Secure.ANDROID_ID mContext!!.contentResolver, Settings.Secure.ANDROID_ID
) )
return if (TextUtils.isEmpty(androidId)) "unknow" else androidId return if (TextUtils.isEmpty(androidId)) "unknow" else androidId
} }
...@@ -776,7 +776,7 @@ class DeviceInfo private constructor() { ...@@ -776,7 +776,7 @@ class DeviceInfo private constructor() {
*/ */
fun getAndroidId(context: Context?): String { fun getAndroidId(context: Context?): String {
val androidId = Settings.Secure.getString( val androidId = Settings.Secure.getString(
mContext?.contentResolver, Settings.Secure.ANDROID_ID mContext?.contentResolver, Settings.Secure.ANDROID_ID
) )
return if (TextUtils.isEmpty(androidId)) "unknow" else androidId return if (TextUtils.isEmpty(androidId)) "unknow" else androidId
}// Gingerbread doesn't support giving a single application access to both cores, but a }// Gingerbread doesn't support giving a single application access to both cores, but a
...@@ -919,7 +919,7 @@ class DeviceInfo private constructor() { ...@@ -919,7 +919,7 @@ class DeviceInfo private constructor() {
return mac return mac
} }
val wifi = mContext!!.getSystemService(Context.WIFI_SERVICE) as WifiManager val wifi = mContext!!.getSystemService(Context.WIFI_SERVICE) as WifiManager
?: return mac ?: return mac
var info: WifiInfo? = null var info: WifiInfo? = null
try { try {
info = wifi.connectionInfo info = wifi.connectionInfo
...@@ -947,8 +947,8 @@ class DeviceInfo private constructor() { ...@@ -947,8 +947,8 @@ class DeviceInfo private constructor() {
var WifiAddress = "02:00:00:00:00:00" var WifiAddress = "02:00:00:00:00:00"
try { try {
WifiAddress = WifiAddress =
BufferedReader(FileReader(File("/sys/class/net/wlan0/address"))) BufferedReader(FileReader(File("/sys/class/net/wlan0/address")))
.readLine() .readLine()
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
} }
...@@ -965,7 +965,7 @@ class DeviceInfo private constructor() { ...@@ -965,7 +965,7 @@ class DeviceInfo private constructor() {
private get() { private get() {
try { try {
val all: List<NetworkInterface> = val all: List<NetworkInterface> =
Collections.list(NetworkInterface.getNetworkInterfaces()) Collections.list(NetworkInterface.getNetworkInterfaces())
for (nif in all) { for (nif in all) {
if (!nif.name.equals("wlan0", ignoreCase = true)) continue if (!nif.name.equals("wlan0", ignoreCase = true)) continue
val macBytes = nif.hardwareAddress ?: return "" val macBytes = nif.hardwareAddress ?: return ""
...@@ -991,11 +991,11 @@ class DeviceInfo private constructor() { ...@@ -991,11 +991,11 @@ class DeviceInfo private constructor() {
get() { get() {
try { try {
val batteryBroadcast: Intent? = mContext!!.registerReceiver( val batteryBroadcast: Intent? = mContext!!.registerReceiver(
null, null,
IntentFilter(Intent.ACTION_BATTERY_CHANGED) IntentFilter(Intent.ACTION_BATTERY_CHANGED)
) )
val isCharging = val isCharging =
batteryBroadcast?.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0 batteryBroadcast?.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0
if (isCharging) { if (isCharging) {
return 1 return 1
} }
...@@ -1012,7 +1012,7 @@ class DeviceInfo private constructor() { ...@@ -1012,7 +1012,7 @@ class DeviceInfo private constructor() {
get() { get() {
try { try {
val enableAdb = Settings.Secure.getInt( val enableAdb = Settings.Secure.getInt(
mContext!!.contentResolver, Settings.Secure.ADB_ENABLED, 0 mContext!!.contentResolver, Settings.Secure.ADB_ENABLED, 0
) > 0 ) > 0
if (enableAdb) { if (enableAdb) {
return 1 return 1
...@@ -1030,7 +1030,7 @@ class DeviceInfo private constructor() { ...@@ -1030,7 +1030,7 @@ class DeviceInfo private constructor() {
get() { get() {
try { try {
val connectivityManager = val connectivityManager =
mContext!!.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager mContext!!.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetInfo: NetworkInfo? = connectivityManager.activeNetworkInfo val activeNetInfo: NetworkInfo? = connectivityManager.activeNetworkInfo
if (activeNetInfo != null && activeNetInfo.getType() === ConnectivityManager.TYPE_WIFI) { if (activeNetInfo != null && activeNetInfo.getType() === ConnectivityManager.TYPE_WIFI) {
return 1 return 1
...@@ -1048,12 +1048,12 @@ class DeviceInfo private constructor() { ...@@ -1048,12 +1048,12 @@ class DeviceInfo private constructor() {
get() { get() {
var file: File? = null var file: File? = null
val paths = arrayOf( val paths = arrayOf(
"/system/bin/", "/system/bin/",
"/system/xbin/", "/system/xbin/",
"/system/sbin/", "/system/sbin/",
"/sbin/", "/sbin/",
"/vendor/bin/", "/vendor/bin/",
"/su/bin/" "/su/bin/"
) )
try { try {
for (path in paths) { for (path in paths) {
...@@ -1086,11 +1086,11 @@ class DeviceInfo private constructor() { ...@@ -1086,11 +1086,11 @@ class DeviceInfo private constructor() {
} }
if (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP and pinfo.applicationInfo.flags == 0 if (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP and pinfo.applicationInfo.flags == 0
&& ApplicationInfo.FLAG_STOPPED and pinfo.applicationInfo.flags == 0 && ApplicationInfo.FLAG_STOPPED and pinfo.applicationInfo.flags == 0
) { ) {
val appMap: MutableMap<String, String> = HashMap() val appMap: MutableMap<String, String> = HashMap()
appMap["appName"] = appMap["appName"] =
pinfo.applicationInfo.loadLabel(mContext!!.packageManager) as String pinfo.applicationInfo.loadLabel(mContext!!.packageManager) as String
appMap["appPkg"] = pinfo.packageName appMap["appPkg"] = pinfo.packageName
appList.add(appMap) appList.add(appMap)
} }
...@@ -1110,84 +1110,93 @@ class DeviceInfo private constructor() { ...@@ -1110,84 +1110,93 @@ class DeviceInfo private constructor() {
* @return * @return
*/ */
fun getAPPInstalledThreeDay(context: Context): Boolean { fun getAPPInstalledThreeDay(context: Context): Boolean {
if (context == null) return false
val onedayItems: MutableList<String?> = val onedayItems: MutableList<String?> =
ArrayList() ArrayList()
val twodayItems: MutableList<String?> = val twodayItems: MutableList<String?> =
ArrayList() ArrayList()
val threedayItems: MutableList<String?> = val threedayItems: MutableList<String?> =
ArrayList() ArrayList()
val installTime: MutableMap<Long, String> = val installTime: MutableMap<Long, String> =
HashMap() HashMap()
val time: MutableList<Long> = ArrayList() val sumCount = AntiAuditManager.instance.getSumCount()
// 获取系统内的所有程序信息 try {
val mainintent = Intent(Intent.ACTION_MAIN, null)
mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
val packageinfo =
context.packageManager.getInstalledPackages(0)
var pinfo: PackageInfo?
val count = packageinfo.size
for (i in 0 until count) {
pinfo = packageinfo[i]
val appInfo = pinfo.applicationInfo
if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM > 0) {
//系统程序 忽略
} else {
//非系统程序
time.add(pinfo.firstInstallTime)
installTime[pinfo.firstInstallTime] =
pinfo.applicationInfo.loadLabel(context.packageManager) as String
}
}
Collections.sort(
time,
Collections.reverseOrder()
) //降序
val now = System.currentTimeMillis()
val sdfOne = SimpleDateFormat("yyyy-MM-dd")
val sdfTime = SimpleDateFormat("yyyy-MM-dd HH-mm-ss")
// 今天已经过完的时间
val overTime: Long = (now - sdfOne.parse(sdfOne.format(now)).time)
for (i in 0 until time.size) { val time: MutableList<Long> = ArrayList()
when { // 获取系统内的所有程序信息
(time[i] > now - (overTime + AntiAuditManager.ONE_DAY * 2) && time[i] < now - (overTime + AntiAuditManager.ONE_DAY)) -> { val mainintent = Intent(Intent.ACTION_MAIN, null)
LogUtil.d( mainintent.addCategory(Intent.CATEGORY_LAUNCHER)
"前三天安装 -> " + "包名:" + installTime[time[i]] + "-时间:" + sdfTime.format( val packageinfo =
time[i] context.packageManager.getInstalledPackages(0)
) var pinfo: PackageInfo?
) val count = packageinfo.size
// 前三天共安装 for (i in 0 until count) {
threedayItems.add(installTime[time[i]]) pinfo = packageinfo[i]
val appInfo = pinfo.applicationInfo
if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM > 0) {
//系统程序 忽略
} else {
//非系统程序
time.add(pinfo.firstInstallTime)
installTime[pinfo.firstInstallTime] =
pinfo.applicationInfo.loadLabel(context.packageManager) as String
} }
(time[i] > now - (overTime + AntiAuditManager.ONE_DAY) && time[i] < now - overTime) -> { }
LogUtil.d( Collections.sort(
"前两天安装 -> " + "包名:" + installTime[time[i]] + "-时间:" + sdfTime.format( time,
time[i] Collections.reverseOrder()
) //降序
val now = System.currentTimeMillis()
val sdfOne = SimpleDateFormat("yyyy-MM-dd")
val sdfTime = SimpleDateFormat("yyyy-MM-dd HH-mm-ss")
// 今天已经过完的时间
val overTime: Long = (now - sdfOne.parse(sdfOne.format(now)).time)
for (i in 0 until time.size) {
when {
(time[i] > now - (overTime + AntiAuditManager.ONE_DAY * 2) && time[i] < now - (overTime + AntiAuditManager.ONE_DAY)) -> {
LogUtil.d(
"前天安装 -> " + "包名:" + installTime[time[i]] + "-时间:" + sdfTime.format(
time[i]
)
) )
) // 前三天共安装
twodayItems.add(installTime[time[i]]) threedayItems.add(installTime[time[i]])
} }
time[i] > now - overTime -> { (time[i] > now - (overTime + AntiAuditManager.ONE_DAY) && time[i] < now - overTime) -> {
LogUtil.d( LogUtil.d(
"今天安装 -> " + "包名:" + installTime[time[i]] + "-时间:" + sdfTime.format( "昨天安装 -> " + "包名:" + installTime[time[i]] + "-时间:" + sdfTime.format(
time[i] time[i]
)
)
twodayItems.add(installTime[time[i]])
}
time[i] > now - overTime -> {
LogUtil.d(
"今天安装 -> " + "包名:" + installTime[time[i]] + "-时间:" + sdfTime.format(
time[i]
)
) )
) onedayItems.add(installTime[time[i]])
onedayItems.add(installTime[time[i]]) }
} }
} }
} val localApkCount = AntiAuditManager.instance.getCurrentDayCount()
val localApkCount = AntiAuditManager.instance.getCurrentDayCount() LogUtil.d("AntiAuditManager", "获取列表-本地个数 -> $localApkCount")
LogUtil.d("AntiAuditManager", "获取列表-本地个数 -> $localApkCount") AntiAuditManager.instance.setCurrentDayCount(if (localApkCount > onedayItems.size) localApkCount else onedayItems.size)
AntiAuditManager.instance.setCurrentDayCount(if (localApkCount > onedayItems.size) localApkCount else onedayItems.size)
LogUtil.d("AntiAuditManager", "ThreeDay -> $threedayItems") LogUtil.d("AntiAuditManager", "ThreeDay -> $threedayItems")
LogUtil.d("AntiAuditManager", "TwoDay -> $twodayItems") LogUtil.d("AntiAuditManager", "TwoDay -> $twodayItems")
LogUtil.d("AntiAuditManager", "OneDay -> $onedayItems") LogUtil.d("AntiAuditManager", "OneDay -> $onedayItems")
} catch (e: Exception) {
e.printStackTrace()
}
val sumCount = AntiAuditManager.instance.getSumCount()
return onedayItems.size >= sumCount || twodayItems.size >= sumCount || threedayItems.size >= sumCount return onedayItems.size >= sumCount || twodayItems.size >= sumCount || threedayItems.size >= sumCount
} }
......
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