Merge "improve audio client: unlock keyguard and ignore orientation change" into jb-mr2-dev
diff --git a/hostsidetests/monkey/Android.mk b/hostsidetests/monkey/Android.mk
index 8a73df3..45d2e37 100644
--- a/hostsidetests/monkey/Android.mk
+++ b/hostsidetests/monkey/Android.mk
@@ -24,7 +24,8 @@
 
 LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed-prebuilt ddmlib-prebuilt junit
 
-LOCAL_CTS_TEST_PACKAGE := android.monkey
+# prefix zzz intentional to run this last
+LOCAL_CTS_TEST_PACKAGE := zzz.android.monkey
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/monkey/src/com/android/cts/monkey/AbstractMonkeyTest.java b/hostsidetests/monkey/src/com/android/cts/monkey/AbstractMonkeyTest.java
index 8580a9d..9c27b62 100644
--- a/hostsidetests/monkey/src/com/android/cts/monkey/AbstractMonkeyTest.java
+++ b/hostsidetests/monkey/src/com/android/cts/monkey/AbstractMonkeyTest.java
@@ -17,7 +17,7 @@
     /** 
      * Base monkey command with flags to avoid side effects like airplane mode.
      */
-    static final String MONKEY_CMD = "monkey --pct-touch 0 --pct-motion 0 --pct-majornav 0 --pct-syskeys 0 --pct-anyevent 0";
+    static final String MONKEY_CMD = "monkey --pct-touch 0 --pct-motion 0 --pct-majornav 0 --pct-syskeys 0 --pct-anyevent 0 --pct-rotation 0";
 
     CtsBuildHelper mBuild;
     ITestDevice mDevice;
diff --git a/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java b/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
index 93b78a2..c0c21d1 100644
--- a/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
+++ b/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
@@ -116,6 +116,7 @@
             mTest = test;
         }
 
+        @Override
         public void run() {
             try {
                 mTest.videoEditTest();
@@ -293,7 +294,7 @@
                     inputDone = true;
                 } else {
                     generateSurfaceFrame(generateIndex);
-                    inputSurface.setPresentationTime(computePresentationTime(generateIndex));
+                    inputSurface.setPresentationTime(computePresentationTime(generateIndex) * 1000);
                     if (VERBOSE) Log.d(TAG, "inputSurface swapBuffers");
                     inputSurface.swapBuffers();
                 }
@@ -586,7 +587,7 @@
                             outputSurface.drawImage();
 
                             // Send it to the encoder.
-                            inputSurface.setPresentationTime(info.presentationTimeUs);
+                            inputSurface.setPresentationTime(info.presentationTimeUs * 1000);
                             if (VERBOSE) Log.d(TAG, "swapBuffers");
                             inputSurface.swapBuffers();
                         }
@@ -810,7 +811,7 @@
     }
 
     /**
-     * Generates the presentation time for frame N.
+     * Generates the presentation time for frame N, in microseconds.
      */
     private static long computePresentationTime(int frameIndex) {
         return 123 + frameIndex * 1000000 / FRAME_RATE;
diff --git a/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java b/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
index 849877a..b7ec961 100644
--- a/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
+++ b/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
@@ -130,6 +130,7 @@
             mTest = test;
         }
 
