Merge "Document kernel code necessary to pass PingTest."
diff --git a/tests/expectations/knownfailures.txt b/tests/expectations/knownfailures.txt
index 9d28c34..5eaff9b 100644
--- a/tests/expectations/knownfailures.txt
+++ b/tests/expectations/knownfailures.txt
@@ -31,74 +31,13 @@
   bug: 11352697
 },
 {
-  name: "android.bionic.DEATHTEST#bzero_fortified",
-  name: "android.bionic.DEATHTEST#bzero_fortified2",
-  name: "android.bionic.DEATHTEST#memcpy_fortified",
-  name: "android.bionic.DEATHTEST#memmove_fortified",
-  name: "android.bionic.DEATHTEST#snprintf_fortified",
-  name: "android.bionic.DEATHTEST#snprintf_fortified2",
-  name: "android.bionic.DEATHTEST#sprintf2_fortified",
-  name: "android.bionic.DEATHTEST#sprintf2_fortified2",
-  name: "android.bionic.DEATHTEST#sprintf_fortified",
-  name: "android.bionic.DEATHTEST#sprintf_fortified2",
-  name: "android.bionic.DEATHTEST#strcat2_fortified2",
-  name: "android.bionic.DEATHTEST#strcat_fortified",
-  name: "android.bionic.DEATHTEST#strcat_fortified2",
-  name: "android.bionic.DEATHTEST#strchr_fortified",
-  name: "android.bionic.DEATHTEST#strchr_fortified2",
-  name: "android.bionic.DEATHTEST#strcpy2_fortified",
-  name: "android.bionic.DEATHTEST#strcpy2_fortified2",
-  name: "android.bionic.DEATHTEST#strcpy3_fortified",
-  name: "android.bionic.DEATHTEST#strcpy3_fortified2",
-  name: "android.bionic.DEATHTEST#strcpy4_fortified",
-  name: "android.bionic.DEATHTEST#strcpy_fortified",
-  name: "android.bionic.DEATHTEST#strcpy_fortified2",
-  name: "android.bionic.DEATHTEST#strlcat_fortified",
-  name: "android.bionic.DEATHTEST#strlcat_fortified2",
-  name: "android.bionic.DEATHTEST#strlcpy_fortified",
-  name: "android.bionic.DEATHTEST#strlcpy_fortified2",
-  name: "android.bionic.DEATHTEST#strlen_fortified",
-  name: "android.bionic.DEATHTEST#strncat2_fortified",
-  name: "android.bionic.DEATHTEST#strncat2_fortified2",
-  name: "android.bionic.DEATHTEST#strncat3_fortified2",
-  name: "android.bionic.DEATHTEST#strncat_fortified",
-  name: "android.bionic.DEATHTEST#strncat_fortified2",
-  name: "android.bionic.DEATHTEST#strncpy_fortified",
-  name: "android.bionic.DEATHTEST#strncpy_fortified2",
-  name: "android.bionic.DEATHTEST#strrchr_fortified",
-  name: "android.bionic.DEATHTEST#strrchr_fortified2",
-  name: "android.bionic.DEATHTEST#umask_fortified",
-  name: "android.bionic.DEATHTEST#vsnprintf2_fortified",
-  name: "android.bionic.DEATHTEST#vsnprintf2_fortified2",
-  name: "android.bionic.DEATHTEST#vsnprintf_fortified",
-  name: "android.bionic.DEATHTEST#vsnprintf_fortified2",
-  name: "android.bionic.DEATHTEST#vsprintf2_fortified",
-  name: "android.bionic.DEATHTEST#vsprintf2_fortified2",
-  name: "android.bionic.DEATHTEST#vsprintf_fortified",
-  name: "android.bionic.DEATHTEST#vsprintf_fortified2",
-  name: "android.bionic.TEST_NAME#memcpy_chk_max_int_size",
-  name: "android.bionic.TEST_NAME#strcat",
-  name: "android.bionic.TEST_NAME#strcat2",
-  name: "android.bionic.TEST_NAME#strcat_chk_max_int_size",
-  name: "android.bionic.TEST_NAME#strcpy_chk_max_int_size",
-  name: "android.bionic.TEST_NAME#strncat",
-  name: "android.bionic.TEST_NAME#strncat2",
-  name: "android.bionic.TEST_NAME#strncat3",
-  name: "android.bionic.TEST_NAME#strncat4",
-  name: "android.bionic.TEST_NAME#strncat5",
-  name: "android.bionic.TEST_NAME#strncat6",
-  name: "android.bionic.dlfcn#dladdr",
-  name: "android.bionic.dlfcn#dladdr_invalid",
-  name: "android.bionic.dlfcn#dlerror_concurrent",
-  name: "android.bionic.dlfcn#dlopen_bad_flags",
-  name: "android.bionic.dlfcn#dlopen_failure",
-  name: "android.bionic.dlfcn#dlopen_library_with_only_gnu_hash",
-  name: "android.bionic.dlfcn#dlsym_failures",
-  name: "android.bionic.dlfcn#dlsym_in_self",
+  name: "android.bionic.DEATHTEST",
+  name: "android.bionic.TEST_NAME",
+  name: "android.bionic.dlfcn",
   name: "android.bionic.math#isfinite",
   name: "android.bionic.math#signbit",
-  name: "android.bionic.stack_protector#same_guard_per_thread",
-  name: "android.bionic.stack_unwinding_DeathTest#unwinding_through_signal_frame",
+  name: "android.bionic.stack_protector",
+  name: "android.bionic.stack_unwinding_DeathTest",
   bug: 11119006
 }
 ]
