Added remove designated errors record function

This commit is contained in:
2022-05-13 23:37:47 +08:00
parent a36362735e
commit a41337a979
12 changed files with 70 additions and 4 deletions

View File

@@ -46,6 +46,12 @@ object Const {
/** 清空 [AppErrorsInfoBean] 数据 */ /** 清空 [AppErrorsInfoBean] 数据 */
const val TYPE_APP_ERRORS_DATA_CLEAR = "app_errors_data_clear_type" const val TYPE_APP_ERRORS_DATA_CLEAR = "app_errors_data_clear_type"
/** 删除指定 [AppErrorsInfoBean] 数据 */
const val TYPE_APP_ERRORS_DATA_REMOVE = "app_errors_data_remove_type"
/** 获取到的 [AppErrorsInfoBean] 数据内容 */ /** 获取到的 [AppErrorsInfoBean] 数据内容 */
const val TAG_APP_ERRORS_DATA_CONTENT = "app_errors_data_content_tag" const val TAG_APP_ERRORS_DATA_GET_CONTENT = "app_errors_data_get_content_tag"
/** 指定删除的 [AppErrorsInfoBean] 数据内容 */
const val TAG_APP_ERRORS_DATA_REMOVE_CONTENT = "app_errors_data_remove_content_tag"
} }

View File

