Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: WILL BREAK RUNTIME. See conversation. Enable the thread police 👮 for debug builds #1050

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keyboardsurfer
Copy link
Member

What I have done and why

App will now crash if someone does funky stuff on the main thread for debug builds.
This enforces programming thread safe programming (even though there are no obvious violations at the moment).
g
Do tests pass?

  • Run local tests on DemoDebug variant: ./gradlew testDemoDebug
  • Check formatting: ./gradlew --init-script gradle/init.gradle.kts spotlessApply

Is this your first pull request?

@lihenggui
Copy link
Contributor

After enabling the StrictMode, the application will crash when launched.
Looks like there are some tasks remaining that need to be completed.

Process: com.google.samples.apps.nowinandroid.demo.debug, PID: 5363
java.lang.RuntimeException: StrictMode ThreadPolicy violation
	at android.os.StrictMode$AndroidBlockGuardPolicy.onThreadPolicyViolation(StrictMode.java:1883)
	at android.os.StrictMode$AndroidBlockGuardPolicy.lambda$handleViolationWithTimingAttempt$0(StrictMode.java:1797)
	at android.os.StrictMode$AndroidBlockGuardPolicy.$r8$lambda$AF9hglpXLeeg2_1ZxHCfZb2exEY(Unknown Source:0)
	at android.os.StrictMode$AndroidBlockGuardPolicy$$ExternalSyntheticLambda1.run(Unknown Source:6)
	at android.os.Handler.handleCallback(Handler.java:958)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
	at android.app.ActivityThread.main(ActivityThread.java:8176)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: android.os.strictmode.DiskReadViolation
	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1666)
	at libcore.io.BlockGuardOs.access(BlockGuardOs.java:74)
	at libcore.io.ForwardingOs.access(ForwardingOs.java:128)
	at android.app.ActivityThread$AndroidOs.access(ActivityThread.java:8053)
	at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:313)
	at java.io.File.exists(File.java:813)
	at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:790)
	at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:781)
	at android.app.ContextImpl.getPreferencesDir(ContextImpl.java:737)
	at android.app.ContextImpl.getSharedPreferencesPath(ContextImpl.java:962)
	at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:583)
	at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:221)
	at com.google.firebase.remoteconfig.RemoteConfigComponent.getMetadataClient(RemoteConfigComponent.java:299)
	at com.google.firebase.remoteconfig.RemoteConfigComponent.get(RemoteConfigComponent.java:162)
	at com.google.firebase.perf.config.RemoteConfigManager.isFirebaseRemoteConfigAvailable(RemoteConfigManager.java:395)
	at com.google.firebase.perf.config.RemoteConfigManager.triggerRemoteConfigFetchIfNecessary(RemoteConfigManager.java:331)
	at com.google.firebase.perf.config.RemoteConfigManager.getRemoteConfigValue(RemoteConfigManager.java:295)
	at com.google.firebase.perf.config.RemoteConfigManager.getBoolean(RemoteConfigManager.java:207)
	at com.google.firebase.perf.config.ConfigResolver.getRemoteConfigBoolean(ConfigResolver.java:867)
	at com.google.firebase.perf.config.ConfigResolver.getIsExperimentTTIDEnabled(ConfigResolver.java:826)
	at com.google.firebase.perf.metrics.AppStartTrace.onActivityResumed(AppStartTrace.java:352)
	at android.app.Application.dispatchActivityResumed(Application.java:431)
	at android.app.Activity.dispatchActivityResumed(Activity.java:1483)
	at android.app.Activity.onResume(Activity.java:2065)
	at com.google.samples.apps.nowinandroid.MainActivity.onResume(MainActivity.kt:157)
	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1603)
	at android.app.Activity.performResume(Activity.java:8743)
	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4951)
	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4994)
	at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:57)
	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:180)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:98)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
	at android.os.Handler.dispatchMessage(Handler.java:106)

@SimonMarquis
Copy link
Contributor

Quick question: should we also enable strict VmPolicy?

@keyboardsurfer keyboardsurfer force-pushed the bw/threadPolicy branch 2 times, most recently from b4e077c to d45ad54 Compare November 21, 2023 10:26
@keyboardsurfer
Copy link
Member Author

The RemoteConfig issue is being tracked here: firebase/firebase-android-sdk#5347 and I'm following up with the team.

@keyboardsurfer keyboardsurfer force-pushed the bw/threadPolicy branch 3 times, most recently from 6812237 to 7af51af Compare November 27, 2023 20:29
@keyboardsurfer keyboardsurfer changed the title Enable the thread police 👮 for debug builds DO NOT MERGE: WILL BREAK RUNTIME. See conversation. Enable the thread police 👮 for debug builds Nov 28, 2023
* App will now crash if someone does funky stuff on the main thread.

Change-Id: I9026c100705f2fec6963a1d888b40906186f9d28
Copy link

github-actions bot commented Sep 5, 2024

Combined test coverage report

Overall Project 42.32% -0.03% 🍏
Files changed 0%

Module Coverage
app 48.05% -0.24%
Files
Module File Coverage
app NiaApplication.kt 0% -27.27%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants