From d729043e432cd08b087f16f1c3c1ef3e77661364 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 6 Oct 2021 20:33:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/AppConst.kt | 18 ++++++------ .../java/io/legado/app/help/CrashHandler.kt | 28 ++++++------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index 83032ceb4..70caafc8d 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -1,6 +1,7 @@ package io.legado.app.constant import android.annotation.SuppressLint +import android.content.pm.PackageManager import android.provider.Settings import io.legado.app.BuildConfig import io.legado.app.R @@ -84,15 +85,16 @@ object AppConst { val appInfo: AppInfo by lazy { val appInfo = AppInfo() - appCtx.packageManager.getPackageInfo(appCtx.packageName, 0)?.let { - appInfo.versionName = it.versionName - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { - appInfo.versionCode = it.longVersionCode - } else { - @Suppress("DEPRECATION") - appInfo.versionCode = it.versionCode.toLong() + appCtx.packageManager.getPackageInfo(appCtx.packageName, PackageManager.GET_ACTIVITIES) + ?.let { + appInfo.versionName = it.versionName + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { + appInfo.versionCode = it.longVersionCode + } else { + @Suppress("DEPRECATION") + appInfo.versionCode = it.versionCode.toLong() + } } - } appInfo } diff --git a/app/src/main/java/io/legado/app/help/CrashHandler.kt b/app/src/main/java/io/legado/app/help/CrashHandler.kt index 94f8b7d02..7d5161298 100644 --- a/app/src/main/java/io/legado/app/help/CrashHandler.kt +++ b/app/src/main/java/io/legado/app/help/CrashHandler.kt @@ -2,9 +2,9 @@ package io.legado.app.help import android.annotation.SuppressLint import android.content.Context -import android.content.pm.PackageManager import android.os.Build import android.util.Log +import io.legado.app.constant.AppConst import io.legado.app.model.ReadAloud import io.legado.app.utils.FileUtils import io.legado.app.utils.longToastOnUi @@ -70,26 +70,14 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { * 收集设备参数信息 */ private fun collectDeviceInfo(ctx: Context) { - //获取versionName,versionCode kotlin.runCatching { - val pm = ctx.packageManager - val pi = pm.getPackageInfo(ctx.packageName, PackageManager.GET_ACTIVITIES) - if (pi != null) { - val versionName = if (pi.versionName == null) "null" else pi.versionName - val versionCode = pi.versionCode.toString() + "" - paramsMap["versionName"] = versionName - paramsMap["versionCode"] = versionCode - } - } - - //获取所有系统信息 - val fields = Build::class.java.declaredFields - kotlin.runCatching { - for (field in fields) { - field.isAccessible = true - field.get(null)?.toString()?.let { - paramsMap[field.name] = it - } + //获取系统信息 + paramsMap["MANUFACTURER"] = Build.MANUFACTURER + paramsMap["BRAND"] = Build.BRAND + //获取app版本信息 + AppConst.appInfo.let { + paramsMap["versionName"] = it.versionName + paramsMap["versionCode"] = it.versionCode.toString() } } }