Merge "Adjust bit rate based on resolution" into jb-mr2-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 9b8d5b1..9ff7edc 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -18,7 +18,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.android.cts.verifier"
       android:versionCode="1"
-      android:versionName="1337">
+      android:versionName="4.3_r1">
 
     <!-- Using 10 for more complete NFC support... -->
     <uses-sdk android:minSdkVersion="10"></uses-sdk>
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 dc906c8..86e21e2 100644
--- a/suite/pts/deviceTests/opengl/AndroidManifest.xml
+++ b/suite/pts/deviceTests/opengl/AndroidManifest.xml
@@ -5,14 +5,14 @@
     android:versionName="1.0" >
 
     <uses-sdk
-        android:targetSdkVersion="17"
-        android:minSdkVersion="16" />
+        android:minSdkVersion="16"
+        android:targetSdkVersion="17" />
 
     <uses-feature
         android:glEsVersion="0x00020000"
         android:required="true" />
 
-    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />\
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
 
     <application android:allowBackup="false" >
@@ -20,6 +20,7 @@
 
         <activity
             android:name="com.android.pts.opengl.primitive.GLPrimitiveActivity"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -27,18 +28,18 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-
         <activity
-            android:name="com.android.pts.opengl.reference.GLReferenceActivity" >
+            android:name="com.android.pts.opengl.reference.GLReferenceActivity"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-
         <activity
             android:name="com.android.pts.opengl.reference.GLGameActivity"
+            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 6925b5d..839e8aa 100644
--- a/suite/pts/deviceTests/ui/AndroidManifest.xml
+++ b/suite/pts/deviceTests/ui/AndroidManifest.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2012 The Android Open Source Project
+<!--
+     Copyright (C) 2012 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.
@@ -15,25 +16,32 @@
 -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-        package="com.android.pts.ui">
+    package="com.android.pts.ui" >
 
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
     <application>
         <uses-library android:name="android.test.runner" />
+
         <activity
-                android:name=".ScrollingActivity"
-                android:screenOrientation="portrait"
-                android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
+            android:name=".ScrollingActivity"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
+            android:screenOrientation="portrait" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER"/>
+
+                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-         <activity android:name="android.openglperf.cts.GlPlanetsActivity" />
+        <activity
+            android:name="android.openglperf.cts.GlPlanetsActivity"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" />
     </application>
-    <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
-            android:targetPackage="com.android.pts.ui"
-            android:label="UI Latency measurement" />
-</manifest>
+
+    <instrumentation
+        android:name="android.test.InstrumentationCtsTestRunner"
+        android:label="UI Latency measurement"
+        android:targetPackage="com.android.pts.ui" />
+
+</manifest>
\ No newline at end of file
diff --git a/suite/pts/hostTests/uihost/appA/AndroidManifest.xml b/suite/pts/hostTests/uihost/appA/AndroidManifest.xml
index 1115ee6..847487d 100644
--- a/suite/pts/hostTests/uihost/appA/AndroidManifest.xml
+++ b/suite/pts/hostTests/uihost/appA/AndroidManifest.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2012 The Android Open Source Project
+<!--
+     Copyright (C) 2012 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.
@@ -15,19 +16,21 @@
 -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-        package="com.android.pts.taskswitching.appa">
+    package="com.android.pts.taskswitching.appa" >
 
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
 
     <application>
         <activity
-                android:name=".AppAActivity"
-                android:screenOrientation="portrait"
-                android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
+            android:name=".AppAActivity"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
+            android:screenOrientation="portrait" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.LAUNCHER"/>
+
+                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
     </application>
-</manifest>
+
+</manifest>
\ No newline at end of file
diff --git a/suite/pts/hostTests/uihost/appB/AndroidManifest.xml b/suite/pts/hostTests/uihost/appB/AndroidManifest.xml
index d0ec4d7..d0c0bb7 100644
--- a/suite/pts/hostTests/uihost/appB/AndroidManifest.xml
+++ b/suite/pts/hostTests/uihost/appB/AndroidManifest.xml
@@ -21,9 +21,10 @@
 
     <application>
         <activity
-                android:name=".AppBActivity"
-                android:screenOrientation="portrait"
-                android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
+            android:name=".AppBActivity"
+            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
+            android:screenOrientation="portrait" >
+
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER"/>
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/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 dfa8301..888a768 100644
--- a/tests/tests/os/src/android/os/cts/BuildVersionTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
@@ -29,7 +29,7 @@
 
     private static final String LOG_TAG = "BuildVersionTest";
     private static final Set<String> EXPECTED_RELEASES =
-            new HashSet<String>(Arrays.asList("4.2", "4.2.1", "4.2.2"));
+            new HashSet<String>(Arrays.asList("4.3"));
     private static final int EXPECTED_SDK = 17;
 
     @SuppressWarnings("deprecation")
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java b/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java
index e91595b..08fca45 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java
@@ -31,7 +31,7 @@
     @Option(name="cts-install-path", description="the path to the cts installation to use")
     private String mCtsRootDirPath = System.getProperty("CTS_ROOT");
 
-    public static final String CTS_BUILD_VERSION = "4.2_r4";
+    public static final String CTS_BUILD_VERSION = "4.3_r1";
 
     /**
      * {@inheritDoc}