OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
606 stars 204 forks source link

[Bug]: No push notifications after reboot until I unlock the phone 1 time (AKA support for Android's directBootAware) #897

Open uj opened 3 months ago

uj commented 3 months ago

What happened?

Push notifications work after I install the app. They work if I force close the app.

However, if I reboot the phone, they do not work UNTIL after I unlock the phone 1 time. Then, they work fine. After that, I can lock the phone again and they still work. I can force close the app, lock the phone, and they still work.

However, if I reboot again, they do not work until I again unlock the phone 1 time after the reboot.

Every time I reboot, they stop working until after the first unlock and then everything is good from that point forward (until the next reboot).

Steps to reproduce?

Use Android 14
Create Flutter app with OneSignal Flutter SDK 3.5.2
Test that push notifications work.
Reboot phone, do not unlock.
Notice that push notifications do not work.
Unlock phone.
Push notifications work.

What did you expect to happen?

I expect push notifications to work after a reboot even if the phone has not yet been unlocked for the 1st time.

OneSignal Android SDK version

3.5.2

Android version

13

Specific Android models

NOT 13!  This is Android 14 (The bug report here with "Android Version" dropdown doesn't have 14 as a choice!  It goes up to 13 and forces you to choose - please fix that!).

Google Pixel 7

Relevant log output

No response

Code of Conduct

jennantilla commented 3 months ago

@uj thanks for the report. That's interesting behavior. Android phones do tend to behave a bit unpredictably in a force-stop state which can vary between device manufacturer. We have some troubleshooting tips here. Can you let us know if any of those tips help?

I'll also update the dropdown to include Android 14. Just to confirm, have you tested on any other Android versions/noticed any differences in behavior (I wouldn't expect it, but just wanted to check!).

uj commented 3 months ago

I assume it is because newer phones are encrypted, and by default, apps cannot run before the initial login after a boot because of that encryption. The initial login provides the decryption.

There is an android:directBootAware attribute that can be enabled, which will allow an app to use some special encrypted data area before decryption. I assume that OneSignal is not using that, and that is the issue here. As soon as I do the initial login, everything works properly.

Android runs in a secure, Direct Boot mode when the device has been powered on but the user hasn't unlocked the device. 
By default, apps don't run during Direct Boot mode. If your app needs to take action during Direct Boot mode, you can register app components to be run during this mode.

https://developer.android.com/privacy-and-security/direct-boot