Merge "Fix the display of not_executed test"
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index 77f70e7..9defdf3 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -1,5 +1,10 @@
 [Hook Scripts]
-checkstyle_hook = ../development/tools/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
+checkstyle_hook = ${REPO_ROOT}/development/tools/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
                   -fw apps/CtsVerifier/src/com/android/cts/verifier/usb/
                       apps/CtsVerifierUSBCompanion/
+                      tests/tests/animation/
                       tests/tests/print/
+                      tests/tests/text/
+                      tests/tests/transition/
+                      tests/tests/view/
+                      tests/tests/widget/
diff --git a/apps/CameraITS/tests/scene1/test_capture_result.py b/apps/CameraITS/tests/scene1/test_capture_result.py
index ec919f8..cde37c2 100644
--- a/apps/CameraITS/tests/scene1/test_capture_result.py
+++ b/apps/CameraITS/tests/scene1/test_capture_result.py
@@ -77,11 +77,11 @@
         h_map = props["android.lens.info.shadingMapSize"]["height"]
 
         print "Testing auto capture results"
-        lsc_map_auto = test_auto(cam, w_map, h_map)
+        lsc_map_auto = test_auto(cam, w_map, h_map, props)
         print "Testing manual capture results"
-        test_manual(cam, w_map, h_map, lsc_map_auto)
+        test_manual(cam, w_map, h_map, lsc_map_auto, props)
         print "Testing auto capture results again"
-        test_auto(cam, w_map, h_map)
+        test_auto(cam, w_map, h_map, props)
 
 # A very loose definition for two floats being close to each other;
 # there may be different interpolation and rounding used to get the
@@ -105,7 +105,7 @@
         ax.plot_wireframe(xs, ys, zs)
         matplotlib.pyplot.savefig("%s_plot_lsc_%s_ch%d.png"%(NAME,name,ch))
 
-def test_auto(cam, w_map, h_map):
+def test_auto(cam, w_map, h_map, props):
     # Get 3A lock first, so the auto values in the capture result are
     # populated properly.
     rect = [[0,0,1,1,1]]
@@ -124,9 +124,12 @@
     print "Gains:", gains
     print "Transform:", [its.objects.rational_to_float(t)
                          for t in transform]
-    print "AE region:", cap_res['android.control.aeRegions']
-    print "AF region:", cap_res['android.control.afRegions']
-    print "AWB region:", cap_res['android.control.awbRegions']
+    if props["android.control.maxRegionsAe"] > 0:
+        print "AE region:", cap_res['android.control.aeRegions']
+    if props["android.control.maxRegionsAf"] > 0:
+        print "AF region:", cap_res['android.control.afRegions']
+    if props["android.control.maxRegionsAwb"] > 0:
+        print "AWB region:", cap_res['android.control.awbRegions']
     print "LSC map:", w_map, h_map, lsc_map[:8]
 
     assert(ctrl_mode == 1)
@@ -154,7 +157,7 @@
 
     return lsc_map
 
-def test_manual(cam, w_map, h_map, lsc_map_auto):
+def test_manual(cam, w_map, h_map, lsc_map_auto, props):
     cap = cam.do_capture(manual_req)
     cap_res = cap["metadata"]
 
@@ -172,9 +175,12 @@
     print "Transform:", [its.objects.rational_to_float(t)
                          for t in transform]
     print "Tonemap:", curves[0][1::16]
-    print "AE region:", cap_res['android.control.aeRegions']
-    print "AF region:", cap_res['android.control.afRegions']
-    print "AWB region:", cap_res['android.control.awbRegions']
+    if props["android.control.maxRegionsAe"] > 0:
+        print "AE region:", cap_res['android.control.aeRegions']
+    if props["android.control.maxRegionsAf"] > 0:
+        print "AF region:", cap_res['android.control.afRegions']
+    if props["android.control.maxRegionsAwb"] > 0:
+        print "AWB region:", cap_res['android.control.awbRegions']
     print "LSC map:", w_map, h_map, lsc_map[:8]
 
     assert(ctrl_mode == 0)
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index d49f279..df9d8f3 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -1055,7 +1055,7 @@
             <meta-data android:name="test_required_features" android:value="android.hardware.location.gps" />
         </activity>
 
-        <activity android:name=".location.GnssStatusTestsActivity"
+        <!--  activity android:name=".location.GnssStatusTestsActivity"
             android:label="@string/location_gnss_status_test"
             android:screenOrientation="locked">
             <intent-filter>
@@ -1064,7 +1064,7 @@
             </intent-filter>
             <meta-data android:name="test_category" android:value="@string/test_category_hardware"/>
             <meta-data android:name="test_required_features" android:value="android.hardware.location.gps" />
-        </activity>
+        </activity -->
 
         <activity android:name=".location.LocationListenerActivity"
                 android:label="@string/location_listener_activity"
diff --git a/hostsidetests/devicepolicy/AndroidTest.xml b/hostsidetests/devicepolicy/AndroidTest.xml
index 48b3b5b..bb0a13e 100644
--- a/hostsidetests/devicepolicy/AndroidTest.xml
+++ b/hostsidetests/devicepolicy/AndroidTest.xml
@@ -14,6 +14,18 @@
      limitations under the License.
 -->
 <configuration description="Config for the CTS Device Policy host tests">
+
+    <!-- Push the list of public APIs to device -->
+    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
+        <option name="run-command" value="mkdir -p /data/local/tmp/device-policy-test" />
+        <option name="teardown-command" value="rm -rf /data/local/tmp/device-policy-test" />
+    </target_preparer>
+    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
+        <!-- The source file current.api is prepared by //cts/tests/signature/api/Android.mk -->
+        <!-- The target path should be consistent with CurrentApiHelper#CURRENT_API_FILE -->
+        <option name="push" value="current.api->/data/local/tmp/device-policy-test/current.api" />
+    </target_preparer>
+
     <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
         <option name="jar" value="CtsDevicePolicyManagerTestCases.jar" />
         <option name="runtime-hint" value="31m41s" />
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk b/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
index 7003012..109804a 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
@@ -27,7 +27,7 @@
 LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit
 
 LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 ctstestrunner compatibility-device-util \
