0

The code, called from Application.onCreate():

private fun enableOnStrictMode() {
    StrictMode.setThreadPolicy(
            StrictMode
                    .ThreadPolicy
                    .Builder()
                    .detectAll()
                    .penaltyLog()
                    .build())
    StrictMode.setVmPolicy(
            StrictMode
                    .VmPolicy
                    .Builder()
                    .detectAll()
                    .penaltyLog()
                    .build())
}

This works perfectly fine on an Android 9.0 Pie device and outputs almost a dozen policy violations including un-tagged network requests and disk reads. But when running the same code on a Marshmallow device (a Samsung J5 Android 6.0) StrictMode outputs no logging, even when it seems reasonable to assume the policy violations are still occurring.

Is there something about the StrictMode configuration that might lead to no output on Android 6.0 Marshmallow?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ollie C
  • 28,313
  • 34
  • 134
  • 217
  • Which violation are you missing, specifically? If it's untagged socket violations and unbuffered i/o violations, then that's probably because those were added in API level 26. – Michael Oct 16 '18 at 14:36
  • @Michael Ah yes, you are right. Add as an answer and I will mark as answered. The main one I expected to see was disk read vioaltions, which surprisingly only came with API 28: https://developer.android.com/reference/android/os/strictmode/DiskReadViolation – Ollie C Oct 16 '18 at 14:42
  • That might just be due to a refactoring of the code. Detection of disk read violations should be available in Marshmallow (but not detection of unbuffered disk reads/writes). – Michael Oct 16 '18 at 14:47

1 Answers1

1

Certain detections are only available starting with later API versions.

For example, API level 26 (Android O) added detectUntaggedSockets and detectUnbufferedIo.

However, detectDiskReads should be available starting with API level 9.

Michael
  • 57,169
  • 9
  • 80
  • 125