Merge "Merge "Merge "Merge "Excluding ScreenLock test for automotive" into marshmallow-cts-dev am: eb30239ed6" into nougat-cts-dev am: 6b87d8f716" into nougat-mr1-cts-dev am: 5679c755aa" into oreo-cts-dev am: a3f6e37ea5
am: 21df4fbf4a

Change-Id: I3008b6283ea8a695d64b51f6eb02ab355d33e062
diff --git a/apps/CtsVerifier/Android.mk b/apps/CtsVerifier/Android.mk
index 2dd5f23..0288d07 100644
--- a/apps/CtsVerifier/Android.mk
+++ b/apps/CtsVerifier/Android.mk
@@ -51,7 +51,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 +71,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 \
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 24a5b68..03d1f01 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -1660,7 +1660,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
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index 901f5b8..807548d 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -1919,7 +1919,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>
@@ -3826,8 +3826,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/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/peripheralprofile/ProfileManager.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/peripheralprofile/ProfileManager.java
index 264e8f0..ebb5991 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
@@ -69,11 +69,14 @@
                 "<InputDevInfo ChanCounts=\"1,2\" ChanPosMasks=\"12,16\" ChanIndexMasks=\"3\" Encodings=\"4\" SampleRates=\"48000\" />" +
                 "<ButtonInfo HasBtnA=\"1\" HasBtnB=\"1\" HasBtnC=\"1\" HasBtnD=\"1\" />" +
             "</PeripheralProfile>" +
