2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

Bug 1834766 - Fix device notifications screen navigation crash

This commit is contained in:
rahulsainani 2023-05-25 10:14:17 +02:00 committed by mergify[bot]
parent 86e3da9898
commit c10a59510d
3 changed files with 25 additions and 21 deletions

View File

@ -156,23 +156,6 @@ private fun Activity.openDefaultBrowserSumoPage(
}
}
/**
* Checks for the presence of an activity before starting it. In case it's not present,
* [onActivityNotPresent] is invoked, preventing ActivityNotFoundException from being thrown.
* This is useful when navigating to external activities like device permission settings,
* notification settings, default app settings, etc.
*
* @param intent The Intent of the activity to resolve and start.
* @param onActivityNotPresent Invoked when the activity to handle the intent is not present.
*/
inline fun Activity.startExternalActivitySafe(intent: Intent, onActivityNotPresent: () -> Unit) {
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
} else {
onActivityNotPresent()
}
}
/**
* Sets the icon for the back (up) navigation button.
* @param icon The resource id of the icon.

View File

@ -88,9 +88,13 @@ val Context.accessibilityManager: AccessibilityManager get() =
getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
/**
* Used to navigate to system notifications settings for app
* Used to navigate to system notifications settings for app.
*
* @param onError Invoked when the activity described by the intent is not present on the device.
*/
fun Context.navigateToNotificationsSettings() {
fun Context.navigateToNotificationsSettings(
onError: () -> Unit,
) {
val intent = Intent()
intent.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -102,7 +106,24 @@ fun Context.navigateToNotificationsSettings() {
it.putExtra("app_uid", this.applicationInfo.uid)
}
}
startActivity(intent)
startExternalActivitySafe(intent, onError)
}
/**
* Checks for the presence of an activity before starting it. In case it's not present,
* [onActivityNotPresent] is invoked, preventing ActivityNotFoundException from being thrown.
* This is useful when navigating to external activities like device permission settings,
* notification settings, default app settings, etc.
*
* @param intent The Intent of the activity to resolve and start.
* @param onActivityNotPresent Invoked when the activity to handle the intent is not present.
*/
inline fun Context.startExternalActivitySafe(intent: Intent, onActivityNotPresent: () -> Unit) {
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
} else {
onActivityNotPresent()
}
}
/**

View File

@ -354,7 +354,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataOnQuitFragment()
}
resources.getString(R.string.pref_key_notifications) -> {
context?.navigateToNotificationsSettings()
context?.navigateToNotificationsSettings {}
null
}
resources.getString(R.string.pref_key_customize) -> {