-	ub-uiautomator android-support-test
+	ub-uiautomator android-support-test guava
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CurrentApiHelper.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CurrentApiHelper.java
new file mode 100644
index 0000000..550f1d3
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CurrentApiHelper.java
@@ -0,0 +1,202 @@
+/*
+ * 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 com.android.cts.managedprofile;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.primitives.Primitives;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import java.io.File;
+import java.lang.reflect.Method;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+/**
+ * Helper class for retrieving the current list of API methods.
+ */
+public class CurrentApiHelper {
+
+    /**
+     * Location of the XML file that lists the current public APIs.
+     *
+     * <p><b>Note:</b> must be consistent with
+     * {@code cts/hostsidetests/devicepolicy/AndroidTest.xml}
+     */
+    private static final String CURRENT_API_FILE = "/data/local/tmp/device-policy-test/current.api";
+
+    private static final String LOG_TAG = "CurrentApiHelper";
+
+    private static final ImmutableMap<String, Class> PRIMITIVE_TYPES = getPrimitiveTypes();
+    private static final ImmutableMap<String, String> PRIMITIVE_ENCODINGS =
+            new ImmutableMap.Builder<String, String>()
+                    .put("boolean", "Z")
+                    .put("byte", "B")
+                    .put("char", "C")
+                    .put("double", "D")
+                    .put("float", "F")
+                    .put("int", "I")
+                    .put("long", "J")
+                    .put("short", "S")
+                    .build();
+
+    private static final String TAG_PACKAGE = "package";
+    private static final String TAG_CLASS = "class";
+    private static final String TAG_METHOD = "method";
+    private static final String TAG_PARAMETER = "parameter";
+
+    private static final String ATTRIBUTE_NAME = "name";
+    private static final String ATTRIBUTE_TYPE = "type";
+
+    /**
+     * Get public API methods of a specific class as defined in the API document.
+     *
+     * @param packageName The name of the package containing the class, e.g. {@code android.app}.
+     * @param className The name of the class, e.g. {@code Application}.
+     * @return an immutable list of {@link Method} instances.
+     */
+    public static ImmutableList<Method> getPublicApis(String packageName, String className)
+            throws Exception {
+        Document apiDocument = parseXmlFile(CURRENT_API_FILE);
+        Element rootElement = apiDocument.getDocumentElement();
+        Element packageElement = getChildElementByName(rootElement, TAG_PACKAGE, packageName);
+        Element classElement = getChildElementByName(packageElement, TAG_CLASS, className);
+
+        ImmutableList.Builder<Method> builder = new ImmutableList.Builder<>();
+
+        NodeList nodes = classElement.getElementsByTagName(TAG_METHOD);
+        if (nodes != null && nodes.getLength() > 0) {
+            Class clazz = Class.forName(packageName + "." + className);
+
+            for (int i = 0; i < nodes.getLength(); ++i) {
+                Element element = (Element) nodes.item(i);
+                String name = element.getAttribute(ATTRIBUTE_NAME);
+                Class[] paramTypes = getParamTypes(element);
+                builder.add(clazz.getMethod(name, paramTypes));
+            }
+        }
+
+        return builder.build();
+    }
+
+    /**
+     * Given a {@link Class} object, get the default value if the {@link Class} refers to a
+     * primitive type, or null if it refers to an object.
+     *
+     * <p><ul>
+     *     <li>For boolean type, return {@code false}
+     *     <li>For other primitive types, return {@code 0}
+     *     <li>For all other types, return {@code null}
+     * </ul>
+     * @param clazz The desired class to instantiate.
+     * @return Default instance as described above.
+     */
+    public static Object instantiate(Class clazz) {
+        if (clazz.isPrimitive()) {
+            if (boolean.class.equals(clazz)) {
+                return false;
+            } else {
+                return 0;
+            }
+        } else {
+            return null;
+        }
+    }
+
+    private static Document parseXmlFile(String filePath) throws Exception {
+        File apiFile = new File(filePath);
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        Document dom = db.parse(apiFile.toURI().toString());
+
+        return dom;
+    }
+
+    private static Element getChildElementByName(Element parent,
+            String childTag, String childName) {
+        NodeList nodeList = parent.getElementsByTagName(childTag);
+        if (nodeList != null && nodeList.getLength() > 0) {
+            for (int i = 0; i < nodeList.getLength(); ++i) {
+                Element el = (Element) nodeList.item(i);
+                if (childName.equals(el.getAttribute(ATTRIBUTE_NAME))) {
+                    return el;
+                }
+            }
+        }
+        return null;
+    }
+
+    private static Class[] getParamTypes(Element methodElement) throws Exception {
+        NodeList nodes = methodElement.getElementsByTagName(TAG_PARAMETER);
+        if (nodes != null && nodes.getLength() > 0) {
+            int paramCount = nodes.getLength();
+            Class[] paramTypes = new Class[paramCount];
+            for (int i = 0; i < paramCount; ++i) {
+                String typeName = ((Element) nodes.item(i)).getAttribute(ATTRIBUTE_TYPE);
+                paramTypes[i] = getClassByName(typeName);
+            }
+            return paramTypes;
+        } else {
+            return new Class[0];
+        }
+    }
+
+    private static Class getClassByName(String typeName) throws ClassNotFoundException {
+        // Check if typeName represents an array
+        int arrayDim = 0;
+        while (typeName.endsWith("[]")) {
+            arrayDim++;
+            typeName = typeName.substring(0, typeName.length() - 2);
+        }
+
+        // Remove type parameters, if any
+        typeName = typeName.replaceAll("<.*>$", "");
+
+        if (arrayDim == 0) {
+            if (isPrimitiveTypeName(typeName)) {
+                return PRIMITIVE_TYPES.get(typeName);
+            } else {
+                return Class.forName(typeName);
+            }
+
+        } else {
+            String prefix = Strings.repeat("[", arrayDim);
+            if (isPrimitiveTypeName(typeName)) {
+                return Class.forName(prefix + PRIMITIVE_ENCODINGS.get(typeName));
+            } else {
+                return Class.forName(prefix + "L" + typeName + ";");
+            }
+        }
+    }
+
+    private static ImmutableMap<String, Class> getPrimitiveTypes() {
+        ImmutableMap.Builder<String, Class> builder = new ImmutableMap.Builder<>();
+        for (Class type : Primitives.allPrimitiveTypes()) {
+            builder.put(type.getName(), type);
+        }
+        return builder.build();
+    }
+
+    private static boolean isPrimitiveTypeName(String typeName) {
+        return PRIMITIVE_TYPES.containsKey(typeName);
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CurrentApiHelperTest.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CurrentApiHelperTest.java
new file mode 100644
index 0000000..c858677
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/CurrentApiHelperTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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 com.android.cts.managedprofile;
+
+import static com.android.cts.managedprofile.CurrentApiHelper.getPublicApis;
+import static com.android.cts.managedprofile.CurrentApiHelper.instantiate;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.test.AndroidTestCase;
+
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Tests for {@link CurrentApiHelper}.
+ */
+public class CurrentApiHelperTest extends AndroidTestCase {
+
+    private Class<DevicePolicyManager> mClazz;
+    private Set<Method> mPublicApis;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+        mClazz = DevicePolicyManager.class;
+        String testPackage = mClazz.getPackage().getName();
+        String testClass = mClazz.getSimpleName();
+        mPublicApis = new HashSet<>(getPublicApis(testPackage, testClass));
+        assertTrue(mPublicApis.size() > 0);
+    }
+
+    /**
+     * Test: {@link CurrentApiHelper#getPublicApis} includes public API methods.
+     */
+    public void testGetPublicApisIncludeMethods() throws Exception {
+        Method publicMethod = mClazz.getMethod("lockNow");
+        assertTrue(mPublicApis.contains(publicMethod));
+        publicMethod = mClazz.getMethod("isProfileOwnerApp", String.class);
+        assertTrue(mPublicApis.contains(publicMethod));
+        publicMethod = mClazz.getMethod("resetPassword", String.class, int.class);
+        assertTrue(mPublicApis.contains(publicMethod));
+        publicMethod = mClazz.getMethod("hasGrantedPolicy", ComponentName.class, int.class);
+        assertTrue(mPublicApis.contains(publicMethod));
+        publicMethod = mClazz.getMethod("installCaCert", ComponentName.class, Class.forName("[B"));
+        assertTrue(mPublicApis.contains(publicMethod));
+    }
+
+    /**
+     * Test: {@link CurrentApiHelper#getPublicApis} excludes private, hidden or {@code @SystemApi}
+     * methods.
+     */
+    public void testGetPublicApisExcludeMethods() throws Exception {
+        Method privateMethod = mClazz.getDeclaredMethod("throwIfParentInstance", String.class);
+        assertFalse(mPublicApis.contains(privateMethod));
+        Method hiddenMethod = mClazz.getMethod("isDeviceProvisioned");
+        assertFalse(mPublicApis.contains(hiddenMethod));
+        Method systemMethod = mClazz.getMethod("getProfileOwnerNameAsUser", int.class);
+        assertFalse(mPublicApis.contains(systemMethod));
+    }
+
+    /** Test for {@link CurrentApiHelper#instantiate}. */
+    public void testInstantiate() {
+        assertEquals(false, instantiate(boolean.class));
+        assertEquals(0, instantiate(byte.class));
+        assertEquals(0, instantiate(char.class));
+        assertEquals(0, instantiate(double.class));
+        assertEquals(0, instantiate(float.class));
+        assertEquals(0, instantiate(int.class));
+        assertEquals(0, instantiate(long.class));
+        assertEquals(0, instantiate(short.class));
+        assertNull(instantiate(String.class));
+        assertNull(instantiate(Integer.class));
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ParentProfileTest.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ParentProfileTest.java
new file mode 100644
index 0000000..7e942d8
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ParentProfileTest.java
@@ -0,0 +1,139 @@
+/*
+ * 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 com.android.cts.managedprofile;
+
+import android.app.admin.DevicePolicyManager;
+import android.util.Log;
+
+import com.google.common.collect.ImmutableSet;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Tests related to the parent profile of a managed profile.
+ *
+ * The parent profile is obtained by
+ * {@link android.app.admin.DevicePolicyManager#getParentProfileInstance}.
+ */
+public class ParentProfileTest extends BaseManagedProfileTest {
+
+    /**
+     * A whitelist of public API methods in {@link android.app.admin.DevicePolicyManager}
+     * that are supported on a parent profile.
+     */
+    public static final ImmutableSet<String> SUPPORTED_APIS = new ImmutableSet.Builder<String>()
+            .add("getPasswordQuality")
+            .add("setPasswordQuality")
+            .add("getPasswordMinimumLength")
+            .add("setPasswordMinimumLength")
+            .add("getPasswordMinimumUpperCase")
+            .add("setPasswordMinimumUpperCase")
+            .add("getPasswordMinimumLowerCase")
+            .add("setPasswordMinimumLowerCase")
+            .add("getPasswordMinimumLetters")
+            .add("setPasswordMinimumLetters")
+            .add("getPasswordMinimumNumeric")
+            .add("setPasswordMinimumNumeric")
+            .add("getPasswordMinimumSymbols")
+            .add("setPasswordMinimumSymbols")
+            .add("getPasswordMinimumNonLetter")
+            .add("setPasswordMinimumNonLetter")
+            .add("getPasswordHistoryLength")
+            .add("setPasswordHistoryLength")
+            .add("getPasswordExpirationTimeout")
+            .add("setPasswordExpirationTimeout")
+            .add("getPasswordExpiration")
+            .add("getPasswordMaximumLength")
+            .add("isActivePasswordSufficient")
+            .add("getCurrentFailedPasswordAttempts")
+            .add("getMaximumFailedPasswordsForWipe")
+            .add("setMaximumFailedPasswordsForWipe")
+            .add("getMaximumTimeToLock")
+            .add("setMaximumTimeToLock")
+            .add("lockNow")
+            .add("getKeyguardDisabledFeatures")
+            .add("setKeyguardDisabledFeatures")
+            .add("getTrustAgentConfiguration")
+            .add("setTrustAgentConfiguration")
+            .build();
+
+    private static final String LOG_TAG = "ParentProfileTest";
+
+    private static final String PACKAGE_NAME = DevicePolicyManager.class.getPackage().getName();
+    private static final String CLASS_NAME = DevicePolicyManager.class.getSimpleName();
+
+    /**
+     * Verify that all public API methods of {@link android.app.admin.DevicePolicyManager},
+     * except those explicitly whitelisted in {@link #SUPPORTED_APIS},
+     * throw a {@link SecurityException} when called on a parent profile.
+     *
+     * <p><b>Note:</b> System API methods (i.e. those with the
+     * {@link android.annotation.SystemApi} annotation) are NOT tested.
+     */
+    public void testParentProfileApiDisabled() throws Exception {
+        List<Method> methods = CurrentApiHelper.getPublicApis(PACKAGE_NAME, CLASS_NAME);
+        assertValidMethodNames(SUPPORTED_APIS, methods);
+
+        boolean failed = false;
+
+        for (Method method : methods) {
+            String methodName = method.getName();
+            if (SUPPORTED_APIS.contains(methodName)) {
+                continue;
+            }
+
+            try {
+                int paramCount = method.getParameterCount();
+                Object[] params = new Object[paramCount];
+                Class[] paramTypes = method.getParameterTypes();
+                for (int i = 0; i < paramCount; ++i) {
+                    params[i] = CurrentApiHelper.instantiate(paramTypes[i]);
+                }
+                method.invoke(mParentDevicePolicyManager, params);
+
+            } catch (InvocationTargetException e) {
+                if (e.getCause() instanceof SecurityException) {
+                    // Method throws SecurityException as expected
+                    continue;
+                } else {
+                    Log.e(LOG_TAG, e.getMessage(), e);
+                }
+            }
+
+            // Either no exception is thrown, or the exception thrown is not a SecurityException
+            failed = true;
+            Log.e(LOG_TAG, methodName + " failed to throw SecurityException");
+        }
+
+        assertFalse("Some method(s) failed to throw SecurityException", failed);
+    }
+
+    private void assertValidMethodNames(Collection<String> names, Collection<Method> allMethods) {
+        Set<String> allNames = allMethods.stream()
+                .map(Method::getName)
+                .collect(Collectors.toSet());
+
+        for (String name : names) {
+            assertTrue(name + " is not found in the API list", allNames.contains(name));
+        }
+    }
+}
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
index 5909920..4cbcd7b 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
@@ -321,6 +321,21 @@
         }
     }
 
+    /** Tests for the API helper class. */
+    public void testCurrentApiHelper() throws Exception {
+        assertTrue(runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".CurrentApiHelperTest",
+                mProfileUserId));
+    }
+
+    /** Test: unsupported public APIs are disabled on a parent profile. */
+    public void testParentProfileApiDisabled() throws Exception {
+        if (!mHasFeature) {
+            return;
+        }
+        assertTrue(runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".ParentProfileTest",
+                "testParentProfileApiDisabled", mProfileUserId));
+    }
+
     // TODO: This test is not specific to managed profiles, but applies to multi-user in general.
     // Move it to a MultiUserTest class when there is one. Should probably move
     // SetPolicyActivity to a more generic apk too as it might be useful for different kinds
