diff options
author | Josh Chien <joshchien@google.com> | 2023-03-13 06:09:34 +0000 |
---|---|---|
committer | Josh Chien <joshchien@google.com> | 2023-03-21 02:53:16 +0000 |
commit | 17076c5e3d01a0d615628857cb3125920c529d57 (patch) | |
tree | f3ad985581f8a7116d49aa1dd3f821f394a50e19 | |
parent | 4e9a6d412ca7058d4992dd605cb63f691e2f4a5f (diff) | |
download | platform_testing-17076c5e3d01a0d615628857cb3125920c529d57.tar.gz |
Create rule for turning on sysui demo mode.
Test: https://android-build.googleplex.com/builds/abtd/run/L53800000959096813
Bug: 273165073
Change-Id: I282f3b6cfa1834aa37cc9c418a8e6459443d2323
-rw-r--r-- | libraries/health/rules/src/android/platform/test/rule/SysuiDemoModeRule.kt | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/libraries/health/rules/src/android/platform/test/rule/SysuiDemoModeRule.kt b/libraries/health/rules/src/android/platform/test/rule/SysuiDemoModeRule.kt new file mode 100644 index 000000000..be7a104ad --- /dev/null +++ b/libraries/health/rules/src/android/platform/test/rule/SysuiDemoModeRule.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.platform.test.rule + +import android.content.Intent +import android.platform.uiautomator_helpers.DeviceHelpers.context +import android.provider.Settings +import org.junit.runner.Description + +/** This rule will modify SysUI demo mode flag and revert it after the test. */ +class SysuiDemoModeRule() : TestWatcher() { + private val contentResolver = context.contentResolver + private val DEMO_MODE_FLAG = "sysui_demo_allowed" + private val ENTER_COMMAND = "enter" + private val DISABLE_COMMAND = "exit" + private val ENABLE_VALUE = 1 + private var DISABLE_VALUE = 0 + + override fun starting(description: Description) { + if (!Settings.Global.putInt(contentResolver, DEMO_MODE_FLAG, ENABLE_VALUE)) { + throw RuntimeException("Could not set SysUI demo mode to $ENABLE_VALUE") + } + sendDemoModeBroadcast(ENTER_COMMAND) + } + + override fun finished(description: Description) { + sendDemoModeBroadcast(DISABLE_COMMAND) + + if (!Settings.Global.putInt(contentResolver, DEMO_MODE_FLAG, DISABLE_VALUE)) { + throw RuntimeException("Could not disable SysUI demo mode.") + } + } + + private fun sendDemoModeBroadcast(command: String) { + val intent = Intent("com.android.systemui.demo") + intent.putExtra("command", command) + context.sendBroadcast(intent) + } +} |