+        @Override
         public void run() {
             try {
                 mTest.encodeDecodeVideoFromBuffer(true);
@@ -178,6 +179,7 @@
             mTest = test;
         }
 
+        @Override
         public void run() {
             try {
                 mTest.encodeDecodeVideoFromSurfaceToSurface();
@@ -745,7 +747,7 @@
                 } else {
                     inputSurface.makeCurrent();
                     generateSurfaceFrame(generateIndex);
-                    inputSurface.setPresentationTime(computePresentationTime(generateIndex));
+                    inputSurface.setPresentationTime(computePresentationTime(generateIndex) * 1000);
                     if (VERBOSE) Log.d(TAG, "inputSurface swapBuffers");
                     inputSurface.swapBuffers();
                 }
@@ -959,7 +961,7 @@
     /**
      * Performs a simple check to see if the frame is more or less right.
      * <p>
-     * See {@link generateFrame} for a description of the layout.  The idea is to sample
+     * See {@link #generateFrame} for a description of the layout.  The idea is to sample
      * one pixel from the middle of the 8 regions, and verify that the correct one has
      * the non-background color.  We can't know exactly what the video encoder has done
      * with our frames, so we just check to see if it looks like more or less the right thing.
@@ -1053,7 +1055,7 @@
     }
 
     /**
-     * Checks the frame for correctness.  Similar to {@link checkFrame}, but uses GL to
+     * Checks the frame for correctness.  Similar to {@link #checkFrame}, but uses GL to
      * read pixels from the current surface.
      *
      * @return true if the frame looks good
@@ -1118,7 +1120,7 @@
     }
 
     /**
-     * Generates the presentation time for frame N.
+     * Generates the presentation time for frame N, in microseconds.
      */
     private static long computePresentationTime(int frameIndex) {
         return 132 + frameIndex * 1000000 / FRAME_RATE;
diff --git a/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java b/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java
index db6ce30..81296e4 100644
--- a/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java
+++ b/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java
@@ -797,7 +797,7 @@
                     if (VERBOSE) Log.d(TAG, "output surface: draw image");
                     outputSurface.drawImage();
                     inputSurface.setPresentationTime(
-                            videoDecoderOutputBufferInfo.presentationTimeUs);
+                            videoDecoderOutputBufferInfo.presentationTimeUs * 1000);
                     if (VERBOSE) Log.d(TAG, "input surface: swap buffers");
                     inputSurface.swapBuffers();
                     if (VERBOSE) Log.d(TAG, "video encoder: notified of new frame");
diff --git a/tests/tests/media/src/android/media/cts/InputSurface.java b/tests/tests/media/src/android/media/cts/InputSurface.java
index 36ec2c7..a916b8f 100644
--- a/tests/tests/media/src/android/media/cts/InputSurface.java
+++ b/tests/tests/media/src/android/media/cts/InputSurface.java
@@ -22,15 +22,9 @@
 import android.opengl.EGLContext;
 import android.opengl.EGLDisplay;
 import android.opengl.EGLSurface;
-import android.opengl.GLES10;
-import android.opengl.GLES11Ext;
-import android.opengl.GLES20;
-import android.opengl.Matrix;
 import android.util.Log;
 import android.view.Surface;
 
-import java.nio.ByteBuffer;
-
 
 /**
  * Holds state associated with a Surface used for MediaCodec encoder input.
@@ -167,10 +161,10 @@
     }
 
     /**
-     * Sends the presentation time stamp to EGL.
+     * Sends the presentation time stamp to EGL.  Time is expressed in nanoseconds.
      */
-    public void setPresentationTime(long when) {
-        EGLExt.eglPresentationTimeANDROID(mEGLDisplay, mEGLSurface, when);
+    public void setPresentationTime(long nsecs) {
+        EGLExt.eglPresentationTimeANDROID(mEGLDisplay, mEGLSurface, nsecs);
     }
 
     /**
diff --git a/tools/device-setup/TestDeviceSetup/Android.mk b/tools/device-setup/TestDeviceSetup/Android.mk
index f6c1079..efa50bf 100644
--- a/tools/device-setup/TestDeviceSetup/Android.mk
+++ b/tools/device-setup/TestDeviceSetup/Android.mk
@@ -26,7 +26,7 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_SDK_VERSION := 16
+LOCAL_SDK_VERSION := 17
 
 LOCAL_PACKAGE_NAME := TestDeviceSetup
 
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
index 565ac7f..49e96a0 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
@@ -77,7 +77,7 @@
         WindowManager wm = (WindowManager) getContext().getSystemService(
                 Context.WINDOW_SERVICE);
         Display d = wm.getDefaultDisplay();
-        d.getMetrics(metrics);
+        d.getRealMetrics(metrics);
         addResult(RESOLUTION, String.format("%sx%s", metrics.widthPixels, metrics.heightPixels));
         addResult(SCREEN_DENSITY, metrics.density);
         addResult(SCREEN_X_DENSITY, metrics.xdpi);
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
index 27f7c21..c6977e5 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
@@ -150,9 +150,9 @@
             "Interval between each reboot in min.")
     private int mRebootIntervalMin = 30;
 
-    @Option(name = "screenshot-on-ui-failure", description =
-            "take a screenshot if a test fails with a message indicating a UI obstruction.")
-    private boolean mScreenshotOnUiFailures = false;
+    @Option(name = "screenshot-on-failure", description =
+            "take a screenshot on every test failure.")
+    private boolean mScreenshotOnFailures = false;
 
     @Option(name = "logcat-on-failure", description =
             "take a logcat snapshot on every test failure. Unlike --bugreport, this can capture" +
@@ -249,13 +249,12 @@
     }
 
     /**
-     * A {@link ResultForwarder} that will forward a screenshot when it detects a failed test due
-     * to a UI obstruction.
+     * A {@link ResultForwarder} that will forward a screenshot on test failures.
      */
-    private static class FailedUiTestScreenshotGenerator extends ResultForwarder {
+    private static class FailedTestScreenshotGenerator extends ResultForwarder {
         private ITestDevice mDevice;
 
-        public FailedUiTestScreenshotGenerator(ITestInvocationListener listener,
+        public FailedTestScreenshotGenerator(ITestInvocationListener listener,
                 ITestDevice device) {
             super(listener);
             mDevice = device;
@@ -265,18 +264,15 @@
         public void testFailed(TestFailure status, TestIdentifier test, String trace) {
             super.testFailed(status, test, trace);
 
-            if (trace.contains(
-                    "Injecting to another application requires INJECT_EVENTS permission")) {
-                try {
-                    InputStreamSource screenSource = mDevice.getScreenshot();
-                    super.testLog(String.format("screenshot-%s_%s", test.getClassName(),
-                            test.getTestName()), LogDataType.PNG, screenSource);
-                    screenSource.cancel();
-                } catch (DeviceNotAvailableException e) {
-                    // TODO: rethrow this somehow
-                    CLog.e("Device %s became unavailable while capturing screenshot, %s",
-                            mDevice.getSerialNumber(), e.toString());
-                }
+            try {
+                InputStreamSource screenSource = mDevice.getScreenshot();
+                super.testLog(String.format("screenshot-%s_%s", test.getClassName(),
+                        test.getTestName()), LogDataType.PNG, screenSource);
+                screenSource.cancel();
+            } catch (DeviceNotAvailableException e) {
+                // TODO: rethrow this somehow
+                CLog.e("Device %s became unavailable while capturing screenshot, %s",
+                        mDevice.getSerialNumber(), e.toString());
             }
         }
     }
@@ -412,8 +408,8 @@
                     getDevice());
             listener = bugListener;
         }
-        if (mScreenshotOnUiFailures) {
-            FailedUiTestScreenshotGenerator screenListener = new FailedUiTestScreenshotGenerator(
+        if (mScreenshotOnFailures) {
+            FailedTestScreenshotGenerator screenListener = new FailedTestScreenshotGenerator(
                     listener, getDevice());
             listener = screenListener;
         }