diff --git a/tests/tests/media/res/raw/video_480x360_mp4_h264_500kbps_25fps_aac_stereo_128kbps_44100hz_id3v2.mp4 b/tests/tests/media/res/raw/video_480x360_mp4_h264_500kbps_25fps_aac_stereo_128kbps_44100hz_id3v2.mp4
new file mode 100644
index 0000000..0902533
--- /dev/null
+++ b/tests/tests/media/res/raw/video_480x360_mp4_h264_500kbps_25fps_aac_stereo_128kbps_44100hz_id3v2.mp4
Binary files differ
diff --git a/tests/tests/media/src/android/media/cts/MediaMetadataRetrieverTest.java b/tests/tests/media/src/android/media/cts/MediaMetadataRetrieverTest.java
index b090e27..30c8370 100644
--- a/tests/tests/media/src/android/media/cts/MediaMetadataRetrieverTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaMetadataRetrieverTest.java
@@ -70,4 +70,52 @@
         assertNull("Writer was unexpected present",
                 retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_WRITER));
     }
+
+    public void testSetDataSourceNull() {
+        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
+
+        try {
+            retriever.setDataSource((String)null);
+            fail("Expected IllegalArgumentException.");
+        } catch (IllegalArgumentException ex) {
+            // Expected, test passed.
+        }
+    }
+
+    public void testID3v2Metadata() {
+        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
+
+        try {
+            Resources resources = getContext().getResources();
+            AssetFileDescriptor afd = resources.openRawResourceFd(
+                    R.raw.video_480x360_mp4_h264_500kbps_25fps_aac_stereo_128kbps_44100hz_id3v2);
+
+            retriever.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
+
+            afd.close();
+        } catch (Exception e) {
+            fail("Unable to open file");
+        }
+
+        assertEquals("Title was other than expected",
+                "Title", retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE));
+
+        assertEquals("Artist was other than expected",
+                "UTF16LE エンディアン ",
+                retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));
+
+        assertEquals("Album was other than expected",
+                "Test album",
+                retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
+
+        assertEquals("Track number was other than expected",
+                "10",
+                retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER));
+
+        assertEquals("Year was other than expected",
+                "2013", retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR));
+
+        assertNull("Writer was unexpectedly present",
+                retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_WRITER));
+    }
 }
diff --git a/tests/tests/net/Android.mk b/tests/tests/net/Android.mk
index 7219fc4..82abd62 100644
--- a/tests/tests/net/Android.mk
+++ b/tests/tests/net/Android.mk
@@ -30,7 +30,8 @@
 
 LOCAL_PACKAGE_NAME := CtsNetTestCases
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestserver ctsdeviceutil ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestserver ctsdeviceutil ctstestrunner \
+                               core-tests-support
 
 # uncomment when dalvik.annotation.Test* are removed or part of SDK
 #LOCAL_SDK_VERSION := current
diff --git a/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java b/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
index ceb74d1..cb8aeaf 100644
--- a/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
+++ b/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
@@ -28,6 +28,8 @@
 
 import dalvik.annotation.BrokenTest;
 
+import libcore.javax.net.ssl.SSLDefaultConfigurationAsserts;
+
 public class SSLCertificateSocketFactoryTest extends AndroidTestCase {
     private SSLCertificateSocketFactory mFactory;
     private int mTimeout;
@@ -39,6 +41,10 @@
         mFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(mTimeout);
     }
 
+    public void testDefaultConfiguration() throws Exception {
+        SSLDefaultConfigurationAsserts.assertSSLSocketFactory(mFactory);
+    }
+
     public void testAccessProperties() throws Exception {
         mFactory.getSupportedCipherSuites();
         mFactory.getDefaultCipherSuites();
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index eaea367..ab6ff46 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -739,7 +739,6 @@
                 new File("/dev/felica_uicc"),
                 new File("/dev/full"),
                 new File("/dev/genlock"),    // b/9035217
-                new File("/dev/hw_random"),  // b/9191279
                 new File("/dev/ion"),
                 new File("/dev/kgsl-3d0"),   // b/9035217
                 new File("/dev/log/events"), // b/9035217
@@ -797,6 +796,24 @@
                 (status.mode & 0666) == 0666);
     }
 
+    public void testDevHwRandomLockedDown() throws Exception {
+        File f = new File("/dev/hw_random");
+        if (!f.exists()) {
+            // HW RNG is not required to be exposed on all devices.
+            return;
+        }
+
+        FileUtils.FileStatus status = new FileUtils.FileStatus();
+        assertTrue(FileUtils.getFileStatus(f.getCanonicalPath(), status, false));
+        assertTrue(
+                f + " has wrong file mode: 0"
+                        + Integer.toOctalString(status.mode),
+                (status.mode & 0777) == 0440);
+
+        assertFileOwnedBy(f, "root");
+        assertFileOwnedByGroup(f, "system");
+    }
+
     /**
      * Test that the /system/bin/run-as command has setuid and setgid
      * attributes set on the file.  If these calls fail, debugger
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/AllocationResize.java b/tests/tests/renderscript/src/android/renderscript/cts/AllocationResize.java
index b6d9a1a..68d7274 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/AllocationResize.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/AllocationResize.java
@@ -49,7 +49,7 @@
         mIn.copy1DRangeFrom(0, INPUTSIZE, inArray);
 
         try {
-            RSUtils.forEach(this, 0, mIn, mOut);
+            forEach(0, mIn, mOut);
         } catch (RSRuntimeException e) {
         }
 
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ClearObjectTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ClearObjectTest.java
index 64deb33..e8a330a 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/ClearObjectTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ClearObjectTest.java
@@ -66,7 +66,7 @@
         Allocation mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum);
         ms_clear.set_element(element);
         try {
-            RSUtils.forEach(this, TEST_ID_ELEMENT, mIn, mOut);
+            forEach(TEST_ID_ELEMENT, mIn, mOut);
         } catch (RSRuntimeException e) {
         }
         int[] tmpArray = new int[ObjectNum];
@@ -83,7 +83,7 @@
         ms_clear.set_type(type);
 
         try {
-            RSUtils.forEach(this, TEST_ID_TYPE, mIn, mOut);
+            forEach(TEST_ID_TYPE, mIn, mOut);
         } catch (RSRuntimeException e) {
         }
         int[] tmpArray = new int[ObjectNum];
@@ -99,7 +99,7 @@
         Allocation allocation = Allocation.createTyped(mRS, mIn.getType());
         ms_clear.set_allocation(allocation);
         try {
-            RSUtils.forEach(this, TEST_ID_ALLOCATION, mIn, mOut);
+            forEach(TEST_ID_ALLOCATION, mIn, mOut);
         } catch (RSRuntimeException e) {
         }
         int[] tmpArray = new int[ObjectNum];
@@ -115,7 +115,7 @@
         Allocation mIn = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum);
         ms_clear.set_sampler(sampler);
         try {
-            RSUtils.forEach(this, TEST_ID_SAMPLER, mIn, mOut);
+            forEach(TEST_ID_SAMPLER, mIn, mOut);
         } catch (RSRuntimeException e) {
         }
         int[] tmpArray = new int[ObjectNum];
@@ -131,7 +131,7 @@
         Allocation mOut = Allocation.createSized(mRS, Element.I32(mRS), ObjectNum);
         ms_clear.set_script(script);
         try {
-            RSUtils.forEach(this, TEST_ID_SCRIPT, mIn, mOut);
+            forEach(TEST_ID_SCRIPT, mIn, mOut);
         } catch (RSRuntimeException e) {
         }
         int[] tmpArray = new int[ObjectNum];
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/GetElementAt.java b/tests/tests/renderscript/src/android/renderscript/cts/GetElementAt.java
index a9be1bc..babc1ef 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/GetElementAt.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/GetElementAt.java
@@ -62,7 +62,7 @@
         mOut = Allocation.createTyped(mRS, gIn.getType());
         script_x.set_gIn(gIn);
         try {
-            RSUtils.forEach(this, TEST_ID_X, mOut);
+            forEach(TEST_ID_X, mOut);
         } catch (RSRuntimeException e) {
         }
         mOut.copyTo(out);
@@ -83,7 +83,7 @@
         mOut = Allocation.createTyped(mRS, gIn.getType());
         script_xy.set_gIn(gIn);
         try {
-            RSUtils.forEach(this, TEST_ID_XY, mOut);
+            forEach(TEST_ID_XY, mOut);
         } catch (RSRuntimeException e) {
         }
         mOut.copyTo(out);
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/InitTest.java b/tests/tests/renderscript/src/android/renderscript/cts/InitTest.java
index ef36927..848c192 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/InitTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/InitTest.java
@@ -46,7 +46,7 @@
         mIn.copy1DRangeFrom(0, INPUTSIZE, in);
 
         try {
-            RSUtils.forEach(this, 0, mIn, mOut);
+            forEach(0, mIn, mOut);
         } catch (RSRuntimeException e) {
         }
         mOut.copyTo(out);
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/PowTest.java b/tests/tests/renderscript/src/android/renderscript/cts/PowTest.java
index 09a2e94..ad3d078 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/PowTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/PowTest.java
@@ -88,8 +88,8 @@
     }
 
     @Override
-    protected void fillRandom(long seed, int fact, int offset, float[] inArray, int rStride, int rSkip) {
-        RSUtils.genRandom(seed, 32, -16, inArray, rStride, rSkip);
+    protected void fillRandomFloats(long seed, int fact, int offset, float[] inArray) {
+        RSUtils.genRandomFloats(seed, 32, -16, inArray);
     }
 
     public void testPowF32() {
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/PownTest.java b/tests/tests/renderscript/src/android/renderscript/cts/PownTest.java
index c95a294..32308ce 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/PownTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/PownTest.java
@@ -82,7 +82,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE];
-        RSUtils.genRandom(0x12345678, 32, 1, -16, n);
+        RSUtils.genRandomInts(0x12345678, 32, -16, n);
         nAlloc.copyFrom(n);
         script_f32.set_n1(nAlloc);
 
@@ -93,7 +93,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE];
-        RSUtils.genRandom(0x12345678, 32, 1, -16, n);
+        RSUtils.genRandomInts(0x12345678, 32, -16, n);
         nAlloc.copyFrom(n);
         script_f32_relaxed.set_n1(nAlloc);
 
@@ -104,7 +104,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_2(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*2];
-        RSUtils.genRandom(0xacdef1, 32, 1, -16, n);
+        RSUtils.genRandomInts(0xacdef1, 32, -16, n);
         nAlloc.copyFrom(n);
         script_f32.set_n2(nAlloc);
 
@@ -115,7 +115,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_2(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*2];
-        RSUtils.genRandom(0xacdef1, 32, 1, -16, n);
+        RSUtils.genRandomInts(0xacdef1, 32, -16, n);
         nAlloc.copyFrom(n);
         script_f32_relaxed.set_n2(nAlloc);
 
@@ -126,7 +126,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_3(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*4];
-        RSUtils.genRandom(0xa123f1, 32, 1, -16, n, 4, 1);
+        RSUtils.genRandomInts(0xa123f1, 32, -16, n);
         nAlloc.copyFrom(n);
         script_f32.set_n3(nAlloc);
 
@@ -137,7 +137,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_3(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*4];
-        RSUtils.genRandom(0xa123f1, 32, 1, -16, n, 4, 1);
+        RSUtils.genRandomInts(0xa123f1, 32, -16, n);
         nAlloc.copyFrom(n);
         script_f32_relaxed.set_n3(nAlloc);
 
@@ -148,7 +148,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_4(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*4];
-        RSUtils.genRandom(0x4323ca, 32, 1, -16, n);
+        RSUtils.genRandomInts(0x4323ca, 32, -16, n);
         nAlloc.copyFrom(n);
         script_f32.set_n4(nAlloc);
 
@@ -159,7 +159,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_4(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*4];
-        RSUtils.genRandom(0x4323ca, 32, 1, -16, n);
+        RSUtils.genRandomInts(0x4323ca, 32, -16, n);
         nAlloc.copyFrom(n);
         script_f32_relaxed.set_n4(nAlloc);
 
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/PowrTest.java b/tests/tests/renderscript/src/android/renderscript/cts/PowrTest.java
index f10995b..cebbe24 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/PowrTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/PowrTest.java
@@ -88,8 +88,8 @@
     }
 
     @Override
-    protected void fillRandom(long seed, int fact, int offset, float[] inArray, int rStride, int rSkip) {
-        RSUtils.genRandom(seed, 64, 0, inArray, rStride, rSkip);
+    protected void fillRandomFloats(long seed, int fact, int offset, float[] inArray) {
+        RSUtils.genRandomFloats(seed, 64, 0, inArray);
     }
 
     public void testPowrF32() {
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java
index d68e628..d7759f1 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java
@@ -89,7 +89,7 @@
                                 int offset, int rStride, int rSkip, int refStride, int outStride,
                                 int inStride, int skip, int ulp) {
         float[] inArray = makeInArray(INPUTSIZE * inStride);
-        fillRandom(seed, fact, offset, inArray, rStride, rSkip);
+        fillRandomFloats(seed, fact, offset, inArray);
         float[] refArray = getRefArray(inArray, INPUTSIZE, inStride, skip);
 
         Allocation mAllocationIn = setInAlloc(inElement);
@@ -97,7 +97,7 @@
 
         Allocation mAllocationOut = setOutAlloc(outElement);
         try {
-            RSUtils.forEach(this, testid, mAllocationIn, mAllocationOut);
+            forEach(testid, mAllocationIn, mAllocationOut);
         } catch (RSRuntimeException e) {
             Log.e("RenderscriptCTS", "Caught RSRuntimeException: " +
                   e.getMessage());
@@ -173,8 +173,8 @@
         return new float[size];
     }
 
-    protected void fillRandom(long seed, int fact, int offset, float[] inArray, int rStride, int rSkip) {
-        RSUtils.genRandom(seed, fact, offset, inArray, rStride, rSkip);
+    protected void fillRandomFloats(long seed, int fact, int offset, float[] inArray) {
+        RSUtils.genRandomFloats(seed, fact, offset, inArray);
     }
 
     protected void fillInAlloc(Allocation mIn, float[] inArray) {
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSUtils.java b/tests/tests/renderscript/src/android/renderscript/cts/RSUtils.java
index 8c81e3d..d3fb5d0 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RSUtils.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSUtils.java
@@ -27,65 +27,23 @@
  */
 public class RSUtils {
 
-    public static void genRandom(long seed, int factor, int offset, float array[]) {
+    /**
+     * Fills the array with random floats.  Values will be: offset + number between 0 and max.
+     */
+    public static void genRandomFloats(long seed, int max, int offset, float array[]) {
         Random r = new Random(seed);
         for (int i = 0; i < array.length; i++) {
-            array[i] = r.nextFloat() * factor + offset;
+            array[i] = r.nextFloat() * max + offset;
         }
     }
 
-    public static void genRandom(long seed, int factor, int offset, float array[],
-            int stride, int skip) {
-        Random r = new Random(seed);
-        for (int i = 0; i < array.length / stride; i++) {
-            for (int j = 0; j < stride; j++) {
-                if (j >= stride - skip)
-                    array[i * stride + j] = 0;
-                else
-                    array[i * stride + j] = r.nextFloat() * factor + offset;
-            }
-        }
-    }
-
-    public static void genRandom(long seed, int max, int factor, int offset, int array[]) {
+    /**
+     * Fills the array with random ints.  Values will be: offset + number between 0 and max (exclusive).
+     */
+    public static void genRandomInts(long seed, int max, int offset, int array[]) {
         Random r = new Random(seed);
         for (int i = 0; i < array.length; i++) {
-            array[i] = (r.nextInt(max) * factor + offset);
+            array[i] = (r.nextInt(max) + offset);
         }
     }
-
-    public static void genRandom(long seed, int factor, int offset, int array[],
-            int stride, int skip) {
-        Random r = new Random(seed);
-        for (int i = 0; i < array.length / stride; i++) {
-            for (int j = 0; j < stride; j++) {
-                if (j >= stride - skip)
-                    array[i * stride + j] = 0;
-                else
-                    array[i * stride + j] = r.nextInt() * factor + offset;
-            }
-        }
-    }
-
-    public static void genRandom(long seed, int max, int factor, int offset, int array[],
-            int stride, int skip) {
-        Random r = new Random(seed);
-        for (int i = 0; i < array.length / stride; i++) {
-            for (int j = 0; j < stride; j++) {
-                if (j >= stride - skip)
-                    array[i * stride + j] = 0;
-                else
-                    array[i * stride + j] = r.nextInt(max) * factor + offset;
-            }
-        }
-    }
-
-    public static void forEach(RSBaseCompute base, int testId, Allocation in) throws RSRuntimeException {
-        base.forEach(testId, in);
-    }
-
-    public static void forEach(RSBaseCompute base, int testId, Allocation in, Allocation out)
-            throws RSRuntimeException {
-        base.forEach(testId, in,out);
-    }
 }
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RootnTest.java b/tests/tests/renderscript/src/android/renderscript/cts/RootnTest.java
index 8301ad5..2c447bb 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RootnTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RootnTest.java
@@ -80,7 +80,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE];
-        RSUtils.genRandom(0x12345678, 32, 1, 1, n);
+        RSUtils.genRandomInts(0x12345678, 32, 1, n);
         nAlloc.copyFrom(n);
         script_f32.set_n1(nAlloc);
 
@@ -91,7 +91,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE];
-        RSUtils.genRandom(0x12345678, 32, 1, 1, n);
+        RSUtils.genRandomInts(0x12345678, 32, 1, n);
         nAlloc.copyFrom(n);
         script_f32_relaxed.set_n1(nAlloc);
 
@@ -103,7 +103,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_2(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*2];
-        RSUtils.genRandom(0xacdef1, 32, 1, 1, n);
+        RSUtils.genRandomInts(0xacdef1, 32, 1, n);
         nAlloc.copyFrom(n);
         script_f32.set_n2(nAlloc);
 
@@ -114,7 +114,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_2(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*2];
-        RSUtils.genRandom(0xacdef1, 32, 1, 1, n);
+        RSUtils.genRandomInts(0xacdef1, 32, 1, n);
         nAlloc.copyFrom(n);
         script_f32_relaxed.set_n2(nAlloc);
 
@@ -126,7 +126,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_3(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*4];
-        RSUtils.genRandom(0xa123f1, 32, 1, 1, n, 4, 1);
+        RSUtils.genRandomInts(0xa123f1, 32, 1, n);
         nAlloc.copyFrom(n);
         script_f32.set_n3(nAlloc);
 
@@ -137,7 +137,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_3(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*4];
-        RSUtils.genRandom(0xa123f1, 32, 1, 1, n, 4, 1);
+        RSUtils.genRandomInts(0xa123f1, 32, 1, n);
         nAlloc.copyFrom(n);
         script_f32_relaxed.set_n3(nAlloc);
 
@@ -148,7 +148,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_4(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*4];
-        RSUtils.genRandom(0x4323ca, 32, 1, 1, n);
+        RSUtils.genRandomInts(0x4323ca, 32, 1, n);
         nAlloc.copyFrom(n);
         script_f32.set_n4(nAlloc);
 
@@ -159,7 +159,7 @@
         Allocation nAlloc = Allocation.createSized(mRS, Element.I32_4(mRS), INPUTSIZE);
 
         n = new int[INPUTSIZE*4];
-        RSUtils.genRandom(0x4323ca, 32, 1, 1, n);
+        RSUtils.genRandomInts(0x4323ca, 32, 1, n);
         nAlloc.copyFrom(n);
         script_f32_relaxed.set_n4(nAlloc);
 
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RsPackColorTo8888Test.java b/tests/tests/renderscript/src/android/renderscript/cts/RsPackColorTo8888Test.java
index 0b008a7..edff5b9 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RsPackColorTo8888Test.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RsPackColorTo8888Test.java
@@ -72,10 +72,10 @@
         float[] inArray = new float[INPUTSIZE * 4];
         byte[] outArray = new byte[INPUTSIZE * 4];
         byte[] refArray = new byte[INPUTSIZE * 4];
-        RSUtils.genRandom(seed, 1, 0, inArray, 4, 1);
+        RSUtils.genRandomFloats(seed, 1, 0, inArray);
         mAllocationIn.copy1DRangeFrom(0, INPUTSIZE, inArray);
         try {
-            RSUtils.forEach(this, testId, mAllocationIn, mAllocationOut);
+            forEach(testId, mAllocationIn, mAllocationOut);
         } catch (RSRuntimeException e) {
         }
         mAllocationOut.copyTo(outArray);
@@ -99,10 +99,10 @@
         float[] inArray = new float[INPUTSIZE * 4];
         byte[] outArray = new byte[INPUTSIZE * 4];
         byte[] refArray = new byte[INPUTSIZE * 4];
-        RSUtils.genRandom(seed, 1, 0, inArray);
+        RSUtils.genRandomFloats(seed, 1, 0, inArray);
         mAllocationIn.copy1DRangeFrom(0, INPUTSIZE, inArray);
         try {
-            RSUtils.forEach(this, testId, mAllocationIn, mAllocationOut);
+            forEach(testId, mAllocationIn, mAllocationOut);
         } catch (RSRuntimeException e) {
         }
         mAllocationOut.copyTo(outArray);
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RsUnpackColor8888Test.java b/tests/tests/renderscript/src/android/renderscript/cts/RsUnpackColor8888Test.java
index 4df1169..3ebbee1 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/RsUnpackColor8888Test.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RsUnpackColor8888Test.java
@@ -44,7 +44,7 @@
 
         mAllocationIn.copy1DRangeFrom(0, INPUTSIZE, inArray);
         try {
-            RSUtils.forEach(this, 0, mAllocationIn, mAllocationOut);
+            forEach(0, mAllocationIn, mAllocationOut);
         } catch (RSRuntimeException e) {
         }
         mAllocationOut.copyTo(outArray);
diff --git a/tests/tests/security/src/android/security/cts/CertificateTest.java b/tests/tests/security/src/android/security/cts/CertificateTest.java
index e6e2a2b..3db7aca 100644
--- a/tests/tests/security/src/android/security/cts/CertificateTest.java
+++ b/tests/tests/security/src/android/security/cts/CertificateTest.java
@@ -16,9 +16,10 @@
 
 package android.security.cts;
 
-import android.test.AndroidTestCase;
+import android.content.res.AssetManager;
+import android.test.InstrumentationTestCase;
 
-import java.io.FileInputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.security.KeyStore;
@@ -27,6 +28,7 @@
 import java.security.NoSuchAlgorithmException;
 import java.security.cert.CertificateEncodingException;
 import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.Arrays;
 import java.util.Collections;
@@ -34,7 +36,7 @@
 import java.util.List;
 import java.util.Set;
 
