Status Update
Comments
vi...@google.com <vi...@google.com> #2
Can you provide the API document where this expected behavior is explained?
Please provide a sample project or apk to reproduce the issue. Also mention the steps to be followed for reproducing the issue with the given sample project or apk.
Screen Record of the Issue
Please capture screen record or video of the issue using following steps:
adb shell screenrecord /sdcard/video.mp4
Subsequently use following command to pull the recorded file:
adb pull /sdcard/video.mp4
Attach the file to this issue.
Android bug report (to be captured after reproducing the issue)
For steps to capture a bug report, please refer:
Alternate method
Navigate to “Developer options”, ensure “USB debugging” is enabled, then enable “Bug report shortcut”. Capture bug report by holding the power button and selecting the “Take bug report” option.
Note: Please upload the bug report and screenshot to google drive and share the folder to android-bugreport@google.com, then share the link here.
ub...@gmail.com <ub...@gmail.com> #3
Here is various documentation for an introduction to StrictMode:
setClassInstanceLimit
:
penaltyListener
:
The latter specifically says:
Call #OnVmViolationListener#onVmViolation(Violation) on every violation.
This is not true for InstanceCountViolation
triggered by setClassInstanceLimit
, the listener is never called for this kind of violation.
I provided a sample project and repro steps in the original issue description above.
There is nothing to see in a screen record/video. The only relevant output is in Logcat. I provided the expected Logcat output in the original issue description above. This output is absent when using penaltyListener
.
"Android bug report" is not relevant for this issue. Issue reproduces readily by running sample project with repro steps.
vi...@google.com <vi...@google.com> #4
We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
Description
Using StrictMode penaltyListener/OnVmViolationListener prevents InstanceCountViolation (from setClassInstanceLimit) to be triggered. I have found this to be true for all applicable Android versions, API 28 - API 35 Beta 3. penaltyListener was introduced in API 28.
This is problematic because penaltyListener is essential these days for filtering endless numbers of false positive StrictMode detections from Android framework and libraries when those detections are enabled. (E.g. NonSdkApiUsedViolation)
Essentially this means that one can either detect InstanceCountViolation or all other violations, but not both.
Minimal repro available here:https://github.com/bubenheimer/strictmodeclassinstancelimit
Here's the gist of it:
The repro sets an (invalid) class instance limit of 0 for
android.app.Application
inMainActivity.kt
.By default the repro has OnVmViolationListener set and no Violation will be logged. Comment out the
penaltyListener()
line to unset the listener, at which point the app will log InstanceCountViolation, as expected:I've reproduced this behavior on all emulator versions from API 28-35. I've also reproduced it on Samsung Galaxy S21 with OneUI 6.1.