-            "<PeripheralProfile ProfileName=\"gen1-headset\" ProfileDescription=\"Google Generation 1 USB Headset\" ProductName=\"USB-Audio - Skylab\">" +
+            "<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/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/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/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/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/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/tests/src/com/android/compatibility/common/tradefed/UnitTests.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/UnitTests.java
index b36d960..337908e 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;
@@ -58,6 +60,7 @@
 @SuiteClasses({
     // build
     CompatibilityBuildHelperTest.class,
+    CompatibilityBuildProviderTest.class,
 
     // command
     CompatibilityConsoleTest.class,
@@ -66,6 +69,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 ee28e64..64b3ff6 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
@@ -97,6 +97,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/appsecurity/Android.mk b/hostsidetests/appsecurity/Android.mk
index 8391b99..d9376a8 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
 
 LOCAL_REQUIRED_MODULES := \
 	CtsCorruptApkTests_b71360999 \
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/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..8e51f22 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionApp22/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionApp22/Android.mk
@@ -34,7 +34,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..5e623d8 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionApp23/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionApp23/Android.mk
@@ -32,7 +32,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/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..9de77f5 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/backup/AllowBackup/Android.mk b/hostsidetests/backup/AllowBackup/Android.mk
new file mode 100644
index 0000000..b798d87
--- /dev/null
+++ b/hostsidetests/backup/AllowBackup/Android.mk
@@ -0,0 +1,15 @@
+# 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/hostsidetests/backup/AllowBackup/BackupAllowedApp/Android.mk b/hostsidetests/backup/AllowBackup/BackupAllowedApp/Android.mk
new file mode 100644
index 0000000..6eaf7f0
--- /dev/null
+++ b/hostsidetests/backup/AllowBackup/BackupAllowedApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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/backup/AllowBackup/BackupNotAllowedApp/Android.mk b/hostsidetests/backup/AllowBackup/BackupNotAllowedApp/Android.mk
new file mode 100644
index 0000000..e8c70b9
--- /dev/null
+++ b/hostsidetests/backup/AllowBackup/BackupNotAllowedApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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/backup/FullBackupOnly/Android.mk b/hostsidetests/backup/FullBackupOnly/Android.mk
new file mode 100644
index 0000000..521ac4d
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/Android.mk
@@ -0,0 +1,17 @@
+#
+# 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/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/Android.mk b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/Android.mk
new file mode 100644
index 0000000..5cce7a4
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseNoAgentApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/Android.mk b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/Android.mk
new file mode 100644
index 0000000..3224b98
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyFalseWithAgentApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/Android.mk b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/Android.mk
new file mode 100644
index 0000000..2f0eae8
--- /dev/null
+++ b/hostsidetests/backup/FullBackupOnly/FullBackupOnlyTrueWithAgentApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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/backup/RestoreAnyVersion/Android.mk b/hostsidetests/backup/RestoreAnyVersion/Android.mk
new file mode 100644
index 0000000..521ac4d
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/Android.mk
@@ -0,0 +1,17 @@
+#
+# 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/hostsidetests/backup/RestoreAnyVersion/NewVersionApp/Android.mk b/hostsidetests/backup/RestoreAnyVersion/NewVersionApp/Android.mk
new file mode 100644
index 0000000..ae38548
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/NewVersionApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/Android.mk b/hostsidetests/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/Android.mk
new file mode 100644
index 0000000..277acb6
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/NoRestoreAnyVersionApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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/backup/RestoreAnyVersion/RestoreAnyVersionApp/Android.mk b/hostsidetests/backup/RestoreAnyVersion/RestoreAnyVersionApp/Android.mk
new file mode 100644
index 0000000..170f362
--- /dev/null
+++ b/hostsidetests/backup/RestoreAnyVersion/RestoreAnyVersionApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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/backup/SharedPreferencesRestoreApp/Android.mk b/hostsidetests/backup/SharedPreferencesRestoreApp/Android.mk
new file mode 100644
index 0000000..bd6929a
--- /dev/null
+++ b/hostsidetests/backup/SharedPreferencesRestoreApp/Android.mk
@@ -0,0 +1,39 @@
+# 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 := 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_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..0849f82 100644
--- a/hostsidetests/bootstats/Android.mk
+++ b/hostsidetests/bootstats/Android.mk
@@ -26,7 +26,7 @@
 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/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..c9bd048 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,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 := 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/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..7d277d9 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdmin/api23/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdmin/api23/Android.mk
@@ -26,11 +26,14 @@
 
 LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/../res
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner compatibility-device-util
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
+    compatibility-device-util \
+    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..ab38265 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdmin/api24/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAdmin/api24/Android.mk
@@ -26,11 +26,14 @@
 
 LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/../res
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner compatibility-device-util
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    ctstestrunner \
+    compatibility-device-util \
+    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..f8467c1 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api23/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api23/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/DeviceAndProfileOwner/api25/Android.mk b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api25/Android.mk
index 962c5f5..8a0d559 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api25/Android.mk
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/api25/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/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/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..5bb5c80 100644
--- a/hostsidetests/devicepolicy/app/LauncherTests/Android.mk
+++ b/hostsidetests/devicepolicy/app/LauncherTests/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/LauncherTestsSupport/Android.mk b/hostsidetests/devicepolicy/app/LauncherTestsSupport/Android.mk
index 9e86d13..95b3e27 100644
--- a/hostsidetests/devicepolicy/app/LauncherTestsSupport/Android.mk
+++ b/hostsidetests/devicepolicy/app/LauncherTestsSupport/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/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/devicepolicy/app/NotificationSender/Android.mk b/hostsidetests/devicepolicy/app/NotificationSender/Android.mk
new file mode 100644
index 0000000..8b85e66
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/NotificationSender/Android.mk
@@ -0,0 +1,37 @@
+# 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
+
+# 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)
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
+
+LOCAL_PACKAGE_NAME := CtsNotificationSenderApp
+
+LOCAL_SDK_VERSION := 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/NotificationSender/AndroidManifest.xml b/hostsidetests/devicepolicy/app/NotificationSender/AndroidManifest.xml
new file mode 100644
index 0000000..0f5ac6d
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/NotificationSender/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?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.managedprofiletests.notificationsender">
+
+    <application>
+      <activity android:name=".SendNotification"
+                android:exported="true">
+      </activity>
+    </application>
+</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/hostsidetests/devicepolicy/app/SingleAdminApp/res/xml/device_admin.xml b/hostsidetests/devicepolicy/app/SingleAdminApp/res/xml/device_admin.xml
new file mode 100644
index 0000000..0f434d2
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/SingleAdminApp/res/xml/device_admin.xml
@@ -0,0 +1,19 @@
+<!-- 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.
+-->
+<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 9a2224e..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..f438d83 100644
--- a/hostsidetests/dumpsys/apps/ProcStatsHelperApp/Android.mk
+++ b/hostsidetests/dumpsys/apps/ProcStatsHelperApp/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/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..5101bf3 100644
--- a/hostsidetests/incident/apps/errorsapp/jni/Android.mk
+++ b/hostsidetests/incident/apps/errorsapp/jni/Android.mk
@@ -25,9 +25,6 @@
 
 LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
 
-# Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts
-
 LOCAL_SDK_VERSION := current
 
 include $(BUILD_SHARED_LIBRARY)
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/ProtoDumpTestCase.java b/hostsidetests/incident/src/com/android/server/cts/ProtoDumpTestCase.java
index f961f6e..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 c9b496c..f309158 100644
--- a/hostsidetests/inputmethodservice/hostside/src/android/inputmethodservice/cts/hostside/InputMethodServiceLifecycleTest.java
+++ b/hostsidetests/inputmethodservice/hostside/src/android/inputmethodservice/cts/hostside/InputMethodServiceLifecycleTest.java
@@ -81,13 +81,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);
@@ -104,13 +98,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);
@@ -125,6 +113,49 @@
         assertNotEquals(newIme, Ime1Constants.IME_ID);
     }
 