-public class CertificateTest extends AndroidTestCase {
+public class CertificateTest extends InstrumentationTestCase {
 
     public void testNoRemovedCertificates() throws Exception {
         Set<String> expectedCertificates = new HashSet<String>(
@@ -45,16 +47,58 @@
     }
 
     /**
-     * {@see OEMCertificateWhitelist#OEM_CERTIFICATE_WHITELIST} for more information on this test.
+     * If you fail CTS as a result of adding a root CA that is not part of the Android root CA
+     * store, please see the following.
+     *
+     * First, this test exists because adding untrustworthy root CAs to a device has a very
+     * significant security impact. In the worst case, adding a rogue CA can permanently compromise
+     * the confidentiality and integrity of your users' network traffic. Because of this risk,
+     * adding new certificates should be done sparingly and as a last resort -- never as a first
+     * response or short term fix. Before attempting to modify this test, please consider whether
+     * adding a new certificate authority is in your users' best interests.
+     *
+     * Second, because the addition of a new root CA by an OEM can have such dire consequences for
+     * so many people it is imperative that it be done transparently and in the open. Any request to
+     * modify the certificate list used by this test must have a corresponding change in AOSP
+     * (one certificate per change) authored by the OEM in question and including:
+     *
+     *     - the certificate in question:
+     *       - The certificate must be in a file under
+     *         cts/tests/tests/security/assets/oem_cacerts, in PEM (Privacy-enhanced Electronic
+     *         Mail) format, with the textual representation of the certificate following the PEM
+     *         section.
+     *       - The file name must be in the format of <hash>.<n> where "hash" is the subject hash
+     *         produced by:
+     *           openssl x509 -in cert_file -subject_hash -noout
+     *         and the "n" is a unique integer identifier starting at 0 to deal with collisions.
+     *         See OpenSSL's c_rehash manpage for details.
+     *       - cts/tests/tests/security/tools/format_cert.sh helps meet the above requirements.
+     *
+     *     - information about who created and maintains both the certificate and the corresponding
+     *       keypair.
+     *
+     *     - information about what the certificate is to be used for and why the certificate is
+     *       appropriate for inclusion.
+     *
+     *     - a statement from the OEM indicating that they have sufficient confidence in the
+     *       security of the key, the security practices of the issuer, and the validity of the
+     *       intended use that they believe adding the certificate is not detrimental to the
+     *       security of the user.
+     *
+     * Finally, please note that this is not the usual process for adding root CAs to Android. If
+     * you have a certificate that you believe should be present on all Android devices, please file
+     * a public bug at https://code.google.com/p/android/issues/entry or http://b.android.com to
+     * seek resolution.
+     *
+     * For questions, comments, and code reviews please contact security@android.com.
      */
     public void testNoAddedCertificates() throws Exception {
-        Set<String> oemCertificateWhitelist = new HashSet<String>(
-                Arrays.asList(OEMCertificateWhitelist.OEM_CERTIFICATE_WHITELIST));
+        Set<String> oemWhitelistedCertificates = getOemWhitelistedCertificates();
         Set<String> expectedCertificates = new HashSet<String>(
                 Arrays.asList(CertificateData.CERTIFICATE_DATA));
         Set<String> deviceCertificates = getDeviceCertificates();
         deviceCertificates.removeAll(expectedCertificates);
-        deviceCertificates.removeAll(oemCertificateWhitelist);
+        deviceCertificates.removeAll(oemWhitelistedCertificates);
         assertEquals("Unknown CA certificates", Collections.EMPTY_SET, deviceCertificates);
     }
 
@@ -88,6 +132,30 @@
         return certificates;
     }
 
+    private static final String ASSETS_DIR_OEM_CERTS = "oem_cacerts";
+
+    private Set<String> getOemWhitelistedCertificates() throws Exception {
+        Set<String> certificates = new HashSet<String>();
+        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
+        AssetManager assetManager = getInstrumentation().getContext().getAssets();
+        for (String path : assetManager.list(ASSETS_DIR_OEM_CERTS)) {
+            File certAssetFile = new File(ASSETS_DIR_OEM_CERTS, path);
+            InputStream in = null;
+            try {
+                in = assetManager.open(certAssetFile.toString());
+                X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(in);
+                certificates.add(getFingerprint(certificate));
+            } catch (Exception e) {
+                throw new Exception("Failed to load certificate from asset: " + certAssetFile, e);
+            } finally {
+                if (in != null) {
+                    in.close();
+                }
+            }
+        }
+        return certificates;
+    }
+
     private String getFingerprint(X509Certificate certificate) throws CertificateEncodingException,
             NoSuchAlgorithmException {
         MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
diff --git a/tests/tests/security/src/android/security/cts/HwRngTest.java b/tests/tests/security/src/android/security/cts/HwRngTest.java
new file mode 100644
index 0000000..3dc11af
--- /dev/null
+++ b/tests/tests/security/src/android/security/cts/HwRngTest.java
@@ -0,0 +1,159 @@
+/*
+ * 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 android.security.cts;
+
+import junit.framework.TestCase;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests for hardware random number generator device {@code /dev/hw_random}.
+ */
+public class HwRngTest extends TestCase {
+
+    // The block of constants below is from hw_random framework documentation and source code:
+    // see https://www.kernel.org/doc/Documentation/hw_random.txt.
+    private static final File DEV_HW_RANDOM = new File("/dev/hw_random");
+    private static final File SYSFS_HW_RANDOM = new File("/sys/class/misc/hw_random");
+    private static final String HWRNG_DRIVER_NAME = "hwrng";
+    private static final int HWRNG_DRIVER_MAJOR = 10;
+    private static final int HWRNG_DRIVER_MINOR = 183;
+
+    /**
+     * Asserts that the {@code /dev/hw_random} device is configured in an acceptable way or is not
+     * present at all.
+     */
+    public void testConfigurationIfFilePresent() throws Exception {
+        if (!DEV_HW_RANDOM.exists()) {
+            // The device is not present
+            return;
+        }
+
+        // Sanity check based on https://www.kernel.org/doc/Documentation/hw_random.txt.
+
+        // In short, assert that:
+        // 1. hwrng kernel driver is using MAJOR 10 and MINOR 183,
+        // 2. a driver is selected in the hrwng framework, and
+        // 3. /dev/hw_random references a character device with the above MAJOR and MINOR.
+
+        // 1. Assert that the hwrng driver is using MAJOR 10 and MINOR 183.
+        //    We achieve this by inspecting /sys/class/misc/hw_random/dev and uevent.
+        assertTrue(SYSFS_HW_RANDOM + " not found", SYSFS_HW_RANDOM.isDirectory());
+        assertEquals(
+                "Driver major:minor",
+                HWRNG_DRIVER_MAJOR + ":" + HWRNG_DRIVER_MINOR,
+                readyFullyAsciiFile(new File(SYSFS_HW_RANDOM, "dev")).trim());
+
+        Map<String, String> ueventVars = parseUeventFile(new File(SYSFS_HW_RANDOM, "uevent"));
+        assertEquals("uevent MAJOR", String.valueOf(HWRNG_DRIVER_MAJOR), ueventVars.get("MAJOR"));
+        assertEquals("uevent MINOR", String.valueOf(HWRNG_DRIVER_MINOR), ueventVars.get("MINOR"));
+        assertEquals("uevent DEVNAME", HWRNG_DRIVER_NAME, ueventVars.get("DEVNAME"));
+
+        // 2. Assert that a driver is selected in the hrwng framework.
+        //    We achieve this by inspecting /sys/class/misc/hw_random/rng_current.
+        File rngCurrentFile = new File(SYSFS_HW_RANDOM, "rng_current");
+        String rngCurrent = readyFullyAsciiFile(rngCurrentFile);
+        assertFalse(
+                "No driver selected according to " + rngCurrentFile,
+                rngCurrent.trim().isEmpty());
+
+        // 3. Assert that /dev/hw_random references a character device with the above MAJOR+MINOR.
+        assertEquals(
+                DEV_HW_RANDOM + " major",
+                HWRNG_DRIVER_MAJOR,
+                LinuxRngTest.getCharDeviceMajor(DEV_HW_RANDOM.getCanonicalPath()));
+        assertEquals(
+                DEV_HW_RANDOM + " minor",
+                HWRNG_DRIVER_MINOR,
+                LinuxRngTest.getCharDeviceMinor(DEV_HW_RANDOM.getCanonicalPath()));
+    }
+
+    private static String readyFullyAsciiFile(File file) throws IOException {
+        InputStream in = null;
+        try {
+            in = new FileInputStream(file);
+            return new String(readyFully(in), "US-ASCII");
+        } finally {
+            closeSilently(in);
+        }
+    }
+
+    private static byte[] readyFully(InputStream in) throws IOException {
+        ByteArrayOutputStream result = new ByteArrayOutputStream();
+        byte[] buffer = new byte[16 * 1024];
+        int chunkSize;
+        while ((chunkSize = in.read(buffer)) != -1) {
+            result.write(buffer, 0, chunkSize);
+        }
+        return result.toByteArray();
+    }
+
+    private static Map<String, String> parseUeventFile(File file) throws IOException {
+        // The format of the file is line-oriented.
+        // Each variable takes up one line.
+        // The typical format of a variable is KEY=VALUE
+
+        Map<String, String> result = new HashMap<String, String>();
+        BufferedReader in = null;
+        try {
+            in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "US-ASCII"));
+            String line;
+            while ((line = in.readLine()) != null) {
+                if (line.trim().length() == 0) {
+                    // Ignore empty lines
+                    continue;
+                }
+
+                String key;
+                String value;
+                int delimiterIndex = line.indexOf('=');
+                if (delimiterIndex != -1) {
+                    key = line.substring(0, delimiterIndex);
+                    value = line.substring(delimiterIndex + 1);
+                } else {
+                    key = line;
+                    value = "";
+                }
+
+                if (result.containsKey(key)) {
+                    throw new IllegalArgumentException("Multiple values for key: " + key);
+                }
+                result.put(key, value);
+            }
+            return result;
+        } finally {
+            closeSilently(in);
+        }
+    }
+
+    private static void closeSilently(Closeable in) {
+        if (in != null) {
+            try {
+                in.close();
+            } catch (IOException ignored) {}
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/tests/security/src/android/security/cts/OEMCertificateWhitelist.java b/tests/tests/security/src/android/security/cts/OEMCertificateWhitelist.java
deleted file mode 100644
index 024c15f..0000000
--- a/tests/tests/security/src/android/security/cts/OEMCertificateWhitelist.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 android.security.cts;
-
-class OEMCertificateWhitelist {
-
-  /**
-   * If you fail CTS as a result of adding a root CA that is not part
-   * of the Android root CA store, please see the following.
-   *
-   * First, this test exists because adding untrustworthy root CAs
-   * to a device has a very significant security impact. In the worst
-   * case, adding a rogue CA to this list can permanently compromise
-   * the confidentiality and integrity of your users' network traffic.
-   * Because of this risk, adding new certificates should be done
-   * sparingly and as a last resort- never as a first response or
-   * short term fix. Before attempting to modify this test, please
-   * consider whether adding a new certificate authority is in your
-   * users' best interests.
-   *
-   * Second, because the addition of a new root CA by an OEM can have
-   * such dire consequences for so many people it is imperative that
-   * it be done transparently and in the open. Any request to modify
-   * this list must have a corresponding change in AOSP authored by
-   * the OEM in question and including:
-   *
-   *     - the certificate in question.
-   *
-   *     - information about who created and maintains
-   *       both the certificate and the corresponding keypair.
-   *
-   *     - information about what the certificate is to be used
-   *       for and why the certificate is appropriate for inclusion.
-   *
-   *     - a statement from the OEM indicating that they have
-   *       sufficient confidence in the security of the key, the
-   *       security practices of the issuer, and the validity
-   *       of the intended use that they believe adding the
-   *       certificate is not detrimental to the security of the
-   *       user.
-   *
-   * Finally, please note that this is not the usual process for
-   * adding root CAs to Android. If you have a certificate that you
-   * believe should be present on all Android devices, please file a
-   * public bug at https://code.google.com/p/android/issues/entry or
-   * http://b.android.com to seek resolution.
-   *
-   * For questions, comments, and code reviews please contact
-   * security@android.com.
-   */
-  static final String[] OEM_CERTIFICATE_WHITELIST = {};
-
-}
diff --git a/tests/tests/security/testeffect/Android.mk b/tests/tests/security/testeffect/Android.mk
index 49441c7..a7e3cac 100644
--- a/tests/tests/security/testeffect/Android.mk
+++ b/tests/tests/security/testeffect/Android.mk
@@ -22,7 +22,7 @@
 
 LOCAL_CFLAGS+= -O2 -fvisibility=hidden
 
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/soundfx
+LOCAL_MODULE_RELATIVE_PATH := soundfx
 LOCAL_MODULE:= libctstesteffect
 
 LOCAL_C_INCLUDES := \
diff --git a/tests/tests/security/tools/format_cert.sh b/tests/tests/security/tools/format_cert.sh
new file mode 100755
index 0000000..94407a0
--- /dev/null
+++ b/tests/tests/security/tools/format_cert.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+# Outputs the provided certificate (PEM or DER) in a format used by CTS tests.
+# The format is PEM block, followed by the textual representation of the
+# certificate, followed by the SHA-1 fingerprint.
+
+# OpenSSL binary built from this Android source
+OPENSSL="$ANDROID_HOST_OUT/bin/openssl"
+if [ "$ANDROID_HOST_OUT" == "" ]; then
+  echo "Android build environment not set up"
+  echo
+  echo "Run the following from the root of the Android source tree:"
+  echo "  . build/envsetup.sh && lunch"
+  exit 1
+fi
+if [ ! -f "$OPENSSL" ]; then
+  echo "openssl binary not found"
+  echo
+  echo "Run 'mmm external/openssl' or 'make openssl' from the root of the" \
+      "Android source tree to build it."
+  exit 1
+fi
+
+# Input file containing the certificate in PEM or DER format
+in_file="$1"
+
+# Output file. If not specified, the file will be named <hash>.0 where "hash"
+# is the certificate's subject hash produced by:
+#   openssl x509 -in cert_file -subject_hash -noout
+out_file="$2"
+
+# Detect whether the input file is PEM or DER.
+in_form="pem"
+subject_hash=$("$OPENSSL" x509 -in "$in_file" -inform $in_form -subject_hash \
+    -noout 2>/dev/null)
+if [ "$?" != "0" ]; then
+  in_form="der"
+  subject_hash=$("$OPENSSL" x509 -in "$in_file" -inform $in_form -subject_hash \
+      -noout)
+  if [ "$?" != "0" ]; then
+    echo "Certificate file format is neither PEM nor DER"
+    exit 1
+  fi
+fi
+
+# Name the output file <hash>.0 if the name is not specified explicitly.
+if [ "$out_file" == "" ]; then
+  out_file="$subject_hash.0"
+  echo "Auto-generated output file name: $out_file"
+fi
+
+# Output the certificate in the target format
+"$OPENSSL" x509 -in "$in_file" -inform $in_form -outform pem > "$out_file" && \
+"$OPENSSL" x509 -in "$in_file" -inform $in_form -noout -text -fingerprint \
+    >> "$out_file"
diff --git a/tools/tradefed-host/etc/cts-tradefed b/tools/tradefed-host/etc/cts-tradefed
index 11f97e6..bc5c07a 100755
--- a/tools/tradefed-host/etc/cts-tradefed
+++ b/tools/tradefed-host/etc/cts-tradefed
@@ -35,9 +35,9 @@
 checkPath java
 
 # check java version
-JAVA_VERSION=$(java -version 2>&1 | head -n 1 | grep '[ "]1\.6[\. "$$]')
+JAVA_VERSION=$(java -version 2>&1 | head -n 1 | grep '[ "]1\.[67][\. "$$]')
 if [ "${JAVA_VERSION}" == "" ]; then
-    echo "Wrong java version. 1.6 is required."
+    echo "Wrong java version. 1.6 or 1.7 is required."
     exit
 fi
 
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/VMHostTest.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/VMHostTest.java
index e972640..0ebdeea 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/VMHostTest.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/VMHostTest.java
@@ -33,6 +33,7 @@
 public class VMHostTest extends JarHostTest {
 
     private static final String VM_TEST_TEMP_DIR = "/data/local/tmp/vm-tests";
+    private static final String EMULATOR_TEMP_DIR = "/data/local/tmp";
 
     /**
      * {@inheritDoc}
@@ -66,7 +67,7 @@
         CLog.d("Creating device temp directory, including dalvik-cache.");
         createRemoteDir(device, VM_TEST_TEMP_DIR + "/dalvik-cache" );
         try {
-            File localTmpDir = FileUtil.createTempDir("cts-vm", new File("/tmp/"));
+            File localTmpDir = FileUtil.createTempDir("cts-vm", new File(System.getProperty("java.io.tmpdir")));
             CLog.d("Creating host temp dir %s", localTmpDir.getPath());
             File jarFile = new File(ctsBuild.getTestCasesDir(), getJarFileName());
             if (!jarFile.exists()) {
@@ -119,11 +120,10 @@
         if (device.doesFileExist(remoteFilePath)) {
             return;
         }
-        File f = new File(remoteFilePath);
-        String parentPath = f.getParent();
-        if (parentPath != null) {
-            createRemoteDir(device, parentPath);
+	 if (!(device.doesFileExist(EMULATOR_TEMP_DIR))) {
+            CLog.e("Error: Can not found the /data/local/tmp directory!!!");
         }
+        device.executeShellCommand(String.format("mkdir %s", VM_TEST_TEMP_DIR));
         device.executeShellCommand(String.format("mkdir %s", remoteFilePath));
     }
 }