relaycorp / relaynet-gateway-android

Awala Gateway for Android
https://relaynet.network/users
GNU General Public License v3.0
9 stars 0 forks source link

Strict mode no longer works in development #708

Closed gnarea closed 12 months ago

gnarea commented 1 year ago

The app won't work unless I disable the following:

https://github.com/relaycorp/relaynet-gateway-android/blob/28e329b9eef9c9580b5753d2e3b4e59f2cd3a44f/app/src/main/java/tech/relaycorp/gateway/App.kt#L106-L107

And @mgulyaev10 just came across the following thread-related issue:

FATAL EXCEPTION: main
Process: tech.relaycorp.gateway, PID: 9339
java.lang.RuntimeException: StrictMode ThreadPolicy violation
    at android.os.StrictMode$AndroidBlockGuardPolicy.onThreadPolicyViolation(StrictMode.java:1813)
    at android.os.StrictMode$AndroidBlockGuardPolicy.lambda$handleViolationWithTimingAttempt$0$StrictMode$AndroidBlockGuardPolicy(StrictMode.java:1727)
    at android.os.-$$Lambda$StrictMode$AndroidBlockGuardPolicy$9nBulCQKaMajrWr41SB7f7YRT1I.run(Unknown Source:6)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:7912)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Caused by: android.os.strictmode.DiskReadViolation
    at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1596)
    at libcore.io.BlockGuardOs.access(BlockGuardOs.java:71)
    at libcore.io.ForwardingOs.access(ForwardingOs.java:72)
    at android.app.ActivityThread$AndroidOs.access(ActivityThread.java:7787)
    at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:281)
    at java.io.File.exists(File.java:815)
    at miui.util.font.FontSettings.checkUsingThemeFont(FontSettings.java:107)
    at miui.util.font.FontSettings.loadFontSetting(FontSettings.java:71)
    at miui.util.TypefaceUtils.loadFontSettings(TypefaceUtils.java:65)
    at miui.contentcatcher.InterceptorProxy.create(InterceptorProxy.java:62)
    at android.app.Activity.onCreate(Activity.java:1648)
    at androidx.core.app.ComponentActivity.onCreate(ComponentActivity.java:85)
    at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:323)
    at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
    at tech.relaycorp.gateway.ui.BaseActivity.onCreate(BaseActivity.kt:36)
    at tech.relaycorp.gateway.ui.main.MainActivity.onCreate(MainActivity.kt:36)
    at android.app.Activity.performCreate(Activity.java:8109)
    at android.app.Activity.performCreate(Activity.java:8083)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1308)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3519)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3718)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2161)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:236) 
    at android.app.ActivityThread.main(ActivityThread.java:7912) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
sdsantos commented 1 year ago

I can only reproduce the ThreadPolicy issue with Typefaces on one of my phones, although the stacktrace is different.

Unfortunately, there aren't great solutions for this: a) Disable those checks entirely, like we did before for other checks; b) Use hacks with reflection to whitelist certain issues (https://medium.com/@tokudu/how-to-whitelist-strictmode-violations-on-android-based-on-stacktrace-eb0018e909aa); c) Use a penaltyListener instead of the penaltyDeath + penaltyLog to be able to filter some issues out, but only on API 28+ (https://developer.android.com/reference/android/os/StrictMode.ThreadPolicy.Builder#penaltyListener(java.util.concurrent.Executor,%20android.os.StrictMode.OnThreadViolationListener))

gnarea commented 1 year ago

Option C seems like the least bad option 😬 😄 Should we go for it?

github-actions[bot] commented 12 months ago

:tada: This issue has been resolved in version 1.8.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: