I\'ve tried adding Crashlytics
to my app, which already has StrictMode
enabled with detectAll()
. The result was Untagged socket dete
Api 28 has introduced:
public StrictMode.VmPolicy.Builder penaltyListener (Executor executor,
StrictMode.OnVmViolationListener listener)
So at least you can listen for specific violations (like UntaggedSocketViolation) and choose to ignore them. Of course, it would be better if Crashlytics were to tag their sockets appropriately.
A workaround is to not use detectAll()
, I've copied the the code of detectAll()
(from Crashlytics) and modified it; however I had to remove part of code since there are classes that are inaccessible.
I'm not a huge fan of this workaround but I'm not sure there's a better solution.
private void setStrictMode() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll() // detectDiskReads, detectDiskWrites, detectNetwork
.penaltyLog()
.build());
StrictMode.setVmPolicy(getStrictModeBuilder().build());
}
}
private StrictMode.VmPolicy.Builder getStrictModeBuilder() {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
builder.detectLeakedSqlLiteObjects();
final int sdkInt = Build.VERSION.SDK_INT;
if (sdkInt >= Build.VERSION_CODES.HONEYCOMB) {
builder.detectActivityLeaks();
builder.detectLeakedClosableObjects();
}
if (sdkInt >= Build.VERSION_CODES.JELLY_BEAN) {
builder.detectLeakedRegistrationObjects();
}
if (sdkInt >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
builder.detectFileUriExposure();
}
if (sdkInt >= Build.VERSION_CODES.O) {
builder.detectContentUriWithoutPermission();
}
builder.penaltyLog().penaltyDeath();
return builder;
}
Option two - remove the penaltyDeath()
from the VmPolicy
- this is what I'm currently doing:
private void setStrictMode() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll() // detectDiskReads, detectDiskWrites, detectNetwork
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog()
.build());
}