Closes #21695: ThreadPenaltyDeathWithIgnoresListener: Ignore stack traces containing InstrumentationHooks class

upstream-sync
Sebastian Kaspari 3 years ago committed by mergify[bot]
parent 9ae2fb636f
commit 8c9f0c835a

@ -12,6 +12,7 @@ import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.utils.ManufacturerCodes
private const val FCQN_EDM_STORAGE_PROVIDER_BASE = "com.android.server.enterprise.storage.EdmStorageProviderBase"
private const val INSTRUMENTED_HOOKS_CLASS = "com.android.tools.deploy.instrument.InstrumentationHooks"
/**
* A [StrictMode.OnThreadViolationListener] that recreates
@ -45,7 +46,8 @@ class ThreadPenaltyDeathWithIgnoresListener(
}
private fun shouldViolationBeIgnored(violation: Violation): Boolean =
isSamsungLgEdmStorageProviderStartupViolation(violation)
isSamsungLgEdmStorageProviderStartupViolation(violation) ||
containsInstrumentedHooksClass(violation)
private fun isSamsungLgEdmStorageProviderStartupViolation(violation: Violation): Boolean {
// Root issue: https://github.com/mozilla-mobile/fenix/issues/17920
@ -70,4 +72,13 @@ class ThreadPenaltyDeathWithIgnoresListener(
// issue, we'd catch it on other manufacturers.
return violation.stackTrace.any { it.className == FCQN_EDM_STORAGE_PROVIDER_BASE }
}
private fun containsInstrumentedHooksClass(violation: Violation): Boolean {
// See https://github.com/mozilla-mobile/fenix/issues/21695
// When deploying debug builds from Android Studio then we may hit a DiskReadViolation
// occasionally. There's an upstream fix for this, but the stable version of Android Studio
// still seems to be affected.
// https://cs.android.com/android-studio/platform/tools/base/+/abbbe67087626460e0127d3f5377f9cf896e9941
return violation.stackTrace.any { it.className == INSTRUMENTED_HOOKS_CLASS }
}
}

@ -68,6 +68,14 @@ class ThreadPenaltyDeathWithIgnoresListenerTest {
listener.onThreadViolation(violation)
}
@Test
fun `WHEN provided the InstrumentationHooks violation THEN it will be ignored and logged`() {
every { violation.stackTrace } returns getInstrumentationHooksStackTrace()
listener.onThreadViolation(violation)
verify { logger.debug("Ignoring StrictMode ThreadPolicy violation", violation) }
}
@Test
fun `WHEN violation is null THEN we don't throw an exception`() {
listener.onThreadViolation(null)
@ -75,4 +83,7 @@ class ThreadPenaltyDeathWithIgnoresListenerTest {
private fun getEdmStorageProviderStackTrace() =
StackTraces.getStackTraceFromLogcat("EdmStorageProviderBaseLogcat.txt")
private fun getInstrumentationHooksStackTrace() =
StackTraces.getStackTraceFromLogcat("InstrumentationHooksLogcat.txt")
}

@ -0,0 +1,20 @@
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1659)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at libcore.io.BlockGuardOs.access(BlockGuardOs.java:74)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at libcore.io.ForwardingOs.access(ForwardingOs.java:131)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.ActivityThread$AndroidOs.access(ActivityThread.java:7719)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:281)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at java.io.File.exists(File.java:813)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at com.android.tools.deploy.instrument.ResourceOverlays.updateLoader(ResourceOverlays.java:73)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at com.android.tools.deploy.instrument.ResourceOverlays.addResourceOverlays(ResourceOverlays.java:36)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at com.android.tools.deploy.instrument.InstrumentationHooks.addResourceOverlays(InstrumentationHooks.java:102)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.LoadedApk.getResources(LoadedApk.java:1312)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.ContextImpl.createAppContext(ContextImpl.java:3011)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.ContextImpl.createAppContext(ContextImpl.java:3003)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.Service.createServiceBaseContext(Service.java:904)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.ActivityThread.handleCreateService(ActivityThread.java:4475)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.ActivityThread.access$1700(ActivityThread.java:247)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2076)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288)
02-08 10:56:02.185 21990 21990 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7842)
Loading…
Cancel
Save