microsoft-authentication-library-for-android icon indicating copy to clipboard operation
microsoft-authentication-library-for-android copied to clipboard

android.os.strictmode.DiskReadViolation on createMultipleAccountPublicClientApplication

Open bartek977 opened this issue 8 months ago • 0 comments

Smartphone (please complete the following information):

  • Device: Samsung Galaxy Tab A8
  • Android Version: 14
  • Browser: Chrome
  • MSAL Version: 6.0.1

To Reproduce

Steps to reproduce the behavior:

Enable strict mode logging in onCreate app

StrictMode.setThreadPolicy(
            StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()
                .penaltyLog()
                .penaltyDialog()
                .build()
        )

and then create msal app:

PublicClientApplication.createMultipleAccountPublicClientApplication(
            this,
            R.raw.auth_config_single_account,
            object : IPublicClientApplication.IMultipleAccountApplicationCreatedListener {

                override fun onCreated(application: IMultipleAccountPublicClientApplication?) {
                    msalApp = application
                }

                override fun onError(exception: MsalException) {

                }
            }
        )

then see in the logcat, and there are logs related to strict mode android.os.strictmode.DiskReadViolation:

StrictMode policy violation; ~duration=37 ms: android.os.strictmode.DiskReadViolation (Ask Gemini)
                                                                                                    	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1658)
                                                                                                    	at android.app.SharedPreferencesImpl.awaitLoadedLocked(SharedPreferencesImpl.java:279)
                                                                                                    	at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:305)
                                                                                                    	at com.microsoft.identity.common.internal.cache.SharedPreferencesFileManager.getString(SharedPreferencesFileManager.java:186)
                                                                                                    	at com.microsoft.identity.common.SharedPreferenceStringStorage.get(SharedPreferenceStringStorage.java:57)
                                                                                                    	at com.microsoft.identity.common.SharedPreferenceStringStorage.get(SharedPreferenceStringStorage.java:43)
                                                                                                    	at com.microsoft.identity.common.java.telemetry.TelemetryPropertiesCache.getOrCreateRandomStableDeviceId(TelemetryPropertiesCache.java:56)
                                                                                                    	at com.microsoft.identity.common.java.telemetry.AbstractTelemetryContext.<init>(AbstractTelemetryContext.java:44)
                                                                                                    	at com.microsoft.identity.common.internal.telemetry.AndroidTelemetryContext.<init>(AndroidTelemetryContext.java:53)
                                                                                                    	at com.microsoft.identity.common.internal.telemetry.Telemetry$Builder.withContext(Telemetry.java:115)
                                                                                                    	at com.microsoft.identity.client.PublicClientApplication.setupTelemetry(PublicClientApplication.java:1336)
                                                                                                    	at com.microsoft.identity.client.PublicClientApplication.initializeApplication(PublicClientApplication.java:1276)
                                                                                                    	at com.microsoft.identity.client.PublicClientApplication.<init>(PublicClientApplication.java:1269)
                                                                                                    	at com.microsoft.identity.client.MultipleAccountPublicClientApplication.<init>(MultipleAccountPublicClientApplication.java:67)
                                                                                                    	at com.microsoft.identity.client.PublicClientApplication$9.onTaskCompleted(PublicClientApplication.java:1114)
                                                                                                    	at com.microsoft.identity.client.PublicClientApplication$9.onTaskCompleted(PublicClientApplication.java:1096)
                                                                                                    	at com.microsoft.identity.common.java.controllers.CommandDispatcher.commandCallbackOnTaskCompleted(CommandDispatcher.java:646)
                                                                                                    	at com.microsoft.identity.common.java.controllers.CommandDispatcher.access$1000(CommandDispatcher.java:98)
                                                                                                    	at com.microsoft.identity.common.java.controllers.CommandDispatcher$4.run(CommandDispatcher.java:622)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:942)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	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)

Expected behavior

Disk operation shouldn't be executed on main thread

Actual Behavior

Reading from disk is executed on main thread.

bartek977 avatar May 28 '25 07:05 bartek977