Skip to content

Commit

Permalink
feat: add errors app's target and min sdk record
Browse files Browse the repository at this point in the history
  • Loading branch information
fankes committed Oct 22, 2023
1 parent 66b9407 commit 936d66a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import android.os.Build
import com.fankes.apperrorstracking.const.ModuleVersion
import com.fankes.apperrorstracking.locale.locale
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.appVersionNameOf
import com.fankes.apperrorstracking.utils.factory.difference
Expand All @@ -45,6 +47,8 @@ import java.util.Locale
* @param packageName 包名
* @param versionName 版本名称
* @param versionCode 版本号
* @param targetSdk 目标 SDK 版本
* @param minSdk 最低 SDK 版本
* @param isNativeCrash 是否为原生层异常
* @param exceptionClassName 异常类名
* @param exceptionMessage 异常信息
Expand All @@ -68,6 +72,10 @@ data class AppErrorsInfoBean(
var versionName: String = "",
@SerializedName("versionCode")
var versionCode: Long = -1L,
@SerializedName("targetSdk")
var targetSdk: Int = -1,
@SerializedName("minSdk")
var minSdk: Int = -1,
@SerializedName("isNativeCrash")
var isNativeCrash: Boolean = false,
@SerializedName("exceptionClassName")
Expand Down Expand Up @@ -108,6 +116,8 @@ data class AppErrorsInfoBean(
packageName = packageName ?: "unknown",
versionName = packageName?.let { context.appVersionNameOf(it).ifBlank { "unknown" } } ?: "",
versionCode = packageName?.let { context.appVersionCodeOf(it) } ?: -1L,
targetSdk = packageName?.let { context.appTargetSdkOf(it) } ?: -1,
minSdk = packageName?.let { context.appMinSdkOf(it) } ?: -1,
isNativeCrash = isNativeCrash,
exceptionClassName = crashInfo?.exceptionClassName ?: "unknown",
exceptionMessage = if (isNativeCrash) crashInfo?.stackTrace.let {
Expand Down Expand Up @@ -212,6 +222,8 @@ data class AppErrorsInfoBean(
[Package Name]: $packageName
[Version Name]: ${versionName.ifBlank { "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"}
[Crash Time]: $utcTime
[Stack Trace]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
binding.appUserIdText.isVisible = appErrorsInfo.userId > 0
binding.appUserIdText.text = locale.userId(appErrorsInfo.userId)
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.errorTypeIcon.setImageResource(if (appErrorsInfo.isNativeCrash) R.drawable.ic_cpp else R.drawable.ic_java)
binding.errorInfoText.text = appErrorsInfo.exceptionMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ fun Context.appVersionNameOf(packageName: String = getPackageName()) = getPackag
*/
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 名称
* @param packageName APP 包名 - 默认为当前 APP
Expand Down
30 changes: 30 additions & 0 deletions module-app/src/main/res/layout/activity_app_errors_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,36 @@
android:textColor="@color/white"
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
android:id="@+id/app_version_text"
android:layout_width="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions module-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,6 @@
<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_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>

0 comments on commit 936d66a

Please sign in to comment.