am 45ad581c: Merge remote branch \'goog/gingerbread\' into manualmerge

* commit '45ad581cadd0d13b75a48dd1d2091a024aa2fe41':
  Parallelize Test Description Generalization
  Remove RequiredFeatures Annotation
  Server thread may not update the current value immediately after request url on testAccessLoadsImagesAutomatically case. Solution: Add one second delay before assert function.
  EGL Config Test
  Allow saving log files in different directory
  StartPreview only after setting fps range paramters
  Fix for the handling of SMS Delivery Report in case of CDMA network
  Fix WifiInfoTest
  Remove Unused Spec Progress Tool
  Fix Build
  Fix CtsTelephonyTestCases:PhoneNumberUtilsTest--testCallMethods fails due to PhoneNumberUtils MIN_MATCH set to 11 for China region ship
  Added sleep within testGetAndSetMasterSyncAutomatically.
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 60e6858..8667573 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -37,6 +37,7 @@
 	CtsDatabaseTestCases \
 	CtsDpiTestCases \
 	CtsDpiTestCases2 \
+	CtsDrmTestCases \
 	CtsExampleTestCases \
 	CtsGestureTestCases \
 	CtsGraphicsTestCases \
@@ -50,6 +51,7 @@
 	CtsPermission2TestCases \
 	CtsPreferenceTestCases \
 	CtsProviderTestCases \
+	CtsRenderscriptTestCases \
 	CtsSaxTestCases \
 	CtsSpeechTestCases \
 	CtsTelephonyTestCases \
diff --git a/development/ide/eclipse/.classpath b/development/ide/eclipse/.classpath
index ac56b05..8d10955 100644
--- a/development/ide/eclipse/.classpath
+++ b/development/ide/eclipse/.classpath
@@ -21,6 +21,7 @@
     <classpathentry kind="src" path="cts/tests/tests/database/src"/>
     <classpathentry kind="src" path="cts/tests/tests/dpi/src"/>
     <classpathentry kind="src" path="cts/tests/tests/dpi2/src"/>
+    <classpathentry kind="src" path="cts/tests/tests/drm/src"/>
     <classpathentry kind="src" path="cts/tests/tests/example/src"/>
     <classpathentry kind="src" path="cts/tests/tests/gesture/src"/>
     <classpathentry kind="src" path="cts/tests/tests/graphics/src"/>
@@ -39,6 +40,7 @@
     <classpathentry kind="src" path="cts/tests/tests/permission2/src"/>
     <classpathentry kind="src" path="cts/tests/tests/preference/src"/>
     <classpathentry kind="src" path="cts/tests/tests/provider/src"/>
+    <classpathentry kind="src" path="cts/tests/tests/renderscript/src"/>
     <classpathentry kind="src" path="cts/tests/tests/speech/src"/>
     <classpathentry kind="src" path="cts/tests/tests/telephony/src"/>
     <classpathentry kind="src" path="cts/tests/tests/text/src"/>
diff --git a/tests/Android.mk b/tests/Android.mk
index 838d01d..641d053 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -18,6 +18,7 @@
 LOCAL_MODULE_TAGS := tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)\
+              $(call all-renderscript-files-under, src)\
               $(call all-java-files-under, core/runner/src)\
               src/android/app/cts/ISecondary.aidl\
               src/android/os/cts/IEmptyService.aidl
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 7eaafb3..6f302a6 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -938,6 +938,11 @@
                     android:resource="@xml/preferences_from_intent" />
         </activity>
 
+        <activity android:name="android.app.cts.ActivityManagerMemoryClassLaunchActivity" />
+
+        <activity android:name="android.app.cts.ActivityManagerMemoryClassTestActivity"
+                android:process=":memoryclass" />
+
     </application>
 
     <!--Test for PackageManager, please put this at the very beginning-->
diff --git a/tests/expectations/knownfailures-3.0_r1.txt b/tests/expectations/knownfailures-3.0_r1.txt
index 46f8952..a13d081 100644
--- a/tests/expectations/knownfailures-3.0_r1.txt
+++ b/tests/expectations/knownfailures-3.0_r1.txt
@@ -5,18 +5,6 @@
   bug: 3198578
 },
 {
-  name: "android.text.cts.StaticLayoutTest#testGetEllipsisCount",
-  bug: 3422121
-},
-{
-  name: "android.text.cts.StaticLayoutTest#testGetEllipsisStart",
-  bug: 3422121
-},
-{
-  name: "android.text.cts.StaticLayoutTest#testGetEllipsizedWidth",
-  bug: 3422121
-},
-{
   name: "android.webkit.cts.WebViewTest#testRequestFocusNodeHref",
   bug: 3241968
 },
@@ -45,11 +33,6 @@
     "android.webkit.cts.WebChromeClientTest#testOnReceivedIcon",
     "android.widget.cts.AbsListViewTest#testGetContextMenuInfo"
   ]
-},
-
-{
-  description: "Crashes the VM",
-  name: "org.apache.harmony.luni.tests.java.net.InetAddressTest#test_getHostName"
 }
 
 ]
