Merge "Adapt CTS to API Council feedback" into oc-mr1-dev
diff --git a/hostsidetests/backup/src/android/cts/backup/BaseBackupHostSideTest.java b/hostsidetests/backup/src/android/cts/backup/BaseBackupHostSideTest.java
index e765971..acdb423 100644
--- a/hostsidetests/backup/src/android/cts/backup/BaseBackupHostSideTest.java
+++ b/hostsidetests/backup/src/android/cts/backup/BaseBackupHostSideTest.java
@@ -23,6 +23,7 @@
 
 import com.android.compatibility.common.tradefed.testtype.CompatibilityHostTestBase;
 import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
 
 import org.junit.After;
@@ -38,18 +39,21 @@
  */
 @RunWith(DeviceJUnit4ClassRunner.class)
 public abstract class BaseBackupHostSideTest extends CompatibilityHostTestBase {
+    protected boolean mIsBackupSupported;
+
     /** Value of PackageManager.FEATURE_BACKUP */
     private static final String FEATURE_BACKUP = "android.software.backup";
 
     private static final String LOCAL_TRANSPORT =
             "android/com.android.internal.backup.LocalTransport";
 
-    private boolean mIsBackupSupported;
-
     @Before
     public void setUp() throws DeviceNotAvailableException, Exception {
         mIsBackupSupported = mDevice.hasFeature("feature:" + FEATURE_BACKUP);
-        assumeTrue(mIsBackupSupported);
+        if (!mIsBackupSupported) {
+            CLog.i("android.software.backup feature is not supported on this device");
+            return;
+        }
 
         // Check that the backup wasn't disabled and the transport wasn't switched unexpectedly.
         assertTrue("Backup was unexpectedly disabled during the module test run",
diff --git a/hostsidetests/backup/src/android/cts/backup/KeyValueBackupRestoreHostSideTest.java b/hostsidetests/backup/src/android/cts/backup/KeyValueBackupRestoreHostSideTest.java
index cbccd7a..70bfc07 100644
--- a/hostsidetests/backup/src/android/cts/backup/KeyValueBackupRestoreHostSideTest.java
+++ b/hostsidetests/backup/src/android/cts/backup/KeyValueBackupRestoreHostSideTest.java
@@ -19,6 +19,7 @@
 import static junit.framework.Assert.assertNull;
 
 import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
 
 import org.junit.After;
@@ -93,6 +94,11 @@
      */
     @Test
     public void testKeyValueBackupAndRestore() throws Exception {
+        if (!mIsBackupSupported) {
+            CLog.i("android.software.backup feature is not supported on this device");
+            return;
+        }
+
         checkDeviceTest("checkSharedPrefIsEmpty");
 
         checkDeviceTest("saveSharedPreferencesAndNotifyBackupManager");
diff --git a/hostsidetests/net/app/AndroidManifest.xml b/hostsidetests/net/app/AndroidManifest.xml
index 0598a3b..7466cb8 100644
--- a/hostsidetests/net/app/AndroidManifest.xml
+++ b/hostsidetests/net/app/AndroidManifest.xml
@@ -21,6 +21,8 @@
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
 
     <application>
         <uses-library android:name="android.test.runner" />
diff --git a/hostsidetests/net/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/hostsidetests/net/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
index f3d5d2c..35e84c5 100644
--- a/hostsidetests/net/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
+++ b/hostsidetests/net/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
@@ -42,6 +42,7 @@
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.SystemClock;
+import android.provider.Settings;
 import android.service.notification.NotificationListenerService;
 import android.test.InstrumentationTestCase;
 import android.text.TextUtils;
@@ -116,6 +117,7 @@
     private MyServiceClient mServiceClient;
     private String mDeviceIdleConstantsSetting;
     private boolean mSupported;
+    private boolean mIsLocationOn;
 
     @Override
     protected void setUp() throws Exception {
@@ -130,6 +132,10 @@
         mServiceClient = new MyServiceClient(mContext);
         mServiceClient.bind();
         mDeviceIdleConstantsSetting = "device_idle_constants";
+        mIsLocationOn = isLocationOn();
+        if (!mIsLocationOn) {
+            enableLocation();
+        }
         mSupported = setUpActiveNetworkMeteringState();
 
         Log.i(TAG, "Apps status on " + getName() + ":\n"
@@ -139,11 +145,35 @@
 
     @Override
     protected void tearDown() throws Exception {
+        if (!mIsLocationOn) {
+            disableLocation();
+        }
         mServiceClient.unbind();
 
         super.tearDown();
     }
 
+    private void enableLocation() throws Exception {
+        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE,
+                Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
+        assertEquals(Settings.Secure.LOCATION_MODE_SENSORS_ONLY,
+                Settings.Secure.getInt(mContext.getContentResolver(),
+                        Settings.Secure.LOCATION_MODE));
+    }
+
+    private void disableLocation() throws Exception {
+        Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE,
+                Settings.Secure.LOCATION_MODE_OFF);
+        assertEquals(Settings.Secure.LOCATION_MODE_OFF,
+                Settings.Secure.getInt(mContext.getContentResolver(),
+                        Settings.Secure.LOCATION_MODE));
+    }
+
+    private boolean isLocationOn() throws Exception {
+        return Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.LOCATION_MODE) != Settings.Secure.LOCATION_MODE_OFF;
+    }
+
     protected int getUid(String packageName) throws Exception {
         return mContext.getPackageManager().getPackageUid(packageName, 0);
     }
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index 7b10600..e1b5bd15 100644
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -119,6 +119,7 @@
 
         <option name="push" value="Bug-33039685->/data/local/tmp/Bug-33039685" />
         <option name="push" value="Bug-35676417->/data/local/tmp/Bug-35676417" />
+        <option name="push" value="Bug-35644812->/data/local/tmp/Bug-35644812" />
 
         <option name="append-bitness" value="true" />
     </target_preparer>
diff --git a/hostsidetests/security/securityPatch/Bug-35644812/Android.mk b/hostsidetests/security/securityPatch/Bug-35644812/Android.mk
new file mode 100644
index 0000000..e02559d
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-35644812/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := Bug-35644812
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-35644812/poc.c b/hostsidetests/security/securityPatch/Bug-35644812/poc.c
new file mode 100644
index 0000000..c0ca91f
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-35644812/poc.c
@@ -0,0 +1,106 @@
+/**

+ * Copyright (C) 2017 The Android Open Source Project

+ *

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

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

+ * You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+

+#ifndef _GNU_SOURCE

+#define _GNU_SOURCE

+#endif

+

+#include <string.h>

+

+#include <android/log.h>

+#include <dirent.h>

+#include <dlfcn.h>

+#include <errno.h>

+#include <fcntl.h>

+#include <linux/futex.h>

+#include <pthread.h>

+#include <sched.h>

+#include <signal.h>

+#include <stdbool.h>

+#include <stdio.h>

+#include <stdlib.h>

+#include <sys/ioctl.h>

+#include <sys/mman.h>

+#include <sys/mount.h>

+#include <sys/ptrace.h>

+#include <sys/select.h>

+#include <sys/socket.h>

+#include <sys/stat.h>

+#include <sys/syscall.h>

+#include <sys/system_properties.h>

+#include <sys/time.h>

+#include <sys/types.h>

+#include <sys/un.h>

+#include <sys/utsname.h>

+#include <sys/wait.h>

+#include <unistd.h>

+

+int fd;

+

+void in_cpu() {

+  int num_processors = sysconf(_SC_NPROCESSORS_CONF);

+  cpu_set_t get;

+  int i = 0;

+  CPU_ZERO(&get);

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

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

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

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

+    }

+  }

+}

+static void bind_child_to_cpu() {

+  in_cpu();

+  cpu_set_t set;

+  CPU_ZERO(&set);

+  CPU_SET(1, &set);

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

+  in_cpu();

+}

+

+#define BLKTRACETEARDOWN _IO(0x12, 118)

+#define SG_SET_RESERVED_SIZE 0x2275

+#define SG_GET_RESERVED_SIZE 0x2272

+static void* overwrite(void* param) {

+  int ret;

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

+    int size = 0x100;

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

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

+  }

+  return param;

+}

+

+int functionOne() {

+  sleep(2);

+  char filename[128];

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

+

+  fd = open(filename, 2);

+  if (fd == -1) {

+    return -1;

+  }

+

+  pthread_t thread0;

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

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

+      perror("overwritethread pthread_create()");

+  }

+

+  return 0;

+}

+

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

diff --git a/hostsidetests/security/src/android/security/cts/Poc17_06.java b/hostsidetests/security/src/android/security/cts/Poc17_06.java
index da7336d..61a5918 100644
--- a/hostsidetests/security/src/android/security/cts/Poc17_06.java
+++ b/hostsidetests/security/src/android/security/cts/Poc17_06.java
@@ -98,8 +98,9 @@
     @SecurityTest
     public void testPocBug_35644815() throws Exception {
         enableAdbRoot(getDevice());
-        String pocOut = AdbUtils.runPoc("Bug-35644815", getDevice(), 60);
-        assertMatches("[\\s\\n\\S]*INFO DISC FLAG: 0000[\\s\\n\\S]*", pocOut);
+        if(containsDriver(getDevice(), "/sys/kernel/debug/ion/clients/pids")) {
+          String pocOut = AdbUtils.runPoc("Bug-35644815", getDevice(), 60);
+          assertMatches("[\\s\\n\\S]*INFO DISC FLAG: 0000[\\s\\n\\S]*", pocOut);
+        }
     }
-
 }
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_09.java b/hostsidetests/security/src/android/security/cts/Poc17_09.java
index 051c589..fbda89c 100644
--- a/hostsidetests/security/src/android/security/cts/Poc17_09.java
+++ b/hostsidetests/security/src/android/security/cts/Poc17_09.java
@@ -42,4 +42,15 @@
           AdbUtils.runPocNoOutput("Bug-35676417", getDevice(), 60);
         }
     }
+
+    /**
+     *  b/35644812
+     */
+    @SecurityTest
+    public void testPocBug_35644812() throws Exception {
+        enableAdbRoot(getDevice());
+        if (containsDriver(getDevice(), "/dev/sg0")) {
+          AdbUtils.runPocNoOutput("Bug-35644812", getDevice(), 60);
+        }
+    }
 }
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
index d24fbdb..27d6c64 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).
      */
-    // TODO: Flaky, add to presubmit when b/63404575 is fixed.
+    @Presubmit
     public void testConfigurationUpdatesWhenResizedFromDockedStack() throws Exception {
         if (!supportsSplitScreenMultiWindow()) {
             CLog.logAndDisplay(LogLevel.INFO, "Skipping test: no multi-window support");
@@ -118,7 +118,7 @@
      * Same as {@link #testConfigurationUpdatesWhenRotatingWhileFullscreen()} but when the Activity
      * is in the docked stack.
      */
-    // TODO: Flaky, add to presubmit when b/63404575 is fixed.
+    @Presubmit
     public void testConfigurationUpdatesWhenRotatingWhileDocked() throws Exception {
         if (!supportsSplitScreenMultiWindow()) {
             CLog.logAndDisplay(LogLevel.INFO, "Skipping test: no multi-window support");
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 8206fdf..f5a53d4 100644
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDisplayTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerDisplayTests.java
@@ -1125,7 +1125,7 @@
     /**
      * Test that all activities that were on the private display are destroyed on display removal.
      */
-    // TODO: Flaky, add to presubmit when b/63404575 is fixed.
+    @Presubmit
     public void testContentDestroyOnDisplayRemoved() throws Exception {
         if (!supportsMultiDisplay()) { return; }
 
diff --git a/tests/autofillservice/src/android/autofillservice/cts/AbstractTimePickerActivity.java b/tests/autofillservice/src/android/autofillservice/cts/AbstractTimePickerActivity.java
index 89c028b..848b3cc 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/AbstractTimePickerActivity.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/AbstractTimePickerActivity.java
@@ -154,8 +154,7 @@
         private FillExpectation(String output, int hour, int minute) {
             // Output is called twice: by the TimeChangeListener and by auto-fill.
             outputWatcher = new MultipleTimesTextWatcher("output", 2, mOutput, output);
-            // TimePicker listener is called twice, for hour and minute changes.
-            timeListener = new MultipleTimesTimeListener("timePicker", 2, mTimePicker, hour,
+            timeListener = new MultipleTimesTimeListener("timePicker", 1, mTimePicker, hour,
                     minute);
         }
     }
diff --git a/tests/autofillservice/src/android/autofillservice/cts/AutofillValueTest.java b/tests/autofillservice/src/android/autofillservice/cts/AutofillValueTest.java
index 1efe0e9..c319730 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/AutofillValueTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/AutofillValueTest.java
@@ -419,7 +419,7 @@
                 .setField("editText", "filled")
                 .setPresentation(createPresentation("dataset"))
                 .build());
-        MultipleTimesTimeListener timeWatcher = new MultipleTimesTimeListener("timePicker", 2,
+        MultipleTimesTimeListener timeWatcher = new MultipleTimesTimeListener("timePicker", 1,
                 mTimePicker, 12, 32);
         mTimePicker.setOnTimeChangedListener(timeWatcher);
 
diff --git a/tests/autofillservice/src/android/autofillservice/cts/DismissType.java b/tests/autofillservice/src/android/autofillservice/cts/DismissType.java
index fd0cbd5..e8e7689 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/DismissType.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/DismissType.java
@@ -17,11 +17,15 @@
 
 /**
  * A simple enum for test cases where the Save UI is dismissed.
+ *
+ * <p><b>Note:</b> When new values are added to the enum, the equivalent tests must be added to
+ * both {@link LoginActivityTest} and {@link SimpleSaveActivityTest}.
  */
 enum DismissType {
     BACK_BUTTON,
     HOME_BUTTON,
     RECENTS_BUTTON,
     TOUCH_OUTSIDE,
-    FOCUS_OUTSIDE
+    FOCUS_OUTSIDE,
+    LAUNCH_ACTIVITY
 }
diff --git a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
index 0a0ba85..9b575ec 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
@@ -1194,12 +1194,7 @@
     @Test
     public void testSaveGoesAwayWhenTappingRecentsButton() throws Exception {
         // Launches new activity first...
-        final Context context = getContext();
-        final Intent intent = new Intent(context, CheckoutActivity.class);
-        intent.setFlags(
-                Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
-        context.startActivity(intent);
-        sUiBot.assertShownByRelativeId(CheckoutActivity.ID_ADDRESS);
+        startCheckoutActivityAsNewTask();
         try {
             // .. then the real activity being tested.
             sUiBot.switchAppsUsingRecents();
@@ -1216,6 +1211,15 @@
         saveGoesAway(DismissType.TOUCH_OUTSIDE);
     }
 
+    @Test
+    public void testSaveGoesAwayWhenLaunchingNewActivity() throws Exception {
+        try {
+            saveGoesAway(DismissType.LAUNCH_ACTIVITY);
+        } finally {
+            CheckoutActivity.finishIt();
+        }
+    }
+
     private void saveGoesAway(DismissType dismissType) throws Exception {
         enableService();
 
@@ -1261,6 +1265,9 @@
                 sUiBot.switchAppsUsingRecents();
                 sUiBot.assertShownByRelativeId(CheckoutActivity.ID_ADDRESS);
                 break;
+            case LAUNCH_ACTIVITY:
+                startCheckoutActivityAsNewTask();
+                break;
             default:
                 throw new IllegalArgumentException("invalid dismiss type: " + dismissType);
         }
@@ -3175,6 +3182,7 @@
                 .isEqualTo(5);
     }
 
+    @Test
     public void testAutofillLargeNumberOfDatasets() throws Exception {
         // Set service.
         enableService();
@@ -3214,4 +3222,35 @@
 
         // TODO: once it supports scrolling, selects the last dataset and asserts it's filled.
     }
+
+    @Test
+    public void testCancellationSignalCalledAfterTimeout() throws Exception {
+        // Set service.
+        enableService();
+
+        // Set expectations.
+        final OneTimeCancellationSignalListener listener =
+                new OneTimeCancellationSignalListener(Helper.FILL_TIMEOUT_MS + 2000);
+        sReplier.addResponse(DO_NOT_REPLY_RESPONSE);
+
+        // Trigger auto-fill.
+        mActivity.onUsername(View::requestFocus);
+
+        // Attach listener to CancellationSignal.
+        waitUntilConnected();
+        sReplier.getNextFillRequest().cancellationSignal.setOnCancelListener(listener);
+
+        // AssertResults
+        waitUntilDisconnected();
+        listener.assertOnCancelCalled();
+    }
+
+    private void startCheckoutActivityAsNewTask() {
+        final Context context = getContext();
+        final Intent intent = new Intent(context, CheckoutActivity.class);
+        intent.setFlags(
+                Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
+        context.startActivity(intent);
+        sUiBot.assertShownByRelativeId(CheckoutActivity.ID_ADDRESS);
+    }
 }
diff --git a/tests/autofillservice/src/android/autofillservice/cts/OneTimeCancellationSignalListener.java b/tests/autofillservice/src/android/autofillservice/cts/OneTimeCancellationSignalListener.java
new file mode 100644
index 0000000..0b055e0
--- /dev/null
+++ b/tests/autofillservice/src/android/autofillservice/cts/OneTimeCancellationSignalListener.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.autofillservice.cts;
+
+import static com.google.common.truth.Truth.assertWithMessage;
+
+import android.os.CancellationSignal;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Custom {@link android.os.CancellationSignal.OnCancelListener} used to assert that
+ * {@link android.os.CancellationSignal.OnCancelListener} was called, and just once.
+ */
+final class OneTimeCancellationSignalListener implements CancellationSignal.OnCancelListener {
+    private final CountDownLatch mLatch = new CountDownLatch(1);
+    private final long mTimeoutMs;
+
+    OneTimeCancellationSignalListener(long timeoutMs) {
+        mTimeoutMs = timeoutMs;
+    }
+
+    void assertOnCancelCalled() throws Exception {
+        final boolean called = mLatch.await(mTimeoutMs, TimeUnit.MILLISECONDS);
+        assertWithMessage("Timeout (%s ms) waiting for onCancel()", mTimeoutMs)
+                .that(called).isTrue();
+    }
+
+    @Override
+    public void onCancel() {
+        mLatch.countDown();
+    }
+}
diff --git a/tests/autofillservice/src/android/autofillservice/cts/OptionalSaveActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/OptionalSaveActivityTest.java
index debbedc..c82fa42 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/OptionalSaveActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/OptionalSaveActivityTest.java
@@ -630,7 +630,7 @@
         // Trigger save...
         mActivity.save();
 
-        // ...and make sure the snack bar is shown.
+        // ...and make sure the snack bar is not shown.
         sUiBot.assertSaveNotShowing(SAVE_DATA_TYPE_ADDRESS);
     }
 
diff --git a/tests/autofillservice/src/android/autofillservice/cts/SimpleRegexValidatorTest.java b/tests/autofillservice/src/android/autofillservice/cts/RegexValidatorTest.java
similarity index 98%
rename from tests/autofillservice/src/android/autofillservice/cts/SimpleRegexValidatorTest.java
rename to tests/autofillservice/src/android/autofillservice/cts/RegexValidatorTest.java
index 558cae9..f7ac268 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/SimpleRegexValidatorTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/RegexValidatorTest.java
@@ -33,7 +33,7 @@
 import java.util.regex.Pattern;
 
 @RunWith(AndroidJUnit4.class)
-public class SimpleRegexValidatorTest {
+public class RegexValidatorTest {
 
     @Test
     public void allNullConstructor() {
diff --git a/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
index 542e3a6..5f7713c 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
@@ -179,11 +179,7 @@
     @Test
     public void testDismissSave_byTappingRecents() throws Exception {
         // Launches a different activity first.
-        final Intent intent = new Intent(mContext, WelcomeActivity.class);
-        intent.setFlags(
-                Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
-        mContext.startActivity(intent);
-        WelcomeActivity.assertShowingDefaultMessage(sUiBot);
+        startWelcomeActivityOnNewTask();
 
         // Then launches the main activity.
         startActivity(true);
@@ -193,6 +189,16 @@
         dismissSaveTest(DismissType.RECENTS_BUTTON);
     }
 
+    @Test
+    public void testDismissSave_byLaunchingNewActivity() throws Exception {
+        startActivity();
+        try {
+            dismissSaveTest(DismissType.LAUNCH_ACTIVITY);
+        } finally {
+            WelcomeActivity.finishIt();
+        }
+    }
+
     private void dismissSaveTest(DismissType dismissType) throws Exception {
         // Set service.
         enableService();
@@ -233,9 +239,20 @@
                 sUiBot.switchAppsUsingRecents();
                 WelcomeActivity.assertShowingDefaultMessage(sUiBot);
                 break;
+            case LAUNCH_ACTIVITY:
+                startWelcomeActivityOnNewTask();
+                break;
             default:
                 throw new IllegalArgumentException("invalid dismiss type: " + dismissType);
         }
         sUiBot.assertSaveNotShowing(SAVE_DATA_TYPE_GENERIC);
     }
+
+    private void startWelcomeActivityOnNewTask() throws Exception {
+        final Intent intent = new Intent(mContext, WelcomeActivity.class);
+        intent.setFlags(
+                Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
+        mContext.startActivity(intent);
+        WelcomeActivity.assertShowingDefaultMessage(sUiBot);
+    }
 }
diff --git a/tests/pdf/AndroidTest.xml b/tests/pdf/AndroidTest.xml
index 5a0f718..ab88726 100644
--- a/tests/pdf/AndroidTest.xml
+++ b/tests/pdf/AndroidTest.xml
@@ -14,11 +14,14 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Pdf test cases">
+    <option name="not-shardable" value="true" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
+
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
         <option name="test-file-name" value="CtsPdfTestCases.apk" />
     </target_preparer>
+
     <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
         <option name="package" value="android.graphics.pdf.cts" />
         <option name="runtime-hint" value="5m" />
diff --git a/tests/tests/media/src/android/media/cts/ClearKeySystemTest.java b/tests/tests/media/src/android/media/cts/ClearKeySystemTest.java
index 30822b4..94f8885 100644
--- a/tests/tests/media/src/android/media/cts/ClearKeySystemTest.java
+++ b/tests/tests/media/src/android/media/cts/ClearKeySystemTest.java
@@ -87,8 +87,10 @@
     private static final Uri MPEG2TS_CLEAR_URL = Uri.parse(
             "android.resource://android.media.cts/" + R.raw.segment000001);
 
-    private static final UUID CLEARKEY_SCHEME_UUID =
+    private static final UUID COMMON_PSSH_SCHEME_UUID =
             new UUID(0x1077efecc0b24d02L, 0xace33c1e52e2fb4bL);
+    private static final UUID CLEARKEY_SCHEME_UUID =
+            new UUID(0xe2719d58a985b3c9L, 0x781ab030af78d30eL);
 
     private byte[] mDrmInitData;
     private byte[] mSessionId;
@@ -220,7 +222,7 @@
         }
     }
 
-    private MediaDrm startDrm(final byte[][] clearKeys, final String initDataType) {
+    private MediaDrm startDrm(final byte[][] clearKeys, final String initDataType, final UUID drmSchemeUuid) {
         new Thread() {
             @Override
             public void run() {
@@ -232,7 +234,7 @@
                 mLooper = Looper.myLooper();
 
                 try {
-                    mDrm = new MediaDrm(CLEARKEY_SCHEME_UUID);
+                    mDrm = new MediaDrm(drmSchemeUuid);
                 } catch (MediaDrmException e) {
                     Log.e(TAG, "Failed to create MediaDrm: " + e.getMessage());
                     return;
@@ -331,6 +333,7 @@
      * Tests clear key system playback.
      */
     private void testClearKeyPlayback(
+            UUID drmSchemeUuid,
             String videoMime, String[] videoFeatures,
             String initDataType, byte[][] clearKeys,
             Uri audioUrl, boolean audioEncrypted,
@@ -339,12 +342,12 @@
         MediaDrm drm = null;
         mSessionId = null;
         if (!scrambled) {
-            drm = startDrm(clearKeys, initDataType);
+            drm = startDrm(clearKeys, initDataType, drmSchemeUuid);
             if (null == drm) {
                 throw new Error("Failed to create drm.");
             }
 
-            if (!drm.isCryptoSchemeSupported(CLEARKEY_SCHEME_UUID)) {
+            if (!drm.isCryptoSchemeSupported(drmSchemeUuid)) {
                 stopDrm(drm);
                 throw new Error("Crypto scheme is not supported.");
             }
@@ -413,6 +416,18 @@
 
     public void testClearKeyPlaybackCenc() throws Exception {
         testClearKeyPlayback(
+            COMMON_PSSH_SCHEME_UUID,
+            // using secure codec even though it is clear key DRM
+            MIME_VIDEO_AVC, new String[] { CodecCapabilities.FEATURE_SecurePlayback },
+            "cenc", new byte[][] { CLEAR_KEY_CENC },
+            CENC_AUDIO_URL, false,
+            CENC_VIDEO_URL, true,
+            VIDEO_WIDTH_CENC, VIDEO_HEIGHT_CENC, false);
+    }
+
+    public void testClearKeyPlaybackCenc2() throws Exception {
+        testClearKeyPlayback(
+            CLEARKEY_SCHEME_UUID,
             // using secure codec even though it is clear key DRM
             MIME_VIDEO_AVC, new String[] { CodecCapabilities.FEATURE_SecurePlayback },
             "cenc", new byte[][] { CLEAR_KEY_CENC },
@@ -423,6 +438,7 @@
 
     public void testClearKeyPlaybackWebm() throws Exception {
         testClearKeyPlayback(
+            COMMON_PSSH_SCHEME_UUID,
             MIME_VIDEO_VP8, new String[0],
             "webm", new byte[][] { CLEAR_KEY_WEBM },
             WEBM_URL, true,
@@ -432,6 +448,7 @@
 
     public void testClearKeyPlaybackMpeg2ts() throws Exception {
         testClearKeyPlayback(
+            COMMON_PSSH_SCHEME_UUID,
             MIME_VIDEO_AVC, new String[0],
             "mpeg2ts", null,
             MPEG2TS_SCRAMBLED_URL, false,
@@ -441,6 +458,7 @@
 
     public void testPlaybackMpeg2ts() throws Exception {
         testClearKeyPlayback(
+            COMMON_PSSH_SCHEME_UUID,
             MIME_VIDEO_AVC, new String[0],
             "mpeg2ts", null,
             MPEG2TS_CLEAR_URL, false,
diff --git a/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java b/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
index 010d992..72838e5 100644
--- a/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
+++ b/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
@@ -264,13 +264,10 @@
             public int getHeight() {
                 return super.getHeight() + OFFSET;
             }
+
             @Override
-            public int getMaxHeight() {
-                return super.getHeight() * 2 + OFFSET;
-            }
-            @Override
-            public int getMaxWidth() {
-                return super.getWidth() * 2 + OFFSET;
+            public boolean isAbrEnabled() {
+                return true;
             }
         };
     }
@@ -281,13 +278,10 @@
             public int getWidth() {
                 return super.getWidth() + OFFSET;
             }
+
             @Override
-            public int getMaxHeight() {
-                return super.getHeight() * 2 + OFFSET;
-            }
-            @Override
-            public int getMaxWidth() {
-                return super.getWidth() * 2 + OFFSET;
+            public boolean isAbrEnabled() {
+                return true;
             }
         };
     }
diff --git a/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java b/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
index 0e92e3d..58f1607 100644
--- a/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
+++ b/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
@@ -20,6 +20,7 @@
 import static org.junit.Assert.assertNotNull;
 
 import com.android.compatibility.common.util.ApiLevelUtil;
+import com.android.compatibility.common.util.MediaUtils;
 
 import android.annotation.TargetApi;
 import android.annotation.SuppressLint;
@@ -38,6 +39,7 @@
 import android.media.MediaCodec;
 import android.media.MediaCodec.BufferInfo;
 import android.media.MediaCodec.CodecException;
+import android.media.MediaCodecInfo.VideoCapabilities;
 import android.media.MediaCodecList;
 import android.media.MediaExtractor;
 import android.media.MediaFormat;
@@ -480,10 +482,27 @@
             if (ApiLevelUtil.isBefore(Build.VERSION_CODES.KITKAT)) {
                 return;
             }
-            if (videoFormat.getMaxWidth() != VideoFormat.INT_UNSET
-                && videoFormat.getMaxHeight() != VideoFormat.INT_UNSET) {
-                mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, videoFormat.getMaxWidth());
-                mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, videoFormat.getMaxHeight());
+            // Set KEY_MAX_WIDTH and KEY_MAX_HEIGHT when isAbrEnabled() is set.
+            if (videoFormat.isAbrEnabled()) {
+                try {
+                    // Check for max resolution supported by the codec.
+                    final MediaCodec decoder = MediaUtils.getDecoder(mediaFormat);
+                    final VideoCapabilities videoCapabilities = MediaUtils.getVideoCapabilities(
+                            decoder.getName(), videoFormat.getMimeType());
+                    decoder.release();
+                    final int maxWidth = videoCapabilities.getSupportedWidths().getUpper();
+                    final int maxHeight =
+                            videoCapabilities.getSupportedHeightsFor(maxWidth).getUpper();
+                    if (maxWidth >= videoFormat.getWidth() && maxHeight >= videoFormat.getHeight()) {
+                        mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, maxWidth);
+                        mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, maxHeight);
+                        return;
+                    }
+                } catch (NullPointerException exception) { /* */ }
+                // Set max width/height to current size if can't get codec's max supported
+                // width/height or max is not greater than the current size.
+                mediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, videoFormat.getWidth());
+                mediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, videoFormat.getHeight());
             }
         }
 
@@ -1591,6 +1610,10 @@
         return getParsedName().getHeight();
     }
 
+    public boolean isAbrEnabled() {
+        return false;
+    }
+
     public String getOriginalSize() {
         if (width == INT_UNSET || height == INT_UNSET) {
             return getParsedName().getSize();
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index aaf3310..35d2cd8 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -1613,10 +1613,10 @@
 
         // Run twice to check if repeated selection-deselection on the same track works well.
         for (int i = 0; i < 2; i++) {
-            // Waits until at least one subtitle is fired. Timeout is 2 seconds.
+            // Waits until at least one subtitle is fired. Timeout is 2.5 seconds.
             selectSubtitleTrack(i);
             mOnSubtitleDataCalled.reset();
-            assertTrue(mOnSubtitleDataCalled.waitForSignal(2000));
+            assertTrue(mOnSubtitleDataCalled.waitForSignal(2500));
 
             // Try deselecting track.
             deselectSubtitleTrack(i);
diff --git a/tests/tests/media/src/android/media/cts/NativeClearKeySystemTest.java b/tests/tests/media/src/android/media/cts/NativeClearKeySystemTest.java
index 4a7b7af..a2af4cf 100644
--- a/tests/tests/media/src/android/media/cts/NativeClearKeySystemTest.java
+++ b/tests/tests/media/src/android/media/cts/NativeClearKeySystemTest.java
@@ -53,8 +53,10 @@
         "llama_h264_main_720p_8000.mp4");
 
     private static final int UUID_BYTE_SIZE = 16;
-    private static final UUID CLEARKEY_SCHEME_UUID =
+    private static final UUID COMMON_PSSH_SCHEME_UUID =
             new UUID(0x1077efecc0b24d02L, 0xace33c1e52e2fb4bL);
+    private static final UUID CLEARKEY_SCHEME_UUID =
+            new UUID(0xe2719d58a985b3c9L, 0x781ab030af78d30eL);
     private static final UUID BAD_SCHEME_UUID =
             new UUID(0xffffffffffffffffL, 0xffffffffffffffffL);
     private MediaCodecClearKeyPlayer mMediaCodecPlayer;
@@ -111,6 +113,7 @@
     }
 
     public void testIsCryptoSchemeSupported() throws Exception {
+        assertTrue(isCryptoSchemeSupportedNative(uuidByteArray(COMMON_PSSH_SCHEME_UUID)));
         assertTrue(isCryptoSchemeSupportedNative(uuidByteArray(CLEARKEY_SCHEME_UUID)));
     }
 
@@ -119,19 +122,34 @@
     }
 
     public void testPssh() throws Exception {
-        assertTrue(testPsshNative(uuidByteArray(CLEARKEY_SCHEME_UUID),
+        // The test uses a canned PSSH that contains the common box UUID.
+        assertTrue(testPsshNative(uuidByteArray(COMMON_PSSH_SCHEME_UUID),
                 CENC_CLEARKEY_VIDEO_URL.toString()));
     }
 
     public void testGetPropertyString() throws Exception {
         StringBuffer value = new StringBuffer();
+        testGetPropertyStringNative(uuidByteArray(COMMON_PSSH_SCHEME_UUID), "description", value);
+        assertEquals("ClearKey CDM", value.toString());
+
+        value.delete(0, value.length());
         testGetPropertyStringNative(uuidByteArray(CLEARKEY_SCHEME_UUID), "description", value);
         assertEquals("ClearKey CDM", value.toString());
     }
 
     public void testUnknownPropertyString() throws Exception {
+        StringBuffer value = new StringBuffer();
+
         try {
-            StringBuffer value = new StringBuffer();
+            testGetPropertyStringNative(uuidByteArray(COMMON_PSSH_SCHEME_UUID),
+                    "unknown-property", value);
+        } catch (RuntimeException e) {
+            Log.e(TAG, "testUnknownPropertyString error = '" + e.getMessage() + "'");
+            assertThat(e.getMessage(), containsString("get property string returns"));
+        }
+
+        value.delete(0, value.length());
+        try {
             testGetPropertyStringNative(uuidByteArray(CLEARKEY_SCHEME_UUID),
                     "unknown-property", value);
         } catch (RuntimeException e) {
@@ -144,10 +162,10 @@
      * Tests native clear key system playback.
      */
     private void testClearKeyPlayback(
-            String mimeType, /*String initDataType,*/ Uri audioUrl, Uri videoUrl,
+            UUID drmSchemeUuid, String mimeType, /*String initDataType,*/ Uri audioUrl, Uri videoUrl,
             int videoWidth, int videoHeight) throws Exception {
 
-        if (!isCryptoSchemeSupportedNative(uuidByteArray(CLEARKEY_SCHEME_UUID))) {
+        if (!isCryptoSchemeSupportedNative(uuidByteArray(drmSchemeUuid))) {
             throw new Error("Crypto scheme is not supported.");
         }
 
@@ -185,7 +203,7 @@
         params.videoUrl = videoUrl.toString();
 
         if (!testClearKeyPlaybackNative(
-            uuidByteArray(CLEARKEY_SCHEME_UUID), params)) {
+            uuidByteArray(drmSchemeUuid), params)) {
             Log.e(TAG, "Fails play back using native media drm APIs.");
         }
         params.surface.release();
@@ -213,9 +231,19 @@
 
     public void testClearKeyPlaybackCenc() throws Exception {
         testClearKeyPlayback(
-                ISO_BMFF_VIDEO_MIME_TYPE,
-                CENC_AUDIO_URL,
-                CENC_CLEARKEY_VIDEO_URL,
-                VIDEO_WIDTH_CENC, VIDEO_HEIGHT_CENC);
+            COMMON_PSSH_SCHEME_UUID,
+            ISO_BMFF_VIDEO_MIME_TYPE,
+            CENC_AUDIO_URL,
+            CENC_CLEARKEY_VIDEO_URL,
+            VIDEO_WIDTH_CENC, VIDEO_HEIGHT_CENC);
+    }
+
+    public void testClearKeyPlaybackCenc2() throws Exception {
+        testClearKeyPlayback(
+            CLEARKEY_SCHEME_UUID,
+            ISO_BMFF_VIDEO_MIME_TYPE,
+            CENC_AUDIO_URL,
+            CENC_CLEARKEY_VIDEO_URL,
+            VIDEO_WIDTH_CENC, VIDEO_HEIGHT_CENC);
     }
 }
diff --git a/tests/tests/os/assets/platform_versions.txt b/tests/tests/os/assets/platform_versions.txt
index a017515..8104cab 100644
--- a/tests/tests/os/assets/platform_versions.txt
+++ b/tests/tests/os/assets/platform_versions.txt
@@ -1 +1 @@
-OMR1
+8.1.0
diff --git a/tests/tests/permission2/src/android/permission2/cts/PrivappPermissionsTest.java b/tests/tests/permission2/src/android/permission2/cts/PrivappPermissionsTest.java
index 11dfb99..f85314e 100644
--- a/tests/tests/permission2/src/android/permission2/cts/PrivappPermissionsTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/PrivappPermissionsTest.java
@@ -94,21 +94,26 @@
                 Set<String> notGranted = new TreeSet<>(requestedPrivPermissions);
                 notGranted.removeAll(grantedPrivPermissions);
                 Set<String> whitelist = getPrivAppPermissions(pkg.packageName);
-                Log.i(TAG, "Application " + pkg.packageName + ". Requested permissions: "
-                        + requestedPrivPermissions + ". Granted permissions: "
-                        + grantedPrivPermissions + ". Not granted: " + notGranted + " Whitelisted: "
-                        + whitelist);
+                Set<String> denylist = getPrivAppDenyPermissions(pkg.packageName);
+                Log.i(TAG, "Application " + pkg.packageName + "."
+                        + " Requested permissions: " + requestedPrivPermissions + "."
+                        + " Granted permissions: " + grantedPrivPermissions + "."
+                        + " Not granted: " + notGranted + "."
+                        + " Whitelisted: " + whitelist + "."
+                        + " Denylisted: " + denylist);
 
                 Set<String> grantedNotInWhitelist = new TreeSet<>(grantedPrivPermissions);
                 grantedNotInWhitelist.removeAll(whitelist);
+                Set<String> notGrantedNotInDenylist = new TreeSet<>(notGranted);
+                notGrantedNotInDenylist.removeAll(denylist);
 
                 assertTrue("Not whitelisted permissions are granted for package "
                                 + pkg.packageName + ": " + grantedNotInWhitelist,
                         grantedNotInWhitelist.isEmpty());
 
                 assertTrue("Requested permissions not granted for package "
-                                + pkg.packageName + ": " + notGranted,
-                        notGranted.isEmpty());
+                                + pkg.packageName + ": " + notGrantedNotInDenylist,
+                        notGrantedNotInDenylist.isEmpty());
             }
         }
     }
@@ -124,4 +129,15 @@
         return Collections.emptySet();
     }
 
+    private Set<String> getPrivAppDenyPermissions(String packageName) throws IOException {
+        String output = SystemUtil.runShellCommand(
+                InstrumentationRegistry.getInstrumentation(),
+                "cmd package get-privapp-deny-permissions " + packageName).trim();
+        if (output.startsWith("{") && output.endsWith("}")) {
+            String[] split = output.substring(1, output.length() - 1).split("\\s*,\\s*");
+            return new LinkedHashSet<>(Arrays.asList(split));
+        }
+        return Collections.emptySet();
+    }
+
 }
diff --git a/tests/tests/print/AndroidTest.xml b/tests/tests/print/AndroidTest.xml
index 1573840..1c771d6 100644
--- a/tests/tests/print/AndroidTest.xml
+++ b/tests/tests/print/AndroidTest.xml
@@ -14,11 +14,14 @@
      limitations under the License.
 -->
 <configuration description="Config for CTS Print test cases">
+    <option name="not-shardable" value="true" />
     <option name="config-descriptor:metadata" key="component" value="framework" />
+
     <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
         <option name="cleanup-apks" value="true" />
         <option name="test-file-name" value="CtsPrintTestCases.apk" />
     </target_preparer>
+
     <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
         <option name="package" value="android.print.cts" />
         <option name="runtime-hint" value="33m00s" />
diff --git a/tests/tests/security/res/raw/bug_62187433.mp4 b/tests/tests/security/res/raw/bug_62187433.mp4
new file mode 100644
index 0000000..058d0f4
--- /dev/null
+++ b/tests/tests/security/res/raw/bug_62187433.mp4
Binary files differ
diff --git a/tests/tests/security/res/raw/cve_2016_6712.mp3 b/tests/tests/security/res/raw/cve_2016_6712.mp3
new file mode 100644
index 0000000..7804a75
--- /dev/null
+++ b/tests/tests/security/res/raw/cve_2016_6712.mp3
Binary files differ
diff --git a/tests/tests/security/src/android/security/cts/StagefrightTest.java b/tests/tests/security/src/android/security/cts/StagefrightTest.java
index 8468bd7..9c73599 100644
--- a/tests/tests/security/src/android/security/cts/StagefrightTest.java
+++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java
@@ -74,6 +74,11 @@
      ***********************************************************/
 
     @SecurityTest
+    public void testStagefright_bug_62187433() throws Exception {
+        doStagefrightTest(R.raw.bug_62187433);
+    }
+
+    @SecurityTest
     public void testStagefrightANR_bug_62673844() throws Exception {
         doStagefrightTestANR(R.raw.bug_62673844);
     }
@@ -222,6 +227,11 @@
     }
 
     @SecurityTest
+    public void testStagefright_cve_2016_6712() throws Exception {
+        doStagefrightTest(R.raw.cve_2016_6712);
+    }
+
+    @SecurityTest
     public void testStagefright_bug_34097672() throws Exception {
         doStagefrightTest(R.raw.bug_34097672);
     }
diff --git a/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java b/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
index eb59329..cd463a3 100644
--- a/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
+++ b/tests/tests/view/src/android/view/cts/surfacevalidator/CapturedActivity.java
@@ -40,6 +40,7 @@
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.Display;
+import android.view.PointerIcon;
 import android.view.View;
 import android.view.cts.R;
 import android.widget.FrameLayout;
@@ -89,6 +90,9 @@
 
         getWindow().getDecorView().setSystemUiVisibility(
                 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);
+        // Set the NULL pointer icon so that it won't obstruct the captured image.
+        getWindow().getDecorView().setPointerIcon(
+                PointerIcon.getSystemIcon(this, PointerIcon.TYPE_NULL));
 
         mProjectionManager =
                 (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index b1ddfcb..a21e4cc 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -18,6 +18,7 @@
 
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.ContextWrapper;
 import android.content.res.AssetManager;
 import android.graphics.Bitmap;
 import android.graphics.Bitmap.Config;
@@ -58,10 +59,12 @@
 import android.webkit.CookieSyncManager;
 import android.webkit.DownloadListener;
 import android.webkit.JavascriptInterface;
+import android.webkit.SafeBrowsingResponse;
 import android.webkit.ValueCallback;
 import android.webkit.WebBackForwardList;
 import android.webkit.WebChromeClient;
 import android.webkit.WebIconDatabase;
+import android.webkit.WebResourceRequest;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebView.HitTestResult;
@@ -97,7 +100,9 @@
 import java.util.concurrent.FutureTask;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.http.Header;
@@ -2613,6 +2618,54 @@
         assertTrue(callbackLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
     }
 
+    public void testSetSafeBrowsingWhitelistWithMalformedList() throws Exception {
+        List whitelist = new ArrayList<String>();
+        // Protocols are not supported in the whitelist
+        whitelist.add("http://google.com");
+        final CountDownLatch resultLatch = new CountDownLatch(1);
+        WebView.setSafeBrowsingWhitelist(whitelist, new ValueCallback<Boolean>() {
+            @Override
+            public void onReceiveValue(Boolean success) {
+                assertFalse(success);
+                resultLatch.countDown();
+            }
+        });
+        assertTrue(resultLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
+    }
+
+    public void testSetSafeBrowsingWhitelistWithValidList() throws Exception {
+        List whitelist = new ArrayList<String>();
+        whitelist.add("safe-browsing");
+        final CountDownLatch resultLatch = new CountDownLatch(1);
+        WebView.setSafeBrowsingWhitelist(whitelist, new ValueCallback<Boolean>() {
+            @Override
+            public void onReceiveValue(Boolean success) {
+                assertTrue(success);
+                resultLatch.countDown();
+            }
+        });
+        assertTrue(resultLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
+
+        final CountDownLatch resultLatch2 = new CountDownLatch(1);
+        mOnUiThread.setWebViewClient(new WebViewClient() {
+            @Override
+            public void onPageFinished(WebView view, String url) {
+                resultLatch2.countDown();
+            }
+
+            @Override
+            public void onSafeBrowsingHit(WebView view, WebResourceRequest request, int threatType,
+                    SafeBrowsingResponse callback) {
+                Assert.fail("Should not invoke onSafeBrowsingHit");
+            }
+        });
+
+        mOnUiThread.loadUrl("chrome://safe-browsing/match?type=malware");
+
+        // Wait until page load has completed
+        assertTrue(resultLatch2.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
+    }
+
     @UiThreadTest
     public void testGetWebViewClient() throws Exception {
         if (!NullWebViewUtils.isWebViewAvailable()) {
@@ -2682,6 +2735,71 @@
         assertSame(webView.getTextClassifier(), classifier);
     }
 
+    private static class MockContext extends ContextWrapper {
+        private boolean mGetApplicationContextWasCalled;
+
+        public MockContext(Context context) {
+            super(context);
+        }
+
+        public Context getApplicationContext() {
+            mGetApplicationContextWasCalled = true;
+            return super.getApplicationContext();
+        }
+
+        public boolean wasGetApplicationContextCalled() {
+            return mGetApplicationContextWasCalled;
+        }
+    }
+
+    public void testInitSafeBrowsingUseApplicationContext() throws Exception {
+        final MockContext ctx = new MockContext(getActivity());
+        final CountDownLatch resultLatch = new CountDownLatch(1);
+        WebView.initSafeBrowsing(ctx, new ValueCallback<Boolean>() {
+            @Override
+            public void onReceiveValue(Boolean value) {
+                assertTrue(ctx.wasGetApplicationContextCalled());
+                resultLatch.countDown();
+                return;
+            }
+        });
+        assertTrue(resultLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
+    }
+
+    public void testInitSafeBrowsingWithNullCallbackDoesntCrash() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
+        WebView.initSafeBrowsing(getActivity().getApplicationContext(), null);
+    }
+
+    public void testInitSafeBrowsingInvokesCallback() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
+        final CountDownLatch resultLatch = new CountDownLatch(1);
+        WebView.initSafeBrowsing(getActivity().getApplicationContext(),
+                new ValueCallback<Boolean>() {
+            @Override
+            public void onReceiveValue(Boolean value) {
+                assertTrue(Looper.getMainLooper().isCurrentThread());
+                resultLatch.countDown();
+                return;
+            }
+        });
+        assertTrue(resultLatch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS));
+    }
+
+    public void testShutdownSafeBrowsingDoesntCrash() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
+        WebView.shutdownSafeBrowsing();
+    }
+
     private void savePrintedPage(final PrintDocumentAdapter adapter,
             final ParcelFileDescriptor descriptor, final FutureTask<Boolean> result) {
         adapter.onWrite(new PageRange[] {PageRange.ALL_PAGES}, descriptor,
diff --git a/tests/tests/widget/src/android/widget/cts/DatePickerTest.java b/tests/tests/widget/src/android/widget/cts/DatePickerTest.java
index a45ac2b..b3c10e3 100644
--- a/tests/tests/widget/src/android/widget/cts/DatePickerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/DatePickerTest.java
@@ -19,6 +19,7 @@
 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.any;
 import static org.mockito.Mockito.anyInt;
@@ -38,6 +39,7 @@
 import android.support.test.runner.AndroidJUnit4;
 import android.util.SparseArray;
 import android.view.View;
+import android.view.autofill.AutofillValue;
 import android.widget.DatePicker;
 
 import org.junit.Before;
@@ -47,6 +49,7 @@
 
 import java.util.Calendar;
 import java.util.GregorianCalendar;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Test {@link DatePicker}.
@@ -88,13 +91,22 @@
     @UiThreadTest
     @Test
     public void testSetEnabled() {
-        assertTrue(mDatePickerCalendarMode.isEnabled());
+        verifySetEnabled(mDatePickerSpinnerMode);
+        verifySetEnabled(mDatePickerCalendarMode);
+    }
 
-        mDatePickerCalendarMode.setEnabled(false);
-        assertFalse(mDatePickerCalendarMode.isEnabled());
+    private void verifySetEnabled(DatePicker datePicker) {
+        assertTrue(datePicker.isEnabled());
 
-        mDatePickerCalendarMode.setEnabled(true);
-        assertTrue(mDatePickerCalendarMode.isEnabled());
+        datePicker.setEnabled(false);
+        assertFalse(datePicker.isEnabled());
+        assertNull(datePicker.getAutofillValue());
+        assertEquals(View.AUTOFILL_TYPE_NONE, datePicker.getAutofillType());
+
+        datePicker.setEnabled(true);
+        assertTrue(datePicker.isEnabled());
+        assertNotNull(datePicker.getAutofillValue());
+        assertEquals(View.AUTOFILL_TYPE_DATE, datePicker.getAutofillType());
     }
 
     private void verifyInit(DatePicker datePicker) {
@@ -102,9 +114,7 @@
                 mock(DatePicker.OnDateChangedListener.class);
 
         datePicker.init(2000, 10, 15, mockDateChangeListener);
-        assertEquals(2000, datePicker.getYear());
-        assertEquals(10, datePicker.getMonth());
-        assertEquals(15, datePicker.getDayOfMonth());
+        assertValues(datePicker, 2000, 10, 15);
 
         verifyZeroInteractions(mockDateChangeListener);
     }
@@ -121,16 +131,12 @@
                 mock(DatePicker.OnDateChangedListener.class);
 
         datePicker.init(2000, 10, 15, mockDateChangeListener);
-        assertEquals(2000, datePicker.getYear());
-        assertEquals(10, datePicker.getMonth());
-        assertEquals(15, datePicker.getDayOfMonth());
+        assertValues(datePicker, 2000, 10, 15);
         verify(mockDateChangeListener, never()).onDateChanged(any(DatePicker.class), anyInt(),
                 anyInt(), anyInt());
 
         datePicker.updateDate(1989, 9, 19);
-        assertEquals(1989, datePicker.getYear());
-        assertEquals(9, datePicker.getMonth());
-        assertEquals(19, datePicker.getDayOfMonth());
+        assertValues(datePicker, 1989, 9, 19);
         verify(mockDateChangeListener, times(1)).onDateChanged(datePicker, 1989, 9, 19);
 
         verifyNoMoreInteractions(mockDateChangeListener);
@@ -151,17 +157,13 @@
 
         datePicker.init(2000, 10, 15, mockDateChangeListener1);
         datePicker.updateDate(1989, 9, 19);
-        assertEquals(1989, datePicker.getYear());
-        assertEquals(9, datePicker.getMonth());
-        assertEquals(19, datePicker.getDayOfMonth());
+        assertValues(datePicker, 1989, 9, 19);
         verify(mockDateChangeListener1, times(1)).onDateChanged(datePicker, 1989, 9, 19);
         verify(mockDateChangeListener2, times(0)).onDateChanged(datePicker, 1989, 9, 19);
 
         datePicker.setOnDateChangedListener(mockDateChangeListener2);
         datePicker.updateDate(2000, 10, 15);
-        assertEquals(2000, datePicker.getYear());
-        assertEquals(10, datePicker.getMonth());
-        assertEquals(15, datePicker.getDayOfMonth());
+        assertValues(datePicker, 2000, 10, 15);
         verify(mockDateChangeListener1, times(0)).onDateChanged(datePicker, 2000, 10, 15);
         verify(mockDateChangeListener2, times(1)).onDateChanged(datePicker, 2000, 10, 15);
     }
@@ -175,9 +177,7 @@
 
     private void verifyUpdateDate(DatePicker datePicker) {
         datePicker.updateDate(1989, 9, 19);
-        assertEquals(1989, datePicker.getYear());
-        assertEquals(9, datePicker.getMonth());
-        assertEquals(19, datePicker.getDayOfMonth());
+        assertValues(datePicker, 1989, 9, 19);
     }
 
     @UiThreadTest
@@ -295,12 +295,64 @@
         datePicker.setId(99);
         assertFalse(datePicker.hasCalledOnRestoreInstanceState());
         datePicker.dispatchRestoreInstanceState(container);
-        assertEquals(2008, datePicker.getYear());
-        assertEquals(9, datePicker.getMonth());
-        assertEquals(10, datePicker.getDayOfMonth());
+        assertValues(datePicker, 2008, 9, 10);
         assertTrue(datePicker.hasCalledOnRestoreInstanceState());
     }
 
+    @UiThreadTest
+    @Test
+    public void testAutofill() {
+        verifyAutofill(mDatePickerSpinnerMode);
+        verifyAutofill(mDatePickerCalendarMode);
+    }
+
+    private void verifyAutofill(DatePicker datePicker) {
+        datePicker.setEnabled(true);
+
+        final AtomicInteger numberOfListenerCalls = new AtomicInteger();
+        datePicker.setOnDateChangedListener(
+                (v, y, m, d) -> numberOfListenerCalls.incrementAndGet());
+
+        final Calendar calendar = new GregorianCalendar();
+        calendar.set(2012, Calendar.DECEMBER, 21);
+
+        final AutofillValue autofilledValue = AutofillValue.forDate(calendar.getTimeInMillis());
+        datePicker.autofill(autofilledValue);
+        assertEquals(autofilledValue, datePicker.getAutofillValue());
+        assertValues(datePicker, 2012, Calendar.DECEMBER, 21);
+        assertEquals(1, numberOfListenerCalls.get());
+
+        // Make sure autofill() is ignored when value is null.
+        numberOfListenerCalls.set(0);
+        datePicker.autofill((AutofillValue) null);
+        assertEquals(autofilledValue, datePicker.getAutofillValue());
+        assertValues(datePicker, 2012, Calendar.DECEMBER, 21);
+        assertEquals(datePicker.getAutofillValue(), autofilledValue);
+        assertEquals(0, numberOfListenerCalls.get());
+
+        // Make sure autofill() is ignored when value is not a date.
+        numberOfListenerCalls.set(0);
+        datePicker.autofill(AutofillValue.forText("Y U NO IGNORE ME?"));
+        assertEquals(autofilledValue, datePicker.getAutofillValue());
+        assertValues(datePicker, 2012, Calendar.DECEMBER, 21);
+        assertEquals(datePicker.getAutofillValue(), autofilledValue);
+        assertEquals(0, numberOfListenerCalls.get());
+
+        // Make sure getAutofillValue() is reset when value is manually filled.
+        datePicker.autofill(autofilledValue); // 2012-12-21
+        datePicker.updateDate(2000, Calendar.JANUARY, 1);
+        calendar.setTimeInMillis(datePicker.getAutofillValue().getDateValue());
+        assertEquals(2000, calendar.get(Calendar.YEAR));
+        assertEquals(Calendar.JANUARY, calendar.get(Calendar.MONTH));
+        assertEquals(1, calendar.get(Calendar.DAY_OF_MONTH));
+    }
+
+    private void assertValues(DatePicker datePicker, int year, int month, int dayOfMonth) {
+        assertEquals(year, datePicker.getYear());
+        assertEquals(month, datePicker.getMonth());
+        assertEquals(dayOfMonth, datePicker.getDayOfMonth());
+    }
+
     private class MockDatePicker extends DatePicker {
         private boolean mCalledOnSaveInstanceState = false;
         private boolean mCalledOnRestoreInstanceState = false;
diff --git a/tests/tests/widget/src/android/widget/cts/TimePickerTest.java b/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
index c65da05..eb3e3e1 100644
--- a/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TimePickerTest.java
@@ -19,6 +19,7 @@
 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.reset;
@@ -39,6 +40,7 @@
 import android.util.AttributeSet;
 import android.view.KeyEvent;
 import android.view.View;
+import android.view.autofill.AutofillValue;
 import android.widget.TimePicker;
 
 import com.android.compatibility.common.util.CtsKeyEventUtil;
@@ -50,7 +52,10 @@
 import org.junit.runner.RunWith;
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Test {@link TimePicker}.
@@ -115,9 +120,59 @@
 
         mTimePicker.setEnabled(false);
         assertFalse(mTimePicker.isEnabled());
+        assertNull(mTimePicker.getAutofillValue());
+        assertEquals(View.AUTOFILL_TYPE_NONE, mTimePicker.getAutofillType());
 
         mTimePicker.setEnabled(true);
         assertTrue(mTimePicker.isEnabled());
+        assertNotNull(mTimePicker.getAutofillValue());
+        assertEquals(View.AUTOFILL_TYPE_DATE, mTimePicker.getAutofillType());
+    }
+
+    @UiThreadTest
+    @Test
+    public void testAutofill() {
+        mTimePicker.setEnabled(true);
+
+        final AtomicInteger numberOfListenerCalls = new AtomicInteger();
+        mTimePicker.setOnTimeChangedListener((v, h, m) -> numberOfListenerCalls.incrementAndGet());
+
+        final Calendar calendar = new GregorianCalendar();
+        calendar.set(Calendar.HOUR_OF_DAY, 4);
+        calendar.set(Calendar.MINUTE, 20);
+
+        final AutofillValue autofilledValue = AutofillValue.forDate(calendar.getTimeInMillis());
+        mTimePicker.autofill(autofilledValue);
+        assertEquals(autofilledValue, mTimePicker.getAutofillValue());
+        assertEquals(4, mTimePicker.getHour());
+        assertEquals(20, mTimePicker.getMinute());
+        assertEquals(1, numberOfListenerCalls.get());
+
+        // Make sure autofill() is ignored when value is null.
+        numberOfListenerCalls.set(0);
+        mTimePicker.autofill((AutofillValue) null);
+        assertEquals(autofilledValue, mTimePicker.getAutofillValue());
+        assertEquals(4, mTimePicker.getHour());
+        assertEquals(20, mTimePicker.getMinute());
+        assertEquals(0, numberOfListenerCalls.get());
+
+        // Make sure autofill() is ignored when value is not a date.
+        numberOfListenerCalls.set(0);
+        mTimePicker.autofill(AutofillValue.forText("Y U NO IGNORE ME?"));
+        assertEquals(autofilledValue, mTimePicker.getAutofillValue());
+        assertEquals(4, mTimePicker.getHour());
+        assertEquals(20, mTimePicker.getMinute());
+        assertEquals(0, numberOfListenerCalls.get());
+
+        // Make sure getAutofillValue() is reset when value is manually filled.
+        mTimePicker.autofill(autofilledValue); // 04:20
+        mTimePicker.setHour(10);
+        calendar.setTimeInMillis(mTimePicker.getAutofillValue().getDateValue());
+        assertEquals(10, calendar.get(Calendar.HOUR));
+        mTimePicker.autofill(autofilledValue); // 04:20
+        mTimePicker.setMinute(8);
+        calendar.setTimeInMillis(mTimePicker.getAutofillValue().getDateValue());
+        assertEquals(8, calendar.get(Calendar.MINUTE));
     }
 
     @UiThreadTest
diff --git a/tools/cts-tradefed/res/config/cts-known-failures.xml b/tools/cts-tradefed/res/config/cts-known-failures.xml
index dfc20e6..262d629 100644
--- a/tools/cts-tradefed/res/config/cts-known-failures.xml
+++ b/tools/cts-tradefed/res/config/cts-known-failures.xml
@@ -121,9 +121,6 @@
     <!-- b/36686383 -->
     <option name="compatibility:exclude-filter" value="CtsIncidentHostTestCases com.android.server.cts.ErrorsTest#testANR" />
 
-    <!-- b/37545399 -->
-    <option name="compatibility:exclude-filter" value="CtsSystemUiTestCases android.systemui.cts.LightBarTests#testLightNavigationBar" />
-
     <!-- b/37482372 -->
     <option name="compatibility:exclude-filter" value="CtsPreference2TestCases android.preference2.cts.PreferenceActivityFlowPortraitTest#multiWindowHistoryPreservePortraitTest" />
     <option name="compatibility:exclude-filter" value="CtsPreference2TestCases android.preference2.cts.PreferenceActivityFlowPortraitTest#multiWindowInOutPortraitTest" />