Merge "Attempt to fix AssistantStackTests presubmit flakiness" into tm-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 05c70e0..e7b33f7 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -18,9 +18,9 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.android.cts.verifier"
           android:versionCode="5"
-          android:versionName="12.1_r1">
+          android:versionName="13_r1">
 
-    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="31"/>
+    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="33"/>
 
     <uses-permission android:name="android.car.permission.CAR_POWERTRAIN" />
     <uses-permission android:name="android.car.permission.READ_CAR_POWER_POLICY" />
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/MidiJavaTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/MidiJavaTestActivity.java
index d3afa36..b8c63a7 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/MidiJavaTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/MidiJavaTestActivity.java
@@ -16,9 +16,6 @@
 
 package com.android.cts.verifier.audio;
 
-import java.io.IOException;
-import java.util.ArrayList;
-
 import android.media.midi.MidiDevice;
 import android.media.midi.MidiDeviceInfo;
 import android.media.midi.MidiInputPort;
@@ -28,11 +25,12 @@
 import android.util.Log;
 
 import com.android.compatibility.common.util.CddTest;
-
 import com.android.cts.verifier.R;
-
 import com.android.cts.verifier.audio.midilib.MidiIODevice;
 
+import java.io.IOException;
+import java.util.ArrayList;
+
 /*
  * A note about the USB MIDI device.
  * Any USB MIDI peripheral with standard female DIN jacks can be used. A standard MIDI cable
@@ -60,7 +58,7 @@
 @CddTest(requirement = "5.9/C-1-4,C-1-2")
 public class MidiJavaTestActivity extends MidiTestActivityBase {
     private static final String TAG = "MidiJavaTestActivity";
-    private static final boolean DEBUG = false;
+    private static final boolean DEBUG = true;
 
     public MidiJavaTestActivity() {
         super();
@@ -209,6 +207,10 @@
             closePorts();
 
             if (mIODevice.mSendDevInfo != null) {
+                if (DEBUG) {
+                    Log.i(TAG, "---- mMidiManager.openDevice() mSendDevice: "
+                            + mIODevice.mSendDevInfo);
+                }
                 mMidiManager.openDevice(mIODevice.mSendDevInfo, new TestModuleOpenListener(), null);
             }
 
@@ -216,6 +218,9 @@
         }
 
         protected void openPorts(MidiDevice device) {
+            if (DEBUG) {
+                Log.i(TAG, "---- openPorts()");
+            }
             mIODevice.openPorts(device, new MidiMatchingReceiver());
         }
 
@@ -427,7 +432,8 @@
             @Override
             public void onSend(byte[] msg, int offset, int count, long timestamp) throws IOException {
                 if (DEBUG) {
-                    Log.i(TAG, "---- onSend(offset:" + offset + " count:" + count);
+                    Log.i(TAG, "---- onSend(offset:" + offset
+                            + " count:" + count + ") mTestRunning:" + mTestRunning);
                     logByteArray("bytes-received: ", msg, offset, count);
                 }
                 synchronized (mTestLock) {
@@ -446,6 +452,11 @@
 
                     mTestMismatched = !matchStream(msg, offset, count);
 
+                    if (DEBUG) {
+                        Log.i(TAG, "  mTestMismatched:" + mTestMismatched);
+                        Log.i(TAG, "  mReceiveStreamPos:" + mReceiveStreamPos + " size:"
+                                + mMatchStream.size());
+                    }
                     if (mTestMismatched || mReceiveStreamPos == mMatchStream.size()) {
                         mTestRunning = false;
                         mRunningTestID = TESTID_NONE;
@@ -462,7 +473,10 @@
                             }
                         }).start();
 
+                        mTestStatus = mTestMismatched
+                                ? TESTSTATUS_FAILED_MISMATCH : TESTSTATUS_PASSED;
                         enableTestButtons(true);
+
                         updateTestStateUI();
                     }
                 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/MidiTestActivityBase.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/MidiTestActivityBase.java
index 2f4ff7b..327cb0f 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/MidiTestActivityBase.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/MidiTestActivityBase.java
@@ -48,7 +48,7 @@
         implements View.OnClickListener {
 
     private static final String TAG = "MidiTestActivityBase";
-    private static final boolean DEBUG = false;
+    private static final boolean DEBUG = true;
 
     protected MidiManager mMidiManager;
 
@@ -212,7 +212,13 @@
             Log.i(TAG, "scanMidiDevices()....");
         }
 
+        // Get the list of all MIDI devices attached
         MidiDeviceInfo[] devInfos = mMidiManager.getDevices();
+        if (DEBUG) {
+            Log.i(TAG, "  numDevices:" + devInfos.length);
+        }
+
+        // Let each module select (if available) the associated device for their type
         mUSBTestModule.scanDevices(devInfos);
         mVirtualTestModule.scanDevices(devInfos);
         mBTTestModule.scanDevices(devInfos);
@@ -378,7 +384,7 @@
         protected boolean             mTestRunning;
 
         // Timeout handling
-        protected static final int    TEST_TIMEOUT_MS = 1000;
+        protected static final int    TEST_TIMEOUT_MS = 5000; // 1000;
         protected final Timer         mTimeoutTimer = new Timer();
 
         public MidiTestModule(int deviceType) {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/midilib/MidiIODevice.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/midilib/MidiIODevice.java
index f9e6781..64a891a 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/midilib/MidiIODevice.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/midilib/MidiIODevice.java
@@ -19,10 +19,9 @@
 import android.media.midi.MidiDevice;
 import android.media.midi.MidiDeviceInfo;
 import android.media.midi.MidiInputPort;
-import android.media.midi.MidiManager;
 import android.media.midi.MidiOutputPort;
 import android.media.midi.MidiReceiver;
-
+import android.os.Bundle;
 import android.util.Log;
 
 import java.io.IOException;
@@ -56,11 +55,32 @@
         mReceivePort = null;
 
         for(MidiDeviceInfo devInfo : devInfos) {
+            Bundle devBundle = devInfo.getProperties();
+            if (DEBUG) {
+                Log.i(TAG, "  mfg:" + devBundle.getString(MidiDeviceInfo.PROPERTY_MANUFACTURER)
+                        + " prod:" + devBundle.getString(MidiDeviceInfo.PROPERTY_PRODUCT));
+            }
+
             // Inputs?
             int numInPorts = devInfo.getInputPortCount();
             if (numInPorts <= 0) {
                 continue; // none?
             }
+
+            // For virtual MIDI devices, we need to find
+            // manufacturer=AndroidCTSVerifier and product=VerifierMidiEcho or else
+            // it might be some other MIDI app providing virtual MIDI services
+            if (mDeviceType == MidiDeviceInfo.TYPE_VIRTUAL) {
+                if (!devBundle.getString(MidiDeviceInfo.PROPERTY_MANUFACTURER)
+                            .equals("AndroidCTSVerifier")
+                        || !devBundle.getString(MidiDeviceInfo.PROPERTY_PRODUCT)
+                            .equals("VerifierMidiEcho")) {
+                    // Virtual [but not ours]
+                    Log.d(TAG, "Virtual Midi Device:" + devInfo);
+                    continue;
+                }
+            }
+
             if (devInfo.getType() == mDeviceType && mSendDevInfo == null) {
                 mSendDevInfo = devInfo;
             }
@@ -80,12 +100,10 @@
         }
 
         if (DEBUG) {
-            if (mSendDevInfo != null) {
-                Log.i(TAG, "---- mSendDevInfo: " + mSendDevInfo);
-            }
-            if (mReceiveDevInfo != null) {
-                Log.i(TAG, "---- mReceiveDevInfo: " + mReceiveDevInfo);
-            }
+            Log.i(TAG, "---- mSendDevInfo: "
+                    + (mSendDevInfo != null ? mSendDevInfo.toString() : "NONE"));
+            Log.i(TAG, "---- mReceiveDevInfo: "
+                    + (mReceiveDevInfo != null ? mReceiveDevInfo.toString() : "NONE"));
         }
     }
 
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/enterprise/PolicyAppliesTest.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/enterprise/PolicyAppliesTest.java
index fff4e1e..57016cc 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/enterprise/PolicyAppliesTest.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/enterprise/PolicyAppliesTest.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.enterprise;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.PRECEDENCE_NOT_IMPORTANT;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -53,5 +54,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default PRECEDENCE_NOT_IMPORTANT;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeNone.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeNone.java
index fcc333a..d720618 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeNone.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeNone.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -43,5 +44,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnAffiliatedDeviceOwnerSecondaryUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnAffiliatedDeviceOwnerSecondaryUser.java
index 71ad1e5..0ea5d97 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnAffiliatedDeviceOwnerSecondaryUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnAffiliatedDeviceOwnerSecondaryUser.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -50,5 +51,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnAffiliatedProfileOwnerSecondaryUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnAffiliatedProfileOwnerSecondaryUser.java
index acc620a..fb71a2a 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnAffiliatedProfileOwnerSecondaryUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnAffiliatedProfileOwnerSecondaryUser.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -50,5 +51,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnBackgroundDeviceOwnerUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnBackgroundDeviceOwnerUser.java
index 02a5592..61a2a11 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnBackgroundDeviceOwnerUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnBackgroundDeviceOwnerUser.java
@@ -17,6 +17,7 @@
 package com.android.bedstead.harrier.annotations.parameterized;
 
 import static com.android.bedstead.harrier.OptionalBoolean.FALSE;
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -49,5 +50,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnDeviceOwnerUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnDeviceOwnerUser.java
index 0b10e96..0c2dccd 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnDeviceOwnerUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnDeviceOwnerUser.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -50,5 +51,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfCorporateOwnedProfileOwner.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfCorporateOwnedProfileOwner.java
index 548c99b..88b203e 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfCorporateOwnedProfileOwner.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfCorporateOwnedProfileOwner.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -46,5 +47,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfProfileOwnerUsingParentInstance.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfProfileOwnerUsingParentInstance.java
index d70b32a..494f836 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfProfileOwnerUsingParentInstance.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfProfileOwnerUsingParentInstance.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -50,5 +51,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfProfileOwnerWithNoDeviceOwner.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfProfileOwnerWithNoDeviceOwner.java
index 34a9d2a..4131866 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfProfileOwnerWithNoDeviceOwner.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnParentOfProfileOwnerWithNoDeviceOwner.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -49,5 +50,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnPrimaryUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnPrimaryUser.java
index bbdca14..35b1b9b 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnPrimaryUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnPrimaryUser.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -45,5 +46,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnProfileOwnerPrimaryUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnProfileOwnerPrimaryUser.java
index 96c73abb..37e7dba 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnProfileOwnerPrimaryUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnProfileOwnerPrimaryUser.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -50,5 +51,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnProfileOwnerProfileWithNoDeviceOwner.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnProfileOwnerProfileWithNoDeviceOwner.java
index 32749a2..ae92e7b 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnProfileOwnerProfileWithNoDeviceOwner.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnProfileOwnerProfileWithNoDeviceOwner.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -47,5 +48,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnSecondaryUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnSecondaryUser.java
index 777a231..8155210 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnSecondaryUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnSecondaryUser.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -45,5 +46,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnSecondaryUserInDifferentProfileGroupToProfileOwnerProfile.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnSecondaryUserInDifferentProfileGroupToProfileOwnerProfile.java
index a243839..6b968c0 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnSecondaryUserInDifferentProfileGroupToProfileOwnerProfile.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnSecondaryUserInDifferentProfileGroupToProfileOwnerProfile.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.UserType;
@@ -49,5 +50,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnUnaffiliatedDeviceOwnerSecondaryUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnUnaffiliatedDeviceOwnerSecondaryUser.java
index bb96ce1..473ee8c 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnUnaffiliatedDeviceOwnerSecondaryUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnUnaffiliatedDeviceOwnerSecondaryUser.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -48,5 +49,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnUnaffiliatedProfileOwnerSecondaryUser.java b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnUnaffiliatedProfileOwnerSecondaryUser.java
index 6989195..0c5442f 100644
--- a/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnUnaffiliatedProfileOwnerSecondaryUser.java
+++ b/common/device-side/bedstead/harrier/common/src/main/java/com/android/bedstead/harrier/annotations/parameterized/IncludeRunOnUnaffiliatedProfileOwnerSecondaryUser.java
@@ -16,6 +16,7 @@
 
 package com.android.bedstead.harrier.annotations.parameterized;
 
+import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.EARLY;
 import static com.android.bedstead.harrier.annotations.AnnotationRunPrecedence.LATE;
 
 import com.android.bedstead.harrier.annotations.AnnotationRunPrecedence;
@@ -50,5 +51,5 @@
      *
      * <p>Weight can be set to a {@link AnnotationRunPrecedence} constant, or to any {@link int}.
      */
-    int weight() default LATE;
+    int weight() default EARLY;
 }
diff --git a/hostsidetests/packagemanager/installedloadingprogess/deviceside/src/com/android/tests/loadingprogress/device/LoadingProgressTest.java b/hostsidetests/packagemanager/installedloadingprogess/deviceside/src/com/android/tests/loadingprogress/device/LoadingProgressTest.java
index b8503ac..8e5aa9a 100644
--- a/hostsidetests/packagemanager/installedloadingprogess/deviceside/src/com/android/tests/loadingprogress/device/LoadingProgressTest.java
+++ b/hostsidetests/packagemanager/installedloadingprogess/deviceside/src/com/android/tests/loadingprogress/device/LoadingProgressTest.java
@@ -60,7 +60,7 @@
     private PackageManager mPackageManager;
     private UserHandle mUser;
     private LauncherApps mLauncherApps;
-    private static final int WAIT_TIMEOUT_MILLIS = 1000; /* 1 second */
+    private static final int WAIT_TIMEOUT_MILLIS = 2000; /* 2 second */
     private ConditionVariable mCalled  = new ConditionVariable();
     private final HandlerThread mCallbackThread = new HandlerThread("callback");
     private LauncherAppsCallback mCallback;