+    @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..511f543 100644
--- a/hostsidetests/jvmti/allocation-tracking/Android.mk
+++ b/hostsidetests/jvmti/allocation-tracking/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiTrackingHostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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/redefining/Android.mk b/hostsidetests/jvmti/redefining/Android.mk
index d0a728d..4c8ac15 100644
--- a/hostsidetests/jvmti/redefining/Android.mk
+++ b/hostsidetests/jvmti/redefining/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRedefineClassesHostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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/run-tests/test-902/Android.mk b/hostsidetests/jvmti/run-tests/test-902/Android.mk
index 7479ad8..f16dd85 100644
--- a/hostsidetests/jvmti/run-tests/test-902/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-902/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest902HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-903/Android.mk b/hostsidetests/jvmti/run-tests/test-903/Android.mk
index 1b67da1..b7d15bd 100644
--- a/hostsidetests/jvmti/run-tests/test-903/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-903/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest903HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-904/Android.mk b/hostsidetests/jvmti/run-tests/test-904/Android.mk
index b814acb..3655374 100644
--- a/hostsidetests/jvmti/run-tests/test-904/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-904/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest904HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-905/Android.mk b/hostsidetests/jvmti/run-tests/test-905/Android.mk
index 9e58b9b..065585e 100644
--- a/hostsidetests/jvmti/run-tests/test-905/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-905/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest905HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-906/Android.mk b/hostsidetests/jvmti/run-tests/test-906/Android.mk
index 553b898..5a61e0f 100644
--- a/hostsidetests/jvmti/run-tests/test-906/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-906/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest906HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-907/Android.mk b/hostsidetests/jvmti/run-tests/test-907/Android.mk
index cf79d0b..5629150 100644
--- a/hostsidetests/jvmti/run-tests/test-907/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-907/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest907HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-908/Android.mk b/hostsidetests/jvmti/run-tests/test-908/Android.mk
index 40ef837..f260e26 100644
--- a/hostsidetests/jvmti/run-tests/test-908/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-908/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest908HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/jvmti/run-tests/test-908/app/Android.mk b/hostsidetests/jvmti/run-tests/test-908/app/Android.mk
index c4eea2e..8cbf7db 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-910/Android.mk b/hostsidetests/jvmti/run-tests/test-910/Android.mk
index 8cfe0a5..bc06790 100644
--- a/hostsidetests/jvmti/run-tests/test-910/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-910/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest910HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-913/Android.mk b/hostsidetests/jvmti/run-tests/test-913/Android.mk
index 8075fe2..d9cdd01 100644
--- a/hostsidetests/jvmti/run-tests/test-913/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-913/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest913HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-914/Android.mk b/hostsidetests/jvmti/run-tests/test-914/Android.mk
index 5f7ddee..e28f495 100644
--- a/hostsidetests/jvmti/run-tests/test-914/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-914/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest914HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-915/Android.mk b/hostsidetests/jvmti/run-tests/test-915/Android.mk
index 2e2e438..7934916 100644
--- a/hostsidetests/jvmti/run-tests/test-915/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-915/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest915HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-917/Android.mk b/hostsidetests/jvmti/run-tests/test-917/Android.mk
index 1e84675..80199f7 100644
--- a/hostsidetests/jvmti/run-tests/test-917/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-917/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest917HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-918/Android.mk b/hostsidetests/jvmti/run-tests/test-918/Android.mk
index 5d6f8d0..5600ece 100644
--- a/hostsidetests/jvmti/run-tests/test-918/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-918/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest918HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-919/Android.mk b/hostsidetests/jvmti/run-tests/test-919/Android.mk
index 8916d6e..76ad7db 100644
--- a/hostsidetests/jvmti/run-tests/test-919/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-919/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest919HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-920/Android.mk b/hostsidetests/jvmti/run-tests/test-920/Android.mk
index f92ed94..678ded5 100644
--- a/hostsidetests/jvmti/run-tests/test-920/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-920/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest920HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-922/Android.mk b/hostsidetests/jvmti/run-tests/test-922/Android.mk
index 2de665a..aab0515 100644
--- a/hostsidetests/jvmti/run-tests/test-922/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-922/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest922HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-923/Android.mk b/hostsidetests/jvmti/run-tests/test-923/Android.mk
index dd1de3c..6bac152 100644
--- a/hostsidetests/jvmti/run-tests/test-923/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-923/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest923HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-924/Android.mk b/hostsidetests/jvmti/run-tests/test-924/Android.mk
index 28c4b89..c16350b 100644
--- a/hostsidetests/jvmti/run-tests/test-924/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-924/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest924HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-926/Android.mk b/hostsidetests/jvmti/run-tests/test-926/Android.mk
index fcd46ad..3ea1d85 100644
--- a/hostsidetests/jvmti/run-tests/test-926/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-926/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest926HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-927/Android.mk b/hostsidetests/jvmti/run-tests/test-927/Android.mk
index 939601c..98d5f2e 100644
--- a/hostsidetests/jvmti/run-tests/test-927/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-927/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest927HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-928/Android.mk b/hostsidetests/jvmti/run-tests/test-928/Android.mk
index 2eac8f9..6084806 100644
--- a/hostsidetests/jvmti/run-tests/test-928/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-928/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest928HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-930/Android.mk b/hostsidetests/jvmti/run-tests/test-930/Android.mk
index 2ac9ae2..10a3d18 100644
--- a/hostsidetests/jvmti/run-tests/test-930/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-930/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest930HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-931/Android.mk b/hostsidetests/jvmti/run-tests/test-931/Android.mk
index ae04387..063c6f5 100644
--- a/hostsidetests/jvmti/run-tests/test-931/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-931/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest931HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-932/Android.mk b/hostsidetests/jvmti/run-tests/test-932/Android.mk
index c952c86..198adae 100644
--- a/hostsidetests/jvmti/run-tests/test-932/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-932/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest932HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-940/Android.mk b/hostsidetests/jvmti/run-tests/test-940/Android.mk
index 4ed5dec..453dee0 100644
--- a/hostsidetests/jvmti/run-tests/test-940/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-940/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest940HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-942/Android.mk b/hostsidetests/jvmti/run-tests/test-942/Android.mk
index d2605b7..8a6657f 100644
--- a/hostsidetests/jvmti/run-tests/test-942/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-942/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest942HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-944/Android.mk b/hostsidetests/jvmti/run-tests/test-944/Android.mk
index 16f9c7f..b90c3e3 100644
--- a/hostsidetests/jvmti/run-tests/test-944/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-944/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest944HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-945/Android.mk b/hostsidetests/jvmti/run-tests/test-945/Android.mk
index e86d85e..754d7ca 100644
--- a/hostsidetests/jvmti/run-tests/test-945/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-945/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest945HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-947/Android.mk b/hostsidetests/jvmti/run-tests/test-947/Android.mk
index 4b4cead..6a612e2 100644
--- a/hostsidetests/jvmti/run-tests/test-947/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-947/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest947HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-951/Android.mk b/hostsidetests/jvmti/run-tests/test-951/Android.mk
index ba45b86..5a6d494 100644
--- a/hostsidetests/jvmti/run-tests/test-951/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-951/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest951HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-981/Android.mk b/hostsidetests/jvmti/run-tests/test-981/Android.mk
index 4bbc20a..151379b 100644
--- a/hostsidetests/jvmti/run-tests/test-981/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-981/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest981HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
diff --git a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk b/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
index ec8f7aa..88727c2 100644
--- a/hostsidetests/jvmti/run-tests/test-981/app/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-981/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/Android.mk b/hostsidetests/jvmti/run-tests/test-982/Android.mk
index 908adaf..154bc70 100644
--- a/hostsidetests/jvmti/run-tests/test-982/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-982/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest982HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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-984/Android.mk b/hostsidetests/jvmti/run-tests/test-984/Android.mk
index 3ddb2ad..1ff5f2e 100644
--- a/hostsidetests/jvmti/run-tests/test-984/Android.mk
+++ b/hostsidetests/jvmti/run-tests/test-984/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiRunTest984HostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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/tagging/Android.mk b/hostsidetests/jvmti/tagging/Android.mk
index 61e06a4..b5674cb 100644
--- a/hostsidetests/jvmti/tagging/Android.mk
+++ b/hostsidetests/jvmti/tagging/Android.mk
@@ -19,7 +19,7 @@
 LOCAL_MODULE := CtsJvmtiTaggingHostTestCases
 LOCAL_STATIC_JAVA_LIBRARIES := CtsJvmtiHostTestBase
 LOCAL_MODULE_TAGS := tests
-LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
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/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 e5becb5..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/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 c7bfcea..ff6a5c9 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 sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 
 # Must match the package name in CtsTestCaseList.mk
 LOCAL_MODULE := CtsSecurityHostTestCases
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index 7d5cc22..241a641 100755
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -18,7 +18,10 @@
     <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
         <option name="cleanup" value="true" />
         <option name="push" value="CVE-2016-8460->/data/local/tmp/CVE-2016-8460" />
+        <option name="push" value="CVE-2017-0403->/data/local/tmp/CVE-2017-0403" />
+        <option name="push" value="CVE-2017-0404->/data/local/tmp/CVE-2017-0404" />
         <option name="push" value="CVE-2016-8482->/data/local/tmp/CVE-2016-8482" />
+        <option name="push" value="CVE-2017-0429->/data/local/tmp/CVE-2017-0429" />
         <option name="push" value="CVE-2016-6730->/data/local/tmp/CVE-2016-6730" />
         <option name="push" value="CVE-2016-6731->/data/local/tmp/CVE-2016-6731" />
         <option name="push" value="CVE-2016-6732->/data/local/tmp/CVE-2016-6732" />
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6730/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6730/Android.mk
index 7857c6d..4db8837 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6730/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6730/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6731/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6731/Android.mk
index 569e2f1..c1d7cce 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6731/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6731/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6732/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6732/Android.mk
index a13ebee..7668ed3 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6732/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6732/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6733/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6733/Android.mk
index d8678fe..a4ac2cb 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6733/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6733/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6734/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6734/Android.mk
index e4ea88b..38667a1 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6734/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6734/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6735/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6735/Android.mk
index f7e3c14..37f8244 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6735/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6735/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-6736/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-6736/Android.mk
index e469e73..e9fcbfa 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-6736/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-6736/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8424/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8424/Android.mk
index 937ed4e..62f99fa 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8424/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8424/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8425/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8425/Android.mk
index af0f6f8..2a4e408 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8425/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8425/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8426/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8426/Android.mk
index f353a4f..721c434 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8426/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8426/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8427/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8427/Android.mk
index f946b5c..7c95d23 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8427/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8427/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8428/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8428/Android.mk
index cbb502f..dba5713 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8428/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8428/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8429/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8429/Android.mk
index 4b8692c..64c0273 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8429/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8429/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8430/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8430/Android.mk
index c9a6b17..72ec70b 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8430/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8430/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8431/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8431/Android.mk
index 1bd395f..9104c9e 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8431/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8431/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8432/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8432/Android.mk
index 689d179..fffa836 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8432/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8432/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8434/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8434/Android.mk
index daa9e8c..b862881 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8434/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8434/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8460/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8460/Android.mk
index 85e201a..6c05204 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8460/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8460/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/securityPatch/CVE-2016-8482/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-8482/Android.mk
index 20ba096..d4448e3 100644
--- a/hostsidetests/security/securityPatch/CVE-2016-8482/Android.mk
+++ b/hostsidetests/security/securityPatch/CVE-2016-8482/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 # Tag this module as a cts test artifact
-LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 LOCAL_CTS_TEST_PACKAGE := android.security.cts
 
 LOCAL_ARM_MODE := arm
diff --git a/hostsidetests/security/src/android/security/cts/SELinuxHostTest.java b/hostsidetests/security/src/android/security/cts/SELinuxHostTest.java
index cff9ef9..54f1a92 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,8 @@
  */
 public class SELinuxHostTest extends DeviceTestCase implements IBuildReceiver, IDeviceTest {
 
+    private static final Map<ITestDevice, File> cachedDevicePolicyFiles = new HashMap<>(1);
+
     private File sepolicyAnalyze;
     private File checkSeapp;
     private File checkFc;
@@ -133,10 +136,33 @@
         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);
+    }
+
+    // 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 {
+        // IMPLEMENTATION DETAILS: We cache the host-side policy file 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.
+        File file;
+        synchronized (cachedDevicePolicyFiles) {
+            file = cachedDevicePolicyFiles.get(device);
+        }
+        if (file != null) {
+            return file;
+        }
+        file = File.createTempFile("sepolicy", ".tmp");
+        file.deleteOnExit();
+        device.pullFile("/sys/fs/selinux/policy", file);
+        synchronized (cachedDevicePolicyFiles) {
+            cachedDevicePolicyFiles.put(device, file);
+        }
+        return file;
     }
 
     /**
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/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 8291c30..555ed36 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
@@ -81,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");
@@ -122,7 +122,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");
@@ -158,6 +158,7 @@
 
         final String logSeparator = clearLogcat();
         launchActivityInDockStack(LAUNCHING_ACTIVITY);
+
         getLaunchActivityBuilder().setToSide(true).setTargetActivityName(RESIZEABLE_ACTIVITY_NAME)
                 .execute();
         final ReportedSizes initialSizes = getActivityDisplaySize(RESIZEABLE_ACTIVITY_NAME,
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 d4ed056..a3faae6 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDisplayTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDisplayTests.java
@@ -1037,7 +1037,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/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/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..b7a2baf 100644
--- a/hostsidetests/sustainedperf/dhrystone/Android.mk
+++ b/hostsidetests/sustainedperf/dhrystone/Android.mk
@@ -14,5 +14,5 @@
 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/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/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/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..6eab01c
--- /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 tzdata_shared2-host tzdata_tools2-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/hostsidetests/tzdata/AndroidTest.xml b/hostsidetests/tzdata/AndroidTest.xml
new file mode 100644
index 0000000..1a2716e
--- /dev/null
+++ b/hostsidetests/tzdata/AndroidTest.xml
@@ -0,0 +1,21 @@
+<?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 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..c059e89
--- /dev/null
+++ b/hostsidetests/tzdata/src/com/android/cts/tzdata/TzDataCheckTest.java
@@ -0,0 +1,976 @@
+/*
+ * 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 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.shared2.DistroVersion;
+import libcore.tzdata.shared2.TimeZoneDistro;
+import libcore.tzdata.testing.ZoneInfoTestHelper;
+import libcore.tzdata.update2.tools.TimeZoneDistroBuilder;
+
+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 libcore.tzdata.update2.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 libcore.tzdata.update2.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 libcore.tzdata.update2.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 libcore.tzdata.update2.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);
+        TimeZoneDistro distro = createValidDistroBuilder().build();
+        unpackOnHost(dataCurrentDir, distro);
+
+        // 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);
+        TimeZoneDistro distro = createValidDistroBuilder().build();
+        unpackOnHost(dataStagedDir, distro);
+
+        // 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, distro);
+    }
+
+    // {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);
+        TimeZoneDistro stagedDistro = createValidDistroBuilder().build();
+        unpackOnHost(dataStagedDir, stagedDistro);
+
+        // 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, stagedDistro);
+    }
+
+    // {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);
+        TimeZoneDistro stagedDistro = createValidDistroBuilder()
+                .setDistroVersion(stagedDistroVersion)
+                .build();
+        unpackOnHost(dataStagedDir, stagedDistro);
+
+        // Create a current installed distro.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        TimeZoneDistro currentDistro = createValidDistroBuilder()
+                .setDistroVersion(currentDistroVersion)
+                .build();
+        unpackOnHost(dataCurrentDir, currentDistro);
+
+        // 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, stagedDistro);
+    }
+
+    // {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);
+        TimeZoneDistro stagedDistro = createValidDistroBuilder()
+                .clearVersionForTests()
+                .buildUnvalidated();
+        unpackOnHost(dataStagedDir, stagedDistro);
+
+        // Create a current installed distro.
+        PathPair dataCurrentDir = mDataDir.createSubPath(CURRENT_DIR_NAME);
+        TimeZoneDistro currentDistro = createValidDistroBuilder().build();
+        unpackOnHost(dataCurrentDir, currentDistro);
+
+        // 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);
+        TimeZoneDistro distroWithoutAVersionFile = createValidDistroBuilder()
+                .clearVersionForTests()
+                .buildUnvalidated();
+        unpackOnHost(dataCurrentDir, distroWithoutAVersionFile);
+
+        // 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().build());
+        // 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().build());
+
+        // 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);
+        TimeZoneDistro distro = createValidDistroBuilder()
+                .setDistroVersion(oldMajorDistroVersion)
+                .build();
+        unpackOnHost(dataCurrentDir, distro);
+
+        // 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);
+        TimeZoneDistro distro = createValidDistroBuilder()
+                .setDistroVersion(newMajorDistroVersion)
+                .build();
+        unpackOnHost(dataCurrentDir, distro);
+
+        // 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);
+        TimeZoneDistro distro = createValidDistroBuilder()
+                .setDistroVersion(oldMinorDistroVersion)
+                .build();
+        unpackOnHost(dataCurrentDir, distro);
+
+        // 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);
+        TimeZoneDistro distro = createValidDistroBuilder()
+                .setDistroVersion(newMajorDistroVersion)
+                .build();
+        unpackOnHost(dataCurrentDir, distro);
+
+        // 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, distro);
+    }
+
+    // {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);
+        TimeZoneDistro validDistro = createValidDistroBuilder().build();
+        unpackOnHost(dataCurrentDir, validDistro);
+
+        // 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, validDistro);
+    }
+
+    // {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);
+        TimeZoneDistro validDistro = createValidDistroBuilder().build();
+        unpackOnHost(dataCurrentDir, validDistro);
+
+        // 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, validDistro);
+    }
+
+    // {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);
+        TimeZoneDistro distro = createValidDistroBuilder()
+                .setDistroVersion(distroVersion)
+                .setTzDataFile(createValidTzDataBytes(distroRulesVersion))
+                .build();
+        unpackOnHost(dataCurrentDir, distro);
+
+        // 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, distro);
+    }
+
+    // {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);
+        TimeZoneDistro distro = createValidDistroBuilder()
+                .setDistroVersion(distroVersion)
+                .setTzDataFile(createValidTzDataBytes(systemRulesVersion))
+                .build();
+        unpackOnHost(dataCurrentDir, distro);
+
+        // 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, distro);
+    }
+
+    // {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);
+        TimeZoneDistro distro = createValidDistroBuilder()
+                .setDistroVersion(distroVersion)
+                .setTzDataFile(createValidTzDataBytes(distroRulesVersion))
+                .build();
+        unpackOnHost(dataCurrentDir, distro);
+
+        // 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, TimeZoneDistro distro) throws Exception {
+        createHostDirectory(path);
+        distro.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, TimeZoneDistro expectedDistro)
+            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, expectedDistro.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/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 7af9d90..d8da5ef 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 20a13c9..979023e 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 329eb15..c40f7aa 100644
--- a/tests/accessibilityservice/AndroidManifest.xml
+++ b/tests/accessibilityservice/AndroidManifest.xml
@@ -65,7 +65,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 aa30f77..ea5b9fb 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
@@ -26,6 +26,7 @@
 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;
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityMagnificationTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityMagnificationTest.java
index 122c9b8..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;
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 df487f1..fa6154e 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;
@@ -80,6 +81,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 */);
@@ -105,6 +111,7 @@
         finishActivity(mMaxAspectRatioResizeableActivity);
         finishActivity(mSdk25MaxAspectRatioActivity);
         finishActivity(mMaxAspectRatioUnsetActivity);
+        finishActivity(mMetaDataMaxAspectRatioActivity);
     }
 
     @Test
@@ -139,6 +146,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..9b4866f 100644
--- a/tests/aslr/Android.mk
+++ b/tests/aslr/Android.mk
@@ -33,6 +33,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/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..d6331e7 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..e6a078f 100644
--- a/tests/camera/libctscamera2jni/Android.mk
+++ b/tests/camera/libctscamera2jni/Android.mk
@@ -27,8 +27,6 @@
 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
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/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/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/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 d34e7af..7469190 100644
--- a/tests/jdwp/Android.mk
+++ b/tests/jdwp/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_MODULE_TAGS := tests
 
 # 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/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..7b5d733 100644
--- a/tests/libcore/luni/Android.mk
+++ b/tests/libcore/luni/Android.mk
@@ -46,13 +46,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..a6e378f 100644
--- a/tests/libcore/ojluni/Android.mk
+++ b/tests/libcore/ojluni/Android.mk
@@ -37,12 +37,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/Android.mk b/tests/libcore/wycheproof/Android.mk
new file mode 100644
index 0000000..c14da89
--- /dev/null
+++ b/tests/libcore/wycheproof/Android.mk
@@ -0,0 +1,51 @@
+# 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 := CtsLibcoreWycheproofTestCases
+
+LOCAL_STATIC_JAVA_LIBRARIES := \
+    cts-core-test-runner \
+    wycheproof
+
+LOCAL_JAVA_LIBRARIES := \
+    bouncycastle \
+    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/libcore/wycheproof/AndroidManifest.xml b/tests/libcore/wycheproof/AndroidManifest.xml
new file mode 100644
index 0000000..09b9da1
--- /dev/null
+++ b/tests/libcore/wycheproof/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?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.libcore.cts.wycheproof">
+    <uses-permission android:name="android.permission.INTERNET" />
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.libcore.cts.wycheproof"
+                     android:label="CTS Libcore Wycheproof test cases" />
+
+</manifest>
diff --git a/tests/libcore/wycheproof/AndroidTest.xml b/tests/libcore/wycheproof/AndroidTest.xml
new file mode 100644
index 0000000..2d303d2
--- /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 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="CtsLibcoreWycheproofTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.compatibility.testtype.LibcoreTest" >
+        <option name="package" value="android.libcore.cts.wycheproof" />
+        <!-- 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/BouncyCastleSupportProvider.java b/tests/libcore/wycheproof/src/android/libcore/cts/wycheproof/BouncyCastleSupportProvider.java
new file mode 100644
index 0000000..d6ab5c1
--- /dev/null
+++ b/tests/libcore/wycheproof/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/src/android/libcore/cts/wycheproof/BouncyCastleTest.java b/tests/libcore/wycheproof/src/android/libcore/cts/wycheproof/BouncyCastleTest.java
new file mode 100644
index 0000000..dfb71e8
--- /dev/null
+++ b/tests/libcore/wycheproof/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/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..bb26fc3 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 d21cd67..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/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/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/tests/accounts/Android.mk b/tests/tests/accounts/Android.mk
index 3f6ad38..a3c1f92 100644
--- a/tests/tests/accounts/Android.mk
+++ b/tests/tests/accounts/Android.mk
@@ -22,7 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
-    CtsAccountTestsCommon ctstestrunner
+    CtsAccountTestsCommon ctstestrunner legacy-android-test
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
@@ -35,7 +35,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/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..1d43a36 100644
--- a/tests/tests/bionic/Android.build.copy.libs.mk
+++ b/tests/tests/bionic/Android.build.copy.libs.mk
@@ -117,6 +117,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..b7ad767 100644
--- a/tests/tests/bionic/Android.mk
+++ b/tests/tests/bionic/Android.mk
@@ -39,15 +39,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..042e260 100644
--- a/tests/tests/calendarcommon/Android.mk
+++ b/tests/tests/calendarcommon/Android.mk
@@ -25,13 +25,13 @@
 # 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)
 
 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/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/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..1fcedf1 100644
