onesignal-expo-plugin icon indicating copy to clipboard operation
onesignal-expo-plugin copied to clipboard

[Bug]: Android 13 runtime notification permission not requested

Open AdamDiament opened this issue 1 year ago • 4 comments

What happened?

  • A user upgraded his Android OS to Android 13
  • They installed my app from the play store
  • The device is seen in the users section of the expo portal, but with "permission not granted" status
  • The user had to manually go into android settings for the app, and manually add permission for notifications in order to receive notifications

Steps to reproduce?

* Setup a basic expo app with onesignal plugin
Make sure OneSignal.setAppId and OneSignal.promptForPushNotificationsWithUserResponse are called
* Launch it on a phone with Android 13 installed
* The app will never ask for notification permission even when promptForPushNotificationsWithUserResponse is called

What did you expect to happen?

I expected the app to request the user's permission for notifications with a popup - as per the onesignal documentation here https://documentation.onesignal.com/docs/android-13-push-notification-developer-update-guide since I am using the latest expo sdk

OneSignal Expo SDK version

"onesignal-expo-plugin": "^1.0.2", "react-native-onesignal": "^4.4.0", "expo": "^46.0.0",

Platform

Android

Relevant log output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

AdamDiament avatar Aug 24 '22 07:08 AdamDiament

UPDATE I see that the expo main build.gradle https://github.com/expo/expo/blob/main/android/app/build.gradle only sets 31 as the compileSDKVersion. Does this mean what I am seeing on an android 13 device is expected behaviour until expo themselves release an sdk compiled for Android 13?

AdamDiament avatar Aug 24 '22 09:08 AdamDiament

Hi @AdamDiament thanks for reporting, I will look into this today!

brismithers avatar Aug 26 '22 12:08 brismithers

I think I have an understanding @AdamDiament!

I've confirmed when you run an app for the first time with the default compileSDKVersion of 31, notifications are immediately denied without prompting the user. I haven't figured out why this is happening yet, but it looks to be something expo/react/development environment related. This might be related. I will look into this further.

OneSignal recommends setting the compileSdkVersion and targetSdkVersion to 33 as it gives the most flexibility and control when requesting notification permissions. As you said the expo default is 31, however the expo-build-properties plugin allows you to override these defaults! I believe if you add this plugin and set compileSdkVersion and targetSdkVersion to 33, the issue you are seeing above will be resolved. Please let me know.

On confirmation, I will update our Android 13 Update Guide to include this additional information for expo developers.

Thanks!

brismithers avatar Aug 26 '22 15:08 brismithers

Thanks for looking into this @brismithers . I followed your advice and used expo-build-properties to set both compileSdkVersion and targetSDKVersion to 33. I built the app on eas with only that change, and it crashes at launch now, after the splash screen is show but before the first app screen.

Running logcat shows this exception. (This is running on a Google Pixel 6 on Android 13)

08-28 13:40:08.570 19612 19697 E ReactNativeJS: Error: Exception in HostObject::get(propName:NativeUnimoduleProxy): java.lang.SecurityException: Settings key: <bluetooth_name> is only readable to apps with targetSdkVersion lower than or equal to: 31
08-28 13:40:08.575 19612 19697 E ReactNativeJS: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
08-28 13:40:08.575 19612 19697 E ReactNativeJS:       This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: Unhandled SoftException
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: java.lang.RuntimeException: Catalyst Instance has already disappeared: requested by FrescoModule
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at com.facebook.react.bridge.ReactContextBaseJavaModule.getReactApplicationContextIfActiveOrWarn(ReactContextBaseJavaModule.java:66)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at com.facebook.react.modules.fresco.FrescoModule.invalidate(FrescoModule.java:202)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at com.facebook.react.bridge.ModuleHolder.destroy(ModuleHolder.java:110)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at com.facebook.react.bridge.NativeModuleRegistry.notifyJSInstanceDestroy(NativeModuleRegistry.java:108)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at com.facebook.react.bridge.CatalystInstanceImpl$1.run(CatalystInstanceImpl.java:368)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at android.os.Handler.handleCallback(Handler.java:942)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at android.os.Looper.loopOnce(Looper.java:201)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at android.os.Looper.loop(Looper.java:288)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
08-28 13:40:08.576 19612 19698 E unknown:ReactContextBaseJavaModule: 	at java.lang.Thread.run(Thread.java:1012)

It's odd because I don't have any Bluetooth functionality in my app. But it does say it could be a corrupt JS bundle. Any thoughts appreciated!

More full stack trace is here

--------- beginning of crash
08-28 13:40:09.951 19612 19659 E AndroidRuntime: FATAL EXCEPTION: expo-updates-error-recovery
08-28 13:40:09.951 19612 19659 E AndroidRuntime: Process: il.co.appli.visionforisraelnew, PID: 19612
08-28 13:40:09.951 19612 19659 E AndroidRuntime: com.facebook.react.common.JavascriptException: Error: Exception in HostObject::get(propName:NativeUnimoduleProxy): java.lang.SecurityException: Settings key: <bluetooth_name> is only readable to apps with targetSdkVersion lower than or equal to: 31, stack:
08-28 13:40:09.951 19612 19659 E AndroidRuntime: <unknown>@392:181
08-28 13:40:09.951 19612 19659 E AndroidRuntime: h@2:1585
08-28 13:40:09.951 19612 19659 E AndroidRuntime: <unknown>@14:1245
08-28 13:40:09.951 19612 19659 E AndroidRuntime: h@2:1585
08-28 13:40:09.951 19612 19659 E AndroidRuntime: <unknown>@11:440
08-28 13:40:09.951 19612 19659 E AndroidRuntime: h@2:1585
08-28 13:40:09.951 19612 19659 E AndroidRuntime: <unknown>@10:482
08-28 13:40:09.951 19612 19659 E AndroidRuntime: h@2:1585
08-28 13:40:09.951 19612 19659 E AndroidRuntime: <unknown>@9:43
08-28 13:40:09.951 19612 19659 E AndroidRuntime: h@2:1585
08-28 13:40:09.951 19612 19659 E AndroidRuntime: <unknown>@8:350
08-28 13:40:09.951 19612 19659 E AndroidRuntime: h@2:1585
08-28 13:40:09.951 19612 19659 E AndroidRuntime: <unknown>@6:47
08-28 13:40:09.951 19612 19659 E AndroidRuntime: h@2:1585
08-28 13:40:09.951 19612 19659 E AndroidRuntime: d@2:958
08-28 13:40:09.951 19612 19659 E AndroidRuntime: global code@2407:3
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:72)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:942)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at android.os.Looper.loopOnce(Looper.java:201)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:288)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
08-28 13:40:09.951 19612 19659 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:1012)

I suppose it could be one of my plugins or libraries with a Bluetooth dependency, or perhaps something in the Facebook integration itself.

https://stackoverflow.com/questions/72271363/what-is-changed-with-bluetooth-in-android-sdk-32 shows similar problems

AdamDiament avatar Aug 28 '22 10:08 AdamDiament

@AdamDiament I see the expo issue has been closed, I'm closing this issue as well but please let me know if there are any additional issues!

brismithers avatar Oct 06 '22 15:10 brismithers