capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

Local Notification Crash during Boot Phase (DirectBoot)

Open mlostekk opened this issue 2 years ago • 2 comments

Bug Report

Plugin(s)

"@capacitor/local-notifications": "^5.0.6",

Capacitor Version

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 5.4.1
  @capacitor/core: 5.4.1
  @capacitor/android: 5.4.1
  @capacitor/ios: 5.4.1

Installed Dependencies:

  @capacitor/cli: 5.4.0
  @capacitor/core: 5.4.0
  @capacitor/android: 5.4.0
  @capacitor/ios: 5.4.0

Platform(s)

  • Android

Current Behavior

The following Crash is reported to the Google Play Console

ndroid.app.ContextImpl.getSharedPreferences
java.lang.IllegalStateException

with the stacktrace

Exception java.lang.IllegalStateException: SharedPreferences in credential encrypted storage are not available until after user is unlocked
  at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:562)
  at android.app.ContextImpl.getSharedPreferences (ContextImpl.java:547)
  at android.content.ContextWrapper.getSharedPreferences (ContextWrapper.java:196)
  at com.google.android.gms.internal.appset.zzl.zzf (com.google.android.gms:play-services-appset@@16.0.0:1)
  at com.google.android.gms.internal.appset.zzl.zzd (com.google.android.gms:play-services-appset@@16.0.0:1)
  at com.google.android.gms.internal.appset.zzh.run
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1137)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:637)
  at java.lang.Thread.run (Thread.java:1012)

Expected Behavior

No Crash

Additional Info

It seems like this is happening when the notification system signs up during boot, before the user unlocked his device. (source). Looking at the manifest of this it is exactly what is happening (here, and here)

Is it possible to disable these manifest values without forking the whole repository?

mlostekk avatar Sep 25 '23 14:09 mlostekk

Is it somehow possible to disable the "directBoot" awareness without forking the whole repository? Nobody else having an production app and is seeing this issue?

mlostekk avatar Sep 29 '23 11:09 mlostekk

Hi. We had a similar issue. To override this behaviour we added the following piece of code to app AndroidManifest:

<receiver
            android:name="com.capacitorjs.plugins.localnotifications.LocalNotificationRestoreReceiver"
            android:exported="false"
            tools:node="replace">

            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
</receiver>

Hope this helps.

TeaKave avatar Dec 12 '23 15:12 TeaKave