Merge "eglPresentationTimeANDROID moved to EGLExt from EGL14" into jb-mr2-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 9ff7edc..abab023 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -21,7 +21,7 @@
       android:versionName="4.3_r1">
 
     <!-- Using 10 for more complete NFC support... -->
-    <uses-sdk android:minSdkVersion="10"></uses-sdk>
+    <uses-sdk android:minSdkVersion="11"></uses-sdk>
 
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
@@ -388,7 +388,27 @@
             <meta-data android:name="test_category" android:value="@string/test_category_networking" />
             <meta-data android:name="test_required_features" android:value="android.hardware.wifi.direct" />
         </activity>
+        
+        <activity android:name=".nls.NotificationListenerVerifierActivity"
+                android:label="@string/nls_test">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.cts.intent.category.MANUAL_TEST" />
+            </intent-filter>
+            <meta-data android:name="test_category" android:value="@string/test_category_notifications" />
+        </activity>
 
+        <service android:name=".nls.MockListener"
+                 android:exported="true"
+                 android:label="@string/nls_service_name"
+                 android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
+            <intent-filter>
+                <action android:name="android.service.notification.NotificationListenerService" />
+            </intent-filter>
+        </service>
+        
+        <service  android:name="nls.NotificationListenerVerifierActivity$DismissService"/>
+        
         <activity android:name=".p2p.GoNegRequesterTestListActivity"
                 android:label="@string/p2p_go_neg_requester"
                 android:configChanges="keyboardHidden|orientation|screenSize" />
diff --git a/apps/CtsVerifier/res/layout/nls_item.xml b/apps/CtsVerifier/res/layout/nls_item.xml
new file mode 100644
index 0000000..3ced3cc
--- /dev/null
+++ b/apps/CtsVerifier/res/layout/nls_item.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2013 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.
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content" >
+
+    <ImageView
+        android:id="@+id/nls_status"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentTop="true"
+        android:layout_marginTop="10dip"
+        android:contentDescription="@string/pass_button_text"
+        android:padding="10dip"
+        android:src="@drawable/fs_indeterminate" />
+
+    <TextView
+        android:id="@+id/nls_instructions"
+        style="@style/InstructionsSmallFont"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentTop="true"
+        android:layout_toRightOf="@id/nls_status"
+        android:text="@string/nls_enable_service" />
+
+    <Button
+        android:id="@+id/nls_launch_settings"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_below="@id/nls_instructions"
+        android:layout_marginLeft="20dip"
+        android:layout_marginRight="20dip"
+        android:layout_toRightOf="@id/nls_status"
+        android:onClick="launchSettings"
+        android:text="@string/nls_start_settings" />
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/apps/CtsVerifier/res/layout/nls_main.xml b/apps/CtsVerifier/res/layout/nls_main.xml
new file mode 100644
index 0000000..0ee4cbf
--- /dev/null
+++ b/apps/CtsVerifier/res/layout/nls_main.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2013 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:padding="10dip" >
+
+    <ScrollView
+        android:id="@+id/nls_test_scroller"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="1"
+        android:orientation="vertical"
+        android:padding="10dip" >
+
+        <LinearLayout
+            android:id="@+id/nls_test_items"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="vertical" >
+        </LinearLayout>
+    </ScrollView>
+
+    <include
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_weight="0"
+        layout="@layout/pass_fail_buttons" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index c6f74cf..7967219 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -579,4 +579,24 @@
     <string name="camera_fov_enable_compass_mode_description">If enabled, the panorama orients
         itself according to the current rotation of the device.</string>
 
+    <string name="test_category_notifications">Notifications</string>
+    <string name="nls_test">Notification Listener Test</string>
+    <string name="nls_service_name">Notification Listener for CTS Verifier</string>
+    <string name="nls_info">This test checks that a NotificationListenerService can be enabled
+        and disabled, and that once enabled the service is able to receive notificaitons and
+        dismiss them.
+    </string>
+    <string name="nls_enable_service">Please enable \"Notification Listener for CTS Verifier\" 
+        under Security > Notification Access and return here.</string>
+    <string name="nls_disable_service">Please disable \"Notification Listener for CTS Verifier\" 
+        under Security > Notification Access and return here.</string>
+    <string name="nls_start_settings">Launch Settings</string>
+    <string name="nls_service_started">Service should start once enabled.</string>
+    <string name="nls_note_received">Check that notification was received.</string>
+    <string name="nls_payload_intact">Check that notification payload was intact.</string>
+    <string name="nls_clear_one">Check that service can clear a notification.</string>
+    <string name="nls_clear_all">Check that service can clear all notifications.</string>
+    <string name="nls_service_stopped">Service should stop once disabled.</string>
+    <string name="nls_note_missed">Check that notification was not received.</string>
+    
 </resources>
diff --git a/apps/CtsVerifier/res/values/styles.xml b/apps/CtsVerifier/res/values/styles.xml
index 0dfd02d..16fa87f 100644
--- a/apps/CtsVerifier/res/values/styles.xml
+++ b/apps/CtsVerifier/res/values/styles.xml
@@ -3,6 +3,8 @@
     <style name="InstructionsFont" parent="@android:style/TextAppearance.Large">
         <item name="android:padding">10dp</item>
     </style>
+    <style name="InstructionsSmallFont" parent="@android:style/TextAppearance.Medium">
+    </style>
     <style name="MessageRow">
         <item name="android:gravity">center_vertical</item>
         <item name="android:textSize">18sp</item>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/CtsTestHelper.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/CtsTestHelper.java
index c080729..bca217b 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/CtsTestHelper.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/CtsTestHelper.java
@@ -50,7 +50,7 @@
         String details = "PhotoSphere FOV test result:\n";
         for (int i = 0; i < resolutions.size(); i++) {
             SelectableResolution res = resolutions.get(i);
-            details += "Resolution:" + res.width + 'x' + res.height
+            details += "Camera:" + res.cameraId + ", Resolution:" + res.width + 'x' + res.height
                     + ", Measured FOV = " + res.measuredFOV + '\n';
 
         }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/PhotoCaptureActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/PhotoCaptureActivity.java
index c5957c0..943ee3d 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/PhotoCaptureActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/PhotoCaptureActivity.java
@@ -22,7 +22,6 @@
 import android.graphics.Color;
 import android.hardware.Camera;
 import android.hardware.Camera.PictureCallback;
-import android.hardware.Camera.Size;
 import android.os.Bundle;
 import android.os.PowerManager;
 import android.os.PowerManager.WakeLock;
@@ -52,7 +51,7 @@
  * An activity for showing the camera preview and taking a picture.
  */
 public class PhotoCaptureActivity extends Activity
-implements PictureCallback, SurfaceHolder.Callback {
+        implements PictureCallback, SurfaceHolder.Callback {
     private static final String TAG = PhotoCaptureActivity.class.getSimpleName();
     private static final int FOV_REQUEST_CODE = 1006;
     private static final String PICTURE_FILENAME = "photo.jpg";
@@ -65,6 +64,7 @@
     private ArrayAdapter<SelectableResolution> mAdapter;
 
     private Camera mCamera;
+    private Size mSurfaceSize;
     private boolean mCameraInitialized = false;
     private boolean mPreviewActive = false;
     private int mResolutionSpinnerIndex = -1;
@@ -119,6 +119,7 @@
                 if (mSupportedResolutions != null) {
                     SelectableResolution resolution = mSupportedResolutions.get(position);
 
+                    switchToCamera(resolution.cameraId);
                     Camera.Parameters params = mCamera.getParameters();
                     params.setPictureSize(resolution.width, resolution.height);
                     mCamera.setParameters(params);
@@ -131,54 +132,38 @@
         });
     }
 
