Merge "Bail out early in case of error" into jb-mr2-dev
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index f9df338..636a945 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -569,7 +569,8 @@
 
         <activity android:name="android.hardware.cts.CameraStubActivity"
             android:label="CameraStubActivity"
-            android:screenOrientation="landscape">
+            android:screenOrientation="landscape"
+            android:configChanges="keyboardHidden|orientation|screenSize">
         </activity>
 
         <activity android:name="android.view.inputmethod.cts.InputMethodStubActivity"
diff --git a/tests/src/android/opengl/cts/CompressedTextureSurfaceView.java b/tests/src/android/opengl/cts/CompressedTextureSurfaceView.java
index 15ce524..d0c8ed4 100644
--- a/tests/src/android/opengl/cts/CompressedTextureSurfaceView.java
+++ b/tests/src/android/opengl/cts/CompressedTextureSurfaceView.java
@@ -180,7 +180,7 @@
             checkGlError("glEnableVertexAttribArray maPositionHandle");
 
             mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
-            GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false,
+            GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
                 TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
             checkGlError("glVertexAttribPointer maTextureHandle");
             GLES20.glEnableVertexAttribArray(maTextureHandle);
diff --git a/tests/tests/app/src/android/app/cts/AlertDialogTest.java b/tests/tests/app/src/android/app/cts/AlertDialogTest.java
index d2edbeb..aefcf01 100644
--- a/tests/tests/app/src/android/app/cts/AlertDialogTest.java
+++ b/tests/tests/app/src/android/app/cts/AlertDialogTest.java
@@ -23,6 +23,7 @@
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
 import android.content.DialogInterface.OnClickListener;