diff --git a/tests/app/src/android/app/cts/NotificationChannelTest.java b/tests/app/src/android/app/cts/NotificationChannelTest.java
index 7cdbb6e..943f0bf 100644
--- a/tests/app/src/android/app/cts/NotificationChannelTest.java
+++ b/tests/app/src/android/app/cts/NotificationChannelTest.java
@@ -16,7 +16,6 @@
 
 package android.app.cts;
 
-import android.app.Notification;
 import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.net.Uri;
@@ -32,23 +31,26 @@
 
     public void testDescribeContents() {
         final int expected = 0;
-        NotificationChannel channel = new NotificationChannel("1", "1");
+        NotificationChannel channel =
+                new NotificationChannel("1", "1", NotificationManager.IMPORTANCE_DEFAULT);
         assertEquals(expected, channel.describeContents());
     }
 
     public void testConstructor() {
-        NotificationChannel channel = new NotificationChannel("1", "one");
+        NotificationChannel channel =
+                new NotificationChannel("1", "one", NotificationManager.IMPORTANCE_DEFAULT);
         assertEquals("1", channel.getId());
         assertEquals("one", channel.getName());
         assertEquals(false, channel.canBypassDnd());
         assertEquals(false, channel.shouldShowLights());
         assertEquals(false, channel.shouldVibrate());
-        assertEquals(NotificationManager.IMPORTANCE_UNSPECIFIED, channel.getImportance());
-        assertEquals(null, channel.getDefaultRingtone());
+        assertEquals(NotificationManager.IMPORTANCE_DEFAULT, channel.getImportance());
+        assertEquals(null, channel.getRingtone());
     }
 
     public void testWriteToParcel() {
-        NotificationChannel channel = new NotificationChannel("1", "one");
+        NotificationChannel channel =
+                new NotificationChannel("1", "one", NotificationManager.IMPORTANCE_DEFAULT);
         Parcel parcel = Parcel.obtain();
         channel.writeToParcel(parcel, 0);
         parcel.setDataPosition(0);
@@ -57,7 +59,8 @@
     }
 
     public void testLights() {
-        NotificationChannel channel = new NotificationChannel("1", "one");
+        NotificationChannel channel =
+                new NotificationChannel("1", "one", NotificationManager.IMPORTANCE_DEFAULT);
         channel.setLights(true);
         assertTrue(channel.shouldShowLights());
         channel.setLights(false);
@@ -65,7 +68,8 @@
     }
 
     public void testVibration() {
-        NotificationChannel channel = new NotificationChannel("1", "one");
+        NotificationChannel channel =
+                new NotificationChannel("1", "one", NotificationManager.IMPORTANCE_DEFAULT);
         channel.setVibration(true);
         assertTrue(channel.shouldVibrate());
         channel.setVibration(false);
@@ -75,8 +79,9 @@
     public void testRingtone() {
         Uri expected = new Uri.Builder().scheme("fruit").appendQueryParameter("favorite", "bananas")
                 .build();
-        NotificationChannel channel = new NotificationChannel("1", "one");
-        channel.setDefaultRingtone(expected);
-        assertEquals(expected, channel.getDefaultRingtone());
+        NotificationChannel channel =
+                new NotificationChannel("1", "one", NotificationManager.IMPORTANCE_DEFAULT);
+        channel.setRingtone(expected);
+        assertEquals(expected, channel.getRingtone());
     }
 }