--- a/tests/tests/dpi2/Android.mk
+++ b/tests/tests/dpi2/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/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/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/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..38111fc 100644
--- a/tests/tests/jni/Android.mk
+++ b/tests/tests/jni/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 android-support-test
 
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/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/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/src/android/media/cts/AdaptivePlaybackTest.java b/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
index 12432d6..2e7a848 100644
--- a/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
+++ b/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
@@ -204,7 +204,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/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index e80dcf4..35d2cd8 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;
@@ -1773,48 +1841,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 +1943,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 +1959,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/MediaSessionTest.java b/tests/tests/media/src/android/media/cts/MediaSessionTest.java
index 58a643d..bb1a501 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);
         }
     }
 
@@ -576,7 +615,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 +624,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 +635,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/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 d69f66e..79a26e3 100644
--- a/tests/tests/nativemedia/aaudio/Android.mk
+++ b/tests/tests/nativemedia/aaudio/Android.mk
@@ -41,7 +41,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..1a9fe43 100644
--- a/tests/tests/nativemedia/xa/Android.mk
+++ b/tests/tests/nativemedia/xa/Android.mk
@@ -41,6 +41,6 @@
 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/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/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/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/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/jni/Android.mk b/tests/tests/os/jni/Android.mk
index 2e4d707..d7da7e1 100644
--- a/tests/tests/os/jni/Android.mk
+++ b/tests/tests/os/jni/Android.mk
@@ -56,4 +56,6 @@
 	LOCAL_CFLAGS += -DARCH_SUPPORTS_SECCOMP
 endif
 
