trigger Disk Reads - Reading from disk can be slow and unpredictable Disk Writes - Writing to disk can be even slower and more unpredictable Network - Using the network blocks the thread until it completes Resource Mismatches - Using the wrong type to get a resource causes extra casting or wrong data. NEW! Unbuffered IO - Unbuffered IO operations are expensive
Activity subclasses Leaked Closable Objects - Detect when an Closeable or other object with a explicit termination method is finalized without having been closed. Leaked Registration Objects - Detect when a BroadcastReceiver or ServiceConnection is leaked during Context teardown. Leaked SqlLite Objects - Detect when an SQLiteCursor or other SQLite object is finalized without having been closed.
traffic from escaping NEW! Content Uri Without Permission - Detect when the calling application sends a content:// Uri to another app without granting permission. File Uri Exposure - Detect when the calling application exposes a file:// Uri to another app. NEW! Untagged Sockets - Detect any sockets in the calling app which have not been tagged using TrafficStats.
StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() // show violations in logcat .build()); StrictMode.setVmPolicy( new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() // show violations in logcat .build()); } …
are clobbered upon the return of execution to ActivityThread in Jelly Bean through Oreo. A fix is committed and will activate itself when targeting a future API Level.
an existing app, dialog is probably your best option as you definitely already have violations. Wouldn't it be nice if you could just get a callback and decide if you want to do something about a violation? Maybe even log them somewhere?
the ThreadLocal violationsBeingTimed in StrictMode and overwrite it with your own subclass of ArrayList that overrides add(). Not calling super.add() has the bonus effect of stopping log, dialog, and flash thread penalties. penaltyDeath() and non-UI thread causes a different non-interceptable code path to run. The object passed to add() can be further reflected on to get information about the specific violation.
the HashMap sLastVmViolationTime in StrictMode and overwrite it with your own subclass of HashMap that overrides containsKey(). Returning true from containsKey() has the bonus effect of stopping log, dialog, and flash VM penalties. penaltyDeath() follows a different code path. Unfortunately, no information about the violation itself is available here.
the activity hosting them has been destroyed. Repeated configuration changes can cause things to leak over and over. High heap utilization leads to GC, poorly timed GC can jank the app.
on any Closeable object. Android will eventually close it for you, but you waste memory in the meantime. Leaking SQLite cursors is more severe as native resources cannot be deallocated. Try/Finally can ensure this mistake is not made.