diff options
author | 2023-07-06 14:30:04 +0000 | |
---|---|---|
committer | 2023-08-18 10:35:43 +0000 | |
commit | a93eb57e8e27d30db48f39090dc93c294a99c680 (patch) | |
tree | 3e1e162870b1ed72419fdbebc4b3bfcad2b22d9a /tests/hostside | |
parent | 4ea1e61845b1560e3402dbf45a46e001df462d95 (diff) |
Improve error messages from RequireSafetyCenterRule
The attached bug was caused by certain devices/configurations
lacking the Safety Center shell commands that this rule uses to
determine whether SC is enabled.
For the time being these mis-configurations seem to have been
fixed so I'm using this CL to change the error message so
that in the future it is easier to figure out what the problem
is, if something similar happens.
The stack traces we see saw said:
`java.io.IOException: cmd safety_center supported exited with status 255`
and a status code of 255 is the unsigned equivalent of the -1 status
code returned by the base shell command handler
[here](https://source.corp.google.com/h/googleplex-android/platform/superproject/+/master:frameworks/libs/modules-utils/java/com/android/modules/utils/BasicShellCommandHandler.java;l=306)
Bug: 289978570
Test: Re-run the test procedure in the above bug
Relnote: N/A
Change-Id: I19ca8830c657146f43d8df2dc6e4600301781654
Diffstat (limited to 'tests/hostside')
-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() } |