diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/hostside/safetycenter/src/android/safetycenter/hostside/rules/RequireSafetyCenterRule.kt | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/tests/hostside/safetycenter/src/android/safetycenter/hostside/rules/RequireSafetyCenterRule.kt b/tests/hostside/safetycenter/src/android/safetycenter/hostside/rules/RequireSafetyCenterRule.kt index 809fe5f0f..edf76e888 100644 --- a/tests/hostside/safetycenter/src/android/safetycenter/hostside/rules/RequireSafetyCenterRule.kt +++ b/tests/hostside/safetycenter/src/android/safetycenter/hostside/rules/RequireSafetyCenterRule.kt @@ -28,10 +28,10 @@ import org.junit.runners.model.Statement class RequireSafetyCenterRule(private val hostTestClass: BaseHostJUnit4Test) : TestRule { private val safetyCenterSupported: Boolean by lazy { - executeShellCommandOrThrow("cmd safety_center supported").toBoolean() + shellCommandStdoutOrThrow("cmd safety_center supported").toBooleanStrict() } private val safetyCenterEnabled: Boolean by lazy { - executeShellCommandOrThrow("cmd safety_center enabled").toBoolean() + shellCommandStdoutOrThrow("cmd safety_center enabled").toBooleanStrict() } override fun apply(base: Statement, description: Description): Statement { @@ -45,13 +45,20 @@ class RequireSafetyCenterRule(private val hostTestClass: BaseHostJUnit4Test) : T } /** Returns the package name of Safety Center on the test device. */ - fun getSafetyCenterPackageName(): String = - executeShellCommandOrThrow("cmd safety_center package-name") + fun getSafetyCenterPackageName(): String { + return shellCommandStdoutOrThrow("cmd safety_center package-name") + } - private fun executeShellCommandOrThrow(command: String): String { + private fun shellCommandStdoutOrThrow(command: String): String { val result = hostTestClass.device.executeShellV2Command(command) if (result.status != CommandStatus.SUCCESS) { - throw IOException("$command exited with status ${result.exitCode}") + throw IOException( + """Host-side test failed to execute adb shell command on test device. + |Command '$command' exited with status code ${result.exitCode}. + |This probably means the test device does not have a compatible version of + |the Permission Mainline module. Please check the test configuration.""" + .trimMargin("|") + ) } return result.stdout.trim() } |