Keep screen on during PermissionHostTest

In some cases it takes a long time for the UI to react and with 15 sec
default timeout the screen might turn off. Hence set the timeout to 30
min and wake up the screen before every test.

Change-Id: I490eaad6e53bbe23f023a029a694ff995a52bf37
Fixes: 65126812
Test: cts-tradefed run singleCommand cts-dev -m CtsAppSecurityHostTestCases --test=android.appsecurity.cts.PermissionsHostTest on Sailfish
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/PermissionsHostTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/PermissionsHostTest.java
index bd98de3..caabeb5 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/PermissionsHostTest.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/PermissionsHostTest.java
@@ -46,6 +46,10 @@
     private static final String APK_ESCLATE_TO_RUNTIME_PERMISSIONS =
             "CtsEscalateToRuntimePermissions.apk";
 
+    private static final String SCREEN_OFF_TIMEOUT_NS = "system";
+    private static final String SCREEN_OFF_TIMEOUT_KEY = "screen_off_timeout";
+    private String mScreenTimeoutBeforeTest;
+
     private IAbi mAbi;
     private CompatibilityBuildHelper mBuildHelper;
 
@@ -70,12 +74,24 @@
         getDevice().uninstallPackage(USES_PERMISSION_PKG);
         getDevice().uninstallPackage(ESCALATE_PERMISSION_PKG);
         getDevice().uninstallPackage(PERMISSION_POLICY_25_PKG);
+
+        // Set screen timeout to 30 min to not timeout while waiting for UI to change
+        mScreenTimeoutBeforeTest = getDevice().getSetting(SCREEN_OFF_TIMEOUT_NS,
+                SCREEN_OFF_TIMEOUT_KEY);
+        getDevice().setSetting(SCREEN_OFF_TIMEOUT_NS, SCREEN_OFF_TIMEOUT_KEY, "1800000");
+
+        // Wake up device
+        getDevice().executeShellCommand("input keyevent KEYCODE_WAKEUP");
+        getDevice().disableKeyguard();
     }
 
     @Override
     protected void tearDown() throws Exception {
         super.tearDown();
 
+        getDevice().setSetting(SCREEN_OFF_TIMEOUT_NS, SCREEN_OFF_TIMEOUT_KEY,
+                mScreenTimeoutBeforeTest);
+
         getDevice().uninstallPackage(USES_PERMISSION_PKG);
         getDevice().uninstallPackage(ESCALATE_PERMISSION_PKG);
         getDevice().uninstallPackage(PERMISSION_POLICY_25_PKG);