Fix dialog leak in RequestPermissionActivity

Dialog still show when activity destroyed will cause leak.

Dismiss dialog when activity onDestroy to fix this issue.

Fix: 279522922
Test: Manually with "Don't keep activities"
Test: Robolectric Test
Change-Id: I445f4b160020823a6f6e2883055218c1224e2c48
This commit is contained in:
Chaohui Wang
2023-05-04 19:26:44 +08:00
parent 08b2b68e22
commit 39bf7dd530
4 changed files with 175 additions and 56 deletions

View File

@@ -30,20 +30,20 @@ object RequestPermissionHelper {
timeout: Int,
onAllow: () -> Unit,
onDeny: () -> Unit,
) {
): AlertDialog? {
if (context.resources.getBoolean(R.bool.auto_confirm_bluetooth_activation_dialog)) {
// Don't even show the dialog if configured this way
onAllow()
return
return null
}
AlertDialog.Builder(context).apply {
return AlertDialog.Builder(context).apply {
setMessage(context.getEnableMessage(timeout, appLabel))
setPositiveButton(R.string.allow) { _, _ ->
if (context.isDisallowBluetooth()) onDeny() else onAllow()
}
setNegativeButton(R.string.deny) { _, _ -> onDeny() }
setOnCancelListener { onDeny() }
}.show()
}.create()
}
fun requestDisable(
@@ -51,18 +51,18 @@ object RequestPermissionHelper {
appLabel: CharSequence?,
onAllow: () -> Unit,
onDeny: () -> Unit,
) {
): AlertDialog? {
if (context.resources.getBoolean(R.bool.auto_confirm_bluetooth_activation_dialog)) {
// Don't even show the dialog if configured this way
onAllow()
return
return null
}
AlertDialog.Builder(context).apply {
return AlertDialog.Builder(context).apply {
setMessage(context.getDisableMessage(appLabel))
setPositiveButton(R.string.allow) { _, _ -> onAllow() }
setNegativeButton(R.string.deny) { _, _ -> onDeny() }
setOnCancelListener { onDeny() }
}.show()
}.create()
}
}