+import android.cts.util.PollingCheck;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.os.Message;
@@ -55,6 +56,12 @@
 
     protected void startDialogActivity(int dialogNumber) {
         mActivity = DialogStubActivity.startDialogActivity(this, dialogNumber);
+        new PollingCheck() {
+            @Override
+            protected boolean check() {
+                return mActivity.getDialog().isShowing();
+            }
+        }.run();
     }
 
     public void testAlertDialog() throws Throwable {
diff --git a/tests/tests/app/src/android/app/cts/AlertDialog_BuilderTest.java b/tests/tests/app/src/android/app/cts/AlertDialog_BuilderTest.java
index 4c40a62..74f85bb 100644
--- a/tests/tests/app/src/android/app/cts/AlertDialog_BuilderTest.java
+++ b/tests/tests/app/src/android/app/cts/AlertDialog_BuilderTest.java
@@ -18,6 +18,7 @@
 
 import java.util.ArrayList;
 
+import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Instrumentation;
 import android.app.AlertDialog.Builder;
@@ -29,6 +30,7 @@
 import android.content.DialogInterface.OnClickListener;
 import android.content.DialogInterface.OnKeyListener;
 import android.content.DialogInterface.OnMultiChoiceClickListener;
+import android.cts.util.PollingCheck;
 import android.database.Cursor;
 import android.database.CursorWrapper;
 import android.graphics.drawable.Drawable;
@@ -108,6 +110,13 @@
         mBuilder = null;
         mInstrumentation = getInstrumentation();
         mContext = getActivity();
+        final Activity activity = getActivity();
+        new PollingCheck() {
+            @Override
+            protected boolean check() {
+                return activity.hasWindowFocus();
+            }
+        }.run();
         mButton = null;
         mView = null;
         mListView = null;
diff --git a/tests/tests/hardware/src/android/hardware/cts/CameraGLTest.java b/tests/tests/hardware/src/android/hardware/cts/CameraGLTest.java
index dd84675..9d7dacb 100644
--- a/tests/tests/hardware/src/android/hardware/cts/CameraGLTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/CameraGLTest.java
@@ -685,7 +685,7 @@
             checkGlError("glEnableVertexAttribArray maPositionHandle");
 
             mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
-            GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false,
+            GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
                                          TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
             checkGlError("glVertexAttribPointer maTextureHandle");
             GLES20.glEnableVertexAttribArray(maTextureHandle);
diff --git a/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java b/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
index c0c21d1..be2dc54 100644
--- a/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
+++ b/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
@@ -802,7 +802,7 @@
      * mLargestColorDelta.
      */
     boolean isColorClose(int actual, int expected) {
-        final int MAX_DELTA = 7;
+        final int MAX_DELTA = 8;
         int delta = Math.abs(actual - expected);
         if (delta > mLargestColorDelta) {
             mLargestColorDelta = delta;
diff --git a/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java b/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
index ddcd4b9..d788102 100644
--- a/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
+++ b/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
@@ -1117,7 +1117,7 @@
      * mLargestColorDelta.
      */
     boolean isColorClose(int actual, int expected) {
-        final int MAX_DELTA = 7;
+        final int MAX_DELTA = 8;
         int delta = Math.abs(actual - expected);
         if (delta > mLargestColorDelta) {
             mLargestColorDelta = delta;
diff --git a/tests/tests/media/src/android/media/cts/InputSurface.java b/tests/tests/media/src/android/media/cts/InputSurface.java
index a916b8f..8d5c133 100644
--- a/tests/tests/media/src/android/media/cts/InputSurface.java
+++ b/tests/tests/media/src/android/media/cts/InputSurface.java
@@ -118,7 +118,7 @@
      * Surface that was passed to our constructor.
      */
     public void release() {
-        if (EGL14.eglGetCurrentContext() == mEGLContext) {
+        if (EGL14.eglGetCurrentContext().equals(mEGLContext)) {
             // Clear the current context and surface to ensure they are discarded immediately.
             EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
                     EGL14.EGL_NO_CONTEXT);
diff --git a/tests/tests/media/src/android/media/cts/OutputSurface.java b/tests/tests/media/src/android/media/cts/OutputSurface.java
index 8494796..5274627 100644
--- a/tests/tests/media/src/android/media/cts/OutputSurface.java
+++ b/tests/tests/media/src/android/media/cts/OutputSurface.java
@@ -183,7 +183,7 @@
      */
     public void release() {
         if (mEGL != null) {
-            if (mEGL.eglGetCurrentContext() == mEGLContext) {
+            if (mEGL.eglGetCurrentContext().equals(mEGLContext)) {
                 // Clear the current context and surface to ensure they are discarded immediately.
                 mEGL.eglMakeCurrent(mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
                         EGL10.EGL_NO_CONTEXT);
diff --git a/tests/tests/media/src/android/media/cts/TextureRender.java b/tests/tests/media/src/android/media/cts/TextureRender.java
index 1ed568a..eb4236c 100644
--- a/tests/tests/media/src/android/media/cts/TextureRender.java
+++ b/tests/tests/media/src/android/media/cts/TextureRender.java
@@ -115,7 +115,7 @@
         checkGlError("glEnableVertexAttribArray maPositionHandle");
 
         mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
-        GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false,
+        GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
             TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
         checkGlError("glVertexAttribPointer maTextureHandle");
         GLES20.glEnableVertexAttribArray(maTextureHandle);
diff --git a/tests/tests/mediastress/src/android/mediastress/cts/SurfaceTextureRenderer.java b/tests/tests/mediastress/src/android/mediastress/cts/SurfaceTextureRenderer.java
index 4c2af8b..80beab9 100644
--- a/tests/tests/mediastress/src/android/mediastress/cts/SurfaceTextureRenderer.java
+++ b/tests/tests/mediastress/src/android/mediastress/cts/SurfaceTextureRenderer.java
@@ -127,7 +127,7 @@
         checkGlError("glEnableVertexAttribArray maPositionHandle");
 
         mVertices.position(VERTICES_DATA_UV_OFFSET);
-        GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false,
+        GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
                 VERTICES_DATA_STRIDE_BYTES, mVertices);
         checkGlError("glVertexAttribPointer maTextureHandle");
         GLES20.glEnableVertexAttribArray(maTextureHandle);
diff --git a/tests/tests/openglperf/src/android/openglperf/cts/GlVboPerfTest.java b/tests/tests/openglperf/src/android/openglperf/cts/GlVboPerfTest.java
index 2e9e10b..8b07b80 100644
--- a/tests/tests/openglperf/src/android/openglperf/cts/GlVboPerfTest.java
+++ b/tests/tests/openglperf/src/android/openglperf/cts/GlVboPerfTest.java
@@ -27,7 +27,7 @@
     private static final int NUM_FRAMES_TO_RENDER = 100;
     private static final long RENDERING_TIMEOUT = 5 * 60;
     // 10% of fps_no_vbo is allowed to compensate variations in measurement
-    private static final float FPS_COMPARISON_MARGIN = 0.1f;
+    private static final float FPS_COMPARISON_MARGIN = 0.2f;
     // the worst case should be above 70% of the best case
     private static final float FPS_MIN_MAX_COMPARISON_PERCENTILE = 0.7f;
 
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index 3a3e672..300bfaf 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -674,6 +674,7 @@
                 new File("/dev/binder"),
                 new File("/dev/full"),
                 new File("/dev/genlock"),    // b/9035217
+                new File("/dev/hw_random"),  // b/9191279
                 new File("/dev/ion"),
                 new File("/dev/kgsl-3d0"),   // b/9035217
                 new File("/dev/log/events"), // b/9035217
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
index ccc6444..3353d50 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
@@ -42,7 +42,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         final WebViewStubActivity activity = getActivity();
-        new PollingCheck() {
+        new PollingCheck(TEST_TIMEOUT) {
             @Override
                 protected boolean check() {
                 return activity.hasWindowFocus();
diff --git a/tests/tests/widget/src/android/widget/cts/GridViewTest.java b/tests/tests/widget/src/android/widget/cts/GridViewTest.java
index 2467861..1dd4764 100755
--- a/tests/tests/widget/src/android/widget/cts/GridViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/GridViewTest.java
@@ -24,6 +24,7 @@
 import android.app.Activity;
 import android.app.Instrumentation;
 import android.content.Context;
+import android.cts.util.PollingCheck;
 import android.database.DataSetObservable;
 import android.database.DataSetObserver;
 import android.graphics.Rect;
@@ -68,6 +69,12 @@
         super.setUp();
         mGridView = null;
         mActivity = getActivity();
+        new PollingCheck() {
+            @Override
+            protected boolean check() {
+                return mActivity.hasWindowFocus();
+            }
+        }.run();
         mInstrumentation = getInstrumentation();
     }