diff --git a/app/src/main/java/com/fankes/apperrorstracking/hook/entity/FrameworkHooker.kt b/app/src/main/java/com/fankes/apperrorstracking/hook/entity/FrameworkHooker.kt index e02ba28..b5f1d57 100644 --- a/app/src/main/java/com/fankes/apperrorstracking/hook/entity/FrameworkHooker.kt +++ b/app/src/main/java/com/fankes/apperrorstracking/hook/entity/FrameworkHooker.kt @@ -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( diff --git a/app/src/main/java/com/fankes/apperrorstracking/hook/factory/DataFactory.kt b/app/src/main/java/com/fankes/apperrorstracking/hook/factory/DataFactory.kt index f45ba02..c5b1310 100644 --- a/app/src/main/java/com/fankes/apperrorstracking/hook/factory/DataFactory.kt +++ b/app/src/main/java/com/fankes/apperrorstracking/hook/factory/DataFactory.kt @@ -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 包名 diff --git a/app/src/main/java/com/fankes/apperrorstracking/locale/LocaleString.kt b/app/src/main/java/com/fankes/apperrorstracking/locale/LocaleString.kt index 9742a76..9454f72 100644 --- a/app/src/main/java/com/fankes/apperrorstracking/locale/LocaleString.kt +++ b/app/src/main/java/com/fankes/apperrorstracking/locale/LocaleString.kt @@ -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) } \ No newline at end of file diff --git a/app/src/main/java/com/fankes/apperrorstracking/ui/activity/errors/AppErrorsRecordActivity.kt b/app/src/main/java/com/fankes/apperrorstracking/ui/activity/errors/AppErrorsRecordActivity.kt index 1029679..060c8be 100644 --- a/app/src/main/java/com/fankes/apperrorstracking/ui/activity/errors/AppErrorsRecordActivity.kt +++ b/app/src/main/java/com/fankes/apperrorstracking/ui/activity/errors/AppErrorsRecordActivity.kt @@ -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() { /** 请求保存文件回调标识 */ private const val WRITE_REQUEST_CODE = 0 + + /** + * 获取 [Intent] + * @return [Intent] + */ + fun intent() = Intent().apply { component = ComponentName(BuildConfig.APPLICATION_ID, AppErrorsRecordActivity::class.java.name) } } /** 当前导出文件的路径 */ diff --git a/app/src/main/java/com/fankes/apperrorstracking/ui/activity/main/ConfigureActivity.kt b/app/src/main/java/com/fankes/apperrorstracking/ui/activity/main/ConfigureActivity.kt index b26a869..c0f0547 100644 --- a/app/src/main/java/com/fankes/apperrorstracking/ui/activity/main/ConfigureActivity.kt +++ b/app/src/main/java/com/fankes/apperrorstracking/ui/activity/main/ConfigureActivity.kt @@ -84,6 +84,7 @@ class ConfigureActivity : BaseActivity() { 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() { listData[p].also { bean -> showDialog { 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() diff --git a/app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt b/app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt index 32ec02d..ced4bda 100644 --- a/app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt +++ b/app/src/main/java/com/fankes/apperrorstracking/utils/factory/FunctionFactory.kt @@ -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()?.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()) + } +} + /** * 跳转到指定页面 * diff --git a/app/src/main/res/layout/activity_app_errors_detail.xml b/app/src/main/res/layout/activity_app_errors_detail.xml index 9190175..8221b47 100644 --- a/app/src/main/res/layout/activity_app_errors_detail.xml +++ b/app/src/main/res/layout/activity_app_errors_detail.xml @@ -2,6 +2,7 @@ + + エラーを無視したアプリを表示する 有効にすると、エラーが発生したアプリがフォアグラウンド(使用中)の場合にのみエラーダイアログが表示されます。エラーが発生したバックグラウンドアプリではエラーダイアログは表示されませんが、すべてがに記録されます。エラー履歴。 有効にすると、エラーダイアログは、アプリで発生したエラーがメインプロセス(最初のアプリケーションインスタンスオブジェクト)にある場合にのみ表示されます。 - ここでは、アプリごとに個別にエラーが発生したときにエラーダイアログを表示するかどうかを設定できます。 + ここでは、アプリごとに個別にエラーが発生したときにエラーダイアログおよびその他のエラーメッセージを表示するかどうかを設定できます。 ここでは、システムの電源を入れてから現在までのすべてのアプリエラーレコードを確認できます。エラー履歴はリスタート後に自動的にクリアされます。レコードの表示、エクスポート、共有、およびクリアが可能です。 ここでは、さまざまな形式のエラーを手動で無視したアプリを見つけることができます。このリストは、リスタート後に自動的にクリアされます。これらの無視されたアプリを管理し、無視リストから削除できます。 エラーを無視したアプリ @@ -109,4 +109,6 @@ %1$s 個 (システムアプリを含む) 統計が生成されています モジュールは完全にアクティブ化されておらず、現在の設定アイテムをロードできない場合があります。システムをリスタートして試してみることをお勧めします。 + エラー通知プッシュを表示 + アプリは未処理のエラーで崩壊しました。クリックして、アプリ開発者への詳細またはフィードバックを表示します。 \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 44ccdea..fc89a12 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -80,7 +80,7 @@ 查看已忽略异常的应用 启用后,只有发生异常的应用处于前台(正在使用中)时才会显示错误对话框,发生异常的后台应用虽然不会显示错误对话框,但是它们都会被记录到异常历史记录中。 启用后,只有应用发生的异常位于主进程(第一个 Application 实例对象)时才会显示错误对话框。 - 你可以在这里对每个应用发生异常时,单独配置其在发生异常时是否显示错误对话框。 + 你可以在这里对每个应用发生异常时,单独配置其在发生异常时是否显示错误对话框以及其它错误提示。 在这里,你可以找到从系统开机以来到现在为止的全部应用异常记录,异常历史记录在重新启动后会自动清空,你可以对记录进行查看、导出和分享以及清空。 在这里,你可以找到已被你以不同形式手动忽略异常的应用,这个列表将会在重新启动后自动清空,你可以对这些已忽略的应用进行管理以及从忽略列表中移除它们。 已忽略异常的应用 @@ -109,4 +109,6 @@ %1$s 个 (含系统应用) 正在生成统计数据 模块未完全激活,可能无法加载当前设置项,建议重新启动系统后重试。 + 显示错误通知推送 + 应用发生了未处理的异常而崩溃,点击查看详情或反馈给应用开发者。 \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 866c947..651f02a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -80,7 +80,7 @@ 查看已忽略異常的程式 啟用後,只有發生異常的程式處於前台(正在使用中)時才會展示錯誤對話框,發生異常的後台程式雖然不會展示錯誤對話框,但是它們都會被記錄到異常歷史記錄中。 啟用後,只有程式發生的異常位於主進程(第一個 Application 實例對象)時才會展示錯誤對話框。 - 你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框。 + 你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框以及其它錯誤提示。 在這裡,你可以找到從系統開機以來到現在為止的全部程式異常記錄,異常歷史記錄在重新啟動後會自動清空,你可以對記錄進行查看、導出和分享以及清空。 在這裡,你可以找到已被你以不同形式手動忽略異常的程式,這個列表將會在重新啟動後自動清空,你可以對這些已忽略的程式進行管理以及從忽略列表中移除它們。 已忽略異常的程式 @@ -109,4 +109,6 @@ %1$s 個 (含系統程式) 統計數據生成中 模組未完全激活,可能無法加載當前設定項,建議重新開機後重試。 + 顯示錯誤通知推送 + 程式發生了未處理的異常而崩潰,點擊查看詳情或反饋給程式開發者。 \ No newline at end of file diff --git a/app/src/main/res/values-zh-rMO/strings.xml b/app/src/main/res/values-zh-rMO/strings.xml index 37157aa..d917ff8 100644 --- a/app/src/main/res/values-zh-rMO/strings.xml +++ b/app/src/main/res/values-zh-rMO/strings.xml @@ -80,7 +80,7 @@ 查看已忽略異常的程式 啟用後,只有發生異常的程式處於前台(正在使用中)時才會展示錯誤對話框,發生異常的後台程式雖然不會展示錯誤對話框,但是它們都會被記錄到異常歷史記錄中。 啟用後,只有程式發生的異常位於主進程(第一個 Application 實例對象)時才會展示錯誤對話框。 - 你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框。 + 你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框以及其它錯誤提示。 在這裡,你可以找到從系統開機以來到現在為止的全部程式異常記錄,異常歷史記錄在重新啟動後會自動清空,你可以對記錄進行查看、導出和分享以及清空。 在這裡,你可以找到已被你以不同形式手動忽略異常的程式,這個列表將會在重新啟動後自動清空,你可以對這些已忽略的程式進行管理以及從忽略列表中移除它們。 已忽略異常的程式 @@ -109,4 +109,6 @@ %1$s 個 (含系統程式) 統計數據生成中 模組未完全激活,可能無法加載當前設定項,建議重新開機後重試。 + 顯示錯誤通知推送 + 程式發生了未處理的異常而崩潰,點擊查看詳情或反饋給程式開發者。 \ No newline at end of file diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 8bf02d1..e1b1fed 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -80,7 +80,7 @@ 查看已忽略異常的程式 啟用後,只有發生異常的程式處於前台(正在使用中)時才會展示錯誤對話框,發生異常的後台程式雖然不會展示錯誤對話框,但是它們都會被記錄到異常歷史記錄中。 啟用後,只有程式發生的異常位於主進程(第一個 Application 實例對象)時才會展示錯誤對話框。 - 你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框。 + 你可以在這裡對每個程式發生異常時,單獨配置其在發生異常時是否展示錯誤對話框以及其它錯誤提示。 在這裡,你可以找到從系統開機以來到現在為止的全部程式異常記錄,異常歷史記錄在重新啟動後會自動清空,你可以對記錄進行查看、導出和分享以及清空。 在這裡,你可以找到已被你以不同形式手動忽略異常的程式,這個列表將會在重新啟動後自動清空,你可以對這些已忽略的程式進行管理以及從忽略列表中移除它們。 已忽略異常的程式 @@ -109,4 +109,6 @@ %1$s 個 (含系統程式) 統計數據生成中 模組未完全激活,可能無法加載當前設定項,建議重新開機後重試。 + 顯示錯誤通知推送 + 程式發生了未處理的異常而崩潰,點擊查看詳情或反饋給程式開發者。 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9302123..3b04c18 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -80,7 +80,7 @@ View muted errors apps 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. 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). - Here you can individually configure whether to display an error dialog when an exception occurs for each apps. + Here you can individually configure whether to display an error dialog and other error tips when an exception occurs for each apps. 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. 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. Muted Errors Apps @@ -109,4 +109,6 @@ %1$s (including system apps) Generating statistics 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. + Show errors notification + App collapses an unprocessed abnormality. Click to view details or feedback to the App developer. \ No newline at end of file