diff --git a/tests/app/src/android/app/cts/NotificationManagerTest.java b/tests/app/src/android/app/cts/NotificationManagerTest.java
index bb005fa..672e5af 100644
--- a/tests/app/src/android/app/cts/NotificationManagerTest.java
+++ b/tests/app/src/android/app/cts/NotificationManagerTest.java
@@ -22,6 +22,7 @@
 import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
+import android.net.Uri;
 import android.provider.Telephony.Threads;
 import android.service.notification.NotificationListenerService;
 import android.service.notification.StatusBarNotification;
@@ -52,20 +53,29 @@
     }
 
     public void testCreateChannel() {
-        NotificationChannel channel = new NotificationChannel("id", "name");
+        NotificationChannel channel =
+                new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_DEFAULT);
+        channel.setVibration(true);
+        channel.setRingtone(new Uri.Builder().scheme("test").build());
+        channel.setLights(true);
+        channel.setBypassDnd(true);
+        channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
         try {
             mNotificationManager.createNotificationChannel(channel);
-            assertEquals(channel, mNotificationManager.getNotificationChannel(channel.getId()));
+            NotificationChannel created =
+                    mNotificationManager.getNotificationChannel(channel.getId());
+            compareChannels(channel, created);
         } finally {
             mNotificationManager.deleteNotificationChannel(channel.getId());
         }
     }
 
     public void testCreateChannelAlreadyExists() {
-        NotificationChannel channel = new NotificationChannel("id", "name");
+        NotificationChannel channel =
+                new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_DEFAULT);
         try {
             mNotificationManager.createNotificationChannel(channel);
-            assertEquals(channel, mNotificationManager.getNotificationChannel(channel.getId()));
+            compareChannels(channel, mNotificationManager.getNotificationChannel(channel.getId()));
             try {
                 mNotificationManager.createNotificationChannel(channel);
                 fail("Created channel with duplicate id");
@@ -77,19 +87,28 @@
         }
     }
 
+    public void testCreateChannelInvalidImportance() {
+        NotificationChannel channel =
+                new NotificationChannel("id2", "name", NotificationManager.IMPORTANCE_UNSPECIFIED);
+        try {
+            mNotificationManager.createNotificationChannel(channel);
+        } catch (IllegalArgumentException e) {
+            //success
+        }
+    }
+
     public void testDeleteChannel() {
-        NotificationChannel channel = new NotificationChannel("id", "name");
+        NotificationChannel channel =
+                new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_LOW);
         mNotificationManager.createNotificationChannel(channel);
