Due to background service limitations, we implemented our app with the help of WorkManager and replaced the AsyncTask. The app supports Direct-boot-mode, so we are storing our required SharedPreferences in Device encrypted storage. App was working fine before WorkManager implementation but now it is crashing after rebooting the device.
logcat:
java.lang.IllegalStateException: SharedPreferences in credential encrypted storage are not available until after user is unlocked
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:387)
        at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:372)
        at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
        at androidx.work.impl.utils.Preferences.getSharedPreferences(Unknown Source:12)
        at androidx.work.impl.utils.Preferences.needsReschedule(Unknown Source:0)
                                                setNeedsReschedule
        at androidx.work.impl.utils.ForceStopRunnable.shouldRescheduleWorkers(Unknown Source:6)
        at androidx.work.impl.utils.ForceStopRunnable.run(Unknown Source:18)
        at androidx.work.impl.utils.SerialExecutor$Task.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
We are providing device protected storage context while initializing the WorkManager:
ContextCompat.createDeviceProtectedStorageContext(appContext);
Please help, how to handle it.
 
    