feat: add errors app's target and min sdk record

This commit is contained in:
2023-10-22 23:13:26 +08:00
parent 66b9407b34
commit 936d66a81e
5 changed files with 60 additions and 0 deletions

View File

@@ -27,6 +27,8 @@ import android.os.Build
import com.fankes.apperrorstracking.const.ModuleVersion import com.fankes.apperrorstracking.const.ModuleVersion
import com.fankes.apperrorstracking.locale.locale import com.fankes.apperrorstracking.locale.locale
import com.fankes.apperrorstracking.utils.factory.appCpuAbiOf import com.fankes.apperrorstracking.utils.factory.appCpuAbiOf
import com.fankes.apperrorstracking.utils.factory.appMinSdkOf
import com.fankes.apperrorstracking.utils.factory.appTargetSdkOf
import com.fankes.apperrorstracking.utils.factory.appVersionCodeOf import com.fankes.apperrorstracking.utils.factory.appVersionCodeOf
import com.fankes.apperrorstracking.utils.factory.appVersionNameOf import com.fankes.apperrorstracking.utils.factory.appVersionNameOf
import com.fankes.apperrorstracking.utils.factory.difference import com.fankes.apperrorstracking.utils.factory.difference
@@ -45,6 +47,8 @@ import java.util.Locale
* @param packageName 包名 * @param packageName 包名
* @param versionName 版本名称 * @param versionName 版本名称
* @param versionCode 版本号 * @param versionCode 版本号
* @param targetSdk 目标 SDK 版本
* @param minSdk 最低 SDK 版本
* @param isNativeCrash 是否为原生层异常 * @param isNativeCrash 是否为原生层异常
* @param exceptionClassName 异常类名 * @param exceptionClassName 异常类名
* @param exceptionMessage 异常信息 * @param exceptionMessage 异常信息
@@ -68,6 +72,10 @@ data class AppErrorsInfoBean(
var versionName: String = "", var versionName: String = "",
@SerializedName("versionCode") @SerializedName("versionCode")
var versionCode: Long = -1L, var versionCode: Long = -1L,
@SerializedName("targetSdk")
var targetSdk: Int = -1,
@SerializedName("minSdk")
var minSdk: Int = -1,
@SerializedName("isNativeCrash") @SerializedName("isNativeCrash")
var isNativeCrash: Boolean = false, var isNativeCrash: Boolean = false,
@SerializedName("exceptionClassName") @SerializedName("exceptionClassName")
@@ -108,6 +116,8 @@ data class AppErrorsInfoBean(
packageName = packageName ?: "unknown", packageName = packageName ?: "unknown",
versionName = packageName?.let { context.appVersionNameOf(it).ifBlank { "unknown" } } ?: "", versionName = packageName?.let { context.appVersionNameOf(it).ifBlank { "unknown" } } ?: "",
versionCode = packageName?.let { context.appVersionCodeOf(it) } ?: -1L, versionCode = packageName?.let { context.appVersionCodeOf(it) } ?: -1L,
targetSdk = packageName?.let { context.appTargetSdkOf(it) } ?: -1,
minSdk = packageName?.let { context.appMinSdkOf(it) } ?: -1,
isNativeCrash = isNativeCrash, isNativeCrash = isNativeCrash,
exceptionClassName = crashInfo?.exceptionClassName ?: "unknown", exceptionClassName = crashInfo?.exceptionClassName ?: "unknown",
exceptionMessage = if (isNativeCrash) crashInfo?.stackTrace.let { exceptionMessage = if (isNativeCrash) crashInfo?.stackTrace.let {
@@ -212,6 +222,8 @@ data class AppErrorsInfoBean(
[Package Name]: $packageName [Package Name]: $packageName
[Version Name]: ${versionName.ifBlank { "unknown" }} [Version Name]: ${versionName.ifBlank { "unknown" }}
[Version Code]: ${versionCode.takeIf { it != -1L } ?: "unknown"} [Version Code]: ${versionCode.takeIf { it != -1L } ?: "unknown"}
[Target SDK]: ${targetSdk.takeIf { it != -1 } ?: "unknown"}
[Min SDK]: ${minSdk.takeIf { it != -1 } ?: "unknown"}
[Error Type]: ${if (isNativeCrash) "Native" else "JVM"} [Error Type]: ${if (isNativeCrash) "Native" else "JVM"}
[Crash Time]: $utcTime [Crash Time]: $utcTime
[Stack Trace]: [Stack Trace]:

View File

@@ -144,6 +144,8 @@ class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
binding.appUserIdText.isVisible = appErrorsInfo.userId > 0 binding.appUserIdText.isVisible = appErrorsInfo.userId > 0
binding.appUserIdText.text = locale.userId(appErrorsInfo.userId) binding.appUserIdText.text = locale.userId(appErrorsInfo.userId)
binding.appCpuAbiText.text = appErrorsInfo.cpuAbi.ifBlank { locale.noCpuAbi } binding.appCpuAbiText.text = appErrorsInfo.cpuAbi.ifBlank { locale.noCpuAbi }
binding.appTargetSdkText.text = locale.appTargetSdk(appErrorsInfo.targetSdk)
binding.appMinSdkText.text = locale.appMinSdk(appErrorsInfo.minSdk)
binding.jvmErrorPanel.isGone = appErrorsInfo.isNativeCrash binding.jvmErrorPanel.isGone = appErrorsInfo.isNativeCrash
binding.errorTypeIcon.setImageResource(if (appErrorsInfo.isNativeCrash) R.drawable.ic_cpp else R.drawable.ic_java) binding.errorTypeIcon.setImageResource(if (appErrorsInfo.isNativeCrash) R.drawable.ic_cpp else R.drawable.ic_java)
binding.errorInfoText.text = appErrorsInfo.exceptionMessage binding.errorInfoText.text = appErrorsInfo.exceptionMessage

View File

@@ -180,6 +180,20 @@ fun Context.appVersionNameOf(packageName: String = getPackageName()) = getPackag
*/ */
fun Context.appVersionCodeOf(packageName: String = getPackageName()) = getPackageInfoCompat(packageName)?.versionCodeCompat ?: -1L fun Context.appVersionCodeOf(packageName: String = getPackageName()) = getPackageInfoCompat(packageName)?.versionCodeCompat ?: -1L
/**
* 得到 APP 目标 SDK 版本
* @param packageName APP 包名 - 默认为当前 APP
* @return [Int] 无法获取时返回 -1
*/
fun Context.appTargetSdkOf(packageName: String = getPackageName()) = getPackageInfoCompat(packageName)?.applicationInfo?.targetSdkVersion ?: -1
/**
* 得到 APP 最低 SDK 版本
* @param packageName APP 包名 - 默认为当前 APP
* @return [Int] 无法获取时返回 -1
*/
fun Context.appMinSdkOf(packageName: String = getPackageName()) = getPackageInfoCompat(packageName)?.applicationInfo?.minSdkVersion ?: -1
/** /**
* 获取 APP CPU ABI 名称 * 获取 APP CPU ABI 名称
* @param packageName APP 包名 - 默认为当前 APP * @param packageName APP 包名 - 默认为当前 APP

View File

@@ -197,6 +197,36 @@
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="9sp" /> android:textSize="9sp" />
<TextView
android:id="@+id/app_target_sdk_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:background="@drawable/bg_blue_round"
android:ellipsize="end"
android:paddingLeft="3dp"
android:paddingTop="0.5dp"
android:paddingRight="3dp"
android:paddingBottom="0.5dp"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="9sp" />
<TextView
android:id="@+id/app_min_sdk_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:background="@drawable/bg_blue_round"
android:ellipsize="end"
android:paddingLeft="3dp"
android:paddingTop="0.5dp"
android:paddingRight="3dp"
android:paddingBottom="0.5dp"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="9sp" />
<TextView <TextView
android:id="@+id/app_version_text" android:id="@+id/app_version_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -149,4 +149,6 @@
<string name="record_count">%1$s records found</string> <string name="record_count">%1$s records found</string>
<string name="ci_notice_dialog_title">CI Auto Build Instruction</string> <string name="ci_notice_dialog_title">CI Auto Build Instruction</string>
<string name="ci_notice_dialog_content">You are using a CI automated build with Commit ID %1$s.\n\nIt is automatically triggered and built after the code is committed, automatically compiled and released, and has not been tested for stability, use it at your own risk.</string> <string name="ci_notice_dialog_content">You are using a CI automated build with Commit ID %1$s.\n\nIt is automatically triggered and built after the code is committed, automatically compiled and released, and has not been tested for stability, use it at your own risk.</string>
<string name="app_target_sdk" translatable="false">Target %1$s</string>
<string name="app_min_sdk" translatable="false">Min %1$s</string>
</resources> </resources>