Added errors showing with notification function and fix some i18n translation bug

This commit is contained in:
2022-06-21 05:34:16 +08:00
parent a512e4854a
commit 8cb57c805e
15 changed files with 135 additions and 24 deletions

View File

@@ -28,20 +28,22 @@ import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.os.Message
import androidx.core.graphics.drawable.IconCompat
import androidx.core.graphics.drawable.toBitmap
import com.fankes.apperrorstracking.BuildConfig
import com.fankes.apperrorstracking.R
import com.fankes.apperrorstracking.bean.AppErrorsDisplayBean
import com.fankes.apperrorstracking.bean.AppErrorsInfoBean
import com.fankes.apperrorstracking.bean.AppInfoBean
import com.fankes.apperrorstracking.bean.MutedErrorsAppBean
import com.fankes.apperrorstracking.data.DataConst
import com.fankes.apperrorstracking.hook.factory.isAppShowErrorsNotify
import com.fankes.apperrorstracking.hook.factory.isAppShowErrorsToast
import com.fankes.apperrorstracking.hook.factory.isAppShowNothing
import com.fankes.apperrorstracking.locale.LocaleString
import com.fankes.apperrorstracking.ui.activity.errors.AppErrorsDisplayActivity
import com.fankes.apperrorstracking.utils.factory.appName
import com.fankes.apperrorstracking.utils.factory.isAppCanOpened
import com.fankes.apperrorstracking.utils.factory.openApp
import com.fankes.apperrorstracking.utils.factory.toast
import com.fankes.apperrorstracking.ui.activity.errors.AppErrorsRecordActivity
import com.fankes.apperrorstracking.utils.factory.*
import com.fankes.apperrorstracking.utils.tool.FrameworkTool
import com.highcapable.yukihookapi.hook.bean.VariousClass
import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker
@@ -221,20 +223,32 @@ object FrameworkHooker : YukiBaseHooker() {
}
/** 判断是否为已忽略的 APP */
if (mutedErrorsIfUnlockApps.contains(packageName) || mutedErrorsIfRestartApps.contains(packageName)) return@afterHook
/** 判断配置模块启用状态 */
if (prefs.get(DataConst.ENABLE_APP_CONFIG_TEMPLATE)) {
if (isAppShowNothing(packageName)) return@afterHook
if (isAppShowErrorsNotify(packageName)) {
context.pushNotify(
channelId = "APPS_ERRORS",
channelName = LocaleString.appName,
title = errorTitle,
content = LocaleString.appErrorsTip,
icon = IconCompat.createWithBitmap(R.mipmap.ic_notify.drawableOf(moduleAppResources).toBitmap()),
color = 0xFFFF6200.toInt(),
intent = AppErrorsRecordActivity.intent()
)
return@afterHook
}
if (isAppShowErrorsToast(packageName)) {
context.toast(errorTitle)
return@afterHook
}
}
/** 判断是否为后台进程 */
if ((isBackgroundProcess || context.isAppCanOpened(packageName).not())
&& prefs.get(DataConst.ENABLE_ONLY_SHOW_ERRORS_IN_FRONT)
) return@afterHook
/** 判断是否为主进程 */
if (isMainProcess.not() && prefs.get(DataConst.ENABLE_ONLY_SHOW_ERRORS_IN_MAIN)) return@afterHook
/** 判断配置模块启用状态 */
if (prefs.get(DataConst.ENABLE_APP_CONFIG_TEMPLATE)) {
if (isAppShowNothing(packageName)) return@afterHook
if (isAppShowErrorsToast(packageName)) {
context.toast(errorTitle)
return@afterHook
}
}
/** 启动错误对话框显示窗口 */
AppErrorsDisplayActivity.start(
context, AppErrorsDisplayBean(

View File

@@ -33,6 +33,12 @@ import com.highcapable.yukihookapi.hook.param.PackageParam
*/
fun PackageParam.isAppShowErrorsDialog(packageName: String) = prefs.getBoolean("${packageName}_show_errors_dialog", true)
/**
* 获取此 APP 是否配置显示错误通知推送
* @param packageName APP 包名
*/
fun PackageParam.isAppShowErrorsNotify(packageName: String) = prefs.getBoolean("${packageName}_show_errors_notify", false)
/**
* 获取此 APP 是否配置显示错误 Toast 提示
* @param packageName APP 包名
@@ -51,6 +57,12 @@ fun PackageParam.isAppShowNothing(packageName: String) = prefs.getBoolean("${pac
*/
fun Context.isAppShowErrorsDialog(packageName: String) = modulePrefs.getBoolean("${packageName}_show_errors_dialog", true)
/**
* 获取此 APP 是否配置显示错误通知推送
* @param packageName APP 包名
*/
fun Context.isAppShowErrorsNotify(packageName: String) = modulePrefs.getBoolean("${packageName}_show_errors_notify", false)
/**
* 获取此 APP 是否配置显示错误 Toast 提示
* @param packageName APP 包名
@@ -70,6 +82,13 @@ fun Context.isAppShowNothing(packageName: String) = modulePrefs.getBoolean("${pa
*/
fun Context.putAppShowErrorsDialog(packageName: String, isApply: Boolean) = modulePrefs.putBoolean("${packageName}_show_errors_dialog", isApply)
/**
* 设置此 APP 是否配置显示错误通知推送
* @param packageName APP 包名
* @param isApply 是否设置
*/
fun Context.putAppShowErrorsNotify(packageName: String, isApply: Boolean) = modulePrefs.putBoolean("${packageName}_show_errors_notify", isApply)
/**
* 设置此 APP 是否配置显示错误 Toast 提示
* @param packageName APP 包名

View File

@@ -418,4 +418,16 @@ object LocaleString {
/** @string Automatic generated */
fun moduleNotFullyActivatedTip(vararg objArrs: Any) = R.string.module_not_fully_activated_tip.bind(*objArrs)
/** @string Automatic generated */
val showErrorsNotify get() = showErrorsNotify()
/** @string Automatic generated */
fun showErrorsNotify(vararg objArrs: Any) = R.string.show_errors_notify.bind(*objArrs)
/** @string Automatic generated */
val appErrorsTip get() = appErrorsTip()
/** @string Automatic generated */
fun appErrorsTip(vararg objArrs: Any) = R.string.app_errors_tip.bind(*objArrs)
}

View File

@@ -24,12 +24,14 @@
package com.fankes.apperrorstracking.ui.activity.errors
import android.app.Activity
import android.content.ComponentName
import android.content.Intent
import android.view.ContextMenu
import android.view.MenuItem
import android.view.View
import android.widget.AdapterView.AdapterContextMenuInfo
import androidx.core.view.isVisible
import com.fankes.apperrorstracking.BuildConfig
import com.fankes.apperrorstracking.R
import com.fankes.apperrorstracking.bean.AppErrorsInfoBean
import com.fankes.apperrorstracking.bean.AppFiltersBean
@@ -50,6 +52,12 @@ class AppErrorsRecordActivity : BaseActivity<ActivityAppErrorsRecordBinding>() {
/** 请求保存文件回调标识 */
private const val WRITE_REQUEST_CODE = 0
/**
* 获取 [Intent]
* @return [Intent]
*/
fun intent() = Intent().apply { component = ComponentName(BuildConfig.APPLICATION_ID, AppErrorsRecordActivity::class.java.name) }
}
/** 当前导出文件的路径 */

View File

@@ -84,6 +84,7 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
binding.appNameText.text = bean.name
binding.configTypeText.text = when {
isAppShowErrorsDialog(bean.packageName) -> LocaleString.showErrorsDialog
isAppShowErrorsNotify(bean.packageName) -> LocaleString.showErrorsNotify
isAppShowErrorsToast(bean.packageName) -> LocaleString.showErrorsToast
isAppShowNothing(bean.packageName) -> LocaleString.showNothing
else -> "Unknown type"
@@ -95,11 +96,13 @@ class ConfigureActivity : BaseActivity<ActivityConfigBinding>() {
listData[p].also { bean ->
showDialog<DiaAppConfigBinding> {
title = bean.name
binding.configRadio1.isChecked = isAppShowErrorsDialog(bean.packageName)
binding.configRadio0.isChecked = isAppShowErrorsDialog(bean.packageName)
binding.configRadio1.isChecked = isAppShowErrorsNotify(bean.packageName)
binding.configRadio2.isChecked = isAppShowErrorsToast(bean.packageName)
binding.configRadio3.isChecked = isAppShowNothing(bean.packageName)
confirmButton {
putAppShowErrorsDialog(bean.packageName, binding.configRadio1.isChecked)
putAppShowErrorsDialog(bean.packageName, binding.configRadio0.isChecked)
putAppShowErrorsNotify(bean.packageName, binding.configRadio1.isChecked)
putAppShowErrorsToast(bean.packageName, binding.configRadio2.isChecked)
putAppShowNothing(bean.packageName, binding.configRadio3.isChecked)
onChanged?.invoke()

View File

@@ -23,17 +23,20 @@
package com.fankes.apperrorstracking.utils.factory
import android.app.Activity
import android.app.Service
import android.app.*
import android.content.*
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
import android.provider.Settings
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.core.content.getSystemService
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.IconCompat
import com.fankes.apperrorstracking.BuildConfig
import com.fankes.apperrorstracking.R
import com.fankes.apperrorstracking.locale.LocaleString
@@ -70,6 +73,13 @@ fun Number.dp(context: Context) = dpFloat(context).toInt()
*/
fun Number.dpFloat(context: Context) = toFloat() * context.resources.displayMetrics.density
/**
* 从 [Int] resId 获取 [Drawable]
* @param resources 使用的 [Resources]
* @return [Drawable]
*/
fun Int.drawableOf(resources: Resources) = ResourcesCompat.getDrawable(resources, this, null) ?: error("Invalid resources")
/**
* 获取 APP 名称
* @param packageName 包名
@@ -111,7 +121,7 @@ fun Context.appIcon(packageName: String) =
runCatching {
packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA)
.applicationInfo.loadIcon(packageManager)
}.getOrNull() ?: ResourcesCompat.getDrawable(resources, R.drawable.ic_android, null)
}.getOrNull() ?: R.drawable.ic_android.drawableOf(resources)
/**
* 计算与当前时间戳相差的友好时间
@@ -181,6 +191,31 @@ fun Context.snake(msg: String, actionText: String = "", callback: () -> Unit = {
setAction(actionText) { callback() }
}.show()
/**
* 推送通知
* @param channelId 渠道 Id
* @param channelName 渠道名称
* @param title 标题
* @param content 内容
* @param icon 图标
* @param color 颜色
* @param intent [Intent]
*/
fun Context.pushNotify(channelId: String, channelName: String, title: String, content: String, icon: IconCompat, color: Int, intent: Intent) {
getSystemService<NotificationManager>()?.apply {
createNotificationChannel(NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH))
notify((0..999).random(), NotificationCompat.Builder(this@pushNotify, channelId).apply {
this.color = color
setAutoCancel(true)
setContentTitle(title)
setContentText(content)
setSmallIcon(icon)
setContentIntent(PendingIntent.getActivity(this@pushNotify, (0..999).random(), intent, PendingIntent.FLAG_IMMUTABLE))
setDefaults(NotificationCompat.DEFAULT_ALL)
}.build())
}
}
/**
* 跳转到指定页面
*

View File

@@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorThemeBackground"

View File

@@ -23,12 +23,19 @@
android:layout_height="wrap_content">
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/config_radio_1"
android:id="@+id/config_radio_0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/show_errors_dialog"
app:buttonTint="@color/colorPrimaryAccent" />
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/config_radio_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/show_errors_notify"
app:buttonTint="@color/colorPrimaryAccent" />
<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/config_radio_2"
android:layout_width="match_parent"

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -80,7 +80,7 @@
<string name="view_muted_errors_apps">エラーを無視したアプリを表示する</string>
<string name="only_show_errors_in_front_tip">有効にすると、エラーが発生したアプリがフォアグラウンド(使用中)の場合にのみエラーダイアログが表示されます。エラーが発生したバックグラウンドアプリではエラーダイアログは表示されませんが、すべてがに記録されます。エラー履歴。</string>
<string name="only_show_errors_in_main_process_tip">有効にすると、エラーダイアログは、アプリで発生したエラーがメインプロセス(最初のアプリケーションインスタンスオブジェクト)にある場合にのみ表示されます。</string>
<string name="apps_config_template_tip">ここでは、アプリごとに個別にエラーが発生したときにエラーダイアログを表示するかどうかを設定できます。</string>
<string name="apps_config_template_tip">ここでは、アプリごとに個別にエラーが発生したときにエラーダイアログおよびその他のエラーメッセージを表示するかどうかを設定できます。</string>
<string name="view_errors_record_tip">ここでは、システムの電源を入れてから現在までのすべてのアプリエラーレコードを確認できます。エラー履歴はリスタート後に自動的にクリアされます。レコードの表示、エクスポート、共有、およびクリアが可能です。</string>
<string name="view_muted_errors_apps_tip">ここでは、さまざまな形式のエラーを手動で無視したアプリを見つけることができます。このリストは、リスタート後に自動的にクリアされます。これらの無視されたアプリを管理し、無視リストから削除できます。</string>
<string name="muted_errors_apps">エラーを無視したアプリ</string>
@@ -109,4 +109,6 @@
<string name="total_apps_unit">%1$s 個 (システムアプリを含む)</string>
<string name="generating_statistics">統計が生成されています</string>
<string name="module_not_fully_activated_tip">モジュールは完全にアクティブ化されておらず、現在の設定アイテムをロードできない場合があります。システムをリスタートして試してみることをお勧めします。</string>
<string name="show_errors_notify">エラー通知プッシュを表示</string>
<string name="app_errors_tip">アプリは未処理のエラーで崩壊しました。クリックして、アプリ開発者への詳細またはフィードバックを表示します。</string>
</resources>

View File

@@ -80,7 +80,7 @@
<string name="view_muted_errors_apps">查看已忽略异常的应用</string>
<string name="only_show_errors_in_front_tip">启用后,只有发生异常的应用处于前台(正在使用中)时才会显示错误对话框,发生异常的后台应用虽然不会显示错误对话框,但是它们都会被记录到异常历史记录中。</string>
<string name="only_show_errors_in_main_process_tip">启用后,只有应用发生的异常位于主进程(第一个 Application 实例对象)时才会显示错误对话框。</string>
<string name="apps_config_template_tip">你可以在这里对每个应用发生异常时,单独配置其在发生异常时是否显示错误对话框。</string>
<string name="apps_config_template_tip">你可以在这里对每个应用发生异常时,单独配置其在发生异常时是否显示错误对话框以及其它错误提示</string>
<string name="view_errors_record_tip">在这里,你可以找到从系统开机以来到现在为止的全部应用异常记录,异常历史记录在重新启动后会自动清空,你可以对记录进行查看、导出和分享以及清空。</string>
<string name="view_muted_errors_apps_tip">在这里,你可以找到已被你以不同形式手动忽略异常的应用,这个列表将会在重新启动后自动清空,你可以对这些已忽略的应用进行管理以及从忽略列表中移除它们。</string>
<string name="muted_errors_apps">已忽略异常的应用</string>
@@ -109,4 +109,6 @@
<string name="total_apps_unit">%1$s 个 (含系统应用)</string>
<string name="generating_statistics">正在生成统计数据</string>
<string name="module_not_fully_activated_tip">模块未完全激活,可能无法加载当前设置项,建议重新启动系统后重试。</string>
<string name="show_errors_notify">显示错误通知推送</string>
<string name="app_errors_tip">应用发生了未处理的异常而崩溃,点击查看详情或反馈给应用开发者。</string>
</resources>

View File

@@ -80,7 +80,7 @@
<string name="view_muted_errors_apps">查看已忽略異常的程式</string>
<string name="only_show_errors_in_front_tip">啟用後,只有發生異常的程式處於前台(正在使用中)時才會展示錯誤對話框,發生異常的後台程式雖然不會展示錯誤對話框,但是它們都會被記錄到異常歷史記錄中。</string>
<string name="only_show_errors_in_main_process_tip">啟用後,只有程式發生的異常位於主進程(第一個 Application 實例對象)時才會展示錯誤對話框。</string>
<string name="apps_config_template_tip">你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框。</string>
<string name="apps_config_template_tip">你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框以及其它錯誤提示</string>
<string name="view_errors_record_tip">在這裡,你可以找到從系統開機以來到現在為止的全部程式異常記錄,異常歷史記錄在重新啟動後會自動清空,你可以對記錄進行查看、導出和分享以及清空。</string>
<string name="view_muted_errors_apps_tip">在這裡,你可以找到已被你以不同形式手動忽略異常的程式,這個列表將會在重新啟動後自動清空,你可以對這些已忽略的程式進行管理以及從忽略列表中移除它們。</string>
<string name="muted_errors_apps">已忽略異常的程式</string>
@@ -109,4 +109,6 @@
<string name="total_apps_unit">%1$s 個 (含系統程式)</string>
<string name="generating_statistics">統計數據生成中</string>
<string name="module_not_fully_activated_tip">模組未完全激活,可能無法加載當前設定項,建議重新開機後重試。</string>
<string name="show_errors_notify">顯示錯誤通知推送</string>
<string name="app_errors_tip">程式發生了未處理的異常而崩潰,點擊查看詳情或反饋給程式開發者。</string>
</resources>

View File

@@ -80,7 +80,7 @@
<string name="view_muted_errors_apps">查看已忽略異常的程式</string>
<string name="only_show_errors_in_front_tip">啟用後,只有發生異常的程式處於前台(正在使用中)時才會展示錯誤對話框,發生異常的後台程式雖然不會展示錯誤對話框,但是它們都會被記錄到異常歷史記錄中。</string>
<string name="only_show_errors_in_main_process_tip">啟用後,只有程式發生的異常位於主進程(第一個 Application 實例對象)時才會展示錯誤對話框。</string>
<string name="apps_config_template_tip">你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框。</string>
<string name="apps_config_template_tip">你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框以及其它錯誤提示</string>
<string name="view_errors_record_tip">在這裡,你可以找到從系統開機以來到現在為止的全部程式異常記錄,異常歷史記錄在重新啟動後會自動清空,你可以對記錄進行查看、導出和分享以及清空。</string>
<string name="view_muted_errors_apps_tip">在這裡,你可以找到已被你以不同形式手動忽略異常的程式,這個列表將會在重新啟動後自動清空,你可以對這些已忽略的程式進行管理以及從忽略列表中移除它們。</string>
<string name="muted_errors_apps">已忽略異常的程式</string>
@@ -109,4 +109,6 @@
<string name="total_apps_unit">%1$s 個 (含系統程式)</string>
<string name="generating_statistics">統計數據生成中</string>
<string name="module_not_fully_activated_tip">模組未完全激活,可能無法加載當前設定項,建議重新開機後重試。</string>
<string name="show_errors_notify">顯示錯誤通知推送</string>
<string name="app_errors_tip">程式發生了未處理的異常而崩潰,點擊查看詳情或反饋給程式開發者。</string>
</resources>

View File

@@ -80,7 +80,7 @@
<string name="view_muted_errors_apps">查看已忽略異常的程式</string>
<string name="only_show_errors_in_front_tip">啟用後,只有發生異常的程式處於前台(正在使用中)時才會展示錯誤對話框,發生異常的後台程式雖然不會展示錯誤對話框,但是它們都會被記錄到異常歷史記錄中。</string>
<string name="only_show_errors_in_main_process_tip">啟用後,只有程式發生的異常位於主進程(第一個 Application 實例對象)時才會展示錯誤對話框。</string>
<string name="apps_config_template_tip">你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框。</string>
<string name="apps_config_template_tip">你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框以及其它錯誤提示</string>
<string name="view_errors_record_tip">在這裡,你可以找到從系統開機以來到現在為止的全部程式異常記錄,異常歷史記錄在重新啟動後會自動清空,你可以對記錄進行查看、導出和分享以及清空。</string>
<string name="view_muted_errors_apps_tip">在這裡,你可以找到已被你以不同形式手動忽略異常的程式,這個列表將會在重新啟動後自動清空,你可以對這些已忽略的程式進行管理以及從忽略列表中移除它們。</string>
<string name="muted_errors_apps">已忽略異常的程式</string>
@@ -109,4 +109,6 @@
<string name="total_apps_unit">%1$s 個 (含系統程式)</string>
<string name="generating_statistics">統計數據生成中</string>
<string name="module_not_fully_activated_tip">模組未完全激活,可能無法加載當前設定項,建議重新開機後重試。</string>
<string name="show_errors_notify">顯示錯誤通知推送</string>
<string name="app_errors_tip">程式發生了未處理的異常而崩潰,點擊查看詳情或反饋給程式開發者。</string>
</resources>

View File

@@ -80,7 +80,7 @@
<string name="view_muted_errors_apps">View muted errors apps</string>
<string name="only_show_errors_in_front_tip">After enabling, the error dialog will only be displayed when the abnormal apps is in the foreground (in use). Although the abnormal background application will not display the error dialog, they will be recorded in the errors history.</string>
<string name="only_show_errors_in_main_process_tip">After enabling, the error dialog will only be displayed if the exception occurred in the application is in the main process (the first Application instance object).</string>
<string name="apps_config_template_tip">Here you can individually configure whether to display an error dialog when an exception occurs for each apps.</string>
<string name="apps_config_template_tip">Here you can individually configure whether to display an error dialog and other error tips when an exception occurs for each apps.</string>
<string name="view_errors_record_tip">Here you can find all apps errors records since the system was turned on until now. The exception history will be automatically cleared after restarting. You can view, export, share and clear the records.</string>
<string name="view_muted_errors_apps_tip">Here you can find apps that you have manually muted errors in different forms. This list will be automatically cleared after restarting. You can manage these ignored applications and remove them from the mute list.</string>
<string name="muted_errors_apps">Muted Errors Apps</string>
@@ -109,4 +109,6 @@
<string name="total_apps_unit">%1$s (including system apps)</string>
<string name="generating_statistics">Generating statistics</string>
<string name="module_not_fully_activated_tip">The module is not fully activated and may not be able to load the current settings item. It is recommended to re -start the system and try it out.</string>
<string name="show_errors_notify">Show errors notification</string>
<string name="app_errors_tip">App collapses an unprocessed abnormality. Click to view details or feedback to the App developer.</string>
</resources>