DO NOT MERGE ICS MR1 Backport of Some Tests

Some tests for monkey, preferences, contacts, and action bar
were added since the last CTS release.

Change-Id: Ia54895c02d3ced61aa1fc54e8447f20f91381df0
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 1c60a45..b4dc4dd 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -22,7 +22,9 @@
 	CtsSimpleAppInstall \
 	CtsSimpleAppInstallDiffCert \
 	CtsTargetInstrumentationApp \
-	CtsUsePermissionDiffCert
+	CtsUsePermissionDiffCert \
+	CtsMonkeyApp \
+	CtsMonkeyApp2 \
 
 # These test cases will be analyzed by the CTS API coverage tools. 
 CTS_COVERAGE_TEST_CASE_LIST := \
@@ -58,6 +60,7 @@
 	CtsPermissionTestCases \
 	CtsPermission2TestCases \
 	CtsPreferenceTestCases \
+	CtsPreference2TestCases \
 	CtsProviderTestCases \
 	CtsRenderscriptTestCases \
 	CtsSaxTestCases \
diff --git a/development/ide/eclipse/.classpath b/development/ide/eclipse/.classpath
index 706a601..314dd50 100644
--- a/development/ide/eclipse/.classpath
+++ b/development/ide/eclipse/.classpath
@@ -4,6 +4,10 @@
     <classpathentry kind="lib" path="prebuilt/common/tradefed/tradefed-prebuilt.jar"/>
     <classpathentry kind="src" path="cts/apps/CtsVerifier/src"/>
     <classpathentry kind="src" path="cts/apps/CtsVerifier/tests/src"/>
+    <classpathentry kind="src" path="cts/tests/appsecurity/src"/>
+    <classpathentry kind="src" path="cts/tests/appsecurity/test-apps/AppWithData/src"/>
+    <classpathentry kind="src" path="cts/tests/appsecurity/test-apps/CtsMonkeyApp/src"/>
+    <classpathentry kind="src" path="cts/tests/appsecurity/test-apps/CtsMonkeyApp2/src"/>
     <classpathentry kind="src" path="cts/libs/vogar-expect/src"/>
     <classpathentry kind="src" path="cts/tests/ApiDemosReferenceTest/src"/>
     <classpathentry kind="src" path="cts/tests/ProcessTest/src"/>
@@ -13,8 +17,6 @@
     <classpathentry kind="src" path="cts/tests/SignatureTest/tests/src"/>
     <classpathentry kind="src" path="cts/tests/acceleration/src"/>
     <classpathentry kind="src" path="cts/tests/accessibilityservice/src"/>
-    <classpathentry kind="src" path="cts/tests/appsecurity-tests/src"/>
-    <classpathentry kind="src" path="cts/tests/appsecurity-tests/test-apps/AppWithData/src"/>
     <classpathentry kind="src" path="cts/tests/core/runner/src"/>
     <classpathentry kind="src" path="cts/tests/deviceadmin/src"/>
     <classpathentry kind="src" path="cts/tests/src"/>
@@ -38,7 +40,9 @@
     <classpathentry kind="src" path="cts/tests/tests/jni/src"/>
     <classpathentry kind="src" path="cts/tests/tests/location/src"/>
     <classpathentry kind="src" path="cts/tests/tests/media/src"/>
+    <classpathentry kind="src" path="cts/tests/tests/mediastress/src"/>
     <classpathentry kind="src" path="cts/tests/tests/net/src"/>
+    <classpathentry kind="src" path="cts/tests/tests/openglperf/src"/>
     <classpathentry kind="src" path="cts/tests/tests/os/src"/>
     <classpathentry kind="src" path="cts/tests/tests/performance/src"/>
     <classpathentry kind="src" path="cts/tests/tests/performance2/src"/>
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 22ba384..22905e9 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -116,6 +116,8 @@
     <application android:label="Android TestCase"
                 android:icon="@drawable/size_48x48" android:name="android.app.cts.MockApplication">
 
+        <activity android:name="android.app.cts.ActionBarActivity" />
+
         <activity android:name="android.media.cts.AudioManagerStub"
             android:label="AudioManagerStub"/>
         <activity android:name="android.media.cts.AudioManagerStubHelper"
diff --git a/tests/appsecurity-tests/src/com/android/cts/monkey/AbstractMonkeyTest.java b/tests/appsecurity-tests/src/com/android/cts/monkey/AbstractMonkeyTest.java
new file mode 100644
index 0000000..0bc2c10
--- /dev/null
+++ b/tests/appsecurity-tests/src/com/android/cts/monkey/AbstractMonkeyTest.java
@@ -0,0 +1,47 @@
+package com.android.cts.monkey;
+
+import com.android.cts.tradefed.build.CtsBuildHelper;
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.testtype.DeviceTestCase;
+import com.android.tradefed.testtype.IBuildReceiver;
+
+import java.io.File;
+
+abstract class AbstractMonkeyTest extends DeviceTestCase implements IBuildReceiver {
+
+    static final String[] PKGS = {"com.android.cts.monkey", "com.android.cts.monkey2"};
+    static final String[] APKS = {"CtsMonkeyApp.apk", "CtsMonkeyApp2.apk"};
+
+    CtsBuildHelper mBuild;
+    ITestDevice mDevice;
+
+    @Override
+    public void setBuild(IBuildInfo buildInfo) {
+        mBuild = CtsBuildHelper.createBuildHelper(buildInfo);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mDevice = getDevice();
+        for (int i = 0; i < PKGS.length; i++) {
+            mDevice.uninstallPackage(PKGS[i]);
+            File app = mBuild.getTestApp(APKS[i]);
+            mDevice.installPackage(app, false);
+        }
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        for (int i = 0; i < PKGS.length; i++) {
+            mDevice.uninstallPackage(PKGS[i]);
+        }
+    }
+
+    void clearLogCat() throws DeviceNotAvailableException {
+        mDevice.executeAdbCommand("logcat", "-c");
+    }
+}
diff --git a/tests/appsecurity-tests/src/com/android/cts/monkey/CategoryTest.java b/tests/appsecurity-tests/src/com/android/cts/monkey/CategoryTest.java
new file mode 100644
index 0000000..3932653
--- /dev/null
+++ b/tests/appsecurity-tests/src/com/android/cts/monkey/CategoryTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.monkey;
+
+public class CategoryTest extends AbstractMonkeyTest {
+
+    public void testDefaultCategories() throws Exception {
+        String out = mDevice.executeShellCommand("monkey -v -p " + PKGS[0] + " 5000");
+        assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+        assertTrue(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+    }
+
+    public void testSingleCategory() throws Exception {
+        String out = mDevice.executeShellCommand("monkey -v -p " + PKGS[0]
+                + " -c android.intent.category.LAUNCHER 5000");
+        assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+        assertFalse(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+
+        out = mDevice.executeShellCommand("monkey -v -p " + PKGS[0]
+                + " -c android.intent.category.MONKEY 5000");
+        assertFalse(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+        assertTrue(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+    }
+
+    public void testMultipleCategories() throws Exception {
+        String out = mDevice.executeShellCommand("monkey -v -p " + PKGS[0]
+                + " -c android.intent.category.LAUNCHER"
+                + " -c android.intent.category.MONKEY 5000");
+        assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+        assertTrue(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+    }
+}
diff --git a/tests/appsecurity-tests/src/com/android/cts/monkey/MonkeyTest.java b/tests/appsecurity-tests/src/com/android/cts/monkey/MonkeyTest.java
new file mode 100644
index 0000000..2bf27ed
--- /dev/null
+++ b/tests/appsecurity-tests/src/com/android/cts/monkey/MonkeyTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.monkey;
+
+import com.android.tradefed.device.DeviceNotAvailableException;
+
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class MonkeyTest extends AbstractMonkeyTest {
+
+    private static final Pattern LOG_PATTERN =
+            Pattern.compile("I/MonkeyActivity\\([\\d ]+\\): (.*)");
+    private static final String MONKEY = "@(>.<)@";
+    private static final String HUMAN = "(^_^)";
+
+    public void testIsMonkey() throws Exception {
+        clearLogCat();
+        mDevice.executeShellCommand("monkey -p " + PKGS[0] + " 500");
+        assertIsUserAMonkey(true);
+    }
+
+    public void testNotMonkey() throws Exception {
+        clearLogCat();
+        mDevice.executeShellCommand("am start -W -a android.intent.action.MAIN "
+                + "-n com.android.cts.monkey/com.android.cts.monkey.MonkeyActivity");
+        assertIsUserAMonkey(false);
+    }
+
+    private void assertIsUserAMonkey(boolean isMonkey) throws DeviceNotAvailableException {
+        String logs = mDevice.executeAdbCommand("logcat", "-d", "MonkeyActivity:I", "*:S");
+        boolean monkeyLogsFound = false;
+        Scanner s = new Scanner(logs);
+        try {
+            while (s.hasNextLine()) {
+                String line = s.nextLine();
+                Matcher m = LOG_PATTERN.matcher(line);
+                if (m.matches()) {
+                    monkeyLogsFound = true;
+                    assertEquals(isMonkey ? MONKEY : HUMAN, m.group(1));
+                }
+            }
+            assertTrue(monkeyLogsFound);
+        } finally {
+            s.close();
+        }
+    }
+}
diff --git a/tests/appsecurity-tests/src/com/android/cts/monkey/PackageTest.java b/tests/appsecurity-tests/src/com/android/cts/monkey/PackageTest.java
new file mode 100644
index 0000000..aa6106b
--- /dev/null
+++ b/tests/appsecurity-tests/src/com/android/cts/monkey/PackageTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.monkey;
+
+public class PackageTest extends AbstractMonkeyTest {
+
+    public void testSinglePackage() throws Exception {
+        String out = mDevice.executeShellCommand("monkey -v -p " + PKGS[0] + " 5000");
+        assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+        assertFalse(out.contains("cmp=com.android.cts.monkey2/.ChimpActivity"));
+
+        out = mDevice.executeShellCommand("monkey -v -p " + PKGS[1] + " 5000");
+        assertFalse(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+        assertTrue(out.contains("cmp=com.android.cts.monkey2/.ChimpActivity"));
+    }
+
+    public void testMultiplePackages() throws Exception {
+        String out = mDevice.executeShellCommand("monkey -v -p " + PKGS[0]
+                + " -p " + PKGS[1] + " 5000");
+        assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+        assertTrue(out.contains("cmp=com.android.cts.monkey2/.ChimpActivity"));
+    }
+}
diff --git a/tests/appsecurity-tests/src/com/android/cts/monkey/SeedTest.java b/tests/appsecurity-tests/src/com/android/cts/monkey/SeedTest.java
new file mode 100644
index 0000000..062fb7d
--- /dev/null
+++ b/tests/appsecurity-tests/src/com/android/cts/monkey/SeedTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.monkey;
+
+import java.util.Scanner;
+
+public class SeedTest extends AbstractMonkeyTest {
+
+    public void testSeed() throws Exception {
+        String cmd1 = "monkey -s 1337 -v -p " + PKGS[0] + " 500";
+        String out1 = mDevice.executeShellCommand(cmd1);
+        String out2 = mDevice.executeShellCommand(cmd1);
+        assertOutputs(out1, out2);
+
+        String cmd2 = "monkey -s 3007 -v -p " + PKGS[0] + " 125";
+        String out3 = mDevice.executeShellCommand(cmd2);
+        String out4 = mDevice.executeShellCommand(cmd2);
+        assertOutputs(out3, out4);
+    }
+
+    private void assertOutputs(String out1, String out2) {
+        Scanner s1 = new Scanner(out1);
+        Scanner s2 = new Scanner(out2);
+        while (s1.hasNextLine()) {
+            assertTrue(s2.hasNextLine());
+
+            String line1 = s1.nextLine().trim();
+            String line2 = s2.nextLine().trim();
+
+            if (line1.startsWith("//[calendar_time") || line1.startsWith("## Network stats")) {
+                // Skip these lines since they have timestamps.
+                continue;
+            }
+
+            assertEquals(line1, line2);
+        }
+        assertFalse(s2.hasNextLine());
+    }
+}
diff --git a/tests/appsecurity-tests/src/com/android/cts/monkey/VerbosityTest.java b/tests/appsecurity-tests/src/com/android/cts/monkey/VerbosityTest.java
new file mode 100644
index 0000000..2956191
--- /dev/null
+++ b/tests/appsecurity-tests/src/com/android/cts/monkey/VerbosityTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.monkey;
+
+public class VerbosityTest extends AbstractMonkeyTest {
+
+    public void testVerbosity() throws Exception {
+        String v0 = mDevice.executeShellCommand("monkey -s 1337 -p " + PKGS[0] + " 500");
+        assertTrue(v0.contains("Events injected"));
+        assertFalse(v0.contains("Sending Touch"));
+        assertFalse(v0.contains("Sending Trackball"));
+        assertFalse(v0.contains("Switch"));
+        assertFalse(v0.contains("Sleeping"));
+
+        String v1 = mDevice.executeShellCommand("monkey -v -p " + PKGS[0] + " 500");
+        assertTrue(v1.contains("Events injected"));
+        assertTrue(v1.contains("Sending Touch"));
+        assertTrue(v1.contains("Sending Trackball"));
+        assertTrue(v1.contains("Switch"));
+        assertFalse(v1.contains("Sleeping"));
+
+        String v2 = mDevice.executeShellCommand("monkey -v -v -p " + PKGS[0] + " 500");
+        assertTrue(v2.contains("Events injected"));
+        assertTrue(v2.contains("Sending Touch"));
+        assertTrue(v2.contains("Sending Trackball"));
+        assertTrue(v2.contains("Switch"));
+        assertTrue(v2.contains("Sleeping"));
+
+        assertTrue(v0.length() < v1.length());
+        assertTrue(v1.length() < v2.length());
+    }
+}
diff --git a/tests/appsecurity-tests/test-apps/CtsMonkeyApp/Android.mk b/tests/appsecurity-tests/test-apps/CtsMonkeyApp/Android.mk
new file mode 100644
index 0000000..85a82d8
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/CtsMonkeyApp/Android.mk
@@ -0,0 +1,27 @@
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# 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)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_PACKAGE_NAME := CtsMonkeyApp
+
+include $(BUILD_PACKAGE)
diff --git a/tests/appsecurity-tests/test-apps/CtsMonkeyApp/AndroidManifest.xml b/tests/appsecurity-tests/test-apps/CtsMonkeyApp/AndroidManifest.xml
new file mode 100644
index 0000000..55f3d6f
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/CtsMonkeyApp/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.monkey">
+
+    <application>
+
+        <activity android:name=".MonkeyActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        
+        <activity android:name=".BaboonActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.MONKEY" />
+            </intent-filter>
+        </activity>
+
+    </application>
+</manifest>
diff --git a/tests/appsecurity-tests/test-apps/CtsMonkeyApp/src/com/android/cts/monkey/BaboonActivity.java b/tests/appsecurity-tests/test-apps/CtsMonkeyApp/src/com/android/cts/monkey/BaboonActivity.java
new file mode 100644
index 0000000..f7b8f47
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/CtsMonkeyApp/src/com/android/cts/monkey/BaboonActivity.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.monkey;
+
+import android.app.Activity;
+
+public class BaboonActivity extends Activity {
+}
diff --git a/tests/appsecurity-tests/test-apps/CtsMonkeyApp/src/com/android/cts/monkey/MonkeyActivity.java b/tests/appsecurity-tests/test-apps/CtsMonkeyApp/src/com/android/cts/monkey/MonkeyActivity.java
new file mode 100644
index 0000000..fd792a7
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/CtsMonkeyApp/src/com/android/cts/monkey/MonkeyActivity.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.monkey;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.os.Bundle;
+import android.util.Log;
+
+/** @(>.<)@  I'm a monkey! */
+public class MonkeyActivity extends Activity {
+
+    private static final String TAG = "MonkeyActivity";
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Log.i(TAG, ActivityManager.isUserAMonkey() ? "@(>.<)@" : "(^_^)");
+    }
+}
diff --git a/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/Android.mk b/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/Android.mk
new file mode 100644
index 0000000..2f3abd2
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/Android.mk
@@ -0,0 +1,27 @@
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# 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)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+LOCAL_PACKAGE_NAME := CtsMonkeyApp2
+
+include $(BUILD_PACKAGE)
diff --git a/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/AndroidManifest.xml b/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/AndroidManifest.xml
new file mode 100644
index 0000000..34bca75
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.monkey2">
+
+    <application>
+
+        <activity android:name=".ChimpActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+    </application>
+</manifest>
diff --git a/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/src/com/android/cts/monkey2/ChimpActivity.java b/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/src/com/android/cts/monkey2/ChimpActivity.java
new file mode 100644
index 0000000..ef9fcc3
--- /dev/null
+++ b/tests/appsecurity-tests/test-apps/CtsMonkeyApp2/src/com/android/cts/monkey2/ChimpActivity.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.monkey2;
+
+import android.app.Activity;
+
+public class ChimpActivity extends Activity {
+}
diff --git a/tests/tests/app/src/android/app/cts/ActionBarActivity.java b/tests/tests/app/src/android/app/cts/ActionBarActivity.java
new file mode 100644
index 0000000..11cee03
--- /dev/null
+++ b/tests/tests/app/src/android/app/cts/ActionBarActivity.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.ActionBar;
+import android.app.Activity;
+import android.os.Bundle;
+
+public class ActionBarActivity extends Activity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        ActionBar bar = getActionBar();
+        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+    }
+}
diff --git a/tests/tests/app/src/android/app/cts/ActionBarTest.java b/tests/tests/app/src/android/app/cts/ActionBarTest.java
new file mode 100644
index 0000000..796cd74
--- /dev/null
+++ b/tests/tests/app/src/android/app/cts/ActionBarTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.ActionBar;
+import android.app.ActionBar.Tab;
+import android.app.ActionBar.TabListener;
+import android.app.FragmentTransaction;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.UiThreadTest;
+
+public class ActionBarTest extends ActivityInstrumentationTestCase2<ActionBarActivity> {
+
+    private ActionBarActivity mActivity;
+    private ActionBar mBar;
+
+    public ActionBarTest() {
+        super(ActionBarActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+        mBar = mActivity.getActionBar();
+    }
+
+    @UiThreadTest
+    public void testAddTab() {
+        assertEquals(0, mBar.getTabCount());
+
+        Tab t1 = createTab("Tab 1");
+        mBar.addTab(t1);
+        assertEquals(1, mBar.getTabCount());
+        assertEquals(t1, mBar.getSelectedTab());
+        assertEquals(t1, mBar.getTabAt(0));
+
+        Tab t2 = createTab("Tab 2");
+        mBar.addTab(t2);
+        assertEquals(2, mBar.getTabCount());
+        assertEquals(t1, mBar.getSelectedTab());
+        assertEquals(t2, mBar.getTabAt(1));
+
+        Tab t3 = createTab("Tab 3");
+        mBar.addTab(t3, true);
+        assertEquals(3, mBar.getTabCount());
+        assertEquals(t3, mBar.getSelectedTab());
+        assertEquals(t3, mBar.getTabAt(2));
+
+        Tab t4 = createTab("Tab 2.5");
+        mBar.addTab(t4, 2);
+        assertEquals(4, mBar.getTabCount());
+        assertEquals(t4, mBar.getTabAt(2));
+        assertEquals(t3, mBar.getTabAt(3));
+
+        Tab t5 = createTab("Tab 0.5");
+        mBar.addTab(t5, 0, true);
+        assertEquals(5, mBar.getTabCount());
+        assertEquals(t5, mBar.getSelectedTab());
+        assertEquals(t5, mBar.getTabAt(0));
+        assertEquals(t1, mBar.getTabAt(1));
+        assertEquals(t2, mBar.getTabAt(2));
+        assertEquals(t4, mBar.getTabAt(3));
+        assertEquals(t3, mBar.getTabAt(4));
+    }
+
+    private Tab createTab(String name) {
+        return mBar.newTab().setText("Tab 1").setTabListener(new TestTabListener());
+    }
+
+    static class TestTabListener implements TabListener {
+        @Override
+        public void onTabSelected(Tab tab, FragmentTransaction ft) {
+        }
+
+        @Override
+        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+        }
+
+        @Override
+        public void onTabReselected(Tab tab, FragmentTransaction ft) {
+        }
+    }
+}
diff --git a/tests/tests/preference2/Android.mk b/tests/tests/preference2/Android.mk
new file mode 100644
index 0000000..4b7b2e5
--- /dev/null
+++ b/tests/tests/preference2/Android.mk
@@ -0,0 +1,31 @@
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# 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)
+
+LOCAL_PACKAGE_NAME := CtsPreference2TestCases
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/tests/tests/preference2/AndroidManifest.xml b/tests/tests/preference2/AndroidManifest.xml
new file mode 100644
index 0000000..5043e1f
--- /dev/null
+++ b/tests/tests/preference2/AndroidManifest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.preference2">
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+        <activity
+            android:name="android.preference2.cts.PreferenceFragmentActivity" >
+        </activity>
+        <activity
+            android:name="android.preference2.cts.PreferenceStubActivity" >
+        </activity>
+        <activity
+            android:name="android.preference2.cts.PreferenceFromCodeActivity" >
+        </activity>
+        <activity android:name="android.preference2.cts.PreferencesFromXml" />
+        <activity android:name="android.preference2.cts.PreferenceWithHeaders" />
+    </application>
+
+    <!-- This is a self-instrumenting test package. -->
+    <instrumentation android:name="android.test.InstrumentationTestRunner"
+                     android:targetPackage="com.android.cts.preference2"
+                     android:label="CTS Test Cases for android.preference"/>
+
+</manifest>
+
diff --git a/tests/tests/preference2/res/drawable-hdpi/ic_launcher.png b/tests/tests/preference2/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..8074c4c
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/tests/tests/preference2/res/drawable-ldpi/ic_launcher.png b/tests/tests/preference2/res/drawable-ldpi/ic_launcher.png
new file mode 100755
index 0000000..1095584
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-ldpi/ic_launcher.png
Binary files differ
diff --git a/tests/tests/preference2/res/drawable-mdpi/ic_launcher.png b/tests/tests/preference2/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..a07c69f
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/tests/tests/preference2/res/drawable-mdpi/ic_settings_applications.png b/tests/tests/preference2/res/drawable-mdpi/ic_settings_applications.png
new file mode 100755
index 0000000..745ff2a
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-mdpi/ic_settings_applications.png
Binary files differ
diff --git a/tests/tests/preference2/res/drawable-mdpi/ic_settings_display.png b/tests/tests/preference2/res/drawable-mdpi/ic_settings_display.png
new file mode 100755
index 0000000..85af393
--- /dev/null
+++ b/tests/tests/preference2/res/drawable-mdpi/ic_settings_display.png
Binary files differ
diff --git a/tests/tests/preference2/res/layout/main.xml b/tests/tests/preference2/res/layout/main.xml
new file mode 100755
index 0000000..a6b7f10
--- /dev/null
+++ b/tests/tests/preference2/res/layout/main.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical" >
+
+    <TextView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        />
+
+</LinearLayout>
diff --git a/tests/tests/preference2/res/values/arrays.xml b/tests/tests/preference2/res/values/arrays.xml
new file mode 100755
index 0000000..198d989
--- /dev/null
+++ b/tests/tests/preference2/res/values/arrays.xml
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.
+-->
+<resources>
+    <!-- Used in View/Spinner1.java -->
+    <string-array name="colors">
+        <item>red</item>
+        <item>orange</item>
+        <item>yellow</item>
+        <item>green</item>
+        <item>blue</item>
+        <item>violet</item>
+    </string-array>
+
+    <!-- Used in View/Spinner1.java -->
+    <string-array name="planets">
+        <item>Mercury</item>
+        <item>Venus</item>
+        <item>Earth</item>
+        <item>Mars</item>
+        <item>Jupiter</item>
+        <item>Saturn</item>
+        <item>Uranus</item>
+        <item>Neptune</item>
+        <item>Pluto</item>
+    </string-array>
+
+    <!-- Used in content/ClipboardSample.java -->
+    <string-array name="clip_data_types">
+        <item>No data in clipboard</item>
+        <item>Text clip</item>
+        <item>Intent clip</item>
+        <item>Uri clip</item>
+    </string-array>
+
+    <!-- Used in App/SearchInvoke.java -->
+    <string-array name="search_menuModes">
+        <item>Search Key</item>
+        <item>Menu Item</item>
+        <item>Type-To-Search</item>
+        <item>Disabled</item>
+    </string-array>
+
+    <!-- Used in app/dialog examples -->
+    <string-array name="select_dialog_items">
+        <item>Command one</item>
+        <item>Command two</item>
+        <item>Command three</item>
+        <item>Command four</item>
+    </string-array>
+
+    <string-array name="select_dialog_items2">
+        <item>Map</item>
+        <item>Satellite</item>
+        <item>Traffic</item>
+        <item>Street view</item>
+    </string-array>
+
+    <string-array name="select_dialog_items3">
+        <item>Every Monday</item>
+        <item>Every Tuesday</item>
+        <item>Every Wednesday</item>
+        <item>Every Thursday</item>
+        <item>Every Friday</item>
+        <item>Every Saturday</item>
+        <item>Every Sunday</item>
+    </string-array>
+
+    <!-- Used in app/menu examples -->
+    <string-array name="entries_list_preference">
+        <item>Alpha Option 01</item>
+        <item>Beta Option 02</item>
+        <item>Charlie Option 03</item>
+    </string-array>
+
+    <!-- Used in app/menu examples -->
+    <string-array name="entryvalues_list_preference">
+        <item>alpha</item>
+        <item>beta</item>
+        <item>charlie</item>
+    </string-array>
+
+    <!-- Used in app/Sample Device Admin -->
+    <string-array name="password_qualities">
+        <item>Unspecified</item>
+        <item>Something</item>
+        <item>Numeric</item>
+        <item>Alphabetic</item>
+        <item>Alphanumeric</item>
+        <item>Complex</item>
+    </string-array>
+
+    <!-- Used in app/Screen Orientation -->
+    <string-array name="screen_orientations">
+        <item>UNSPECIFIED</item>
+        <item>LANDSCAPE</item>
+        <item>PORTRAIT</item>
+        <item>USER</item>
+        <item>BEHIND</item>
+        <item>SENSOR</item>
+        <item>NOSENSOR</item>
+        <item>SENSOR_LANDSCAPE</item>
+        <item>SENSOR_PORTRAIT</item>
+        <item>REVERSE_LANDSCAPE</item>
+        <item>REVERSE_PORTRAIT</item>
+        <item>FULL_SENSOR</item>
+    </string-array>
+
+    <!-- Used in view/Secure View examples -->
+    <string-array name="secure_view_clicked">
+        <item>*bzzt*\nTransferred $1,000,000 to J. Phisher.  Thank you!</item>
+        <item>*bzzt*\nSending all life savings to the International Cabal of Evil Penguins.</item>
+        <item>*bzzt*\nOpening portal to R\'lyeh.  Long live Cthulhu!</item>
+        <item>*bzzt*\nYou\'re not very good at this, are you?</item>
+        <item>*bzzt*\nGo away...</item>
+    </string-array>
+
+    <!-- Used in view/Split Touch View example -->
+    <string-array name="cheese_responses">
+        <item>I\'m afraid we\'re fresh out.</item>
+        <item>I\'m afraid we never have that at the end of the week, sir.  We get it fresh on Monday.
+        </item>
+        <item>Ah. It\'s been on order, sir, for two weeks.  I was expecting it this morning.</item>
+        <item>Normally, sir, yes.  Today the van broke down.</item>
+        <item>No.</item>
+        <item>No.</item>
+        <item>No.</item>
+        <item>Yes, sir.  It\'s, ah ..... it\'s a bit runny.</item>
+        <item>Well, it\'s very runny, actually, sir.</item>
+        <item>I think it\'s a bit runnier than you\'ll like it, sir.</item>
+        <item>Oh... The cat\'s eaten it.</item>
+        <item>No.</item>
+        <item>No.</item>
+        <item>No.</item>
+        <item>Mmm... cheese.</item>
+    </string-array>
+</resources>
diff --git a/tests/tests/preference2/res/values/attrs.xml b/tests/tests/preference2/res/values/attrs.xml
new file mode 100755
index 0000000..e80e204
--- /dev/null
+++ b/tests/tests/preference2/res/values/attrs.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>

+<!-- Copyright (C) 2012 The Android Open Source Project

+

+     Licensed under the Apache License, Version 2.0 (the "License");

+     you may not use this file except in compliance with the License.

+     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.

+-->

+<resources>

+     <declare-styleable name="CustPref">

+        <attr name="icon" format="integer"/>

+        <attr name="title" format="string"/>

+    </declare-styleable>

+</resources>

diff --git a/tests/tests/preference2/res/values/colors.xml b/tests/tests/preference2/res/values/colors.xml
new file mode 100755
index 0000000..bfcd0b4
--- /dev/null
+++ b/tests/tests/preference2/res/values/colors.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>

+<!-- Copyright (C) 2012 The Android Open Source Project

+

+     Licensed under the Apache License, Version 2.0 (the "License");

+     you may not use this file except in compliance with the License.

+     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.

+-->

+<resources>

+    <color name="white">#FFFFFF</color>

+    <color name="android_orange">#FF9E18</color>

+    <color name="android_yellow">#F2E406</color>

+    <color name="black">#000000</color>

+    <color name="red">#FF0000</color>

+</resources>

diff --git a/tests/tests/preference2/res/values/strings.xml b/tests/tests/preference2/res/values/strings.xml
new file mode 100755
index 0000000..d43d3eb
--- /dev/null
+++ b/tests/tests/preference2/res/values/strings.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.
+-->
+<resources>
+    <string name="app_name">CtsPreferenceTestCases</string>
+    <string name="test_prefs">Test Preferences</string>
+
+    <string name="preferences_from_xml">Preference/1. Preferences from XML</string>
+    <string name="launching_preferences">Preference/2. Launching preferences</string>
+    <string name="preference_dependencies">Preference/3. Preference dependencies</string>
+    <string name="default_values">Preference/4. Default values</string>
+    <string name="preferences_from_code">Preference/5. Preferences from code</string>
+    <string name="advanced_preferences">Preference/6. Advanced preferences</string>
+    <string name="fragment_preferences">Preference/7. Fragment</string>
+    <string name="preference_with_headers">Preference/8. Headers</string>
+
+    <string name="launch_preference_activity">Launch PreferenceActivity</string>
+    <string name="counter_value_is">The counter value is</string>
+
+    <string name="inline_preferences">In-line preferences</string>
+    <string name="dialog_based_preferences">Dialog-based preferences</string>
+    <string name="launch_preferences">Launch preferences</string>
+    <string name="preference_attributes">Preference attributes</string>
+
+    <string name="title_checkbox_preference">Checkbox preference</string>
+    <string name="summary_checkbox_preference">This is a checkbox</string>
+    <string name="summary_on_checkbox_preference">Checkbox preference On</string>
+    <string name="summary_off_checkbox_preference">Checkbox preference Off</string>
+
+    <string name="title_switch_preference">Switch preference</string>
+    <string name="summary_switch_preference">This is a switch</string>
+    <string name="summary_on_switch_preference">Switch Summary On</string>
+    <string name="summary_off_switch_preference">Switch Summary Off</string>
+     <string name="switchtext_on">Switch Text On</string>
+    <string name="switchtext_off">Switch Text Off</string>
+
+    <string name="summary_switch_preference_yes_no">This is a switch with custom text</string>
+
+    <string name="title_yesno_preference">Yes or no preference</string>
+    <string name="summary_yesno_preference">An example that uses a yes/no dialog</string>
+    <string name="dialog_title_yesno_preference">Do you like bananas?</string>
+
+    <string name="title_edittext_preference">Edit text preference</string>
+    <string name="summary_edittext_preference">An example that uses an edit text dialog</string>
+    <string name="dialog_title_edittext_preference">Enter your favorite animal</string>
+
+    <string name="title_list_preference">List preference</string>
+    <string name="summary_list_preference">An example that uses a list dialog</string>
+    <string name="dialog_title_list_preference">Choose one</string>
+
+    <string name="title_screen_preference">Screen preference</string>
+    <string name="summary_screen_preference">Shows another screen of preferences</string>
+
+    <string name="title_fragment_preference">Fragment preference</string>
+    <string name="summary_fragment_preference">Shows another fragment of preferences</string>
+
+    <string name="title_next_screen_toggle_preference">Toggle preference</string>
+    <string name="summary_next_screen_toggle_preference">
+    Preference that is on the next screen but same hierarchy</string>
+
+    <string name="title_intent_preference">Intent preference</string>
+    <string name="summary_intent_preference">Launches an Activity from an Intent</string>
+
+    <string name="title_my_preference">My preference</string>
+    <string name="summary_my_preference">This is a custom counter preference</string>
+
+    <string name="title_advanced_toggle_preference">Haunted preference</string>
+    <string name="summary_on_advanced_toggle_preference">I\'m on! :)</string>
+    <string name="summary_off_advanced_toggle_preference">I\'m off! :(</string>
+
+    <string name="title_parent_preference">Parent checkbox preference</string>
+    <string name="summary_parent_preference">This is visually a parent</string>
+    <string name="title_child_preference">Child checkbox preference</string>
+    <string name="summary_child_preference">This is visually a child</string>
+
+    <string name="example_preference_dependency">Example preference dependency</string>
+    <string name="title_wifi">WiFi</string>
+    <string name="title_wifi_settings">WiFi settings</string>
+
+    <string name="default_value_list_preference">beta</string>
+    <string name="default_value_edittext_preference">Default value</string>
+    <string name="text_edittext_preference">Edit Text</string>
+    <string name="preset_title">Preset Title</string>
+    <string name="dialog_message">"Dialog Message"</string>
+    
+    <string name="title_dialog_preference">Dialog preference</string>
+    <string name="dialogtitle_dialog_preference">Dialog Title</string>
+    <string name="summary_dialog_preference">An example that uses a dialog</string>
+    <string name="positive_button_text">"Accept"</string>
+    <string name="negative_button_text">"Decline"</string>
+
+    <string name="cust_title_dialog_preference">Custom Dialog preference</string>
+    <string name="cust_dialogtitle_dialog_preference">Custom Dialog Title</string>
+</resources>
diff --git a/tests/tests/preference2/res/xml/fragmented_preferences.xml b/tests/tests/preference2/res/xml/fragmented_preferences.xml
new file mode 100755
index 0000000..24537b4
--- /dev/null
+++ b/tests/tests/preference2/res/xml/fragmented_preferences.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.
+-->
+
+<!-- This is a primitive example showing the different types of preferences available. -->
+<PreferenceScreen
+        xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <PreferenceCategory
+            android:title="@string/inline_preferences">
+
+        <CheckBoxPreference
+                android:key="checkbox_preference"
+                android:title="@string/title_checkbox_preference"
+                android:summary="@string/summary_checkbox_preference" />
+
+        <SwitchPreference
+                android:key="checkbox_preference"
+                android:title="@string/title_switch_preference"
+                android:summary="@string/summary_switch_preference" />
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+            android:title="@string/dialog_based_preferences">
+
+        <EditTextPreference
+                android:key="edittext_preference"
+                android:title="@string/title_edittext_preference"
+                android:summary="@string/summary_edittext_preference"
+                android:dialogTitle="@string/dialog_title_edittext_preference" />
+
+        <ListPreference
+                android:key="list_preference"
+                android:title="@string/title_list_preference"
+                android:summary="@string/summary_list_preference"
+                android:entries="@array/entries_list_preference"
+                android:entryValues="@array/entryvalues_list_preference"
+                android:dialogTitle="@string/dialog_title_list_preference" />
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+            android:title="@string/launch_preferences">
+
+        <!-- This PreferenceScreen tag sends the user to a new fragment of
+             preferences.  If running in a large screen, they can be embedded
+             inside of the overall preferences UI. -->
+        <PreferenceScreen
+                android:fragment="
+                    com.example.android.apis.preference.PreferenceWithHeaders$Prefs1FragmentInner"
+                android:title="@string/title_fragment_preference"
+                android:summary="@string/summary_fragment_preference">
+            <!-- Arbitrary key/value pairs can be included for fragment arguments -->
+            <extra android:name="someKey" android:value="somePrefValue" />
+        </PreferenceScreen>
+
+        <!-- This PreferenceScreen tag sends the user to a completely different
+             activity, switching out of the current preferences UI. -->
+        <PreferenceScreen
+                android:title="@string/title_intent_preference"
+                android:summary="@string/summary_intent_preference">
+
+            <intent android:action="android.intent.action.VIEW"
+                    android:data="http://www.android.com" />
+
+        </PreferenceScreen>
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+            android:title="@string/preference_attributes">
+
+        <CheckBoxPreference
+                android:key="parent_checkbox_preference"
+                android:title="@string/title_parent_preference"
+                android:summary="@string/summary_parent_preference" />
+
+        <!-- The visual style of a child is defined by this styled theme attribute. -->
+        <CheckBoxPreference
+                android:key="child_checkbox_preference"
+                android:dependency="parent_checkbox_preference"
+                android:layout="?android:attr/preferenceLayoutChild"
+                android:title="@string/title_child_preference"
+                android:summary="@string/summary_child_preference" />
+
+    </PreferenceCategory>
+
+</PreferenceScreen>
+
diff --git a/tests/tests/preference2/res/xml/fragmented_preferences_inner.xml b/tests/tests/preference2/res/xml/fragmented_preferences_inner.xml
new file mode 100755
index 0000000..fe235db
--- /dev/null
+++ b/tests/tests/preference2/res/xml/fragmented_preferences_inner.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.
+-->
+
+<PreferenceScreen
+        xmlns:android="http://schemas.android.com/apk/res/android">
+    <CheckBoxPreference
+            android:key="next_screen_checkbox_preference"
+            android:title="@string/title_next_screen_toggle_preference"
+            android:summary="@string/summary_next_screen_toggle_preference" />
+</PreferenceScreen>
+
diff --git a/tests/tests/preference2/res/xml/pref_cb.xml b/tests/tests/preference2/res/xml/pref_cb.xml
new file mode 100755
index 0000000..b5f77b9
--- /dev/null
+++ b/tests/tests/preference2/res/xml/pref_cb.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2012 The Android Open Source Project

+

+     Licensed under the Apache License, Version 2.0 (the "License");

+     you may not use this file except in compliance with the License.

+     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.

+-->

+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"

+    xmlns:in="http://schemas.android.com/apk/res/com.android.cts.preference2" >

+

+    <PreferenceCategory android:title="@string/inline_preferences" >

+        <android.preference2.cts.CustomCheckBoxPreference

+            android:id="@+id/custom_check"

+            style="?android:attr/buttonStyleSmall"

+            android:layout_width="wrap_content"

+            android:layout_height="wrap_content"

+            android:layout_marginTop="25dp"

+            android:key="custom_checkbox_pref_1"

+            in:icon="@drawable/ic_launcher"

+            in:title="@string/preset_title" />

+        <android.preference2.cts.CustomSwitchPreference

+            android:id="@+id/custom_switch"

+            style="?android:attr/buttonStyleSmall"

+            android:layout_width="wrap_content"

+            android:layout_height="wrap_content"

+            android:layout_marginTop="25dp"

+            android:key="custom_switch_pref_1"

+            in:icon="@drawable/ic_launcher"

+            in:title="@string/preset_title" />

+

+         <android.preference2.cts.CustomDialogPreference

+            android:id="@+id/custom_switch"

+            style="?android:attr/buttonStyleSmall"

+            android:layout_width="wrap_content"

+            android:layout_height="wrap_content"

+            android:layout_marginTop="25dp"

+            android:key="custom_dialog_pref_1"

+            in:icon="@drawable/ic_launcher"

+            in:title="@string/preset_title" />

+

+         <android.preference2.cts.CustomEditTextPreference

+            android:id="@+id/custom_switch"

+            style="?android:attr/buttonStyleSmall"

+            android:layout_width="wrap_content"

+            android:layout_height="wrap_content"

+            android:layout_marginTop="25dp"

+            android:key="custom_edittext_pref_1"

+            in:icon="@drawable/ic_launcher"

+            in:title="@string/preset_title" />

+    </PreferenceCategory>

+</PreferenceScreen>

diff --git a/tests/tests/preference2/res/xml/preference_dependencies.xml b/tests/tests/preference2/res/xml/preference_dependencies.xml
new file mode 100755
index 0000000..405cad6
--- /dev/null
+++ b/tests/tests/preference2/res/xml/preference_dependencies.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.
+-->
+<PreferenceScreen
+        xmlns:android="http://schemas.android.com/apk/res/android">
+    <PreferenceCategory
+            android:title="@string/example_preference_dependency">
+        <CheckBoxPreference
+                android:key="wifi"
+                android:title="@string/title_wifi" />
+        <EditTextPreference
+                android:layout="?android:attr/preferenceLayoutChild"
+                android:title="@string/title_wifi_settings"
+                android:dependency="wifi" />
+    </PreferenceCategory>
+</PreferenceScreen>
diff --git a/tests/tests/preference2/res/xml/preference_headers.xml b/tests/tests/preference2/res/xml/preference_headers.xml
new file mode 100755
index 0000000..45ee629
--- /dev/null
+++ b/tests/tests/preference2/res/xml/preference_headers.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.
+-->
+<preference-headers
+        xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <header android:fragment=
+        "com.example.android.apis.preference.PreferenceWithHeaders$Prefs1Fragment"
+            android:icon="@drawable/ic_settings_applications"
+            android:title="Prefs 1"
+            android:summary="An example of some preferences." />
+
+    <header android:fragment=
+        "com.example.android.apis.preference.PreferenceWithHeaders$Prefs2Fragment"
+            android:icon="@drawable/ic_settings_display"
+            android:title="Prefs 2"
+            android:summary="Some other preferences you can see.">
+        <!-- Arbitrary key/value pairs can be included with a header as
+             arguments to its fragment. -->
+        <extra android:name="someKey" android:value="someHeaderValue" />
+    </header>
+
+    <header android:icon="@drawable/ic_settings_display"
+            android:title="Intent"
+            android:summary="Launches an Intent.">
+        <intent android:action="android.intent.action.VIEW"
+                android:data="http://www.android.com" />
+    </header>
+
+</preference-headers>
diff --git a/tests/tests/preference2/res/xml/preferences.xml b/tests/tests/preference2/res/xml/preferences.xml
new file mode 100755
index 0000000..fa35107
--- /dev/null
+++ b/tests/tests/preference2/res/xml/preferences.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     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.
+-->
+
+<!-- This is a primitive example showing the different types of preferences available. -->
+
+<PreferenceScreen
+        xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <PreferenceCategory
+            android:title="@string/inline_preferences">
+ 
+        <CheckBoxPreference android:id="@+id/checkbox1"
+                android:key="checkbox_preference"
+                android:title="@string/title_checkbox_preference"
+                android:summary="@string/summary_checkbox_preference" />
+
+        <SwitchPreference
+                android:key="checkbox_preference"
+                android:title="@string/title_switch_preference"
+                android:summary="@string/summary_switch_preference" />
+
+        <SwitchPreference
+                android:key="checkbox_preference"
+                android:title="@string/title_switch_preference"
+                android:summary="@string/summary_switch_preference_yes_no"
+                android:switchTextOn = "YES"
+                android:switchTextOff = "NO" />
+    </PreferenceCategory>
+
+    <PreferenceCategory
+            android:title="@string/dialog_based_preferences">
+
+        <EditTextPreference
+                android:key="edittext_preference"
+                android:title="@string/title_edittext_preference"
+                android:summary="@string/summary_edittext_preference"
+                android:dialogTitle="@string/dialog_title_edittext_preference" />
+        <ListPreference
+                android:key="list_preference"
+                android:title="@string/title_list_preference"
+                android:summary="@string/summary_list_preference"
+                android:entries="@array/entries_list_preference"
+                android:entryValues="@array/entryvalues_list_preference"
+                android:dialogTitle="@string/dialog_title_list_preference" />
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+            android:title="@string/launch_preferences">
+
+        <!-- This PreferenceScreen tag serves as a screen break (similar to page break
+             in word processing). Like for other preference types, we assign a key
+             here so it is able to save and restore its instance state. -->
+        <PreferenceScreen
+                android:key="screen_preference"
+                android:title="@string/title_screen_preference"
+                android:summary="@string/summary_screen_preference">
+
+            <!-- You can place more preferences here that will be shown on the next screen. -->
+
+            <CheckBoxPreference
+                    android:key="next_screen_checkbox_preference"
+                    android:title="@string/title_next_screen_toggle_preference"
+                    android:summary="@string/summary_next_screen_toggle_preference" />
+
+        </PreferenceScreen>
+
+        <PreferenceScreen
+                android:title="@string/title_intent_preference"
+                android:summary="@string/summary_intent_preference">
+
+            <intent android:action="android.intent.action.VIEW"
+                    android:data="http://www.android.com" />
+
+        </PreferenceScreen>
+
+    </PreferenceCategory>
+
+    <PreferenceCategory
+            android:title="@string/preference_attributes">
+
+        <CheckBoxPreference
+                android:key="parent_checkbox_preference"
+                android:title="@string/title_parent_preference"
+                android:summary="@string/summary_parent_preference" />
+
+        <!-- The visual style of a child is defined by this styled theme attribute. -->
+        <CheckBoxPreference
+                android:key="child_checkbox_preference"
+                android:dependency="parent_checkbox_preference"
+                android:layout="?android:attr/preferenceLayoutChild"
+                android:title="@string/title_child_preference"
+                android:summary="@string/summary_child_preference" />
+    </PreferenceCategory>
+
+</PreferenceScreen>
+
diff --git a/tests/tests/preference2/src/android/preference2/cts/CheckBoxPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CheckBoxPreferenceTest.java
new file mode 100755
index 0000000..de129e0
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CheckBoxPreferenceTest.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.preference.CheckBoxPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.cts.preference2.R;
+
+public class CheckBoxPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+    private PreferenceFromCodeActivity mActivity;
+
+    public CheckBoxPreferenceTest() {
+        super(PreferenceFromCodeActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+    }
+
+    public void testNotNull() {
+        CheckBoxPreference checkBoxPref = (CheckBoxPreference) mActivity.findPreference(
+                    "checkbox_preference");
+        assertNotNull(checkBoxPref);
+    }
+
+    public void testGetSummary() {
+        CheckBoxPreference checkBoxPref = (CheckBoxPreference) mActivity.findPreference(
+                    "checkbox_preference");
+        String summary = (String) checkBoxPref.getSummary();
+        String summaryExp = mActivity.getResources().getString(
+            R.string.summary_checkbox_preference);
+        assertEquals(summaryExp, summary);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreference.java
new file mode 100755
index 0000000..d51eddd
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreference.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.CheckBoxPreference;
+import android.util.AttributeSet;
+
+public class CustomCheckBoxPreference extends CheckBoxPreference {
+    private Drawable mIcon;
+    private String mTitle;
+    public CustomCheckBoxPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(attrs);
+        setIcon(mIcon);
+        this.setTitle(mTitle);
+    }
+
+    public CustomCheckBoxPreference(Context context) {
+        super(context);
+    }
+
+    public CustomCheckBoxPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init(attrs);
+        setIcon(mIcon);
+        this.setTitle(mTitle);
+    }
+
+    private void init(AttributeSet attrs) {
+        TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+        mTitle = a.getString(R.styleable.CustPref_title);
+        mIcon = a.getDrawable(R.styleable.CustPref_icon);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreferenceTest.java
new file mode 100755
index 0000000..25ba3f3
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomCheckBoxPreferenceTest.java
@@ -0,0 +1,44 @@
+ /*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.preference.CheckBoxPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class CustomCheckBoxPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferencesFromXml> {
+
+    private PreferencesFromXml mActivity;
+    private CheckBoxPreference mCheckBoxPref;
+
+    public CustomCheckBoxPreferenceTest() {
+        super(PreferencesFromXml.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+        mCheckBoxPref = (CheckBoxPreference) mActivity.findPreference(
+                "custom_checkbox_pref_1");
+    }
+
+    public void testNotNull() {
+        assertNotNull(mCheckBoxPref);
+    }
+
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreference.java
new file mode 100755
index 0000000..db584ac
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreference.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+
+public class CustomDialogPreference extends DialogPreference {
+    private Drawable mIcon;
+    private String mTitle;
+    public CustomDialogPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(attrs);
+        setIcon(mIcon);
+        this.setTitle(mTitle);
+    }
+
+    public CustomDialogPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init(attrs);
+        setIcon(mIcon);
+        this.setTitle(mTitle);
+    }
+
+    private void init(AttributeSet attrs) {
+        TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+        mTitle = a.getString(R.styleable.CustPref_title);
+        mIcon = a.getDrawable(R.styleable.CustPref_icon);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreferenceTest.java
new file mode 100755
index 0000000..5384420
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomDialogPreferenceTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class CustomDialogPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferencesFromXml> {
+
+    private PreferencesFromXml mActivity;
+    private CustomDialogPreference mDialogPref;
+
+    public CustomDialogPreferenceTest() {
+        super(PreferencesFromXml.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+        mDialogPref = (CustomDialogPreference) mActivity.findPreference(
+               "custom_dialog_pref_1");
+    }
+
+    public void testNotNull() {
+        assertNotNull(mDialogPref);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreference.java
new file mode 100755
index 0000000..51fdf13
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreference.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.EditTextPreference;
+import android.util.AttributeSet;
+
+public class CustomEditTextPreference extends EditTextPreference {
+    private Drawable mIcon;
+    private String mTitle;
+    public CustomEditTextPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(attrs);
+        setIcon(mIcon);
+        this.setTitle(mTitle);
+    }
+
+    public CustomEditTextPreference(Context context) {
+        super(context);
+    }
+
+    public CustomEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init(attrs);
+        setIcon(mIcon);
+        this.setTitle(mTitle);
+    }
+
+    private void init(AttributeSet attrs) {
+        TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+        mTitle =a.getString(R.styleable.CustPref_title);
+        mIcon  = a.getDrawable(R.styleable.CustPref_icon);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreferenceTest.java
new file mode 100755
index 0000000..c131539
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomEditTextPreferenceTest.java
@@ -0,0 +1,42 @@
+ /*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class CustomEditTextPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferencesFromXml> {
+
+    private PreferencesFromXml mActivity;
+    private CustomEditTextPreference mEditTextPref;
+
+    public CustomEditTextPreferenceTest() {
+        super(PreferencesFromXml.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = (PreferencesFromXml)getActivity();
+        mEditTextPref = (CustomEditTextPreference) mActivity.findPreference(
+                "custom_edittext_pref_1");
+    }
+
+    public void testNotNull() {
+        assertNotNull(mEditTextPref);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreference.java b/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreference.java
new file mode 100755
index 0000000..54e7861
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreference.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+
+import com.android.cts.preference2.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.preference.SwitchPreference;
+import android.util.AttributeSet;
+
+public class CustomSwitchPreference extends SwitchPreference {
+    private Drawable mIcon;
+    private String mTitle;
+    public CustomSwitchPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(attrs);
+        setIcon(mIcon);
+        this.setTitle(mTitle);
+    }
+
+    public CustomSwitchPreference(Context context) {
+        super(context);
+    }
+
+    public CustomSwitchPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init(attrs);
+        setIcon(mIcon);
+        this.setTitle(mTitle);
+    }
+    
+    private void init(AttributeSet attrs) {
+        TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CustPref);
+        mTitle =a.getString(R.styleable.CustPref_title);
+        mIcon  = a.getDrawable(R.styleable.CustPref_icon);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreferenceTest.java
new file mode 100755
index 0000000..937e48f
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/CustomSwitchPreferenceTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class CustomSwitchPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferencesFromXml> {
+
+    private PreferencesFromXml mActivity;
+    private CustomSwitchPreference mSwitchPref;
+
+    public CustomSwitchPreferenceTest() {
+        super(PreferencesFromXml.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+        mSwitchPref = (CustomSwitchPreference) mActivity.findPreference(
+                "custom_switch_pref_1");
+    }
+
+    public void testNotNull() {
+        assertNotNull(mSwitchPref);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/DialogPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/DialogPreferenceTest.java
new file mode 100755
index 0000000..1136cee
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/DialogPreferenceTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.graphics.drawable.Drawable;
+import android.preference.DialogPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.cts.preference2.R;
+
+public class DialogPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+    private PreferenceFromCodeActivity mActivity;
+    private DialogPreference mDialogPreference;
+
+    public DialogPreferenceTest() {
+        super(PreferenceFromCodeActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+        mDialogPreference = (DialogPreference)mActivity.findPreference(
+                "dialog_preference");
+    }
+
+    public void testGetTitle() {
+        String title = (String) mDialogPreference.getTitle();
+        String titleExp = mActivity.getResources().getString(R.string.title_dialog_preference);
+        assertEquals(titleExp, title);
+    }
+
+    public void testGetDialogTitle() {
+        String title = (String) mDialogPreference.getDialogTitle();
+        String titleExp = mActivity.getResources().getString(
+                R.string.dialogtitle_dialog_preference);
+        assertEquals(titleExp, title);
+    }
+
+    public void testGetDialogIcon() {
+        Drawable drawable = mDialogPreference.getDialogIcon();
+        Drawable drawableExp = mActivity.getResources().getDrawable(R.drawable.ic_launcher);
+        assertEquals(drawableExp.getBounds(), drawable.getBounds());
+    }
+
+    public void testGetDialogMessage() {
+        CharSequence dialogMessage = mDialogPreference.getDialogMessage();
+        CharSequence dialogMessageExp =  mActivity.getResources().getString(
+                R.string.dialog_message);
+        assertEquals(dialogMessageExp, dialogMessage);
+    }
+
+    public void testGetPositiveButtonText() {
+        CharSequence positiveButtonText = mDialogPreference.getPositiveButtonText();
+        CharSequence postiveButtonTextExp =  mActivity.getResources().getString(
+                R.string.positive_button_text);
+        assertEquals(positiveButtonText, postiveButtonTextExp);
+    }
+
+    public void testGetNegativeButtonText() {
+        CharSequence negativeButtonText = mDialogPreference.getNegativeButtonText();
+        CharSequence negativeButtonTextExp =  mActivity.getResources().getString(
+                R.string.negative_button_text);
+        assertEquals(negativeButtonText, negativeButtonTextExp);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/EditTextPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/EditTextPreferenceTest.java
new file mode 100755
index 0000000..e0d5c8c
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/EditTextPreferenceTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.preference.EditTextPreference;
+import android.test.ActivityInstrumentationTestCase2;
+import android.widget.EditText;
+
+public class EditTextPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+    private PreferenceFromCodeActivity mActivity;
+    private EditTextPreference mEditTextPref;
+
+    public EditTextPreferenceTest() {
+        super(PreferenceFromCodeActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+        mEditTextPref = (EditTextPreference) mActivity.findPreference(
+                "edittext_preference");
+    }
+
+    public void testGetEditText() {
+        EditText editText = mEditTextPref.getEditText();
+        assertNotNull(editText);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/ListPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/ListPreferenceTest.java
new file mode 100755
index 0000000..32596ff
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/ListPreferenceTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.preference.ListPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.cts.preference2.R;
+
+public class ListPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+    private PreferenceFromCodeActivity mActivity;
+    private ListPreference mListPref;
+
+    public ListPreferenceTest() {
+        super(PreferenceFromCodeActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+        mListPref = (ListPreference) mActivity.findPreference("list_preference");
+    }
+
+    public void testGetEntries() {
+        String[] entries = convertToStringArray((CharSequence[]) mListPref.getEntries());
+        String[] entriesExp = mActivity.getResources().getStringArray(
+                R.array.entries_list_preference);
+        compareArrays(entriesExp, entries);
+    }
+
+    public void testGetEntryValues() {
+        String[] entryValues = convertToStringArray((CharSequence[]) mListPref.getEntryValues());
+        String[] entryValuesExp = mActivity.getResources().getStringArray(
+                R.array.entryvalues_list_preference);
+        compareArrays(entryValuesExp,entryValues);
+    }
+
+    public void testIsEnabled() {
+        boolean isEnabled = mListPref.isEnabled();
+        assertTrue(isEnabled);
+    }
+
+    private synchronized String[] convertToStringArray(CharSequence[] array){
+        String[] strArray = new String[array.length];
+        for(int i = 0; i < array.length; i++){
+            strArray[i] = (String) array[i];
+        }
+        return strArray;
+    }
+
+    private void compareArrays(String[] firstArray,String[] secArray){
+        assertEquals(firstArray.length, secArray.length);
+        for(int i = 0; i < firstArray.length; i++) {
+            assertEquals(firstArray[i], secArray[i]);
+        }
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceCategoryTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceCategoryTest.java
new file mode 100755
index 0000000..33adceb
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceCategoryTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.preference.Preference;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class PreferenceCategoryTest
+        extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+    private PreferenceFromCodeActivity mActivity;
+
+    public PreferenceCategoryTest() {
+        super(PreferenceFromCodeActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+    }
+
+    public void testPreferenceCategory() {
+         Preference prefCat = mActivity.findPreference("pref-1");
+         assertNotNull(prefCat);
+         assertTrue(!prefCat.isEnabled());
+
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentActivity.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentActivity.java
new file mode 100755
index 0000000..4f12d17
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentActivity.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.app.Activity;
+import android.app.FragmentTransaction;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+/**
+ * Demonstration of PreferenceFragment, showing a single fragment in an
+ * activity.
+ */
+public class PreferenceFragmentActivity extends Activity {
+
+    public PrefFragment prefFragment;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        prefFragment = new PrefFragment();
+
+        FragmentTransaction transaction = getFragmentManager().beginTransaction()
+                .replace(android.R.id.content, prefFragment, PrefFragment.TAG);
+        transaction.commit();
+    }
+
+    public class PrefFragment extends PreferenceFragment {
+        public static final String TAG = "Pref-1";
+
+        public PrefFragment() {
+
+        }
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentTest.java
new file mode 100755
index 0000000..4c883c2
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceFragmentTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.preference.PreferenceManager;
+import android.preference.PreferenceScreen;
+import android.preference2.cts.PreferenceFragmentActivity.PrefFragment;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class PreferenceFragmentTest
+        extends ActivityInstrumentationTestCase2<PreferenceFragmentActivity> {
+
+    private PreferenceFragmentActivity mActivity;
+
+    public PreferenceFragmentTest() {
+        super(PreferenceFragmentActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+    }
+
+    public void testGetPreferenceManager() {
+        PrefFragment prefFragment =  (PrefFragment) mActivity.getFragmentManager().
+                findFragmentByTag(PrefFragment.TAG);
+        PreferenceManager prefManager = prefFragment.getPreferenceManager();
+        assertNotNull(prefManager);
+    }
+
+    public void testGetPreferenceScreen() {
+        PrefFragment prefsFragment = (PrefFragment) mActivity.getFragmentManager().
+            findFragmentByTag(PrefFragment.TAG);
+        PreferenceScreen prefScreen = prefsFragment.getPreferenceScreen();
+        assertNull(prefScreen);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java
new file mode 100755
index 0000000..ee0dde1
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceFromCodeActivity.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceCategory;
+import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
+
+public class PreferenceFromCodeActivity extends PreferenceActivity {
+    private Preference mPref;
+    protected PreferenceScreen mPrefScreen;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mPrefScreen = getPreferenceManager().createPreferenceScreen(this);
+        addPreferenceCategory();
+        setPreferenceScreen(mPrefScreen);
+    }
+
+    private void addPreferenceCategory() {
+        PreferenceCategory prefCat = new PreferenceCategory(this);
+        prefCat.setTitle(R.string.inline_preferences);
+        prefCat.setKey("pref-1");
+        mPrefScreen.addPreference(prefCat);
+
+        //CheckBox Preference
+        CheckBoxPreference checkboxPref = new CheckBoxPreference(this);
+        checkboxPref.setKey("checkbox_preference");
+        checkboxPref.setTitle(R.string.title_checkbox_preference);
+        checkboxPref.setSummary(R.string.summary_checkbox_preference);
+        checkboxPref.setSummaryOn(R.string.summary_on_checkbox_preference);
+        checkboxPref.setSummaryOff(R.string.summary_off_checkbox_preference);
+        checkboxPref.setChecked(true);
+        checkboxPref.shouldDisableDependents();
+        prefCat.addPreference(checkboxPref);
+
+        // Switch preference
+        SwitchPreference switchPref = new SwitchPreference(this);
+        switchPref.setKey("switch_preference");
+        switchPref.setTitle(R.string.title_switch_preference);
+        switchPref.setSummary(R.string.summary_switch_preference);
+        switchPref.setSummaryOn(R.string.summary_on_switch_preference);
+        switchPref.setSummaryOff(R.string.summary_off_switch_preference);
+        switchPref.setSwitchTextOff(R.string.switchtext_off);
+        switchPref.setSwitchTextOn(R.string.switchtext_on);
+        prefCat.addPreference(switchPref);
+
+        SwitchPreference switchPref2 = new SwitchPreference(this);
+        switchPref2.setKey("switch_preference_2");
+        switchPref2.setTitle(R.string.title_switch_preference);
+        switchPref2.setSummary(R.string.summary_switch_preference);
+        switchPref2.setSummaryOn(R.string.summary_on_switch_preference);
+        switchPref2.setSummaryOff(R.string.summary_off_switch_preference);
+        prefCat.addPreference(switchPref2);
+
+        // Dialog based preferences
+        PreferenceCategory dialogBasedPrefCat = new PreferenceCategory(this);
+        dialogBasedPrefCat.setTitle(R.string.dialog_based_preferences);
+        mPrefScreen.addPreference(dialogBasedPrefCat);
+
+        // Edit text preference
+        EditTextPreference editTextPref = new EditTextPreference(this);
+        editTextPref.setDialogTitle(R.string.dialog_title_edittext_preference);
+        editTextPref.setKey("edittext_preference");
+        editTextPref.setTitle(R.string.title_edittext_preference);
+        editTextPref.setSummary(R.string.summary_edittext_preference);
+        editTextPref.setText(getResources().getString(R.string.text_edittext_preference));
+        dialogBasedPrefCat.addPreference(editTextPref);
+
+        EditTextPreference dialogPref = new EditTextPreference(this);
+        dialogPref.setDialogTitle(R.string.dialogtitle_dialog_preference);
+        dialogPref.setKey("dialog_preference");
+        dialogPref.setTitle(R.string.title_dialog_preference);
+        dialogPref.setSummary(R.string.summary_dialog_preference);
+        dialogPref.setDialogIcon(R.drawable.ic_launcher);
+        dialogPref.setDialogMessage(R.string.dialog_message);
+        dialogPref.setNegativeButtonText(R.string.negative_button_text);
+        dialogPref.setPositiveButtonText(R.string.positive_button_text);
+
+        dialogBasedPrefCat.addPreference(dialogPref);
+
+        ListPreference listPref = new ListPreference(this);
+        listPref.setEntries(R.array.entries_list_preference);
+        listPref.setEntryValues(R.array.entryvalues_list_preference);
+        listPref.setDialogTitle(R.string.dialog_title_list_preference);
+        listPref.setKey("list_preference");
+        listPref.setTitle(R.string.title_list_preference);
+        listPref.setSummary(R.string.summary_list_preference);
+        dialogBasedPrefCat.addPreference(listPref);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java
new file mode 100755
index 0000000..7a23daf
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeaders.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.widget.Button;
+import com.android.cts.preference2.R;
+import java.util.List;
+
+/**
+ * Demonstration of PreferenceActivity to make a top-level preference
+ * panel with headers.
+ */
+
+public class PreferenceWithHeaders extends PreferenceActivity {
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState); 
+        // Add a button to the header list.
+        if (hasHeaders()) {
+            Button button = new Button(this);
+            button.setText("Some action");
+            setListFooter(button);
+        }
+    }
+
+    /**
+     * Populate the activity with the top-level headers.
+     */
+    @Override
+    public void onBuildHeaders(List<Header> target) {
+        loadHeadersFromResource(R.xml.preference_headers, target);
+    }
+}
+
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java
new file mode 100755
index 0000000..5b78369
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferenceWithHeadersTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import com.android.cts.preference2.R;
+
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+import android.test.ActivityInstrumentationTestCase2;
+
+public class PreferenceWithHeadersTest
+        extends ActivityInstrumentationTestCase2<PreferenceWithHeaders> {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+    }
+
+    private PreferenceWithHeaders mActivity;
+
+    public PreferenceWithHeadersTest() {
+        super(PreferenceWithHeaders.class);
+    }
+
+    public void testHasHeaders() {
+        assertTrue(mActivity.hasHeaders());
+    }
+
+    public void testOnIsHidingHeaders() {
+        assertFalse(mActivity.onIsHidingHeaders());
+    }
+
+    public class PrefsOneFragment extends PreferenceFragment {
+        @Override
+        public void onCreate(Bundle savedInstanceState) {
+            super.onCreate(savedInstanceState);
+            addPreferencesFromResource(R.xml.preferences);
+        }
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/PreferencesFromXml.java b/tests/tests/preference2/src/android/preference2/cts/PreferencesFromXml.java
new file mode 100755
index 0000000..0a61461
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/PreferencesFromXml.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import com.android.cts.preference2.R;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class PreferencesFromXml extends PreferenceActivity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        addPreferencesFromResource(R.xml.pref_cb);
+    }
+}
diff --git a/tests/tests/preference2/src/android/preference2/cts/SwitchPreferenceTest.java b/tests/tests/preference2/src/android/preference2/cts/SwitchPreferenceTest.java
new file mode 100755
index 0000000..3bd42d2
--- /dev/null
+++ b/tests/tests/preference2/src/android/preference2/cts/SwitchPreferenceTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.preference2.cts;
+
+import 	android.content.res.Resources;
+import android.preference.SwitchPreference;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.cts.preference2.R;
+
+public class SwitchPreferenceTest
+        extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
+
+    private PreferenceFromCodeActivity mActivity;
+    private SwitchPreference mSwitchPref;
+    private Resources mResources;
+
+    public SwitchPreferenceTest() {
+        super(PreferenceFromCodeActivity.class);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+        mSwitchPref = (SwitchPreference) mActivity.findPreference(
+                "switch_preference");
+        mResources = mActivity.getResources();
+    }
+
+    public void testGetTitle() {
+        String title = (String) mSwitchPref.getTitle();
+        String titleExp = mResources.getString(R.string.title_switch_preference);
+        assertEquals(titleExp, title);
+    }
+
+    public void testGetSummary() {
+        String summary = (String) mSwitchPref.getSummary();
+        String summaryExp = mResources.getString(R.string.summary_switch_preference);  
+        assertEquals(summaryExp, summary);
+    }
+
+    public void testGetSummaryOn() {
+        String summaryOn = (String) mSwitchPref.getSummaryOn();
+        String summaryOnExp = mResources.getString(
+                R.string.summary_on_switch_preference);
+        assertEquals(summaryOnExp, summaryOn);
+    }
+
+    public void testSummaryOff() {
+        String summaryOff = (String) mSwitchPref.getSummaryOff();
+        String summaryOffExp = mResources.getString(
+                R.string.summary_off_switch_preference);
+        assertEquals(summaryOffExp, summaryOff);
+    }
+
+    public void testSetSwitchTextOff_One() throws Throwable {
+        final CharSequence switchOff = "SwitchedOff";
+        this.runTestOnUiThread(new Runnable() {
+            public void run() {
+                mSwitchPref.setSwitchTextOff(switchOff);
+            }
+        });
+        CharSequence switchOffExp = mSwitchPref.getSwitchTextOff();
+        assertEquals(switchOffExp, switchOff);
+    }
+
+    public void testSetSwitchTextOff_Two() throws Throwable {
+        final CharSequence switchOffExp = mResources.getString(
+                R.string.switchtext_off);
+        CharSequence switchOff = mSwitchPref.getSwitchTextOff();
+        assertEquals(switchOffExp, switchOff);
+    }
+
+    public void testSetSwitchTextOn_One() throws Throwable {
+        final CharSequence switchOn = "SwitchedOff";
+        this.runTestOnUiThread(new Runnable() {
+            public void run() {
+                mSwitchPref.setSwitchTextOn(switchOn);
+            }
+        }); 
+        CharSequence switchOnExp = mSwitchPref.getSwitchTextOn();
+        assertEquals(switchOnExp, switchOn);
+    }
+
+    public void testSetSwitchTextOn_Two() throws Throwable {
+        final CharSequence switchOnExp = mResources.getString(
+                R.string.switchtext_on);
+
+        CharSequence switchOn = mSwitchPref.getSwitchTextOn();
+        assertEquals(switchOnExp, switchOn);
+    }
+}
diff --git a/tests/tests/provider/src/android/provider/cts/ContactsContract_StatusUpdatesTest.java b/tests/tests/provider/src/android/provider/cts/ContactsContract_StatusUpdatesTest.java
new file mode 100644
index 0000000..2f3cdeb
--- /dev/null
+++ b/tests/tests/provider/src/android/provider/cts/ContactsContract_StatusUpdatesTest.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.provider.cts;
+
+import android.content.ContentProviderOperation;
+import android.content.ContentProviderResult;
+import android.content.ContentResolver;
+import android.content.ContentUris;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.ContactsContract;
+import android.provider.ContactsContract.CommonDataKinds.Im;
+import android.provider.ContactsContract.Data;
+import android.provider.ContactsContract.RawContacts;
+import android.provider.ContactsContract.StatusUpdates;
+import android.test.AndroidTestCase;
+
+import java.util.ArrayList;
+
+public class ContactsContract_StatusUpdatesTest extends AndroidTestCase {
+
+    private static final String ACCOUNT_TYPE = "com.android.cts.provider";
+    private static final String ACCOUNT_NAME = "ContactsContract_StatusUpdatesTest";
+
+    private ContentResolver mResolver;
+    private long dataId;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mResolver = mContext.getContentResolver();
+
+        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
+
+        ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
+                .withValue(RawContacts.ACCOUNT_TYPE, ACCOUNT_TYPE)
+                .withValue(RawContacts.ACCOUNT_NAME, ACCOUNT_NAME)
+                .build());
+
+        ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
+                .withValueBackReference(Data.RAW_CONTACT_ID, 0)
+                .withValue(Data.MIMETYPE, Im.CONTENT_ITEM_TYPE)
+                .withValue(Im.TYPE, Im.TYPE_HOME)
+                .withValue(Im.PROTOCOL, Im.PROTOCOL_GOOGLE_TALK)
+                .build());
+
+        ContentProviderResult[] results = mResolver.applyBatch(ContactsContract.AUTHORITY, ops);
+        assertNotNull(results[0].uri);
+        assertNotNull(results[1].uri);
+
+        dataId = ContentUris.parseId(results[1].uri);
+    }
+
+    public void testInsertStatus() throws Exception {
+        Uri uri = insertStatusUpdate(dataId, StatusUpdates.DO_NOT_DISTURB, null, null);
+        assertPresence(uri, StatusUpdates.DO_NOT_DISTURB);
+        assertStatus(uri, null);
+        assertHasTimestamp(uri, false);
+        assertRowCount(uri, 1);
+
+        Uri uri2 = insertStatusUpdate(dataId, StatusUpdates.AVAILABLE, null, null);
+        assertEquals(uri, uri2);
+
+        assertPresence(uri, StatusUpdates.AVAILABLE);
+        assertStatus(uri, null);
+        assertHasTimestamp(uri, false);
+        assertRowCount(uri, 1);
+
+        Uri uri3 = insertStatusUpdate(dataId, StatusUpdates.AWAY, "Grabbing a byte", null);
+        assertEquals(uri2, uri3);
+
+        assertPresence(uri, StatusUpdates.AWAY);
+        assertStatus(uri, "Grabbing a byte");
+        assertHasTimestamp(uri, false);
+        assertRowCount(uri, 1);
+
+        // Inserting a new status message causes a timestamp to be inserted
+        Uri uri4 = insertStatusUpdate(dataId, StatusUpdates.IDLE, "Taking a bit of a break", null);
+        assertEquals(uri3, uri4);
+
+        assertPresence(uri, StatusUpdates.IDLE);
+        assertStatus(uri, "Taking a bit of a break");
+        assertHasTimestamp(uri, true);
+        assertRowCount(uri, 1);
+    }
+
+    private Uri insertStatusUpdate(long dataId, int presence, String status, Long timestamp)
+            throws Exception {
+        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
+        ops.add(ContentProviderOperation.newInsert(StatusUpdates.CONTENT_URI)
+                .withValue(StatusUpdates.DATA_ID, dataId)
+                .withValue(StatusUpdates.PRESENCE, presence)
+                .withValue(StatusUpdates.STATUS, status)
+                .withValue(StatusUpdates.STATUS_TIMESTAMP, timestamp)
+                .withValue(StatusUpdates.PROTOCOL, Im.PROTOCOL_GOOGLE_TALK)
+                .withValue(StatusUpdates.IM_HANDLE, "mrBugDroid1337")
+                .build());
+
+        ContentProviderResult[] results = mResolver.applyBatch(ContactsContract.AUTHORITY, ops);
+        assertNotNull(results[0].uri);
+        return results[0].uri;
+    }
+
+    private void assertRowCount(Uri uri, int count) throws Exception {
+        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
+        ops.add(ContentProviderOperation.newAssertQuery(uri)
+                .withExpectedCount(count)
+                .build());
+
+        mResolver.applyBatch(ContactsContract.AUTHORITY, ops);
+    }
+
+    private void assertPresence(Uri uri, int status) throws Exception {
+        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
+        ops.add(ContentProviderOperation.newAssertQuery(uri)
+                .withValue(StatusUpdates.PRESENCE, status)
+                .withExpectedCount(1)
+                .build());
+
+        mResolver.applyBatch(ContactsContract.AUTHORITY, ops);
+    }
+
+    private void assertStatus(Uri uri, String status) throws Exception {
+        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
+        ops.add(ContentProviderOperation.newAssertQuery(uri)
+                .withValue(StatusUpdates.STATUS, status)
+                .withExpectedCount(1)
+                .build());
+
+        mResolver.applyBatch(ContactsContract.AUTHORITY, ops);
+    }
+
+    private void assertHasTimestamp(Uri uri, boolean hasTimestmap) throws Exception {
+        Cursor cursor = mResolver.query(uri, null, null, null, null);
+        try {
+            assertTrue(cursor.moveToNext());
+
+            if (hasTimestmap) {
+                assertNotNull(cursor.getString(cursor.getColumnIndexOrThrow(
+                        StatusUpdates.STATUS_TIMESTAMP)));
+            } else {
+                assertNull(cursor.getString(cursor.getColumnIndexOrThrow(
+                        StatusUpdates.STATUS_TIMESTAMP)));
+            }
+        } finally {
+            cursor.close();
+        }
+    }
+
+    public void testGetPresencePrecedence() {
+        assertPrecedence(StatusUpdates.AVAILABLE);
+        assertPrecedence(StatusUpdates.AWAY);
+        assertPrecedence(StatusUpdates.DO_NOT_DISTURB);
+        assertPrecedence(StatusUpdates.IDLE);
+        assertPrecedence(StatusUpdates.INVISIBLE);
+        assertPrecedence(StatusUpdates.OFFLINE);
+    }
+
+    private void assertPrecedence(int status) {
+        assertTrue(StatusUpdates.getPresencePrecedence(status) >= 0);
+    }
+
+    public void testGetPresenceIconresourceId() {
+        assertResource(StatusUpdates.AVAILABLE);
+        assertResource(StatusUpdates.AWAY);
+        assertResource(StatusUpdates.DO_NOT_DISTURB);
+        assertResource(StatusUpdates.IDLE);
+        assertResource(StatusUpdates.INVISIBLE);
+        assertResource(StatusUpdates.OFFLINE);
+    }
+
+    private void assertResource(int status) {
+        assertTrue(0 != StatusUpdates.getPresenceIconResourceId(status));
+    }
+}