2

I've enabled StrictMode on my app by code:

public void onCreate() {
    setStrictMode();
    super.onCreate();
}

private void setStrictMode() {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectAll()
            .penaltyLog()
            .penaltyDeath()
            .build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
            .detectAll()
            .penaltyLog()
            .build());
}

I found a crash when startup with log below :

StrictMode policy violation; ~duration=0 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=95 violation=2 at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1137) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:182) at libcore.io.IoBridge.open(IoBridge.java:442) at java.io.FileInputStream.(FileInputStream.java:76) at android.graphics.Typeface.getFullFlipFont(Typeface.java:582) at android.graphics.Typeface.getFontPathFlipFont(Typeface.java:530) at android.graphics.Typeface.SetFlipFonts(Typeface.java:717) at android.graphics.Typeface.SetAppTypeFace(Typeface.java:844) at android.app.Application.onCreate(Application.java:108)

I think is an io operate on main thread violation, My device is samsung s6, android version 5.1.1, but I can't find the method getFullFlipFont anywhere, if I disable strictmode it will be alright, where is the io violation happen?

Mr.icefox
  • 41
  • 1
  • 5

1 Answers1

2

This seems to happens on Samsung's phone. I have the same problem when running StrictMode on Samsung S7. But the issue is not there when running on Nexus 6P.

Two ways to resolve this. One is to turn on your Strict Mode after your application super.onCreate(). This is not ideal, as I believe you'll encounter other issue along the way that doesn't belong to your code.

The other one is to suppress it. You could check out this page. That's using Kotlin, but you could think of a way to work for Java, but a little more hassle.

Optionally, you could consider trying to suppress using this approach Filter Android StrictMode violations by duration

Rumit Patel
  • 8,830
  • 18
  • 51
  • 70
Elye
  • 53,639
  • 54
  • 212
  • 474