Move android.os out of CtsTestStubs

bug: 17399677
Change-Id: I2a32b51fb1c02d2128c3eefb5363d6c497b0bc62
diff --git a/tests/Android.mk b/tests/Android.mk
index f66946a..499909b 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -19,8 +19,7 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)\
               $(call all-renderscript-files-under, src)\
-              src/android/app/cts/ISecondary.aidl\
-              src/android/os/cts/IEmptyService.aidl\
+              src/android/app/cts/ISecondary.aidl
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
diff --git a/tests/tests/os/Android.mk b/tests/tests/os/Android.mk
index 0007a54..f0fb88a 100644
--- a/tests/tests/os/Android.mk
+++ b/tests/tests/os/Android.mk
@@ -23,17 +23,21 @@
 
 LOCAL_PROGUARD_ENABLED := disabled
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner guava
+LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil ctstestrunner guava
+
+LOCAL_JNI_SHARED_LIBRARIES := libctsos_jni
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
-        src/android/os/cts/IParcelFileDescriptorPeer.aidl
+        src/android/os/cts/IParcelFileDescriptorPeer.aidl \
+        src/android/os/cts/IEmptyService.aidl \
+        src/android/os/cts/ISecondary.aidl
 
 LOCAL_PACKAGE_NAME := CtsOsTestCases
 
-LOCAL_INSTRUMENTATION_FOR := CtsTestStubs
-
 # uncomment when b/13282254 is fixed
 #LOCAL_SDK_VERSION := current
 LOCAL_JAVA_LIBRARIES += android.test.runner
 
 include $(BUILD_CTS_PACKAGE)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/tests/os/AndroidManifest.xml b/tests/tests/os/AndroidManifest.xml
index 155e772..0599c89 100644
--- a/tests/tests/os/AndroidManifest.xml
+++ b/tests/tests/os/AndroidManifest.xml
@@ -18,11 +18,52 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.android.cts.os">
 
+    <permission android:name="android.os.cts.permission.TEST_GRANTED"
+        android:protectionLevel="normal"
+            android:label="@string/permlab_testGranted"
+            android:description="@string/permdesc_testGranted">
+        <meta-data android:name="android.os.cts.string" android:value="foo" />
+        <meta-data android:name="android.os.cts.boolean" android:value="true" />
+        <meta-data android:name="android.os.cts.integer" android:value="100" />
+        <meta-data android:name="android.os.cts.color" android:value="#ff000000" />
+        <meta-data android:name="android.os.cts.float" android:value="100.1" />
+        <meta-data android:name="android.os.cts.reference" android:resource="@xml/metadata" />
+    </permission>
+
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
     <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
     <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.VIBRATE" />
+    <uses-permission android:name="android.permission.SEND_SMS" />
+    <uses-permission android:name="android.permission.RECEIVE_SMS" />
+    <uses-permission android:name="android.permission.READ_SMS"/>
+    <uses-permission android:name="android.permission.WRITE_SMS"/>
+    <uses-permission android:name="android.permission.CALL_PHONE" />
+    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
+    <uses-permission android:name="android.permission.DEVICE_POWER" />
+    <uses-permission android:name="android.app.cts.permission.TEST_GRANTED" />
 
     <application>
+        <activity android:name="android.app.os.LaunchpadActivity"
+                  android:configChanges="keyboardHidden|orientation|screenSize"
+                  android:multiprocess="true">
+        </activity>
+
+        <activity android:name="android.app.os.AliasActivityStub">
+            <meta-data android:name="android.app.alias"
+                android:resource="@xml/alias" />
+        </activity>
+
+        <activity android:name="android.os.cts.CountDownTimerTestStub"
+            android:label="CountDownTimerTestStub">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
+
         <service
             android:name="android.os.cts.ParcelFileDescriptorPeer$Red"
             android:process=":red"
@@ -31,11 +72,63 @@
             android:name="android.os.cts.ParcelFileDescriptorPeer$Blue"
             android:process=":blue"
             android:exported="true" />
+
+        <service android:name="android.os.cts.LocalService">
+            <intent-filter>
+                <action android:name="android.os.cts.activity.SERVICE_LOCAL" />
+            </intent-filter>
+            <meta-data android:name="android.os.cts.string" android:value="foo" />
+            <meta-data android:name="android.os.cts.boolean" android:value="true" />
+            <meta-data android:name="android.os.cts.integer" android:value="100" />
+            <meta-data android:name="android.os.cts.color" android:value="#ff000000" />
+            <meta-data android:name="android.os.cts.float" android:value="100.1" />
+            <meta-data android:name="android.os.cts.reference" android:resource="@xml/metadata" />
+        </service>
+
+        <service android:name="android.os.cts.LocalGrantedService"
+             android:permission="android.os.cts.permission.TEST_GRANTED">
+            <intent-filter>
+                <action android:name="android.os.cts.activity.SERVICE_LOCAL_GRANTED" />
+            </intent-filter>
+        </service>
+
+        <service android:name="android.os.cts.LocalDeniedService"
+               android:permission="android.os.cts.permission.TEST_DENIED">
+            <intent-filter>
+                <action android:name="android.os.cts.activity.SERVICE_LOCAL_DENIED" />
+            </intent-filter>
+        </service>
+
+
+        <service android:name="android.os.cts.EmptyService"
+            android:process=":remote">
+            <intent-filter>
+                <action
+                    android:name="android.os.cts.IEmptyService" />
+                <action
+                    android:name="android.os.REMOTESERVICE" />
+            </intent-filter>
+        </service>
+
+        <service android:name="android.os.cts.CtsRemoteService"
+            android:process=":remote">
+            <intent-filter>
+                <action
+                    android:name="android.os.cts.ISecondary" />
+                <action
+                    android:name="android.os.REMOTESERVICE" />
+            </intent-filter>
+        </service>
+
+        <service android:name="android.os.cts.MessengerService"
+                android:process=":messengerService">
+        </service>
+
         <uses-library android:name="android.test.runner" />
     </application>
 
     <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
-                     android:targetPackage="com.android.cts.stub"
+                     android:targetPackage="com.android.cts.os"
                      android:label="CTS tests of android.os">
         <meta-data android:name="listener"
             android:value="com.android.cts.runner.CtsTestRunListener" />
diff --git a/tests/tests/os/assets/otacerts.zip b/tests/tests/os/assets/otacerts.zip
new file mode 100644
index 0000000..937a128
--- /dev/null
+++ b/tests/tests/os/assets/otacerts.zip
Binary files differ
diff --git a/tests/tests/os/assets/otasigned.zip b/tests/tests/os/assets/otasigned.zip
new file mode 100644
index 0000000..a6bc53e
--- /dev/null
+++ b/tests/tests/os/assets/otasigned.zip
Binary files differ
diff --git a/tests/jni/Android.mk b/tests/tests/os/jni/Android.mk
similarity index 95%
rename from tests/jni/Android.mk
rename to tests/tests/os/jni/Android.mk
index a3e401e..a39b5d1 100644
--- a/tests/jni/Android.mk
+++ b/tests/tests/os/jni/Android.mk
@@ -16,13 +16,13 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE := libcts_jni
+LOCAL_MODULE := libctsos_jni
 
 # Don't include this package in any configuration by default.
 LOCAL_MODULE_TAGS := optional
 
 LOCAL_SRC_FILES := \
-		CtsJniOnLoad.cpp \
+		CtsOsJniOnLoad.cpp \
 		android_os_cts_CpuInstructions.cpp.arm \
 		android_os_cts_TaggedPointer.cpp \
 		android_os_cts_OSFeatures.cpp \
diff --git a/tests/jni/CtsJniOnLoad.cpp b/tests/tests/os/jni/CtsOsJniOnLoad.cpp
similarity index 100%
rename from tests/jni/CtsJniOnLoad.cpp
rename to tests/tests/os/jni/CtsOsJniOnLoad.cpp
diff --git a/tests/jni/android_os_cts_CpuFeatures.cpp b/tests/tests/os/jni/android_os_cts_CpuFeatures.cpp
similarity index 100%
rename from tests/jni/android_os_cts_CpuFeatures.cpp
rename to tests/tests/os/jni/android_os_cts_CpuFeatures.cpp
diff --git a/tests/jni/android_os_cts_CpuInstructions.cpp b/tests/tests/os/jni/android_os_cts_CpuInstructions.cpp
similarity index 100%
rename from tests/jni/android_os_cts_CpuInstructions.cpp
rename to tests/tests/os/jni/android_os_cts_CpuInstructions.cpp
diff --git a/tests/jni/android_os_cts_FileUtils.cpp b/tests/tests/os/jni/android_os_cts_FileUtils.cpp
similarity index 100%
rename from tests/jni/android_os_cts_FileUtils.cpp
rename to tests/tests/os/jni/android_os_cts_FileUtils.cpp
diff --git a/tests/jni/android_os_cts_OSFeatures.cpp b/tests/tests/os/jni/android_os_cts_OSFeatures.cpp
similarity index 100%
rename from tests/jni/android_os_cts_OSFeatures.cpp
rename to tests/tests/os/jni/android_os_cts_OSFeatures.cpp
diff --git a/tests/jni/android_os_cts_TaggedPointer.cpp b/tests/tests/os/jni/android_os_cts_TaggedPointer.cpp
similarity index 100%
rename from tests/jni/android_os_cts_TaggedPointer.cpp
rename to tests/tests/os/jni/android_os_cts_TaggedPointer.cpp
diff --git a/tests/tests/os/res/raw/test1.obb b/tests/tests/os/res/raw/test1.obb
new file mode 100644
index 0000000..33479aa
--- /dev/null
+++ b/tests/tests/os/res/raw/test1.obb
Binary files differ
diff --git a/tests/tests/os/res/raw/test1_nosig.obb b/tests/tests/os/res/raw/test1_nosig.obb
new file mode 100644
index 0000000..5c3573f
--- /dev/null
+++ b/tests/tests/os/res/raw/test1_nosig.obb
Binary files differ
diff --git a/tests/tests/os/res/raw/test1_wrongpackage.obb b/tests/tests/os/res/raw/test1_wrongpackage.obb
new file mode 100644
index 0000000..d0aafe1
--- /dev/null
+++ b/tests/tests/os/res/raw/test1_wrongpackage.obb
Binary files differ
diff --git a/tests/tests/os/res/values/strings.xml b/tests/tests/os/res/values/strings.xml
new file mode 100644
index 0000000..c167278
--- /dev/null
+++ b/tests/tests/os/res/values/strings.xml
@@ -0,0 +1,179 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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 xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="permlab_testGranted">Test Granted</string>
+    <string name="permdesc_testGranted">Used for running CTS tests, for testing operations
+        where we have the permission.</string>
+    <string name="permlab_testDynamic">Test Dynamic</string>
+    <string name="permdesc_testDynamic">Used for running CTS tests, for testing adding
+        dynamic permissions.</string>
+    <string name="permlab_testDenied">Test Denied</string>
+    <string name="permdesc_testDenied">Used for running CTS tests, for testing operations
+        where we do not have the permission.</string>
+    <string name="explain">1. click start. \n2. if above image shaked, then press pass button,
+         else press failed button.</string>
+    <string name="text_view_hello">Hello! Text view!</string>
+    <string name="text_view_hello_two_lines">Hello! \nText view!</string>
+    <string name="text_view_simple_hint">This is a hint.</string>
+    <string name="text_view_hint">This is a string for testing hint of textview.</string>
+    <string name="activity_forwarding">App/Forwarding</string>
+    <string name="forwarding">$$$</string>
+    <string name="go">Go</string>
+    <string name="back">Back</string>
+    <string name="forward_target">
+        Press back button and notice we don\'t see the previous activity.
+    </string>
+    <string name="edit_text">testing</string>
+    <string name="text">DialogTest</string>
+    <string name="text_country">Country</string>
+    <string name="text_name">Name</string>
+    <string name="hello_world">Hello, World!</string>
+    <string name="hello_android">Hello, Android!</string>
+    <string name="alert_dialog_username">Name:</string>
+    <string name="alert_dialog_password">Password:</string>
+    <string name="alert_dialog_positive">Positive</string>
+    <string name="alert_dialog_negative">Negative</string>
+    <string name="alert_dialog_neutral">Neutral</string>
+    <string name="notify">Notify </string>
+    <string name="tabs_1">testing</string>
+    <string name="table_layout_first">first</string>
+    <string name="table_layout_second">second</string>
+    <string name="table_layout_third">third</string>
+    <string name="table_layout_long">Very long to make the string out of the screen</string>
+    <string name="chronometer_text">Test Chronometer</string>
+    <string name="am">AM</string>
+    <string name="pm">PM</string>
+    <string name="viewgroup_test">ViewGroup test</string>
+    <string name="viewanimator_test">ViewAnimator test</string>
+    <string name="id_ok">OK</string>
+    <string name="id_cancel">Cancel</string>
+    <string name="context_test_string1">This is %s string.</string>
+    <string name="context_test_string2">This is test string.</string>
+    <string name="animationutils_test_instructions">Choose different animations</string>
+    <string name="animationutils_test_alpha">Alpha animation</string>
+    <string name="animationutils_test_scale">Scale animation</string>
+    <string name="animationutils_test_rotate">Rotate animation</string>
+    <string name="animationutils_test_translate">Translate animation</string>
+    <string name="animationutils_test_set">Animation set</string>
+    <string name="animationutils_test_layout">Layout animation</string>
+    <string name="animationutils_test_gridlayout">Grid layout animation</string>
+    <string name="twolinelistitem_test_text1">text1</string>
+    <string name="twolinelistitem_test_text2">text2</string>
+    <string name="metadata_text">metadata text</string>
+    <string name="horizontal_text_1">horizontal 1</string>
+    <string name="horizontal_text_2">horizontal 2</string>
+    <string name="horizontal_text_3">horizontal 3</string>
+    <string name="vertical_text_1">vertical 1</string>
+    <string name="vertical_text_2">vertical 2</string>
+    <string name="vertical_text_3">vertical 3</string>
+    <string name="reference">here</string>
+    <string name="coerceIntegerToString">100</string>
+    <string name="coerceBooleanToString">true</string>
+    <string name="coerceColorToString">#fff</string>
+    <string name="coerceFloatToString">100.0</string>
+    <string name="coerceDimensionToString">100px</string>
+    <string name="coerceFractionToString">100<xliff:g id="percent">%</xliff:g></string>
+    <string name="formattedStringNone">Format[]</string>
+    <string name="formattedStringOne">Format[<xliff:g id="format">%d</xliff:g>]</string>
+    <string name="formattedStringTwo">Format[<xliff:g id="format">%3$d,%2$s</xliff:g>]</string>
+    <string name="checkboxpref_key">checkboxpref_key</string>
+   <string name="checkboxpref_title">title of preference</string>
+   <string name="checkboxpref_summary">summary of preference</string>
+   <string name="checkboxpref_summary_on">summary on of preference</string>
+   <string name="checkboxpref_summary_off">summary off of preference</string>
+   <string name="checkboxpref_depend">checkboxpref_depend</string>
+   <string name="checkboxpref_depend_title"> depend title of preference</string>
+   <string name="checkboxpref_depend_summary"> depend summary of preference</string>
+   <string name="edittextpref_key">edittextpref_key</string>
+   <string name="edittextpref_default_value">default value of preference</string>
+   <string name="edittextpref_title">title of edit text preference</string>
+   <string name="edittextpref_summary">summary of edit text preference</string>
+   <string name="edittextpref_dialog_title">dialog title of edit text preference</string>
+   <string name="edittextpref_text">text of  edit text preference</string>
+   <string name="listpref_key">listpref_key</string>
+   <string name="listpref_title">title of list preference</string>
+   <string name="listpref_summary">summary of list preference</string>
+   <string name="listpref_dialogtitle">dialog title of list preference</string>
+   <string name="easy">Easy</string>
+   <string name="medium">Medium</string>
+   <string name="hard">Hard</string>
+   <string name="footer_view">Footer view</string>
+   <string name="header_view">Header view</string>
+   <string name="dialogpref_title">title of dialog preference </string>
+   <string name="dialogpref_dialog_title">dialog title of dialog preference </string>
+   <string name="dialogpref_key">dialogpref_key</string>
+   <string name="dialogpref_default_value">default value of dialog preference</string>
+   <string name="dialogpref_summary">summary of dialog preference</string>
+   <string name="dialogpref_message">message of dialog preference</string>
+   <string name="dialogpref_sure">Sure</string>
+   <string name="dialogpref_cancel">Cancel</string>
+   <string name="pref_key">pref_key</string>
+   <string name="pref_title">title of preference</string>
+   <string name="pref_summary">summary of preference</string>
+   <string name="pref_depend_key">pref_depend_key</string>
+   <string name="pref_depend_title"> depend title of preference</string>
+   <string name="pref_depend_summary"> depend summary of preference</string>
+   <string name="android_intent_action_preference">android.intent.action.PREFERENCE</string>
+   <string name="def_pref_key">def_pref_key</string>
+   <string name="def_pref_title">default preference</string>
+   <string name="def_pref_summary">This is default preference of cts</string>
+   <string name="relative_view1">view 1</string>
+   <string name="relative_view2">view 2</string>
+   <string name="relative_view3">view 3</string>
+   <string name="relative_view4">view 4</string>
+   <string name="relative_view5">view 5</string>
+   <string name="relative_view6">view 6</string>
+   <string name="relative_view7">view 7</string>
+   <string name="relative_view8">view 8</string>
+   <string name="relative_view9">view 9</string>
+   <string name="relative_view10">view 10</string>
+   <string name="relative_view11">view 11</string>
+   <string name="relative_view12">view 12</string>
+   <string name="relative_view13">view 13</string>
+   <string name="country">Country:</string>
+   <string name="symbol">Symbol:</string>
+   <string name="country_warning">No such country registered</string>
+   <string name="version_cur">base</string>
+   <string name="version_old">base</string>
+   <string name="version_v3">base</string>
+   <string name="authenticator_label">Android CTS</string>
+   <string name="search_label">Android CTS</string>
+   <string name="tag1">tag 1</string>
+   <string name="tag2">tag 2</string>
+
+   <string name="button">Button</string>
+   <string name="holo_test">Holo Test</string>
+   <string name="holo_generator">Holo Generator</string>
+   <string name="holo_light_test">Holo Light Test</string>
+   <string name="holo_light_generator">Holo Light Generator</string>
+   <string name="reference_image">Reference Image: </string>
+   <string name="generated_image">Generated Image: </string>
+   <string name="themes_prompt">Select a Theme:</string>
+   <string name="sample_text">Sample text goes here. I wanted something creative and whimsical
+but then I just got bored...</string>
+    <string name="long_text">This is a really long string which exceeds the width of the view.
+New devices have a much larger screen which actually enables long strings to be displayed
+with no fading. I have made this string longer to fix this case. If you are correcting this
+text, I would love to see the kind of devices you guys now use! Guys, maybe some devices need longer string!
+I think so, so how about double this string, like copy and paste!
+This is a really long string which exceeds the width of the view.
+New devices have a much larger screen which actually enables long strings to be displayed
+with no fading. I have made this string longer to fix this case. If you are correcting this
+text, I would love to see the kind of devices you guys now use! Guys, maybe some devices need longer string!
+I think so, so how about double this string, like copy and paste! </string>
+    <string name="rectangle200">"M 0,0 l 200,0 l 0, 200 l -200, 0 z"</string>
+</resources>
diff --git a/tests/tests/os/res/xml/alias.xml b/tests/tests/os/res/xml/alias.xml
new file mode 100644
index 0000000..f88f3dc
--- /dev/null
+++ b/tests/tests/os/res/xml/alias.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (C) 2008 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.
+ */
+-->
+
+<alias xmlns:android="http://schemas.android.com/apk/res/android">
+    <intent android:action="android.intent.action.MAIN"
+        android:targetPackage="com.android.cts.stub"
+        android:targetClass="android.app.cts.ChildActivity"
+        android:data="http://www.google.com/">
+    </intent>
+</alias>
+
diff --git a/tests/tests/os/res/xml/metadata.xml b/tests/tests/os/res/xml/metadata.xml
new file mode 100644
index 0000000..336b931
--- /dev/null
+++ b/tests/tests/os/res/xml/metadata.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+
+<thedata xmlns:android="http://schemas.android.com/apk/res/android"
+    rawText="some raw text"
+    rawColor="#ffffff00"
+    android:color="#f00"
+    android:text="@string/metadata_text"/>
diff --git a/tests/tests/os/src/android/os/cts/ActivityTestsBase.java b/tests/tests/os/src/android/os/cts/ActivityTestsBase.java
new file mode 100644
index 0000000..3f7d91d
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/ActivityTestsBase.java
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2008 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.os.cts;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.test.AndroidTestCase;
+import android.test.PerformanceTestCase;
+
+public class ActivityTestsBase extends AndroidTestCase implements PerformanceTestCase,
+        LaunchpadActivity.CallingTest {
+    public static final String PERMISSION_GRANTED = "android.os.cts.permission.TEST_GRANTED";
+    public static final String PERMISSION_DENIED = "android.os.cts.permission.TEST_DENIED";
+
+    private static final int TIMEOUT_MS = 60 * 1000;
+
+    protected Intent mIntent;
+
+    private PerformanceTestCase.Intermediates mIntermediates;
+    private String mExpecting;
+
+    // Synchronization of activity result.
+    private boolean mFinished;
+    private int mResultCode = 0;
+    private Intent mData;
+    private RuntimeException mResultStack = null;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mIntent = new Intent(mContext, LaunchpadActivity.class);
+        mIntermediates = null;
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        mIntermediates = null;
+        super.tearDown();
+    }
+
+    public boolean isPerformanceOnly() {
+        return false;
+    }
+
+    public void setInternalIterations(int count) {
+    }
+
+    public void startTiming(boolean realTime) {
+        if (mIntermediates != null) {
+            mIntermediates.startTiming(realTime);
+        }
+    }
+
+    public void addIntermediate(String name) {
+        if (mIntermediates != null) {
+            mIntermediates.addIntermediate(name);
+        }
+    }
+
+    public void addIntermediate(String name, long timeInNS) {
+        if (mIntermediates != null) {
+            mIntermediates.addIntermediate(name, timeInNS);
+        }
+    }
+
+    public void finishTiming(boolean realTime) {
+        if (mIntermediates != null) {
+            mIntermediates.finishTiming(realTime);
+        }
+    }
+
+    public void activityFinished(int resultCode, Intent data, RuntimeException where) {
+        finishWithResult(resultCode, data, where);
+    }
+
+    public Intent editIntent() {
+        return mIntent;
+    }
+
+    @Override
+    public Context getContext() {
+        return mContext;
+    }
+
+    public int startPerformance(Intermediates intermediates) {
+        mIntermediates = intermediates;
+        return 1;
+    }
+
+    public void finishGood() {
+        finishWithResult(Activity.RESULT_OK, null);
+    }
+
+    public void finishBad(String error) {
+        finishWithResult(Activity.RESULT_CANCELED, new Intent().setAction(error));
+    }
+
+    public void finishWithResult(int resultCode, Intent data) {
+        final RuntimeException where = new RuntimeException("Original error was here");
+        where.fillInStackTrace();
+        finishWithResult(resultCode, data, where);
+    }
+
+    public void finishWithResult(int resultCode, Intent data, RuntimeException where) {
+        synchronized (this) {
+            mResultCode = resultCode;
+            mData = data;
+            mResultStack = where;
+            mFinished = true;
+            notifyAll();
+        }
+    }
+
+    public int runLaunchpad(String action) {
+        startLaunchpadActivity(action);
+        return waitForResultOrThrow(TIMEOUT_MS);
+    }
+
+    private void startLaunchpadActivity(String action) {
+        LaunchpadActivity.setCallingTest(this);
+
+        synchronized (this) {
+            mIntent.setAction(action);
+            mFinished = false;
+            mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mContext.startActivity(mIntent);
+        }
+    }
+
+    public int waitForResultOrThrow(int timeoutMs) {
+        return waitForResultOrThrow(timeoutMs, null);
+    }
+
+    public int waitForResultOrThrow(int timeoutMs, String expected) {
+        final int res = waitForResult(timeoutMs, expected);
+
+        if (res == Activity.RESULT_CANCELED) {
+            if (mResultStack != null) {
+                throw new RuntimeException(mData != null ? mData.toString() : "Unable to launch",
+                        mResultStack);
+            } else {
+                throw new RuntimeException(mData != null ? mData.toString() : "Unable to launch");
+            }
+        }
+        return res;
+    }
+
+    public int waitForResult(int timeoutMs, String expected) {
+        mExpecting = expected;
+
+        final long endTime = System.currentTimeMillis() + timeoutMs;
+
+        boolean timeout = false;
+        synchronized (this) {
+            while (!mFinished) {
+                final long delay = endTime - System.currentTimeMillis();
+                if (delay < 0) {
+                    timeout = true;
+                    break;
+                }
+
+                try {
+                    wait(delay);
+                } catch (final java.lang.InterruptedException e) {
+                    // do nothing
+                }
+            }
+        }
+
+        mFinished = false;
+
+        if (timeout) {
+            mResultCode = Activity.RESULT_CANCELED;
+            onTimeout();
+        }
+        return mResultCode;
+    }
+
+
+    public int getResultCode() {
+        return mResultCode;
+    }
+
+    public Intent getResultData() {
+        return mData;
+    }
+
+    public RuntimeException getResultStack() {
+        return mResultStack;
+    }
+
+    public void onTimeout() {
+        final String msg = mExpecting == null ? "Timeout" : "Timeout while expecting " + mExpecting;
+        finishWithResult(Activity.RESULT_CANCELED, new Intent().setAction(msg));
+    }
+}
diff --git a/tests/tests/os/src/android/os/cts/AliasActivityStub.java b/tests/tests/os/src/android/os/cts/AliasActivityStub.java
new file mode 100644
index 0000000..cff405e
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/AliasActivityStub.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.os.cts;
+
+import android.app.AliasActivity;
+import android.os.Bundle;
+
+public class AliasActivityStub extends AliasActivity {
+
+    public static boolean isOnCreateCalled = false;
+    public static boolean isFinished = false;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        isOnCreateCalled = true;
+    }
+
+    @Override
+    public void finish() {
+        super.finish();
+        isFinished = true;
+    }
+}
diff --git a/tests/tests/os/src/android/os/cts/BinderTest.java b/tests/tests/os/src/android/os/cts/BinderTest.java
index 7a30169..435e247 100644
--- a/tests/tests/os/src/android/os/cts/BinderTest.java
+++ b/tests/tests/os/src/android/os/cts/BinderTest.java
@@ -20,8 +20,6 @@
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 
-import android.app.cts.ActivityTestsBase;
-import android.app.cts.LocalService;
 import android.content.ComponentName;
 import android.content.Intent;
 import android.content.ServiceConnection;