-        assertEquals(channel, mNotificationManager.getNotificationChannel(channel.getId()));
+        compareChannels(channel, mNotificationManager.getNotificationChannel(channel.getId()));
         mNotificationManager.deleteNotificationChannel(channel.getId());
         assertNull(mNotificationManager.getNotificationChannel(channel.getId()));
     }
 
     public void testCannotDeleteDefaultChannel() {
-        NotificationChannel channel =
-                new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name");
         try {
-            mNotificationManager.deleteNotificationChannel(channel.getId());
+            mNotificationManager.deleteNotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID);
             fail("Deleted default channel");
         } catch (IllegalArgumentException e) {
             //success
@@ -97,20 +116,28 @@
     }
 
     public void testGetChannel() {
-        NotificationChannel channel1 = new NotificationChannel("id", "name");
-        NotificationChannel channel2 = new NotificationChannel("id2", "name2");
-        NotificationChannel channel3 = new NotificationChannel("id3", "name3");
-        NotificationChannel channel4 = new NotificationChannel("id4", "name4");
+        NotificationChannel channel1 =
+                new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_DEFAULT);
+        NotificationChannel channel2 =
+                new NotificationChannel("id2", "name2", NotificationManager.IMPORTANCE_HIGH);
+        NotificationChannel channel3 =
+                new NotificationChannel("id3", "name3", NotificationManager.IMPORTANCE_LOW);
+        NotificationChannel channel4 =
+                new NotificationChannel("id4", "name4", NotificationManager.IMPORTANCE_MIN);
         try {
             mNotificationManager.createNotificationChannel(channel1);
             mNotificationManager.createNotificationChannel(channel2);
             mNotificationManager.createNotificationChannel(channel3);
             mNotificationManager.createNotificationChannel(channel4);
 
-            assertEquals(channel2, mNotificationManager.getNotificationChannel(channel2.getId()));
-            assertEquals(channel3, mNotificationManager.getNotificationChannel(channel3.getId()));
-            assertEquals(channel1, mNotificationManager.getNotificationChannel(channel1.getId()));
-            assertEquals(channel4, mNotificationManager.getNotificationChannel(channel4.getId()));
+            compareChannels(channel2,
+                    mNotificationManager.getNotificationChannel(channel2.getId()));
+            compareChannels(channel3,
+                    mNotificationManager.getNotificationChannel(channel3.getId()));
+            compareChannels(channel1,
+                    mNotificationManager.getNotificationChannel(channel1.getId()));
+            compareChannels(channel4,
+                    mNotificationManager.getNotificationChannel(channel4.getId()));
         } finally {
             mNotificationManager.deleteNotificationChannel(channel1.getId());
             mNotificationManager.deleteNotificationChannel(channel2.getId());
@@ -119,28 +146,6 @@
         }
     }
 
-    public void testUpdateChannel() {
-        NotificationChannel channel = new NotificationChannel("id", "name");
-        try {
-            mNotificationManager.createNotificationChannel(channel);
-            channel.setLights(true);
-            mNotificationManager.updateNotificationChannel(channel);
-            assertEquals(channel, mNotificationManager.getNotificationChannel(channel.getId()));
-        } finally {
-            mNotificationManager.deleteNotificationChannel(channel.getId());
-        }
-    }
-
-    public void testUpdateChannelDoesNotExist() {
-        try {
-            mNotificationManager.updateNotificationChannel(
-                    new NotificationChannel("blah", "blahname"));
-            fail("Update on non existent channel succeeded");
-        } catch (IllegalArgumentException e){
-            // pass
-        }
-    }
-
     public void testNotify() {
         mNotificationManager.cancelAll();
 
@@ -235,4 +240,15 @@
         }
         return found == shouldExist;
     }
+
+    private void compareChannels(NotificationChannel expected, NotificationChannel actual) {
+        assertEquals(expected.getId(), actual.getId());
+        assertEquals(expected.getName(), actual.getName());
+        assertEquals(expected.shouldVibrate(), actual.shouldVibrate());
+        assertEquals(expected.shouldShowLights(), actual.shouldShowLights());
+        assertEquals(expected.getImportance(), actual.getImportance());
+        assertEquals(expected.getLockscreenVisibility(), actual.getLockscreenVisibility());
+        assertEquals(expected.getRingtone(), actual.getRingtone());
+        assertEquals(expected.canBypassDnd(), actual.canBypassDnd());
+    }
 }
diff --git a/tests/signature/api/Android.mk b/tests/signature/api/Android.mk
index d27a83b..3d67cd8 100644
--- a/tests/signature/api/Android.mk
+++ b/tests/signature/api/Android.mk
@@ -18,6 +18,9 @@
 include $(CLEAR_VARS)
 
 # current api, in XML format.
+# NOTE: the output XML file is also used
+# in //cts/hostsidetests/devicepolicy/AndroidTest.xml
+# by com.android.cts.managedprofile.CurrentApiHelper
 # ============================================================
 include $(CLEAR_VARS)
 LOCAL_MODULE := cts-current-api
diff --git a/tests/tests/animation/src/android/animation/cts/AnimationActivity.java b/tests/tests/animation/src/android/animation/cts/AnimationActivity.java
index 598048e..da52d30 100644
--- a/tests/tests/animation/src/android/animation/cts/AnimationActivity.java
+++ b/tests/tests/animation/src/android/animation/cts/AnimationActivity.java
@@ -37,9 +37,8 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.animation.AccelerateInterpolator;
-import java.util.ArrayList;
 
