[Bug]: DiskReadViolation on initWithContext
What happened?
After adding OneSignal to my app, I can see in logs a lot of DiskReadViolations.
Steps to reproduce?
1. Add implementation("com.onesignal:OneSignal:5.1.34") to the app module
2. Add strict mode logging:
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.penaltyDialog()
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.build()
)
3. Invoke initWithContext(this, "APP_ID") in onCreate Application (but after setting strict mode policy logging)
4. Open the app and see logcat.
What did you expect to happen?
no strict mode policy violations
OneSignal Android SDK version
5.1.34
Android version
14
Specific Android models
Samsung Galaxy Tab A8
Relevant log output
StrictMode policy violation; ~duration=327 ms: android.os.strictmode.DiskReadViolation (Ask Gemini)
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1658)
at libcore.io.BlockGuardOs.access(BlockGuardOs.java:74)
at libcore.io.ForwardingOs.access(ForwardingOs.java:128)
at android.app.ActivityThread$AndroidOs.access(ActivityThread.java:8610)
at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:332)
at java.io.File.exists(File.java:829)
at com.onesignal.core.internal.preferences.PreferenceStoreFix.ensureNoObfuscatedPrefStore(PreferenceStoreFix.kt:31)
at com.onesignal.internal.OneSignalImp.initWithContext(OneSignalImp.kt:198)
at com.onesignal.OneSignal.initWithContext(OneSignal.kt:135)
at com.bartekturkosz.myapplication.MyApp.onCreate(MyApp.kt:36)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1266)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7614)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2400)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8757)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Hi @bartek977, thank you for reporting this issue. It is likely caused by a disk access during OneSignal initialization, which is used to ensure a smooth migration. We’ll look into it and keep you updated.
Thanks for reporting disk read violation issue. We’ve just published Android SDK 5.4.0-alpha-01, which includes a major refactor of the initialization process. In this release, all heavy initialization work has been moved to background threads, which should remove this disk violation during the initialization.
We’d love for you to give this version a try and let us know how it works in your environment. Your feedback will be invaluable in helping us confirm the fix and ensure it’s ready for a stable release. Thank you again for bringing this to our attention and for helping us make the SDK better for everyone!
I tested with version 5.4.0-alpha-01, and I can confirm that the DiskReadViolation on initWithContext no longer occurs. Thanks for addressing this issue!