Skip to content

Bug: Perms dialogs may stack causing confusing UI #114

@williscool

Description

@williscool

Bug: Permission dialogs may stack causing confusing UX

The checkNotificationPermission() call at line 260 is non-blocking - it either shows an AlertDialog or triggers the system permission request, both of which return immediately. The code then proceeds directly to the battery optimization check at line 263, which may show another AlertDialog. On Android 13+ devices that haven't granted notification permission and haven't dismissed the battery warning, both dialogs can appear simultaneously, stacking on top of each other and confusing users. The battery optimization check needs to be deferred until after the notification permission flow completes.

android/app/src/main/java/com/github/quarck/calnotify/ui/MainActivity.kt#L258-L286

else {
// Check notification permission (Android 13+)
checkNotificationPermission()
// if we have essential permissions - now check for power manager optimisations
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !settings.doNotShowBatteryOptimisationWarning) {
if (!powerManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID)) {
AlertDialog.Builder(this)
.setTitle(getString(R.string.battery_optimisation_title))
.setMessage(getString(R.string.battery_optimisation_details))
.setPositiveButton(getString(R.string.you_can_do_it)) @TargetApi(Build.VERSION_CODES.M) {
_, _ ->
val intent = Intent()
.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
.setData(Uri.parse("package:" + BuildConfig.APPLICATION_ID))
startActivity(intent)
}
.setNeutralButton(getString(R.string.you_can_do_it_later)) {
_, _ ->
}
.setNegativeButton(getString(R.string.you_cannot_do_it)) {
_, _ ->
settings.doNotShowBatteryOptimisationWarning = true
}
.create()
.show()
}

android/app/src/main/java/com/github/quarck/calnotify/ui/MainActivity.kt#L294-L314

*/
private fun checkNotificationPermission() {
if (!PermissionsManager.hasNotificationPermission(this)) {
if (PermissionsManager.shouldShowNotificationRationale(this)) {
AlertDialog.Builder(this)
.setTitle(R.string.notification_permission_title)
.setMessage(R.string.notification_permission_explanation)
.setCancelable(false)
.setPositiveButton(android.R.string.ok) { _, _ ->
PermissionsManager.requestNotificationPermission(this)
}
.setNegativeButton(R.string.cancel) { _, _ ->
// User declined, they won't get notifications
}
.create()
.show()
} else {
PermissionsManager.requestNotificationPermission(this)
}
}
}

Fix in Cursor Fix in Web


Originally posted by @cursor[bot] in #113 (review)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions