Bug 1168175 - Turn on screen and disable keyboard before running each test. r=gbrown
authorNick Alexander <nalexander@mozilla.com>
Thu, 04 Feb 2016 09:54:12 -0800
changeset 283253 edfca1614182aa60d23d763a3a2142dbdf966e6f
parent 283252 926d1440ce98c618194236956342a627fdec4a93
child 283254 7a62e97f07c2c90d9f34c2c7de40f3cb193f6312
push id71491
push userphilringnalda@gmail.com
push dateSat, 06 Feb 2016 03:42:29 +0000
treeherdermozilla-inbound@3c3e39e9becc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1168175
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1168175 - Turn on screen and disable keyboard before running each test. r=gbrown
mobile/android/app/src/androidTest/AndroidManifest.xml
mobile/android/tests/browser/robocop/AndroidManifest.xml.in
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/FennecInstrumentationTestRunner.java
--- a/mobile/android/app/src/androidTest/AndroidManifest.xml
+++ b/mobile/android/app/src/androidTest/AndroidManifest.xml
@@ -6,16 +6,19 @@
     android:versionName="1.0" >
 
     <uses-sdk android:minSdkVersion="${MOZ_ANDROID_MIN_SDK_VERSION}"
               android:targetSdkVersion="23"/>
     <!-- TODO: re-instate maxSdkVersion. -->
 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 
+    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+
     <instrumentation
         android:name="org.mozilla.gecko.FennecInstrumentationTestRunner"
         android:targetPackage="${ANDROID_PACKAGE_NAME}" />
 
     <application
         android:label="@string/app_name">
 
         <uses-library android:name="android.test.runner" />
--- a/mobile/android/tests/browser/robocop/AndroidManifest.xml.in
+++ b/mobile/android/tests/browser/robocop/AndroidManifest.xml.in
@@ -11,16 +11,19 @@
     <uses-sdk android:minSdkVersion="@MOZ_ANDROID_MIN_SDK_VERSION@"
 #ifdef MOZ_ANDROID_MAX_SDK_VERSION
               android:maxSdkVersion="@MOZ_ANDROID_MAX_SDK_VERSION@"
 #endif
               android:targetSdkVersion="23"/>
 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 
+    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+
     <instrumentation
         android:name="org.mozilla.gecko.FennecInstrumentationTestRunner"
         android:targetPackage="@ANDROID_PACKAGE_NAME@" />
 
     <application
         android:label="@string/app_name"
         android:debuggable="true">
 
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/FennecInstrumentationTestRunner.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/FennecInstrumentationTestRunner.java
@@ -1,20 +1,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
+import android.app.KeyguardManager;
+import android.content.Context;
 import android.os.Bundle;
+import android.os.PowerManager;
 import android.test.InstrumentationTestRunner;
 import android.util.Log;
 
+import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP;
+import static android.os.PowerManager.FULL_WAKE_LOCK;
+import static android.os.PowerManager.ON_AFTER_RELEASE;
+
 public class FennecInstrumentationTestRunner extends InstrumentationTestRunner {
     private static Bundle sArguments;
+    private PowerManager.WakeLock wakeLock;
+    private KeyguardManager.KeyguardLock keyguardLock;
 
     @Override
     public void onCreate(Bundle arguments) {
         sArguments = arguments;
         if (sArguments == null) {
             Log.e("Robocop", "FennecInstrumentationTestRunner.onCreate got null bundle");
         }
         super.onCreate(arguments);
@@ -23,9 +32,37 @@ public class FennecInstrumentationTestRu
     // unfortunately we have to make this static because test classes that don't extend
     // from ActivityInstrumentationTestCase2 can't get a reference to this class.
     public static Bundle getFennecArguments() {
         if (sArguments == null) {
             Log.e("Robocop", "FennecInstrumentationTestCase.getFennecArguments returns null bundle");
         }
         return sArguments;
     }
+
+    @Override
+    public void onStart() {
+        final Context app = getTargetContext().getApplicationContext();
+
+        final String name = FennecInstrumentationTestRunner.class.getSimpleName();
+        // Unlock the device so that the tests can input keystrokes.
+        final KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
+        // Deprecated in favour of window flags, which aren't appropriate here.
+        keyguardLock = keyguard.newKeyguardLock(name);
+        keyguardLock.disableKeyguard();
+
+        // Wake up the screen.
+        final PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
+        wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name);
+        wakeLock.acquire();
+
+        super.onStart();
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+
+        wakeLock.release();
+        // Deprecated in favour of window flags, which aren't appropriate here.
+        keyguardLock.reenableKeyguard();
+    }
 }