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

Writes to disk on main thread #61

Closed
EGecius opened this issue May 12, 2015 · 4 comments
Closed

Writes to disk on main thread #61

EGecius opened this issue May 12, 2015 · 4 comments

Comments

@EGecius
Copy link

EGecius commented May 12, 2015

Android's Strict mode detected a disk write with the following stack trace:

05-12 07:48:03.093    9989-9989/? D/StrictMode﹕ StrictMode policy violation; ~duration=98 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=341 violation=1
            at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1111)
            at libcore.io.BlockGuardOs.mkdir(BlockGuardOs.java:172)
            at java.io.File.mkdirErrno(File.java:874)
            at java.io.File.mkdirs(File.java:898)
            at java.io.File.mkdirs(File.java:892)
            at com.android.server.pm.Settings.writePackageRestrictionsLPr(Settings.java:1277)
            at com.android.server.pm.PackageManagerService.setEnabledSetting(PackageManagerService.java:12201)
            at com.android.server.pm.PackageManagerService.setComponentEnabledSetting(PackageManagerService.java:12109)
            at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:1219)
            at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:1862)
            at android.os.Binder.execTransact(Binder.java:446)
    # via Binder call with stack:
    android.os.StrictMode$LogStackTrace
            at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1717)
            at android.os.Parcel.readExceptionCode(Parcel.java:1527)
            at android.os.Parcel.readException(Parcel.java:1496)
            at android.content.pm.IPackageManager$Stub$Proxy.setComponentEnabledSetting(IPackageManager.java:3394)
            at android.app.ApplicationPackageManager.setComponentEnabledSetting(ApplicationPackageManager.java:1489)
            at com.squareup.leakcanary.LeakCanary.setEnabled(LeakCanary.java:195)
            at com.squareup.leakcanary.LeakCanary.enableDisplayLeakActivity(LeakCanary.java:75)
            at com.squareup.leakcanary.LeakCanary.install(LeakCanary.java:55)
            at com.squareup.leakcanary.LeakCanary.install(LeakCanary.java:43)
            at various.App.onCreate(App.java:44)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
            at android.app.ActivityThread.access$1500(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
@pyricau
Copy link
Member

pyricau commented May 12, 2015

Duplicates #15 , although different. Wow so we can't call ApplicationPackageManager.setComponentEnabledSetting().

@pyricau pyricau closed this as completed May 12, 2015
@pepyakin
Copy link

But what can we do with it? If I get it right, violation happens in another process?

@pyricau
Copy link
Member

pyricau commented May 12, 2015

Stacktrace wasn't formatted so I didn't read through it. I edited, now it's better.

This is very interesting. If you do an IPC call (which is blocking) on the main thread and then the other process reads the file system, then strict mode complains. Smarts. And sort of makes sense.

What we can do is the same thing as we'd do with a normal strict mode violation: do all the setEnabled() calls asynchronously. Hopefully we won't have a leak before all the setEnabled() calls finish.

@pepyakin
Copy link

@pyricau Hm, I thought we can call setEnabled() only on main thread.

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

No branches or pull requests

3 participants