-    /**
-     * Get the best supported focus mode.
-     *
-     * @param camera - Android camera object.
-     * @return the best supported focus mode.
-     */
-    protected String getFocusMode(Camera camera) {
-        List<String> modes = camera.getParameters().getSupportedFocusModes();
-        if (modes != null) {
-            if (modes.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
-                Log.v(TAG, "Using Focus mode infinity");
-                return Camera.Parameters.FOCUS_MODE_INFINITY;
-            }
-            if (modes.contains(Camera.Parameters.FOCUS_MODE_FIXED)) {
-                Log.v(TAG, "Using Focus mode fixed");
-                return Camera.Parameters.FOCUS_MODE_FIXED;
-            }
-        }
-        Log.v(TAG, "Using Focus mode auto.");
-        return Camera.Parameters.FOCUS_MODE_AUTO;
-    }
-
     @Override
     protected void onResume() {
         super.onResume();
-        mCamera = Camera.open();
-
         // Keep the device from going to sleep.
         PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
         mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);
         mWakeLock.acquire();
 
         if (mSupportedResolutions == null) {
-            // Get the supported picture sizes and fill the spinner.
-            List<Size> supportedSizes =
-                    mCamera.getParameters().getSupportedPictureSizes();
             mSupportedResolutions = new ArrayList<SelectableResolution>();
-            for (Size size : supportedSizes) {
-                mSupportedResolutions.add(
-                        new SelectableResolution(size.width, size.height));
+            int numCameras = Camera.getNumberOfCameras();
+            for (int cameraId = 0; cameraId < numCameras; ++cameraId) {
+                Camera camera = Camera.open(cameraId);
+
+                // Get the supported picture sizes and fill the spinner.
+                List<Camera.Size> supportedSizes =
+                        camera.getParameters().getSupportedPictureSizes();
+                for (Camera.Size size : supportedSizes) {
+                    mSupportedResolutions.add(
+                            new SelectableResolution(cameraId, size.width, size.height));
+                }
+                camera.release();
             }
         }
 
-        // find teh first untested one.
+        // Find the first untested entry.
         for (mResolutionSpinnerIndex = 0;
                 mResolutionSpinnerIndex < mSupportedResolutions.size();
                 mResolutionSpinnerIndex++) {
-            if (!mSupportedResolutions.get(mResolutionSpinnerIndex).tested) break;
+            if (!mSupportedResolutions.get(mResolutionSpinnerIndex).tested) {
+                break;
+            }
         }
 
         mAdapter = new ArrayAdapter<SelectableResolution>(
@@ -215,20 +200,23 @@
             fos.close();
             Log.d(TAG, "File saved to " + pictureFile.getAbsolutePath());
 
-            // Start activity which will use he taken picture to determine the FOV.
+            // Start activity which will use the taken picture to determine the
+            // FOV.
             startActivityForResult(new Intent(this, DetermineFovActivity.class),
                     FOV_REQUEST_CODE + mResolutionSpinnerIndex, null);
         } catch (IOException e) {
             Log.e(TAG, "Could not save picture file.", e);
             Toast.makeText(this, "Could not save picture file: " + e.getMessage(),
-                           Toast.LENGTH_LONG).show();
+                    Toast.LENGTH_LONG).show();
             return;
         }
     }
 
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (resultCode != RESULT_OK) return;
+        if (resultCode != RESULT_OK) {
+            return;
+        }
         int testIndex = requestCode - FOV_REQUEST_CODE;
         SelectableResolution res = mSupportedResolutions.get(testIndex);
         res.tested = true;
@@ -260,10 +248,10 @@
         }
         if (allPassed) {
             TestResult.setPassedResult(this, getClass().getName(),
-                                       CtsTestHelper.getTestDetails(mSupportedResolutions));
+                    CtsTestHelper.getTestDetails(mSupportedResolutions));
         } else {
             TestResult.setFailedResult(this, getClass().getName(),
-                                       CtsTestHelper.getTestDetails(mSupportedResolutions));
+                    CtsTestHelper.getTestDetails(mSupportedResolutions));
         }
         finish();
     }
@@ -271,32 +259,8 @@
     @Override
     public void surfaceChanged(
             SurfaceHolder holder, int format, int width, int height) {
-        if (mCamera == null || mSurfaceHolder.getSurface() == null) {
-            return;
-        }
-
-        try {
-            mCamera.setPreviewDisplay(mSurfaceHolder);
-        } catch (Throwable t) {
-            Log.e("TAG", "Could not set preview display", t);
-            Toast.makeText(this, t.getMessage(), Toast.LENGTH_LONG).show();
-            return;
-        }
-
-        // The picture size is taken and set from the spinner selection callback.
-        Camera.Parameters params = mCamera.getParameters();
-        params.setJpegThumbnailSize(0, 0);
-        params.setJpegQuality(100);
-        params.setFocusMode(getFocusMode(mCamera));
-        params.setZoom(0);
-
-        Camera.Size size = getBestPreviewSize(width, height, params);
-        if (size != null) {
-            params.setPreviewSize(size.width, size.height);
-            mCamera.setParameters(params);
-            mCameraInitialized = true;
-        }
-        startPreview();
+        mSurfaceSize = new Size(width, height);
+        initializeCamera();
     }
 
     @Override
@@ -309,6 +273,31 @@
         // Nothing to do.
     }
 
+    public void initializeCamera() {
+        if (mCamera == null || mSurfaceHolder.getSurface() == null) {
+            return;
+        }
+
+        try {
+            mCamera.setPreviewDisplay(mSurfaceHolder);
+        } catch (Throwable t) {
+            Log.e("TAG", "Could not set preview display", t);
+            Toast.makeText(this, t.getMessage(), Toast.LENGTH_LONG).show();
+            return;
+        }
+
+        Camera.Parameters params = setCameraParams(mCamera);
+
+        Camera.Size selectedPreviewSize =
+            getBestPreviewSize(mSurfaceSize.width, mSurfaceSize.height, params);
+        if (selectedPreviewSize != null) {
+            params.setPreviewSize(selectedPreviewSize.width, selectedPreviewSize.height);
+            mCamera.setParameters(params);
+            mCameraInitialized = true;
+        }
+        startPreview();
+    }
+
     private void startPreview() {
         if (mCameraInitialized && mCamera != null) {
             mCamera.startPreview();
@@ -316,6 +305,52 @@
         }
     }
 
