StrictMode listener should log all available information
Closed this issue · 2 comments
Description
I enabled StrictMode violation reporting according to the docs. The information I see in the Bugsnag console is incomplete and doesn't help me in finding the root cause of the violation:
However, if I enable Logcat logging on the StrictMode configuration, I get a much more detailed description of the violation:
D/StrictMode: StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. Callsite: readFromParcel
at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1929)
at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:305)
at android.view.SurfaceControl.finalize(SurfaceControl.java:1119)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:291)
at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:278)
Note the Callsite: readFromParcel
part of the log message.
This logging can be enabled by calling .penaltyLog()
:
val vmListener = BugsnagVmViolationListener()
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyListener(executor, vmListener)
.penaltyLog()
.build()
)
Describe the solution you'd like
The Logcat logger is implemented in the following way in StrictMode.java
:
private static final ViolationLogger LOGCAT_LOGGER =
info -> {
String msg;
if (info.durationMillis != -1) {
msg = "StrictMode policy violation; ~duration=" + info.durationMillis + " ms:";
} else {
msg = "StrictMode policy violation:";
}
Log.d(TAG, msg + " " + info.getStackTrace());
};
Describe alternatives you've considered
Additional context
Hey @ofalvai, I think that information would definitely be handy to have in the Bugsnag report. Unfortunately, the information that's added to the Logcat output by addition of .penaltyLog()
is from a ViolationInfo
object which is not part of the Violation
object sent to StrictMode listeners, and is hidden. I don't think there's a way that this can be captured by a listener unfortunately – at least not at present.
Hey @xander-jones, thank you for looking into this, it makes perfect sense.