diff --git a/tests/src/android/app/cts/ActivityManagerMemoryClassLaunchActivity.java b/tests/src/android/app/cts/ActivityManagerMemoryClassLaunchActivity.java
new file mode 100644
index 0000000..f1f95b8
--- /dev/null
+++ b/tests/src/android/app/cts/ActivityManagerMemoryClassLaunchActivity.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 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.app.cts;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * {@link Activity} that just launches {@link ActivityManagerMemoryClassTestActivity} and
+ * returns the result of that activity.
+ */
+public class ActivityManagerMemoryClassLaunchActivity extends Activity {
+
+    public static final String MEMORY_CLASS_EXTRA = "activityMemoryClass";
+
+    private static final int TEST_ACTIVITY_REQUEST_CODE = 1337;
+
+    private final CountDownLatch mLatch = new CountDownLatch(1);
+
+    private int mChildResult = RESULT_CANCELED;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        // Start the activity that runs in a separate process to do the actual testing,
+        // since the test itself cannot start an activity in a separate process. A separate
+        // process is used to avoid including the overhead of the test instrumentation process.
+
+        Intent intent = getIntent();
+        int memoryClass = intent.getIntExtra(MEMORY_CLASS_EXTRA, -1);
+
+        Intent testIntent = new Intent(this, ActivityManagerMemoryClassTestActivity.class);
+        testIntent.putExtra(MEMORY_CLASS_EXTRA, memoryClass);
+        startActivityForResult(testIntent, TEST_ACTIVITY_REQUEST_CODE);
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        super.onActivityResult(requestCode, resultCode, data);
+        if (requestCode == 1337) {
+            synchronized (this) {
+                mChildResult = resultCode;
+            }
+        } else {
+            throw new IllegalStateException("Request code: " + requestCode);
+        }
+    }
+
+    public int getResult() throws InterruptedException {
+        mLatch.await(5, TimeUnit.SECONDS);
+        synchronized (this) {
+            return mChildResult;
+        }
+    }
+}
diff --git a/tests/src/android/app/cts/ActivityManagerMemoryClassTestActivity.java b/tests/src/android/app/cts/ActivityManagerMemoryClassTestActivity.java
new file mode 100644
index 0000000..e717b03
--- /dev/null
+++ b/tests/src/android/app/cts/ActivityManagerMemoryClassTestActivity.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2011 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.app.cts;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+
+/**
+ * {@link Activity} that allocates arrays of 256k until reaching 75% of the specified memory class.
+ */
+public class ActivityManagerMemoryClassTestActivity extends Activity {
+
+    private static final String TAG = "ActivityManagerMemoryClassTest";
+
+    private static final double FREE_MEMORY_PERCENTAGE = 0.75;
+
+    private static final int ARRAY_BYTES_SIZE = 256 * 1024;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Intent intent = getIntent();
+        int memoryClass =
+                intent.getIntExtra(ActivityManagerMemoryClassLaunchActivity.MEMORY_CLASS_EXTRA, -1);
+        new AllocateMemoryTask(memoryClass).execute();
+    }
+
+    private class AllocateMemoryTask extends AsyncTask<Void, Void, Void> {
+
+        private final int mMemoryClass;
+
+        AllocateMemoryTask(int memoryClass) {
+            this.mMemoryClass = memoryClass;
+        }
+
+        @Override
+        protected Void doInBackground(Void... params) {
+            int targetMbs = (int) (mMemoryClass * FREE_MEMORY_PERCENTAGE);
+            int numArrays = targetMbs * 1024 * 1024 / ARRAY_BYTES_SIZE;
+            Log.i(TAG, "Memory class: " + mMemoryClass + "mb Target memory: "
+                    + targetMbs + "mb Number of arrays: " + numArrays);
+
+            byte[][] arrays = new byte[numArrays][];
+            for (int i = 0; i < arrays.length; i++) {
+                Log.i(TAG, "Allocating array " + i + " of " + arrays.length
+                        + " (" + (i * ARRAY_BYTES_SIZE / 1024 / 1024) + "mb)");
+                arrays[i] = new byte[ARRAY_BYTES_SIZE];
+            }
+            return null;
+        }
+
+        @Override
+        protected void onPostExecute(Void result) {
+            super.onPostExecute(result);
+            setResult(RESULT_OK);
+            finish();
+        }
+    }
+}
diff --git a/tests/src/android/renderscript/cts/passthrough.rs b/tests/src/android/renderscript/cts/passthrough.rs
new file mode 100644
index 0000000..008f7f2
--- /dev/null
+++ b/tests/src/android/renderscript/cts/passthrough.rs
@@ -0,0 +1,8 @@
+#pragma version(1)
+#pragma rs java_package_name(android.renderscript.cts)
+
+void passthrough(int i) {
+    rsDebug("i: ", i);
+    return;
+}
+
diff --git a/tests/src/android/renderscript/cts/primitives.rs b/tests/src/android/renderscript/cts/primitives.rs
new file mode 100644
index 0000000..d2ffd26
--- /dev/null
+++ b/tests/src/android/renderscript/cts/primitives.rs
@@ -0,0 +1,61 @@
+#include "shared.rsh"
+
+// Testing primitive types
+float floatTest = 1.99f;
+double doubleTest = 2.05;
+char charTest = -8;
+short shortTest = -16;
+int intTest = -32;
+long longTest = 17179869184l; // 1 << 34
+long long longlongTest = 68719476736l; // 1 << 36
+
+uchar ucharTest = 8;
+ushort ushortTest = 16;
+uint uintTest = 32;
+ulong ulongTest = 4611686018427387904L;
+int64_t int64_tTest = -17179869184l; // - 1 << 34
+uint64_t uint64_tTest = 117179869184l;
+
+static bool test_primitive_types() {
+    bool failed = false;
+    start();
+
+    _RS_ASSERT(floatTest == 2.99f);
+    _RS_ASSERT(doubleTest == 3.05);
+    _RS_ASSERT(charTest == -16);
+    _RS_ASSERT(shortTest == -32);
+    _RS_ASSERT(intTest == -64);
+    _RS_ASSERT(longTest == 17179869185l);
+    _RS_ASSERT(longlongTest == 68719476735l);
+
+    _RS_ASSERT(ucharTest == 8);
+    _RS_ASSERT(ushortTest == 16);
+    _RS_ASSERT(uintTest == 32);
+    _RS_ASSERT(ulongTest == 4611686018427387903L);
+    _RS_ASSERT(int64_tTest == -17179869184l);
+    _RS_ASSERT(uint64_tTest == 117179869185l);
+
+    float time = end();
+
+    if (failed) {
+        rsDebug("test_primitive_types FAILED", time);
+    }
+    else {
+        rsDebug("test_primitive_types PASSED", time);
+    }
+
+    return failed;
+}
+
+void test() {
+    bool failed = false;
+    failed |= test_primitive_types();
+
+    if (failed) {
+        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+    }
+    else {
+        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+    }
+}
+
diff --git a/tests/src/android/renderscript/cts/shared.rsh b/tests/src/android/renderscript/cts/shared.rsh
new file mode 100644
index 0000000..b91611d
--- /dev/null
+++ b/tests/src/android/renderscript/cts/shared.rsh
@@ -0,0 +1,27 @@
+#pragma version(1)
+#pragma rs java_package_name(android.renderscript.cts)
+
+static int64_t g_time;
+
+static void start(void) {
+    g_time = rsUptimeMillis();
+}
+
+static float end(void) {
+    int64_t t = rsUptimeMillis() - g_time;
+    return ((float)t) / 1000.f;
+}
+
+#define _RS_ASSERT(b) \
+do { \
+    if (!(b)) { \
+        failed = true; \
+        rsDebug(#b " FAILED", 0); \
+    } \
+\
+} while (0)
+
+/* These constants must match those in UnitTest.java */
+static const int RS_MSG_TEST_PASSED = 100;
+static const int RS_MSG_TEST_FAILED = 101;
+
diff --git a/tests/tests/app/src/android/app/cts/ActivityManagerMemoryClassTest.java b/tests/tests/app/src/android/app/cts/ActivityManagerMemoryClassTest.java
new file mode 100644
index 0000000..9506261
--- /dev/null
+++ b/tests/tests/app/src/android/app/cts/ActivityManagerMemoryClassTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2011 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.app.cts;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.DisplayMetrics;
+import android.view.Display;
+import android.view.WindowManager;
+
+/**
+ * {@link ActivityInstrumentationTestCase2} that tests {@link ActivityManager#getMemoryClass()}
+ * by checking that the memory class matches the proper screen density and by launching an
+ * application that attempts to allocate memory on the heap.
+ */
+public class ActivityManagerMemoryClassTest
+        extends ActivityInstrumentationTestCase2<ActivityManagerMemoryClassLaunchActivity> {
+
+    public ActivityManagerMemoryClassTest() {
+        super(ActivityManagerMemoryClassLaunchActivity.class);
+    }
+
+    public void testGetMemoryClass() throws Exception {
+        int memoryClass = getMemoryClass();
+        int screenDensity = getScreenDensity();
+        int screenSize = getScreenSize();
+        assertMemoryForScreenDensity(memoryClass, screenDensity, screenSize);
+
+        runHeapTestApp(memoryClass);
+    }
+
+    private int getMemoryClass() {
+        Context context = getInstrumentation().getTargetContext();
+        ActivityManager activityManager =
+                (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+        return activityManager.getMemoryClass();
+    }
+
+    private int getScreenDensity() {
+        Context context = getInstrumentation().getTargetContext();
+        WindowManager windowManager =
+                (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+        Display display = windowManager.getDefaultDisplay();
+        DisplayMetrics metrics = new DisplayMetrics();
+        display.getMetrics(metrics);
+        return metrics.densityDpi;
+    }
+
+    private int getScreenSize() {
+        Context context = getInstrumentation().getTargetContext();
+        Configuration config = context.getResources().getConfiguration();
+        return config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
+    }
+
+    private void assertMemoryForScreenDensity(int memoryClass, int screenDensity, int screenSize) {
+        int expectedMinimumMemory = -1;
+        boolean isXLarge = screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE;
+        switch (screenDensity) {
+            case DisplayMetrics.DENSITY_LOW:
+                expectedMinimumMemory = 16;
+                break;
+
+            case DisplayMetrics.DENSITY_MEDIUM:
+                expectedMinimumMemory = isXLarge ? 32 : 16;
+                break;
+
+            case DisplayMetrics.DENSITY_HIGH:
+            case DisplayMetrics.DENSITY_XHIGH:
+                expectedMinimumMemory = isXLarge ? 48 : 24;
+                break;
+
+            default:
+                throw new IllegalArgumentException("No memory requirement specified "
+                        + " for screen density " + screenDensity);
+        }
+
+        assertTrue("Expected to have at least " + expectedMinimumMemory
+                + "mb of memory for screen density " + screenDensity,
+                        memoryClass >= expectedMinimumMemory);
+    }
+
+    private void runHeapTestApp(int memoryClass) throws InterruptedException {
+        Intent intent = new Intent();
+        intent.putExtra(ActivityManagerMemoryClassLaunchActivity.MEMORY_CLASS_EXTRA,
+                memoryClass);
+        setActivityIntent(intent);
+        ActivityManagerMemoryClassLaunchActivity activity = getActivity();
+        assertEquals("The test application couldn't allocate memory close to the amount "
+                + " specified by the memory class.", Activity.RESULT_OK, activity.getResult());
+    }
+}
diff --git a/tests/tests/app/src/android/app/cts/InstrumentationTest.java b/tests/tests/app/src/android/app/cts/InstrumentationTest.java
index 6ab9ac6..d2c55c2 100644
--- a/tests/tests/app/src/android/app/cts/InstrumentationTest.java
+++ b/tests/tests/app/src/android/app/cts/InstrumentationTest.java
@@ -954,6 +954,11 @@
             }
 
             @Override
+            public boolean superDispatchGenericMotionEvent(MotionEvent event) {
+                return false;
+            }
+
+            @Override
             public void takeKeyEvents(boolean get) {
             }
 
diff --git a/tests/tests/content/src/android/content/cts/IntentTest.java b/tests/tests/content/src/android/content/cts/IntentTest.java
index 15400be..995c668 100644
--- a/tests/tests/content/src/android/content/cts/IntentTest.java
+++ b/tests/tests/content/src/android/content/cts/IntentTest.java
@@ -16,11 +16,13 @@
 
 package android.content.cts;
 
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Set;
+import com.android.internal.app.ResolverActivity;
+import com.android.internal.util.XmlUtils;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -45,13 +47,11 @@
 import android.util.AttributeSet;
 import android.util.Xml;
 
-import com.android.internal.app.ResolverActivity;
-import com.android.internal.util.XmlUtils;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Set;
 
 @TestTargetClass(Intent.class)
 public class IntentTest extends AndroidTestCase {
@@ -1746,7 +1746,7 @@
         assertEquals(Intent.FILL_IN_DATA, destIntent.fillIn(sourceIntent, Intent.FILL_IN_DATA));
         assertEquals(TEST_URI, destIntent.getData());
     }
-    
+
     /**
      * Test that fillIn copies data type.
      */
@@ -2087,8 +2087,6 @@
         assertFalse(mIntent.filterEquals(target));
         mIntent.addCategory(TEST_CATEGORY + "test");
         assertFalse(mIntent.filterEquals(target));
-        mIntent.addCategory(null);
-        assertFalse(mIntent.filterEquals(target));
         mIntent.addCategory(TEST_CATEGORY);
         assertFalse(mIntent.filterEquals(target));
     }
diff --git a/tests/tests/drm/Android.mk b/tests/tests/drm/Android.mk
new file mode 100644
index 0000000..61e1f10
--- /dev/null
+++ b/tests/tests/drm/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2011 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# don't include this package in any target
+LOCAL_MODULE_TAGS := optional
+# and when built explicitly put it in the data partition
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsDrmTestCases
+
+LOCAL_INSTRUMENTATION_FOR := CtsTestStubs
+
+# uncomment when dalvik.annotation.Test* are removed or part of SDK
+#LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/tests/tests/drm/AndroidManifest.xml b/tests/tests/drm/AndroidManifest.xml
new file mode 100644
index 0000000..fe515f3
--- /dev/null
+++ b/tests/tests/drm/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.cts.drm">
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
+                     android:targetPackage="com.android.cts.stub"
+                     android:label="CTS tests of android.drm"/>
+
+</manifest>
+
diff --git a/tests/tests/drm/README b/tests/tests/drm/README
new file mode 100644
index 0000000..dd0ef17
--- /dev/null
+++ b/tests/tests/drm/README
@@ -0,0 +1,6 @@
+- User of CTS code needs to edit configuration files in
+  "src/android/drm/cts/configs/" according to the specification
+  of user's DRM plug-in.
+- If new plug-in is added, user should add corresponding configuration
+  file under "src/android/drm/cts/configs/" and update
+  "src/android/drm/cts/ConfigFactory.java".
diff --git a/tests/tests/drm/src/android/drm/cts/Config.java b/tests/tests/drm/src/android/drm/cts/Config.java
new file mode 100644
index 0000000..736c0ad
--- /dev/null
+++ b/tests/tests/drm/src/android/drm/cts/Config.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011 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.drm.cts;
+
+import java.util.HashMap;
+
+public interface Config {
+    String getPluginName();
+    String getMimeType();
+    String getAccountId();
+    String getRightsPath();
+    String getContentPath();
+    HashMap<String, String> getInfoOfRegistration();
+    HashMap<String, String> getInfoOfUnregistration();
+    HashMap<String, String> getInfoOfRightsAcquisition();
+}
diff --git a/tests/tests/drm/src/android/drm/cts/ConfigFactory.java b/tests/tests/drm/src/android/drm/cts/ConfigFactory.java
new file mode 100644
index 0000000..643bb67
--- /dev/null
+++ b/tests/tests/drm/src/android/drm/cts/ConfigFactory.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2011 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.drm.cts;
+
+import android.util.Log;
+
+import android.drm.cts.configs.PassthruConfig;
+import android.drm.cts.configs.FwdLockConfig;
+
+public final class ConfigFactory {
+    private static final String TAG = "ConfigFactory";
+
+    /**
+     * Get configurations of specified plug-in name.
+     *
+     * @param plugInName Name of DRM plug-in. The name SHOULD be consistent with
+     *                   the name defined in plug-in's onGetSupportInfo().
+     */
+    public static Config getConfig(String plugInName) {
+        if (plugInName.equals("Passthru plug-in")) {
+            return PassthruConfig.getInstance();
+        } else if (plugInName.equals("OMA V1 Forward Lock")) {
+            return FwdLockConfig.getInstance();
+        } else {
+            Log.e(TAG, "Configuration for " + plugInName + " is not registered.");
+            return null;
+        }
+    }
+}
diff --git a/tests/tests/drm/src/android/drm/cts/DRMTest.java b/tests/tests/drm/src/android/drm/cts/DRMTest.java
new file mode 100644
index 0000000..c43bf4b
--- /dev/null
+++ b/tests/tests/drm/src/android/drm/cts/DRMTest.java
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 2011 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.drm.cts;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+
+import android.content.ContentValues;
+import android.test.AndroidTestCase;
+import android.util.Log;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import android.drm.DrmManagerClient;
+import android.drm.DrmConvertedStatus;
+import android.drm.DrmEvent;
+import android.drm.DrmInfo;
+import android.drm.DrmInfoRequest;
+import android.drm.DrmInfoStatus;
+import android.drm.DrmRights;
+import android.drm.DrmStore;
+import android.drm.DrmUtils;
+
+@TestTargetClass(DrmManagerClient.class)
+public class DRMTest extends AndroidTestCase {
+    private static String TAG = "CtsDRMTest";
+    private static final int WAIT_TIME = 60000; // 1 min max
+
+    private Object mLock = new Object();
+    private ArrayList<Config> mConfigs = new ArrayList<Config>();
+    private DrmRights mDrmRights;
+    private DrmManagerClient mDrmManagerClient;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mDrmManagerClient = new DrmManagerClient(getContext());
+        String[] plugins = mDrmManagerClient.getAvailableDrmEngines();
+
+        mConfigs.clear();
+        for(String plugInName : plugins) {
+            Config config = ConfigFactory.getConfig(plugInName);
+            if (null != config) {
+                mConfigs.add(config);
+            }
+        }
+    }
+
+    private void register(Config config) throws Exception {
+        DrmInfo drmInfo = executeAcquireDrmInfo(DrmInfoRequest.TYPE_REGISTRATION_INFO,
+                                            config.getInfoOfRegistration(),
+                                            config.getMimeType());
+        executeProcessDrmInfo(drmInfo, config);
+    }
+
+    private void acquireRights(Config config) throws Exception {
+        DrmInfo drmInfo = executeAcquireDrmInfo(DrmInfoRequest.TYPE_RIGHTS_ACQUISITION_INFO,
+                                            config.getInfoOfRightsAcquisition(),
+                                            config.getMimeType());
+        executeProcessDrmInfo(drmInfo, config);
+    }
+
+    private void deregister(Config config) throws Exception {
+        DrmInfo drmInfo = executeAcquireDrmInfo(DrmInfoRequest.TYPE_UNREGISTRATION_INFO,
+                                            config.getInfoOfRegistration(),
+                                            config.getMimeType());
+        executeProcessDrmInfo(drmInfo, config);
+    }
+
+    public void testRegisterAndDeregister() throws Exception {
+        for (Config config : mConfigs) {
+            register(config);
+            deregister(config);
+        }
+    }
+
+    public void testAcquireRights() throws Exception {
+        for (Config config : mConfigs) {
+            register(config);
+            acquireRights(config);
+            deregister(config);
+        }
+    }
+
+    public void testGetConstraints() throws Exception {
+        for (Config config : mConfigs) {
+            register(config);
+            acquireRights(config);
+            ContentValues constraints = mDrmManagerClient.getConstraints(
+                                            config.getContentPath(),
+                                            DrmStore.Action.DEFAULT);
+            assertNotNull("Failed on plugin: " + config.getPluginName(), constraints);
+            deregister(config);
+        }
+    }
+
+    public void testCanHandle() throws Exception {
+        for (Config config : mConfigs) {
+            assertTrue("Failed on plugin: " + config.getPluginName(),
+                    mDrmManagerClient.canHandle(config.getContentPath(), config.getMimeType()));
+        }
+    }
+
+    public void testGetOriginalMimeType() throws Exception {
+        for (Config config : mConfigs) {
+            assertNotNull("Failed on plugin: " + config.getPluginName(),
+                    mDrmManagerClient.getOriginalMimeType(config.getContentPath()));
+        }
+    }
+
+    public void testCheckRightsStatus() throws Exception {
+        for (Config config : mConfigs) {
+            register(config);
+            acquireRights(config);
+            int rightsStatus = mDrmManagerClient.checkRightsStatus(
+                                                config.getContentPath(),
+                                                DrmStore.Action.PLAY);
+            assertEquals("Failed on plugin: " + config.getPluginName(),
+                    DrmStore.RightsStatus.RIGHTS_VALID, rightsStatus);
+            deregister(config);
+        }
+    }
+
+    public void testRemoveRights() throws Exception {
+        for (Config config : mConfigs) {
+            assertEquals("Failed on plugin: " + config.getPluginName(),
+                    DrmManagerClient.ERROR_NONE,
+                    mDrmManagerClient.removeRights(config.getContentPath()));
+        }
+    }
+
+    public void testRemoveAllRights() throws Exception {
+        for (Config config : mConfigs) {
+            assertEquals("Failed on plugin: " + config.getPluginName(),
+                    mDrmManagerClient.removeAllRights(), DrmManagerClient.ERROR_NONE);
+        }
+    }
+
+    public void testConvertData() throws Exception {
+        for (Config config : mConfigs) {
+            byte[] inputData = new byte[]{'T','E','S','T'};
+
+            int convertId = mDrmManagerClient.openConvertSession(config.getMimeType());
+            DrmConvertedStatus drmConvertStatus
+                                = mDrmManagerClient.convertData(convertId, inputData);
+            mDrmManagerClient.closeConvertSession(convertId);
+        }
+    }
+
+    private DrmInfo executeAcquireDrmInfo(
+            int type, HashMap<String, String> request, String mimeType) throws Exception {
+        DrmInfoRequest infoRequest = new DrmInfoRequest(type, mimeType);
+
+        for (Iterator it = request.keySet().iterator(); it.hasNext(); ) {
+            String key = (String) it.next();
+            String value = request.get(key);
+            infoRequest.put(key, value);
+        }
+
+        return mDrmManagerClient.acquireDrmInfo(infoRequest);
+    }
+
+    private void executeProcessDrmInfo(DrmInfo drmInfo, Config config) throws Exception {
+        assertNotNull("Failed on plugin: " + config.getPluginName(), drmInfo);
+
+        mDrmManagerClient.setOnEventListener(new OnEventListenerImpl(config));
+        drmInfo.put(DrmInfoRequest.ACCOUNT_ID, config.getAccountId());
+        assertEquals("Failed on plugin: " + config.getPluginName(),
+                DrmManagerClient.ERROR_NONE, mDrmManagerClient.processDrmInfo(drmInfo));
+
+        synchronized(mLock) {
+            try {
+                mLock.wait(WAIT_TIME);
+            } catch(Exception e) {
+                Log.v(TAG, "ProcessDrmInfo: wait was interrupted.");
+            }
+        }
+    }
+
+    private class OnEventListenerImpl implements DrmManagerClient.OnEventListener {
+        private Config mConfig;
+        public OnEventListenerImpl(Config config) {
+            mConfig = config;
+        }
+
+        @Override
+        public void onEvent(DrmManagerClient client, DrmEvent event) {
+            switch (event.getType()) {
+            case DrmEvent.TYPE_DRM_INFO_PROCESSED:
+                Log.d(TAG, "processDrmInfo() completed");
+                DrmInfoStatus infoStatus
+                        = (DrmInfoStatus) event.getAttribute(DrmEvent.DRM_INFO_STATUS_OBJECT);
+                switch (infoStatus.infoType) {
+                case DrmInfoRequest.TYPE_RIGHTS_ACQUISITION_INFO:
+                    mDrmRights = new DrmRights(infoStatus.data, infoStatus.mimeType);
+                    assertNotNull(mDrmRights);
+                    try {
+                        assertEquals(DrmManagerClient.ERROR_NONE, mDrmManagerClient.saveRights(
+                                    mDrmRights, mConfig.getRightsPath(), mConfig.getContentPath()));
+                        Log.d(TAG, "Rights saved");
+                    } catch (IOException e) {
+                        Log.e(TAG, "Save Rights failed");
+                        e.printStackTrace();
+                    }
+                    break;
+                case DrmInfoRequest.TYPE_REGISTRATION_INFO:
+                    Log.d(TAG, "Registration completed");
+                    break;
+                case DrmInfoRequest.TYPE_UNREGISTRATION_INFO:
+                    Log.d(TAG, "Deregistration completed");
+                    break;
+                default:
+                    break;
+                }
+                break;
+            default:
+                break;
+            }
+            synchronized (mLock) {
+                mLock.notify();
+            }
+        }
+    }
+}
diff --git a/tests/tests/drm/src/android/drm/cts/configs/FwdLockConfig.java b/tests/tests/drm/src/android/drm/cts/configs/FwdLockConfig.java
new file mode 100644
index 0000000..e67ff03
--- /dev/null
+++ b/tests/tests/drm/src/android/drm/cts/configs/FwdLockConfig.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011 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.drm.cts.configs;
+
+import java.util.HashMap;
+
+import android.drm.cts.Config;
+
+public class FwdLockConfig implements Config {
+    private static FwdLockConfig sInstance = new FwdLockConfig();
+    private FwdLockConfig() {}
+    public static FwdLockConfig getInstance() {
+        return sInstance;
+    }
+    public String getPluginName() {
+        return "Forward Lock";
+    }
+    public String getMimeType() {
+        return "application/x-android-drm-fl";
+    }
+    public String getAccountId() {
+        return "01234567";
+    }
+    public String getRightsPath() {
+        // Fwd lock does not have rights but send back dummy string anyways.
+        return "/sdcard/non_existing_rights.xml";
+    }
+    public String getContentPath() {
+        return "/sdcard/dummy_fwdlock_content.dm";
+    }
+    public HashMap<String, String> getInfoOfRegistration() {
+        return sInfoOfRegistration;
+    }
+    public HashMap<String, String> getInfoOfUnregistration() {
+        return sInfoOfUnregistration;
+    }
+    public HashMap<String, String> getInfoOfRightsAcquisition(){
+        return sInfoOfRightsAcquisition;
+    }
+
+    private static HashMap<String, String> sInfoOfRegistration = new HashMap<String, String>();
+    private static HashMap<String, String> sInfoOfUnregistration = new HashMap<String, String>();
+    private static HashMap<String, String> sInfoOfRightsAcquisition =
+        new HashMap<String, String>();
+
+    static {
+        sInfoOfRegistration.put("Dummy-FwdLock-1", "Dummy-FwdLock-1");
+
+        sInfoOfUnregistration.put("Dummy-FwdLock-2", "Dummy-FwdLock-2");
+
+        sInfoOfRightsAcquisition.put("Dummy-FwdLock-3", "Dummy-FwdLock-3");
+    }
+}
diff --git a/tests/tests/drm/src/android/drm/cts/configs/PassthruConfig.java b/tests/tests/drm/src/android/drm/cts/configs/PassthruConfig.java
new file mode 100644
index 0000000..7310825
--- /dev/null
+++ b/tests/tests/drm/src/android/drm/cts/configs/PassthruConfig.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2011 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.drm.cts.configs;
+
+import java.util.HashMap;
+
+import android.drm.cts.Config;
+
+public class PassthruConfig implements Config {
+    private static PassthruConfig sInstance = new PassthruConfig();
+    private PassthruConfig() {}
+    public static PassthruConfig getInstance() {
+        return sInstance;
+    }
+    public String getPluginName() {
+        return "Passthru";
+    }
+    public String getMimeType() {
+        return "application/vnd.passthru.drm";
+    }
+    public String getAccountId() {
+        return "01234567";
+    }
+    public String getRightsPath() {
+        return "/sdcard/dummy_passthru_rights.xml";
+    }
+    public String getContentPath() {
+        return "/sdcard/dummy_passthru_content.passthru";
+    }
+    public HashMap<String, String> getInfoOfRegistration() {
+        return sInfoOfRegistration;
+    }
+    public HashMap<String, String> getInfoOfUnregistration() {
+        return sInfoOfUnregistration;
+    }
+    public HashMap<String, String> getInfoOfRightsAcquisition(){
+        return sInfoOfRightsAcquisition;
+    }
+
+    private static HashMap<String, String> sInfoOfRegistration = new HashMap<String, String>();
+    private static HashMap<String, String> sInfoOfUnregistration = new HashMap<String, String>();
+    private static HashMap<String, String> sInfoOfRightsAcquisition = new HashMap<String, String>();
+
+    static {
+        sInfoOfRegistration.put("Foo-1", "foo-1");
+
+        sInfoOfUnregistration.put("Foo-2", "foo-2");
+
+        sInfoOfRightsAcquisition.put("Foo-3", "foo-3");
+    }
+}
diff --git a/tests/tests/graphics/src/android/graphics/cts/RadialGradientTest.java b/tests/tests/graphics/src/android/graphics/cts/RadialGradientTest.java
deleted file mode 100644
index 3db864b..0000000
--- a/tests/tests/graphics/src/android/graphics/cts/RadialGradientTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (C) 2009 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.graphics.cts;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.RadialGradient;
-import android.graphics.Shader;
-import android.graphics.Shader.TileMode;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(RadialGradient.class)
-public class RadialGradientTest extends TestCase {
-    private static final int SIZE = 200;
-    private static final int RADIUS = 80;
-    private static final int CENTER = SIZE / 2;
-
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        method = "RadialGradient",
-        args = {float.class, float.class, float.class, int[].class, float[].class,
-                TileMode.class}
-    )
-    public void testRadialGradient() {
-        final int[] colors = { Color.BLUE, Color.GREEN, Color.RED };
-        final float[] positions = { 0f, 0.3f, 1f };
-        int tolerance = (int)(0xFF / (0.3f * RADIUS) * 2);
-        RadialGradient rg = new RadialGradient(CENTER, CENTER, RADIUS, colors, positions,
-                Shader.TileMode.CLAMP);
-        Bitmap b = Bitmap.createBitmap(SIZE, SIZE, Bitmap.Config.ARGB_8888);
-        Canvas canvas = new Canvas(b);
-        Paint p = new Paint();
-        p.setShader(rg);
-        canvas.drawRect(0, 0, SIZE, SIZE, p);
-        checkPixels(b, colors, positions, tolerance);
-    }
-
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        method = "RadialGradient",
-        args = {float.class, float.class, float.class, int.class, int.class, TileMode.class}
-    )
-    public void testRadialGradientWithColor() {
-        final int[] colors = { Color.BLUE, Color.GREEN };
-        final float[] positions = { 0f, 1f };
-        int tolerance = (int)(0xFF / RADIUS * 2);
-        RadialGradient rg = new RadialGradient(CENTER, CENTER, RADIUS, colors[0], colors[1],
-                Shader.TileMode.CLAMP);
-        Bitmap b = Bitmap.createBitmap(SIZE, SIZE, Bitmap.Config.ARGB_8888);
-        Canvas canvas = new Canvas(b);
-        Paint p = new Paint();
-        p.setShader(rg);
-        canvas.drawRect(0, 0, SIZE, SIZE, p);
-        checkPixels(b, colors, positions, tolerance);
-    }
-
-    private void checkPixels(Bitmap bitmap, int[] colors, float[] positions, int tolerance) {
-        for (int y = 0; y < SIZE; y++) {
-            for (int x = 0; x < SIZE; x++) {
-                double dist = dist(x, y, CENTER, CENTER) / RADIUS;
-                int idx;
-                int color;
-                for (idx = 0; idx < positions.length; idx++) {
-                    if (positions[idx] > dist) {
-                        break;
-                    }
-                }
-                if (idx == 0) {
-                    // use start color
-                    color = colors[0];
-                } else if (idx == positions.length) {
-                    // clamp to end color
-                    color = colors[positions.length - 1];
-                } else {
-                    // linear interpolation
-                    int i1 = idx - 1; // index of next lower color and position
-                    int i2 = idx; // index of next higher color and position
-                    double delta = (dist - positions[i1]) / (positions[i2] - positions[i1]);
-                    int alpha = (int) ((1d - delta) * Color.alpha(colors[i1]) +
-                            delta * Color.alpha(colors[i2]));
-                    int red = (int) ((1d - delta) * Color.red(colors[i1]) +
-                            delta * Color.red(colors[i2]));
-                    int green = (int) ((1d - delta) * Color.green(colors[i1]) +
-                            delta * Color.green(colors[i2]));
-                    int blue = (int) ((1d - delta) * Color.blue(colors[i1]) +
-                            delta * Color.blue(colors[i2]));
-                    color = Color.argb(alpha, red, green, blue);
-                }
-                int pixel = bitmap.getPixel(x, y);
-
-                assertEquals(Color.alpha(color), Color.alpha(pixel), tolerance);
-                assertEquals(Color.red(color), Color.red(pixel), tolerance);
-                assertEquals(Color.green(color), Color.green(pixel), tolerance);
-                assertEquals(Color.blue(color), Color.blue(pixel), tolerance);
-            }
-        }
-    }
-
-    /**
-     * Calculate distance between two points.
-     */
-    private double dist(int x1, int y1, int x2, int y2) {
-        int distX = x1 - x2;
-        int distY = y1 - y2;
-        return Math.sqrt(distX * distX + distY * distY);
-    }
-
-}
diff --git a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
index 12a828d..d75b5bc 100644
--- a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
@@ -162,7 +162,9 @@
         public void onPreviewFrame(byte [] data, Camera camera) {
             assertNotNull(data);
             Size size = camera.getParameters().getPreviewSize();
-            assertEquals(size.width * size.height * 3 / 2, data.length);
+            int format = camera.getParameters().getPreviewFormat();
+            int bitsPerPixel = ImageFormat.getBitsPerPixel(format);
+            assertEquals(size.width * size.height * bitsPerPixel / 8, data.length);
             mPreviewCallbackResult = true;
             mCamera.stopPreview();
             if (LOGV) Log.v(TAG, "notify the preview callback");
@@ -223,7 +225,7 @@
     private final class TestErrorCallback implements ErrorCallback {
         public void onError(int error, Camera camera) {
             mErrorCallbackResult = true;
-            fail("The Error code is: " + error);
+            fail("Got camera error from ErrorCallback: " + error);
         }
     }
 
@@ -577,7 +579,6 @@
         // Parameters constants
         final int PICTURE_FORMAT = ImageFormat.JPEG;
         final int PREVIEW_FORMAT = ImageFormat.NV21;
-        final int PREVIEW_FRAMERATE = 10;
 
         // Before setting Parameters
         final int origPictureFormat = parameters.getPictureFormat();
@@ -623,7 +624,9 @@
         int jpegThumnailQuality = parameters.getJpegThumbnailQuality();
         assertTrue(previewSizes != null && previewSizes.size() != 0);
         assertTrue(pictureSizes != null && pictureSizes.size() != 0);
-        assertTrue(previewFormats != null && previewFormats.size() != 0);
+        assertTrue(previewFormats != null && previewFormats.size() >= 2);
+        assertTrue(previewFormats.contains(ImageFormat.NV21));
+        assertTrue(previewFormats.contains(ImageFormat.YV12));
         assertTrue(pictureFormats != null && pictureFormats.size() != 0);
         assertTrue(frameRates != null && frameRates.size() != 0);
         assertTrue(focusModes != null && focusModes.size() != 0);
@@ -899,6 +902,7 @@
         assertEquals((float)latitude, latLong[0], 0.0001f);
         assertEquals((float)longitude, latLong[1], 0.0001f);
         assertEquals(altitude, exif.getAltitude(-1), 1);
+        assertEquals(timestamp, exif.getGpsDateTime() / 1000);
     }
 
     private void checkGpsDataNull(ExifInterface exif) {
@@ -1039,9 +1043,11 @@
             callback.mNumCbWithBuffer1 = 0;
             callback.mNumCbWithBuffer2 = 0;
             callback.mNumCbWithBuffer3 = 0;
-            callback.mBuffer1 = new byte[size.width * size.height * 3 / 2];
-            callback.mBuffer2 = new byte[size.width * size.height * 3 / 2];
-            callback.mBuffer3 = new byte[size.width * size.height * 3 / 2];
+            int format = mCamera.getParameters().getPreviewFormat();
+            int bitsPerPixel = ImageFormat.getBitsPerPixel(format);
+            callback.mBuffer1 = new byte[size.width * size.height * bitsPerPixel / 8];
+            callback.mBuffer2 = new byte[size.width * size.height * bitsPerPixel / 8];
+            callback.mBuffer3 = new byte[size.width * size.height * bitsPerPixel / 8];
 
             // Test if we can get the preview callbacks with specified buffers.
             mCamera.addCallbackBuffer(callback.mBuffer1);
@@ -1549,7 +1555,9 @@
             assertNotNull(data);
             Size size = camera.getParameters().getPreviewSize();
             assertEquals(expectedPreviewSize, size);
-            assertEquals(size.width * size.height * 3 / 2, data.length);
+            int format = camera.getParameters().getPreviewFormat();
+            int bitsPerPixel = ImageFormat.getBitsPerPixel(format);
+            assertEquals(size.width * size.height * bitsPerPixel / 8, data.length);
             camera.setPreviewCallback(null);
             mPreviewCallbackResult = true;
             mPreviewDone.open();
@@ -1597,9 +1605,11 @@
 
         // Test if the actual fps is within fps range.
         Size size = parameters.getPreviewSize();
-        byte[] buffer1 = new byte[size.width * size.height * 3 / 2];
-        byte[] buffer2 = new byte[size.width * size.height * 3 / 2];
-        byte[] buffer3 = new byte[size.width * size.height * 3 / 2];
+        int format = mCamera.getParameters().getPreviewFormat();
+        int bitsPerPixel = ImageFormat.getBitsPerPixel(format);
+        byte[] buffer1 = new byte[size.width * size.height * bitsPerPixel / 8];
+        byte[] buffer2 = new byte[size.width * size.height * bitsPerPixel / 8];
+        byte[] buffer3 = new byte[size.width * size.height * bitsPerPixel / 8];
         FpsRangePreviewCb callback = new FpsRangePreviewCb();
         int[] readBackFps = new int[2];
         for (int[] fps: fpsList) {
@@ -1895,4 +1905,64 @@
 
         terminateMessageLooper();
     }
+
+    public void testGetParameterDuringFocus() throws Exception {
+        int nCameras = Camera.getNumberOfCameras();
+        for (int id = 0; id < nCameras; id++) {
+            Log.v(TAG, "Camera id=" + id);
+            testGetParameterDuringFocusByCamera(id);
+        }
+    }
+
+    private void testGetParameterDuringFocusByCamera(int cameraId) throws Exception {
+        initializeMessageLooper(cameraId);
+        mCamera.setPreviewDisplay(getActivity().getSurfaceView().getHolder());
+        mCamera.setErrorCallback(mErrorCallback);
+        mCamera.startPreview();
+        Parameters parameters = mCamera.getParameters();
+        for (String focusMode: parameters.getSupportedFocusModes()) {
+            if (focusMode.equals(parameters.FOCUS_MODE_AUTO)
+                    || focusMode.equals(parameters.FOCUS_MODE_MACRO)) {
+                parameters.setFocusMode(focusMode);
+                mCamera.setParameters(parameters);
+                mCamera.autoFocus(mAutoFocusCallback);
+                // This should not crash or throw exception.
+                mCamera.getParameters();
+                waitForFocusDone();
+
+
+                mCamera.autoFocus(mAutoFocusCallback);
+                // Add a small delay to make sure focus has started.
+                Thread.sleep(100);
+                // This should not crash or throw exception.
+                mCamera.getParameters();
+            }
+        }
+        terminateMessageLooper();
+    }
+
+    public void testPreviewFormats() throws Exception {
+        int nCameras = Camera.getNumberOfCameras();
+        for (int id = 0; id < nCameras; id++) {
+            Log.v(TAG, "Camera id=" + id);
+            testPreviewFormatsByCamera(id);
+        }
+    }
+
+    private void testPreviewFormatsByCamera(int cameraId) throws Exception {
+        initializeMessageLooper(cameraId);
+        mCamera.setPreviewDisplay(getActivity().getSurfaceView().getHolder());
+        mCamera.setErrorCallback(mErrorCallback);
+        Parameters parameters = mCamera.getParameters();
+        for (int format: parameters.getSupportedPreviewFormats()) {
+            Log.v(TAG, "Test preview format " + format);
+            parameters.setPreviewFormat(format);
+            mCamera.setParameters(parameters);
+            mCamera.setOneShotPreviewCallback(mPreviewCallback);
+            mCamera.startPreview();
+            waitForPreviewDone();
+            assertTrue(mPreviewCallbackResult);
+        }
+        terminateMessageLooper();
+    }
 }