@@ -120,9 +120,14 @@ object FrameworkHooker : YukiBaseHooker() {
action = Const.ACTION_MODULE_HANDLER_RECEIVER action = Const.ACTION_MODULE_HANDLER_RECEIVER
when (it) { when (it) {
Const.TYPE_APP_ERRORS_DATA_GET -> { Const.TYPE_APP_ERRORS_DATA_GET -> {
putExtra(Const.TAG_APP_ERRORS_DATA_CONTENT, appErrorsRecords) putExtra(Const.TAG_APP_ERRORS_DATA_GET_CONTENT, appErrorsRecords)
putExtra(Const.KEY_MODULE_HOST_FETCH, Const.TYPE_APP_ERRORS_DATA_GET) putExtra(Const.KEY_MODULE_HOST_FETCH, Const.TYPE_APP_ERRORS_DATA_GET)
} }
Const.TYPE_APP_ERRORS_DATA_REMOVE -> {
runCatching { intent.getSerializableExtra(Const.TAG_APP_ERRORS_DATA_REMOVE_CONTENT) as? AppErrorsInfoBean? }
.getOrNull()?.also { e -> appErrorsRecords.remove(e) }
putExtra(Const.KEY_MODULE_HOST_FETCH, Const.TYPE_APP_ERRORS_DATA_REMOVE)
}
Const.TYPE_APP_ERRORS_DATA_CLEAR -> { Const.TYPE_APP_ERRORS_DATA_CLEAR -> {
appErrorsRecords.clear() appErrorsRecords.clear()
putExtra(Const.KEY_MODULE_HOST_FETCH, Const.TYPE_APP_ERRORS_DATA_CLEAR) putExtra(Const.KEY_MODULE_HOST_FETCH, Const.TYPE_APP_ERRORS_DATA_CLEAR)

View File

@@ -220,4 +220,10 @@ object LocaleString {
/** @string Automatic generated */ /** @string Automatic generated */
fun noCpuAbi(vararg objArrs: Any) = R.string.no_cpu_abi.bind(*objArrs) fun noCpuAbi(vararg objArrs: Any) = R.string.no_cpu_abi.bind(*objArrs)
/** @string Automatic generated */
val areYouSureRemoveRecord get() = areYouSureRemoveRecord()
/** @string Automatic generated */
fun areYouSureRemoveRecord(vararg objArrs: Any) = R.string.are_you_sure_remove_record.bind(*objArrs)
} }

View File

@@ -167,6 +167,13 @@ class AppErrorsRecordActivity : BaseActivity<ActivityAppErrorsRecordBinding>() {
when (item.itemId) { when (item.itemId) {
R.id.aerrors_view_detail -> AppErrorsDetailActivity.start(context = this, listData[it.position]) R.id.aerrors_view_detail -> AppErrorsDetailActivity.start(context = this, listData[it.position])
R.id.aerrors_app_info -> openSelfSetting(listData[it.position].packageName) R.id.aerrors_app_info -> openSelfSetting(listData[it.position].packageName)
R.id.aerrors_remove_record ->
showDialog {
title = LocaleString.notice
msg = LocaleString.areYouSureRemoveRecord
confirmButton { FrameworkTool.removeAppErrorsInfoData(context, listData[it.position]) { refreshData() } }
cancelButton()
}
} }
} }
return super.onContextItemSelected(item) return super.onContextItemSelected(item)

View File

@@ -30,6 +30,7 @@ import android.content.IntentFilter
import com.fankes.apperrorstracking.bean.AppErrorsInfoBean import com.fankes.apperrorstracking.bean.AppErrorsInfoBean
import com.fankes.apperrorstracking.const.Const import com.fankes.apperrorstracking.const.Const
import com.highcapable.yukihookapi.hook.log.loggerE import com.highcapable.yukihookapi.hook.log.loggerE
import java.io.Serializable
/** /**
* 系统框架控制工具 * 系统框架控制工具
@@ -39,6 +40,9 @@ object FrameworkTool {
/** 回调获取的 APP 异常信息 */ /** 回调获取的 APP 异常信息 */
private var onAppErrorsInfoDataCallback: ((ArrayList<AppErrorsInfoBean>) -> Unit)? = null private var onAppErrorsInfoDataCallback: ((ArrayList<AppErrorsInfoBean>) -> Unit)? = null
/** 回调 APP 异常信息是否移除 */
private var onRemoveAppErrorsInfoDataCallback: (() -> Unit)? = null
/** 回调 APP 异常信息是否清空 */ /** 回调 APP 异常信息是否清空 */
private var onClearAppErrorsInfoDataCallback: (() -> Unit)? = null private var onClearAppErrorsInfoDataCallback: (() -> Unit)? = null
@@ -52,9 +56,10 @@ object FrameworkTool {
if (it.isNotBlank()) when (it) { if (it.isNotBlank()) when (it) {
Const.TYPE_APP_ERRORS_DATA_GET -> runCatching { Const.TYPE_APP_ERRORS_DATA_GET -> runCatching {
onAppErrorsInfoDataCallback?.invoke( onAppErrorsInfoDataCallback?.invoke(
intent.getSerializableExtra(Const.TAG_APP_ERRORS_DATA_CONTENT) as ArrayList<AppErrorsInfoBean> intent.getSerializableExtra(Const.TAG_APP_ERRORS_DATA_GET_CONTENT) as ArrayList<AppErrorsInfoBean>
) )
}.onFailure { onAppErrorsInfoDataCallback?.invoke(arrayListOf()) } }.onFailure { onAppErrorsInfoDataCallback?.invoke(arrayListOf()) }
Const.TYPE_APP_ERRORS_DATA_REMOVE -> onRemoveAppErrorsInfoDataCallback?.invoke()
Const.TYPE_APP_ERRORS_DATA_CLEAR -> onClearAppErrorsInfoDataCallback?.invoke() Const.TYPE_APP_ERRORS_DATA_CLEAR -> onClearAppErrorsInfoDataCallback?.invoke()
else -> {} else -> {}
} }
@@ -68,11 +73,22 @@ object FrameworkTool {
* 发送广播 * 发送广播
* @param context 实例 * @param context 实例
* @param type 类型 * @param type 类型
* @param key 可选传值
* @param value 可选传值
*/ */
private fun pushReceiver(context: Context, type: String) { private fun pushReceiver(context: Context, type: String, key: String = "", value: Any = "") {
context.sendBroadcast(Intent().apply { context.sendBroadcast(Intent().apply {
action = Const.ACTION_HOST_HANDLER_RECEIVER action = Const.ACTION_HOST_HANDLER_RECEIVER
putExtra(Const.KEY_MODULE_HOST_FETCH, type) putExtra(Const.KEY_MODULE_HOST_FETCH, type)
if (key.isNotBlank()) putExtra(
key, when (value) {
is String -> value
is Int -> value
is Boolean -> value
is Serializable -> value
else -> error("value is not allowed")
}
)
}) })
} }
@@ -86,6 +102,17 @@ object FrameworkTool {
pushReceiver(context, Const.TYPE_APP_ERRORS_DATA_GET) pushReceiver(context, Const.TYPE_APP_ERRORS_DATA_GET)
} }
/**
* 移除指定 APP 异常信息
* @param context 实例
* @param appErrorsInfo 指定 APP 异常信息
* @param it 成功后回调
*/
fun removeAppErrorsInfoData(context: Context, appErrorsInfo: AppErrorsInfoBean, it: () -> Unit) {
onRemoveAppErrorsInfoDataCallback = it
pushReceiver(context, Const.TYPE_APP_ERRORS_DATA_REMOVE, Const.TAG_APP_ERRORS_DATA_REMOVE_CONTENT, appErrorsInfo)
}
/** /**
* 清空 APP 异常信息数组 * 清空 APP 异常信息数组
* @param context 实例 * @param context 实例

View File

@@ -6,4 +6,7 @@
<item <item
android:id="@+id/aerrors_app_info" android:id="@+id/aerrors_app_info"
android:title="@string/app_info" /> android:title="@string/app_info" />
<item
android:id="@+id/aerrors_remove_record"
android:title="@string/remove_record" />
</menu> </menu>

View File

@@ -43,4 +43,6 @@
<string name="export_all_errors_success">すべてのエラーレコードがエクスポートされました</string> <string name="export_all_errors_success">すべてのエラーレコードがエクスポートされました</string>
<string name="export_all_errors_fail">すべてのエラーレコードのエクスポートに失敗しました</string> <string name="export_all_errors_fail">すべてのエラーレコードのエクスポートに失敗しました</string>
<string name="no_cpu_abi">アビなし</string> <string name="no_cpu_abi">アビなし</string>
<string name="remove_record">レコードを削除</string>
<string name="are_you_sure_remove_record">このレコードを削除してもよろしいですか</string>
</resources> </resources>

View File

@@ -43,4 +43,6 @@
<string name="export_all_errors_success">已导出全部异常记录</string> <string name="export_all_errors_success">已导出全部异常记录</string>
<string name="export_all_errors_fail">导出全部异常记录失败</string> <string name="export_all_errors_fail">导出全部异常记录失败</string>
<string name="no_cpu_abi">无原生库</string> <string name="no_cpu_abi">无原生库</string>
<string name="remove_record">移除记录</string>
<string name="are_you_sure_remove_record">你确定要移除这条记录吗</string>
</resources> </resources>

View File

@@ -43,4 +43,6 @@
<string name="export_all_errors_success">已導出全部異常紀錄</string> <string name="export_all_errors_success">已導出全部異常紀錄</string>
<string name="export_all_errors_fail">導出全部異常紀錄失敗</string> <string name="export_all_errors_fail">導出全部異常紀錄失敗</string>
<string name="no_cpu_abi">無原生庫</string> <string name="no_cpu_abi">無原生庫</string>
<string name="remove_record">移除紀錄</string>
<string name="are_you_sure_remove_record">你確認要移除這條紀錄嗎</string>
</resources> </resources>

View File

@@ -43,4 +43,6 @@
<string name="export_all_errors_success">已導出全部異常紀錄</string> <string name="export_all_errors_success">已導出全部異常紀錄</string>
<string name="export_all_errors_fail">導出全部異常紀錄失敗</string> <string name="export_all_errors_fail">導出全部異常紀錄失敗</string>
<string name="no_cpu_abi">無原生庫</string> <string name="no_cpu_abi">無原生庫</string>
<string name="remove_record">移除紀錄</string>
<string name="are_you_sure_remove_record">你確認要移除這條紀錄嗎</string>
</resources> </resources>

View File

@@ -43,4 +43,6 @@
<string name="export_all_errors_success">已導出全部異常紀錄</string> <string name="export_all_errors_success">已導出全部異常紀錄</string>
<string name="export_all_errors_fail">導出全部異常紀錄失敗</string> <string name="export_all_errors_fail">導出全部異常紀錄失敗</string>
<string name="no_cpu_abi">無原生庫</string> <string name="no_cpu_abi">無原生庫</string>
<string name="remove_record">移除紀錄</string>
<string name="are_you_sure_remove_record">你確認要移除這條紀錄嗎</string>
</resources> </resources>

View File

@@ -42,4 +42,6 @@
<string name="export_all_errors_success">All errors record exported</string> <string name="export_all_errors_success">All errors record exported</string>
<string name="export_all_errors_fail">Failed to exported all errors record</string> <string name="export_all_errors_fail">Failed to exported all errors record</string>
<string name="no_cpu_abi">No ABI</string> <string name="no_cpu_abi">No ABI</string>
<string name="remove_record">Remove record</string>
<string name="are_you_sure_remove_record">Are you sure you want to remove this record?</string>
</resources> </resources>