leakcanary icon indicating copy to clipboard operation
leakcanary copied to clipboard

Support Android 13 run time notification permission

Open ashish-kshirsagar opened this issue 3 years ago • 1 comments

Problem description

Android 13 is changing the requirement for notification permission to run-time grant by user instead of auto grant. Refer this link.

Due to this change for apps that are not changing target SDK version to 33 have no control over permission rationale dialog and it is shown to user as soon as a notification channel is created or a notification is posted by app. With using LeakCanary, notification channel is created upon finding first leak and hence causes a permission dialog to be shown. Refer screenshot displayed in third screen at this link. So app has no control on when this permission dialog shows up. This affects the user behavior and there isn't any work around.

Expecting a way to control the leak canary notifications to be generated only after a certain point after notification permission is granted.

Potential solutions

There can be couple of solutions possible.

  1. Allow app to control enablement of notifications for LeakCanary. So App can control run time permission before any notification is shown.
  2. LeakCanary can check if notification permission granted for an app and only then show leak notifications.

Additional information

Not specific with app but can be checked with any app that targets lower than 33 API and includes leak canary. Refer to a comment for related change https://github.com/square/leakcanary/pull/2395#issuecomment-1175168639

ashish-kshirsagar avatar Jul 08 '22 20:07 ashish-kshirsagar

Thx. The linked PR would help with disabling / delaying notifications until the permission is granted.

However, I'm not clear what the default behavior when you don't set anything should be.

pyricau avatar Jul 13 '22 13:07 pyricau

One of the drivers here is to allow apps to control when we should attempt to show notifications, for scenarios where we don't want that permission to show up.

pyricau avatar Nov 09 '22 23:11 pyricau

As a first step, we'll add a control to allow disabling all LeakCanary notifications.

pyricau avatar Nov 10 '22 19:11 pyricau

@pyricau I still want the notifications, but I want to be the one to request for the permission and Leak Canary should show notifications after that. Is that possible at the moment?

SunnyBe avatar Jan 26 '23 16:01 SunnyBe

I believe yes, just set LeakCanary.config.showNotifications to false (=> won't show notifications) and then set it to true once you've gotten the permission.

pyricau avatar Feb 07 '23 19:02 pyricau