Merge "CtsIncidentHostTestCases: enable bluetoothadapter" into oc-mr1-dev
diff --git a/apps/CtsVerifier/res/layout/dialer_telecom_intents.xml b/apps/CtsVerifier/res/layout/dialer_telecom_intents.xml
index 96d9be6..6c2e3ac 100644
--- a/apps/CtsVerifier/res/layout/dialer_telecom_intents.xml
+++ b/apps/CtsVerifier/res/layout/dialer_telecom_intents.xml
@@ -68,6 +68,13 @@
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/dialer_telecom_intents_call_settings"/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="@dimen/js_padding"
+        android:layout_marginBottom="@dimen/js_padding">
       <CheckBox
           android:id="@+id/dialer_telecom_intents_call_settings_check_box"
           android:text="@string/dialer_check_intents_check_box"
@@ -85,6 +92,13 @@
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/dialer_telecom_intents_short_sms"/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="@dimen/js_padding"
+        android:layout_marginBottom="@dimen/js_padding">
       <CheckBox
           android:id="@+id/dialer_telecom_intents_short_sms_check_box"
           android:text="@string/dialer_check_intents_check_box"
@@ -102,6 +116,13 @@
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/dialer_telecom_intents_calling_accounts"/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="@dimen/js_padding"
+        android:layout_marginBottom="@dimen/js_padding">
       <CheckBox
           android:id="@+id/dialer_telecom_intents_calling_accounts_check_box"
           android:text="@string/dialer_check_intents_check_box"
@@ -119,6 +140,13 @@
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/dialer_telecom_intents_accessibility_settings"/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="@dimen/js_padding"
+        android:layout_marginBottom="@dimen/js_padding">
       <CheckBox
           android:id="@+id/dialer_telecom_intents_accessibility_settings_check_box"
           android:text="@string/dialer_check_intents_check_box"
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundTestActivity.java
index 85b3e37..0276e60 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/HifiUltrasoundTestActivity.java
@@ -102,6 +102,7 @@
         R.string.hifi_ultrasound_test_default_false_string))) {
       micSupport = false;
       getPassButton().setEnabled(true);
+      getPassButton().performClick();
       info.append(getResources().getString(R.string.hifi_ultrasound_test_mic_no_support));
     }
     if (spkrSupportString.equalsIgnoreCase(getResources().getString(
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/EnterprisePrivacyTestListActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/EnterprisePrivacyTestListActivity.java
index a4adfda..71c4421 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/EnterprisePrivacyTestListActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/EnterprisePrivacyTestListActivity.java
@@ -209,20 +209,24 @@
                         new ButtonInfo(R.string.enterprise_privacy_finish,
                                 buildCommandIntent(
                                         CommandReceiverActivity.COMMAND_CLEAR_ALWAYS_ON_VPN))}));
-        adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_COMP_ALWAYS_ON_VPN,
-                R.string.enterprise_privacy_comp_always_on_vpn,
-                R.string.enterprise_privacy_comp_always_on_vpn_info,
-                new ButtonInfo[] {
-                        new ButtonInfo(R.string.enterprise_privacy_start,
-                                buildCommandIntent(
-                                        CommandReceiverActivity.COMMAND_CREATE_MANAGED_PROFILE)),
-                        new ButtonInfo(R.string.enterprise_privacy_open_settings,
-                                new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)),
-                        new ButtonInfo(R.string.enterprise_privacy_set_always_on_vpn,
-                                new Intent(CompHelperActivity.ACTION_SET_ALWAYS_ON_VPN)),
-                        new ButtonInfo(R.string.enterprise_privacy_finish,
-                                buildCommandIntent(
-                                        CommandReceiverActivity.COMMAND_REMOVE_MANAGED_PROFILE))}));
+        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)) {
+            adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_COMP_ALWAYS_ON_VPN,
+                    R.string.enterprise_privacy_comp_always_on_vpn,
+                    R.string.enterprise_privacy_comp_always_on_vpn_info,
+                    new ButtonInfo[] {
+                            new ButtonInfo(R.string.enterprise_privacy_start,
+                                    buildCommandIntent(
+                                            CommandReceiverActivity.
+                                            COMMAND_CREATE_MANAGED_PROFILE)),
+                            new ButtonInfo(R.string.enterprise_privacy_open_settings,
+                                    new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)),
+                            new ButtonInfo(R.string.enterprise_privacy_set_always_on_vpn,
+                                    new Intent(CompHelperActivity.ACTION_SET_ALWAYS_ON_VPN)),
+                            new ButtonInfo(R.string.enterprise_privacy_finish,
+                                    buildCommandIntent(
+                                            CommandReceiverActivity.
+                                            COMMAND_REMOVE_MANAGED_PROFILE))}));
+        }
         adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_GLOBAL_HTTP_PROXY,
                 R.string.enterprise_privacy_global_http_proxy,
                 R.string.enterprise_privacy_global_http_proxy_info,