@@ -188,4 +188,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/hostsidetests/securitybulletin/res/cve_2019_2180_ipp.mp4 b/hostsidetests/securitybulletin/res/cve_2019_2180_ipp.mp4
new file mode 100644
index 0000000..09483b5
--- /dev/null
+++ b/hostsidetests/securitybulletin/res/cve_2019_2180_ipp.mp4
Binary files differ
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2180/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2180/Android.bp
new file mode 100644
index 0000000..5fc8e88
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2180/Android.bp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2022 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 {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_test {
+    name: "CVE-2019-2180",
+    defaults: [
+        "cts_hostsidetests_securitybulletin_defaults"
+    ],
+    srcs: [
+        "poc.c",
+    ],
+    shared_libs: [
+        "libcups",
+    ],
+}
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2019-2180/poc.c b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2180/poc.c
new file mode 100644
index 0000000..8abf500a
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2019-2180/poc.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdbool.h>
+#include <dlfcn.h>
+#include <fcntl.h>
+#include <ipp.h>
+#include "../includes/common.h"
+
+bool isInitialized = false;
+
+bool isVulnerable = false;
+
+bool isTestInProgress = false;
+
+const char *kExposedLanguageString = "en-us";
+
+static size_t (*realStrlen)(const char *str) = NULL;
+
+void init() {
+    realStrlen = (size_t(*)(const char *))dlsym(RTLD_NEXT, "strlen");
+    if (realStrlen == NULL) {
+        return;
+    }
+    isInitialized = true;
+}
+
+size_t strlen(const char *str) {
+    if (!isInitialized) {
+        init();
+    }
+    if (isTestInProgress && (strcmp(str, kExposedLanguageString) == 0)) {
+        isVulnerable = true;
+    }
+    return realStrlen(str);
+}
+
+int main(int argc, char **argv) {
+    FAIL_CHECK(argc > 1);
+    int fileDescriptor = open((const char *)argv[1], O_RDONLY);
+    FAIL_CHECK(fileDescriptor >= 0);
+    ipp_t *job = ippNew();
+    if (!job) {
+        close(fileDescriptor);
+        FAIL_CHECK(job != NULL);
+    }
+    isTestInProgress = true;
+    ippReadFile(fileDescriptor, job);
+    isTestInProgress = false;
+    free(job);
+    close(fileDescriptor);
+    return (isVulnerable) ? EXIT_VULNERABLE : EXIT_SUCCESS;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2180.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2180.java
new file mode 100644
index 0000000..31ab4ce
--- /dev/null
+++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2019_2180.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.security.cts;
+
+import android.platform.test.annotations.AsbSecurityTest;
+
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class CVE_2019_2180 extends SecurityTestCase {
+
+    /**
+     * b/110899492
+     * Vulnerability Behaviour: EXIT_VULNERABLE (113)
+     */
+    @AsbSecurityTest(cveBugId = 110899492)
+    @Test
+    public void testPocCVE_2019_2180() throws Exception {
+        String binaryName = "CVE-2019-2180";
+        String inputFiles[] = {"cve_2019_2180_ipp.mp4"};
+        String arguments = AdbUtils.TMP_PATH + inputFiles[0];
+        try {
+            AdbUtils.pushResources(inputFiles, AdbUtils.TMP_PATH, getDevice());
+            AdbUtils.runPocAssertExitStatusNotVulnerable(binaryName, arguments, null, getDevice(),
+                    AdbUtils.TIMEOUT_SEC);
+        } finally {
+            AdbUtils.removeResources(inputFiles, AdbUtils.TMP_PATH, getDevice());
+        }
+    }
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0928.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0928.java
index 1e6b91a..cbf1088 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0928.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_0928.java
@@ -23,7 +23,7 @@
 
 import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
-import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase;
 
 import org.junit.Assert;
 import org.junit.Before;
@@ -31,7 +31,7 @@
 import org.junit.runner.RunWith;
 
 @RunWith(DeviceJUnit4ClassRunner.class)
-public class CVE_2021_0928 extends BaseHostJUnit4Test {
+public class CVE_2021_0928 extends StsExtraBusinessLogicHostTestBase {
     private static final String TEST_PKG = "android.security.cts.CVE_2021_0928";
     private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest";
     private static final String TEST_APP = "CVE-2021-0928.apk";
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_39702.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_39702.java
index d92af4d..cf8a688 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_39702.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2021_39702.java
@@ -21,14 +21,14 @@
 
 import com.android.tradefed.device.ITestDevice;
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
-import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase;
 
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 @RunWith(DeviceJUnit4ClassRunner.class)
-public class CVE_2021_39702 extends BaseHostJUnit4Test {
+public class CVE_2021_39702 extends StsExtraBusinessLogicHostTestBase {
     private static final String TEST_PKG = "android.security.cts.CVE_2021_39702";
     private static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest";
     private static final String TEST_APP = "CVE-2021-39702.apk";
diff --git a/tests/appsearch/src/com/android/cts/appsearch/app/GlobalSearchSessionPlatformCtsTest.java b/tests/appsearch/src/com/android/cts/appsearch/app/GlobalSearchSessionPlatformCtsTest.java
index d558ae0..ffc4e7e 100644
--- a/tests/appsearch/src/com/android/cts/appsearch/app/GlobalSearchSessionPlatformCtsTest.java
+++ b/tests/appsearch/src/com/android/cts/appsearch/app/GlobalSearchSessionPlatformCtsTest.java
@@ -240,6 +240,40 @@
     }
 
     @Test
+    public void testRemoveVisibilitySetting_noRemainingSettings() throws Exception {
+        // Set schema and allow PKG_A to access.
+        mDb.setSchema(
+                new SetSchemaRequest.Builder()
+                        .addSchemas(AppSearchEmail.SCHEMA)
+                        .setSchemaTypeVisibilityForPackage(
+                                AppSearchEmail.SCHEMA_TYPE,
+                                /*visible=*/ true,
+                                new PackageIdentifier(PKG_A, PKG_A_CERT_SHA256))
+                        .build())
+                .get();
+        checkIsBatchResultSuccess(
+                mDb.put(
+                        new PutDocumentsRequest.Builder()
+                                .addGenericDocuments(EMAIL_DOCUMENT)
+                                .build()));
+
+        // PKG_A can access.
+        assertPackageCanAccess(EMAIL_DOCUMENT, PKG_A);
+        assertPackageCannotAccess(PKG_B);
+
+        // Remove the schema.
+        mDb.setSchema(new SetSchemaRequest.Builder().setForceOverride(true).build()).get();
+
+        // Add the schema back with default visibility setting.
+        mDb.setSchema(new SetSchemaRequest.Builder()
+                .addSchemas(AppSearchEmail.SCHEMA).build()).get();
+
+        // No pcakage can access.
+        assertPackageCannotAccess(PKG_A);
+        assertPackageCannotAccess(PKG_B);
+    }
+
+    @Test
     public void testAllowMultiplePackageAccess() throws Exception {
         mDb.setSchema(
                         new SetSchemaRequest.Builder()
diff --git a/tests/framework/base/windowmanager/AndroidManifest.xml b/tests/framework/base/windowmanager/AndroidManifest.xml
index 3277fb3..8e6f014 100644
--- a/tests/framework/base/windowmanager/AndroidManifest.xml
+++ b/tests/framework/base/windowmanager/AndroidManifest.xml
@@ -431,7 +431,9 @@
         <activity android:name="android.server.wm.ForceRelayoutTestBase$TestActivity"
              android:exported="true"/>
 
-        <activity android:name="android.server.wm.ActivityTransitionTests$LauncherActivity"/>
+        <activity android:name="android.server.wm.ActivityTransitionTests$LauncherActivity"
+            android:theme="@style/Theme.TranslucentBars"
+            android:fitsSystemWindows="true" />
 
         <activity android:name="android.server.wm.ActivityTransitionTests$TransitionActivity"/>
 
@@ -442,6 +444,12 @@
             android:exported="true"
             android:colorMode="wideColorGamut"/>
 
+        <activity android:name="android.server.wm.ActivityTransitionTests$EdgeExtensionActivity"
+            android:theme="@style/Theme.EdgeExtensions"
+            android:exported="true"
+            android:colorMode="wideColorGamut"
+            android:fitsSystemWindows="true" />
+
         <activity android:name="android.server.wm.WindowUntrustedTouchTest$TestActivity"
                   android:exported="true"
                   android:configChanges="screenSize|screenLayout|orientation"
diff --git a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingBoundsTests.java b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingBoundsTests.java
index 0377c7a..46d3fa8 100644
--- a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingBoundsTests.java
+++ b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingBoundsTests.java
@@ -27,6 +27,8 @@
 
 import android.app.Activity;
 import android.content.Intent;
+import android.platform.test.annotations.FlakyTest;
+import android.platform.test.annotations.Presubmit;
 import android.server.wm.jetpack.utils.TestActivity;
 import android.server.wm.jetpack.utils.TestActivityWithId;
 import android.server.wm.jetpack.utils.TestConfigChangeHandlingActivity;
@@ -52,6 +54,7 @@
  * Build/Install/Run:
  *     atest CtsWindowManagerJetpackTestCases:ActivityEmbeddingBoundsTests
  */
+@Presubmit
 @RunWith(AndroidJUnit4.class)
 public class ActivityEmbeddingBoundsTests extends ActivityEmbeddingTestBase {
 
@@ -160,6 +163,7 @@
      * {@link SplitPairRule}, and is not assumed to be 0.5 or match the split ratio of the previous
      * top-most activity split.
      */
+    @FlakyTest(bugId = 213322133)
     @Test
     public void testSplitRatio() {
         final String activityAId = "activityA";
diff --git a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingCrossUidTests.java b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingCrossUidTests.java
index 834eae3..0092ed2 100644
--- a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingCrossUidTests.java
+++ b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingCrossUidTests.java
@@ -34,6 +34,7 @@
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.os.Bundle;
+import android.platform.test.annotations.Presubmit;
 import android.server.wm.NestedShellPermission;
 import android.server.wm.jetpack.utils.TestActivityWithId;
 import android.server.wm.jetpack.utils.TestConfigChangeHandlingActivity;
@@ -57,6 +58,7 @@
  * Build/Install/Run:
  *     atest CtsWindowManagerJetpackTestCases:ActivityEmbeddingCrossUidTests
  */
+@Presubmit
 @RunWith(AndroidJUnit4.class)
 public class ActivityEmbeddingCrossUidTests extends ActivityEmbeddingTestBase {
 
diff --git a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingFinishTests.java b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingFinishTests.java
index c1fa777..f4fa70c 100644
--- a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingFinishTests.java
+++ b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingFinishTests.java
@@ -33,6 +33,7 @@
 import static org.junit.Assert.assertTrue;
 
 import android.app.Activity;
+import android.platform.test.annotations.Presubmit;
 import android.server.wm.jetpack.utils.TestActivity;
 import android.server.wm.jetpack.utils.TestActivityWithId;
 import android.server.wm.jetpack.utils.TestConfigChangeHandlingActivity;
@@ -58,7 +59,7 @@
  * Build/Install/Run:
  *     atest CtsWindowManagerJetpackTestCases:ActivityEmbeddingFinishTests
  */
-
+@Presubmit
 @RunWith(AndroidJUnit4.class)
 public class ActivityEmbeddingFinishTests extends ActivityEmbeddingTestBase {
 
diff --git a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingLaunchTests.java b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingLaunchTests.java
index 38c34f1..fc462c5 100644
--- a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingLaunchTests.java
+++ b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingLaunchTests.java
@@ -29,6 +29,8 @@
 
 import android.app.Activity;
 import android.content.Intent;
+import android.platform.test.annotations.FlakyTest;
+import android.platform.test.annotations.Presubmit;
 import android.server.wm.jetpack.utils.TestActivityWithId;
 import android.server.wm.jetpack.utils.TestConfigChangeHandlingActivity;
 import android.util.Pair;
@@ -59,6 +61,7 @@
  * Build/Install/Run:
  *     atest CtsWindowManagerJetpackTestCases:ActivityEmbeddingLaunchTests
  */
+@Presubmit
 @RunWith(AndroidJUnit4.class)
 public class ActivityEmbeddingLaunchTests extends ActivityEmbeddingTestBase {
 
@@ -270,6 +273,7 @@
      * Tests launching an activity that is set to always expand when it is launched over an existing
      * split from the current secondary activity.
      */
+    @FlakyTest(bugId = 213322133)
     @Test
     public void testAlwaysExpandOverSplit_launchFromSecondary() {
         // Create activity rule that sets the target activity to always expand
diff --git a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingPlaceholderTests.java b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingPlaceholderTests.java
index 814956e..e7235a2 100644
--- a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingPlaceholderTests.java
+++ b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingPlaceholderTests.java
@@ -29,6 +29,7 @@
 
 import android.app.Activity;
 import android.content.Intent;
+import android.platform.test.annotations.Presubmit;
 import android.server.wm.jetpack.utils.TestActivity;
 import android.server.wm.jetpack.utils.TestActivityWithId;
 import android.util.Pair;
@@ -58,6 +59,7 @@
  * Build/Install/Run:
  *     atest CtsWindowManagerJetpackTestCases:ActivityEmbeddingPlaceholderTests
  */
+@Presubmit
 @RunWith(AndroidJUnit4.class)
 public class ActivityEmbeddingPlaceholderTests extends ActivityEmbeddingTestBase {
 
@@ -140,7 +142,7 @@
      * activity it launched with is not finished.
      */
     @Test
-    @Ignore
+    @Ignore("b/222188067")
     public void testPlaceholderFinishPrimaryWithSecondary_FinishNever() {
         // Set embedding rules with finishPrimaryWithSecondary set to FINISH_NEVER
         final SplitPlaceholderRule splitPlaceholderRule =
diff --git a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingTestBase.java b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingTestBase.java
index 9867569..009b404 100644
--- a/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingTestBase.java
+++ b/tests/framework/base/windowmanager/jetpack/src/android/server/wm/jetpack/ActivityEmbeddingTestBase.java
@@ -19,8 +19,10 @@
 import static android.server.wm.jetpack.utils.ExtensionUtil.assumeExtensionSupportedDevice;
 import static android.server.wm.jetpack.utils.ExtensionUtil.getWindowExtensions;
 
+import static org.junit.Assume.assumeFalse;
 import static org.junit.Assume.assumeNotNull;
 
+import android.os.SystemProperties;
 import android.server.wm.ActivityManagerTestBase.ReportedDisplayMetrics;
 import android.server.wm.jetpack.utils.TestValueCountConsumer;
 import android.server.wm.jetpack.utils.WindowManagerJetpackTestBase;
@@ -45,11 +47,15 @@
     protected TestValueCountConsumer<List<SplitInfo>> mSplitInfoConsumer;
     protected ReportedDisplayMetrics mReportedDisplayMetrics =
             ReportedDisplayMetrics.getDisplayMetrics(Display.DEFAULT_DISPLAY);
+    private static final boolean ENABLE_SHELL_TRANSITIONS =
+            SystemProperties.getBoolean("persist.wm.debug.shell_transit", false);
 
     @Override
     @Before
     public void setUp() {
         super.setUp();
+        // TODO(b/207070762): remove the assumption after shell transition enabled.
+        assumeFalse(ENABLE_SHELL_TRANSITIONS);
         assumeExtensionSupportedDevice();
         WindowExtensions windowExtensions = getWindowExtensions();
         assumeNotNull(windowExtensions);
diff --git a/tests/framework/base/windowmanager/overlayappbase/res/anim/alpha_0.xml b/tests/framework/base/windowmanager/overlayappbase/res/anim/alpha_0.xml
new file mode 100644
index 0000000..40a1581
--- /dev/null
+++ b/tests/framework/base/windowmanager/overlayappbase/res/anim/alpha_0.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright (C) 2020 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.
+  -->
+<alpha
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:fromAlpha="0"
+    android:toAlpha="0"
+    android:duration="@integer/animation_duration"
+    />
diff --git a/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_bottom.xml b/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_bottom.xml
new file mode 100644
index 0000000..48f004d
--- /dev/null
+++ b/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_bottom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2022 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shareInterpolator="false">
+
+    <alpha
+        android:fromAlpha="1.0"
+        android:toAlpha="1.0"
+        android:fillEnabled="true"
+        android:fillBefore="true"
+        android:fillAfter="true"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+    <scale
+        android:fromXScale="1.0"
+        android:toXScale="1.0"
+        android:fromYScale="0.5"
+        android:toYScale="0.5"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+    <extend
+        android:fromExtendLeft="0"
+        android:fromExtendTop="0"
+        android:fromExtendRight="0"
+        android:fromExtendBottom="100%"
+        android:toExtendLeft="0"
+        android:toExtendTop="0"
+        android:toExtendRight="0"
+        android:toExtendBottom="100%"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+</set>
diff --git a/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_left.xml b/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_left.xml
new file mode 100644
index 0000000..6be9f1b
--- /dev/null
+++ b/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_left.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2022 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shareInterpolator="false">
+
+    <alpha
+        android:fromAlpha="1.0"
+        android:toAlpha="1.0"
+        android:fillEnabled="true"
+        android:fillBefore="true"
+        android:fillAfter="true"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+    <scale
+        android:fromXScale="0.5"
+        android:toXScale="0.5"
+        android:fromYScale="1.0"
+        android:toYScale="1.0"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+    <translate
+        android:fromXDelta="50%"
+        android:toXDelta="50%"
+        android:interpolator="@android:interpolator/linear"
+        android:duration="5000" />
+
+    <extend
+        android:fromExtendLeft="100%"
+        android:fromExtendTop="0"
+        android:fromExtendRight="0"
+        android:fromExtendBottom="0"
+        android:toExtendLeft="100%"
+        android:toExtendTop="0"
+        android:toExtendRight="0"
+        android:toExtendBottom="0"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+</set>
diff --git a/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_right.xml b/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_right.xml
new file mode 100644
index 0000000..c589f0e
--- /dev/null
+++ b/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_right.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2022 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shareInterpolator="false">
+
+    <alpha
+        android:fromAlpha="1.0"
+        android:toAlpha="1.0"
+        android:fillEnabled="true"
+        android:fillBefore="true"
+        android:fillAfter="true"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+    <scale
+        android:fromXScale="0.5"
+        android:toXScale="0.5"
+        android:fromYScale="1.0"
+        android:toYScale="1.0"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+    <extend
+        android:fromExtendLeft="0"
+        android:fromExtendTop="0"
+        android:fromExtendRight="100%"
+        android:fromExtendBottom="0"
+        android:toExtendLeft="0"
+        android:toExtendTop="0"
+        android:toExtendRight="100%"
+        android:toExtendBottom="0"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+</set>
diff --git a/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_top.xml b/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_top.xml
new file mode 100644
index 0000000..0b421a4
--- /dev/null
+++ b/tests/framework/base/windowmanager/overlayappbase/res/anim/edge_extension_top.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2022 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shareInterpolator="false">
+
+    <alpha
+        android:fromAlpha="1.0"
+        android:toAlpha="1.0"
+        android:fillEnabled="true"
+        android:fillBefore="true"
+        android:fillAfter="true"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+    <scale
+        android:fromXScale="1.0"
+        android:toXScale="1.0"
+        android:fromYScale="0.5"
+        android:toYScale="0.5"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+    <translate
+        android:fromYDelta="50%"
+        android:toYDelta="50%"
+        android:interpolator="@android:interpolator/linear"
+        android:duration="5000" />
+
+    <extend
+        android:fromExtendLeft="0"
+        android:fromExtendTop="100%"
+        android:fromExtendRight="0"
+        android:fromExtendBottom="0"
+        android:toExtendLeft="0"
+        android:toExtendTop="100%"
+        android:toExtendRight="0"
+        android:toExtendBottom="0"
+        android:interpolator="@android:interpolator/linear"
+        android:startOffset="0"
+        android:duration="5000" />
+
+</set>
diff --git a/tests/framework/base/windowmanager/res/layout/vertical_color_split.xml b/tests/framework/base/windowmanager/res/layout/vertical_color_split.xml
new file mode 100644
index 0000000..d24ee56
--- /dev/null
+++ b/tests/framework/base/windowmanager/res/layout/vertical_color_split.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2022 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.
+  -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal">
+
+    <View
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:background="#0000FF" />
+
+    <View
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:background="#FF0000" />
+</LinearLayout>
diff --git a/tests/framework/base/windowmanager/res/values/styles.xml b/tests/framework/base/windowmanager/res/values/styles.xml
index 5910fc2..9d6e9dc 100644
--- a/tests/framework/base/windowmanager/res/values/styles.xml
+++ b/tests/framework/base/windowmanager/res/values/styles.xml
@@ -46,4 +46,12 @@
         <item name="android:windowBackground">#ffffff</item>
         <item name="android:colorBackground">#ffffff</item>
     </style>
+    <style name="Theme.EdgeExtensions" parent="Theme.WhiteBackground">
+        <item name="android:statusBarColor">@android:color/transparent</item>
+        <item name="android:navigationBarColor">@android:color/transparent</item>
+    </style>
+    <style name="Theme.TranslucentBars" parent="@android:style/Theme.Material.NoActionBar">
+        <item name="android:statusBarColor">@android:color/transparent</item>
+        <item name="android:navigationBarColor">@android:color/transparent</item>
+    </style>
 </resources>
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/ActivityTransitionTests.java b/tests/framework/base/windowmanager/src/android/server/wm/ActivityTransitionTests.java
index 083e72c..f7e56fd 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/ActivityTransitionTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/ActivityTransitionTests.java
@@ -17,6 +17,11 @@
 package android.server.wm;
 
 import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
+import static android.server.wm.ActivityTransitionTests.EdgeExtensionActivity.BOTTOM;
+import static android.server.wm.ActivityTransitionTests.EdgeExtensionActivity.DIRECTION_KEY;
+import static android.server.wm.ActivityTransitionTests.EdgeExtensionActivity.LEFT;
+import static android.server.wm.ActivityTransitionTests.EdgeExtensionActivity.RIGHT;
+import static android.server.wm.ActivityTransitionTests.EdgeExtensionActivity.TOP;
 import static android.server.wm.ActivityTransitionTests.OverridePendingTransitionActivity.BACKGROUND_COLOR_KEY;
 import static android.server.wm.ActivityTransitionTests.OverridePendingTransitionActivity.ENTER_ANIM_KEY;
 import static android.server.wm.ActivityTransitionTests.OverridePendingTransitionActivity.EXIT_ANIM_KEY;
@@ -26,6 +31,7 @@
 import static com.android.compatibility.common.util.SystemUtil.runShellCommand;
 
 import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -47,8 +53,10 @@
 import android.platform.test.annotations.Presubmit;
 import android.server.wm.cts.R;
 import android.util.Range;
+import android.view.WindowInsets;
 import android.view.WindowManager;
 
+import androidx.annotation.Nullable;
 import androidx.test.platform.app.InstrumentationRegistry;
 
 import com.android.compatibility.common.util.SystemUtil;
@@ -82,6 +90,9 @@
     private String mInitialTransitionAnimationScale;
     private String mInitialAnimatorDurationScale;
 
+    // We need to allow for some variation stemming from color conversions
+    private static final float COLOR_VALUE_VARIANCE_TOLERANCE = 0.03f;
+
     @Before
     public void setUp() throws Exception {
         super.setUp();
@@ -256,6 +267,106 @@
         assertAppRegionOfScreenIsColor(screenshot, backgroundColor);
     }
 
+    /**
+     * Checks that when an activity transition with a left edge extension is run that the animating
+     * activity is extended on the left side by clamping the edge pixels of the activity.
+     *
+     * The test runs an activity transition where the animating activities are X scaled to 50%,
+     * positioned of the right side of the screen, and edge extended on the left. Because the
+     * animating activities are half red half blue (split at the middle of the X axis of the
+     * activity). We expect first 75% pixel columns of the screen to be red (50% from the edge
+     * extension and the next 25% from from the activity) and the remaining 25% columns after that
+     * to be blue (from the activity).
+     *
+     * @see R.anim.edge_extension_left for the transition applied.
+     */
+    @Test
+    public void testLeftEdgeExtensionWorksDuringActivityTransition() {
+        final Bundle extras = new Bundle();
+        extras.putInt(DIRECTION_KEY, LEFT);
+
+        final Bitmap screenshot = runAndScreenshotActivityTransition(
+                EdgeExtensionActivity.class, extras);
+        final Rect fullyVisibleBounds = getActivityFullyVisibleRegion();
+        assertColorChangeXIndex(screenshot,
+                (fullyVisibleBounds.left + fullyVisibleBounds.right) / 4 * 3);
+    }
+
+    /**
+     * Checks that when an activity transition with a top edge extension is run that the animating
+     * activity is extended on the left side by clamping the edge pixels of the activity.
+     *
+     * The test runs an activity transition where the animating activities are Y scaled to 50%,
+     * positioned of the bottom of the screen, and edge extended on the top. Because the
+     * animating activities are half red half blue (split at the middle of the X axis of the
+     * activity). We expect first 50% pixel columns of the screen to be red (the top half from the
+     * extension and the bottom half from the activity) and the remaining 50% columns after that
+     * to be blue (the top half from the extension and the bottom half from the activity).
+     *
+     * @see R.anim.edge_extension_top for the transition applied.
+     */
+    @Test
+    public void testTopEdgeExtensionWorksDuringActivityTransition() {
+        final Bundle extras = new Bundle();
+        extras.putInt(DIRECTION_KEY, TOP);
+
+        final Bitmap screenshot = runAndScreenshotActivityTransition(
+                EdgeExtensionActivity.class, extras);
+        final Rect fullyVisibleBounds = getActivityFullyVisibleRegion();
+        assertColorChangeXIndex(screenshot,
+                (fullyVisibleBounds.left + fullyVisibleBounds.right) / 2);
+    }
+
+    /**
+     * Checks that when an activity transition with a right edge extension is run that the animating
+     * activity is extended on the right side by clamping the edge pixels of the activity.
+     *
+     * The test runs an activity transition where the animating activities are X scaled to 50% and
+     * edge extended on the right. Because the animating activities are half red half blue. We
+     * expect first 25% pixel columns of the screen to be red (from the activity) and the remaining
+     * 75% columns after that to be blue (25% from the activity and 50% from the edge extension
+     * which should be extending the right edge pixel (so red pixels).
+     *
+     * @see R.anim.edge_extension_right for the transition applied.
+     */
+    @Test
+    public void testRightEdgeExtensionWorksDuringActivityTransition() {
+        final Bundle extras = new Bundle();
+        extras.putInt(DIRECTION_KEY, RIGHT);
+
+        final Bitmap screenshot = runAndScreenshotActivityTransition(
+                EdgeExtensionActivity.class, extras);
+        final Rect fullyVisibleBounds = getActivityFullyVisibleRegion();
+        assertColorChangeXIndex(screenshot,
+                (fullyVisibleBounds.left + fullyVisibleBounds.right) / 4);
+    }
+
+    /**
+     * Checks that when an activity transition with a bottom edge extension is run that the
+     * animating activity is extended on the bottom side by clamping the edge pixels of the
+     * activity.
+     *
+     * The test runs an activity transition where the animating activities are Y scaled to 50%,
+     * positioned of the top of the screen, and edge extended on the bottom. Because the
+     * animating activities are half red half blue (split at the middle of the X axis of the
+     * activity). We expect first 50% pixel columns of the screen to be red (the top half from the
+     * activity and the bottom half from gthe extensions) and the remaining 50% columns after that
+     * to be blue (the top half from the activity and the bottom half from the extension).
+     *
+     * @see R.anim.edge_extension_bottom for the transition applied.
+     */
+    @Test
+    public void testBottomEdgeExtensionWorksDuringActivityTransition() {
+        final Bundle extras = new Bundle();
+        extras.putInt(DIRECTION_KEY, BOTTOM);
+
+        final Bitmap screenshot = runAndScreenshotActivityTransition(
+                EdgeExtensionActivity.class, extras);
+        final Rect fullyVisibleBounds = getActivityFullyVisibleRegion();
+        assertColorChangeXIndex(screenshot,
+                (fullyVisibleBounds.left + fullyVisibleBounds.right) / 2);
+    }
+
     private Bitmap runAndScreenshotActivityTransition(Class<?> klass) {
         return runAndScreenshotActivityTransition(klass, Bundle.EMPTY);
     }
@@ -307,7 +418,7 @@
                         new float[] {
                                 expectedColor.red(), expectedColor.green(), expectedColor.blue() },
                         new float[] { sRgbColor.red(), sRgbColor.green(), sRgbColor.blue() },
-                        0.03f); // need to allow for some variation stemming from conversions
+                        COLOR_VALUE_VARIANCE_TOLERANCE);
             }
         }
     }
@@ -342,6 +453,77 @@
                 displayBounds.right, displayBounds.bottom - bottomHeightToIgnore);
     }
 
+    private void assertColorChangeXIndex(Bitmap screen, int xIndex) {
+        final int colorChangeXIndex = getColorChangeXIndex(screen);
+        final Rect fullyVisibleBounds = getActivityFullyVisibleRegion();
+        // Check to make sure the activity was scaled for an extension to be visible on screen
+        assertEquals(xIndex, colorChangeXIndex);
+
+        // The activity we are extending is a half red, half blue.
+        // We are scaling the activity in the animation so if the extension doesn't work we should
+        // have a blue, then red, then black section, and if it does work we should see on a blue,
+        // followed by an extended red section.
+        for (int x = 0; x < screen.getWidth(); x++) {
+            for (int y = fullyVisibleBounds.top;
+                    y < fullyVisibleBounds.bottom; y++) {
+                final Color expectedColor;
+                if (x < xIndex) {
+                    expectedColor = Color.valueOf(Color.BLUE);
+                } else {
+                    expectedColor = Color.valueOf(Color.RED);
+                }
+
+                final Color rawColor = screen.getColor(x, y);
+                final Color sRgbColor;
+                if (!rawColor.getColorSpace().equals(ColorSpace.get(ColorSpace.Named.SRGB))) {
+                    // Conversion is required because the color space of the screenshot may be in
+                    // the DCI-P3 color space or some other color space and we want to compare the
+                    // color against once in the SRGB color space, so we must convert the color back
+                    // to the SRGB color space.
+                    sRgbColor = screen.getColor(x, y)
+                            .convert(ColorSpace.get(ColorSpace.Named.SRGB));
+                } else {
+                    sRgbColor = rawColor;
+                }
+
+                assertArrayEquals("Screen pixel (" + x + ", " + y + ") is not the right color",
+                        new float[] {
+                                expectedColor.red(), expectedColor.green(), expectedColor.blue() },
+                        new float[] { sRgbColor.red(), sRgbColor.green(), sRgbColor.blue() },
+                        0.03f); // need to allow for some variation stemming from conversions
+            }
+        }
+    }
+
+    private int getColorChangeXIndex(Bitmap screen) {
+        // Look for color changing index at middle of app
+        final int y =
+                (getActivityFullyVisibleRegion().top + getActivityFullyVisibleRegion().bottom) / 2;
+
+        Color prevColor = screen.getColor(0, y)
+                .convert(ColorSpace.get(ColorSpace.Named.SRGB));
+        for (int x = 0; x < screen.getWidth(); x++) {
+            final Color c = screen.getColor(x, y)
+                    .convert(ColorSpace.get(ColorSpace.Named.SRGB));
+
+            if (!colorsEqual(prevColor, c)) {
+                return x;
+            }
+        }
+
+        throw new RuntimeException("Failed to find color change index");
+    }
+
+    private boolean colorsEqual(Color c1, Color c2) {
+        return almostEquals(c1.red(), c2.red(), COLOR_VALUE_VARIANCE_TOLERANCE)
+                && almostEquals(c1.green(), c2.green(), COLOR_VALUE_VARIANCE_TOLERANCE)
+                && almostEquals(c1.blue(), c2.blue(), COLOR_VALUE_VARIANCE_TOLERANCE);
+    }
+
+    private boolean almostEquals(float a, float b, float delta) {
+        return Math.abs(a - b) < delta;
+    }
+
     private void setDefaultAnimationScale() {
         mInitialWindowAnimationScale =
                 runShellCommandSafe("settings get global window_animation_scale");
@@ -382,6 +564,15 @@
 
     public static class LauncherActivity extends Activity {
 
+        @Override
+        protected void onCreate(@Nullable Bundle savedInstanceState) {
+            super.onCreate(savedInstanceState);
+
+            // Ensure the activity is edge-to-edge
+            // In tests we rely on the activity's content filling the entire window
+            getWindow().setDecorFitsSystemWindows(false);
+        }
+
         public void startTransitionActivity(ActivityOptions activityOptions) {
             startTransitionActivity(activityOptions, TransitionActivity.class);
         }
@@ -418,4 +609,50 @@
     }
 
     public static class TransitionActivityWithWhiteBackground extends Activity { }
+
+    public static class EdgeExtensionActivity extends Activity {
+        static final String DIRECTION_KEY = "direction";
+        static final int LEFT = 0;
+        static final int TOP = 1;
+        static final int RIGHT = 2;
+        static final int BOTTOM = 3;
+
+        @Override
+        protected void onCreate(@Nullable Bundle savedInstanceState) {
+            super.onCreate(savedInstanceState);
+            setContentView(R.layout.vertical_color_split);
+
+            // Ensure the activity is edge-to-edge
+            // In tests we rely on the activity's content filling the entire window
+            getWindow().setDecorFitsSystemWindows(false);
+
+            // Hide anything that the decor view might add to the window to avoid extending that
+            getWindow().getInsetsController()
+                    .hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
+        }
+
+        @Override
+        protected void onResume() {
+            super.onResume();
+
+            Bundle extras = getIntent().getExtras();
+            int direction = extras.getInt(DIRECTION_KEY);
+            int enterAnim = 0;
+            switch (direction) {
+                case LEFT:
+                    enterAnim = R.anim.edge_extension_left;
+                    break;
+                case TOP:
+                    enterAnim = R.anim.edge_extension_top;
+                    break;
+                case RIGHT:
+                    enterAnim = R.anim.edge_extension_right;
+                    break;
+                case BOTTOM:
+                    enterAnim = R.anim.edge_extension_bottom;
+                    break;
+            }
+            overridePendingTransition(enterAnim, R.anim.alpha_0);
+        }
+    }
 }
diff --git a/tests/location/location_privileged/src/android/location/cts/privileged/GnssMeasurementCorrectionsInjectionTest.java b/tests/location/location_privileged/src/android/location/cts/privileged/GnssMeasurementCorrectionsInjectionTest.java
index 21f3d2b..41e092a 100644
--- a/tests/location/location_privileged/src/android/location/cts/privileged/GnssMeasurementCorrectionsInjectionTest.java
+++ b/tests/location/location_privileged/src/android/location/cts/privileged/GnssMeasurementCorrectionsInjectionTest.java
@@ -16,6 +16,8 @@
 
 package android.location.cts.privileged;
 
+import static org.junit.Assume.assumeTrue;
+
 import android.Manifest;
 import android.content.Context;
 import android.location.GnssMeasurementCorrections;
@@ -41,8 +43,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import static org.junit.Assume.assumeTrue;
-
 /**
  * Tests for {@link GnssMeasurementCorrections} injection.
  *
@@ -66,6 +66,9 @@
                 .getUiAutomation()
                 .adoptShellPermissionIdentity(Manifest.permission.LOCATION_HARDWARE);
         assumeTrue(TestMeasurementUtil.canTestRunOnCurrentDevice(mTestLocationManager, TAG));
+        assumeTrue(
+                mTestLocationManager.getLocationManager().getGnssCapabilities()
+                        .hasMeasurementCorrections());
     }
 
     @After
diff --git a/tests/media/src/android/mediav2/cts/CodecTestBase.java b/tests/media/src/android/mediav2/cts/CodecTestBase.java
index ff2e7b4..6ec5f47 100644
--- a/tests/media/src/android/mediav2/cts/CodecTestBase.java
+++ b/tests/media/src/android/mediav2/cts/CodecTestBase.java
@@ -874,6 +874,16 @@
         return isDefault;
     }
 
+    static boolean isVendorCodec(String codecName) {
+        MediaCodecList mcl = new MediaCodecList(MediaCodecList.ALL_CODECS);
+        for (MediaCodecInfo codecInfo : mcl.getCodecInfos()) {
+            if (codecName.equals(codecInfo.getName())) {
+                return codecInfo.isVendor();
+            }
+        }
+        return false;
+    }
+
     static ArrayList<String> compileRequiredMimeList(boolean isEncoder, boolean needAudio,
             boolean needVideo) {
         Set<String> list = new HashSet<>();
diff --git a/tests/media/src/android/mediav2/cts/DecodeGlAccuracyTest.java b/tests/media/src/android/mediav2/cts/DecodeGlAccuracyTest.java
new file mode 100644
index 0000000..c6e0ae6
--- /dev/null
+++ b/tests/media/src/android/mediav2/cts/DecodeGlAccuracyTest.java
@@ -0,0 +1,359 @@
+/*
+ * Copyright (C) 2022 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.mediav2.cts;
+
+import static android.media.MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface;
+
+import static org.junit.Assert.assertTrue;
+
+import android.media.MediaCodec;
+import android.media.MediaFormat;
+import android.opengl.GLES20;
+import android.util.Log;
+
+import androidx.test.filters.LargeTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import javax.microedition.khronos.opengles.GL10;
+
+/**
+ * Validates the correctness of color conversion in the decode followed by OpenGL
+ * rendering scenarios. The input video files fed to the decoders contain the pixel
+ * data in compressed YUV format. The output of the decoders is shared with OpenGL
+ * as external textures. And OpenGL outputs RGB pixels. The class validates whether
+ * the conversion of input YUV to output RGB is in accordance with the chosen color
+ * aspects.
+ */
+@RunWith(Parameterized.class)
+public class DecodeGlAccuracyTest extends CodecDecoderTestBase {
+    private final String LOG_TAG = DecodeGlAccuracyTest.class.getSimpleName();
+
+    // Allowed color tolerance to account for differences in the conversion process
+    private final int ALLOWED_COLOR_DELTA = 8;
+
+    // The test video assets were generated with a set of color bars.
+    // Depending on the color aspects, the values from OpenGL pbuffer
+    // should not differ from the reference color values for the
+    // given color aspects below by more than the allowed tolerance.
+    //
+    // The reference RGB values were computed using the process described below.
+    //
+    // RGB = Transpose(FLOOR_CLIP_PIXEL(CONV_CSC * (Transpose(YUV) - LVL_OFFSET)))
+    // The matrices LVL_OFFSET and CONV_CSC for different color aspects are below.
+    //
+    // YUV values in the 8bit color bar test videos
+    //     {{126, 191, 230},
+    //      {98, 104, 204},
+    //      {180, 20, 168},
+    //      {121, 109, 60},
+    //      {114, 179, 172},
+    //      {133, 138, 118},
+    //      {183, 93, 153},
+    //      {203, 20, 33},
+    //      {147, 131, 183},
+    //      {40, 177, 202},
+    //      {170, 82, 96},
+    //
+    // The color conversion matrices (CONV_CSC) for the RGB equation above:
+    // MULTIPLY_ROW_WISE_LR = Transpose({255/219, 255/224, 255/224})
+    // CONV_FLOAT_601_FR =
+    //     {{1, 0, 1.402},
+    //      {1, -0.344136, -0.714136},
+    //      {1, 1.772, 0},}
+    // CONV_FLOAT_709_FR =
+    //     {{1, 0, 1.5748},
+    //      {1, -0.1873, -0.4681},
+    //      {1, 1.8556, 0},}
+    // CONV_FLOAT_601_LR = MULTIPLY_ROW_WISE_LR . CONV_FLOAT_601_FR
+    // CONV_FLOAT_709_LR = MULTIPLY_ROW_WISE_LR . CONV_FLOAT_709_FR
+    //
+    // The level shift matrices (LVL_OFFSET) for the RGB equation above:
+    // LVL_OFFSET_LR = Transpose({16, 128, 128})
+    // LVL_OFFSET_FR = Transpose({0, 128, 128})
+
+    // Reference RGB values for 601 Limited Range
+    private final int[][] mColorBars601LR = new int[][]{
+            {255, 17, 252},
+            {219, 40, 44},
+            {255, 196, 0},
+            {11, 182, 81},
+            {185, 55, 214},
+            {119, 137, 153},
+            {235, 183, 119},
+            {62, 255, 0},
+            {242, 103, 155},
+            {148, 0, 126},
+            {127, 219, 82},
+    };
+    // Reference RGB values for 601 Full Range
+    private final int[][] mColorBars601FR = new int[][]{
+            {255, 31, 237},
+            {204, 51, 55},
+            {236, 188, 0},
+            {25, 176, 87},
+            {175, 65, 204},
+            {118, 136, 150},
+            {218, 177, 120},
+            {69, 255, 11},
+            {224, 106, 152},
+            {143, 0, 126},
+            {125, 208, 88},
+    };
+    // Reference RGB values for 709 Limited Range
+    private final int[][] mColorBars709LR = new int[][]{
+            {255, 57, 255},
+            {234, 57, 42},
+            {255, 188, 0},
+            {0, 159, 79},
+            {194, 77, 219},
+            {117, 136, 154},
+            {240, 184, 116},
+            {43, 255, 0},
+            {253, 119, 155},
+            {163, 0, 130},
+            {120, 202, 78},
+    };
+
+    private int[][] mColorBars;
+
+    private final String mCompName;
+    private final String mFileName;
+    private int mWidth;
+    private int mHeight;
+    private final int mRange;
+    private final int mStandard;
+    private final int mTransferCurve;
+
+    private OutputSurface mEGLWindowOutSurface;
+
+    // The test videos were generated with the above color bars. Each bar is of
+    // width 16.
+    private final int mColorBarWidth = 16;
+    private final int xOffset = 8;
+    private final int yOffset = 64;
+    private int mBadFrames = 0;
+
+    public DecodeGlAccuracyTest(String decoder, String mediaType, String fileName, int range,
+            int standard, int transfer) {
+        super(null, mediaType, null);
+        mCompName = decoder;
+        mFileName = fileName;
+        mRange = range;
+        mStandard = standard;
+        mTransferCurve = transfer;
+
+        mColorBars = mColorBars601LR;
+        if ((mStandard == MediaFormat.COLOR_STANDARD_BT601_NTSC) &&
+                (mRange == MediaFormat.COLOR_RANGE_LIMITED)) {
+            mColorBars = mColorBars601LR;
+        } else if ((mStandard == MediaFormat.COLOR_STANDARD_BT601_NTSC) &&
+                (mRange == MediaFormat.COLOR_RANGE_FULL)) {
+            mColorBars = mColorBars601FR;
+        } else if ((mStandard == MediaFormat.COLOR_STANDARD_BT709) &&
+                (mRange == MediaFormat.COLOR_RANGE_LIMITED)) {
+            mColorBars = mColorBars709LR;
+        } else {
+            Log.e(LOG_TAG, "Unsupported Color Aspects.");
+        }
+    }
+
+    @Parameterized.Parameters(name = "{index}({0}_{1}_{3}_{4}_{5})")
+    public static Collection<Object[]> input() {
+        final boolean isEncoder = false;
+        final boolean needAudio = false;
+        final boolean needVideo = true;
+        final List<Object[]> argsList = Arrays.asList(new Object[][]{
+                // mediaType, asset, range, standard, transfer
+                // 601LR
+                {MediaFormat.MIMETYPE_VIDEO_AVC, "color_bands_176x176_h264_8bit.mp4",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_HEVC, "color_bands_176x176_hevc_8bit.mp4",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_VP8, "color_bands_176x176_vp8_8bit.webm",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_VP9, "color_bands_176x176_vp9_8bit.webm",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_AV1, "color_bands_176x176_av1_8bit.webm",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+
+                // 601FR
+                {MediaFormat.MIMETYPE_VIDEO_AVC, "color_bands_176x176_h264_8bit.mp4",
+                        MediaFormat.COLOR_RANGE_FULL,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_HEVC, "color_bands_176x176_hevc_8bit.mp4",
+                        MediaFormat.COLOR_RANGE_FULL,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_VP8, "color_bands_176x176_vp8_8bit.webm",
+                        MediaFormat.COLOR_RANGE_FULL,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_VP9, "color_bands_176x176_vp9_8bit.webm",
+                        MediaFormat.COLOR_RANGE_FULL,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_AV1, "color_bands_176x176_av1_8bit.webm",
+                        MediaFormat.COLOR_RANGE_FULL,
+                        MediaFormat.COLOR_STANDARD_BT601_NTSC,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+
+                // 709LR
+                {MediaFormat.MIMETYPE_VIDEO_AVC, "color_bands_176x176_h264_8bit.mp4",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT709,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_HEVC, "color_bands_176x176_hevc_8bit.mp4",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT709,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_VP8, "color_bands_176x176_vp8_8bit.webm",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT709,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_VP9, "color_bands_176x176_vp9_8bit.webm",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT709,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+                {MediaFormat.MIMETYPE_VIDEO_AV1, "color_bands_176x176_av1_8bit.webm",
+                        MediaFormat.COLOR_RANGE_LIMITED,
+                        MediaFormat.COLOR_STANDARD_BT709,
+                        MediaFormat.COLOR_TRANSFER_SDR_VIDEO},
+
+                // Note: OpenGL is not required to support 709 FR. So we are not testing it.
+        });
+        return CodecTestBase.prepareParamList(argsList, isEncoder, needAudio, needVideo,
+                false);
+    }
+
+    boolean isColorClose(int actual, int expected) {
+        int delta = Math.abs(actual - expected);
+        return (delta <= ALLOWED_COLOR_DELTA);
+    }
+
+    private boolean checkSurfaceFrame(int frameIndex) {
+        ByteBuffer pixelBuf = ByteBuffer.allocateDirect(4);
+        boolean frameFailed = false;
+        for (int i = 0; i < mColorBars.length; i++) {
+            int x = mColorBarWidth * i + xOffset;
+            int y = yOffset;
+            GLES20.glReadPixels(x, y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixelBuf);
+            int r = pixelBuf.get(0) & 0xff;
+            int g = pixelBuf.get(1) & 0xff;
+            int b = pixelBuf.get(2) & 0xff;
+            if (!(isColorClose(r, mColorBars[i][0]) &&
+                    isColorClose(g, mColorBars[i][1]) &&
+                    isColorClose(b, mColorBars[i][2]))) {
+                Log.w(LOG_TAG, "Bad frame " + frameIndex + " (rect={" + x + " " + y + "} :rgb=" +
+                        r + "," + g + "," + b + " vs. expected " + mColorBars[i][0] +
+                        "," + mColorBars[i][1] + "," + mColorBars[i][2] + ")");
+                frameFailed = true;
+            }
+        }
+        return frameFailed;
+    }
+
+    void dequeueOutput(int bufferIndex, MediaCodec.BufferInfo info) {
+        if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
+            mSawOutputEOS = true;
+        }
+        if (ENABLE_LOGS) {
+            Log.v(LOG_TAG, "output: id: " + bufferIndex + " flags: " + info.flags + " size: " +
+                    info.size + " timestamp: " + info.presentationTimeUs);
+        }
+        if (info.size > 0 && (info.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) == 0) {
+            mOutputBuff.saveOutPTS(info.presentationTimeUs);
+            mOutputCount++;
+        }
+        mCodec.releaseOutputBuffer(bufferIndex, mSurface != null);
+        if (info.size > 0) {
+            mEGLWindowOutSurface.awaitNewImage();
+            mEGLWindowOutSurface.drawImage();
+            if (checkSurfaceFrame(mOutputCount - 1)) mBadFrames++;
+        }
+    }
+
+    /**
+     * The test decodes video assets with color bars and outputs frames to OpenGL input surface.
+     * The OpenGL fragment shader reads the frame buffers as externl textures and renders to
+     * a pbuffer. The output RGB values are read and compared against the expected values.
+     */
+    @LargeTest
+    @Test(timeout = CodecTestBase.PER_TEST_TIMEOUT_LARGE_TEST_MS)
+    public void testDecodeGlAccuracyRGB() throws IOException, InterruptedException {
+
+        // TODO (b/219748700): Android software codecs work only with 601LR. Skip for now.
+        if (!isVendorCodec(mCompName)) {
+            if (mRange != MediaFormat.COLOR_RANGE_LIMITED
+                    || mStandard != MediaFormat.COLOR_STANDARD_BT601_NTSC) {
+                Log.w(LOG_TAG, "Skipping " + mCompName + " for color range " + mRange
+                        + " and color standard " + mStandard);
+                return;
+            }
+        }
+
+        MediaFormat format = setUpSource(mFileName);
+
+        // Set color parameters
+        format.setInteger(MediaFormat.KEY_COLOR_RANGE, mRange);
+        format.setInteger(MediaFormat.KEY_COLOR_STANDARD, mStandard);
+        format.setInteger(MediaFormat.KEY_COLOR_TRANSFER, mTransferCurve);
+
+        // Set the format to surface mode
+        format.setInteger(MediaFormat.KEY_COLOR_FORMAT, COLOR_FormatSurface);
+
+        mWidth = format.getInteger(MediaFormat.KEY_WIDTH);
+        mHeight = format.getInteger(MediaFormat.KEY_HEIGHT);
+        mEGLWindowOutSurface = new OutputSurface(mWidth, mHeight, false);
+        mSurface = mEGLWindowOutSurface.getSurface();
+
+        mCodec = MediaCodec.createByCodecName(mCompName);
+        configureCodec(format, true, true, false);
+        mOutputBuff = new OutputManager();
+        mCodec.start();
+        doWork(Integer.MAX_VALUE);
+        queueEOS();
+        validateColorAspects(mCodec.getOutputFormat(), mRange, mStandard, mTransferCurve);
+        waitForAllOutputs();
+        mCodec.stop();
+        mCodec.release();
+        mEGLWindowOutSurface.release();
+
+        assertTrue("color difference exceeds allowed tolerance in " + mBadFrames + " out of " +
+                mOutputCount + " frames", 0 == mBadFrames);
+    }
+}
+
diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothSapTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothSapTest.java
index 1f220cd..ad5cfff 100644
--- a/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothSapTest.java
+++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BluetoothSapTest.java
@@ -44,7 +44,7 @@
 
     private boolean mHasBluetooth;
     private BluetoothAdapter mAdapter;
-    private UiAutomation mUiAutomation;;
+    private UiAutomation mUiAutomation;
 
     private BluetoothSap mBluetoothSap;
     private boolean mIsProfileReady;
@@ -71,7 +71,7 @@
         assertTrue(BTAdapterUtils.enableAdapter(mAdapter, mContext));
 
         mProfileConnectedlock = new ReentrantLock();
-        mConditionProfileIsConnected  = mProfileConnectedlock.newCondition();
+        mConditionProfileIsConnected = mProfileConnectedlock.newCondition();
         mIsProfileReady = false;
         mBluetoothSap = null;
 
@@ -139,7 +139,8 @@
                 BluetoothProfile.STATE_DISCONNECTED);
 
         mUiAutomation.dropShellPermissionIdentity();
-        assertThrows(SecurityException.class, () -> mBluetoothSap.getConnectionState(testDevice));
+        assertEquals(mBluetoothSap.getConnectionState(testDevice),
+                BluetoothProfile.STATE_DISCONNECTED);
     }
 
     @MediumTest
@@ -155,7 +156,7 @@
         mUiAutomation.dropShellPermissionIdentity();
         BluetoothDevice testDevice = mAdapter.getRemoteDevice("00:11:22:AA:BB:CC");
         assertThrows(SecurityException.class, () -> mBluetoothSap.setConnectionPolicy(testDevice,
-                    BluetoothProfile.CONNECTION_POLICY_FORBIDDEN));
+                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN));
         assertThrows(SecurityException.class, () -> mBluetoothSap.getConnectionPolicy(testDevice));
     }
 
diff --git a/tests/tests/openglperf/Android.bp b/tests/tests/openglperf/Android.bp
index da7eaa7..c298873 100644
--- a/tests/tests/openglperf/Android.bp
+++ b/tests/tests/openglperf/Android.bp
@@ -41,4 +41,8 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":com.replica.replicaisland",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/os/Android.bp b/tests/tests/os/Android.bp
index a8116ac..8bc8222 100644
--- a/tests/tests/os/Android.bp
+++ b/tests/tests/os/Android.bp
@@ -74,4 +74,11 @@
     // Do not compress minijail policy files.
     aaptflags: ["-0 .policy"],
     min_sdk_version: "29",
+    data: [
+        ":CtsAutoRevokeQApp",
+        ":CtsAutoRevokeSApp",
+        ":CtsAutoRevokeRApp",
+        ":CtsCompanionTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/os/AutoRevokeRApp/AndroidManifest.xml b/tests/tests/os/AutoRevokeRApp/AndroidManifest.xml
index be31c6d..91777a0 100644
--- a/tests/tests/os/AutoRevokeRApp/AndroidManifest.xml
+++ b/tests/tests/os/AutoRevokeRApp/AndroidManifest.xml
@@ -20,6 +20,7 @@
 
     <uses-permission android:name="android.permission.READ_CALENDAR" />
     <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
 
     <application>
         <activity android:name="android.os.cts.autorevokerapp.MainActivity"
diff --git a/tests/tests/os/src/android/os/cts/AppHibernationIntegrationTest.kt b/tests/tests/os/src/android/os/cts/AppHibernationIntegrationTest.kt
index 0f71b58..26473ed 100644
--- a/tests/tests/os/src/android/os/cts/AppHibernationIntegrationTest.kt
+++ b/tests/tests/os/src/android/os/cts/AppHibernationIntegrationTest.kt
@@ -61,6 +61,7 @@
 import org.junit.Assert.assertTrue
 import org.junit.Assume.assumeFalse
 import org.junit.Before
+import org.junit.BeforeClass
 import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -83,6 +84,12 @@
         const val HIBERNATION_ENABLED_KEY = "app_hibernation_enabled"
 
         const val CMD_KILL = "am kill %s"
+
+        @JvmStatic
+        @BeforeClass
+        fun beforeAllTests() {
+            runBootCompleteReceiver(InstrumentationRegistry.getTargetContext(), LOG_TAG)
+        }
     }
     private val context: Context = InstrumentationRegistry.getTargetContext()
     private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
diff --git a/tests/tests/os/src/android/os/cts/AppHibernationUtils.kt b/tests/tests/os/src/android/os/cts/AppHibernationUtils.kt
index 69d020b..cdbd58c 100644
--- a/tests/tests/os/src/android/os/cts/AppHibernationUtils.kt
+++ b/tests/tests/os/src/android/os/cts/AppHibernationUtils.kt
@@ -16,12 +16,17 @@
 
 package android.os.cts
 
+import android.app.Activity
 import android.app.ActivityManager
 import android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_TOP_SLEEPING
 import android.app.Instrumentation
 import android.app.UiAutomation
+import android.content.BroadcastReceiver
 import android.content.Context
+import android.content.Intent
 import android.content.pm.PackageManager
+import android.os.Handler
+import android.os.Looper
 import android.os.ParcelFileDescriptor
 import android.os.Process
 import android.provider.DeviceConfig
@@ -32,6 +37,7 @@
 import android.support.test.uiautomator.UiScrollable
 import android.support.test.uiautomator.UiSelector
 import android.support.test.uiautomator.Until
+import android.util.Log
 import androidx.test.InstrumentationRegistry
 import com.android.compatibility.common.util.ExceptionUtils.wrappingExceptions
 import com.android.compatibility.common.util.LogcatInspector
@@ -48,7 +54,12 @@
 import org.hamcrest.Matchers
 import org.junit.Assert
 import org.junit.Assert.assertThat
+import org.junit.Assert.assertTrue
 import java.io.InputStream
+import java.util.concurrent.CountDownLatch
+import java.util.concurrent.TimeUnit
+
+private const val BROADCAST_TIMEOUT_MS = 60000L
 
 const val SYSUI_PKG_NAME = "com.android.systemui"
 const val NOTIF_LIST_ID = "com.android.systemui:id/notification_stack_scroller"
@@ -68,6 +79,40 @@
 const val APK_PATH_Q_APP = "/data/local/tmp/cts/os/CtsAutoRevokeQApp.apk"
 const val APK_PACKAGE_NAME_Q_APP = "android.os.cts.autorevokeqapp"
 
+fun runBootCompleteReceiver(context: Context, testTag: String) {
+    val pkgManager = context.packageManager
+    val permissionControllerPkg = pkgManager.permissionControllerPackageName
+    val receivers = pkgManager.queryBroadcastReceivers(
+        Intent(Intent.ACTION_BOOT_COMPLETED), /* flags= */ 0)
+    for (ri in receivers) {
+        val pkg = ri.activityInfo.packageName
+        if (pkg == permissionControllerPkg) {
+            val permissionControllerSetupIntent = Intent()
+                .setClassName(pkg, ri.activityInfo.name)
+                .setFlags(Intent.FLAG_RECEIVER_FOREGROUND)
+                .setPackage(permissionControllerPkg)
+            val countdownLatch = CountDownLatch(1)
+            Log.d(testTag, "Sending boot complete broadcast directly to ${ri.activityInfo.name} " +
+                "in package $permissionControllerPkg")
+            context.sendOrderedBroadcast(
+                permissionControllerSetupIntent,
+                /* receiverPermission= */ null,
+                object : BroadcastReceiver() {
+                    override fun onReceive(context: Context?, intent: Intent?) {
+                        countdownLatch.countDown()
+                        Log.d(testTag, "Broadcast received by $permissionControllerPkg")
+                    }
+                },
+                Handler.createAsync(Looper.getMainLooper()),
+                Activity.RESULT_OK,
+                /* initialData= */ null,
+                /* initialExtras= */ null)
+            assertTrue("Timed out while waiting for boot receiver broadcast to be received",
+                countdownLatch.await(BROADCAST_TIMEOUT_MS, TimeUnit.MILLISECONDS))
+        }
+    }
+}
+
 fun runAppHibernationJob(context: Context, tag: String) {
     val logcat = Logcat()
 
diff --git a/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt b/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt
index 8845ef0..7de2727 100644
--- a/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt
+++ b/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt
@@ -64,7 +64,8 @@
 import org.junit.Assert.assertTrue
 import org.junit.Assume.assumeFalse
 import org.junit.Before
-import org.junit.Ignore;
+import org.junit.BeforeClass
+import org.junit.Ignore
 import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -95,6 +96,12 @@
 
     companion object {
         const val LOG_TAG = "AutoRevokeTest"
+
+        @JvmStatic
+        @BeforeClass
+        fun beforeAllTests() {
+            runBootCompleteReceiver(InstrumentationRegistry.getTargetContext(), LOG_TAG)
+        }
     }
 
     @get:Rule
diff --git a/tests/tests/packageinstaller/adminpackageinstaller/Android.bp b/tests/tests/packageinstaller/adminpackageinstaller/Android.bp
index 62a44fc..f829a93 100644
--- a/tests/tests/packageinstaller/adminpackageinstaller/Android.bp
+++ b/tests/tests/packageinstaller/adminpackageinstaller/Android.bp
@@ -34,4 +34,8 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsEmptyTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/packageinstaller/install/Android.bp b/tests/tests/packageinstaller/install/Android.bp
index 8444e02..3d3e21a 100644
--- a/tests/tests/packageinstaller/install/Android.bp
+++ b/tests/tests/packageinstaller/install/Android.bp
@@ -40,4 +40,8 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsEmptyTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/packageinstaller/install_appop_default/Android.bp b/tests/tests/packageinstaller/install_appop_default/Android.bp
index 7808af1..8eb0e34 100644
--- a/tests/tests/packageinstaller/install_appop_default/Android.bp
+++ b/tests/tests/packageinstaller/install_appop_default/Android.bp
@@ -33,4 +33,8 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsEmptyTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/packageinstaller/install_appop_denied/Android.bp b/tests/tests/packageinstaller/install_appop_denied/Android.bp
index ee76790..20e1ad4 100644
--- a/tests/tests/packageinstaller/install_appop_denied/Android.bp
+++ b/tests/tests/packageinstaller/install_appop_denied/Android.bp
@@ -34,4 +34,8 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsEmptyTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/packageinstaller/nopermission/Android.bp b/tests/tests/packageinstaller/nopermission/Android.bp
index 24747d1..3e5d914 100644
--- a/tests/tests/packageinstaller/nopermission/Android.bp
+++ b/tests/tests/packageinstaller/nopermission/Android.bp
@@ -43,4 +43,8 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsEmptyTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/packageinstaller/nopermission25/Android.bp b/tests/tests/packageinstaller/nopermission25/Android.bp
index 581c9b4..ab2aed3 100644
--- a/tests/tests/packageinstaller/nopermission25/Android.bp
+++ b/tests/tests/packageinstaller/nopermission25/Android.bp
@@ -28,4 +28,8 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsEmptyTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/packageinstaller/tapjacking/Android.bp b/tests/tests/packageinstaller/tapjacking/Android.bp
index 8035d6d..59c491d 100644
--- a/tests/tests/packageinstaller/tapjacking/Android.bp
+++ b/tests/tests/packageinstaller/tapjacking/Android.bp
@@ -33,4 +33,8 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsEmptyTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/packageinstaller/uninstall/Android.bp b/tests/tests/packageinstaller/uninstall/Android.bp
index 537dad7..8b26e33 100644
--- a/tests/tests/packageinstaller/uninstall/Android.bp
+++ b/tests/tests/packageinstaller/uninstall/Android.bp
@@ -35,4 +35,9 @@
         "general-tests",
         "sts",
     ],
+    data: [
+        ":CtsEmptyTestApp",
+        ":CtsSelfUninstallingTestApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/permission4/Android.bp b/tests/tests/permission4/Android.bp
index 22b0aa2..b20f24d 100644
--- a/tests/tests/permission4/Android.bp
+++ b/tests/tests/permission4/Android.bp
@@ -39,4 +39,8 @@
         "general-tests",
         "mts-permission",
     ],
+    data: [
+        ":CtsAppThatAccessesMicAndCameraPermission",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/print/Android.bp b/tests/tests/print/Android.bp
index 23ed10c..0af9c18 100644
--- a/tests/tests/print/Android.bp
+++ b/tests/tests/print/Android.bp
@@ -28,4 +28,8 @@
     static_libs: ["print-test-util-lib"],
     sdk_version: "test_current",
     required: ["com.android.cts.helpers.aosp"],
+    data: [
+        ":CtsExternalPrintService",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/security/Android.bp b/tests/tests/security/Android.bp
index cf064c6..00a1e37 100644
--- a/tests/tests/security/Android.bp
+++ b/tests/tests/security/Android.bp
@@ -74,7 +74,9 @@
         "sts",
     ],
     certificate: ":security_cts_test_certificate",
+    per_testcase_directory: true,
     data: [
+        ":CtsDeviceInfo",
         ":RolePermissionOverrideTestApp",
         ":SplitBluetoothPermissionTestApp",
     ],
diff --git a/tests/tests/security/src/android/security/cts/AttributionSourceTest.java b/tests/tests/security/src/android/security/cts/AttributionSourceTest.java
index e36fa49..35a7bbe 100644
--- a/tests/tests/security/src/android/security/cts/AttributionSourceTest.java
+++ b/tests/tests/security/src/android/security/cts/AttributionSourceTest.java
@@ -27,9 +27,10 @@
 import android.platform.test.annotations.AsbSecurityTest;
 import androidx.test.core.app.ApplicationProvider;
 import androidx.test.runner.AndroidJUnit4;
+import com.android.sts.common.util.StsExtraBusinessLogicTestCase;
 
 @RunWith(AndroidJUnit4.class)
-public class AttributionSourceTest {
+public class AttributionSourceTest extends StsExtraBusinessLogicTestCase {
 
     @AsbSecurityTest(cveBugId = 200288596)
     @Test
diff --git a/tests/tests/security/src/android/security/cts/RolePermissionOverrideTest.kt b/tests/tests/security/src/android/security/cts/RolePermissionOverrideTest.kt
index 2394cd2..334fe31 100644
--- a/tests/tests/security/src/android/security/cts/RolePermissionOverrideTest.kt
+++ b/tests/tests/security/src/android/security/cts/RolePermissionOverrideTest.kt
@@ -21,12 +21,12 @@
 import android.os.Process
 import android.platform.test.annotations.AsbSecurityTest
 import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.platform.app.InstrumentationRegistry
 import com.android.compatibility.common.util.SystemUtil.callWithShellPermissionIdentity
 import com.android.compatibility.common.util.SystemUtil.runShellCommand
 import com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity
 import com.android.compatibility.common.util.mainline.MainlineModule
 import com.android.compatibility.common.util.mainline.ModuleDetector
+import com.android.sts.common.util.StsExtraBusinessLogicTestCase
 import com.google.common.truth.Truth.assertThat
 import java.util.concurrent.CompletableFuture
 import java.util.concurrent.TimeUnit
@@ -39,13 +39,14 @@
 import org.junit.runner.RunWith
 
 @RunWith(AndroidJUnit4::class)
-class RolePermissionOverrideTest {
-    private val instrumentation = InstrumentationRegistry.getInstrumentation()
-    private val context = instrumentation.targetContext
+class RolePermissionOverrideTest : StsExtraBusinessLogicTestCase {
+    private val context = getInstrumentation().targetContext
     private val packageManager = context.packageManager
     private val roleManager = context.getSystemService(RoleManager::class.java)
     private val user = Process.myUserHandle()
 
+    constructor() : super()
+
     @Before
     fun setUp() {
         installPackage(TEST_APP_APK_PATH)
diff --git a/tests/tests/sensorprivacy/Android.bp b/tests/tests/sensorprivacy/Android.bp
index 608f445..8d63414 100644
--- a/tests/tests/sensorprivacy/Android.bp
+++ b/tests/tests/sensorprivacy/Android.bp
@@ -45,4 +45,9 @@
         "android.test.runner",
         "android.test.base",
     ],
+    data: [
+        ":CtsUseMicOrCameraAndOverlayForSensorPrivacy",
+        ":CtsUseMicOrCameraForSensorPrivacy",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/sharesheet/Android.bp b/tests/tests/sharesheet/Android.bp
index 8b4b62a..dc85889 100644
--- a/tests/tests/sharesheet/Android.bp
+++ b/tests/tests/sharesheet/Android.bp
@@ -40,4 +40,10 @@
     srcs: ["src/**/*.java"],
 
     sdk_version: "test_current",
+    data: [
+        ":CtsSharesheetExcludeTester",
+        ":CtsSharesheetActivityLabelTester",
+        ":CtsSharesheetIntentFilterLabelTester",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/shortcutmanager/Android.bp b/tests/tests/shortcutmanager/Android.bp
index fab3c5e..ead524c 100644
--- a/tests/tests/shortcutmanager/Android.bp
+++ b/tests/tests/shortcutmanager/Android.bp
@@ -34,6 +34,18 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsShortcutManagerPackage4",
+        ":CtsShortcutManagerPackage1",
+        ":CtsShortcutManagerPackage2",
+        ":CtsShortcutManagerPackage3",
+        ":CtsShortcutManagerLauncher4",
+        ":CtsShortcutManagerLauncher3",
+        ":CtsShortcutManagerThrottlingTest",
+        ":CtsShortcutManagerLauncher2",
+        ":CtsShortcutManagerLauncher1",
+    ],
+    per_testcase_directory: true,
 }
 
 //-----------------------------------------------------------
diff --git a/tests/tests/syncmanager/Android.bp b/tests/tests/syncmanager/Android.bp
index 5abee47..2042319 100644
--- a/tests/tests/syncmanager/Android.bp
+++ b/tests/tests/syncmanager/Android.bp
@@ -38,4 +38,9 @@
         "general-tests",
     ],
     sdk_version: "test_current",
+    data: [
+        ":CtsSyncManagerApp1",
+        ":CtsSyncManagerApp2",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/systemui/Android.bp b/tests/tests/systemui/Android.bp
index 0d28f65..e33d8fc 100644
--- a/tests/tests/systemui/Android.bp
+++ b/tests/tests/systemui/Android.bp
@@ -46,4 +46,12 @@
         "src/**/*.kt",
     ],
     platform_apis: true,
+    data: [
+        ":CtsVpnFirewallApp",
+        ":PipTestApp",
+        ":CtsMockInputMethod",
+        ":AudioRecorderTestApp_AudioRecord",
+        ":AudioRecorderTestApp_MediaRecorder",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/telecom/Android.bp b/tests/tests/telecom/Android.bp
index c056b0a..ea2cec2 100644
--- a/tests/tests/telecom/Android.bp
+++ b/tests/tests/telecom/Android.bp
@@ -99,6 +99,18 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":ThirdPtyInCallServiceTestApp",
+        ":CarModeTestAppTwo",
+        ":Api29InCallServiceTestApp",
+        ":CallRedirectionServiceTestApp",
+        ":ThirdPtyDialerTestAppTwo",
+        ":ThirdPtyDialerTestApp",
+        ":CarModeTestApp",
+        ":CarModeTestAppSelfManaged",
+        ":CallScreeningServiceTestApp",
+    ],
+    per_testcase_directory: true,
 }
 
 java_library {
diff --git a/tests/tests/telephony/current/Android.bp b/tests/tests/telephony/current/Android.bp
index 5459267..6e68b64 100644
--- a/tests/tests/telephony/current/Android.bp
+++ b/tests/tests/telephony/current/Android.bp
@@ -82,6 +82,17 @@
         "compatibility-host-telephony-preconditions",
         "cts-tradefed",
     ],
+    data: [
+        ":TestSmsApp22",
+        ":LocationAccessingApp",
+        ":LocationAccessingAppSdk28",
+        ":TestFinancialSmsApp",
+        ":TestSmsRetrieverApp",
+        ":TestSmsApp",
+        ":TestExternalImsServiceApp",
+        ":EmbmsMiddlewareCtsTestApp",
+    ],
+    per_testcase_directory: true,
 }
 
 filegroup {
diff --git a/tests/tests/text/Android.bp b/tests/tests/text/Android.bp
index fed0629..6dc1c92 100644
--- a/tests/tests/text/Android.bp
+++ b/tests/tests/text/Android.bp
@@ -56,4 +56,8 @@
         "mts",
         "sts",
     ],
+    data: [
+        ":CtsTextTestResourceData",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/textclassifier/Android.bp b/tests/tests/textclassifier/Android.bp
index 0a25497..fb4b336 100644
--- a/tests/tests/textclassifier/Android.bp
+++ b/tests/tests/textclassifier/Android.bp
@@ -45,4 +45,8 @@
     resource_dirs: ["res"],
     sdk_version: "test_current",
     min_sdk_version: "30",
+    data: [
+        ":CtsQueryTextClassifierServiceActivity",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/uidmigration/Android.bp b/tests/tests/uidmigration/Android.bp
index 4f98ae6..b826fa3 100644
--- a/tests/tests/uidmigration/Android.bp
+++ b/tests/tests/uidmigration/Android.bp
@@ -38,4 +38,16 @@
         "general-tests",
     ],
     platform_apis: true,
+    data: [
+        ":CtsSharedUserMigrationInstallTestApp4",
+        ":CtsSharedUserMigrationPermissionTestApp2",
+        ":CtsSharedUserMigrationInstallTestApp3",
+        ":CtsSharedUserMigrationPermissionTestApp1",
+        ":CtsSharedUserMigrationDataTestApp1",
+        ":CtsSharedUserMigrationDataTestApp2",
+        ":CtsSharedUserMigrationPermissionTestApp3",
+        ":CtsSharedUserMigrationInstallTestApp",
+        ":CtsSharedUserMigrationInstallTestApp2",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/view/src/android/view/cts/PixelCopyTest.java b/tests/tests/view/src/android/view/cts/PixelCopyTest.java
index 68c6f70..9ac6864 100644
--- a/tests/tests/view/src/android/view/cts/PixelCopyTest.java
+++ b/tests/tests/view/src/android/view/cts/PixelCopyTest.java
@@ -23,6 +23,7 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import android.app.Activity;
 import android.app.Instrumentation;
 import android.content.Context;
 import android.content.pm.ActivityInfo;
@@ -40,6 +41,7 @@
 import android.media.ImageReader;
 import android.media.ImageWriter;
 import android.os.Debug;
+import android.server.wm.IgnoreOrientationRequestSession;
 import android.util.Half;
 import android.util.Log;
 import android.view.PixelCopy;
@@ -121,6 +123,24 @@
         mCopyHelper = new SynchronousPixelCopy();
     }
 
+    /**
+     * Helper method used to execute a runnable that enables the
+     * {@link Activity#setRequestedOrientation} API.
+     *
+     * On Android 12L large screen devices ignore requests to the setRequestedOrientation.
+     * So in order to support test cases that rely on this API, use
+     * {@link IgnoreOrientationRequestSession} to temporarily enable the setRequestedOrientation API
+     */
+    private void withRequestedOrientationsEnabled(Runnable runnable) {
+        IgnoreOrientationRequestSession session = new IgnoreOrientationRequestSession(
+                false /* enable setRequestedOrientation */);
+        try {
+            runnable.run();
+        } finally {
+            session.close();
+        }
+    }
+
     @Test(expected = IllegalArgumentException.class)
     public void testNullDest() {
         Bitmap dest = null;
@@ -306,99 +326,111 @@
 
     @Test
     public void testWindowProducer() {
-        Bitmap bitmap;
-        Window window = waitForWindowProducerActivity();
-        PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
-        do {
-            Rect src = makeWindowRect(0, 0, 100, 100);
-            bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.ARGB_8888);
-            int result = mCopyHelper.request(window, src, bitmap);
-            assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
-            assertEquals(Config.ARGB_8888, bitmap.getConfig());
-            assertBitmapQuadColor(bitmap,
-                    Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
-            assertBitmapEdgeColor(bitmap, Color.YELLOW);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            Bitmap bitmap;
+            Window window = waitForWindowProducerActivity();
+            PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
+            do {
+                Rect src = makeWindowRect(0, 0, 100, 100);
+                bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.ARGB_8888);
+                int result = mCopyHelper.request(window, src, bitmap);
+                assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
+                assertEquals(Config.ARGB_8888, bitmap.getConfig());
+                assertBitmapQuadColor(bitmap,
+                        Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
+                assertBitmapEdgeColor(bitmap, Color.YELLOW);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testWindowProducerCropTopLeft() {
-        Window window = waitForWindowProducerActivity();
-        Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
-        PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
-        do {
-            int result = mCopyHelper.request(window, makeWindowRect(0, 0, 50, 50), bitmap);
-            assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
-            assertBitmapQuadColor(bitmap,
-                    Color.RED, Color.RED, Color.RED, Color.RED);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForWindowProducerActivity();
+            Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+            PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
+            do {
+                int result = mCopyHelper.request(window, makeWindowRect(0, 0, 50, 50), bitmap);
+                assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
+                assertBitmapQuadColor(bitmap,
+                        Color.RED, Color.RED, Color.RED, Color.RED);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testWindowProducerCropCenter() {
-        Window window = waitForWindowProducerActivity();
-        Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
-        PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
-        do {
-            int result = mCopyHelper.request(window, makeWindowRect(25, 25, 75, 75), bitmap);
-            assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
-            assertBitmapQuadColor(bitmap,
-                    Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForWindowProducerActivity();
+            Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+            PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
+            do {
+                int result = mCopyHelper.request(window, makeWindowRect(25, 25, 75, 75), bitmap);
+                assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
+                assertBitmapQuadColor(bitmap,
+                        Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testWindowProducerCropBottomHalf() {
-        Window window = waitForWindowProducerActivity();
-        Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
-        PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
-        do {
-            int result = mCopyHelper.request(window, makeWindowRect(0, 50, 100, 100), bitmap);
-            assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
-            assertBitmapQuadColor(bitmap,
-                    Color.BLUE, Color.BLACK, Color.BLUE, Color.BLACK);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForWindowProducerActivity();
+            Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+            PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
+            do {
+                int result = mCopyHelper.request(window, makeWindowRect(0, 50, 100, 100), bitmap);
+                assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
+                assertBitmapQuadColor(bitmap,
+                        Color.BLUE, Color.BLACK, Color.BLUE, Color.BLACK);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testWindowProducerScaling() {
-        // Since we only sample mid-pixel of each qudrant, filtering
-        // quality isn't tested
-        Window window = waitForWindowProducerActivity();
-        Bitmap bitmap = Bitmap.createBitmap(20, 20, Config.ARGB_8888);
-        PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
-        do {
-            int result = mCopyHelper.request(window, bitmap);
-            assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
-            // Make sure nothing messed with the bitmap
-            assertEquals(20, bitmap.getWidth());
-            assertEquals(20, bitmap.getHeight());
-            assertEquals(Config.ARGB_8888, bitmap.getConfig());
-            assertBitmapQuadColor(bitmap,
-                    Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            // Since we only sample mid-pixel of each qudrant, filtering
+            // quality isn't tested
+            Window window = waitForWindowProducerActivity();
+            Bitmap bitmap = Bitmap.createBitmap(20, 20, Config.ARGB_8888);
+            PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
+            do {
+                int result = mCopyHelper.request(window, bitmap);
+                assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
+                // Make sure nothing messed with the bitmap
+                assertEquals(20, bitmap.getWidth());
+                assertEquals(20, bitmap.getHeight());
+                assertEquals(Config.ARGB_8888, bitmap.getConfig());
+                assertBitmapQuadColor(bitmap,
+                        Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testWindowProducerCopyToRGBA16F() {
-        Window window = waitForWindowProducerActivity();
-        PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForWindowProducerActivity();
+            PixelCopyViewProducerActivity activity = mWindowSourceActivityRule.getActivity();
 
-        Bitmap bitmap;
-        do {
-            Rect src = makeWindowRect(0, 0, 100, 100);
-            bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.RGBA_F16);
-            int result = mCopyHelper.request(window, src, bitmap);
-            // On OpenGL ES 2.0 devices a copy to RGBA_F16 can fail because there's
-            // not support for float textures
-            if (result != PixelCopy.ERROR_DESTINATION_INVALID) {
-                assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
-                assertEquals(Config.RGBA_F16, bitmap.getConfig());
-                assertBitmapQuadColor(bitmap,
-                        Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
-                assertBitmapEdgeColor(bitmap, Color.YELLOW);
-            }
-        } while (activity.rotate());
+            Bitmap bitmap;
+            do {
+                Rect src = makeWindowRect(0, 0, 100, 100);
+                bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.RGBA_F16);
+                int result = mCopyHelper.request(window, src, bitmap);
+                // On OpenGL ES 2.0 devices a copy to RGBA_F16 can fail because there's
+                // not support for float textures
+                if (result != PixelCopy.ERROR_DESTINATION_INVALID) {
+                    assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
+                    assertEquals(Config.RGBA_F16, bitmap.getConfig());
+                    assertBitmapQuadColor(bitmap,
+                            Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
+                    assertBitmapEdgeColor(bitmap, Color.YELLOW);
+                }
+            } while (activity.rotate());
+        });
     }
 
     private Window waitForWideGamutWindowProducerActivity() {
@@ -416,101 +448,111 @@
 
     @Test
     public void testWideGamutWindowProducerCopyToRGBA8888() {
-        Window window = waitForWideGamutWindowProducerActivity();
-        assertEquals(
-                ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT, window.getAttributes().getColorMode());
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForWideGamutWindowProducerActivity();
+            assertEquals(
+                    ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT,
+                    window.getAttributes().getColorMode()
+            );
 
-        // Early out if the device does not support wide color gamut rendering
-        if (!window.isWideColorGamut()) {
-            return;
-        }
+            // Early out if the device does not support wide color gamut rendering
+            if (!window.isWideColorGamut()) {
+                return;
+            }
 
-        PixelCopyWideGamutViewProducerActivity activity =
-                mWideGamutWindowSourceActivityRule.getActivity();
+            PixelCopyWideGamutViewProducerActivity activity =
+                    mWideGamutWindowSourceActivityRule.getActivity();
 
-        Bitmap bitmap;
-        do {
-            Rect src = makeWideGamutWindowRect(0, 0, 128, 128);
-            bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.ARGB_8888);
-            int result = mCopyHelper.request(window, src, bitmap);
+            Bitmap bitmap;
+            do {
+                Rect src = makeWideGamutWindowRect(0, 0, 128, 128);
+                bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.ARGB_8888);
+                int result = mCopyHelper.request(window, src, bitmap);
 
-            assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
-            assertEquals(Config.ARGB_8888, bitmap.getConfig());
+                assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
+                assertEquals(Config.ARGB_8888, bitmap.getConfig());
 
-            assertEquals("Top left", Color.RED, bitmap.getPixel(32, 32));
-            assertEquals("Top right", Color.GREEN, bitmap.getPixel(96, 32));
-            assertEquals("Bottom left", Color.BLUE, bitmap.getPixel(32, 96));
-            assertEquals("Bottom right", Color.YELLOW, bitmap.getPixel(96, 96));
-        } while (activity.rotate());
+                assertEquals("Top left", Color.RED, bitmap.getPixel(32, 32));
+                assertEquals("Top right", Color.GREEN, bitmap.getPixel(96, 32));
+                assertEquals("Bottom left", Color.BLUE, bitmap.getPixel(32, 96));
+                assertEquals("Bottom right", Color.YELLOW, bitmap.getPixel(96, 96));
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testWideGamutWindowProducerCopyToRGBA16F() {
-        Window window = waitForWideGamutWindowProducerActivity();
-        assertEquals(
-                ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT, window.getAttributes().getColorMode());
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForWideGamutWindowProducerActivity();
+            assertEquals(
+                    ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT,
+                    window.getAttributes().getColorMode()
+            );
 
-        // Early out if the device does not support wide color gamut rendering
-        if (!window.isWideColorGamut()) {
-            return;
-        }
+            // Early out if the device does not support wide color gamut rendering
+            if (!window.isWideColorGamut()) {
+                return;
+            }
 
-        PixelCopyWideGamutViewProducerActivity activity =
-                mWideGamutWindowSourceActivityRule.getActivity();
-        final WindowManager windowManager = (WindowManager) activity.getSystemService(
-                Context.WINDOW_SERVICE);
-        final ColorSpace colorSpace = windowManager.getDefaultDisplay()
-                .getPreferredWideGamutColorSpace();
-        final ColorSpace.Connector proPhotoToDisplayWideColorSpace = ColorSpace.connect(
-                ColorSpace.get(ColorSpace.Named.PRO_PHOTO_RGB), colorSpace);
-        final ColorSpace.Connector displayWideColorSpaceToExtendedSrgb = ColorSpace.connect(
-                colorSpace, ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB));
+            PixelCopyWideGamutViewProducerActivity activity =
+                    mWideGamutWindowSourceActivityRule.getActivity();
+            final WindowManager windowManager = (WindowManager) activity.getSystemService(
+                    Context.WINDOW_SERVICE);
+            final ColorSpace colorSpace = windowManager.getDefaultDisplay()
+                    .getPreferredWideGamutColorSpace();
+            final ColorSpace.Connector proPhotoToDisplayWideColorSpace = ColorSpace.connect(
+                    ColorSpace.get(ColorSpace.Named.PRO_PHOTO_RGB), colorSpace);
+            final ColorSpace.Connector displayWideColorSpaceToExtendedSrgb = ColorSpace.connect(
+                    colorSpace, ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB));
 
-        final float[] intermediateRed = proPhotoToDisplayWideColorSpace.transform(1.0f, 0.0f, 0.0f);
-        final float[] intermediateGreen = proPhotoToDisplayWideColorSpace
-                .transform(0.0f, 1.0f, 0.0f);
-        final float[] intermediateBlue = proPhotoToDisplayWideColorSpace
-                .transform(0.0f, 0.0f, 1.0f);
-        final float[] intermediateYellow = proPhotoToDisplayWideColorSpace
-                .transform(1.0f, 1.0f, 0.0f);
+            final float[] intermediateRed =
+                    proPhotoToDisplayWideColorSpace.transform(1.0f, 0.0f, 0.0f);
+            final float[] intermediateGreen = proPhotoToDisplayWideColorSpace
+                    .transform(0.0f, 1.0f, 0.0f);
+            final float[] intermediateBlue = proPhotoToDisplayWideColorSpace
+                    .transform(0.0f, 0.0f, 1.0f);
+            final float[] intermediateYellow = proPhotoToDisplayWideColorSpace
+                    .transform(1.0f, 1.0f, 0.0f);
 
-        final float[] expectedRed = displayWideColorSpaceToExtendedSrgb.transform(intermediateRed);
-        final float[] expectedGreen = displayWideColorSpaceToExtendedSrgb
-                .transform(intermediateGreen);
-        final float[] expectedBlue = displayWideColorSpaceToExtendedSrgb
-                .transform(intermediateBlue);
-        final float[] expectedYellow = displayWideColorSpaceToExtendedSrgb
-                .transform(intermediateYellow);
+            final float[] expectedRed =
+                    displayWideColorSpaceToExtendedSrgb.transform(intermediateRed);
+            final float[] expectedGreen = displayWideColorSpaceToExtendedSrgb
+                    .transform(intermediateGreen);
+            final float[] expectedBlue = displayWideColorSpaceToExtendedSrgb
+                    .transform(intermediateBlue);
+            final float[] expectedYellow = displayWideColorSpaceToExtendedSrgb
+                    .transform(intermediateYellow);
 
-        Bitmap bitmap;
-        int i = 0;
-        do {
-            Rect src = makeWideGamutWindowRect(0, 0, 128, 128);
-            bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.RGBA_F16, true,
-                    ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB));
-            int result = mCopyHelper.request(window, src, bitmap);
+            Bitmap bitmap;
+            int i = 0;
+            do {
+                Rect src = makeWideGamutWindowRect(0, 0, 128, 128);
+                bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.RGBA_F16,
+                        true, ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB));
+                int result = mCopyHelper.request(window, src, bitmap);
 
-            assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
-            assertEquals(Config.RGBA_F16, bitmap.getConfig());
+                assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
+                assertEquals(Config.RGBA_F16, bitmap.getConfig());
 
-            ByteBuffer dst = ByteBuffer.allocateDirect(bitmap.getAllocationByteCount());
-            bitmap.copyPixelsToBuffer(dst);
-            dst.rewind();
-            dst.order(ByteOrder.LITTLE_ENDIAN);
+                ByteBuffer dst = ByteBuffer.allocateDirect(bitmap.getAllocationByteCount());
+                bitmap.copyPixelsToBuffer(dst);
+                dst.rewind();
+                dst.order(ByteOrder.LITTLE_ENDIAN);
 
-            // ProPhoto RGB red in scRGB-nl
-            assertEqualsRgba16f("Top left",     bitmap, 32, 32, dst, expectedRed[0],
-                    expectedRed[1], expectedRed[2], 1.0f);
-            // ProPhoto RGB green in scRGB-nl
-            assertEqualsRgba16f("Top right",    bitmap, 96, 32, dst, expectedGreen[0],
-                    expectedGreen[1], expectedGreen[2], 1.0f);
-            // ProPhoto RGB blue in scRGB-nl
-            assertEqualsRgba16f("Bottom left",  bitmap, 32, 96, dst, expectedBlue[0],
-                    expectedBlue[1], expectedBlue[2], 1.0f);
-            // ProPhoto RGB yellow in scRGB-nl
-            assertEqualsRgba16f("Bottom right", bitmap, 96, 96, dst, expectedYellow[0],
-                    expectedYellow[1], expectedYellow[2], 1.0f);
-        } while (activity.rotate());
+                // ProPhoto RGB red in scRGB-nl
+                assertEqualsRgba16f("Top left", bitmap, 32, 32, dst, expectedRed[0],
+                        expectedRed[1], expectedRed[2], 1.0f);
+                // ProPhoto RGB green in scRGB-nl
+                assertEqualsRgba16f("Top right", bitmap, 96, 32, dst,
+                        expectedGreen[0], expectedGreen[1], expectedGreen[2], 1.0f);
+                // ProPhoto RGB blue in scRGB-nl
+                assertEqualsRgba16f("Bottom left",  bitmap, 32, 96, dst,
+                        expectedBlue[0], expectedBlue[1], expectedBlue[2], 1.0f);
+                // ProPhoto RGB yellow in scRGB-nl
+                assertEqualsRgba16f("Bottom right", bitmap, 96, 96, dst,
+                        expectedYellow[0], expectedYellow[1], expectedYellow[2], 1.0f);
+            } while (activity.rotate());
+        });
     }
 
     private Window waitForDialogProducerActivity() {
@@ -528,99 +570,111 @@
 
     @Test
     public void testDialogProducer() {
-        Bitmap bitmap;
-        Window window = waitForDialogProducerActivity();
-        PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
-        do {
-            Rect src = makeDialogRect(0, 0, 100, 100);
-            bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.ARGB_8888);
-            int result = mCopyHelper.request(window, src, bitmap);
-            assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
-            assertEquals(Config.ARGB_8888, bitmap.getConfig());
-            assertBitmapQuadColor(bitmap,
-                    Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
-            assertBitmapEdgeColor(bitmap, Color.YELLOW);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            Bitmap bitmap;
+            Window window = waitForDialogProducerActivity();
+            PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
+            do {
+                Rect src = makeDialogRect(0, 0, 100, 100);
+                bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.ARGB_8888);
+                int result = mCopyHelper.request(window, src, bitmap);
+                assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
+                assertEquals(Config.ARGB_8888, bitmap.getConfig());
+                assertBitmapQuadColor(bitmap,
+                        Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
+                assertBitmapEdgeColor(bitmap, Color.YELLOW);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testDialogProducerCropTopLeft() {
-        Window window = waitForDialogProducerActivity();
-        Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
-        PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
-        do {
-            int result = mCopyHelper.request(window, makeDialogRect(0, 0, 50, 50), bitmap);
-            assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
-            assertBitmapQuadColor(bitmap,
-                    Color.RED, Color.RED, Color.RED, Color.RED);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForDialogProducerActivity();
+            Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+            PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
+            do {
+                int result = mCopyHelper.request(window, makeDialogRect(0, 0, 50, 50), bitmap);
+                assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
+                assertBitmapQuadColor(bitmap,
+                        Color.RED, Color.RED, Color.RED, Color.RED);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testDialogProducerCropCenter() {
-        Window window = waitForDialogProducerActivity();
-        Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
-        PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
-        do {
-            int result = mCopyHelper.request(window, makeDialogRect(25, 25, 75, 75), bitmap);
-            assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
-            assertBitmapQuadColor(bitmap,
-                    Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForDialogProducerActivity();
+            Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+            PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
+            do {
+                int result = mCopyHelper.request(window, makeDialogRect(25, 25, 75, 75), bitmap);
+                assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
+                assertBitmapQuadColor(bitmap,
+                        Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testDialogProducerCropBottomHalf() {
-        Window window = waitForDialogProducerActivity();
-        Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
-        PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
-        do {
-            int result = mCopyHelper.request(window, makeDialogRect(0, 50, 100, 100), bitmap);
-            assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
-            assertBitmapQuadColor(bitmap,
-                    Color.BLUE, Color.BLACK, Color.BLUE, Color.BLACK);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForDialogProducerActivity();
+            Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
+            PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
+            do {
+                int result = mCopyHelper.request(window, makeDialogRect(0, 50, 100, 100), bitmap);
+                assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
+                assertBitmapQuadColor(bitmap,
+                        Color.BLUE, Color.BLACK, Color.BLUE, Color.BLACK);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testDialogProducerScaling() {
-        // Since we only sample mid-pixel of each qudrant, filtering
-        // quality isn't tested
-        Window window = waitForDialogProducerActivity();
-        Bitmap bitmap = Bitmap.createBitmap(20, 20, Config.ARGB_8888);
-        PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
-        do {
-            int result = mCopyHelper.request(window, bitmap);
-            assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
-            // Make sure nothing messed with the bitmap
-            assertEquals(20, bitmap.getWidth());
-            assertEquals(20, bitmap.getHeight());
-            assertEquals(Config.ARGB_8888, bitmap.getConfig());
-            assertBitmapQuadColor(bitmap,
-                    Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
-        } while (activity.rotate());
+        withRequestedOrientationsEnabled(() -> {
+            // Since we only sample mid-pixel of each qudrant, filtering
+            // quality isn't tested
+            Window window = waitForDialogProducerActivity();
+            Bitmap bitmap = Bitmap.createBitmap(20, 20, Config.ARGB_8888);
+            PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
+            do {
+                int result = mCopyHelper.request(window, bitmap);
+                assertEquals("Scaled copy request failed", PixelCopy.SUCCESS, result);
+                // Make sure nothing messed with the bitmap
+                assertEquals(20, bitmap.getWidth());
+                assertEquals(20, bitmap.getHeight());
+                assertEquals(Config.ARGB_8888, bitmap.getConfig());
+                assertBitmapQuadColor(bitmap,
+                        Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
+            } while (activity.rotate());
+        });
     }
 
     @Test
     public void testDialogProducerCopyToRGBA16F() {
-        Window window = waitForDialogProducerActivity();
-        PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
+        withRequestedOrientationsEnabled(() -> {
+            Window window = waitForDialogProducerActivity();
+            PixelCopyViewProducerActivity activity = mDialogSourceActivityRule.getActivity();
 
-        Bitmap bitmap;
-        do {
-            Rect src = makeDialogRect(0, 0, 100, 100);
-            bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.RGBA_F16);
-            int result = mCopyHelper.request(window, src, bitmap);
-            // On OpenGL ES 2.0 devices a copy to RGBA_F16 can fail because there's
-            // not support for float textures
-            if (result != PixelCopy.ERROR_DESTINATION_INVALID) {
-                assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
-                assertEquals(Config.RGBA_F16, bitmap.getConfig());
-                assertBitmapQuadColor(bitmap,
-                        Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
-                assertBitmapEdgeColor(bitmap, Color.YELLOW);
-            }
-        } while (activity.rotate());
+            Bitmap bitmap;
+            do {
+                Rect src = makeDialogRect(0, 0, 100, 100);
+                bitmap = Bitmap.createBitmap(src.width(), src.height(), Config.RGBA_F16);
+                int result = mCopyHelper.request(window, src, bitmap);
+                // On OpenGL ES 2.0 devices a copy to RGBA_F16 can fail because there's
+                // not support for float textures
+                if (result != PixelCopy.ERROR_DESTINATION_INVALID) {
+                    assertEquals("Fullsize copy request failed", PixelCopy.SUCCESS, result);
+                    assertEquals(Config.RGBA_F16, bitmap.getConfig());
+                    assertBitmapQuadColor(bitmap,
+                            Color.RED, Color.GREEN, Color.BLUE, Color.BLACK);
+                    assertBitmapEdgeColor(bitmap, Color.YELLOW);
+                }
+            } while (activity.rotate());
+        });
     }
 
     private static void assertEqualsRgba16f(String message, Bitmap bitmap, int x, int y,
diff --git a/tests/tests/virtualdevice/Android.bp b/tests/tests/virtualdevice/Android.bp
index 5952408..108f19b 100644
--- a/tests/tests/virtualdevice/Android.bp
+++ b/tests/tests/virtualdevice/Android.bp
@@ -46,6 +46,10 @@
         "cts",
         "general-tests",
     ],
+    data: [
+        ":CtsVirtualDeviceStreamedTestApp",
+    ],
+    per_testcase_directory: true,
 }
 
 filegroup {
diff --git a/tests/tests/virtualdevice/src/android/virtualdevice/cts/CreateVirtualDisplayTest.java b/tests/tests/virtualdevice/src/android/virtualdevice/cts/CreateVirtualDisplayTest.java
index 13fe872..dcba1f0 100644
--- a/tests/tests/virtualdevice/src/android/virtualdevice/cts/CreateVirtualDisplayTest.java
+++ b/tests/tests/virtualdevice/src/android/virtualdevice/cts/CreateVirtualDisplayTest.java
@@ -46,7 +46,6 @@
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -116,7 +115,6 @@
                 .isNotEqualTo(0);
     }
 
-    @Ignore("Need allow_always_unlocked_virtual_displays flag to be on by default")
     @Test
     public void createVirtualDisplay_alwaysUnlocked_shouldSpecifyFlagInVirtualDisplays() {
         mVirtualDevice =
diff --git a/tests/tests/voiceRecognition/Android.bp b/tests/tests/voiceRecognition/Android.bp
index 6a6da3f..fbd229c 100644
--- a/tests/tests/voiceRecognition/Android.bp
+++ b/tests/tests/voiceRecognition/Android.bp
@@ -35,4 +35,8 @@
     srcs: ["src/**/*.java"],
     resource_dirs: ["res"],
     sdk_version: "test_current",
+    data: [
+        ":CtsVoiceRecognitionService",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/voiceinteraction/Android.bp b/tests/tests/voiceinteraction/Android.bp
index 8ef6608..b847f7f 100644
--- a/tests/tests/voiceinteraction/Android.bp
+++ b/tests/tests/voiceinteraction/Android.bp
@@ -43,4 +43,10 @@
         "general-tests",
     ],
     sdk_version: "test_current",
+    data: [
+        ":CtsNoRecognitionVoiceInteractionService",
+        ":CtsVoiceInteractionApp",
+        ":CtsVoiceInteractionService",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/voicesettings/Android.bp b/tests/tests/voicesettings/Android.bp
index 341a533..f682207 100644
--- a/tests/tests/voicesettings/Android.bp
+++ b/tests/tests/voicesettings/Android.bp
@@ -34,4 +34,8 @@
         "general-tests",
     ],
     sdk_version: "test_current",
+    data: [
+        ":CtsVoiceSettingsService",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/widget/Android.bp b/tests/tests/widget/Android.bp
index 98290f0..4966f4b 100644
--- a/tests/tests/widget/Android.bp
+++ b/tests/tests/widget/Android.bp
@@ -50,4 +50,10 @@
         "general-tests",
     ],
 
+    data: [
+        ":TestIme",
+        ":CtsMockInputMethod",
+        ":CtsWidgetApp",
+    ],
+    per_testcase_directory: true,
 }
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
index 0a83f24..d83bdb2 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
@@ -1894,6 +1894,12 @@
             for (int i = 0; i < testBandsAndChannels.size(); i++) {
                 TestLocalOnlyHotspotCallback callback = new TestLocalOnlyHotspotCallback(mLock);
                 int testBand = testBandsAndChannels.keyAt(i);
+                // WPA2_PSK is not allowed in 6GHz band. So test with WPA3_SAE which is
+                // mandatory to support in 6GHz band.
+                if (testBand == SoftApConfiguration.BAND_6GHZ) {
+                    customConfigBuilder.setPassphrase(TEST_PASSPHRASE,
+                            SoftApConfiguration.SECURITY_TYPE_WPA3_SAE);
+                }
                 customConfigBuilder.setBand(testBand);
                 mWifiManager.startLocalOnlyHotspot(customConfigBuilder.build(), executor, callback);
                 // now wait for callback
diff --git a/tests/translation/src/android/translation/cts/CtsTestIme.java b/tests/translation/src/android/translation/cts/CtsTestIme.java
index 2588405..c72569d 100644
--- a/tests/translation/src/android/translation/cts/CtsTestIme.java
+++ b/tests/translation/src/android/translation/cts/CtsTestIme.java
@@ -127,7 +127,8 @@
     }
 
     private void notifyCommandDone(Intent sourceIntent, Intent resultIntent) {
-        final PendingIntent pendingIntent = sourceIntent.getParcelableExtra(EXTRA_FINISH_COMMAND);
+        final PendingIntent pendingIntent = sourceIntent.getParcelableExtra(EXTRA_FINISH_COMMAND,
+                PendingIntent.class);
         if (pendingIntent != null) {
             try {
                 final String action = sourceIntent.getAction();
diff --git a/tests/translation/src/android/translation/cts/UiTranslationManagerTest.java b/tests/translation/src/android/translation/cts/UiTranslationManagerTest.java
index 86bc847..85a7712 100644
--- a/tests/translation/src/android/translation/cts/UiTranslationManagerTest.java
+++ b/tests/translation/src/android/translation/cts/UiTranslationManagerTest.java
@@ -79,7 +79,6 @@
 import androidx.test.core.app.ApplicationProvider;
 import androidx.test.filters.FlakyTest;
 import androidx.test.runner.AndroidJUnit4;
-import androidx.test.uiautomator.UiObject2;
 
 import com.android.compatibility.common.util.BlockingBroadcastReceiver;
 import com.android.compatibility.common.util.PollingCheck;
@@ -206,34 +205,38 @@
         UiTranslationStateCallback mockCallback = Mockito.mock(UiTranslationStateCallback.class);
         manager.registerUiTranslationStateCallback(executor, mockCallback);
 
-        final String translatedText = "success";
-        // Set response
-        final TranslationResponse response =
+        try {
+            final String translatedText = "success";
+            // Set response
+            final TranslationResponse response =
                 createViewsTranslationResponse(views, translatedText);
-        sTranslationReplier.addResponse(response);
+            sTranslationReplier.addResponse(response);
 
-        // Start an Activity in the same task then call translation APIs
-        mSimpleActivity.startEmptyActivity();
+            // Start an Activity in the same task then call translation APIs
+            mSimpleActivity.startEmptyActivity();
 
-        startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
+            startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1))
-            .onStarted(any(ULocale.class), any(ULocale.class), any(String.class));
+            assertScreenText(mTextView, translatedText);
 
-        pauseUiTranslation(contentCaptureContext);
+            Mockito.verify(mockCallback, Mockito.times(1))
+                .onStarted(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onPaused(any(String.class));
+            pauseUiTranslation(contentCaptureContext);
 
-        resumeUiTranslation(contentCaptureContext);
+            Mockito.verify(mockCallback, Mockito.times(1)).onPaused(any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.times(1))
-            .onResumed(any(ULocale.class), any(ULocale.class), any(String.class));
+            resumeUiTranslation(contentCaptureContext);
 
-        finishUiTranslation(contentCaptureContext);
+            Mockito.verify(mockCallback, Mockito.times(1))
+                .onResumed(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+            finishUiTranslation(contentCaptureContext);
 
-        manager.unregisterUiTranslationStateCallback(mockCallback);
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+        } finally {
+            manager.unregisterUiTranslationStateCallback(mockCallback);
+        }
     }
 
     @Test
@@ -247,9 +250,6 @@
             final ContentCaptureContext contentCaptureContext = result.second;
 
             final String translatedText = "success";
-            final UiObject2 helloText = Helper.findObjectByResId(Helper.ACTIVITY_PACKAGE,
-                    SimpleActivity.HELLO_TEXT_ID);
-            assertThat(helloText).isNotNull();
             // Set response
             final TranslationResponse response =
                     createViewsTranslationResponse(views, translatedText);
@@ -274,21 +274,21 @@
             assertThat(translationContext.getActivityId())
                     .isEqualTo(contentCaptureContext.getActivityId());
 
-            assertThat(helloText.getText()).isEqualTo(translatedText);
+            assertScreenText(mTextView, translatedText);
             assertThat(mTextView.getViewTranslationResponse())
                     .isEqualTo(response.getViewTranslationResponses().get(0));
 
             pauseUiTranslation(contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(originalText.toString());
+            assertScreenText(mTextView, originalText.toString());
 
             resumeUiTranslation(contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(translatedText);
+            assertScreenText(mTextView, translatedText);
 
             finishUiTranslation(contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(originalText.toString());
+            assertScreenText(mTextView, originalText.toString());
 
             // Check the Translation session is destroyed after calling finishTranslation()
             translationService.awaitSessionDestroyed();
@@ -298,12 +298,12 @@
 
             startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(translatedText);
+            assertScreenText(mTextView, translatedText);
 
             // Also make sure pausing still works.
             pauseUiTranslation(contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(originalText.toString());
+            assertScreenText(mTextView, originalText.toString());
         } catch (Throwable t) {
             Helper.takeScreenshotAndSave(sContext, TestNameUtils.getCurrentTestName(),
                     Helper.LOCAL_TEST_FILES_DIR);
@@ -332,9 +332,6 @@
             final ContentCaptureContext contentCaptureContext = result.second;
 
             final String translatedText = "success";
-            final UiObject2 helloText = Helper.findObjectByResId(Helper.ACTIVITY_PACKAGE,
-                    SimpleActivity.HELLO_TEXT_ID);
-            assertThat(helloText).isNotNull();
             // Set response
             final TranslationResponse response =
                     createViewsTranslationResponse(views, translatedText);
@@ -342,19 +339,19 @@
 
             startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(translatedText);
+            assertScreenText(mTextView, translatedText);
 
             pauseUiTranslation(contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(originalText.toString());
+            assertScreenText(mTextView, originalText.toString());
 
             resumeUiTranslation(contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(translatedText);
+            assertScreenText(mTextView, translatedText);
 
             finishUiTranslation(contentCaptureContext);
 
-            assertThat(helloText.getText()).isEqualTo(originalText.toString());
+            assertScreenText(mTextView, originalText.toString());
         } finally {
             // restore animation
             SystemUtil.runWithShellPermissionIdentity(() -> {
@@ -376,9 +373,6 @@
         final ContentCaptureContext contentCaptureContext = result.second;
 
         final String translatedText = "success";
-        final UiObject2 helloText = Helper.findObjectByResId(Helper.ACTIVITY_PACKAGE,
-                SimpleActivity.HELLO_TEXT_ID);
-        assertThat(helloText).isNotNull();
         // Set response
         final TranslationResponse response =
                 createViewsTranslationResponse(views, translatedText);
@@ -386,17 +380,17 @@
 
         startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
 
-        assertThat(helloText.getText()).isEqualTo(translatedText);
+        assertScreenText(mTextView, translatedText);
 
         pauseUiTranslation(contentCaptureContext);
 
-        assertThat(helloText.getText()).isEqualTo(originalText.toString());
+        assertScreenText(mTextView, originalText.toString());
 
         sTranslationReplier.addResponse(createViewsTranslationResponse(views, translatedText));
 
         startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
 
-        assertThat(helloText.getText()).isEqualTo(translatedText);
+        assertScreenText(mTextView, translatedText);
     }
 
     @Test
@@ -567,9 +561,9 @@
             // Get result to check the onStarted() was called
             Intent onStartIntent = onStartResultReceiver.awaitForBroadcast();
             ULocale receivedSource =
-                    (ULocale) onStartIntent.getSerializableExtra(EXTRA_SOURCE_LOCALE);
+                    onStartIntent.getSerializableExtra(EXTRA_SOURCE_LOCALE, ULocale.class);
             ULocale receivedTarget =
-                    (ULocale) onStartIntent.getSerializableExtra(EXTRA_TARGET_LOCALE);
+                    onStartIntent.getSerializableExtra(EXTRA_TARGET_LOCALE, ULocale.class);
             int startedCallCount = onStartIntent.getIntExtra(EXTRA_CALL_COUNT, -999);
             String startedPackageName = onStartIntent.getStringExtra(EXTRA_PACKAGE_NAME);
             assertThat(receivedSource).isEqualTo(ULocale.ENGLISH);
@@ -644,32 +638,35 @@
         UiTranslationStateCallback mockCallback = Mockito.mock(UiTranslationStateCallback.class);
         manager.registerUiTranslationStateCallback(executor, mockCallback);
 
-        startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
+        try {
+            startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
 
-        // TODO(b/191417938): add tests for the Activity isn't the same package of the
-        //  registered callback app
-        Mockito.verify(mockCallback, Mockito.times(1))
+            // TODO(b/191417938): add tests for the Activity isn't the same package of the
+            //  registered callback app
+            Mockito.verify(mockCallback, Mockito.times(1))
                 .onStarted(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        pauseUiTranslation(contentCaptureContext);
+            pauseUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onPaused(any(String.class));
+            Mockito.verify(mockCallback, Mockito.times(1)).onPaused(any(String.class));
 
-        resumeUiTranslation(contentCaptureContext);
+            resumeUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1))
+            Mockito.verify(mockCallback, Mockito.times(1))
                 .onResumed(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        finishUiTranslation(contentCaptureContext);
+            finishUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
 
-        // Make sure onFinished will not be called twice.
-        mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
-        mActivityScenario = null;
-        SystemClock.sleep(UI_WAIT_TIMEOUT);
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
-
+            // Make sure onFinished will not be called twice.
+            mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
+            mActivityScenario = null;
+            SystemClock.sleep(UI_WAIT_TIMEOUT);
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+        } finally {
+            manager.unregisterUiTranslationStateCallback(mockCallback);
+        }
         // TODO(b/191417938): add a test to verify startUiTranslation + Activity destroyed.
     }
 
@@ -694,28 +691,32 @@
         manager.registerUiTranslationStateCallback(executor, mockCallback);
         SystemClock.sleep(UI_WAIT_TIMEOUT);
 
-        // Callback should receive onStarted.
-        Mockito.verify(mockCallback, Mockito.times(1))
+        try {
+            // Callback should receive onStarted.
+            Mockito.verify(mockCallback, Mockito.times(1))
                 .onStarted(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        pauseUiTranslation(contentCaptureContext);
+            pauseUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onPaused(any(String.class));
+            Mockito.verify(mockCallback, Mockito.times(1)).onPaused(any(String.class));
 
-        resumeUiTranslation(contentCaptureContext);
+            resumeUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1))
+            Mockito.verify(mockCallback, Mockito.times(1))
                 .onResumed(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        finishUiTranslation(contentCaptureContext);
+            finishUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
 
-        // Make sure onFinished will not be called twice.
-        mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
-        mActivityScenario = null;
-        SystemClock.sleep(UI_WAIT_TIMEOUT);
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+            // Make sure onFinished will not be called twice.
+            mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
+            mActivityScenario = null;
+            SystemClock.sleep(UI_WAIT_TIMEOUT);
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+        } finally {
+            manager.unregisterUiTranslationStateCallback(mockCallback);
+        }
     }
 
     @Test
@@ -741,26 +742,30 @@
         manager.registerUiTranslationStateCallback(executor, mockCallback);
         SystemClock.sleep(UI_WAIT_TIMEOUT);
 
-        // Callback should receive onStarted and onPaused events.
-        Mockito.verify(mockCallback, Mockito.times(1))
+        try {
+            // Callback should receive onStarted and onPaused events.
+            Mockito.verify(mockCallback, Mockito.times(1))
                 .onStarted(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onPaused(any(String.class));
+            Mockito.verify(mockCallback, Mockito.times(1)).onPaused(any(String.class));
 
-        resumeUiTranslation(contentCaptureContext);
+            resumeUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1))
+            Mockito.verify(mockCallback, Mockito.times(1))
                 .onResumed(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        finishUiTranslation(contentCaptureContext);
+            finishUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
 
-        // Make sure onFinished will not be called twice.
-        mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
-        mActivityScenario = null;
-        SystemClock.sleep(UI_WAIT_TIMEOUT);
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+            // Make sure onFinished will not be called twice.
+            mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
+            mActivityScenario = null;
+            SystemClock.sleep(UI_WAIT_TIMEOUT);
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+        } finally {
+            manager.unregisterUiTranslationStateCallback(mockCallback);
+        }
     }
 
     @Test
@@ -788,25 +793,29 @@
         manager.registerUiTranslationStateCallback(executor, mockCallback);
         SystemClock.sleep(UI_WAIT_TIMEOUT);
 
-        // Callback should receive onStarted event but NOT an onPaused event, because translation
-        // was already resumed prior to registration.
-        Mockito.verify(mockCallback, Mockito.times(1))
+        try {
+            // Callback should receive onStarted event but NOT an onPaused event, because
+            // translation was already resumed prior to registration.
+            Mockito.verify(mockCallback, Mockito.times(1))
                 .onStarted(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.never()).onPaused(any(String.class));
+            Mockito.verify(mockCallback, Mockito.never()).onPaused(any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.never())
+            Mockito.verify(mockCallback, Mockito.never())
                 .onResumed(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        finishUiTranslation(contentCaptureContext);
+            finishUiTranslation(contentCaptureContext);
 
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
 
-        // Make sure onFinished will not be called twice.
-        mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
-        mActivityScenario = null;
-        SystemClock.sleep(UI_WAIT_TIMEOUT);
-        Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+            // Make sure onFinished will not be called twice.
+            mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
+            mActivityScenario = null;
+            SystemClock.sleep(UI_WAIT_TIMEOUT);
+            Mockito.verify(mockCallback, Mockito.times(1)).onFinished(any(String.class));
+        } finally {
+            manager.unregisterUiTranslationStateCallback(mockCallback);
+        }
     }
 
     @Test
@@ -836,22 +845,26 @@
         manager.registerUiTranslationStateCallback(executor, mockCallback);
         SystemClock.sleep(UI_WAIT_TIMEOUT);
 
-        // Callback should receive no events.
-        Mockito.verify(mockCallback, Mockito.never())
+        try {
+            // Callback should receive no events.
+            Mockito.verify(mockCallback, Mockito.never())
                 .onStarted(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.never()).onPaused(any(String.class));
+            Mockito.verify(mockCallback, Mockito.never()).onPaused(any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.never())
+            Mockito.verify(mockCallback, Mockito.never())
                 .onResumed(any(ULocale.class), any(ULocale.class), any(String.class));
 
-        Mockito.verify(mockCallback, Mockito.never()).onFinished(any(String.class));
+            Mockito.verify(mockCallback, Mockito.never()).onFinished(any(String.class));
 
-        // Make sure onFinished will not be called at all.
-        mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
-        mActivityScenario = null;
-        SystemClock.sleep(UI_WAIT_TIMEOUT);
-        Mockito.verify(mockCallback, Mockito.never()).onFinished(any(String.class));
+            // Make sure onFinished will not be called at all.
+            mActivityScenario.moveToState(Lifecycle.State.DESTROYED);
+            mActivityScenario = null;
+            SystemClock.sleep(UI_WAIT_TIMEOUT);
+            Mockito.verify(mockCallback, Mockito.never()).onFinished(any(String.class));
+        } finally {
+            manager.unregisterUiTranslationStateCallback(mockCallback);
+        }
     }
 
     @Test
@@ -1126,11 +1139,7 @@
             startUiTranslation(/* shouldPadContent */ false, views, contentCaptureContext);
 
             // Verify result. Translation response doesn't set, it should show original text
-            assertThat(mResponseNotSetTextView.getSavedResponse()).isNotNull();
-            final UiObject2 responseNotSetText = Helper.findObjectByResId(Helper.ACTIVITY_PACKAGE,
-                    CustomTextViewActivity.ID_RESPONSE_NOT_SET_TEXT);
-            assertThat(responseNotSetText).isNotNull();
-            assertThat(responseNotSetText.getText()).isEqualTo("Hello World 1");
+            assertScreenText(mResponseNotSetTextView, "Hello World 1");
         } catch (Throwable t) {
             Helper.takeScreenshotAndSave(sContext, TestNameUtils.getCurrentTestName(),
                     Helper.LOCAL_TEST_FILES_DIR);
@@ -1165,14 +1174,11 @@
 
             // Verify result.
             assertThat(mCustomTextView.isMyTagTranslationSupported()).isTrue();
-            final UiObject2 customText = Helper.findObjectByResId(Helper.ACTIVITY_PACKAGE,
-                    CustomTextViewActivity.ID_CUSTOM_TEXT);
-            assertThat(customText).isNotNull();
-            assertThat(customText.getText()).isEqualTo(translatedText);
+            assertScreenText(mCustomTextView, translatedText);
 
             finishUiTranslation(contentCaptureContext);
 
-            assertThat(customText.getText()).isEqualTo("Hello World 2");
+            assertScreenText(mCustomTextView, "Hello World 2");
         } catch (Throwable t) {
             Helper.takeScreenshotAndSave(sContext, TestNameUtils.getCurrentTestName(),
                     Helper.LOCAL_TEST_FILES_DIR);
@@ -1180,6 +1186,12 @@
         }
     }
 
+
+    private void assertScreenText(TextView textView, String expected) {
+        String screenText = textView.getLayout().getText().toString();
+        assertThat(screenText).isEqualTo(expected);
+    }
+
     private void startUiTranslation(boolean shouldPadContent, List<AutofillId> views,
             ContentCaptureContext contentCaptureContext) {
         startUiTranslation(shouldPadContent, views, contentCaptureContext, ULocale.ENGLISH,
diff --git a/tools/cts-tradefed/Android.bp b/tools/cts-tradefed/Android.bp
index dee557e..a335da1 100644
--- a/tools/cts-tradefed/Android.bp
+++ b/tools/cts-tradefed/Android.bp
@@ -34,7 +34,7 @@
     wrapper: "etc/cts-tradefed",
     short_name: "CTS",
     full_name: "Compatibility Test Suite",
-    version: "12.1_r1",
+    version: "13_r1",
     static_libs: ["cts-tradefed-harness"],
     required: ["compatibility-host-util"],
 }