diff --git a/tests/tests/os/src/android/os/cts/ClearTop.java b/tests/tests/os/src/android/os/cts/ClearTop.java
new file mode 100644
index 0000000..278336c
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/ClearTop.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2008 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.os.cts;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+public class ClearTop extends Activity {
+    public static final String WAIT_CLEAR_TASK = "waitClearTask";
+    private static final String TAG = "ClearTop";
+    public ClearTop() {
+    }
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        final Intent intent = new Intent(getIntent()).setAction(LocalScreen.CLEAR_TASK).setClass(
+                this, LocalScreen.class);
+        startActivity(intent);
+    }
+
+    @Override
+    public void onNewIntent(Intent intent) {
+        Log.i(TAG, "onNewIntent");
+        if (LocalScreen.CLEAR_TASK.equals(intent.getAction())) {
+            setResult(RESULT_OK);
+        } else {
+            setResult(RESULT_CANCELED, new Intent().setAction("New intent received " + intent
+                    + ", expecting action " + TestedScreen.CLEAR_TASK));
+        }
+        finish();
+    }
+}
diff --git a/tests/src/android/os/cts/CountDownTimerTestStub.java b/tests/tests/os/src/android/os/cts/CountDownTimerTestStub.java
similarity index 100%
rename from tests/src/android/os/cts/CountDownTimerTestStub.java
rename to tests/tests/os/src/android/os/cts/CountDownTimerTestStub.java
diff --git a/tests/src/android/os/cts/CpuFeatures.java b/tests/tests/os/src/android/os/cts/CpuFeatures.java
similarity index 97%
rename from tests/src/android/os/cts/CpuFeatures.java
rename to tests/tests/os/src/android/os/cts/CpuFeatures.java
index fa6628b2..553f264 100644
--- a/tests/src/android/os/cts/CpuFeatures.java
+++ b/tests/tests/os/src/android/os/cts/CpuFeatures.java
@@ -41,7 +41,7 @@
     public static final int HWCAP_IDIVT = (1 << 18);
 
     static {
-        System.loadLibrary("cts_jni");
+        System.loadLibrary("ctsos_jni");
     }
 
     public static native boolean isArmCpu();
diff --git a/tests/src/android/os/cts/CpuInstructions.java b/tests/tests/os/src/android/os/cts/CpuInstructions.java
similarity index 95%
rename from tests/src/android/os/cts/CpuInstructions.java
rename to tests/tests/os/src/android/os/cts/CpuInstructions.java
index e001ceb..45fb2f1 100644
--- a/tests/src/android/os/cts/CpuInstructions.java
+++ b/tests/tests/os/src/android/os/cts/CpuInstructions.java
@@ -19,7 +19,7 @@
 public class CpuInstructions {
 
     static {
-        System.loadLibrary("cts_jni");
+        System.loadLibrary("ctsos_jni");
     }
 
     public static native boolean canReadCntvct();
diff --git a/tests/tests/os/src/android/os/cts/CtsRemoteService.java b/tests/tests/os/src/android/os/cts/CtsRemoteService.java
new file mode 100644
index 0000000..daae49e
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/CtsRemoteService.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2008 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.os.cts;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+import android.os.Process;
+
+public class CtsRemoteService extends Service{
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        android.util.Log.d("Process test stub", "CtsRemoteServiceProcessPid:" + Process.myPid());
+    }
+
+    private final ISecondary.Stub mSecondaryBinder = new ISecondary.Stub() {
+        public int getPid() {
+            return Process.myPid();
+        }
+
+        public long getElapsedCpuTime() {
+            return Process.getElapsedCpuTime();
+        }
+
+        public String getTimeZoneID() {
+            return java.util.TimeZone.getDefault().getID();
+        }
+    };
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        if (ISecondary.class.getName().equals(intent.getAction())) {
+            return mSecondaryBinder;
+        }
+        return null;
+    }
+
+}
diff --git a/tests/src/android/os/cts/EmptyService.java b/tests/tests/os/src/android/os/cts/EmptyService.java
similarity index 100%
rename from tests/src/android/os/cts/EmptyService.java
rename to tests/tests/os/src/android/os/cts/EmptyService.java
diff --git a/tests/src/android/os/cts/FileUtils.java b/tests/tests/os/src/android/os/cts/FileUtils.java
similarity index 98%
rename from tests/src/android/os/cts/FileUtils.java
rename to tests/tests/os/src/android/os/cts/FileUtils.java
index ea31c54..8600d8b 100644
--- a/tests/src/android/os/cts/FileUtils.java
+++ b/tests/tests/os/src/android/os/cts/FileUtils.java
@@ -54,7 +54,7 @@
     public static final int S_IXOTH = 00001;
 
     static {
-        System.loadLibrary("cts_jni");
+        System.loadLibrary("ctsos_jni");
     }
 
     public static class FileStatus {
diff --git a/tests/tests/os/src/android/os/cts/IBinderParcelable.java b/tests/tests/os/src/android/os/cts/IBinderParcelable.java
new file mode 100644
index 0000000..e48f58a
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/IBinderParcelable.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.os.cts;
+
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class IBinderParcelable implements Parcelable {
+    public IBinder binder;
+
+    public IBinderParcelable(IBinder source) {
+        binder = source;
+    }
+
+    public int describeContents() {
+        return 0;
+    }
+
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeStrongBinder(binder);
+    }
+
+    public static final Parcelable.Creator<IBinderParcelable>
+        CREATOR = new Parcelable.Creator<IBinderParcelable>() {
+
+        public IBinderParcelable createFromParcel(Parcel source) {
+            return new IBinderParcelable(source);
+        }
+
+        public IBinderParcelable[] newArray(int size) {
+            return new IBinderParcelable[size];
+        }
+    };
+
+    private IBinderParcelable(Parcel source) {
+        binder = source.readStrongBinder();
+    }
+}
diff --git a/tests/src/android/os/cts/IEmptyService.aidl b/tests/tests/os/src/android/os/cts/IEmptyService.aidl
similarity index 100%
rename from tests/src/android/os/cts/IEmptyService.aidl
rename to tests/tests/os/src/android/os/cts/IEmptyService.aidl
diff --git a/tests/src/android/os/cts/TaggedPointer.java b/tests/tests/os/src/android/os/cts/ISecondary.aidl
similarity index 74%
copy from tests/src/android/os/cts/TaggedPointer.java
copy to tests/tests/os/src/android/os/cts/ISecondary.aidl
index 16e76c9..2c60149 100644
--- a/tests/src/android/os/cts/TaggedPointer.java
+++ b/tests/tests/os/src/android/os/cts/ISecondary.aidl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2008 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.
@@ -16,11 +16,11 @@
 
 package android.os.cts;
 