@@ -247,20 +251,24 @@
                         new ButtonInfo(R.string.enterprise_privacy_finish,
                                 buildCommandIntent(
                                         CommandReceiverActivity.COMMAND_CLEAR_CA_CERT))}));
-        adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_COMP_CA_CERTS,
-                R.string.enterprise_privacy_comp_ca_certs,
-                R.string.enterprise_privacy_comp_ca_certs_info,
-                new ButtonInfo[] {
-                        new ButtonInfo(R.string.enterprise_privacy_start,
-                                buildCommandIntent(
-                                        CommandReceiverActivity.COMMAND_CREATE_MANAGED_PROFILE)),
-                        new ButtonInfo(R.string.enterprise_privacy_settings,
-                                new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)),
-                        new ButtonInfo(R.string.enterprise_privacy_install_cert,
-                                new Intent(CompHelperActivity.ACTION_INSTALL_CA_CERT)),
-                        new ButtonInfo(R.string.enterprise_privacy_finish,
-                                buildCommandIntent(
-                                        CommandReceiverActivity.COMMAND_REMOVE_MANAGED_PROFILE))}));
+        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS)) {
+            adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_COMP_CA_CERTS,
+                    R.string.enterprise_privacy_comp_ca_certs,
+                    R.string.enterprise_privacy_comp_ca_certs_info,
+                    new ButtonInfo[] {
+                            new ButtonInfo(R.string.enterprise_privacy_start,
+                                    buildCommandIntent(
+                                            CommandReceiverActivity.
+                                            COMMAND_CREATE_MANAGED_PROFILE)),
+                            new ButtonInfo(R.string.enterprise_privacy_settings,
+                                    new Intent(Settings.ACTION_ENTERPRISE_PRIVACY_SETTINGS)),
+                            new ButtonInfo(R.string.enterprise_privacy_install_cert,
+                                    new Intent(CompHelperActivity.ACTION_INSTALL_CA_CERT)),
+                            new ButtonInfo(R.string.enterprise_privacy_finish,
+                                    buildCommandIntent(
+                                            CommandReceiverActivity.
+                                            COMMAND_REMOVE_MANAGED_PROFILE))}));
+        }
         // Disabled for API 26 due to b/63696536.
         // adapter.add(createInteractiveTestItem(this, ENTERPRISE_PRIVACY_FAILED_PASSWORD_WIPE,
         //         R.string.enterprise_privacy_failed_password_wipe,
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
index c941ff2..e86fae9 100644
--- a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
@@ -48,7 +48,9 @@
 LOCAL_CERTIFICATE := PRESIGNED
 LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
 
-LOCAL_SRC_FILES := CtsShimPrivUpgrade.apk
+my_archs := arm x86
+my_src_arch := $(call get-prebuilt-src-arch, $(my_archs))
+LOCAL_REPLACE_PREBUILT_APK_INSTALLED := $(LOCAL_PATH)/apk/$(my_src_arch)/CtsShimPrivUpgrade.apk
 
 include $(BUILD_PREBUILT)
 
@@ -65,6 +67,8 @@
 LOCAL_CERTIFICATE := PRESIGNED
 LOCAL_COMPATIBILITY_SUITE := cts vts general-tests
 
-LOCAL_SRC_FILES := CtsShimPrivUpgradeWrongSHA.apk
+my_archs := arm x86
+my_src_arch := $(call get-prebuilt-src-arch, $(my_archs))
+LOCAL_REPLACE_PREBUILT_APK_INSTALLED := $(LOCAL_PATH)/apk/$(my_src_arch)/CtsShimPrivUpgradeWrongSHA.apk
 
 include $(BUILD_PREBUILT)
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/CtsShimPrivUpgrade.apk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/CtsShimPrivUpgrade.apk
deleted file mode 100644
index a277907..0000000
--- a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/CtsShimPrivUpgrade.apk
+++ /dev/null
Binary files differ
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/CtsShimPrivUpgradeWrongSHA.apk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/CtsShimPrivUpgradeWrongSHA.apk
deleted file mode 100644
index a40f791..0000000
--- a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/CtsShimPrivUpgradeWrongSHA.apk
+++ /dev/null
Binary files differ
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/arm/CtsShimPrivUpgrade.apk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/arm/CtsShimPrivUpgrade.apk
new file mode 100644
index 0000000..23df503
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/arm/CtsShimPrivUpgrade.apk
Binary files differ
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/arm/CtsShimPrivUpgradeWrongSHA.apk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/arm/CtsShimPrivUpgradeWrongSHA.apk
new file mode 100644
index 0000000..11f8674
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/arm/CtsShimPrivUpgradeWrongSHA.apk
Binary files differ
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/x86/CtsShimPrivUpgrade.apk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/x86/CtsShimPrivUpgrade.apk
new file mode 100644
index 0000000..fc9f02e
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/x86/CtsShimPrivUpgrade.apk
Binary files differ
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/x86/CtsShimPrivUpgradeWrongSHA.apk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/x86/CtsShimPrivUpgradeWrongSHA.apk
new file mode 100644
index 0000000..bf49682
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/apk/x86/CtsShimPrivUpgradeWrongSHA.apk
Binary files differ
diff --git a/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java b/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
index 48cff55..0fa7e87 100644
--- a/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
+++ b/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
@@ -203,8 +203,9 @@
     }
 
     private boolean hasNotificationSupport() {
-        return !getContext().getPackageManager()
-                .hasSystemFeature(PackageManager.FEATURE_LEANBACK);
+        final PackageManager manager = getContext().getPackageManager();
+        return !manager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
+                && !manager.hasSystemFeature(PackageManager.FEATURE_EMBEDDED);
     }
 
     private void allowSyncAdapterRunInBackgroundAndDataInBackground() throws IOException {
diff --git a/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/SuspendPackageTest.java b/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/SuspendPackageTest.java
index 19c13b5..a505b52 100644
--- a/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/SuspendPackageTest.java
+++ b/hostsidetests/devicepolicy/app/IntentSender/src/com/android/cts/intent/sender/SuspendPackageTest.java
@@ -100,6 +100,6 @@
 
     private boolean isWatch() {
         return (getInstrumentation().getContext().getResources().getConfiguration().uiMode
-                & Configuration.UI_MODE_TYPE_WATCH) == Configuration.UI_MODE_TYPE_WATCH;
+                & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_WATCH;
     }
 }
diff --git a/hostsidetests/incident/apps/batterystatsapp/src/com/android/server/cts/device/batterystats/SimpleForegroundService.java b/hostsidetests/incident/apps/batterystatsapp/src/com/android/server/cts/device/batterystats/SimpleForegroundService.java
index ce690a6..a53cc1b 100644
--- a/hostsidetests/incident/apps/batterystatsapp/src/com/android/server/cts/device/batterystats/SimpleForegroundService.java
+++ b/hostsidetests/incident/apps/batterystatsapp/src/com/android/server/cts/device/batterystats/SimpleForegroundService.java
@@ -17,8 +17,12 @@
 package com.android.server.cts.device.batterystats;
 
 import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
 import android.app.Service;
+import android.content.Context;
 import android.content.Intent;
+import android.os.Build;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
@@ -27,10 +31,14 @@
 import android.os.Process;
 import android.util.Log;
 
+import com.android.compatibility.common.util.ApiLevelUtil;
+
 public class SimpleForegroundService extends Service {
     private static final String TAG = "SimpleForegroundService";
+    private static final String NOTIFICATION_CHANNEL_ID = "Foreground Service";
     private Looper mServiceLooper;
     private ServiceHandler mServiceHandler;
+    private boolean mChannelCreated;
 
     private final class ServiceHandler extends Handler {
         public ServiceHandler(Looper looper) {
@@ -67,11 +75,23 @@
         // Get the HandlerThread's Looper and use it for our Handler
         mServiceLooper = thread.getLooper();
         mServiceHandler = new ServiceHandler(mServiceLooper);
+
+        if (ApiLevelUtil.isBefore(Build.VERSION_CODES.O_MR1)) {
+            return;
+        }
+        // OMR1 requires notification channel to be set
+        NotificationManager notificationManager =
+                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
+                NOTIFICATION_CHANNEL_ID,
+                NotificationManager.IMPORTANCE_HIGH);
+        notificationManager.createNotificationChannel(channel);
+        mChannelCreated = true;
     }
 
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
-        Notification notification = new Notification.Builder(this, "Foreground Service")
+        Notification notification = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
                 .setContentTitle("CTS Foreground")
                 .setSmallIcon(android.R.drawable.ic_secure)
                 .build();
@@ -89,4 +109,13 @@
     public IBinder onBind(Intent intent) {
         return null;
     }
+
+    @Override
+    public void onDestroy () {
+        if (mChannelCreated) {
+            NotificationManager notificationManager =
+                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+            notificationManager.deleteNotificationChannel(NOTIFICATION_CHANNEL_ID);
+        }
+    }
 }
diff --git a/tests/tests/app.usage/Android.mk b/tests/tests/app.usage/Android.mk
index 84559fa..dbef83c 100644
--- a/tests/tests/app.usage/Android.mk
+++ b/tests/tests/app.usage/Android.mk
@@ -24,13 +24,12 @@
 # and when built explicitly put it in the data partition
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
 LOCAL_STATIC_JAVA_LIBRARIES := \
-    ctstestrunner \
     android-support-test \
+    ctstestrunner \
     junit \
-    legacy-android-test
+    legacy-android-test \
+    ub-uiautomator
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
diff --git a/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java b/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
index d900292..ddc59b3 100644
--- a/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
+++ b/tests/tests/app.usage/src/android/app/usage/cts/UsageStatsTest.java
@@ -18,27 +18,28 @@
 
 import android.app.Activity;
 import android.app.AppOpsManager;
-import android.app.Instrumentation;
 import android.app.usage.UsageEvents;
 import android.app.usage.UsageStats;
 import android.app.usage.UsageStatsManager;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Parcel;
-import android.os.ParcelFileDescriptor;
 import android.os.SystemClock;
+import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.Until;
 import android.test.InstrumentationTestCase;
+import android.util.SparseLongArray;
 
-import java.io.FileInputStream;
-import java.io.IOException;
+import junit.framework.AssertionFailedError;
+
+import org.junit.Ignore;
+
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-
-import android.util.SparseLongArray;
-import junit.framework.AssertionFailedError;
-import org.junit.Ignore;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Test the UsageStats API. It is difficult to test the entire surface area
@@ -58,19 +59,22 @@
     private static final String APPOPS_SET_SHELL_COMMAND = "appops set {0} " +
             AppOpsManager.OPSTR_GET_USAGE_STATS + " {1}";
 
-    private static final long MINUTE = 1000 * 60;
-    private static final long DAY = MINUTE * 60 * 24;
+    private static final long TIMEOUT = TimeUnit.SECONDS.toMillis(5);
+    private static final long MINUTE = TimeUnit.MINUTES.toMillis(1);
+    private static final long DAY = TimeUnit.DAYS.toMillis(1);
     private static final long WEEK = 7 * DAY;
     private static final long MONTH = 30 * DAY;
     private static final long YEAR = 365 * DAY;
     private static final long TIME_DIFF_THRESHOLD = 200;
 
