mirror of
https://github.com/KitsunePie/AppErrorsTracking.git
synced 2025-09-01 08:45:16 +08:00
Modify make app errors records data to persistent storage
This commit is contained in:
@@ -38,6 +38,9 @@ import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData
|
|||||||
*/
|
*/
|
||||||
object ConfigData {
|
object ConfigData {
|
||||||
|
|
||||||
|
/** 存取全部应用异常数据的键值名称 */
|
||||||
|
const val APP_ERRORS_DATA = "app_errors_data"
|
||||||
|
|
||||||
/** 显示开发者提示 */
|
/** 显示开发者提示 */
|
||||||
val SHOW_DEVELOPER_NOTICE = PrefsData("_show_developer_notice", true)
|
val SHOW_DEVELOPER_NOTICE = PrefsData("_show_developer_notice", true)
|
||||||
|
|
||||||
|
@@ -81,8 +81,8 @@ object FrameworkHooker : YukiBaseHooker() {
|
|||||||
/** 已忽略错误的 APP 数组 - 直到重新启动 */
|
/** 已忽略错误的 APP 数组 - 直到重新启动 */
|
||||||
private var mutedErrorsIfRestartApps = HashSet<String>()
|
private var mutedErrorsIfRestartApps = HashSet<String>()
|
||||||
|
|
||||||
/** 已记录的 APP 异常信息数组 - 直到重新启动 */
|
/** 已记录的 APP 异常信息数组 */
|
||||||
private val appErrorsRecords = ArrayList<AppErrorsInfoBean>()
|
private var appErrorsRecords = ArrayList<AppErrorsInfoBean>()
|
||||||
|
|
||||||
/** 注册生命周期 */
|
/** 注册生命周期 */
|
||||||
private fun registerLifecycle() {
|
private fun registerLifecycle() {
|
||||||
@@ -91,12 +91,20 @@ object FrameworkHooker : YukiBaseHooker() {
|
|||||||
registerReceiver(Intent.ACTION_USER_PRESENT) { _, _ -> mutedErrorsIfUnlockApps.clear() }
|
registerReceiver(Intent.ACTION_USER_PRESENT) { _, _ -> mutedErrorsIfUnlockApps.clear() }
|
||||||
/** 刷新模块 Resources 缓存 */
|
/** 刷新模块 Resources 缓存 */
|
||||||
registerReceiver(Intent.ACTION_LOCALE_CHANGED) { _, _ -> refreshModuleAppResources() }
|
registerReceiver(Intent.ACTION_LOCALE_CHANGED) { _, _ -> refreshModuleAppResources() }
|
||||||
|
/** 启动时从本地获取异常记录 */
|
||||||
|
onCreate { appErrorsRecords = ConfigData.getResolverString(ConfigData.APP_ERRORS_DATA).toEntity() ?: arrayListOf() }
|
||||||
}
|
}
|
||||||
FrameworkTool.Host.with(instance = this) {
|
FrameworkTool.Host.with(instance = this) {
|
||||||
onOpenAppUsedFramework { appContext?.openApp(it) }
|
onOpenAppUsedFramework { appContext?.openApp(it) }
|
||||||
onPushAppErrorsInfoData { appErrorsRecords }
|
onPushAppErrorsInfoData { appErrorsRecords }
|
||||||
onRemoveAppErrorsInfoData { appErrorsRecords.remove(it) }
|
onRemoveAppErrorsInfoData {
|
||||||
onClearAppErrorsInfoData { appErrorsRecords.clear() }
|
appErrorsRecords.remove(it)
|
||||||
|
saveAllAppErrorsRecords()
|
||||||
|
}
|
||||||
|
onClearAppErrorsInfoData {
|
||||||
|
appErrorsRecords.clear()
|
||||||
|
saveAllAppErrorsRecords()
|
||||||
|
}
|
||||||
onMutedErrorsIfUnlock { mutedErrorsIfUnlockApps.add(it) }
|
onMutedErrorsIfUnlock { mutedErrorsIfUnlockApps.add(it) }
|
||||||
onMutedErrorsIfRestart { mutedErrorsIfRestartApps.add(it) }
|
onMutedErrorsIfRestart { mutedErrorsIfRestartApps.add(it) }
|
||||||
onPushMutedErrorsAppsData {
|
onPushMutedErrorsAppsData {
|
||||||
@@ -138,6 +146,9 @@ object FrameworkHooker : YukiBaseHooker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 保存异常记录到本地 */
|
||||||
|
private fun saveAllAppErrorsRecords() = newThread { ConfigData.putResolverString(ConfigData.APP_ERRORS_DATA, appErrorsRecords.toJson()) }
|
||||||
|
|
||||||
override fun onHook() {
|
override fun onHook() {
|
||||||
/** 注册生命周期 */
|
/** 注册生命周期 */
|
||||||
registerLifecycle()
|
registerLifecycle()
|
||||||
@@ -301,6 +312,8 @@ object FrameworkHooker : YukiBaseHooker() {
|
|||||||
val appInfo = ProcessRecordClass.toClass().field { name = "info" }.get(args().first().any()).cast<ApplicationInfo>()
|
val appInfo = ProcessRecordClass.toClass().field { name = "info" }.get(args().first().any()).cast<ApplicationInfo>()
|
||||||
/** 添加当前异常信息到第一位 */
|
/** 添加当前异常信息到第一位 */
|
||||||
appErrorsRecords.add(0, AppErrorsInfoBean.clone(appInfo?.packageName, args().last().cast()))
|
appErrorsRecords.add(0, AppErrorsInfoBean.clone(appInfo?.packageName, args().last().cast()))
|
||||||
|
/** 保存异常记录到本地 */
|
||||||
|
saveAllAppErrorsRecords()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user