-public class TaggedPointer {
+interface ISecondary {
 
-    static {
-        System.loadLibrary("cts_jni");
-    }
+    int getPid();
 
-    public static native boolean hasTaggedPointer();
+    long getElapsedCpuTime();
+
+    String getTimeZoneID();
 }
diff --git a/tests/tests/os/src/android/os/cts/LaunchpadActivity.java b/tests/tests/os/src/android/os/cts/LaunchpadActivity.java
new file mode 100644
index 0000000..e812908
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/LaunchpadActivity.java
@@ -0,0 +1,648 @@
+/*
+ * Copyright (C) 2008 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.os.cts;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.test.PerformanceTestCase;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+class MyBadParcelable implements Parcelable {
+    public MyBadParcelable() {
+    }
+
+    public void writeToParcel(Parcel out, int flags) {
+        out.writeString("I am bad");
+    }
+
+    public int describeContents() {
+        return 0;
+    }
+
+    public static final Parcelable.Creator<MyBadParcelable> CREATOR =
+        new Parcelable.Creator<MyBadParcelable>() {
+        public MyBadParcelable createFromParcel(Parcel in) {
+            return new MyBadParcelable(in);
+        }
+
+        public MyBadParcelable[] newArray(int size) {
+            return new MyBadParcelable[size];
+        }
+    };
+
+    public MyBadParcelable(Parcel in) {
+        in.readString();
+    }
+}
+
+public class LaunchpadActivity extends Activity {
+    public interface CallingTest extends PerformanceTestCase.Intermediates {
+        public void startTiming(boolean realTime);
+
+        public void addIntermediate(String name);
+
+        public void addIntermediate(String name, long timeInNS);
+
+        public void finishTiming(boolean realTime);
+
+        public void activityFinished(int resultCode, Intent data, RuntimeException where);
+    }
+
+    // Also used as the Binder interface descriptor string in these tests
+    public static final String LAUNCH = "android.app.cts.activity.LAUNCH";
+
+    public static final String FORWARD_RESULT = "android.app.cts.activity.FORWARD_RESULT";
+    public static final String RETURNED_RESULT = "android.app.cts.activity.RETURNED_RESULT";
+
+    public static final String BAD_PARCELABLE = "android.app.cts.activity.BAD_PARCELABLE";
+
+    public static final int LAUNCHED_RESULT = 1;
+    public static final int FORWARDED_RESULT = 2;
+
+    public static final String LIFECYCLE_BASIC = "android.app.cts.activity.LIFECYCLE_BASIC";
+    public static final String LIFECYCLE_SCREEN = "android.app.cts.activity.LIFECYCLE_SCREEN";
+    public static final String LIFECYCLE_DIALOG = "android.app.cts.activity.LIFECYCLE_DIALOG";
+
+    public static final String BROADCAST_REGISTERED = "android.app.cts.activity.BROADCAST_REGISTERED";
+    public static final String BROADCAST_LOCAL = "android.app.cts.activity.BROADCAST_LOCAL";
+    public static final String BROADCAST_REMOTE = "android.app.cts.activity.BROADCAST_REMOTE";
+    public static final String BROADCAST_ALL = "android.app.cts.activity.BROADCAST_ALL";
+    public static final String BROADCAST_REPEAT = "android.app.cts.activity.BROADCAST_REPEAT";
+    public static final String BROADCAST_MULTI = "android.app.cts.activity.BROADCAST_MULTI";
+    public static final String BROADCAST_ABORT = "android.app.cts.activity.BROADCAST_ABORT";
+
+    public static final String EXPANDLIST_SELECT = "EXPANDLIST_SELECT";
+    public static final String EXPANDLIST_VIEW = "EXPANDLIST_VIEW";
+    public static final String EXPANDLIST_CALLBACK = "EXPANDLIST_CALLBACK";
+
+    public static final String BROADCAST_STICKY1 = "android.app.cts.activity.BROADCAST_STICKY1";
+    public static final String BROADCAST_STICKY2 = "android.app.cts.activity.BROADCAST_STICKY2";
+
+    public static final String ALIAS_ACTIVITY = "android.app.cts.activity.ALIAS_ACTIVITY";
+
+    public static final String RECEIVER_REG = "receiver-reg";
+    public static final String RECEIVER_LOCAL = "receiver-local";
+    public static final String RECEIVER_REMOTE = "receiver-remote";
+    public static final String RECEIVER_ABORT = "receiver-abort";
+
+    public static final String DATA_1 = "one";
+    public static final String DATA_2 = "two";
+
+    public static final String ON_START = "onStart";
+    public static final String ON_RESTART = "onRestart";
+    public static final String ON_RESUME = "onResume";
+    public static final String ON_FREEZE = "onSaveInstanceState";
+    public static final String ON_PAUSE = "onPause";
+
+    // ON_STOP and ON_DESTROY are not tested because they may not be called.
+
+    public static final String DO_FINISH = "finish";
+    public static final String DO_LOCAL_SCREEN = "local-screen";
+    public static final String DO_LOCAL_DIALOG = "local-dialog";
+
+    private static final String TAG = "LaunchpadActivity";
+
+    private boolean mBadParcelable = false;
+
+    private boolean mStarted = false;
+
+    private int mResultCode = RESULT_CANCELED;
+    private Intent mData = new Intent().setAction("No result received");
+    private RuntimeException mResultStack = null;
+
+    /** Index into the {@link #mNextLifecycle} array. */
+    private int mNextLifecycle;
+
+    /** Current lifecycle expected to be followed. */
+    private String[] mExpectedLifecycle;
+
+    /** Other possible lifecycles. Never includes the current {@link #mExpectedLifecycle}. */
+    private List<String[]> mOtherPossibleLifecycles = new ArrayList<String[]>(2);
+
+    /** Map from lifecycle arrays to debugging log names. */
+    private Map<String[], String> mLifecycleNames = new HashMap<String[], String>(2);
+
+    private String[] mExpectedReceivers = null;
+    private int mNextReceiver;
+
+    private String[] mExpectedData = null;
+    private boolean[] mReceivedData = null;
+
+    boolean mReceiverRegistered = false;
+
+    private static CallingTest sCallingTest = null;
+
+    public static void setCallingTest(CallingTest ct) {
+        sCallingTest = ct;
+    }
+
+    public LaunchpadActivity() {
+    }
+
+    @Override
+    protected void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        resetLifecycles();
+
+        // ON_STOP and ON_DESTROY are not tested because they may not be called.
+
+        final String action = getIntent().getAction();
+        if (LIFECYCLE_BASIC.equals(action)) {
+            addPossibleLifecycle(LIFECYCLE_BASIC, new String[] {
+                    ON_START, ON_RESUME, DO_FINISH, ON_PAUSE
+            });
+        } else if (LIFECYCLE_SCREEN.equals(action)) {
+            addPossibleLifecycle(LIFECYCLE_SCREEN + "_RESTART", new String[] {
+                    ON_START, ON_RESUME, DO_LOCAL_SCREEN, ON_PAUSE,
+                    ON_RESTART, ON_START, ON_RESUME, DO_FINISH, ON_PAUSE
+            });
+            addPossibleLifecycle(LIFECYCLE_SCREEN + "_RESUME", new String[] {
+                    ON_START, ON_RESUME, DO_LOCAL_SCREEN, ON_PAUSE,
+                    ON_RESUME, DO_FINISH, ON_PAUSE
+            });
+        } else if (LIFECYCLE_DIALOG.equals(action)) {
+            addPossibleLifecycle(LIFECYCLE_DIALOG + "_RESTART", new String[] {
+                    ON_START, ON_RESUME, DO_LOCAL_DIALOG, ON_PAUSE,
+                    ON_RESTART, ON_START, ON_RESUME, DO_FINISH, ON_PAUSE
+            });
+            addPossibleLifecycle(LIFECYCLE_DIALOG + "_RESUME", new String[] {
+                    ON_START, ON_RESUME, DO_LOCAL_DIALOG, ON_PAUSE,
+                    ON_RESUME, DO_FINISH, ON_PAUSE
+            });
+        }
+    }
+
+    private void resetLifecycles() {
+        mNextLifecycle = 0;
+        mExpectedLifecycle = null;
+        mOtherPossibleLifecycles.clear();
+        mLifecycleNames.clear();
+    }
+
+    /**
+     * Add a potential lifecycle that this activity may follow, since there
+     * are usually multiple valid lifecycles. For instance, sometimes onPause
+     * will lead to onResume rather than onStop when another activity is
+     * raised over the current one.
+     *
+     * @param debugName for the lifecycle shown in the logs
+     * @param lifecycle array containing tokens indicating the expected lifecycle
+     */
+    private void addPossibleLifecycle(String debugName, String[] lifecycle) {
+        mLifecycleNames.put(lifecycle, debugName);
+        if (mExpectedLifecycle == null) {
+            mExpectedLifecycle = lifecycle;
+        } else {
+            mOtherPossibleLifecycles.add(lifecycle);
+        }
+    }
+
+    /**
+     * Switch to the next possible lifecycle and return if switching was
+     * successful. Call this method when mExpectedLifecycle doesn't match
+     * the current lifecycle and you need to check another possible lifecycle.
+     *
+     * @return whether on not there was a lifecycle to switch to
+     */
+    private boolean switchToNextPossibleLifecycle() {
+        if (!mOtherPossibleLifecycles.isEmpty()) {
+            String[] newLifecycle = mOtherPossibleLifecycles.remove(0);
+            Log.w(TAG, "Switching expected lifecycles from "
+                    + mLifecycleNames.get(mExpectedLifecycle) + " to "
+                    + mLifecycleNames.get(newLifecycle));
+            mExpectedLifecycle = newLifecycle;
+            return true;
+        } else {
+            Log.w(TAG, "No more lifecycles after "
+                    + mLifecycleNames.get(mExpectedLifecycle));
+            mExpectedLifecycle = null;
+            return false;
+        }
+    }
+
+    @Override
+    protected void onStart() {
+        super.onStart();
+        checkLifecycle(ON_START);
+    }
+
+    @Override
+    protected void onRestart() {
+        super.onStart();
+        checkLifecycle(ON_RESTART);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+
+        checkLifecycle(ON_RESUME);
+
+        if (!mStarted) {
+            mStarted = true;
+
+            mHandler.postDelayed(mTimeout, 10 * 1000);
+
+            final String action = getIntent().getAction();
+
+            sCallingTest.startTiming(true);
+
+            if (LAUNCH.equals(action)) {
+                final Intent intent = getIntent();
+                intent.setFlags(0);
+                intent.setComponent((ComponentName) intent.getParcelableExtra("component"));
+                startActivityForResult(intent, LAUNCHED_RESULT);
+
+            } else if (FORWARD_RESULT.equals(action)) {
+                final Intent intent = getIntent();
+                intent.setFlags(0);
+                intent.setClass(this, LocalScreen.class);
+                startActivityForResult(intent, FORWARDED_RESULT);
+            } else if (BAD_PARCELABLE.equals(action)) {
+                mBadParcelable = true;
+                final Intent intent = getIntent();
+                intent.setFlags(0);
+                intent.setClass(this, LocalScreen.class);
+                startActivityForResult(intent, LAUNCHED_RESULT);
+            } else if (BROADCAST_REGISTERED.equals(action)) {
+                setExpectedReceivers(new String[] {
+                    RECEIVER_REG
+                });
+                registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED));
+                sCallingTest.addIntermediate("after-register");
+                sendBroadcast(makeBroadcastIntent(BROADCAST_REGISTERED));
+            } else if (BROADCAST_LOCAL.equals(action)) {
+                setExpectedReceivers(new String[] {
+                    RECEIVER_LOCAL
+                });
+                sendBroadcast(makeBroadcastIntent(BROADCAST_LOCAL));
+            } else if (BROADCAST_REMOTE.equals(action)) {
+                setExpectedReceivers(new String[] {
+                    RECEIVER_REMOTE
+                });
+                sendBroadcast(makeBroadcastIntent(BROADCAST_REMOTE));
+            } else if (BROADCAST_ALL.equals(action)) {
+                setExpectedReceivers(new String[] {
+                        RECEIVER_REMOTE, RECEIVER_REG, RECEIVER_LOCAL
+                });
+                registerMyReceiver(new IntentFilter(BROADCAST_ALL));
+                sCallingTest.addIntermediate("after-register");
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_ALL), null);
+            } else if (BROADCAST_MULTI.equals(action)) {
+                setExpectedReceivers(new String[] {
+                        RECEIVER_REMOTE, RECEIVER_REG, RECEIVER_LOCAL, RECEIVER_REMOTE,
+                        RECEIVER_REG, RECEIVER_LOCAL, RECEIVER_REMOTE, RECEIVER_REG,
+                        RECEIVER_LOCAL, RECEIVER_LOCAL, RECEIVER_REMOTE, RECEIVER_LOCAL,
+                        RECEIVER_REMOTE, RECEIVER_REMOTE, RECEIVER_REG, RECEIVER_LOCAL,
+                        RECEIVER_REMOTE, RECEIVER_REG, RECEIVER_LOCAL, RECEIVER_REMOTE,
+                        RECEIVER_REG, RECEIVER_LOCAL, RECEIVER_REMOTE, RECEIVER_LOCAL,
+                        RECEIVER_REMOTE, RECEIVER_LOCAL
+                });
+                registerMyReceiver(new IntentFilter(BROADCAST_ALL));
+                sCallingTest.addIntermediate("after-register");
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_ALL), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_ALL), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_ALL), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_LOCAL), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_REMOTE), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_LOCAL), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_REMOTE), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_ALL), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_ALL), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_ALL), null);
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_REPEAT), null);
+            } else if (BROADCAST_ABORT.equals(action)) {
+                setExpectedReceivers(new String[] {
+                        RECEIVER_REMOTE, RECEIVER_ABORT
+                });
+                registerMyReceiver(new IntentFilter(BROADCAST_ABORT));
+                sCallingTest.addIntermediate("after-register");
+                sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_ABORT), null);
+            } else if (BROADCAST_STICKY1.equals(action)) {
+                setExpectedReceivers(new String[] {
+                    RECEIVER_REG
+                });
+                setExpectedData(new String[] {
+                    DATA_1
+                });
+                registerMyReceiver(new IntentFilter(BROADCAST_STICKY1));
+                sCallingTest.addIntermediate("after-register");
+            } else if (BROADCAST_STICKY2.equals(action)) {
+                setExpectedReceivers(new String[] {
+                        RECEIVER_REG, RECEIVER_REG
+                });
+                setExpectedData(new String[] {
+                        DATA_1, DATA_2
+                });
+                final IntentFilter filter = new IntentFilter(BROADCAST_STICKY1);
+                filter.addAction(BROADCAST_STICKY2);
+                registerMyReceiver(filter);
+                sCallingTest.addIntermediate("after-register");
+            } else if (ALIAS_ACTIVITY.equals(action)) {
+                final Intent intent = getIntent();
+                intent.setFlags(0);
+                intent.setClass(this, AliasActivityStub.class);
+                startActivityForResult(intent, LAUNCHED_RESULT);
+            } else if (EXPANDLIST_SELECT.equals(action)) {
+                final Intent intent = getIntent();
+                intent.setFlags(0);
+                intent.setAction(action);
+                intent.setComponent((ComponentName) intent.getParcelableExtra("component"));
+                startActivityForResult(intent, LAUNCHED_RESULT);
+            } else if (EXPANDLIST_VIEW.equals(action)) {
+                final Intent intent = getIntent();
+                intent.setFlags(0);
+                intent.setAction(action);
+                intent.setComponent((ComponentName) intent.getParcelableExtra("component"));
+                startActivityForResult(intent, LAUNCHED_RESULT);
+            } else if (EXPANDLIST_CALLBACK.equals(action)) {
+                final Intent intent = getIntent();
+                intent.setFlags(0);
+                intent.setAction(action);
+                intent.setComponent((ComponentName) intent.getParcelableExtra("component"));
+                startActivityForResult(intent, LAUNCHED_RESULT);
+            }
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle icicle) {
+        super.onSaveInstanceState(icicle);
+        if (mBadParcelable) {
+            icicle.putParcelable("baddy", new MyBadParcelable());
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        checkLifecycle(ON_PAUSE);
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        switch (requestCode) {
+            case LAUNCHED_RESULT:
+                sCallingTest.finishTiming(true);
+                finishWithResult(resultCode, data);
+                break;
+            case FORWARDED_RESULT:
+                sCallingTest.finishTiming(true);
+                if (RETURNED_RESULT.equals(data.getAction())) {
+                    finishWithResult(resultCode, data);
+                } else {
+                    finishWithResult(RESULT_CANCELED, new Intent().setAction("Bad data returned: "
+                            + data));
+                }
+                break;
+            default:
+                sCallingTest.finishTiming(true);
+                finishWithResult(RESULT_CANCELED, new Intent()
+                        .setAction("Unexpected request code: " + requestCode));
+                break;
+        }
+    }
+
+    private void checkLifecycle(String where) {
+        String action = getIntent().getAction();
+
+        if (mExpectedLifecycle == null) {
+            return;
+        }
+
+        if (mNextLifecycle >= mExpectedLifecycle.length) {
+            finishBad("Activity lifecycle for " + action + " incorrect: received " + where
+                    + " but don't expect any more calls");
+            mExpectedLifecycle = null;
+            return;
+        }
+
+        do {
+            if (mExpectedLifecycle[mNextLifecycle].equals(where)) {
+                Log.w(TAG, "Matched: " + where);
+                break;
+            } else {
+                Log.w(TAG, "Expected " + mExpectedLifecycle[mNextLifecycle] + " but got " + where);
+            }
+        } while (switchToNextPossibleLifecycle());
+
+        if (mExpectedLifecycle == null) {
+            finishBad("Activity lifecycle for " + action + " incorrect: received " + where
+                    + " at " + mNextLifecycle);
+            return;
+        }
+
+        mNextLifecycle++;
+
+        if (mNextLifecycle >= mExpectedLifecycle.length) {
+            finishGood();
+            return;
+        }
+
+        final String next = mExpectedLifecycle[mNextLifecycle];
+        if (next.equals(DO_FINISH)) {
+            mNextLifecycle++;
+            if (mNextLifecycle >= mExpectedLifecycle.length) {
+                setTestResult(RESULT_OK, null);
+            }
+            if (!isFinishing()) {
+                finish();
+            }
+        } else if (next.equals(DO_LOCAL_SCREEN)) {
+            mNextLifecycle++;
+            final Intent intent = new Intent(TestedScreen.WAIT_BEFORE_FINISH);
+            intent.setClass(this, LocalScreen.class);
+            startActivity(intent);
+        } else if (next.equals(DO_LOCAL_DIALOG)) {
+            mNextLifecycle++;
+            final Intent intent = new Intent(TestedScreen.WAIT_BEFORE_FINISH);
+            intent.setClass(this, LocalDialog.class);
+            startActivity(intent);
+        }
+    }
+
+    private void setExpectedReceivers(String[] receivers) {
+        mExpectedReceivers = receivers;
+        mNextReceiver = 0;
+    }
+
+    private void setExpectedData(String[] data) {
+        mExpectedData = data;
+        mReceivedData = new boolean[data.length];
+    }
+
+    @SuppressWarnings("deprecation")
+    private Intent makeBroadcastIntent(String action) {
+        final Intent intent = new Intent(action, null);
+        intent.putExtra("caller", mCallTarget);
+        return intent;
+    }
+
+    private void finishGood() {
+        finishWithResult(RESULT_OK, null);
+    }
+
+    private void finishBad(String error) {
+        finishWithResult(RESULT_CANCELED, new Intent().setAction(error));
+    }
+
+    private void finishWithResult(int resultCode, Intent data) {
+        setTestResult(resultCode, data);
+        finish();
+
+        // Member fields set by calling setTestResult above...
+        sCallingTest.activityFinished(mResultCode, mData, mResultStack);
+    }
+
+    private void setTestResult(int resultCode, Intent data) {
+        mHandler.removeCallbacks(mTimeout);
+        unregisterMyReceiver();
+        mResultCode = resultCode;
+        mData = data;
+        mResultStack = new RuntimeException("Original error was here");
+        mResultStack.fillInStackTrace();
+    }
+
+    private void registerMyReceiver(IntentFilter filter) {
+        mReceiverRegistered = true;
+        registerReceiver(mReceiver, filter);
+    }
+
+    private void unregisterMyReceiver() {
+        if (mReceiverRegistered) {
+            mReceiverRegistered = false;
+            unregisterReceiver(mReceiver);
+        }
+    }
+
+    private final Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+        }
+    };
+
+    static final int GOT_RECEIVE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION;
+    static final int ERROR_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 1;
+
+    private final Binder mCallTarget = new Binder() {
+        @Override
+        public boolean onTransact(int code, Parcel data, Parcel reply, int flags) {
+            data.setDataPosition(0);
+            data.enforceInterface(LaunchpadActivity.LAUNCH);
+            if (code == GOT_RECEIVE_TRANSACTION) {
+                final String name = data.readString();
+                gotReceive(name, null);
+                return true;
+            } else if (code == ERROR_TRANSACTION) {
+                finishBad(data.readString());
+                return true;
+            }
+            return false;
+        }
+    };
+
+    private final void gotReceive(String name, Intent intent) {
+        synchronized (this) {
+
+            sCallingTest.addIntermediate(mNextReceiver + "-" + name);
+
+            if (mExpectedData != null) {
+                final int n = mExpectedData.length;
+                int i;
+                boolean prev = false;
+                for (i = 0; i < n; i++) {
+                    if (mExpectedData[i].equals(intent.getStringExtra("test"))) {
+                        if (mReceivedData[i]) {
+                            prev = true;
+                            continue;
+                        }
+                        mReceivedData[i] = true;
+                        break;
+                    }
+                }
+                if (i >= n) {
+                    if (prev) {
+                        finishBad("Receive got data too many times: "
+                                + intent.getStringExtra("test"));
+                    } else {
+                        finishBad("Receive got unexpected data: " + intent.getStringExtra("test"));
+                    }
+                    return;
+                }
+            }
+
+            if (mNextReceiver >= mExpectedReceivers.length) {
+                finishBad("Got too many onReceiveIntent() calls!");
+            } else if (!mExpectedReceivers[mNextReceiver].equals(name)) {
+                finishBad("Receive out of order: got " + name + " but expected "
+                        + mExpectedReceivers[mNextReceiver] + " at " + mNextReceiver);
+            } else {
+                mNextReceiver++;
+                if (mNextReceiver == mExpectedReceivers.length) {
+                    mHandler.post(mUnregister);
+                }
+            }
+
+        }
+    }
+
+    private final Runnable mUnregister = new Runnable() {
+        public void run() {
+            if (mReceiverRegistered) {
+                sCallingTest.addIntermediate("before-unregister");
+                unregisterMyReceiver();
+            }
+            sCallingTest.finishTiming(true);
+            finishGood();
+        }
+    };
+
+    private final Runnable mTimeout = new Runnable() {
+        public void run() {
+            Log.i(TAG, "timeout");
+            String msg = "Timeout";
+            if (mExpectedReceivers != null && mNextReceiver < mExpectedReceivers.length) {
+                msg = msg + " waiting for " + mExpectedReceivers[mNextReceiver];
+            }
+            finishBad(msg);
+        }
+    };
+
+    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            gotReceive(RECEIVER_REG, intent);
+        }
+    };
+}
diff --git a/tests/src/android/os/cts/TaggedPointer.java b/tests/tests/os/src/android/os/cts/LocalDialog.java
similarity index 75%
copy from tests/src/android/os/cts/TaggedPointer.java
copy to tests/tests/os/src/android/os/cts/LocalDialog.java
index 16e76c9..6ccca57 100644
--- a/tests/src/android/os/cts/TaggedPointer.java
+++ b/tests/tests/os/src/android/os/cts/LocalDialog.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2008 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.
@@ -16,11 +16,7 @@
 
 package android.os.cts;
 