+LOCAL_CPPFLAGS_arm := -mcpu=generic
+
 include $(BUILD_SHARED_LIBRARY)
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/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/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 7ff1e70..219c6f9 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/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 7846dc2..485761f 100644
--- a/tests/tests/permission2/res/raw/android_manifest.xml
+++ b/tests/tests/permission2/res/raw/android_manifest.xml
@@ -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"
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..3b71035 100644
--- a/tests/tests/provider/Android.mk
+++ b/tests/tests/provider/Android.mk
@@ -26,7 +26,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 telephony-common
 
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 d1bad79..f57af32 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/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/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/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/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 8db55d5..7cd73a2 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 sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 
 include $(BUILD_CTS_PACKAGE)
 
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/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/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/selinux/selinuxTargetSdk/Android.mk b/tests/tests/selinux/selinuxTargetSdk/Android.mk
index cfbe04c..138da59 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 \
+    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..80c5e55 100644
--- a/tests/tests/simpleperf/Android.mk
+++ b/tests/tests/simpleperf/Android.mk
@@ -44,7 +44,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 db278de..f3c54b3 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..58b6afd 100644
--- a/tests/tests/telephony/Android.mk
+++ b/tests/tests/telephony/Android.mk
@@ -36,7 +36,7 @@
 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/AndroidTest.xml b/tests/tests/telephony/AndroidTest.xml
index 0aebd01..70f0147 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" />
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 1e18760..f93b297 100644
--- a/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java
@@ -194,9 +194,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/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..8cc6a49 100644
--- a/tests/tests/transition/Android.mk
+++ b/tests/tests/transition/Android.mk
@@ -31,13 +31,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/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/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/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..eb801a1 100644
--- a/tests/tests/wrap/nowrap/Android.mk
+++ b/tests/tests/wrap/nowrap/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_PACKAGE_NAME := CtsWrapNoWrapTestCases
diff --git a/tests/tests/wrap/wrap_debug/Android.mk b/tests/tests/wrap/wrap_debug/Android.mk
index 2bfb7a5..e955115 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
diff --git a/tests/tests/wrap/wrap_nodebug/Android.mk b/tests/tests/wrap/wrap_nodebug/Android.mk
index 799030d..c4fb53f 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
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 c8fcef3..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 7479275..0e91b4b 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;
 
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..9fd01b1 100644
--- a/tests/vr/src/android/vr/cts/VrSetFIFOThreadTest.java
+++ b/tests/vr/src/android/vr/cts/VrSetFIFOThreadTest.java
@@ -69,7 +69,7 @@
     }
 
     public void testSetVrThreadAPISuccess() throws Throwable {
-        setIntent(1, 1, 0, 0);
+        setIntent(OpenGLESActivity.RENDERER_BASIC, 1, 0, 0);
         ComponentName requestedComponent = new ComponentName(mContext, MockVrListenerService.class);
         Settings.Secure.putString(mContext.getContentResolver(),
             ENABLED_VR_LISTENERS,
@@ -92,7 +92,7 @@
     }
 
     public void testSetVrThreadAPIFailure() throws Throwable {
-        setIntent(1, 1, 0, 0);
+        setIntent(OpenGLESActivity.RENDERER_BASIC, 1, 0, 0);
         ComponentName requestedComponent = new ComponentName(mContext, MockVrListenerService.class);
         Settings.Secure.putString(mContext.getContentResolver(),
             ENABLED_VR_LISTENERS,
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..fb82c95 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;
@@ -264,9 +263,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 ee1b060..717b181 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 sts
+LOCAL_COMPATIBILITY_SUITE := cts general-tests sts
 
 include $(BUILD_CTS_DEVICE_INFO_PACKAGE)
 
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/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 5b9fc0e..f44d20a 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" />
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..a0794aa 100644
--- a/tools/vm-tests-tf/Android.mk
+++ b/tools/vm-tests-tf/Android.mk
@@ -25,7 +25,7 @@
 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)
@@ -68,11 +68,13 @@
 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)
+vmteststf_dep_jars := \
+    $(HOST_JDK_TOOLS_JAR) \
+    $(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)
 
@@ -86,7 +88,7 @@
 $(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_CLASS_PATH := $(call normalize-path-list, $(vmteststf_dep_jars))
 $(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
@@ -94,7 +96,9 @@
 	$(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) \
+	$(hide) java \
+	    $(if $(EXPERIMENTAL_USE_OPENJDK9),--add-exports jdk.jartool/sun.tools.jar=ALL-UNNAMED) \
+	    -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)"
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/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)