+    private UiDevice mUiDevice;
     private UsageStatsManager mUsageStatsManager;
     private String mTargetPackage;
-    private ArrayList<Activity> mStartedActivities = new ArrayList<>();
 
     @Override
     protected void setUp() throws Exception {
+        super.setUp();
+        mUiDevice = UiDevice.getInstance(getInstrumentation());
         mUsageStatsManager = (UsageStatsManager) getInstrumentation().getContext()
                 .getSystemService(Context.USAGE_STATS_SERVICE);
         mTargetPackage = getInstrumentation().getContext().getPackageName();
@@ -78,13 +82,6 @@
         setAppOpsMode("allow");
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        for (Activity activity : mStartedActivities) {
-            activity.finish();
-        }
-    }
-
     private static void assertLessThan(long left, long right) {
         if (left >= right) {
             throw new AssertionFailedError("Expected " + left + " to be less than " + right);
@@ -101,28 +98,16 @@
     private void setAppOpsMode(String mode) throws Exception {
         final String command = MessageFormat.format(APPOPS_SET_SHELL_COMMAND,
                 getInstrumentation().getContext().getPackageName(), mode);
-        ParcelFileDescriptor pfd = getInstrumentation().getUiAutomation()
-                .executeShellCommand(command);
-        try (FileInputStream fis = new FileInputStream(pfd.getFileDescriptor())){
-            final byte[] buffer = new byte[4096];
-            while (fis.read(buffer) != -1) { }
-        } finally {
-            try {
-                pfd.close();
-            } catch (IOException e) {
-                // Ignore.
-            }
-        }
+        mUiDevice.executeShellCommand(command);
     }
 
     private void launchSubActivity(Class<? extends Activity> clazz) {
-        final Instrumentation.ActivityResult result =
-                new Instrumentation.ActivityResult(0, new Intent());
-        final Instrumentation.ActivityMonitor monitor =
-                new Instrumentation.ActivityMonitor(clazz.getName(), result, false);
-        getInstrumentation().addMonitor(monitor);
-        launchActivity(mTargetPackage, clazz, null);
-        mStartedActivities.add(monitor.waitForActivity());
+        final Context context = getInstrumentation().getContext();
+        final Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.setClassName(mTargetPackage, clazz.getName());
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        context.startActivity(intent);
+        mUiDevice.wait(Until.hasObject(By.clazz(clazz)), TIMEOUT);
     }
 
     private void launchSubActivities(Class<? extends Activity>[] activityClasses) {
@@ -323,7 +308,9 @@
                 startTime, endTime);
         assertFalse(stats.isEmpty());
 
-        setAppOpsMode("default");
+        // We set the mode to ignore because our package has the PACKAGE_USAGE_STATS permission,
+        // and default would allow in this case.
+        setAppOpsMode("ignore");
 
         stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST,
                 startTime, endTime);
diff --git a/tests/tests/media/AndroidManifest.xml b/tests/tests/media/AndroidManifest.xml
index 9d2af70..482cd6a 100644
--- a/tests/tests/media/AndroidManifest.xml
+++ b/tests/tests/media/AndroidManifest.xml
@@ -40,7 +40,8 @@
             android:label="AudioManagerStubHelper"/>
         <activity android:name="android.media.cts.DecodeAccuracyTestActivity"
             android:label="DecodeAccuracyTestActivity"
-            android:screenOrientation="locked">
+            android:screenOrientation="locked"
+            android:configChanges="mcc|mnc|keyboard|keyboardHidden|orientation|screenSize|navigation">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
diff --git a/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java b/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
index c273d13..6c4de33 100644
--- a/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
+++ b/tests/tests/transition/src/android/transition/cts/ActivityTransitionTest.java
@@ -465,7 +465,7 @@
         mActivityRule.runOnUiThread(() -> targetActivity.finishAfterTransition());
 
         // Should only take a short time, but there's no need to rush it on failure.
-        assertTrue(startCalled.await(1, TimeUnit.SECONDS));
+        assertTrue(startCalled.await(5, TimeUnit.SECONDS));
 
         TargetActivity.sLastCreated = null;
     }