diff --git a/tests/tests/os/src/android/os/cts/BuildVersionTest.java b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
index 2ef5167..954507b 100644
--- a/tests/tests/os/src/android/os/cts/BuildVersionTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
@@ -32,8 +32,8 @@
 
     private static final String LOG_TAG = "BuildVersionTest";
     private static final Set<String> EXPECTED_RELEASES =
-        new HashSet<String>(Arrays.asList("3.0", "3.0.1"));
-    private static final int EXPECTED_SDK = 11;
+        new HashSet<String>(Arrays.asList("3.1"));
+    private static final int EXPECTED_SDK = 12;
 
     public void testReleaseVersion() {
         // Applications may rely on the exact release version
diff --git a/tests/tests/os/src/android/os/cts/ParcelTest.java b/tests/tests/os/src/android/os/cts/ParcelTest.java
index 28d7728..52b068f 100644
--- a/tests/tests/os/src/android/os/cts/ParcelTest.java
+++ b/tests/tests/os/src/android/os/cts/ParcelTest.java
@@ -776,6 +776,30 @@
             assertEquals(c[i], d[i]);
         }
         p.recycle();
+
+        // Test array bounds checks (null already checked above).
+        p = Parcel.obtain();
+        try {
+            p.writeByteArray(c, -1, 1); // Negative offset.
+            fail();
+        } catch (RuntimeException expected) {
+        }
+        try {
+            p.writeByteArray(c, 0, -1); // Negative count.
+            fail();
+        } catch (RuntimeException expected) {
+        }
+        try {
+            p.writeByteArray(c, c.length + 1, 1); // High offset.
+            fail();
+        } catch (RuntimeException expected) {
+        }
+        try {
+            p.writeByteArray(c, 0, c.length + 1); // High count.
+            fail();
+        } catch (RuntimeException expected) {
+        }
+        p.recycle();
     }
 
     @TestTargets({
@@ -875,12 +899,11 @@
         d = new byte[c.length - 2];
         p.setDataPosition(0);
         p.readByteArray(d);
-        assertEquals(7, d.length);;
         for (int i = 0; i < d.length; i++) {
             Log.d("Trace", "i=" + i + " d[i]=" + d[i]);
         }
         for (int i = 0; i < 7; i++) {
-            assertEquals(c[i], d[i]);
+            assertEquals(c[i + 1], d[i]);
         }
         p.recycle();
     }
diff --git a/tests/tests/provider/src/android/provider/cts/BrowserTest.java b/tests/tests/provider/src/android/provider/cts/BrowserTest.java
index 9eb5b82..73db4c3 100644
--- a/tests/tests/provider/src/android/provider/cts/BrowserTest.java
+++ b/tests/tests/provider/src/android/provider/cts/BrowserTest.java
@@ -52,6 +52,7 @@
     private ContentResolver mContentResolver;
     private IContentProvider mProvider;
     private BrowserStubActivity mActivity;
+    private boolean mMasterSyncEnabled;
 
     // the backup for the 2 tables which we will modify in test cases
     private ArrayList<ContentValues> mBookmarksBackup;
@@ -72,14 +73,23 @@
         mBookmarksBackup = new ArrayList<ContentValues>();
         mSearchesBackup = new ArrayList<ContentValues>();
 
-        // backup the current contents in database (_id=1 is a fixed id root)
-        Cursor cursor = mProvider.query(Bookmarks.CONTENT_URI, null, "_id != 1", null, null);
+        // Disable sync
+        mMasterSyncEnabled = ContentResolver.getMasterSyncAutomatically();
+        ContentResolver.setMasterSyncAutomatically(false);
+
+        // backup the current contents in database
+        Cursor cursor = mProvider.query(Bookmarks.CONTENT_URI, null, null, null, null);
         if (cursor.moveToFirst()) {
             String[] colNames = cursor.getColumnNames();
             while (!cursor.isAfterLast()) {
                 ContentValues value = new ContentValues();
 
                 for (int i = 0; i < colNames.length; i++) {
+                    if (Bookmarks.PARENT_SOURCE_ID.equals(colNames[i])
+                            || Bookmarks.INSERT_AFTER_SOURCE_ID.equals(colNames[i])) {
+                        // These aren't actual columns, so skip them in the backup
+                        continue;
+                    }
                     switch (cursor.getType(i)) {
                     case Cursor.FIELD_TYPE_BLOB:
                         value.put(colNames[i], cursor.getBlob(i));
@@ -130,6 +140,7 @@
     @Override
     protected void tearDown() throws Exception {
         try {
+
             // clear all new contents added in test cases.
             Uri uri = Bookmarks.CONTENT_URI.buildUpon()
                 .appendQueryParameter(BrowserContract.CALLER_IS_SYNCADAPTER, "true")
@@ -139,12 +150,15 @@
 
             // recover the old backup contents
             for (ContentValues value : mBookmarksBackup) {
-                mProvider.insert(Bookmarks.CONTENT_URI, value);
+                mProvider.insert(uri, value);
             }
 
             for (ContentValues value : mSearchesBackup) {
                 mProvider.insert(Browser.SEARCHES_URI, value);
             }
+
+            // Re-enable sync
+            ContentResolver.setMasterSyncAutomatically(mMasterSyncEnabled);
         } finally {
             super.tearDown();
         }
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
index c53393f..36d4303 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
@@ -155,8 +155,9 @@
         Uri membersUri = Members.getContentUri(MediaStoreAudioTestHelper.EXTERNAL_VOLUME_NAME,
                 playlistId);
         Uri audioUri = mContentResolver.insert(membersUri, values);
+
         assertNotNull(audioUri);
-        assertEquals(Uri.withAppendedPath(membersUri, Long.toString(mIdOfAudio1)), audioUri);
+        assertTrue(audioUri.toString().startsWith(membersUri.toString()));
 
         try {
             // query the audio info
@@ -164,7 +165,7 @@
             assertEquals(1, c.getCount());
             c.moveToFirst();
             long memberId = c.getLong(c.getColumnIndex(Members._ID));
-            assertTrue(memberId > 0);
+            assertEquals(memberId, Long.parseLong(audioUri.getPathSegments().get(5)));
             assertEquals(Audio1.EXTERNAL_DATA, c.getString(c.getColumnIndex(Members.DATA)));
             assertTrue(c.getLong(c.getColumnIndex(Members.DATE_ADDED)) > 0);
             assertEquals(Audio1.DATE_MODIFIED, c.getLong(c.getColumnIndex(Members.DATE_MODIFIED)));
diff --git a/tests/tests/renderscript/Android.mk b/tests/tests/renderscript/Android.mk
new file mode 100644
index 0000000..fc64614
--- /dev/null
+++ b/tests/tests/renderscript/Android.mk
@@ -0,0 +1,37 @@
+# Copyright (C) 2011 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# Replace "Example" with your name.
+LOCAL_PACKAGE_NAME := CtsRenderscriptTestCases
+
+# Don't include this package in any target.
+LOCAL_MODULE_TAGS := optional
+
+# When built, explicitly put it in the data partition.
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+# All tests should include android.test.runner.
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_INSTRUMENTATION_FOR := CtsTestStubs
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/tests/tests/renderscript/AndroidManifest.xml b/tests/tests/renderscript/AndroidManifest.xml
new file mode 100644
index 0000000..7205b3c
--- /dev/null
+++ b/tests/tests/renderscript/AndroidManifest.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+
+<!-- Replace all the "example" stuff below with your package name, and
+     remove this comment.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.cts.renderscript">
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <!-- This is a self-instrumenting test package. -->
+    <instrumentation android:name="android.test.InstrumentationTestRunner"
+                     android:targetPackage="com.android.cts.stub"
+                     android:label="CTS tests of Renderscript component"/>
+
+</manifest>
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java b/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
new file mode 100644
index 0000000..0f77369
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/AllocationTest.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.Allocation;
+import android.renderscript.Allocation.MipmapControl;
+import android.renderscript.Element;
+import android.renderscript.Type;
+import android.renderscript.Type.Builder;
+
+public class AllocationTest extends RSBaseGraphics {
+
+    // Test power of two and non power of two, equal and non-equal sizes
+    void createTypedHelper(Element e) {
+
+        Type.Builder typeBuilder = new Type.Builder(mRS, e);
+        for (int mips = 0; mips <= 1; mips ++) {
+            boolean useMips = (mips == 1);
+
+            for (int faces = 0; faces <= 1; faces++) {
+                boolean useFaces = (faces == 1);
+
+                for (int x = 1; x < 8; x ++) {
+                    for (int y = 1; y < 8; y ++) {
+                        typeBuilder.setMipmaps(useMips);
+                        typeBuilder.setFaces(useFaces);
+                        typeBuilder.setX(x).setY(y);
+                        Allocation.createTyped(mRS, typeBuilder.create());
+                    }
+                }
+            }
+        }
+
+    }
+
+    void createTypedTextureHelper(Element e) {
+        // No mips graphics
+        Type.Builder typeBuilder = new Type.Builder(mRS, e);
+        Allocation.createTyped(mRS, typeBuilder.setX(8).create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE);
+        Allocation.createTyped(mRS, typeBuilder.setY(8).create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE);
+        // No mips graphics and script
+        Allocation.createTyped(mRS, typeBuilder.create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE |
+                               Allocation.USAGE_SCRIPT);
+        // With mips
+        Allocation.createTyped(mRS, typeBuilder.create(),
+                               MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE);
+        Allocation.createTyped(mRS, typeBuilder.create(),
+                               MipmapControl.MIPMAP_FULL,
+                               Allocation.USAGE_GRAPHICS_TEXTURE |
+                               Allocation.USAGE_SCRIPT);
+
+        // Only texture npot
+        Allocation.createTyped(mRS, typeBuilder.setX(7).setY(1).create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE);
+        Allocation.createTyped(mRS, typeBuilder.setX(7).setY(3).create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE);
+        Allocation.createTyped(mRS, typeBuilder.setX(7).setY(7).create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE);
+
+        // Script and texture
+        Allocation.createTyped(mRS, typeBuilder.setX(7).setY(1).create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE |
+                               Allocation.USAGE_SCRIPT);
+        Allocation.createTyped(mRS, typeBuilder.setX(7).setY(3).create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE |
+                               Allocation.USAGE_SCRIPT);
+        Allocation.createTyped(mRS, typeBuilder.setX(7).setY(7).create(),
+                               MipmapControl.MIPMAP_NONE,
+                               Allocation.USAGE_GRAPHICS_TEXTURE |
+                               Allocation.USAGE_SCRIPT);
+    }
+
+    void createSizedHelper(Element e) {
+        for (int i = 1; i <= 8; i ++) {
+            Allocation.createSized(mRS, e, i);
+        }
+    }
+
+    public void testCreateTyped() {
+         createTypedHelper(Element.A_8(mRS));
+         createTypedHelper(Element.RGB_565(mRS));
+         createTypedHelper(Element.RGB_888(mRS));
+         createTypedHelper(Element.RGBA_8888(mRS));
+         createTypedHelper(Element.F32(mRS));
+         createTypedHelper(Element.F32_2(mRS));
+         createTypedHelper(Element.F32_3(mRS));
+         createTypedHelper(Element.F32_4(mRS));
+         createTypedHelper(Element.BOOLEAN(mRS));
+         createTypedHelper(Element.F64(mRS));
+         createTypedHelper(Element.I8(mRS));
+         createTypedHelper(Element.I16(mRS));
+         createTypedHelper(Element.I32(mRS));
+         createTypedHelper(Element.I64(mRS));
+         createTypedHelper(Element.U8(mRS));
+         createTypedHelper(Element.U8_4(mRS));
+         createTypedHelper(Element.U16(mRS));
+         createTypedHelper(Element.U32(mRS));
+         createTypedHelper(Element.U64(mRS));
+         createTypedHelper(Element.MATRIX_2X2(mRS));
+         createTypedHelper(Element.MATRIX_3X3(mRS));
+         createTypedHelper(Element.MATRIX_4X4(mRS));
+         createTypedHelper(Element.MESH(mRS));
+         createTypedHelper(Element.PROGRAM_FRAGMENT(mRS));
+         createTypedHelper(Element.PROGRAM_RASTER(mRS));
+         createTypedHelper(Element.PROGRAM_STORE(mRS));
+         createTypedHelper(Element.PROGRAM_VERTEX(mRS));
+         createTypedHelper(Element.ALLOCATION(mRS));
+         createTypedHelper(Element.SAMPLER(mRS));
+         createTypedHelper(Element.SCRIPT(mRS));
+         createTypedHelper(Element.TYPE(mRS));
+
+         createTypedTextureHelper(Element.A_8(mRS));
+         createTypedTextureHelper(Element.RGB_565(mRS));
+         createTypedTextureHelper(Element.RGB_888(mRS));
+         createTypedTextureHelper(Element.RGBA_8888(mRS));
+    }
+
+    public void testCreateSized() {
+         createSizedHelper(Element.A_8(mRS));
+         createSizedHelper(Element.RGB_565(mRS));
+         createSizedHelper(Element.RGB_888(mRS));
+         createSizedHelper(Element.RGBA_8888(mRS));
+         createSizedHelper(Element.F32(mRS));
+         createSizedHelper(Element.F32_2(mRS));
+         createSizedHelper(Element.F32_3(mRS));
+         createSizedHelper(Element.F32_4(mRS));
+         createSizedHelper(Element.BOOLEAN(mRS));
+         createSizedHelper(Element.F64(mRS));
+         createSizedHelper(Element.I8(mRS));
+         createSizedHelper(Element.I16(mRS));
+         createSizedHelper(Element.I32(mRS));
+         createSizedHelper(Element.I64(mRS));
+         createSizedHelper(Element.U8(mRS));
+         createSizedHelper(Element.U8_4(mRS));
+         createSizedHelper(Element.U16(mRS));
+         createSizedHelper(Element.U32(mRS));
+         createSizedHelper(Element.U64(mRS));
+         createSizedHelper(Element.MATRIX_2X2(mRS));
+         createSizedHelper(Element.MATRIX_3X3(mRS));
+         createSizedHelper(Element.MATRIX_4X4(mRS));
+         createSizedHelper(Element.MESH(mRS));
+         createSizedHelper(Element.PROGRAM_FRAGMENT(mRS));
+         createSizedHelper(Element.PROGRAM_RASTER(mRS));
+         createSizedHelper(Element.PROGRAM_STORE(mRS));
+         createSizedHelper(Element.PROGRAM_VERTEX(mRS));
+         createSizedHelper(Element.ALLOCATION(mRS));
+         createSizedHelper(Element.SAMPLER(mRS));
+         createSizedHelper(Element.SCRIPT(mRS));
+         createSizedHelper(Element.TYPE(mRS));
+    }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ComputeTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ComputeTest.java
new file mode 100644
index 0000000..a5c4f16
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ComputeTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.renderscript.RenderScript;
+import android.renderscript.RenderScript.RSMessageHandler;
+import android.test.AndroidTestCase;
+import com.android.cts.stub.R;
+
+public class ComputeTest extends RSBaseCompute {
+
+    private boolean initializeGlobals(ScriptC_primitives s) {
+        float pF = s.get_floatTest();
+        if (pF != 1.99f) {
+            return false;
+        }
+        s.set_floatTest(2.99f);
+
+        double pD = s.get_doubleTest();
+        if (pD != 2.05) {
+            return false;
+        }
+        s.set_doubleTest(3.05);
+
+        byte pC = s.get_charTest();
+        if (pC != -8) {
+            return false;
+        }
+        s.set_charTest((byte)-16);
+
+        short pS = s.get_shortTest();
+        if (pS != -16) {
+            return false;
+        }
+        s.set_shortTest((short)-32);
+
+        int pI = s.get_intTest();
+        if (pI != -32) {
+            return false;
+        }
+        s.set_intTest(-64);
+
+        long pL = s.get_longTest();
+        if (pL != 17179869184l) {
+            return false;
+        }
+        s.set_longTest(17179869185l);
+
+        long puL = s.get_ulongTest();
+        if (puL != 4611686018427387904L) {
+            return false;
+        }
+        s.set_ulongTest(4611686018427387903L);
+
+
+        long pLL = s.get_longlongTest();
+        if (pLL != 68719476736L) {
+            return false;
+        }
+        s.set_longlongTest(68719476735L);
+
+        long pu64 = s.get_uint64_tTest();
+        if (pu64 != 117179869184l) {
+            return false;
+        }
+        s.set_uint64_tTest(117179869185l);
+
+        return true;
+    }
+
+    /**
+     * Test primitive types.
+     */
+    public void testPrimitives() {
+        ScriptC_primitives t = new ScriptC_primitives(mRS,
+                                                      mRes,
+                                                      R.raw.primitives);
+
+        assertTrue(initializeGlobals(t));
+        t.invoke_test();
+        waitForMessage();
+        assertEquals(result, RS_MSG_TEST_PASSED);
+    }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ElementTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ElementTest.java
new file mode 100644
index 0000000..55572a3
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ElementTest.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.Element;
+import android.renderscript.Element.DataType;
+import android.renderscript.Element.DataKind;
+
+public class ElementTest extends RSBaseCompute {
+
+    public void testCreatePixel() {
+        assertTrue(Element.createPixel(mRS,
+                                       DataType.UNSIGNED_8,
+                                       DataKind.PIXEL_A) != null);
+        assertTrue(Element.createPixel(mRS,
+                                       DataType.UNSIGNED_5_6_5,
+                                       DataKind.PIXEL_RGB) != null);
+        assertTrue(Element.createPixel(mRS,
+                                       DataType.UNSIGNED_8,
+                                       DataKind.PIXEL_RGB) != null);
+        assertTrue(Element.createPixel(mRS,
+                                       DataType.UNSIGNED_5_5_5_1,
+                                       DataKind.PIXEL_RGBA) != null);
+        assertTrue(Element.createPixel(mRS,
+                                       DataType.UNSIGNED_4_4_4_4,
+                                       DataKind.PIXEL_RGBA) != null);
+        assertTrue(Element.createPixel(mRS,
+                                       DataType.UNSIGNED_8,
+                                       DataKind.PIXEL_RGBA) != null);
+    }
+
+    public void testCreateVector() {
+
+        Element e = null;
+        for (int len = 2; len <= 4; len ++) {
+            assertTrue(Element.createVector(mRS, DataType.FLOAT_32, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.FLOAT_64, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.SIGNED_8, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.SIGNED_16, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.SIGNED_32, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.SIGNED_64, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.UNSIGNED_8, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.UNSIGNED_16, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.UNSIGNED_32, len) != null);
+            assertTrue(Element.createVector(mRS, DataType.UNSIGNED_64, len) != null);
+        }
+    }
+
+    public void testPrebuiltElements() {
+        assertTrue(Element.A_8(mRS) != null);
+        assertTrue(Element.RGBA_4444(mRS) != null);
+        assertTrue(Element.RGBA_5551(mRS) != null);
+        assertTrue(Element.RGB_565(mRS) != null);
+        assertTrue(Element.RGB_888(mRS) != null);
+        assertTrue(Element.RGBA_8888(mRS) != null);
+        assertTrue(Element.F32(mRS) != null);
+        assertTrue(Element.F32_2(mRS) != null);
+        assertTrue(Element.F32_3(mRS) != null);
+        assertTrue(Element.F32_4(mRS) != null);
+        assertTrue(Element.F64(mRS) != null);
+        assertTrue(Element.I8(mRS) != null);
+        assertTrue(Element.I16(mRS) != null);
+        assertTrue(Element.I32(mRS) != null);
+        assertTrue(Element.I64(mRS) != null);
+        assertTrue(Element.U8(mRS) != null);
+        assertTrue(Element.U8_4(mRS) != null);
+        assertTrue(Element.U16(mRS) != null);
+        assertTrue(Element.U32(mRS) != null);
+        assertTrue(Element.U64(mRS) != null);
+        assertTrue(Element.MATRIX_2X2(mRS) != null);
+        assertTrue(Element.MATRIX_3X3(mRS) != null);
+        assertTrue(Element.MATRIX_4X4(mRS) != null);
+        assertTrue(Element.MESH(mRS) != null);
+        assertTrue(Element.PROGRAM_FRAGMENT(mRS) != null);
+        assertTrue(Element.PROGRAM_RASTER(mRS) != null);
+        assertTrue(Element.PROGRAM_STORE(mRS) != null);
+        assertTrue(Element.PROGRAM_VERTEX(mRS) != null);
+        assertTrue(Element.ALLOCATION(mRS) != null);
+        assertTrue(Element.SAMPLER(mRS) != null);
+        assertTrue(Element.SCRIPT(mRS) != null);
+        assertTrue(Element.TYPE(mRS) != null);
+        assertTrue(Element.BOOLEAN(mRS) != null);
+        assertTrue(Element.ELEMENT(mRS) != null);
+    }
+
+    public void testElementBuilder() {
+        for (int arraySize = 1; arraySize <= 3; arraySize++) {
+            // Now test array size
+            Element.Builder eb = new Element.Builder(mRS);
+            eb.add(Element.A_8(mRS), "A_8", arraySize);
+            eb.add(Element.RGBA_4444(mRS), "RGBA_4444", arraySize);
+            eb.add(Element.RGBA_5551(mRS), "RGBA_5551", arraySize);
+            eb.add(Element.RGB_565(mRS), "RGB_565", arraySize);
+            eb.add(Element.RGB_888(mRS), "RGB_888", arraySize);
+            eb.add(Element.RGBA_8888(mRS), "RGBA_8888", arraySize);
+            eb.add(Element.F32(mRS), "F32", arraySize);
+            eb.add(Element.F32_2(mRS), "F32_2", arraySize);
+            eb.add(Element.F32_3(mRS), "F32_3", arraySize);
+            eb.add(Element.F32_4(mRS), "F32_4", arraySize);
+            eb.add(Element.F64(mRS), "F64", arraySize);
+            eb.add(Element.I8(mRS), "I8", arraySize);
+            eb.add(Element.I16(mRS), "I16", arraySize);
+            eb.add(Element.I32(mRS), "I32", arraySize);
+            eb.add(Element.I64(mRS), "I64", arraySize);
+            eb.add(Element.U8(mRS), "U8", arraySize);
+            eb.add(Element.U8_4(mRS), "U8_4", arraySize);
+            eb.add(Element.U16(mRS), "U16", arraySize);
+            eb.add(Element.U32(mRS), "U32", arraySize);
+            eb.add(Element.U64(mRS), "U64", arraySize);
+            eb.add(Element.MATRIX_2X2(mRS), "MATRIX_2X2", arraySize);
+            eb.add(Element.MATRIX_3X3(mRS), "MATRIX_3X3", arraySize);
+            eb.add(Element.MATRIX_4X4(mRS), "MATRIX_4X4", arraySize);
+            eb.add(Element.MESH(mRS), "MESH", arraySize);
+            eb.add(Element.PROGRAM_FRAGMENT(mRS), "PROGRAM_FRAGMENT", arraySize);
+            eb.add(Element.PROGRAM_RASTER(mRS), "PROGRAM_RASTER", arraySize);
+            eb.add(Element.PROGRAM_STORE(mRS), "PROGRAM_STORE", arraySize);
+            eb.add(Element.PROGRAM_VERTEX(mRS), "PROGRAM_VERTEX", arraySize);
+            eb.add(Element.ALLOCATION(mRS), "ALLOCATION", arraySize);
+            eb.add(Element.SAMPLER(mRS), "SAMPLER", arraySize);
+            eb.add(Element.SCRIPT(mRS), "SCRIPT", arraySize);
+            eb.add(Element.TYPE(mRS), "TYPE", arraySize);
+            eb.add(Element.BOOLEAN(mRS), "BOOLEAN", arraySize);
+            eb.add(Element.ELEMENT(mRS), "ELEMENT", arraySize);
+            assertTrue(eb.create() != null);
+        }
+    }
+
+    public void testIsComplex() {
+        assertFalse(Element.A_8(mRS).isComplex());
+        assertFalse(Element.RGBA_4444(mRS).isComplex());
+        assertFalse(Element.RGBA_5551(mRS).isComplex());
+        assertFalse(Element.RGB_565(mRS).isComplex());
+        assertFalse(Element.RGB_888(mRS).isComplex());
+        assertFalse(Element.RGBA_8888(mRS).isComplex());
+        assertFalse(Element.F32(mRS).isComplex());
+        assertFalse(Element.F32_2(mRS).isComplex());
+        assertFalse(Element.F32_3(mRS).isComplex());
+        assertFalse(Element.F32_4(mRS).isComplex());
+        assertFalse(Element.F64(mRS).isComplex());
+        assertFalse(Element.I8(mRS).isComplex());
+        assertFalse(Element.I16(mRS).isComplex());
+        assertFalse(Element.I32(mRS).isComplex());
+        assertFalse(Element.I64(mRS).isComplex());
+        assertFalse(Element.U8(mRS).isComplex());
+        assertFalse(Element.U8_4(mRS).isComplex());
+        assertFalse(Element.U16(mRS).isComplex());
+        assertFalse(Element.U32(mRS).isComplex());
+        assertFalse(Element.U64(mRS).isComplex());
+        assertFalse(Element.MATRIX_2X2(mRS).isComplex());
+        assertFalse(Element.MATRIX_3X3(mRS).isComplex());
+        assertFalse(Element.MATRIX_4X4(mRS).isComplex());
+        assertFalse(Element.MESH(mRS).isComplex());
+        assertFalse(Element.PROGRAM_FRAGMENT(mRS).isComplex());
+        assertFalse(Element.PROGRAM_RASTER(mRS).isComplex());
+        assertFalse(Element.PROGRAM_STORE(mRS).isComplex());
+        assertFalse(Element.PROGRAM_VERTEX(mRS).isComplex());
+        assertFalse(Element.ALLOCATION(mRS).isComplex());
+        assertFalse(Element.SAMPLER(mRS).isComplex());
+        assertFalse(Element.SCRIPT(mRS).isComplex());
+        assertFalse(Element.TYPE(mRS).isComplex());
+        assertFalse(Element.BOOLEAN(mRS).isComplex());
+        assertFalse(Element.ELEMENT(mRS).isComplex());
+
+        Element.Builder eb = new Element.Builder(mRS);
+        eb.add(Element.F32(mRS), "FLOAT");
+        eb.add(Element.SAMPLER(mRS), "SAMPLER");
+        Element e1 = eb.create();
+        assertFalse(e1.isComplex());
+
+        eb = new Element.Builder(mRS);
+        eb.add(Element.A_8(mRS), "A_8");
+        eb.add(Element.RGBA_4444(mRS), "RGBA_4444");
+        Element e2 = eb.create();
+        assertFalse(e2.isComplex());
+
+        eb = new Element.Builder(mRS);
+        eb.add(e1, "e1");
+        eb.add(e2, "e2");
+        assertTrue(eb.create().isComplex());
+    }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ProgramRasterTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ProgramRasterTest.java
new file mode 100644
index 0000000..bebb8b0
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ProgramRasterTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.ProgramRaster;
+import android.renderscript.ProgramRaster.Builder;
+import android.renderscript.ProgramRaster.CullMode;
+
+public class ProgramRasterTest extends RSBaseGraphics {
+
+    public void testProgramRasterBuilder() {
+        ProgramRaster.Builder b = new ProgramRaster.Builder(mRS);
+        for (int p = 0; p <= 1; p++) {
+            boolean pSprite = (p == 1);
+            b.setPointSpriteEnabled(pSprite);
+            for (CullMode cull : CullMode.values()) {
+                b.setCullMode(cull);
+                b.create();
+            }
+        }
+    }
+
+    public void testPrebuiltProgramRaster() {
+        assertTrue(ProgramRaster.CULL_BACK(mRS) != null);
+        assertTrue(ProgramRaster.CULL_FRONT(mRS) != null);
+    }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/ProgramStoreTest.java b/tests/tests/renderscript/src/android/renderscript/cts/ProgramStoreTest.java
new file mode 100644
index 0000000..54c5672
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/ProgramStoreTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.ProgramStore;
+import android.renderscript.ProgramStore.Builder;
+import android.renderscript.ProgramStore.DepthFunc;
+import android.renderscript.ProgramStore.BlendSrcFunc;
+import android.renderscript.ProgramStore.BlendDstFunc;
+
+public class ProgramStoreTest extends RSBaseGraphics {
+
+    void varyBuilderColorAndDither(ProgramStore.Builder pb) {
+        for (int r = 0; r <= 1; r++) {
+            boolean isR = (r == 1);
+            for (int g = 0; g <= 1; g++) {
+                boolean isG = (g == 1);
+                for (int b = 0; b <= 1; b++) {
+                    boolean isB = (b == 1);
+                    for (int a = 0; a <= 1; a++) {
+                        boolean isA = (a == 1);
+                        for (int dither = 0; dither <= 1; dither++) {
+                            boolean isDither = (dither == 1);
+                            pb.setDepthMaskEnabled(isDither);
+                            pb.setColorMaskEnabled(isR, isG, isB, isA);
+                            pb.create();
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    public void testProgramStoreBuilder() {
+        for (int depth = 0; depth <= 1; depth++) {
+            boolean depthMask = (depth == 1);
+            for (DepthFunc df : DepthFunc.values()) {
+                for (BlendSrcFunc bsf : BlendSrcFunc.values()) {
+                    for (BlendDstFunc bdf : BlendDstFunc.values()) {
+                        ProgramStore.Builder b = new ProgramStore.Builder(mRS);
+                        b.setDepthFunc(df);
+                        b.setDepthMaskEnabled(depthMask);
+                        b.setBlendFunc(bsf, bdf);
+                        varyBuilderColorAndDither(b);
+                    }
+                }
+            }
+        }
+    }
+
+    public void testPrebuiltProgramStore() {
+        assertTrue(ProgramStore.BLEND_ALPHA_DEPTH_NONE(mRS) != null);
+        assertTrue(ProgramStore.BLEND_ALPHA_DEPTH_TEST(mRS) != null);
+        assertTrue(ProgramStore.BLEND_NONE_DEPTH_NONE(mRS) != null);
+        assertTrue(ProgramStore.BLEND_NONE_DEPTH_TEST(mRS) != null);
+    }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSBase.java b/tests/tests/renderscript/src/android/renderscript/cts/RSBase.java
new file mode 100644
index 0000000..10aa8e6
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSBase.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.renderscript.RenderScript.RSMessageHandler;
+import android.test.AndroidTestCase;
+import com.android.cts.stub.R;
+
+/**
+ * Base RenderScript test class. This class provides a message handler and a
+ * convenient way to wait for compute scripts to complete their execution.
+ */
+class RSBase extends AndroidTestCase {
+
+    Context mCtx;
+    Resources mRes;
+
+    public int result;
+    private boolean msgHandled;
+
+    public static final int RS_MSG_TEST_PASSED = 100;
+    public static final int RS_MSG_TEST_FAILED = 101;
+
+    RSMessageHandler mRsMessage = new RSMessageHandler() {
+        public void run() {
+            if (result == 0) {
+                switch (mID) {
+                    case RS_MSG_TEST_PASSED:
+                    case RS_MSG_TEST_FAILED:
+                        result = mID;
+                        break;
+                    default:
+                        fail("Got unexpected RS message");
+                        return;
+                }
+            }
+            msgHandled = true;
+        }
+    };
+
+    protected void waitForMessage() {
+        while (!msgHandled) {
+            Thread.yield();
+        }
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        result = 0;
+        msgHandled = false;
+        mCtx = getContext();
+        mRes = mCtx.getResources();
+    }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java
new file mode 100644
index 0000000..84616ca
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseCompute.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.renderscript.RenderScript;
+import android.renderscript.RenderScript.RSMessageHandler;
+import android.test.AndroidTestCase;
+import com.android.cts.stub.R;
+
+/**
+ * Base RenderScript test class. This class provides a message handler and a
+ * convenient way to wait for compute scripts to complete their execution.
+ */
+class RSBaseCompute extends RSBase {
+    RenderScript mRS;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mRS = RenderScript.create(mCtx);
+        mRS.setMessageHandler(mRsMessage);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (mRS != null) {
+            mRS.destroy();
+            mRS = null;
+        }
+        super.tearDown();
+    }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RSBaseGraphics.java b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseGraphics.java
new file mode 100644
index 0000000..83a2744
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RSBaseGraphics.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.renderscript.RenderScript;
+import android.renderscript.RenderScript.RSMessageHandler;
+import android.renderscript.RenderScriptGL;
+import android.renderscript.RenderScriptGL.SurfaceConfig;
+import android.test.AndroidTestCase;
+import com.android.cts.stub.R;
+
+/**
+ * Base RenderScript test class. This class provides a message handler and a
+ * convenient way to wait for compute scripts to complete their execution.
+ */
+class RSBaseGraphics extends RSBase {
+    RenderScriptGL mRS;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mRS = new RenderScriptGL(mCtx, new SurfaceConfig());
+        mRS.setMessageHandler(mRsMessage);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (mRS != null) {
+            mRS.destroy();
+            mRS = null;
+        }
+        super.tearDown();
+    }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/RenderScriptTest.java b/tests/tests/renderscript/src/android/renderscript/cts/RenderScriptTest.java
new file mode 100644
index 0000000..e2d7968
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/RenderScriptTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.RenderScript;
+import android.test.AndroidTestCase;
+
+public class RenderScriptTest extends AndroidTestCase {
+
+    /**
+     * Simple test for Renderscript that executes a passthrough function
+     * from cts/tests/src/android/renderscript/cts/passthrough.rs.
+     */
+    public void testRenderScript() {
+        RenderScript mRS = RenderScript.create(getContext());
+        ScriptC_passthrough t = new ScriptC_passthrough(mRS,
+            getContext().getResources(), R.raw.passthrough);
+        t.invoke_passthrough(5);
+        mRS.destroy();
+    }
+
+    /**
+     * Excercise all API calls in the basic RenderScript class.
+     */
+    public void testAPI() {
+        try {
+            RenderScript mRS = RenderScript.create(null);
+            fail("should throw NullPointerException.");
+        } catch (NullPointerException e) {
+        }
+
+        RenderScript mRS = RenderScript.create(getContext());
+        mRS.contextDump();
+        mRS.finish();
+        assertEquals(mRS.getApplicationContext(),
+                     getContext().getApplicationContext());
+        RenderScript.RSErrorHandler mEH = mRS.getErrorHandler();
+        RenderScript.RSMessageHandler mMH = mRS.getMessageHandler();
+        mRS.setErrorHandler(mEH);
+        mRS.setMessageHandler(mMH);
+        mRS.setPriority(RenderScript.Priority.LOW);
+        mRS.setPriority(RenderScript.Priority.NORMAL);
+        mRS.destroy();
+    }
+
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/SamplerTest.java b/tests/tests/renderscript/src/android/renderscript/cts/SamplerTest.java
new file mode 100644
index 0000000..7f2b052
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/SamplerTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.Sampler;
+import android.renderscript.Sampler.Builder;
+import android.renderscript.Sampler.Value;
+
+public class SamplerTest extends RSBaseGraphics {
+
+    Sampler.Value[] mMinValues;
+    Sampler.Value[] mMagValues;
+    Sampler.Value[] mWrapValues;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        mMinValues = new Sampler.Value[4];
+        mMinValues[0] = Sampler.Value.NEAREST;
+        mMinValues[1] = Sampler.Value.LINEAR;
+        mMinValues[2] = Sampler.Value.LINEAR_MIP_LINEAR;
+        mMinValues[3] = Sampler.Value.LINEAR_MIP_NEAREST;
+
+        mMagValues = new Sampler.Value[2];
+        mMagValues[0] = Sampler.Value.NEAREST;
+        mMagValues[1] = Sampler.Value.LINEAR;
+
+        mWrapValues = new Sampler.Value[2];
+        mWrapValues[0] = Sampler.Value.CLAMP;
+        mWrapValues[1] = Sampler.Value.WRAP;
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mMinValues = null;
+        mMagValues = null;
+        mWrapValues = null;
+        super.tearDown();
+    }
+
+    boolean contains(Sampler.Value[] array, Sampler.Value val) {
+        for (int i = 0; i < array.length; i ++) {
+            if (array[i] == val) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public void testSamplerBuilder() {
+        for (int aniso = 1; aniso <= 4; aniso++) {
+            for (Sampler.Value minV : Sampler.Value.values()) {
+                for (Sampler.Value magV : Sampler.Value.values()) {
+                    for (Sampler.Value wrapSV : Sampler.Value.values()) {
+                        for (Sampler.Value wrapTV : Sampler.Value.values()) {
+                            Sampler.Builder b = new Sampler.Builder(mRS);
+                            b.setAnisotropy(aniso);
+
+                            // Some value combinations are illegal
+                            boolean validMin = contains(mMinValues, minV);
+                            boolean validMag = contains(mMagValues, magV);
+                            boolean validS = contains(mWrapValues, wrapSV);
+                            boolean validT = contains(mWrapValues, wrapTV);
+
+                            try {
+                                b.setMinification(minV);
+                            } catch (IllegalArgumentException e) {
+                                assertFalse(validMin);
+                            }
+                            try {
+                                b.setMagnification(magV);
+                            } catch (IllegalArgumentException e) {
+                                assertFalse(validMag);
+                            }
+                            try {
+                                b.setWrapS(wrapSV);
+                            } catch (IllegalArgumentException e) {
+                                assertFalse(validS);
+                            }
+                            try {
+                                b.setWrapT(wrapTV);
+                            } catch (IllegalArgumentException e) {
+                                assertFalse(validT);
+                            }
+
+                            if (validMin && validMag && validS && validT) {
+                                b.create();
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+    public void testPrebuiltSamplers() {
+        assertTrue(Sampler.CLAMP_LINEAR(mRS) != null);
+        assertTrue(Sampler.CLAMP_LINEAR_MIP_LINEAR(mRS) != null);
+        assertTrue(Sampler.CLAMP_NEAREST(mRS) != null);
+        assertTrue(Sampler.WRAP_LINEAR(mRS) != null);
+        assertTrue(Sampler.WRAP_LINEAR_MIP_LINEAR(mRS) != null);
+        assertTrue(Sampler.WRAP_NEAREST(mRS) != null);
+    }
+}
+
+
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/TypeTest.java b/tests/tests/renderscript/src/android/renderscript/cts/TypeTest.java
new file mode 100644
index 0000000..82c7a79
--- /dev/null
+++ b/tests/tests/renderscript/src/android/renderscript/cts/TypeTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2011 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.renderscript.cts;
+
+import com.android.cts.stub.R;
+
+import android.renderscript.Element;
+import android.renderscript.Element.DataType;
+import android.renderscript.Element.DataKind;
+import android.renderscript.Type;
+import android.renderscript.Type.Builder;
+
+public class TypeTest extends RSBaseCompute {
+
+    void testBuilderSizes(Type.Builder b, int min, int max) {
+        for (int x = min; x < max; x ++) {
+            for (int y = min; y < max; y ++) {
+                b.setX(x).setY(y);
+                b.create();
+            }
+        }
+    }
+
+    void testTypeBuilderHelper(Element e) {
+        Type.Builder b = new Type.Builder(mRS, e);
+        for (int mips = 0; mips <= 1; mips ++) {
+            boolean useMips = (mips == 1);
+
+            for (int faces = 0; faces <= 1; faces++) {
+                boolean useFaces = (faces == 1);
+
+                b.setMipmaps(useMips);
+                b.setFaces(useFaces);
+                testBuilderSizes(b, 1, 8);
+            }
+        }
+    }
+
+    public void testTypeBuilder() {
+        testTypeBuilderHelper(Element.A_8(mRS));
+        testTypeBuilderHelper(Element.RGB_565(mRS));
+        testTypeBuilderHelper(Element.RGB_888(mRS));
+        testTypeBuilderHelper(Element.RGBA_8888(mRS));
+        testTypeBuilderHelper(Element.F32(mRS));
+        testTypeBuilderHelper(Element.F32_2(mRS));
+        testTypeBuilderHelper(Element.F32_3(mRS));
+        testTypeBuilderHelper(Element.F32_4(mRS));
+        testTypeBuilderHelper(Element.BOOLEAN(mRS));
+        testTypeBuilderHelper(Element.F64(mRS));
+        testTypeBuilderHelper(Element.I8(mRS));
+        testTypeBuilderHelper(Element.I16(mRS));
+        testTypeBuilderHelper(Element.I32(mRS));
+        testTypeBuilderHelper(Element.I64(mRS));
+        testTypeBuilderHelper(Element.U8(mRS));
+        testTypeBuilderHelper(Element.U8_4(mRS));
+        testTypeBuilderHelper(Element.U16(mRS));
+        testTypeBuilderHelper(Element.U32(mRS));
+        testTypeBuilderHelper(Element.U64(mRS));
+        testTypeBuilderHelper(Element.MATRIX_2X2(mRS));
+        testTypeBuilderHelper(Element.MATRIX_3X3(mRS));
+        testTypeBuilderHelper(Element.MATRIX_4X4(mRS));
+        testTypeBuilderHelper(Element.MESH(mRS));
+        testTypeBuilderHelper(Element.PROGRAM_FRAGMENT(mRS));
+        testTypeBuilderHelper(Element.PROGRAM_RASTER(mRS));
+        testTypeBuilderHelper(Element.PROGRAM_STORE(mRS));
+        testTypeBuilderHelper(Element.PROGRAM_VERTEX(mRS));
+        testTypeBuilderHelper(Element.ALLOCATION(mRS));
+        testTypeBuilderHelper(Element.SAMPLER(mRS));
+        testTypeBuilderHelper(Element.SCRIPT(mRS));
+        testTypeBuilderHelper(Element.TYPE(mRS));
+
+        // Add some complex and struct types to test here
+    }
+
+    public void testGetCount() {
+        Type.Builder b = new Type.Builder(mRS, Element.F32(mRS));
+        for (int faces = 0; faces <= 1; faces++) {
+            boolean useFaces = faces == 1;
+            int faceMultiplier = useFaces ? 6 : 1;
+            for (int x = 1; x < 8; x ++) {
+                for (int y = 1; y < 8; y ++) {
+                    b.setFaces(useFaces);
+                    b.setX(x).setY(y);
+                    Type t = b.create();
+                    assertTrue(t.getCount() == x * y * faceMultiplier);
+                }
+            }
+        }
+
+        // Test mipmaps
+        b.setFaces(false);
+        b.setMipmaps(true);
+        Type t = b.setX(8).setY(1).create();
+        int expectedCount = 8 + 4 + 2 + 1;
+        assertTrue(t.getCount() == expectedCount);
+
+        t = b.setX(8).setY(8).create();
+        expectedCount = 8*8 + 4*4 + 2*2 + 1;
+        assertTrue(t.getCount() == expectedCount);
+
+        t = b.setX(8).setY(4).create();
+        expectedCount = 8*4 + 4*2 + 2*1 + 1;
+        assertTrue(t.getCount() == expectedCount);
+
+        t = b.setX(4).setY(8).create();
+        assertTrue(t.getCount() == expectedCount);
+
+        t = b.setX(7).setY(1).create();
+        expectedCount = 7 + 3 + 1;
+        assertTrue(t.getCount() == expectedCount);
+
+        t = b.setX(7).setY(3).create();
+        expectedCount = 7*3 + 3*1 + 1;
+        assertTrue(t.getCount() == expectedCount);
+    }
+}
+
+
diff --git a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
index 37b337f..f24117e 100644
--- a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
@@ -32,6 +32,7 @@
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
+import java.util.TimeZone;
 
 @TestTargetClass(DateFormat.class)
 public class DateFormatTest extends AndroidTestCase {
@@ -174,4 +175,29 @@
         actual = DateFormat.format(format, formatDate.getTime());
         assertEquals(expectedString, actual.toString());
     }
+
+    @TestTargetNew(level = TestLevel.ADDITIONAL)
+    public void test2038() {
+        Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
+
+        calendar.setTimeInMillis(((long) Integer.MIN_VALUE + Integer.MIN_VALUE) * 1000L);
+        assertEquals("Sun Nov 24 17:31:44 GMT+00:00 1833",
+                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+
+        calendar.setTimeInMillis(Integer.MIN_VALUE * 1000L);
+        assertEquals("Fri Dec 13 20:45:52 GMT+00:00 1901",
+                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+
+        calendar.setTimeInMillis(0L);
+        assertEquals("Thu Jan 01 00:00:00 GMT+00:00 1970",
+                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+
+        calendar.setTimeInMillis(Integer.MAX_VALUE * 1000L);
+        assertEquals("Tue Jan 19 03:14:07 GMT+00:00 2038",
+                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+
+        calendar.setTimeInMillis((2L + Integer.MAX_VALUE + Integer.MAX_VALUE) * 1000L);
+        assertEquals("Sun Feb 07 06:28:16 GMT+00:00 2106",
+                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+    }
 }
diff --git a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
index 6d034b9..9e773cb 100644
--- a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
@@ -16,17 +16,17 @@
 
 package android.text.format.cts;
 
+import android.content.Context;
+import android.test.AndroidTestCase;
+import android.text.format.DateUtils;
+import dalvik.annotation.KnownFailure;
 import dalvik.annotation.TestLevel;
 import dalvik.annotation.TestTargetClass;
 import dalvik.annotation.TestTargetNew;
 import dalvik.annotation.TestTargets;
-
-import android.content.Context;
-import android.test.AndroidTestCase;
-import android.text.format.DateUtils;
-
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Formatter;
 import java.util.Locale;
 
 @TestTargetClass(DateUtils.class)
@@ -302,4 +302,32 @@
         assertTrue(DateUtils.isToday(mBaseTime));
         assertFalse(DateUtils.isToday(mBaseTime - DAY_DURATION));
     }
+
+    /**
+     * DateUtils is broken beyond Integer.MAX_VALUE seconds of 1970.
+     * http://code.google.com/p/android/issues/detail?id=13050
+     */
+    @TestTargetNew(level = TestLevel.ADDITIONAL)
+    @KnownFailure("http://b/2519073")
+    public void test2038() {
+        assertEquals("00:00, Thursday, January 1, 1970", formatFull(0L));
+
+        // these tests all fail in Honeycomb
+        assertEquals("17:31, Sunday, November 24, 1833",
+                formatFull(((long) Integer.MIN_VALUE + Integer.MIN_VALUE) * 1000L));
+        assertEquals("20:45, Friday, December 13, 1901", formatFull(Integer.MIN_VALUE * 1000L));
+        assertEquals("03:14, Tuesday, January 19, 2038", formatFull(Integer.MAX_VALUE * 1000L));
+        assertEquals("06:28, Sunday, February 7, 2106",
+                formatFull((2L + Integer.MAX_VALUE + Integer.MAX_VALUE) * 1000L));
+    }
+
+    private String formatFull(long millis) {
+        Formatter formatter = new Formatter();
+        int flags = DateUtils.FORMAT_SHOW_DATE
+                | DateUtils.FORMAT_SHOW_WEEKDAY
+                | DateUtils.FORMAT_SHOW_TIME
+                | DateUtils.FORMAT_24HOUR;
+        DateUtils.formatDateRange(null, formatter, millis, millis, flags, "UTC");
+        return formatter.toString();
+    }
 }
diff --git a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
index b751b32..6dde08d 100755
--- a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
@@ -147,8 +147,7 @@
 
         mMethod.reset();
         // 12-key support
-        KeyCharacterMap keymap
-                = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+        KeyCharacterMap keymap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
         if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
             // "HELLO" in case of 12-key(NUMERIC) keyboard
             sendKeys("6*4 6*3 7*5 DPAD_RIGHT 7*5 7*6 DPAD_RIGHT");
diff --git a/tests/tests/view/src/android/view/cts/WindowTest.java b/tests/tests/view/src/android/view/cts/WindowTest.java
index f7cdbac..4b9e282 100755
--- a/tests/tests/view/src/android/view/cts/WindowTest.java
+++ b/tests/tests/view/src/android/view/cts/WindowTest.java
@@ -1122,6 +1122,10 @@
             return true;
         }
 
+        public boolean superDispatchGenericMotionEvent(MotionEvent event) {
+            return true;
+        }
+
         public View getDecorView() {
             return null;
         }
@@ -1200,6 +1204,10 @@
             return true;
         }
 
+        public boolean dispatchGenericMotionEvent(MotionEvent event) {
+            return true;
+        }
+
         public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
             return true;
         }
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java b/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
index 72a113b..830e91f 100755
--- a/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
@@ -349,8 +349,7 @@
         });
 
         // 12-key support
-        KeyCharacterMap keymap
-                = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+        KeyCharacterMap keymap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
         if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
             // 'Q' in case of 12-key(NUMERIC) keyboard
             mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_7));
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
index ef4d0dc..3b7d340 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
@@ -62,6 +62,7 @@
         assertSame(csm1, csm2);
 
         final CookieManager cookieManager = CookieManager.getInstance();
+        cookieManager.setAcceptFileSchemeCookies(true);
 
         // Remove all cookies from the database.
         cookieManager.removeAllCookie();
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
index 6427808..c526a1f 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
@@ -244,7 +244,6 @@
             args = {boolean.class}
         )
     })
-    @ToBeFixed(explanation = "Implementation does not work as expected.")
     public void testAccessBlockNetworkImage() throws Exception {
         String url = TestHtmlConstants.EMBEDDED_IMG_URL;
         final String ext = MimeTypeMap.getFileExtensionFromUrl(url);
@@ -260,13 +259,11 @@
             }
         }.run();
 
-        /* ToBeFixed: Uncomment after fixing the framework
         mWebView.clearCache(true);
         mSettings.setBlockNetworkImage(true);
         assertTrue(mSettings.getBlockNetworkImage());
-        loadUrl(url);
+        loadAssetUrl(url);
         assertTrue(mWebServer.getLastRequestUrl().endsWith(ext));
-        */
     }
 
     @TestTargets({
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index b1398ec..608a85f 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -38,6 +38,7 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
+import android.os.SystemClock;
 import android.test.ActivityInstrumentationTestCase2;
 import android.test.UiThreadTest;
 import android.util.AttributeSet;
@@ -1397,8 +1398,9 @@
         handler.reset();
         int[] location = new int[2];
         mWebView.getLocationOnScreen(location);
+        long time = SystemClock.uptimeMillis();
         getInstrumentation().sendPointerSync(
-                MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN,
+                MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN,
                         location[0] + imgWidth / 2,
                         location[1] + imgHeight / 2, 0));
         mWebView.requestImageRef(msg);
diff --git a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
index 0f17552..76bf39b 100755
--- a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
@@ -97,8 +97,7 @@
                 .findViewById(R.id.autocompletetv_edit);
         mAdapter = new ArrayAdapter<String>(mActivity,
                 android.R.layout.simple_dropdown_item_1line, WORDS);
-        KeyCharacterMap keymap
-                = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
+        KeyCharacterMap keymap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
         if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
             mNumeric = true;
         }
@@ -513,6 +512,7 @@
         } else {
             testString = "tes";
         }
+
         // Test the filter if the input string is not long enough to threshold
         runTestOnUiThread(new Runnable() {
             public void run() {
diff --git a/tools/dx-tests/Android.mk b/tools/dx-tests/Android.mk
index 9bdef58..d249cea 100644
--- a/tools/dx-tests/Android.mk
+++ b/tools/dx-tests/Android.mk
@@ -38,7 +38,7 @@
 	@echo "Copy: $(PRIVATE_MODULE) ($@)"
 	$(copy-file-to-new-target)
 	$(hide) chmod 755 $@
-	@$(PRIVATE_CURRENT_MODULE_SCRIPT) "$(PRIVATE_BASE)" "$(HOST_JAVAC)" "$(PRIVATE_INTERMEDIATES)" "$(HOST_OUT_JAVA_LIBRARIES)/dx.jar:$(HOST_OUT_JAVA_LIBRARIES)/cfassembler.jar" "$(HOST_OUT)"
+	$(hide) PATH=$(HOST_OUT_EXECUTABLES):$$PATH $(PRIVATE_CURRENT_MODULE_SCRIPT) "$(PRIVATE_BASE)" "$(HOST_JAVAC)" "$(PRIVATE_INTERMEDIATES)" "$(HOST_OUT_JAVA_LIBRARIES)/dx.jar:$(HOST_OUT_JAVA_LIBRARIES)/cfassembler.jar" "$(HOST_OUT)"
 
 # cfassembler host module
 #============================================================
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
index 6bcab73..1c90d83 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
@@ -25,6 +25,7 @@
 import com.android.tradefed.build.IFolderBuildInfo;
 import com.android.tradefed.config.Option;
 import com.android.tradefed.result.CollectingTestListener;
+import com.android.tradefed.result.InputStreamSource;
 import com.android.tradefed.result.LogDataType;
 import com.android.tradefed.result.TestResult;
 import com.android.tradefed.result.TestRunResult;
@@ -116,7 +117,7 @@
      * {@inheritDoc}
      */
     @Override
-    public void testLog(String dataName, LogDataType dataType, InputStream dataStream) {
+    public void testLog(String dataName, LogDataType dataType, InputStreamSource dataStream) {
         // save as zip file in report dir
         // TODO: ensure uniqueness of file name
         // TODO: use dataType.getFileExt() when its made public
@@ -124,7 +125,7 @@
         // TODO: consider compressing large files
         File logFile = new File(mReportDir, fileName);
         try {
-            FileUtil.writeToFile(dataStream, logFile);
+            FileUtil.writeToFile(dataStream.createInputStream(), logFile);
         } catch (IOException e) {
             Log.e(LOG_TAG, String.format("Failed to write log %s", logFile.getAbsolutePath()));
         }
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
index 6ed55d3..2834793 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
@@ -32,6 +32,7 @@
 import com.android.tradefed.testtype.IRemoteTest;
 import com.android.tradefed.testtype.IResumableTest;
 import com.android.tradefed.testtype.IShardableTest;
+import com.android.tradefed.testtype.InstrumentationTest;
 import com.android.tradefed.util.xml.AbstractXmlParser.ParseException;
 
 import java.io.BufferedInputStream;
@@ -248,6 +249,12 @@
             if (test instanceof IDeviceTest) {
                 ((IDeviceTest)test).setDevice(getDevice());
             }
+            // Increment the timeout for collecting the tests.
+            // TODO: move this to testPackage.createTest() instead and only increase timeout when
+            // tests number is large.
+            if (test instanceof InstrumentationTest) {
+                ((InstrumentationTest)test).setCollectsTestsShellTimeout(10*60*1000);
+            }
             ResultFilter filter = new ResultFilter(listener, testPair.getKnownTests());
             test.run(filter);
             mRemainingTests.remove(0);