3

Google Play Vitals reports crashes occurring on the Android devices running Android 8.0 and 8.1 which have the similar structure:

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:5743)
  at android.app.ActivityThread.-wrap1 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1656)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6494)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
Caused by: java.lang.IllegalStateException: 
  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 foo.bar.core.data.UserPreferences.<init> (UserPreferences.java:11)
  at foo.bar.android.core.di.AppModule.a (AppModule.java:7)
  at foo.bar.android.core.di.AppModule_ProvideUserPreferencesFactory.a (AppModule_ProvideUserPreferencesFactory.java:10)
  at foo.bar.android.core.di.AppModule_ProvideUserPreferencesFactory.get (AppModule_ProvideUserPreferencesFactory.java)
  at dagger.internal.DoubleCheck.get (DoubleCheck.java:15)
  at foo.bar.android.core.di.DaggerAppComponent.n (DaggerAppComponent.java:2)
  at foo.bar.android.Application.d (FooApplication.java:9)

The strange thing is that the way I create the SharedPreferences is pretty straightforward:

private val userPreferences: SharedPreferences = context.getSharedPreferences(USER_PREFS_FILE_NAME, Context.MODE_PRIVATE)

Another strange thing is that I am on Android 8.1 and I did not notice any crashes, while Play Vitals reports them happening on exactly the same device as the one I am using all the time: Pixel 2 XL, Android 8.1 (there're other devices with that issue as well).

Am I missing some obvious change in the SharedPreferences introduced in Android 8.0 (the crashes are happening on both 8.0 and 8.1, but ~96% of crashes are on 8.1)?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
aga
  • 27,954
  • 13
  • 86
  • 121
  • 2
    FWIW, this looks to be that `IllegalStateException`: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/ContextImpl.java#387. – Mike M. May 21 '18 at 23:13
  • @MikeM. ah, so this is happening when the app is trying to wake up and its storage is not accessible. That's what I thought as well. Thank you! – aga May 22 '18 at 08:36
  • The thing is, my app sometimes wakes up due to the beacons detection and/or upon geofence enter/exit event. So the Application's onCreate() method is called, which tries to access SharedPreferences, which fails due to FS being in encrypted state. Ok, now I just need to figure out how to cope with that and the case is closed. Thank you again. – aga May 22 '18 at 08:40
  • Yep, that's what I gathered from that. I haven't had to deal with that yet, though, so I couldn't really suggest anything, apart from just pointing it out. :-) – Mike M. May 22 '18 at 08:42
  • @MikeM. any findings for this. We too are observing the same in Android 8.0, 8.1 & 9.0. Seems like there is some restriction / protection for these OS versions. – Vrajesh Hirani Jan 01 '19 at 05:51

0 Answers0