+    private void switchToCamera(int cameraId) {
+        if (mCamera != null) {
+            mCamera.stopPreview();
+            mCamera.release();
+        }
+        mCamera = Camera.open(cameraId);
+        initializeCamera();
+    }
+
+    /**
+     * Get the best supported focus mode.
+     *
+     * @param camera - Android camera object.
+     * @return the best supported focus mode.
+     */
+    private static String getFocusMode(Camera camera) {
+        List<String> modes = camera.getParameters().getSupportedFocusModes();
+        if (modes != null) {
+            if (modes.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
+                Log.v(TAG, "Using Focus mode infinity");
+                return Camera.Parameters.FOCUS_MODE_INFINITY;
+            }
+            if (modes.contains(Camera.Parameters.FOCUS_MODE_FIXED)) {
+                Log.v(TAG, "Using Focus mode fixed");
+                return Camera.Parameters.FOCUS_MODE_FIXED;
+            }
+        }
+        Log.v(TAG, "Using Focus mode auto.");
+        return Camera.Parameters.FOCUS_MODE_AUTO;
+    }
+
+    /**
+     * Set the common camera parameters on the given camera and returns the
+     * parameter object for further modification, if needed.
+     */
+    private static Camera.Parameters setCameraParams(Camera camera) {
+        // The picture size is taken and set from the spinner selection
+        // callback.
+        Camera.Parameters params = camera.getParameters();
+        params.setJpegThumbnailSize(0, 0);
+        params.setJpegQuality(100);
+        params.setFocusMode(getFocusMode(camera));
+        params.setZoom(0);
+        return params;
+    }
+
     private Camera.Size getBestPreviewSize(
             int width, int height, Camera.Parameters parameters) {
         Camera.Size result = null;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/SelectableResolution.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/SelectableResolution.java
index 5e87eee..9057dbf 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/SelectableResolution.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/SelectableResolution.java
@@ -20,21 +20,24 @@
  * A resolution to be used in the adapter that feeds the resolution spinner.
  */
 public class SelectableResolution {
+    public final int cameraId;
     public final int width;
     public final int height;
     public boolean passed;
     public boolean tested;
     public float measuredFOV;
 
-    public SelectableResolution(int width, int height) {
+    public SelectableResolution(int cameraId, int width, int height) {
+        this.cameraId = cameraId;
         this.width = width;
         this.height = height;
-        passed = false;
-        tested = false;
+        this.passed = false;
+        this.tested = false;
     }
 
     @Override
     public String toString() {
-        return width + " x " + height + " - " + (!tested ? "untested" : "done");
+        return "Cam " + cameraId + ": " + width + " x " + height + " - "
+                + (!tested ? "untested" : "done");
     }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/Size.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/Size.java
new file mode 100644
index 0000000..709478b
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/Size.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2013 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 com.android.cts.verifier.camera.fov;
+
+/**
+ * Simple immutable class for keeping a size.
+ */
+public class Size {
+    public final int width;
+    public final int height;
+
+    public Size(int width, int height) {
+        this.width = width;
+        this.height = height;
+    }
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nls/MockListener.java b/apps/CtsVerifier/src/com/android/cts/verifier/nls/MockListener.java
new file mode 100644
index 0000000..62a09c9
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nls/MockListener.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2013 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 com.android.cts.verifier.nls;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.service.notification.NotificationListenerService;
+import android.service.notification.StatusBarNotification;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MockListener extends NotificationListenerService {
+    static final String TAG = "MockListener";
+
+    static final String SERVICE_CHECK = "android.service.notification.cts.SERVICE_CHECK";
+    static final String SERVICE_POSTED = "android.service.notification.cts.SERVICE_POSTED";
+    static final String SERVICE_PAYLOADS = "android.service.notification.cts.SERVICE_PAYLOADS";
+    static final String SERVICE_REMOVED = "android.service.notification.cts.SERVICE_REMOVED";
+    static final String SERVICE_RESET = "android.service.notification.cts.SERVICE_RESET";
+    static final String SERVICE_CLEAR_ONE = "android.service.notification.cts.SERVICE_CLEAR_ONE";
+    static final String SERVICE_CLEAR_ALL = "android.service.notification.cts.SERVICE_CLEAR_ALL";
+
+    static final String EXTRA_PAYLOAD = "TAGS";
+    static final String EXTRA_TAG = "TAG";
+    static final String EXTRA_CODE = "CODE";
+
+    static final int RESULT_TIMEOUT = Activity.RESULT_FIRST_USER;
+    static final int RESULT_NO_SERVER = Activity.RESULT_FIRST_USER + 1;
+
+    private ArrayList<String> mPosted = new ArrayList<String>();
+    private ArrayList<String> mPayloads = new ArrayList<String>();
+    private ArrayList<String> mRemoved = new ArrayList<String>();
+    private BroadcastReceiver mReceiver;
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        Log.d(TAG, "created");
+
+        mPosted = new ArrayList<String>();
+        mRemoved = new ArrayList<String>();
+
+        mReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                String action = intent.getAction();
+                if (SERVICE_CHECK.equals(action)) {
+                    Log.d(TAG, "SERVICE_CHECK");
+                    setResultCode(Activity.RESULT_OK);
+                } else if (SERVICE_POSTED.equals(action)) {
+                    Log.d(TAG, "SERVICE_POSTED");
+                    Bundle bundle = new Bundle();
+                    bundle.putStringArrayList(EXTRA_PAYLOAD, mPosted);
+                    setResultExtras(bundle);
+                    setResultCode(Activity.RESULT_OK);
+                } else if (SERVICE_PAYLOADS.equals(action)) {
+                    Log.d(TAG, "SERVICE_PAYLOADS");
+                    Bundle bundle = new Bundle();
+                    bundle.putStringArrayList(EXTRA_PAYLOAD, mPayloads);
+                    setResultExtras(bundle);
+                    setResultCode(Activity.RESULT_OK);
+                } else if (SERVICE_REMOVED.equals(action)) {
+                    Log.d(TAG, "SERVICE_REMOVED");
+                    Bundle bundle = new Bundle();
+                    bundle.putStringArrayList(EXTRA_PAYLOAD, mRemoved);
+                    setResultExtras(bundle);
+                    setResultCode(Activity.RESULT_OK);
+                } else if (SERVICE_CLEAR_ONE.equals(action)) {
+                    Log.d(TAG, "SERVICE_CLEAR_ONE");
+                    MockListener.this.cancelNotification(
+                            context.getApplicationInfo().packageName,
+                            intent.getStringExtra(EXTRA_TAG),
+                            intent.getIntExtra(EXTRA_CODE, 0));
+                } else if (SERVICE_CLEAR_ALL.equals(action)) {
+                    Log.d(TAG, "SERVICE_CLEAR_ALL");
+                    MockListener.this.cancelAllNotifications();
+                } else if (SERVICE_RESET.equals(action)) {
+                    Log.d(TAG, "SERVICE_RESET");
+                    resetData();
+                } else {
+                    Log.w(TAG, "unknown action");
+                    setResultCode(Activity.RESULT_CANCELED);
+                }
+            }
+        };
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(SERVICE_CHECK);
+        filter.addAction(SERVICE_POSTED);
+        filter.addAction(SERVICE_PAYLOADS);
+        filter.addAction(SERVICE_REMOVED);
+        filter.addAction(SERVICE_CLEAR_ONE);
+        filter.addAction(SERVICE_CLEAR_ALL);
+        filter.addAction(SERVICE_RESET);
+        registerReceiver(mReceiver, filter);
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        unregisterReceiver(mReceiver);
+        mReceiver = null;
+        Log.d(TAG, "destroyed");
+    }
+
+    public void resetData() {
+        mPosted.clear();
+        mPayloads.clear();
+        mRemoved.clear();
+        Log.d(TAG, "reset");
+    }
+
+    @Override
+    public void onNotificationPosted(StatusBarNotification sbn) {
+        Log.d(TAG, "posted: " + sbn.getTag());
+        mPosted.add(sbn.getTag());
+        StringBuilder payload = new StringBuilder();
+        payload.append(sbn.getTag());
+        payload.append(":");
+        payload.append(sbn.getId());
+        payload.append(":");
+        payload.append(sbn.getPackageName());
+        mPayloads.add(payload.toString());
+    }
+
+    @Override
+    public void onNotificationRemoved(StatusBarNotification sbn) {
+        Log.d(TAG, "removed: " + sbn.getTag());
+        mRemoved.add(sbn.getTag());
+    }
+
+    public static void resetListenerData(Context context) {
+        sendCommand(context, SERVICE_RESET, null, 0);
+    }
+
+    public static void probeListenerStatus(Context context, IntegerResultCatcher catcher) {
+        requestIntegerResult(context, SERVICE_CHECK, catcher);
+    }
+
+    public static void probeListenerPosted(Context context, StringListResultCatcher catcher) {
+        requestStringListResult(context, SERVICE_POSTED, catcher);
+    }
+
+    public static void probeListenerPayloads(Context context, StringListResultCatcher catcher) {
+        requestStringListResult(context, SERVICE_PAYLOADS, catcher);
+    }
+
+    public static void probeListenerRemoved(Context context, StringListResultCatcher catcher) {
+        requestStringListResult(context, SERVICE_REMOVED, catcher);
+    }
+
+    public static void clearOne(Context context, String tag, int code) {
+        sendCommand(context, SERVICE_CLEAR_ONE, tag, code);
+    }
+
+    public static void clearAll(Context context) {
+        sendCommand(context, SERVICE_CLEAR_ALL, null, 0);
+    }
+
+    private static void sendCommand(Context context, String action, String tag, int code) {
+        Intent broadcast = new Intent(action);
+        if (tag != null) {
+            broadcast.putExtra(EXTRA_TAG, tag);
+            broadcast.putExtra(EXTRA_CODE, code);
+        }
+        context.sendBroadcast(broadcast);
+    }
+
+    public abstract static class IntegerResultCatcher extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            accept(Integer.valueOf(getResultCode()));
+        }
+
+        abstract public void accept(int result);
+    }
+
+    private static void requestIntegerResult(Context context, String action,
+            IntegerResultCatcher catcher) {
+        Intent broadcast = new Intent(action);
+        context.sendOrderedBroadcast(broadcast, null, catcher, null, RESULT_NO_SERVER, null, null);
+    }
+
+    public abstract static class StringListResultCatcher extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            accept(getResultExtras(true).getStringArrayList(EXTRA_PAYLOAD));
+        }
+
+        abstract public void accept(List<String> result);
+    }
+
+    private static void requestStringListResult(Context context, String action,
+            StringListResultCatcher catcher) {
+        Intent broadcast = new Intent(action);
+        context.sendOrderedBroadcast(broadcast, null, catcher, null, RESULT_NO_SERVER, null, null);
+    }
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/nls/NotificationListenerVerifierActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/nls/NotificationListenerVerifierActivity.java
new file mode 100644
index 0000000..7c64eb6
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/nls/NotificationListenerVerifierActivity.java
@@ -0,0 +1,420 @@
+/*
+ * Copyright (C) 2013 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 com.android.cts.verifier.nls;
+
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.provider.Settings.Secure;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.android.cts.verifier.PassFailButtons;
+import com.android.cts.verifier.R;
+import com.android.cts.verifier.nfc.TagVerifierActivity;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.LinkedBlockingQueue;
+
+public class NotificationListenerVerifierActivity extends PassFailButtons.Activity
+implements Runnable {
+    static final String TAG = TagVerifierActivity.class.getSimpleName();
+    private static final String STATE = "state";
+    private static final String LISTENER_PATH = "com.android.cts.verifier/" + 
+            "com.android.cts.verifier.nls.MockListener";
+    private static final int PASS = 1;
+    private static final int FAIL = 2;
+    private static final int WAIT_FOR_USER = 3;
+    private static final int NOTIFICATION_ID = 1001;
+    private static LinkedBlockingQueue<String> sDeletedQueue = new LinkedBlockingQueue<String>();
+
+    private int mState = -1;
+    private int[] mStatus;
+    private LayoutInflater mInflater;
+    private ViewGroup mItemList;
+    private PackageManager mPackageManager;
+    private String mTag1;
+    private String mTag2;
+    private String mTag3;
+    private NotificationManager mNm;
+    private Context mContext;
+    private Runnable mRunner;
+    private View mHandler;
+    private String mIdString;
+    private String mPackageString;
+
+    public static class DismissService extends Service {
+        @Override
+        public IBinder onBind(Intent intent) {
+            return null;
+        }
+
+        @Override
+        public void onStart(Intent intent, int startId) {
+            sDeletedQueue.offer(intent.getAction());
+        }
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        if (savedInstanceState != null) {
+            mState = savedInstanceState.getInt(STATE, -1);
+        }
+        mContext = this;
+        mRunner = this;
+        mNm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+        mPackageManager = getPackageManager();
+        mInflater = getLayoutInflater();
+        View view = mInflater.inflate(R.layout.nls_main, null);
+        mItemList = (ViewGroup) view.findViewById(R.id.nls_test_items);
+        mHandler = mItemList;
+        createTestItems();
+        mStatus = new int[mItemList.getChildCount()];
+        setContentView(view);
+
+        setPassFailButtonClickListeners();
+        setInfoResources(R.string.nls_test, R.string.nls_info, -1);
+
+        getPassButton().setEnabled(false);
+    }
+
+    @Override
+    protected void onSaveInstanceState (Bundle outState) {
+        outState.putInt(STATE, mState);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        mHandler.post(mRunner);
+    }
+
+    // Interface Utilities
+
+    private void createTestItems() {
+        createUserItem(R.string.nls_enable_service);
+        createAutoItem(R.string.nls_service_started);
+        createAutoItem(R.string.nls_note_received);
+        createAutoItem(R.string.nls_payload_intact);
+        createAutoItem(R.string.nls_clear_one);
+        createAutoItem(R.string.nls_clear_all);
+        createUserItem(R.string.nls_disable_service);
+        createAutoItem(R.string.nls_service_stopped);
+        createAutoItem(R.string.nls_note_missed);
+    }
+
+    private void setItemState(int index, boolean passed) {
+        if (index != -1) {
+            ViewGroup item = (ViewGroup) mItemList.getChildAt(index);
+            ImageView status = (ImageView) item.findViewById(R.id.nls_status);
+            status.setImageResource(passed ? R.drawable.fs_good : R.drawable.fs_error);
+            View button = item.findViewById(R.id.nls_launch_settings);
+            button.setClickable(false);
+            button.setEnabled(false);
+            status.invalidate();
+        }
+    }
+
+    private View createUserItem(int stringId) {
+        View item = mInflater.inflate(R.layout.nls_item, mItemList, false);
+        TextView instructions = (TextView) item.findViewById(R.id.nls_instructions);
+        instructions.setText(stringId);
+        mItemList.addView(item);
+        return item;
+    }
+
+    private View createAutoItem(int stringId) {
+        View item = mInflater.inflate(R.layout.nls_item, mItemList, false);
+        TextView instructions = (TextView) item.findViewById(R.id.nls_instructions);
+        instructions.setText(stringId);
+        View button = item.findViewById(R.id.nls_launch_settings);
+        button.setVisibility(View.GONE);
+        mItemList.addView(item);
+        return item;
+    }
+
+    // Test management
+
+    public void run() {
+        while (mState >= 0 && mState < mStatus.length && mStatus[mState] != WAIT_FOR_USER) {
+            if (mStatus[mState] == PASS) {
+                setItemState(mState, true);
+                mState++;
+            } else if (mStatus[mState] == FAIL) {
+                setItemState(mState, false);
+                return;
+            } else {
+                break;
+            }
+        }
+
+        switch (mState) {
+            case -1:
+                mState++;
+                mHandler.post(mRunner);
+                break;
+            case 0:
+                testIsEnabled(0);
+                break;
+            case 1:
+                testIsStarted(1);
+                break;
+            case 2:
+                testNotificationRecieved(2);
+                break;
+            case 3:
+                testDataIntact(3);
+                break;
+            case 4:
+                testDismissOne(4);
+                break;
+            case 5:
+                testDismissAll(5);
+                break;
+            case 6:
+                testIsDisabled(6);
+                break;
+            case 7:
+                testIsStopped(7);
+                break;
+            case 8:
+                testNotificationNotRecieved(8);
+                break;
+            case 9:
+                getPassButton().setEnabled(true);
+                break;
+        }
+    }
+
+    public void launchSettings(View button) {
+        startActivity(
+                new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
+    }
+
+    private PendingIntent makeIntent(int code, String tag) {
+        Intent intent = new Intent(tag);
+        intent.setComponent(new ComponentName(mContext, DismissService.class));
+        PendingIntent pi = PendingIntent.getService(mContext, code, intent,
+                PendingIntent.FLAG_UPDATE_CURRENT);
+        return pi;
+    }
+
+    @SuppressLint("NewApi")
+    private void sendNotificaitons() {
+        mTag1 = UUID.randomUUID().toString();
+        mTag2 = UUID.randomUUID().toString();
+        mTag3 = UUID.randomUUID().toString();
+
+        mNm.cancelAll();
+
+        Notification n1 = new Notification.Builder(mContext)
+        .setContentTitle("ClearTest 1")
+        .setContentText(mTag1.toString())
+        .setPriority(Notification.PRIORITY_LOW)
+        .setSmallIcon(R.drawable.fs_good)
+        .setDeleteIntent(makeIntent(1, mTag1))
+        .build();
+        mNm.notify(mTag1, NOTIFICATION_ID + 1, n1);
+        mIdString = Integer.toString(NOTIFICATION_ID + 1);
+        mPackageString = "com.android.cts.verifier";
+
+        Notification n2 = new Notification.Builder(mContext)
+        .setContentTitle("ClearTest 2")
+        .setContentText(mTag2.toString())
+        .setPriority(Notification.PRIORITY_LOW)
+        .setSmallIcon(R.drawable.fs_good)
+        .setDeleteIntent(makeIntent(2, mTag2))
+        .build();
+        mNm.notify(mTag2, NOTIFICATION_ID + 2, n2);
+
+        Notification n3 = new Notification.Builder(mContext)
+        .setContentTitle("ClearTest 3")
+        .setContentText(mTag3.toString())
+        .setPriority(Notification.PRIORITY_LOW)
+        .setSmallIcon(R.drawable.fs_good)
+        .setDeleteIntent(makeIntent(3, mTag3))
+        .build();
+        mNm.notify(mTag3, NOTIFICATION_ID + 3, n3);
+    }
+
+    // Tests
+
+    private void testIsEnabled(int i) {
+        Intent settings = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
+        if (settings.resolveActivity(mPackageManager) == null) {
+            mStatus[i] = FAIL;
+        } else {
+            // TODO: find out why Secure.ENABLED_NOTIFICATION_LISTENERS is hidden
+            String listeners = Secure.getString(getContentResolver(),
+                    "enabled_notification_listeners");
+            if (listeners != null && listeners.contains(LISTENER_PATH)) {
+                mStatus[i] = PASS;
+            } else {
+                mStatus[i] = WAIT_FOR_USER;
+            }
+        }
+        mHandler.postDelayed(mRunner, 2000);
+    }
+
+    private void testIsStarted(final int i) {
+        MockListener.resetListenerData(this);
+        MockListener.probeListenerStatus(mContext,
+                new MockListener.IntegerResultCatcher() {
+            @Override
+            public void accept(int result) {
+                if (result == Activity.RESULT_OK) {
+                    mStatus[i] = PASS;
+                    // setup for testNotificationRecieved
+                    sendNotificaitons();
+                } else {
+                    mStatus[i] = FAIL;
+                }
+                mHandler.postDelayed(mRunner, 2000);
+            }
+        });
+    }
+
+    private void testNotificationRecieved(final int i) {
+        MockListener.probeListenerPosted(mContext,
+                new MockListener.StringListResultCatcher() {
+            @Override
+            public void accept(List<String> result) {
+                if (result.size() > 0 && result.contains(mTag1)) {
+                    mStatus[i] = PASS;
+                } else {
+                    mStatus[i] = FAIL;
+                }
+                mHandler.post(mRunner);
+            }});
+    }
+
+    private void testDataIntact(final int i) {
+        MockListener.probeListenerPayloads(mContext,
+                new MockListener.StringListResultCatcher() {
+            @Override
+            public void accept(List<String> result) {
+                mStatus[i] = FAIL;
+                if (result.size() > 0) {
+                    for(String payload : result) {
+                        if (payload.contains(mTag1) &&
+                                payload.contains(mIdString) &&
+                                payload.contains(mPackageString)) {
+                            mStatus[i] = PASS;
+                        }
+                    }
+                }
+                // setup for testDismissOne
+                MockListener.resetListenerData(mContext);
+                MockListener.clearOne(mContext, mTag1, NOTIFICATION_ID + 1);
+                mHandler.postDelayed(mRunner, 1000);
+            }});
+    }
+
+    private void testDismissOne(final int i) {
+        MockListener.probeListenerRemoved(mContext,
+                new MockListener.StringListResultCatcher() {
+            @Override
+            public void accept(List<String> result) {
+                if (result.size() > 0 && result.contains(mTag1)) {
+                    mStatus[i] = PASS;
+                } else {
+                    mStatus[i] = FAIL;
+                }
+
+                // setup for testDismissAll
+                MockListener.resetListenerData(mContext);
+                MockListener.clearAll(mContext);
+                mHandler.postDelayed(mRunner, 1000);
+            }});
+    }
+
+    private void testDismissAll(final int i) {
+        MockListener.probeListenerRemoved(mContext,
+                new MockListener.StringListResultCatcher() {
+            @Override
+            public void accept(List<String> result) {
+                if (result.size() == 2 && result.contains(mTag2) && result.contains(mTag3)) {
+                    mStatus[i] = PASS;
+                } else {
+                    mStatus[i] = FAIL;
+                }
+                mHandler.post(mRunner);
+            }
+        });   
+    }
+
+    private void testIsDisabled(int i) {
+        MockListener.resetListenerData(this);
+        // TODO: find out why Secure.ENABLED_NOTIFICATION_LISTENERS is hidden
+        String listeners = Secure.getString(getContentResolver(),
+                "enabled_notification_listeners");
+        if (listeners == null || !listeners.contains(LISTENER_PATH)) {
+            mStatus[i] = PASS;
+        } else {
+            mStatus[i] = WAIT_FOR_USER;
+        }
+        mHandler.postDelayed(mRunner, 2000);
+    }
+
+    private void testIsStopped(final int i) {
+        MockListener.probeListenerStatus(mContext,
+                new MockListener.IntegerResultCatcher() {
+            @Override
+            public void accept(int result) {
+                if (result == Activity.RESULT_OK) {
+                    MockListener.resetListenerData(mContext);
+                    sendNotificaitons();
+                    mStatus[i] = FAIL;
+                } else {
+                    mStatus[i] = PASS;
+                }
+                // setup for testNotificationRecieved
+                sendNotificaitons();
+                mHandler.postDelayed(mRunner, 1000);
+            }
+        });
+    }
+
+    private void testNotificationNotRecieved(final int i) {
+        MockListener.probeListenerPosted(mContext,
+                new MockListener.StringListResultCatcher() {
+            @Override
+            public void accept(List<String> result) {
+                if (result == null || result.size() == 0) {
+                    mStatus[i] = PASS;
+                } else {
+                    mStatus[i] = FAIL;
+                }
+                mHandler.post(mRunner);
+            }});
+    }
+}
diff --git a/suite/pts/deviceTests/browserbench/assets/octane/index.html b/suite/pts/deviceTests/browserbench/assets/octane/index.html
index 704123f..9c072d6 100644
--- a/suite/pts/deviceTests/browserbench/assets/octane/index.html
+++ b/suite/pts/deviceTests/browserbench/assets/octane/index.html
@@ -73,7 +73,6 @@
     document.getElementById("progress-bar-container").style.visibility = 'hidden';
     document.getElementById("bottom-text").style.visibility = 'visible';
     document.getElementById("inside-anchor").removeChild(document.getElementById("bar-appendix"));
-    document.getElementById("warning-header").style.visibility = 'hidden';
   }
 
   function Run() {
diff --git a/suite/pts/deviceTests/dram/src/com/android/pts/dram/BandwidthTest.java b/suite/pts/deviceTests/dram/src/com/android/pts/dram/BandwidthTest.java
index 8f6860f..62b0163 100644
--- a/suite/pts/deviceTests/dram/src/com/android/pts/dram/BandwidthTest.java
+++ b/suite/pts/deviceTests/dram/src/com/android/pts/dram/BandwidthTest.java
@@ -35,11 +35,14 @@
  */
 public class BandwidthTest extends PtsAndroidTestCase {
     private static final String TAG = "BandwidthTest";
-    private static final int REPETITION = 10;
+    private static final int MEMCPY_REPETITION = 10;
+    private static final int MEMSET_REPETITION = 30;
     private static final int REPEAT_IN_EACH_CALL = 100;
     private static final int KB = 1024;
     private static final int MB = 1024 * 1024;
     private static final int MEMSET_CHAR = 0xa5;
+    // reject data outside +/- this value * median
+    private static final double OUTLIER_THRESHOLD = 0.1;
 
     @Override
     protected void setUp() throws Exception {
@@ -153,13 +156,13 @@
     }
 
     private void doRunMemcpy(int bufferSize) {
-        double[] result = new double[REPETITION];
+        double[] result = new double[MEMCPY_REPETITION];
         int repeatInEachCall = REPEAT_IN_EACH_CALL;
         if (bufferSize < (1 * MB)) {
             // too small buffer size finishes too early to give accurate result.
             repeatInEachCall *= (1 * MB / bufferSize);
         }
-        for (int i = 0; i < REPETITION; i++) {
+        for (int i = 0; i < MEMCPY_REPETITION; i++) {
             result[i] = MemoryNative.runMemcpy(bufferSize, repeatInEachCall);
         }
         getReportLog().printArray("memcpy time", result, ResultType.LOWER_BETTER,
@@ -168,7 +171,10 @@
                 (double)bufferSize * repeatInEachCall / 1024.0 / 1024.0, result);
         getReportLog().printArray("memcpy throughput", mbps, ResultType.HIGHER_BETTER,
                 ResultUnit.MBPS);
-        Stat.StatResult stat = Stat.getStat(mbps);
+        Stat.StatResult stat = Stat.getStatWithOutlierRejection(mbps, OUTLIER_THRESHOLD);
+        if (stat.mDataCount != result.length) {
+            Log.w(TAG, "rejecting " + (result.length - stat.mDataCount) + " outliers");
+        }
         WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
         Point size = new Point();
         wm.getDefaultDisplay().getSize(size);
@@ -183,13 +189,13 @@
     }
 
     private void doRunMemset(int bufferSize) {
-        double[] result = new double[REPETITION];
+        double[] result = new double[MEMSET_REPETITION];
         int repeatInEachCall = REPEAT_IN_EACH_CALL;
         if (bufferSize < (1 * MB)) {
             // too small buffer size finishes too early to give accurate result.
             repeatInEachCall *= (1 * MB / bufferSize);
         }
-        for (int i = 0; i < REPETITION; i++) {
+        for (int i = 0; i < MEMSET_REPETITION; i++) {
             result[i] = MemoryNative.runMemset(bufferSize, repeatInEachCall, MEMSET_CHAR);
         }
         getReportLog().printArray("memset time", result, ResultType.LOWER_BETTER,
@@ -198,7 +204,10 @@
                 (double)bufferSize * repeatInEachCall / 1024.0 / 1024.0, result);
         getReportLog().printArray("memset throughput", mbps, ResultType.HIGHER_BETTER,
                 ResultUnit.MBPS);
-        Stat.StatResult stat = Stat.getStat(mbps);
+        Stat.StatResult stat = Stat.getStatWithOutlierRejection(mbps, OUTLIER_THRESHOLD);
+        if (stat.mDataCount != result.length) {
+            Log.w(TAG, "rejecting " + (result.length - stat.mDataCount) + " outliers");
+        }
         WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
         Point size = new Point();
         wm.getDefaultDisplay().getSize(size);
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java
index 75b443d..b43c80d 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java
@@ -114,7 +114,7 @@
     @TimeoutReq(minutes = 60)
     public void testRandomUpdate() throws Exception {
         final int BUFFER_SIZE = 4 * 1024;
-        final long fileSize = 400L * 1024L * 1024L;
+        final long fileSize = 256L * 1024L * 1024L;
         FileUtil.doRandomWriteTest(getContext(), DIR_RANDOM_WR, getReportLog(), fileSize,
                 BUFFER_SIZE);
     }
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FileUtil.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FileUtil.java
index d698b4b..2119ee5 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FileUtil.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/FileUtil.java
@@ -287,6 +287,7 @@
 
             @Override
             public void run(int i) throws IOException {
+                Log.i(TAG, "starting " + i + " -th round");
                 int start = i * readsInOneMeasure;
                 int end = (i + 1) * readsInOneMeasure;
                 for (int j = start; j < end; j++) {
@@ -330,7 +331,7 @@
                     ~(bufferSize - 1);
         }
         final int runsInOneGo = 16;
-        final int writesInOneMeasure = totalWriteCount / runsInOneGo; // 32MB at a time
+        final int writesInOneMeasure = totalWriteCount / runsInOneGo;
 
         final RandomAccessFile randomFile = new RandomAccessFile(file, "rwd"); // force O_SYNC
         double[] rdAmount = new double[runsInOneGo];
@@ -339,6 +340,7 @@
 
             @Override
             public void run(int i) throws IOException {
+                Log.i(TAG, "starting " + i + " -th round");
                 int start = i * writesInOneMeasure;
                 int end = (i + 1) * writesInOneMeasure;
                 for (int j = start; j < end; j++) {
@@ -378,6 +380,7 @@
         int numberRepeatInOneRun = (int)(fileSize / bufferSize);
         double[] mbpsAll = new double[numberRepetition * numberRepeatInOneRun];
         for (int i = 0; i < numberRepetition; i++) {
+            Log.i(TAG, "starting " + i + " -th round");
             final RandomAccessFile randomFile = new RandomAccessFile(file, "rwd");  // force O_SYNC
             randomFile.seek(0L);
             double[] times = MeasureTime.measure(numberRepeatInOneRun, new MeasureRun() {
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
index 0ac096f..6b6086b 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
@@ -43,11 +43,11 @@
                 READ_BUFFER_SIZE);
     }
 
-    // It is taking too long in tuna, and thus cannot run multiple times
+    // It is taking too long in some device, and thus cannot run multiple times
     @TimeoutReq(minutes = 60)
     public void testRandomUpdate() throws Exception {
         final int WRITE_BUFFER_SIZE = 4 * 1024;
-        final long fileSize = 512 * 1024 * 1024;
+        final long fileSize = 256 * 1024 * 1024;
         FileUtil.doRandomWriteTest(getContext(), DIR_RANDOM_WR, getReportLog(), fileSize,
                 WRITE_BUFFER_SIZE);
     }
diff --git a/suite/pts/deviceTests/opengl/AndroidManifest.xml b/suite/pts/deviceTests/opengl/AndroidManifest.xml
index 7cfebaa..86e21e2 100644
--- a/suite/pts/deviceTests/opengl/AndroidManifest.xml
+++ b/suite/pts/deviceTests/opengl/AndroidManifest.xml
@@ -20,7 +20,7 @@
 
         <activity
             android:name="com.android.pts.opengl.primitive.GLPrimitiveActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -30,7 +30,7 @@
         </activity>
         <activity
             android:name="com.android.pts.opengl.reference.GLReferenceActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize" >
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
@@ -39,7 +39,7 @@
         </activity>
         <activity
             android:name="com.android.pts.opengl.reference.GLGameActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
         </activity>
     </application>
diff --git a/suite/pts/deviceTests/simplecpu/src/com/android/pts/simplecpu/SimpleCpuTest.java b/suite/pts/deviceTests/simplecpu/src/com/android/pts/simplecpu/SimpleCpuTest.java
index 8b17171..8278618 100644
--- a/suite/pts/deviceTests/simplecpu/src/com/android/pts/simplecpu/SimpleCpuTest.java
+++ b/suite/pts/deviceTests/simplecpu/src/com/android/pts/simplecpu/SimpleCpuTest.java
@@ -17,6 +17,7 @@
 package com.android.pts.simplecpu;
 
 import android.cts.util.TimeoutReq;
+import android.util.Log;
 
 import com.android.pts.util.ResultType;
 import com.android.pts.util.ResultUnit;
@@ -35,6 +36,8 @@
     private static final int KB = 1024;
     private static final int MB = 1024 * 1024;
     private static final int NUMBER_REPEAT = 20;
+    // reject data outside +/- this value * median
+    private static final double OUTLIER_THRESHOLD = 0.1;
 
     @Override
     protected void setUp() throws Exception {
@@ -99,7 +102,10 @@
         }
         getReportLog().printArray("sorting time", result, ResultType.LOWER_BETTER,
                 ResultUnit.MS);
-        Stat.StatResult stat = Stat.getStat(result);
+        Stat.StatResult stat = Stat.getStatWithOutlierRejection(result, OUTLIER_THRESHOLD);
+        if (stat.mDataCount != result.length) {
+            Log.w(TAG, "rejecting " + (result.length - stat.mDataCount) + " outliers");
+        }
         getReportLog().printSummary("sorting time", stat.mAverage, ResultType.LOWER_BETTER,
                 ResultUnit.MS);
     }
@@ -118,7 +124,10 @@
         }
         getReportLog().printArray("matrix mutiplication time", result, ResultType.LOWER_BETTER,
                 ResultUnit.MS);
-        Stat.StatResult stat = Stat.getStat(result);
+        Stat.StatResult stat = Stat.getStatWithOutlierRejection(result, OUTLIER_THRESHOLD);
+        if (stat.mDataCount != result.length) {
+            Log.w(TAG, "rejecting " + (result.length - stat.mDataCount) + " outliers");
+        }
         getReportLog().printSummary("matrix mutiplication time", stat.mAverage,
                 ResultType.LOWER_BETTER, ResultUnit.MS);
     }
diff --git a/suite/pts/deviceTests/ui/AndroidManifest.xml b/suite/pts/deviceTests/ui/AndroidManifest.xml
index 639e3d6..839e8aa 100644
--- a/suite/pts/deviceTests/ui/AndroidManifest.xml
+++ b/suite/pts/deviceTests/ui/AndroidManifest.xml
@@ -26,7 +26,7 @@
 
         <activity
             android:name=".ScrollingActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
             android:screenOrientation="portrait" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -36,7 +36,7 @@
         </activity>
         <activity
             android:name="android.openglperf.cts.GlPlanetsActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize" />
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" />
     </application>
 
     <instrumentation
diff --git a/suite/pts/hostTests/uihost/appA/AndroidManifest.xml b/suite/pts/hostTests/uihost/appA/AndroidManifest.xml
index 4491210..847487d 100644
--- a/suite/pts/hostTests/uihost/appA/AndroidManifest.xml
+++ b/suite/pts/hostTests/uihost/appA/AndroidManifest.xml
@@ -23,7 +23,7 @@
     <application>
         <activity
             android:name=".AppAActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
             android:screenOrientation="portrait" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
diff --git a/suite/pts/hostTests/uihost/appB/AndroidManifest.xml b/suite/pts/hostTests/uihost/appB/AndroidManifest.xml
index 29bf661..d0c0bb7 100644
--- a/suite/pts/hostTests/uihost/appB/AndroidManifest.xml
+++ b/suite/pts/hostTests/uihost/appB/AndroidManifest.xml
@@ -22,7 +22,7 @@
     <application>
         <activity
             android:name=".AppBActivity"
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
             android:screenOrientation="portrait" >
 
             <intent-filter>
diff --git a/suite/pts/hostTests/uihost/src/com/android/pts/uihost/InstallTimeTest.java b/suite/pts/hostTests/uihost/src/com/android/pts/uihost/InstallTimeTest.java
index 55e9b40..b6f8f40 100644
--- a/suite/pts/hostTests/uihost/src/com/android/pts/uihost/InstallTimeTest.java
+++ b/suite/pts/hostTests/uihost/src/com/android/pts/uihost/InstallTimeTest.java
@@ -17,6 +17,7 @@
 package com.android.pts.uihost;
 
 import com.android.cts.tradefed.build.CtsBuildHelper;
+import com.android.ddmlib.Log;
 import com.android.pts.util.HostReportLog;
 import com.android.pts.util.MeasureRun;
 import com.android.pts.util.MeasureTime;
@@ -40,8 +41,10 @@
     private CtsBuildHelper mBuild;
     private ITestDevice mDevice;
 
+    private static final String TAG = "InstallTimeTest";
     static final String PACKAGE = "com.replica.replicaisland";
     static final String APK = "com.replica.replicaisland.apk";
+    private static final double OUTLIER_THRESHOLD = 0.1;
 
     @Override
     public void setBuild(IBuildInfo buildInfo) {
@@ -80,7 +83,10 @@
         });
         report.printArray("install time", result, ResultType.LOWER_BETTER,
                 ResultUnit.MS);
-        StatResult stat = Stat.getStat(result);
+        Stat.StatResult stat = Stat.getStatWithOutlierRejection(result, OUTLIER_THRESHOLD);
+        if (stat.mDataCount != result.length) {
+            Log.w(TAG, "rejecting " + (result.length - stat.mDataCount) + " outliers");
+        }
         report.printSummary("install time", stat.mAverage, ResultType.LOWER_BETTER,
                 ResultUnit.MS);
         report.deliverReportToHost();
diff --git a/suite/pts/lib/commonutil/src/com/android/pts/util/Stat.java b/suite/pts/lib/commonutil/src/com/android/pts/util/Stat.java
index d56f59e..5560292 100644
--- a/suite/pts/lib/commonutil/src/com/android/pts/util/Stat.java
+++ b/suite/pts/lib/commonutil/src/com/android/pts/util/Stat.java
@@ -16,6 +16,8 @@
 
 package com.android.pts.util;
 
+import java.util.Arrays;
+
 /**
  * Utilities for doing statistics
  *
@@ -30,11 +32,13 @@
         public double mMin;
         public double mMax;
         public double mStddev;
-        public StatResult(double average, double min, double max, double stddev) {
+        public int mDataCount;
+        public StatResult(double average, double min, double max, double stddev, int dataCount) {
             mAverage = average;
             mMin = min;
             mMax = max;
             mStddev = stddev;
+            mDataCount = dataCount;
         }
     }
 
@@ -60,7 +64,58 @@
         eX2 /= data.length;
         // stddev = sqrt(E[X^2] - (E[X])^2)
         double stddev = Math.sqrt(eX2 - average * average);
-        return new StatResult(average, min, max, stddev);
+        return new StatResult(average, min, max, stddev, data.length);
+    }
+
+    /**
+     * Calculate statistics properties likes average, min, max, and stddev for the given array
+     * while rejecting outlier +/- median * rejectionThreshold.
+     * rejectionThreshold should be bigger than 0.0 and be lowerthan 1.0
+     */
+    public static StatResult getStatWithOutlierRejection(double[] data, double rejectionThreshold) {
+        double[] dataCopied = Arrays.copyOf(data, data.length);
+        Arrays.sort(dataCopied);
+        int medianIndex = dataCopied.length / 2;
+        double median;
+        if (dataCopied.length % 2 == 1) {
+            median = dataCopied[medianIndex];
+        } else {
+            median = (dataCopied[medianIndex - 1] + dataCopied[medianIndex]) / 2.0;
+        }
+        double thresholdMin = median * (1.0 - rejectionThreshold);
+        double thresholdMax = median * (1.0 + rejectionThreshold);
+
+        double average = 0.0;
+        double min = median;
+        double max = median;
+        double eX2 = 0.0; // will become E[X^2]
+        int validDataCounter = 0;
+        for (int i = 0; i < data.length; i++) {
+            if ((data[i] > thresholdMin) && (data[i] < thresholdMax)) {
+                validDataCounter++;
+                average += data[i];
+                eX2 += data[i] * data[i];
+                if (data[i] > max) {
+                    max = data[i];
+                }
+                if (data[i] < min) {
+                    min = data[i];
+                }
+            }
+            //TODO report rejected data
+        }
+        double stddev;
+        if (validDataCounter > 0) {
+            average /= validDataCounter;
+            eX2 /= validDataCounter;
+            // stddev = sqrt(E[X^2] - (E[X])^2)
+            stddev = Math.sqrt(eX2 - average * average);
+        } else { // both median is showing too much diff
+            average = median;
+            stddev = 0; // don't care
+        }
+
+        return new StatResult(average, min, max, stddev, validDataCounter);
     }
 
     /**
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 662693e..75ba598 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -959,7 +959,8 @@
 
         <activity android:name="android.opengl.cts.OpenGlEsVersionStubActivity"/>
 
-        <activity android:name="android.opengl.cts.EglConfigStubActivity"/>
+        <activity android:name="android.opengl.cts.EglConfigStubActivity"
+            android:configChanges="keyboardHidden|orientation|screenSize|uiMode" />
 
         <activity android:name="android.opengl.cts.CompressedTextureStubActivity"
             android:label="CompressedTextureStubActivity"
diff --git a/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java b/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
index 4bbd05d..93b78a2 100644
--- a/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
+++ b/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
@@ -23,7 +23,6 @@
 import android.opengl.GLES20;
 import android.test.AndroidTestCase;
 import android.util.Log;
-import android.view.Surface;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
@@ -31,7 +30,6 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
-import java.util.Arrays;
 
 import javax.microedition.khronos.opengles.GL10;
 
@@ -59,7 +57,6 @@
 
     // parameters for the encoder
     private static final String MIME_TYPE = "video/avc";    // H.264 Advanced Video Coding
-    private static final int BIT_RATE = 2000000;            // 2Mbps
     private static final int FRAME_RATE = 15;               // 15fps
     private static final int IFRAME_INTERVAL = 10;          // 10 seconds between I-frames
 
@@ -86,21 +83,23 @@
     // size of a frame, in pixels
     private int mWidth = -1;
     private int mHeight = -1;
+    // bit rate, in bits per second
+    private int mBitRate = -1;
 
     // largest color component delta seen (i.e. actual vs. expected)
     private int mLargestColorDelta;
 
 
     public void testVideoEditQCIF() throws Throwable {
-        setSize(176, 144);
+        setParameters(176, 144, 1000000);
         VideoEditWrapper.runTest(this);
     }
     public void testVideoEditQVGA() throws Throwable {
-        setSize(320, 240);
+        setParameters(320, 240, 2000000);
         VideoEditWrapper.runTest(this);
     }
     public void testVideoEdit720p() throws Throwable {
-        setSize(1280, 720);
+        setParameters(1280, 720, 6000000);
         VideoEditWrapper.runTest(this);
     }
 
@@ -138,14 +137,15 @@
     }
 
     /**
-     * Sets the desired frame size.
+     * Sets the desired frame size and bit rate.
      */
-    private void setSize(int width, int height) {
+    private void setParameters(int width, int height, int bitRate) {
         if ((width % 16) != 0 || (height % 16) != 0) {
             Log.w(TAG, "WARNING: width or height not multiple of 16");
         }
         mWidth = width;
         mHeight = height;
+        mBitRate = bitRate;
     }
 
     /**
@@ -206,7 +206,7 @@
             // configure() call to throw an unhelpful exception.
             format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
                     MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
-            format.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
+            format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
             format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
             format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
             if (VERBOSE) Log.d(TAG, "format: " + format);
diff --git a/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java b/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
index 5d1a3ba..849877a 100644
--- a/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
+++ b/tests/tests/media/src/android/media/cts/EncodeDecodeTest.java
@@ -16,7 +16,6 @@
 
 package android.media.cts;
 
-import android.graphics.SurfaceTexture;
 import android.media.MediaCodec;
 import android.media.MediaCodecInfo;
 import android.media.MediaCodecList;
@@ -24,7 +23,6 @@
 import android.opengl.GLES20;
 import android.test.AndroidTestCase;
 import android.util.Log;
-import android.view.Surface;
 
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -54,7 +52,6 @@
 
     // parameters for the encoder
     private static final String MIME_TYPE = "video/avc";    // H.264 Advanced Video Coding
-    private static final int BIT_RATE = 2000000;            // 2Mbps
     private static final int FRAME_RATE = 15;               // 15fps
     private static final int IFRAME_INTERVAL = 10;          // 10 seconds between I-frames
 
@@ -74,6 +71,8 @@
     // size of a frame, in pixels
     private int mWidth = -1;
     private int mHeight = -1;
+    // bit rate, in bits per second
+    private int mBitRate = -1;
 
     // largest color component delta seen (i.e. actual vs. expected)
     private int mLargestColorDelta;
@@ -85,15 +84,15 @@
      * validity.
      */
     public void testEncodeDecodeVideoFromBufferToBufferQCIF() throws Exception {
-        setSize(176, 144);
+        setParameters(176, 144, 1000000);
         encodeDecodeVideoFromBuffer(false);
     }
     public void testEncodeDecodeVideoFromBufferToBufferQVGA() throws Exception {
-        setSize(320, 240);
+        setParameters(320, 240, 2000000);
         encodeDecodeVideoFromBuffer(false);
     }
     public void testEncodeDecodeVideoFromBufferToBuffer720p() throws Exception {
-        setSize(1280, 720);
+        setParameters(1280, 720, 6000000);
         encodeDecodeVideoFromBuffer(false);
     }
 
@@ -110,15 +109,15 @@
      * the test.
      */
     public void testEncodeDecodeVideoFromBufferToSurfaceQCIF() throws Throwable {
-        setSize(176, 144);
+        setParameters(176, 144, 1000000);
         BufferToSurfaceWrapper.runTest(this);
     }
     public void testEncodeDecodeVideoFromBufferToSurfaceQVGA() throws Throwable {
-        setSize(320, 240);
+        setParameters(320, 240, 2000000);
         BufferToSurfaceWrapper.runTest(this);
     }
     public void testEncodeDecodeVideoFromBufferToSurface720p() throws Throwable {
-        setSize(1280, 720);
+        setParameters(1280, 720, 6000000);
         BufferToSurfaceWrapper.runTest(this);
     }
 
@@ -158,15 +157,15 @@
      * a Surface and decoded onto a Surface.  The output is checked for validity.
      */
     public void testEncodeDecodeVideoFromSurfaceToSurfaceQCIF() throws Throwable {
-        setSize(176, 144);
+        setParameters(176, 144, 1000000);
         SurfaceToSurfaceWrapper.runTest(this);
     }
     public void testEncodeDecodeVideoFromSurfaceToSurfaceQVGA() throws Throwable {
-        setSize(320, 240);
+        setParameters(320, 240, 2000000);
         SurfaceToSurfaceWrapper.runTest(this);
     }
     public void testEncodeDecodeVideoFromSurfaceToSurface720p() throws Throwable {
-        setSize(1280, 720);
+        setParameters(1280, 720, 6000000);
         SurfaceToSurfaceWrapper.runTest(this);
     }
 
@@ -202,14 +201,15 @@
     }
 
     /**
-     * Sets the desired frame size.
+     * Sets the desired frame size and bit rate.
      */
-    private void setSize(int width, int height) {
+    private void setParameters(int width, int height, int bitRate) {
         if ((width % 16) != 0 || (height % 16) != 0) {
             Log.w(TAG, "WARNING: width or height not multiple of 16");
         }
         mWidth = width;
         mHeight = height;
+        mBitRate = bitRate;
     }
 
     /**
@@ -245,7 +245,7 @@
             // Set some properties.  Failing to specify some of these can cause the MediaCodec
             // configure() call to throw an unhelpful exception.
             format.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
-            format.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
+            format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
             format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
             format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
             if (VERBOSE) Log.d(TAG, "format: " + format);
@@ -308,7 +308,7 @@
             // Set some properties.  Failing to specify some of these can cause the MediaCodec
             // configure() call to throw an unhelpful exception.
             format.setInteger(MediaFormat.KEY_COLOR_FORMAT, colorFormat);
-            format.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
+            format.setInteger(MediaFormat.KEY_BIT_RATE, mBitRate);
             format.setInteger(MediaFormat.KEY_FRAME_RATE, FRAME_RATE);
             format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, IFRAME_INTERVAL);
             if (VERBOSE) Log.d(TAG, "format: " + format);
diff --git a/tests/tests/media/src/android/media/cts/MediaDrmMockTest.java b/tests/tests/media/src/android/media/cts/MediaDrmMockTest.java
index 4074e70..a8131bf 100644
--- a/tests/tests/media/src/android/media/cts/MediaDrmMockTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaDrmMockTest.java
@@ -21,6 +21,7 @@
 import android.media.MediaDrm.KeyRequest;
 import android.media.MediaDrm.CryptoSession;
 import android.media.MediaDrmException;
+import android.media.NotProvisionedException;
 import android.test.AndroidTestCase;
 import android.util.Log;
 import java.util.HashMap;
@@ -164,7 +165,7 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
         md.closeSession(sessionId);
     }
 
@@ -206,7 +207,7 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
 
         // Set up mock expected responses using properties
         byte testRequest[] = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12};
@@ -240,7 +241,7 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
 
         // Set up mock expected responses using properties
         byte testRequest[] = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12};
@@ -270,7 +271,7 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
 
         // Set up mock expected responses using properties
         byte testRequest[] = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12};
@@ -300,7 +301,7 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
 
         // Set up mock expected responses using properties
         byte testRequest[] = {0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12};
@@ -327,7 +328,7 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
 
         // Set up mock expected responses using properties
         byte testResponse[] = {0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20};
@@ -344,7 +345,7 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
 
         byte testResponse[] = {0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20};
         byte[] keySetId = md.provideKeyResponse(sessionId, testResponse);
@@ -359,13 +360,13 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
 
         byte testResponse[] = {0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20};
         byte[] keySetId = md.provideKeyResponse(sessionId, testResponse);
         md.closeSession(sessionId);
 
-        sessionId = md.openSession();
+        sessionId = openSession(md);
         md.restoreKeys(sessionId, keySetId);
         md.closeSession(sessionId);
     }
@@ -376,7 +377,7 @@
         }
 
         MediaDrm md = new MediaDrm(mockScheme);
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
         HashMap<String, String> infoMap = md.queryKeyStatus(sessionId);
 
         // these are canned strings returned by the mock
@@ -466,9 +467,9 @@
 
         MediaDrm md = new MediaDrm(mockScheme);
 
-        byte[] session1 = md.openSession();
-        byte[] session2 = md.openSession();
-        byte[] session3 = md.openSession();
+        byte[] session1 = openSession(md);
+        byte[] session2 = openSession(md);
+        byte[] session3 = openSession(md);
 
         assertFalse(Arrays.equals(session1, session2));
         assertFalse(Arrays.equals(session2, session3));
@@ -485,7 +486,7 @@
 
         MediaDrm md = new MediaDrm(mockScheme);
 
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
         CryptoSession cs = md.getCryptoSession(sessionId, "AES/CBC/NoPadding", "HmacSHA256");
         assertFalse(cs == null);
     }
@@ -499,7 +500,7 @@
 
         boolean gotException = false;
         try {
-            byte[] sessionId = md.openSession();
+            byte[] sessionId = openSession(md);
             CryptoSession cs = md.getCryptoSession(sessionId, "bad", "bad");
         } catch (IllegalArgumentException e) {
             gotException = true;
@@ -514,7 +515,7 @@
 
         MediaDrm md = new MediaDrm(mockScheme);
 
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
         CryptoSession cs = md.getCryptoSession(sessionId, "AES/CBC/NoPadding", "HmacSHA256");
         assertFalse(cs == null);
 
@@ -540,7 +541,7 @@
 
         MediaDrm md = new MediaDrm(mockScheme);
 
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
         CryptoSession cs = md.getCryptoSession(sessionId, "AES/CBC/NoPadding", "HmacSHA256");
         assertFalse(cs == null);
 
@@ -566,7 +567,7 @@
 
         MediaDrm md = new MediaDrm(mockScheme);
 
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
         CryptoSession cs = md.getCryptoSession(sessionId, "AES/CBC/NoPadding", "HmacSHA256");
         assertFalse(cs == null);
 
@@ -590,7 +591,7 @@
 
         MediaDrm md = new MediaDrm(mockScheme);
 
-        byte[] sessionId = md.openSession();
+        byte[] sessionId = openSession(md);
         CryptoSession cs = md.getCryptoSession(sessionId, "AES/CBC/NoPadding", "HmacSHA256");
         assertFalse(cs == null);
 
@@ -708,7 +709,7 @@
                 }
 
 
-                final byte[] expected_sessionId = mMediaDrm.openSession();
+                final byte[] expected_sessionId = openSession(mMediaDrm);
                 final byte[] expected_data = {0x10, 0x11, 0x12, 0x13, 0x14,
                                               0x15, 0x16, 0x17, 0x18, 0x19};
 
@@ -761,4 +762,14 @@
         mLooper.quit();
         assertTrue(mGotEvent);
     }
+
+    private byte[] openSession(MediaDrm md) {
+        byte[] sessionId = null;
+        try {
+            sessionId = md.openSession();
+        } catch (NotProvisionedException e) {
+            // ignore, not thrown by mock
+        }
+        return sessionId;
+    }
 }
diff --git a/tests/tests/os/src/android/os/cts/BuildVersionTest.java b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
index 888a768..d1b88a1 100644
--- a/tests/tests/os/src/android/os/cts/BuildVersionTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
@@ -30,7 +30,7 @@
     private static final String LOG_TAG = "BuildVersionTest";
     private static final Set<String> EXPECTED_RELEASES =
             new HashSet<String>(Arrays.asList("4.3"));
-    private static final int EXPECTED_SDK = 17;
+    private static final int EXPECTED_SDK = 18;
 
     @SuppressWarnings("deprecation")
     public void testReleaseVersion() {