-import android.animation.cts.R;
+import java.util.ArrayList;
 
 public class AnimationActivity extends Activity {
     private static final String BALL_HEIGHT = "ballwidth";
diff --git a/tests/tests/animation/src/android/animation/cts/ButtonViewActivity.java b/tests/tests/animation/src/android/animation/cts/ButtonViewActivity.java
index fe66951..6d288c6 100644
--- a/tests/tests/animation/src/android/animation/cts/ButtonViewActivity.java
+++ b/tests/tests/animation/src/android/animation/cts/ButtonViewActivity.java
@@ -19,8 +19,6 @@
 import android.app.Activity;
 import android.os.Bundle;
 
-import android.animation.cts.R;
-
 public class ButtonViewActivity extends Activity {
 
     @Override
diff --git a/tests/tests/animation/src/android/animation/cts/KeyframeTest.java b/tests/tests/animation/src/android/animation/cts/KeyframeTest.java
index 99b8645..1072487 100644
--- a/tests/tests/animation/src/android/animation/cts/KeyframeTest.java
+++ b/tests/tests/animation/src/android/animation/cts/KeyframeTest.java
@@ -23,7 +23,6 @@
 import android.animation.TimeInterpolator;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
-import android.test.InstrumentationTestCase;
 import android.view.animation.AccelerateInterpolator;
 
 import org.junit.Test;
diff --git a/tests/tests/animation/src/android/animation/cts/ObjectAnimatorTest.java b/tests/tests/animation/src/android/animation/cts/ObjectAnimatorTest.java
index f3e0867..16a517f 100644
--- a/tests/tests/animation/src/android/animation/cts/ObjectAnimatorTest.java
+++ b/tests/tests/animation/src/android/animation/cts/ObjectAnimatorTest.java
@@ -20,7 +20,10 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
diff --git a/tests/tests/animation/src/android/animation/cts/ShapeHolder.java b/tests/tests/animation/src/android/animation/cts/ShapeHolder.java
index 4723c67..e35ef64 100644
--- a/tests/tests/animation/src/android/animation/cts/ShapeHolder.java
+++ b/tests/tests/animation/src/android/animation/cts/ShapeHolder.java
@@ -16,10 +16,10 @@
 
 package android.animation.cts;
 
-import android.graphics.drawable.ShapeDrawable;
-import android.graphics.drawable.shapes.Shape;
 import android.graphics.Paint;
 import android.graphics.RadialGradient;
+import android.graphics.drawable.ShapeDrawable;
+import android.graphics.drawable.shapes.Shape;
 
 /**
  * A data structure that holds a Shape and various properties that can be used to define
diff --git a/tests/tests/media/src/android/media/cts/MediaCodecTest.java b/tests/tests/media/src/android/media/cts/MediaCodecTest.java
index 8f02dea..f9b3b5a 100644
--- a/tests/tests/media/src/android/media/cts/MediaCodecTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaCodecTest.java
@@ -86,6 +86,13 @@
     private boolean mAudioEncoderHadError = false;
     private volatile boolean mVideoEncodingOngoing = false;
 
+    private static final int INPUT_RESOURCE_ID =
+            R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
+
+    // The test should fail if the decoder never produces output frames for the input.
+    // Time out decoding, as we have no way to query whether the decoder will produce output.
+    private static final int DECODING_TIMEOUT_MS = 10000;
+
     /**
      * Tests:
      * <br> Exceptions for MediaCodec factory methods
@@ -547,6 +554,103 @@
         callbackThread.join();
     }
 
+    public void testAsyncFlushAndReset() throws Exception, InterruptedException {
+        testAsyncReset(false /* testStop */);
+    }
+
+    public void testAsyncStopAndReset() throws Exception, InterruptedException {
+        testAsyncReset(true /* testStop */);
+    }
+
+    private void testAsyncReset(boolean testStop) throws Exception, InterruptedException {
+        // Test video and audio 10x each
+        for (int i = 0; i < 10; i++) {
+            testAsyncReset(false /* audio */, (i % 2) == 0 /* swap */, testStop);
+        }
+        for (int i = 0; i < 10; i++) {
+            testAsyncReset(true /* audio */, (i % 2) == 0 /* swap */, testStop);
+        }
+    }
+
+    /*
+     * This method simulates a race between flush (or stop) and reset() called from
+     * two threads. Neither call should get stuck. This should be run multiple rounds.
+     */
+    private void testAsyncReset(boolean audio, boolean swap, final boolean testStop)
+            throws Exception, InterruptedException {
+        String mimeTypePrefix  = audio ? "audio/" : "video/";
+        final MediaExtractor mediaExtractor = getMediaExtractorForMimeType(
+                INPUT_RESOURCE_ID, mimeTypePrefix);
+        MediaFormat mediaFormat = mediaExtractor.getTrackFormat(
+                mediaExtractor.getSampleTrackIndex());
+        if (!MediaUtils.checkDecoderForFormat(mediaFormat)) {
+            return; // skip
+        }
+
+        OutputSurface outputSurface = audio ? null : new OutputSurface(1, 1);
+        final Surface surface = outputSurface == null ? null : outputSurface.getSurface();
+
+        String mimeType = mediaFormat.getString(MediaFormat.KEY_MIME);
+        final MediaCodec mediaCodec = MediaCodec.createDecoderByType(mimeType);
+
+        try {
+            mediaCodec.configure(mediaFormat, surface, null /* crypto */, 0 /* flags */);
+
+            mediaCodec.start();
+
+            assertTrue(runDecodeTillFirstOutput(mediaCodec, mediaExtractor));
+
+            Thread flushingThread = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        if (testStop) {
+                            mediaCodec.stop();
+                        } else {
+                            mediaCodec.flush();
+                        }
+                    } catch (IllegalStateException e) {
+                        // This is okay, since we're simulating a race between flush and reset.
+                        // If reset executed first, flush could fail.
+                    }
+                }
+            });
+
+            Thread resettingThread = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    mediaCodec.reset();
+                }
+            });
+
+            // start flushing (or stopping) and resetting in two threads
+            if (swap) {
+                flushingThread.start();
+                resettingThread.start();
+            } else {
+                resettingThread.start();
+                flushingThread.start();
+            }
+
+            // wait for at most 5 sec, and check if the thread exits properly
+            flushingThread.join(5000);
+            assertFalse(flushingThread.isAlive());
+
+            resettingThread.join(5000);
+            assertFalse(resettingThread.isAlive());
+        } finally {
+            if (mediaCodec != null) {
+                mediaCodec.release();
+            }
+            if (mediaExtractor != null) {
+                mediaExtractor.release();
+            }
+            if (outputSurface != null) {
+                outputSurface.release();
+            }
+        }
+    }
+
     private static class FlushThread extends Thread {
         final MediaCodec mEncoder;
         final CountDownLatch mBuffersExhausted;
@@ -882,13 +986,6 @@
     }
 
     private void testDecodeAfterFlush(final boolean audio) throws InterruptedException {
-        final int INPUT_RESOURCE_ID =
-                R.raw.video_480x360_mp4_h264_1350kbps_30fps_aac_stereo_192kbps_44100hz;
-
-        // The test should fail if the decoder never produces output frames for the input.
-        // Time out decoding, as we have no way to query whether the decoder will produce output.
-        final int DECODING_TIMEOUT_MS = 10000;
-
         final AtomicBoolean completed = new AtomicBoolean(false);
         Thread decodingThread = new Thread(new Runnable() {
             @Override
diff --git a/tests/tests/text/src/android/text/cts/LoginFilterTest.java b/tests/tests/text/src/android/text/cts/LoginFilterTest.java
index 9ebc7ec..855823a 100644
--- a/tests/tests/text/src/android/text/cts/LoginFilterTest.java
+++ b/tests/tests/text/src/android/text/cts/LoginFilterTest.java
@@ -35,8 +35,6 @@
 import android.text.Spanned;
 import android.text.SpannedString;
 
-import junit.framework.TestCase;
-
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
diff --git a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
index 525bf50..341cae5 100644
--- a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
@@ -23,7 +23,6 @@
 import static org.junit.Assert.fail;
 
 import android.app.UiAutomation;
-import android.content.ContentResolver;
 import android.content.Context;
 import android.cts.util.SystemUtil;
 import android.os.ParcelFileDescriptor;
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 9252c76..735f6a0 100644
--- a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
@@ -20,7 +20,6 @@
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import android.content.Context;
 import android.support.test.InstrumentationRegistry;
diff --git a/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
index b9fa8cc..c73b7fa 100644
--- a/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
@@ -26,7 +26,6 @@
 import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
 import android.support.test.filters.LargeTest;
diff --git a/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java b/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
index e568072..8317775 100644
--- a/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
+++ b/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
@@ -17,7 +17,7 @@
 
 import static android.cts.util.CtsMockitoUtils.within;
 
-import static junit.framework.Assert.*;
+import static junit.framework.Assert.fail;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Matchers.any;
diff --git a/tests/tests/transition/src/android/transition/cts/FadeTest.java b/tests/tests/transition/src/android/transition/cts/FadeTest.java
index 500d7ea..22a6039 100644
--- a/tests/tests/transition/src/android/transition/cts/FadeTest.java
+++ b/tests/tests/transition/src/android/transition/cts/FadeTest.java
@@ -15,7 +15,6 @@
  */
 package android.transition.cts;
 
-import static org.junit.Assert.assertEquals;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
diff --git a/tests/tests/transition/src/android/transition/cts/SlideEdgeTest.java b/tests/tests/transition/src/android/transition/cts/SlideEdgeTest.java
index f97bcf0..d746dcd 100644
--- a/tests/tests/transition/src/android/transition/cts/SlideEdgeTest.java
+++ b/tests/tests/transition/src/android/transition/cts/SlideEdgeTest.java
@@ -36,8 +36,6 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.util.concurrent.TimeUnit;
-
 @MediumTest
 @RunWith(AndroidJUnit4.class)
 public class SlideEdgeTest extends BaseTransitionTest  {
diff --git a/tests/tests/transition/src/android/transition/cts/TransitionManagerTest.java b/tests/tests/transition/src/android/transition/cts/TransitionManagerTest.java
index 9791758..d4375cc 100644
--- a/tests/tests/transition/src/android/transition/cts/TransitionManagerTest.java
+++ b/tests/tests/transition/src/android/transition/cts/TransitionManagerTest.java
@@ -16,11 +16,9 @@
 package android.transition.cts;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.times;
diff --git a/tests/tests/transition/src/android/transition/cts/TransitionTest.java b/tests/tests/transition/src/android/transition/cts/TransitionTest.java
index 7d86b49..6c577fd 100644
--- a/tests/tests/transition/src/android/transition/cts/TransitionTest.java
+++ b/tests/tests/transition/src/android/transition/cts/TransitionTest.java
@@ -20,7 +20,6 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
diff --git a/tests/tests/view/src/android/view/animation/cts/AnimationTest.java b/tests/tests/view/src/android/view/animation/cts/AnimationTest.java
index f06b731..0d700af 100644
--- a/tests/tests/view/src/android/view/animation/cts/AnimationTest.java
+++ b/tests/tests/view/src/android/view/animation/cts/AnimationTest.java
@@ -27,7 +27,6 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
diff --git a/tests/tests/view/src/android/view/animation/cts/AnimationTestCtsActivity.java b/tests/tests/view/src/android/view/animation/cts/AnimationTestCtsActivity.java
index 0316f28..bf85d73 100644
--- a/tests/tests/view/src/android/view/animation/cts/AnimationTestCtsActivity.java
+++ b/tests/tests/view/src/android/view/animation/cts/AnimationTestCtsActivity.java
@@ -16,11 +16,9 @@
 
 package android.view.animation.cts;
 
-import android.view.cts.R;
-
 import android.app.Activity;
 import android.os.Bundle;
-import android.util.Log;
+import android.view.cts.R;
 
 import java.util.concurrent.TimeUnit;
 
diff --git a/tests/tests/view/src/android/view/animation/cts/GridLayoutAnimCtsActivity.java b/tests/tests/view/src/android/view/animation/cts/GridLayoutAnimCtsActivity.java
index 371af41..b6bc8fb 100644
--- a/tests/tests/view/src/android/view/animation/cts/GridLayoutAnimCtsActivity.java
+++ b/tests/tests/view/src/android/view/animation/cts/GridLayoutAnimCtsActivity.java
@@ -16,13 +16,12 @@
 
 package android.view.animation.cts;
 
-import android.view.cts.R;
-
 import android.app.Activity;
 import android.database.DataSetObserver;
 import android.os.Bundle;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.cts.R;
 import android.widget.AbsListView;
 import android.widget.GridView;
 import android.widget.ImageView;
diff --git a/tests/tests/view/src/android/view/cts/DragDropActivity.java b/tests/tests/view/src/android/view/cts/DragDropActivity.java
index b4324e3..e4e4fdc 100644
--- a/tests/tests/view/src/android/view/cts/DragDropActivity.java
+++ b/tests/tests/view/src/android/view/cts/DragDropActivity.java
@@ -16,8 +16,6 @@
 
 package android.view.cts;
 
-import android.view.cts.R;
-
 import android.app.Activity;
 import android.os.Bundle;
 
diff --git a/tests/tests/view/src/android/view/cts/DragDropTest.java b/tests/tests/view/src/android/view/cts/DragDropTest.java
index 238fcad..64c170c 100644
--- a/tests/tests/view/src/android/view/cts/DragDropTest.java
+++ b/tests/tests/view/src/android/view/cts/DragDropTest.java
@@ -16,7 +16,9 @@
 
 package android.view.cts;
 
-import com.android.internal.util.ArrayUtils;
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertTrue;
+import static junit.framework.TestCase.fail;
 
 import android.app.Instrumentation;
 import android.app.UiAutomation;
@@ -33,21 +35,18 @@
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.android.internal.util.ArrayUtils;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.lang.InterruptedException;
-import java.lang.StringBuilder;
-import java.lang.Thread;
 import java.util.ArrayList;
+import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
-import java.util.Objects;
-
-import static junit.framework.TestCase.*;
 
 @RunWith(AndroidJUnit4.class)
 public class DragDropTest {
diff --git a/tests/tests/view/src/android/view/cts/FocusFinderCtsActivity.java b/tests/tests/view/src/android/view/cts/FocusFinderCtsActivity.java
index d2fa729..ae0b4bf 100644
--- a/tests/tests/view/src/android/view/cts/FocusFinderCtsActivity.java
+++ b/tests/tests/view/src/android/view/cts/FocusFinderCtsActivity.java
@@ -16,12 +16,8 @@
 
 package android.view.cts;
 
-import android.view.cts.R;
-
 import android.app.Activity;
-import android.content.Context;
 import android.os.Bundle;
-import android.util.AttributeSet;
 import android.view.ViewGroup;
 import android.widget.Button;
 
diff --git a/tests/tests/view/src/android/view/cts/FocusHandlingCtsActivity.java b/tests/tests/view/src/android/view/cts/FocusHandlingCtsActivity.java
index 86a1c9e..56fd97b 100644
--- a/tests/tests/view/src/android/view/cts/FocusHandlingCtsActivity.java
+++ b/tests/tests/view/src/android/view/cts/FocusHandlingCtsActivity.java
@@ -16,8 +16,6 @@
 
 package android.view.cts;
 
-import android.view.cts.R;
-
 import android.app.Activity;
 import android.os.Bundle;
 
diff --git a/tests/tests/view/src/android/view/cts/HoverTest.java b/tests/tests/view/src/android/view/cts/HoverTest.java
index 23eda03..24e3020 100644
--- a/tests/tests/view/src/android/view/cts/HoverTest.java
+++ b/tests/tests/view/src/android/view/cts/HoverTest.java
@@ -16,6 +16,13 @@
 
 package android.view.cts;
 
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
 import android.app.Activity;
 import android.app.Instrumentation;
 import android.os.SystemClock;
@@ -27,6 +34,7 @@
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
+
 import org.hamcrest.Description;
 import org.junit.Before;
 import org.junit.Rule;
@@ -35,13 +43,6 @@
 import org.mockito.ArgumentMatcher;
 import org.mockito.InOrder;
 
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
 /**
  * Test hover events.
  */
diff --git a/tests/tests/view/src/android/view/cts/MockView.java b/tests/tests/view/src/android/view/cts/MockView.java
index 6b2cc18..7938d64 100644
--- a/tests/tests/view/src/android/view/cts/MockView.java
+++ b/tests/tests/view/src/android/view/cts/MockView.java
@@ -25,12 +25,12 @@
 import android.util.AttributeSet;
 import android.util.SparseArray;
 import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.PointerIcon;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.ContextMenu.ContextMenuInfo;
 
 public class MockView extends View {
     private boolean mCalledOnCreateContextMenu = false;
diff --git a/tests/tests/view/src/android/view/cts/PanicPressBackActivity.java b/tests/tests/view/src/android/view/cts/PanicPressBackActivity.java
index fe16e3f..bb52491 100644
--- a/tests/tests/view/src/android/view/cts/PanicPressBackActivity.java
+++ b/tests/tests/view/src/android/view/cts/PanicPressBackActivity.java
@@ -17,10 +17,8 @@
 package android.view.cts;
 
 import android.app.Activity;
-import android.view.cts.R;
 
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 public class PanicPressBackActivity extends Activity {
 
diff --git a/tests/tests/view/src/android/view/cts/PanicPressBackTest.java b/tests/tests/view/src/android/view/cts/PanicPressBackTest.java
index b0b073d..8a0bf31 100644
--- a/tests/tests/view/src/android/view/cts/PanicPressBackTest.java
+++ b/tests/tests/view/src/android/view/cts/PanicPressBackTest.java
@@ -16,28 +16,23 @@
 
 package android.view.cts;
 
+import static junit.framework.TestCase.assertFalse;
+import static junit.framework.TestCase.assertTrue;
+
 import android.app.UiAutomation;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.pm.PackageManager;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.rule.ActivityTestRule;
 import android.support.test.runner.AndroidJUnit4;
-import android.view.ViewConfiguration;
-
 import android.view.KeyEvent;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import android.view.ViewConfiguration;
 
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import static junit.framework.TestCase.*;
+import java.util.concurrent.TimeUnit;
 
 @RunWith(AndroidJUnit4.class)
 public class PanicPressBackTest {
diff --git a/tests/tests/view/src/android/view/cts/WindowCtsActivity.java b/tests/tests/view/src/android/view/cts/WindowCtsActivity.java
index 3cfcc96..0d8e14c 100644
--- a/tests/tests/view/src/android/view/cts/WindowCtsActivity.java
+++ b/tests/tests/view/src/android/view/cts/WindowCtsActivity.java
@@ -16,8 +16,6 @@
 
 package android.view.cts;
 
-import android.view.cts.R;
-
 import android.app.Activity;
 import android.os.Bundle;
 import android.view.KeyEvent;
diff --git a/tests/tests/view/src/android/view/cts/surfacevalidator/AnimationTestCase.java b/tests/tests/view/src/android/view/cts/surfacevalidator/AnimationTestCase.java
index 6b455e2..74ee5ee 100644
--- a/tests/tests/view/src/android/view/cts/surfacevalidator/AnimationTestCase.java
+++ b/tests/tests/view/src/android/view/cts/surfacevalidator/AnimationTestCase.java
@@ -16,7 +16,6 @@
 package android.view.cts.surfacevalidator;
 
 import android.animation.ValueAnimator;
-import android.annotation.SuppressLint;
 import android.content.Context;
 import android.view.View;
 import android.widget.FrameLayout;
diff --git a/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java b/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
index 20c3ba2..237ab7c 100644
--- a/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
+++ b/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
@@ -15,6 +15,8 @@
  */
 package android.view.cts.surfacevalidator;
 
+import static org.junit.Assert.assertTrue;
+
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
@@ -40,10 +42,6 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.*;
-
 
 public class CapturedActivity extends Activity {
     public static class TestResult {
diff --git a/tests/tests/view/src/android/view/cts/surfacevalidator/SurfacePixelValidator.java b/tests/tests/view/src/android/view/cts/surfacevalidator/SurfacePixelValidator.java
index 5a30b77..3d9f66b 100644
--- a/tests/tests/view/src/android/view/cts/surfacevalidator/SurfacePixelValidator.java
+++ b/tests/tests/view/src/android/view/cts/surfacevalidator/SurfacePixelValidator.java
@@ -28,11 +28,6 @@
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.Surface;
-import android.view.cts.surfacevalidator.PixelChecker;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
 
 public class SurfacePixelValidator {
     private static final String TAG = "SurfacePixelValidator";
diff --git a/tests/tests/view/src/android/view/cts/util/DrawingUtils.java b/tests/tests/view/src/android/view/cts/util/DrawingUtils.java
index 3be7447..ce8a0f7 100644
--- a/tests/tests/view/src/android/view/cts/util/DrawingUtils.java
+++ b/tests/tests/view/src/android/view/cts/util/DrawingUtils.java
@@ -23,6 +23,7 @@
 import android.graphics.Rect;
 import android.util.Pair;
 import android.view.View;
+
 import junit.framework.Assert;
 
 import java.util.List;
diff --git a/tests/tests/view/src/android/view/cts/util/XmlUtils.java b/tests/tests/view/src/android/view/cts/util/XmlUtils.java
index f1df4ff..77d53e6 100644
--- a/tests/tests/view/src/android/view/cts/util/XmlUtils.java
+++ b/tests/tests/view/src/android/view/cts/util/XmlUtils.java
@@ -16,10 +16,6 @@
 
 package android.view.cts.util;
 
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
 import android.graphics.Bitmap;
 import android.graphics.Bitmap.CompressFormat;
 import android.graphics.BitmapFactory;
@@ -28,6 +24,10 @@
 import android.util.Base64;
 import android.util.Xml;
 
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/EditorInfoTest.java b/tests/tests/view/src/android/view/inputmethod/cts/EditorInfoTest.java
index 97bffe6..1557511 100644
--- a/tests/tests/view/src/android/view/inputmethod/cts/EditorInfoTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/EditorInfoTest.java
@@ -18,11 +18,9 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
 import android.os.Bundle;
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/InputConnectionWrapperTest.java b/tests/tests/view/src/android/view/inputmethod/cts/InputConnectionWrapperTest.java
index 6982fdc..f26f55a 100644
--- a/tests/tests/view/src/android/view/inputmethod/cts/InputConnectionWrapperTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/InputConnectionWrapperTest.java
@@ -20,7 +20,6 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
diff --git a/tools/cts-tradefed/res/config/cts-known-failures.xml b/tools/cts-tradefed/res/config/cts-known-failures.xml
index 10bb65c..e28a503 100644
--- a/tools/cts-tradefed/res/config/cts-known-failures.xml
+++ b/tools/cts-tradefed/res/config/cts-known-failures.xml
@@ -23,9 +23,6 @@
     <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/23776083 -->
-    <option name="compatibility:exclude-filter" value="CtsAlarmClockTestCases" />
-
     <!-- 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" />