-public class TaggedPointer {
-
-    static {
-        System.loadLibrary("cts_jni");
+public class LocalDialog extends TestedScreen {
+    public LocalDialog() {
     }
-
-    public static native boolean hasTaggedPointer();
 }
diff --git a/tests/src/android/os/cts/TaggedPointer.java b/tests/tests/os/src/android/os/cts/LocalScreen.java
similarity index 75%
copy from tests/src/android/os/cts/TaggedPointer.java
copy to tests/tests/os/src/android/os/cts/LocalScreen.java
index 16e76c9..0a017c4 100644
--- a/tests/src/android/os/cts/TaggedPointer.java
+++ b/tests/tests/os/src/android/os/cts/LocalScreen.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2008 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.
@@ -16,11 +16,7 @@
 
 package android.os.cts;
 
-public class TaggedPointer {
-
-    static {
-        System.loadLibrary("cts_jni");
+public class LocalScreen extends TestedScreen {
+    public LocalScreen() {
     }
-
-    public static native boolean hasTaggedPointer();
 }
diff --git a/tests/tests/os/src/android/os/cts/LocalService.java b/tests/tests/os/src/android/os/cts/LocalService.java
new file mode 100644
index 0000000..0353c23
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/LocalService.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2008 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.os.cts;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.RemoteException;
+
+public class LocalService extends Service {
+    public static final String SERVICE_LOCAL =
+            "android.os.cts.activity.SERVICE_LOCAL";
+    public static final String SERVICE_LOCAL_GRANTED =
+            "android.os.cts.activity.SERVICE_LOCAL_GRANTED";
+    public static final String SERVICE_LOCAL_DENIED =
+            "android.os.cts.activity.SERVICE_LOCAL_DENIED";
+
+    public static final String REPORT_OBJ_NAME = "report";
+
+    public static final int STARTED_CODE = 1;
+    public static final int DESTROYED_CODE = 2;
+    public static final int SET_REPORTER_CODE = 3;
+    public static final int UNBIND_CODE = 4;
+    public static final int REBIND_CODE = 5;
+
+    private IBinder mReportObject;
+    private int mStartCount = 1;
+
+    private final IBinder mBinder = new Binder() {
+        @Override
+        protected boolean onTransact(int code, Parcel data, Parcel reply,
+                int flags) throws RemoteException {
+            if (code == SET_REPORTER_CODE) {
+                data.enforceInterface(SERVICE_LOCAL);
+                mReportObject = data.readStrongBinder();
+                return true;
+            } else {
+                return super.onTransact(code, data, reply, flags);
+            }
+        }
+    };
+
+
+    public LocalService() {
+    }
+
+    @Override
+    public void onStart(Intent intent, int startId) {
+        if (intent.getExtras() != null) {
+            IBinderParcelable parcelable
+                    = (IBinderParcelable) intent.getExtras().getParcelable(REPORT_OBJ_NAME);
+            mReportObject = parcelable.binder;
+            if (mReportObject != null) {
+                bindAction(STARTED_CODE);
+            }
+        }
+    }
+
+    @Override
+    public void onDestroy() {
+        if (mReportObject != null) {
+            bindAction(DESTROYED_CODE);
+        }
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        return mBinder;
+    }
+
+    @Override
+    public boolean onUnbind(Intent intent) {
+        if (mReportObject != null) {
+            bindAction(UNBIND_CODE);
+        }
+        return true;
+    }
+
+    @Override
+    public void onRebind(Intent intent) {
+        if (mReportObject != null) {
+            bindAction(REBIND_CODE);
+        }
+    }
+
+    private void bindAction(final int bindCode) {
+        try {
+            Parcel data = Parcel.obtain();
+            data.writeInterfaceToken(SERVICE_LOCAL);
+            if (bindCode == STARTED_CODE) {
+                data.writeInt(mStartCount);
+                mStartCount++;
+            }
+            mReportObject.transact(
+                    bindCode, data, null, 0);
+            data.recycle();
+        } catch (RemoteException e) {
+            // fail
+        }
+    }
+}
diff --git a/tests/src/android/os/cts/MessengerService.java b/tests/tests/os/src/android/os/cts/MessengerService.java
similarity index 100%
rename from tests/src/android/os/cts/MessengerService.java
rename to tests/tests/os/src/android/os/cts/MessengerService.java
diff --git a/tests/src/android/os/cts/OSFeatures.java b/tests/tests/os/src/android/os/cts/OSFeatures.java
similarity index 95%
rename from tests/src/android/os/cts/OSFeatures.java
rename to tests/tests/os/src/android/os/cts/OSFeatures.java
index 59556db..9c4660c 100644
--- a/tests/src/android/os/cts/OSFeatures.java
+++ b/tests/tests/os/src/android/os/cts/OSFeatures.java
@@ -18,7 +18,7 @@
 
 public class OSFeatures {
     static {
-        System.loadLibrary("cts_jni");
+        System.loadLibrary("ctsos_jni");
     }
 
     public static native int getNoNewPrivs();
diff --git a/tests/tests/os/src/android/os/cts/ProcessTest.java b/tests/tests/os/src/android/os/cts/ProcessTest.java
index 90c2eb9..2ca0fd0 100644
--- a/tests/tests/os/src/android/os/cts/ProcessTest.java
+++ b/tests/tests/os/src/android/os/cts/ProcessTest.java
@@ -16,7 +16,6 @@
 
 package android.os.cts;
 
-import android.app.cts.ISecondary;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
diff --git a/tests/src/android/os/cts/ReadElf.java b/tests/tests/os/src/android/os/cts/ReadElf.java
similarity index 100%
rename from tests/src/android/os/cts/ReadElf.java
rename to tests/tests/os/src/android/os/cts/ReadElf.java
diff --git a/tests/tests/os/src/android/os/cts/RemoteCallbackListTest.java b/tests/tests/os/src/android/os/cts/RemoteCallbackListTest.java
index 4c3f3cf..e00fe89 100644
--- a/tests/tests/os/src/android/os/cts/RemoteCallbackListTest.java
+++ b/tests/tests/os/src/android/os/cts/RemoteCallbackListTest.java
@@ -17,7 +17,6 @@
 package android.os.cts;
 
 
-import android.app.cts.ISecondary;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
diff --git a/tests/src/android/os/cts/TaggedPointer.java b/tests/tests/os/src/android/os/cts/TaggedPointer.java
similarity index 94%
rename from tests/src/android/os/cts/TaggedPointer.java
rename to tests/tests/os/src/android/os/cts/TaggedPointer.java
index 16e76c9..11c3eba 100644
--- a/tests/src/android/os/cts/TaggedPointer.java
+++ b/tests/tests/os/src/android/os/cts/TaggedPointer.java
@@ -19,7 +19,7 @@
 public class TaggedPointer {
 
     static {
-        System.loadLibrary("cts_jni");
+        System.loadLibrary("ctsos_jni");
     }
 
     public static native boolean hasTaggedPointer();
diff --git a/tests/tests/os/src/android/os/cts/TestThread.java b/tests/tests/os/src/android/os/cts/TestThread.java
new file mode 100644
index 0000000..1a28a20
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/TestThread.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.os.cts;
+
+/**
+ * Thread class for executing a Runnable containing assertions in a separate thread.
+ * Uncaught exceptions in the Runnable are rethrown in the context of the the thread
+ * calling the <code>runTest()</code> method.
+ */
+public final class TestThread extends Thread {
+    private Throwable mThrowable;
+    private Runnable mTarget;
+
+    public TestThread(Runnable target) {
+        mTarget = target;
+    }
+
+    @Override
+    public final void run() {
+        try {
+            mTarget.run();
+        } catch (Throwable t) {
+            mThrowable = t;
+        }
+    }
+
+    /**
+     * Run the target Runnable object and wait until the test finish or throw
+     * out Exception if test fail.
+     *
+     * @param runTime
+     * @throws Throwable
+     */
+    public void runTest(long runTime) throws Throwable {
+        start();
+        joinAndCheck(runTime);
+    }
+
+    /**
+     * Get the Throwable object which is thrown when test running
+     * @return  The Throwable object
+     */
+    public Throwable getThrowable() {
+        return mThrowable;
+    }
+
+    /**
+     * Set the Throwable object which is thrown when test running
+     * @param t The Throwable object
+     */
+    public void setThrowable(Throwable t) {
+        mThrowable = t;
+    }
+
+    /**
+     * Wait for the test thread to complete and throw the stored exception if there is one.
+     *
+     * @param runTime The time to wait for the test thread to complete.
+     * @throws Throwable
+     */
+    public void joinAndCheck(long runTime) throws Throwable {
+        this.join(runTime);
+        if (this.isAlive()) {
+            this.interrupt();
+            this.join(runTime);
+            throw new Exception("Thread did not finish within allotted time.");
+        }
+        checkException();
+    }
+
+    /**
+     * Check whether there is an exception when running Runnable object.
+     * @throws Throwable
+     */
+    public void checkException() throws Throwable {
+        if (mThrowable != null) {
+            throw mThrowable;
+        }
+    }
+}
diff --git a/tests/tests/os/src/android/os/cts/TestedScreen.java b/tests/tests/os/src/android/os/cts/TestedScreen.java
new file mode 100644
index 0000000..49f3e70
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/TestedScreen.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2008 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.os.cts;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.MessageQueue;
+import android.os.SystemClock;
+import android.util.Log;
+
+public class TestedScreen extends Activity {
+    public static final String WAIT_BEFORE_FINISH = "TestedScreen.WAIT_BEFORE_FINISH";
+    public static final String DELIVER_RESULT = "TestedScreen.DELIVER_RESULT";
+    public static final String CLEAR_TASK = "TestedScreen.CLEAR_TASK";
+    private static final String TAG = "TestedScreen" ;
+    public TestedScreen() {
+    }
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        if (LaunchpadActivity.FORWARD_RESULT.equals(getIntent().getAction())) {
+            final Intent intent = new Intent(getIntent());
+            intent.setAction(DELIVER_RESULT);
+            intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+            startActivity(intent);
+            finish();
+        } else if (DELIVER_RESULT.equals(getIntent().getAction())) {
+            setResult(RESULT_OK, new Intent().setAction(LaunchpadActivity.RETURNED_RESULT));
+            finish();
+        } else if (CLEAR_TASK.equals(getIntent().getAction())) {
+            if (!getIntent().getBooleanExtra(ClearTop.WAIT_CLEAR_TASK, false)) {
+                launchClearTask();
+            }
+        }
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle state) {
+        super.onRestoreInstanceState(state);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        if (CLEAR_TASK.equals(getIntent().getAction())) {
+            if (getIntent().getBooleanExtra(ClearTop.WAIT_CLEAR_TASK, false)) {
+                Looper.myLooper();
+                Looper.myQueue().addIdleHandler(new Idler());
+            }
+        } else {
+            Looper.myLooper();
+            Looper.myQueue().addIdleHandler(new Idler());
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+    }
+
+    private void launchClearTask() {
+        final Intent intent = new Intent(getIntent()).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
+                .setClass(this, ClearTop.class);
+        startActivity(intent);
+    }
+
+    private final Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            if (CLEAR_TASK.equals(getIntent().getAction())) {
+                launchClearTask();
+            } else {
+                setResult(RESULT_OK);
+                finish();
+            }
+        }
+    };
+
+    private class Idler implements MessageQueue.IdleHandler {
+        public final boolean queueIdle() {
+            Log.i(TAG, "idle");
+            if (WAIT_BEFORE_FINISH.equals(getIntent().getAction())) {
+                final Message m = Message.obtain();
+                mHandler.sendMessageAtTime(m, SystemClock.uptimeMillis() + 1000);
+            } else if (CLEAR_TASK.equals(getIntent().getAction())) {
+                final Message m = Message.obtain();
+                mHandler.sendMessageAtTime(m, SystemClock.uptimeMillis() + 1000);
+            } else {
+                setResult(RESULT_OK);
+                finish();
+            }
+            return false;
+        }
+    }
+}
diff --git a/tests/tests/os/src/android/os/storage/cts/StorageManagerTest.java b/tests/tests/os/src/android/os/storage/cts/StorageManagerTest.java
index 45c5e45..a4a5759 100644
--- a/tests/tests/os/src/android/os/storage/cts/StorageManagerTest.java
+++ b/tests/tests/os/src/android/os/storage/cts/StorageManagerTest.java
@@ -16,7 +16,7 @@
 
 package android.os.storage.cts;
 
-import com.android.cts.stub.R;
+import com.android.cts.os.R;
 
 import android.content.Context;
 import android.content.res.Resources;