react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

Android 13 - Notification permission requested on boot

Open JorenVos opened this issue 2 years ago • 14 comments

After adding the react-native-background-geolocation package to our project, the user has to grant permission on boot. You don't have to call any functionality, just installing the package is enough to encounter this issue.

Your Environment

  • Plugin version: 4.8.2
  • Platform: Android
  • OS version: 13
  • Device manufacturer / model: Google Pixel 6a
  • React Native version: 0.64.2
  • Plugin config: Not important, installing library is enough to encounter this issue

Expected Behavior

When booting an application on Android 13 that has react-native-background-geolocation installed, users will see the native notification permission request. In our code, no interaction with any RN Background Geolocation-functionality is done. It should not be requested on boot without any RN Background Geolocation-interaction.

Actual Behavior

The library should not request notification permission

Steps to Reproduce

  1. Add the library to your project
  2. Boot the app
  3. (Eventually, kill and boot again)
  4. Notification permission is requested

JorenVos avatar Aug 30 '22 09:08 JorenVos

I have not yet tested in Android 13

christocracy avatar Aug 30 '22 14:08 christocracy

This is a UX-blocker for us in production, it's not the way we want to request permissions from our users. Is it possible to get yourself an Android 13 device and test/reproduce/fix this issue?

JorenVos avatar Aug 30 '22 15:08 JorenVos

I’ll be installing Android 13 soon.

christocracy avatar Aug 30 '22 15:08 christocracy

After a fresh install of Android 13 on my Pixel 6, I don’t notice anything unusual and the demo app operates exactly as before.

I will try now with a fresh install of demo app.

christocracy avatar Aug 30 '22 18:08 christocracy

After fresh install of demo app on Android 13, terminate app, reboot app: I don't see anything about a "Notification permission requested".

I'm using:

    compileSdkVersion   = 33
    targetSdkVersion    = 33

christocracy avatar Aug 30 '22 20:08 christocracy

I did a fresh install of the app from the Play Store and the first thing I see is: Notification permission request.

It's in Dutch, but it's really strange that you don't see the notification popup.

https://user-images.githubusercontent.com/10380088/187535210-997861d0-bcce-4aed-9572-f55e5f11e4ec.mp4

JorenVos avatar Aug 30 '22 20:08 JorenVos

Create for me simple Hello World app which reproduces this for me. Share it in a public GitHub repo.

christocracy avatar Aug 30 '22 20:08 christocracy

Followed the setup instructions to add the library to a clean project. Same behavior happens after a restart of the app.

SampleProject.zip

I do not have access to the codebase of the internal library, but I think that (for debugging purposes) a NotificationChannel might be created on boot?

https://developer.android.com/develop/ui/views/notifications/notification-permission

If your app targets 12L (API level 32) or lower, the system shows the permission dialog the first time your app starts an activity after you create a notification channel, or when your app starts an activity and then creates its first notification channel. This is usually on app startup.

When setting compileSdkVersion and targetSdkVersion to 33, the problem is indeed resolved.

https://user-images.githubusercontent.com/10380088/187632169-7a18b8ab-44bf-4c24-b6ce-565010d3dc12.mp4

JorenVos avatar Aug 31 '22 08:08 JorenVos

When setting compileSdkVersion and targetSdkVersion to 33, the problem is indeed resolved.

Correct. This is what you have to do. See Notification Permission Exemptions:

Screen Shot 2022-08-31 at 9 50 44 AM

I am using targetSdkVersion 33 / compileSdkVersion 33 locally here. This is why I didn't see the runtime permission. When I downgrade to targetSdkVersion 31, I do experience the behaviour you describe.

christocracy avatar Aug 31 '22 13:08 christocracy

Also see the Best Practices section: Updates your app's target SDK version

Screen Shot 2022-08-31 at 10 06 24 AM

christocracy avatar Aug 31 '22 14:08 christocracy

In my opinion, it still needs a fix. react-native-background-geolocation should not ask for notification permissions because these are only used for debugging purposes. Everyone who's using this package and has not updated their targetSdkVersion or compileSdkVersion will have to deal with the notification permission package.

It might be useful to create the notification channels only when debugging is on. Otherwise, everyone will have a notification channel for debugging this library, even end-users who will never see notifications from react-native-background-geolocation.

JorenVos avatar Aug 31 '22 15:08 JorenVos

should not ask for notification permissions because these are only used for debugging purposes

No. This is not for debugging purposes, at all. This is the Required Persistent Notification for Foreground Services.

Screen Shot 2022-08-31 at 11 14 15 AM

The Android plugin does not use notifications for debugging.

christocracy avatar Aug 31 '22 15:08 christocracy

It should not request the permission before a config or init of the library is called. The fact that this library can cause a permission request on boot is unwanted.

JorenVos avatar Sep 01 '22 08:09 JorenVos

It's wrong in the first place for Android 13 to request notification run-time permission for foreground-services — targetSdkVersion 33 fixes that wrong.

christocracy avatar Sep 01 '22 12:09 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jun 07 '24 01:06 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 22 '24 01:06 github-actions[bot]