Run media session related tests with bedstead

This change fixes the failures reported
by below bugs by exempting certain test methods that
can't succeed when run with a user of type
`profile.MANAGED` because such users aren't a full
user.

Running the tests with bedstead and annotate them
to run for certain users makes sure these test are run
for these users when run with 'atest'. Before this change
the tests where run only for the owner.

Bug: 376412792
Bug: 378817823
Bug: 378520643
Bug: 378781441
Bug: 354813096
Flag: TEST_ONLY
Test: Part of CTS media tests
Change-Id: I650a6954423e972cf31023982f43c2572b0952fa
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaActivityTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaActivityTest.java
index 7de46f9..f194fef 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaActivityTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaActivityTest.java
@@ -39,10 +39,12 @@
 import android.view.KeyEvent;
 
 import androidx.test.core.app.ActivityScenario;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.LargeTest;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 import com.android.compatibility.common.util.FrameworkSpecificTest;
 import com.android.compatibility.common.util.SystemUtil;
 
@@ -59,12 +61,10 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-/**
- * Test {@link MediaSessionTestActivity} which has called {@link Activity#setMediaController}.
- */
+/** Test {@link MediaSessionTestActivity} which has called {@link Activity#setMediaController}. */
 @FrameworkSpecificTest
 @LargeTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(BedsteadJUnit4.class)
 public class MediaActivityTest {
     private static final String TAG = "MediaActivityTest";
     private static final int WAIT_TIME_MS = 5000;
@@ -182,10 +182,9 @@
         }
     }
 
-    /**
-     * Tests whether volume key changes volume with the session's stream.
-     */
+    /** Tests whether volume key changes volume with the session's stream. */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testVolumeKey_whileSessionAlive() throws Exception {
         assumeTrue(/* message= */ "Test skipped on automotive target",
                 !isAutomotive());
@@ -214,10 +213,11 @@
     }
 
     /**
-     * Tests whether volume key changes a stream volume even after the session is released,
-     * without being ignored.
+     * Tests whether volume key changes a stream volume even after the session is released, without
+     * being ignored.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testVolumeKey_afterSessionReleased() throws Exception {
         assumeTrue(/* message= */ "Test skipped on automotive target",
                 !isAutomotive());
@@ -247,6 +247,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testMediaKey_whileSessionAlive() throws Exception {
         int testKeyEvent = KeyEvent.KEYCODE_MEDIA_PLAY;
 
@@ -269,6 +270,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testMediaKey_whileSessionReleased() throws Exception {
         int testKeyEvent = KeyEvent.KEYCODE_MEDIA_PLAY;
 
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaBrowserServiceTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaBrowserServiceTest.java
index a1ac438..2868f97 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaBrowserServiceTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaBrowserServiceTest.java
@@ -52,9 +52,11 @@
 import android.service.media.MediaBrowserService.BrowserRoot;
 
 import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 import com.android.compatibility.common.util.FrameworkSpecificTest;
 import com.android.media.flags.Flags;
 
@@ -70,11 +72,9 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-/**
- * Test {@link android.service.media.MediaBrowserService}.
- */
+/** Test {@link android.service.media.MediaBrowserService}. */
 @FrameworkSpecificTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(BedsteadJUnit4.class)
 @AppModeNonSdkSandbox(reason = "SDK sandbox does not need MediaBrowser.")
 public class MediaBrowserServiceTest {
 
@@ -176,12 +176,14 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetSessionToken() {
         assertThat(mMediaBrowserService.getSessionToken())
                 .isEqualTo(StubMediaBrowserService.sSession.getSessionToken());
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testNotifyChildrenChanged() throws Exception {
         getInstrumentation().runOnMainSync(()-> {
             mMediaBrowser.subscribe(StubMediaBrowserService.MEDIA_ID_ROOT, mSubscriptionCallback);
@@ -194,6 +196,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testNotifyChildrenChangedWithNullOptionsThrowsIAE() {
         assertThrows(IllegalArgumentException.class,
                 () -> mMediaBrowserService.notifyChildrenChanged(
@@ -201,6 +204,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testNotifyChildrenChangedWithPagination() {
         final int pageSize = 5;
         final int page = 2;
@@ -240,6 +244,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testDelayedNotifyChildrenChanged() throws Exception {
         getInstrumentation().runOnMainSync(()-> {
             mMediaBrowser.subscribe(StubMediaBrowserService.MEDIA_ID_CHILDREN_DELAYED,
@@ -260,6 +265,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testDelayedItem() throws Exception {
         getInstrumentation().runOnMainSync(()-> {
             mMediaBrowser.getItem(StubMediaBrowserService.MEDIA_ID_CHILDREN_DELAYED,
@@ -272,6 +278,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetBrowserInfo() throws Exception {
         // StubMediaBrowserService stores the browser info in its onGetRoot().
         assertThat(compareRemoteUserInfo(mBrowserInfo, StubMediaBrowserService.sBrowserInfo))
@@ -295,6 +302,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBrowserRoot() {
         final String id = "test-id";
         final String key = "test-key";
@@ -312,6 +320,7 @@
      * {@link MediaBrowser} on the remote process due to binder buffer overflow.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSeriesOfNotifyChildrenChanged() throws Exception {
         String parentMediaId = "testSeriesOfNotifyChildrenChanged";
         int numberOfCalls = 100;
@@ -345,6 +354,7 @@
 
     @RequiresFlagsEnabled(Flags.FLAG_ENABLE_NULL_SESSION_IN_MEDIA_BROWSER_SERVICE)
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetNullSessionToken() {
         MediaBrowserCallbackImpl browserCallback = new MediaBrowserCallbackImpl();
         ComponentName componentName = new ComponentName(mContext, SimpleMediaBrowserService.class);
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaBrowserTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaBrowserTest.java
index 75dc238..51e32b1 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaBrowserTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaBrowserTest.java
@@ -27,9 +27,11 @@
 import android.os.Bundle;
 import android.platform.test.annotations.AppModeNonSdkSandbox;
 
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 import com.android.compatibility.common.util.FrameworkSpecificTest;
 import com.android.compatibility.common.util.PollingCheck;
 
@@ -45,11 +47,9 @@
 import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
 
-/**
- * Test {@link android.media.browse.MediaBrowser}.
- */
+/** Test {@link android.media.browse.MediaBrowser}. */
 @FrameworkSpecificTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(BedsteadJUnit4.class)
 @AppModeNonSdkSandbox(reason = "SDK sandbox does not need MediaBrowser.")
 public class MediaBrowserTest {
     // The maximum time to wait for an operation.
@@ -133,6 +133,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testThrowingISEWhileNotConnected() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -154,6 +155,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testConnectTwice() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -165,6 +167,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testConnectionFailed() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_INVALID_BROWSER_SERVICE);
@@ -182,6 +185,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testReconnection() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
 
@@ -233,6 +237,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testConnectionCallbackNotCalledAfterDisconnect() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
         runOnMainThread(() -> {
@@ -255,6 +260,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSubscribe() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -296,6 +302,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSubscribeWithIllegalArguments() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
 
@@ -324,6 +331,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSubscribeWithOptions() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
         connectMediaBrowserService();
@@ -383,6 +391,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSubscribeInvalidItem() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -401,6 +410,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSubscribeInvalidItemWithOptions() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -430,6 +440,7 @@
 
     @Ignore // TODO(b/291800179): Diagnose flakiness and re-enable.
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSubscriptionCallbackNotCalledAfterDisconnect() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
         connectMediaBrowserService();
@@ -451,6 +462,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testUnsubscribeWithIllegalArguments() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
         runOnMainThread(() -> {
@@ -472,6 +484,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testUnsubscribeForMultipleSubscriptions() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
         connectMediaBrowserService();
@@ -520,6 +533,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testUnsubscribeWithSubscriptionCallbackForMultipleSubscriptions() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
         connectMediaBrowserService();
@@ -586,6 +600,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetItem() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -605,6 +620,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetItemThrowsIAE() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -628,6 +644,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetItemWhileNotConnected() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -648,6 +665,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetItemFailure() throws Throwable {
         resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
@@ -666,6 +684,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testItemCallbackNotCalledAfterDisconnect() throws Throwable {
         createMediaBrowser(TEST_BROWSER_SERVICE);
         connectMediaBrowserService();
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaCommunicationManagerTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaCommunicationManagerTest.java
index e72604f..d8b1c79 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaCommunicationManagerTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaCommunicationManagerTest.java
@@ -32,7 +32,10 @@
 import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.SdkSuppress;
 import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
+
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 
 import com.google.common.base.Objects;
 
@@ -49,10 +52,8 @@
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
-/**
- * Tests {@link android.media.MediaCommunicationManager}.
- */
-@RunWith(AndroidJUnit4.class)
+/** Tests {@link android.media.MediaCommunicationManager}. */
+@RunWith(BedsteadJUnit4.class)
 @SmallTest
 @SdkSuppress(minSdkVersion = 31, codeName = "S")
 public class MediaCommunicationManagerTest {
@@ -75,12 +76,14 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetVersion() {
         assertNotNull("Missing MediaCommunicationManager", mManager);
         assertTrue(mManager.getVersion() > 0);
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetSession2Tokens() throws Exception {
         // registerSessionCallback requires permission MEDIA_CONTENT_CONTROL
         InstrumentationRegistry.getInstrumentation()
@@ -109,6 +112,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void registerSessionCallback_noMediaContentControlPermission_throwsSecurityException()
             throws Exception {
         Executor executor = Executors.newSingleThreadExecutor();
@@ -122,6 +126,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER}) // SystemApi. Requires full user. Don't run for work profile.
     public void testManagerSessionCallback() throws Exception {
         // registerSessionCallback requires permission MEDIA_CONTENT_CONTROL
         InstrumentationRegistry.getInstrumentation()
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaController2Test.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaController2Test.java
index 8a21b1c..2c6ef91 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaController2Test.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaController2Test.java
@@ -34,10 +34,13 @@
 import android.os.HandlerThread;
 import android.os.Process;
 
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.SmallTest;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
+
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -52,10 +55,8 @@
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 
-/**
- * Tests {@link android.media.MediaController2}.
- */
-@RunWith(AndroidJUnit4.class)
+/** Tests {@link android.media.MediaController2}. */
+@RunWith(BedsteadJUnit4.class)
 @SmallTest
 public class MediaController2Test {
     private static final long WAIT_TIME_MS = 100L;
@@ -145,6 +146,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_withIllegalArguments() {
         final Session2Token token = new Session2Token(
                 mContext, new ComponentName(mContext, this.getClass()));
@@ -179,6 +181,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_setConnectionHints_withFrameworkParcelable() throws Exception {
         final List<MediaSession2.ControllerInfo> controllerInfoList = new ArrayList<>();
         final CountDownLatch latch = new CountDownLatch(1);
@@ -218,6 +221,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_setConnectionHints_withCustomParcelable() {
         final Session2Token token = new Session2Token(
                 mContext, new ComponentName(mContext, this.getClass()));
@@ -236,6 +240,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCreatingControllerWithoutCallback() throws Exception {
         try (MediaController2 controller =
                      new MediaController2.Builder(mContext, mSession.getToken()).build()) {
@@ -247,6 +252,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetConnectedToken() {
         Controller2Callback controllerCallback = new Controller2Callback();
         try (MediaController2 controller =
@@ -269,6 +275,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallback_onConnected_onDisconnected() {
         Controller2Callback controllerCallback = new Controller2Callback();
         try (MediaController2 controller =
@@ -285,6 +292,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallback_onSessionCommand() {
         Controller2Callback controllerCallback = new Controller2Callback();
         try (MediaController2 controller =
@@ -321,6 +329,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallback_onCommandResult() {
         Controller2Callback controllerCallback = new Controller2Callback();
         try (MediaController2 controller =
@@ -355,6 +364,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCancelSessionCommand() {
         Controller2Callback controllerCallback = new Controller2Callback();
         try (MediaController2 controller =
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaControllerTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaControllerTest.java
index 946fed9..c69b487 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaControllerTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaControllerTest.java
@@ -42,9 +42,11 @@
 import android.os.ResultReceiver;
 import android.view.KeyEvent;
 
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 import com.android.compatibility.common.util.FrameworkSpecificTest;
 
 import org.junit.After;
@@ -52,11 +54,9 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-/**
- * Test {@link android.media.session.MediaController}.
- */
+/** Test {@link android.media.session.MediaController}. */
 @FrameworkSpecificTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(BedsteadJUnit4.class)
 public class MediaControllerTest {
     // The maximum time to wait for an operation.
     private static final long TIME_OUT_MS = 3000L;
@@ -96,12 +96,14 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetPackageName() {
         assertThat(mController.getPackageName())
                 .isEqualTo(getContext().getPackageName());
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetPlaybackState() {
         final int testState = STATE_PLAYING;
         final long testPosition = 100000L;
@@ -143,6 +145,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetRatingType() {
         assertWithMessage("Default rating type of a session must be Rating.RATING_NONE")
                 .that(mController.getRatingType())
@@ -154,11 +157,13 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetSessionToken() {
         assertThat(mController.getSessionToken()).isEqualTo(mSession.getSessionToken());
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetSessionInfo() {
         Bundle sessionInfo = mController.getSessionInfo();
         assertThat(sessionInfo).isNotNull();
@@ -169,6 +174,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetSessionInfoReturnsAnEmptyBundleWhenNotSet() {
         MediaSession session = new MediaSession(getContext(), "test_tag", /*sessionInfo=*/ null);
         try {
@@ -179,11 +185,13 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetTag() {
         assertThat(mController.getTag()).isEqualTo(SESSION_TAG);
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSendCommand() throws Exception {
         synchronized (mWaitLock) {
             mCallback.reset();
@@ -201,6 +209,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSendCommandWithIllegalArgumentsThrowsIAE() {
         Bundle args = new Bundle();
         ResultReceiver resultReceiver = new ResultReceiver(mHandler);
@@ -213,6 +222,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetPlaybackSpeed() throws Exception {
         synchronized (mWaitLock) {
             mCallback.reset();
@@ -228,12 +238,14 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testAdjustVolumeWithIllegalDirection() {
         // Call the method with illegal direction. System should not reboot.
         mController.adjustVolume(37, 0);
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testVolumeControl() throws Exception {
         VolumeProvider vp = new VolumeProvider(VolumeProvider.VOLUME_CONTROL_ABSOLUTE, 11, 5) {
             @Override
@@ -279,6 +291,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testTransportControlsAndMediaSessionCallback() throws Exception {
         MediaController.TransportControls controls = mController.getTransportControls();
         final MediaSession.Callback callback = (MediaSession.Callback) mCallback;
@@ -476,6 +489,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testRegisterCallbackWithNullThrowsIAE() {
         assertThrows(IllegalArgumentException.class,
                 () -> mController.registerCallback(/*handler=*/ null));
@@ -485,6 +499,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testRegisteringSameCallbackWithDifferentHandlerHasNoEffect() {
         MediaController.Callback callback = new MediaController.Callback() {};
         mController.registerCallback(callback, mHandler);
@@ -508,12 +523,14 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testUnregisterCallbackWithNull() {
         assertThrows(IllegalArgumentException.class,
                 () -> mController.unregisterCallback(/*handler=*/ null));
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testUnregisterCallbackShouldRemoveCallback() {
         MediaController.Callback callback = new MediaController.Callback() {};
         mController.registerCallback(callback, mHandler);
@@ -525,18 +542,21 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testDispatchMediaButtonEventWithNullKeyEvent() {
         assertThrows(IllegalArgumentException.class,
                 () -> mController.dispatchMediaButtonEvent(/*keyEvent=*/ null));
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testDispatchMediaButtonEventWithNonMediaKeyEventReturnsFalse() {
         KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_CAPS_LOCK);
         assertThat(mController.dispatchMediaButtonEvent(keyEvent)).isFalse();
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testPlaybackInfoCreatorNewArray() {
         final int arrayLength = 5;
         MediaController.PlaybackInfo[] playbackInfoArrayInitializedWithNulls =
@@ -549,6 +569,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testTransportControlsPlayAndPrepareFromMediaIdWithIllegalArgumentsThrowsIAE() {
         MediaController.TransportControls transportControls = mController.getTransportControls();
 
@@ -569,6 +590,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testTransportControlsPlayAndPrepareFromUriWithIllegalArgumentsThrowsIAE() {
         MediaController.TransportControls transportControls = mController.getTransportControls();
 
@@ -586,6 +608,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testTransportControlsPlayAndPrepareFromSearchWithNullDoesNotCrash()
             throws Exception {
         MediaController.TransportControls transportControls = mController.getTransportControls();
@@ -603,6 +626,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSendCustomActionWithIllegalArgumentsThrowsIAE() {
         MediaController.TransportControls transportControls = mController.getTransportControls();
 
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaItemTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaItemTest.java
index 53b159a..ffbe33a 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaItemTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaItemTest.java
@@ -21,18 +21,17 @@
 import android.media.browse.MediaBrowser.MediaItem;
 import android.os.Parcel;
 
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 import com.android.compatibility.common.util.FrameworkSpecificTest;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-/**
- * Test {@link android.media.browse.MediaBrowser.MediaItem}.
- */
+/** Test {@link android.media.browse.MediaBrowser.MediaItem}. */
 @FrameworkSpecificTest
-@RunWith(AndroidJUnit4.class)
+@RunWith(BedsteadJUnit4.class)
 public class MediaItemTest {
     private static final String DESCRIPTION = "test_description";
     private static final String MEDIA_ID = "test_media_id";
@@ -71,6 +70,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testPlayableMediaItem() {
         MediaDescription description = new MediaDescription.Builder()
                 .setDescription(DESCRIPTION).setMediaId(MEDIA_ID)
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaMetadataTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaMetadataTest.java
index af6d3bc..5a06931 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaMetadataTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaMetadataTest.java
@@ -29,6 +29,8 @@
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.SmallTest;
 
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 import com.android.compatibility.common.util.FrameworkSpecificTest;
 
 import org.junit.Test;
@@ -45,6 +47,7 @@
 public class MediaMetadataTest {
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_defaultConstructor_hasNoData() {
         MediaMetadata metadata = new MediaMetadata.Builder().build();
 
@@ -53,6 +56,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putText() {
         String testTitle = "test_title";
         MediaMetadata metadata = new MediaMetadata.Builder()
@@ -65,6 +69,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putString() {
         String testTitle = "test_title";
         MediaMetadata metadata = new MediaMetadata.Builder()
@@ -77,6 +82,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putLong() {
         long testYear = 2021;
         MediaMetadata metadata = new MediaMetadata.Builder()
@@ -89,6 +95,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putRating() {
         Rating testHeartRating = Rating.newHeartRating(/*hasHeart=*/ true);
         MediaMetadata metadata = new MediaMetadata.Builder()
@@ -101,6 +108,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putText_throwsIAE_withNonTextKey() {
         MediaMetadata.Builder builder = new MediaMetadata.Builder();
 
@@ -109,6 +117,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putString_throwsIAE_withNonTextKey() {
         MediaMetadata.Builder builder = new MediaMetadata.Builder();
 
@@ -117,6 +126,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putLong_throwsIAE_withNonLongKey() {
         MediaMetadata.Builder builder = new MediaMetadata.Builder();
 
@@ -125,6 +135,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putRating_throwsIAE_withNonRatingKey() {
         Rating testHeartRating = Rating.newHeartRating(/*hasHeart=*/ true);
         MediaMetadata.Builder builder = new MediaMetadata.Builder();
@@ -134,6 +145,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_putBitmap_throwsIAE_withNonBitmapKey() {
         Bitmap testBitmap = Bitmap.createBitmap(/*width=*/ 16, /*height=*/16,
                 Bitmap.Config.ARGB_8888);
@@ -144,6 +156,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_copyConstructor() {
         long testYear = 2021;
         MediaMetadata originalMetadata = new MediaMetadata.Builder()
@@ -155,6 +168,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void equalsAndHashCode() {
         String testTitle = "test_title";
         long testYear = 2021;
@@ -172,6 +186,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void equalsAndHashCode_ignoreRatingAndBitmap() {
         Rating testHeartRating = Rating.newHeartRating(/*hasHeart=*/ true);
         Bitmap testBitmap = Bitmap.createBitmap(/*width=*/ 16, /*height=*/16,
@@ -187,6 +202,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void sizeAndKeySet() {
         Rating testHeartRating = Rating.newHeartRating(/*hasHeart=*/ true);
         Bitmap testBitmap = Bitmap.createBitmap(/*width=*/ 16, /*height=*/16,
@@ -203,6 +219,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void describeContents() {
         long testYear = 2021;
         MediaMetadata metadata = new MediaMetadata.Builder()
@@ -213,6 +230,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void writeToParcel() {
         String testTitle = "test_title";
         long testYear = 2021;
@@ -231,6 +249,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void getDescription() {
         String testMediaId = "media_id";
         String testTitle = "test_title";
@@ -259,12 +278,14 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void getBitmapDimensionLimit_returnsIntegerMaxWhenNotSet() {
         MediaMetadata metadata = new MediaMetadata.Builder().build();
         assertThat(metadata.getBitmapDimensionLimit()).isEqualTo(Integer.MAX_VALUE);
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_setBitmapDimensionLimit_bitmapsAreScaledDown() {
         // A large bitmap (64MB).
         final int originalWidth = 4096;
@@ -287,6 +308,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_setBitmapDimensionLimit_bitmapsAreNotScaledDown() {
         // A small bitmap.
         final int originalWidth = 16;
@@ -310,6 +332,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void builder_setMaxBitmapDimensionLimit_unsetLimit() {
         final int testBitmapDimensionLimit = 256;
         MediaMetadata metadata = new MediaMetadata.Builder()
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSession2ServiceTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSession2ServiceTest.java
index 7d85a22..769f32a 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSession2ServiceTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSession2ServiceTest.java
@@ -35,10 +35,13 @@
 import android.platform.test.annotations.AppModeNonSdkSandbox;
 
 import androidx.annotation.NonNull;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.SmallTest;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
+
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -51,10 +54,8 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-/**
- * Tests {@link MediaSession2Service}.
- */
-@RunWith(AndroidJUnit4.class)
+/** Tests {@link MediaSession2Service}. */
+@RunWith(BedsteadJUnit4.class)
 @SmallTest
 @AppModeNonSdkSandbox(reason = "MediaSession2Service use is restricted to the sandbox.")
 public class MediaSession2ServiceTest {
@@ -109,10 +110,11 @@
     }
 
     /**
-     * Tests whether {@link MediaSession2Service#onGetSession(ControllerInfo)}
-     * is called when controller tries to connect, with the proper arguments.
+     * Tests whether {@link MediaSession2Service#onGetSession(ControllerInfo)} is called when
+     * controller tries to connect, with the proper arguments.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testOnGetSessionIsCalled() throws InterruptedException {
         final List<ControllerInfo> controllerInfoList = new ArrayList<>();
         final CountDownLatch latch = new CountDownLatch(1);
@@ -142,12 +144,13 @@
     }
 
     /**
-     * Tests whether the controller is connected to the session which is returned from
-     * {@link MediaSession2Service#onGetSession(ControllerInfo)}.
-     * Also checks whether the connection hints are properly passed to
-     * {@link MediaSession2.SessionCallback#onConnect(MediaSession2, ControllerInfo)}.
+     * Tests whether the controller is connected to the session which is returned from {@link
+     * MediaSession2Service#onGetSession(ControllerInfo)}. Also checks whether the connection hints
+     * are properly passed to {@link MediaSession2.SessionCallback#onConnect(MediaSession2,
+     * ControllerInfo)}.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testOnGetSession_returnsSession() throws InterruptedException {
         final List<ControllerInfo> controllerInfoList = new ArrayList<>();
         final CountDownLatch latch = new CountDownLatch(2);
@@ -208,10 +211,11 @@
     }
 
     /**
-     * Tests whether {@link MediaSession2Service#onGetSession(ControllerInfo)}
-     * can return different sessions for different controllers.
+     * Tests whether {@link MediaSession2Service#onGetSession(ControllerInfo)} can return different
+     * sessions for different controllers.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testOnGetSession_returnsDifferentSessions() throws InterruptedException {
         final List<Session2Token> tokens = new ArrayList<>();
         StubMediaSession2Service.setTestInjector(new StubMediaSession2Service.TestInjector() {
@@ -237,10 +241,11 @@
     }
 
     /**
-     * Tests whether {@link MediaSession2Service#onGetSession(ControllerInfo)}
-     * can reject incoming connection by returning null.
+     * Tests whether {@link MediaSession2Service#onGetSession(ControllerInfo)} can reject incoming
+     * connection by returning null.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testOnGetSession_rejectsConnection() throws InterruptedException {
         StubMediaSession2Service.setTestInjector(new StubMediaSession2Service.TestInjector() {
             @Override
@@ -264,6 +269,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testAllControllersDisconnected_oneSession() throws InterruptedException {
         final CountDownLatch latch = new CountDownLatch(1);
         final MediaSession2 testSession =
@@ -292,6 +298,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testAllControllersDisconnected_multipleSessions() throws InterruptedException {
         final CountDownLatch latch = new CountDownLatch(1);
         StubMediaSession2Service.setTestInjector(new StubMediaSession2Service.TestInjector() {
@@ -319,6 +326,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetSessions() throws InterruptedException {
         MediaController2 controller = createConnectedController(mToken);
         MediaSession2Service service = StubMediaSession2Service.getInstance();
@@ -338,6 +346,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testAddSessions_removedWhenClose() throws InterruptedException {
         MediaController2 controller = createConnectedController(mToken);
         MediaSession2Service service = StubMediaSession2Service.getInstance();
@@ -357,6 +366,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testOnUpdateNotification() throws InterruptedException {
         MediaController2 controller = createConnectedController(mToken);
         MediaSession2Service service = StubMediaSession2Service.getInstance();
@@ -392,6 +402,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testOnBind() throws Exception {
         MediaController2 controller1 = createConnectedController(mToken);
         MediaSession2Service service = StubMediaSession2Service.getInstance();
@@ -404,6 +415,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testMediaNotification() {
         final int testId = 1001;
         final String testChannelId = "channelId";
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSession2Test.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSession2Test.java
index e9c4fea..1e32e49 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSession2Test.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSession2Test.java
@@ -40,10 +40,13 @@
 import android.os.Parcelable;
 import android.os.Process;
 
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.SmallTest;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
+
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -56,10 +59,8 @@
 import java.util.concurrent.Executor;
 import java.util.concurrent.TimeUnit;
 
-/**
- * Tests {@link android.media.MediaSession2}.
- */
-@RunWith(AndroidJUnit4.class)
+/** Tests {@link android.media.MediaSession2}. */
+@RunWith(BedsteadJUnit4.class)
 @SmallTest
 public class MediaSession2Test {
     private static final long WAIT_TIME_MS = 300L;
@@ -116,6 +117,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_setIllegalArguments() {
         assertThrows("null context shouldn't be allowed",
                 IllegalArgumentException.class,
@@ -129,6 +131,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_setSessionActivity() {
         Intent intent = new Intent(Intent.ACTION_MAIN);
         PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0 /* requestCode */,
@@ -142,6 +145,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_createSessionWithoutId() {
         try (MediaSession2 session = new MediaSession2.Builder(mContext).build()) {
             assertThat(session.getId()).isEqualTo("");
@@ -149,6 +153,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_createSessionWithDupId() {
         final String dupSessionId = "TEST_SESSION_DUP_ID";
         MediaSession2.Builder builder = new MediaSession2.Builder(mContext).setId(dupSessionId);
@@ -160,6 +165,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_setExtras_withFrameworkParcelable() {
         final String testKey = "test_key";
         final Session2Token frameworkParcelable = new Session2Token(mContext,
@@ -179,6 +185,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder_setExtras_withCustomParcelable() {
         final String testKey = "test_key";
         final CustomParcelable customParcelable = new CustomParcelable(1);
@@ -194,6 +201,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSession2Token() {
         final Bundle extras = new Bundle();
         try (MediaSession2 session = new MediaSession2.Builder(mContext)
@@ -210,6 +218,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSession2Token_extrasNotSet() {
         try (MediaSession2 session = new MediaSession2.Builder(mContext)
                 .build()) {
@@ -219,6 +228,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetConnectedControllers_newController() throws Exception {
         Session2Callback sessionCallback = new Session2Callback();
         try (MediaSession2 session = new MediaSession2.Builder(mContext)
@@ -245,6 +255,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetConnectedControllers_closedController() throws Exception {
         Session2Callback sessionCallback = new Session2Callback();
         try (MediaSession2 session = new MediaSession2.Builder(mContext)
@@ -265,6 +276,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSession2Token_writeToParcel() {
         final Bundle extras = new Bundle();
         extras.putString(TEST_KEY, TEST_VALUE);
@@ -292,6 +304,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBroadcastSessionCommand() throws Exception {
         Session2Callback sessionCallback = new Session2Callback();
 
@@ -354,6 +367,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallback_onConnect_onDisconnect() throws Exception {
         Session2Callback sessionCallback = new Session2Callback();
         try (MediaSession2 session = new MediaSession2.Builder(mContext)
@@ -393,6 +407,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallback_onPostConnect_connected() throws Exception {
         Session2Callback sessionCallback = new Session2Callback();
         try (MediaSession2 session = new MediaSession2.Builder(mContext)
@@ -410,6 +425,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallback_onPostConnect_rejected() throws Exception {
         Session2Callback sessionCallback = new Session2Callback() {
             @Override
@@ -433,6 +449,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallback_onSessionCommand() {
         Session2Callback sessionCallback = new Session2Callback();
 
@@ -478,6 +495,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallback_onCommandResult() {
         Session2Callback sessionCallback = new Session2Callback();
 
@@ -533,6 +551,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetPlaybackActive() {
         final boolean testInitialPlaybackActive = true;
         final boolean testPlaybackActive = false;
@@ -569,6 +588,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCancelSessionCommand() {
         Session2Callback sessionCallback = new Session2Callback();
         try (MediaSession2 session = new MediaSession2.Builder(mContext)
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionManagerTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionManagerTest.java
index ea20325..40a3bf2 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionManagerTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionManagerTest.java
@@ -46,10 +46,11 @@
 import android.text.TextUtils;
 import android.view.KeyEvent;
 
-import androidx.test.annotation.UiThreadTest;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 import com.android.compatibility.common.util.ApiLevelUtil;
 import com.android.compatibility.common.util.FrameworkSpecificTest;
 import com.android.compatibility.common.util.SystemUtil;
@@ -71,7 +72,7 @@
 import java.util.concurrent.TimeUnit;
 
 @AppModeFull(reason = "TODO: evaluate and port to instant")
-@RunWith(AndroidJUnit4.class)
+@RunWith(BedsteadJUnit4.class)
 public class MediaSessionManagerTest {
     private static final String TAG = "MediaSessionManagerTest";
     private static final int TIMEOUT_MS = 3000;
@@ -107,6 +108,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetActiveSessions() throws Exception {
         assertThrows("Expected security exception for unauthorized call to getActiveSessions",
                 SecurityException.class,
@@ -116,6 +118,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetMediaKeyEventSession_throwsSecurityException() {
         assertThrows("Expected security exception for call to getMediaKeyEventSession",
                 SecurityException.class,
@@ -124,6 +127,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetMediaKeyEventSessionPackageName_throwsSecurityException() {
         assertThrows("Expected security exception for call to getMediaKeyEventSessionPackageName",
                 SecurityException.class,
@@ -132,6 +136,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER}) // Requires a full user. Don't run for work profile.
     public void testOnMediaKeyEventSessionChangedListener() throws Exception {
         getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(
                 Manifest.permission.MEDIA_CONTENT_CONTROL,
@@ -162,6 +167,7 @@
     @Ignore // TODO(b/291800179): Diagnose flakiness and re-enable.
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER}) // Requires a full user. Don't run for work profile.
     public void testOnMediaKeyEventSessionChangedListener_whenSessionIsReleased() throws Exception {
         getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(
                 Manifest.permission.MEDIA_CONTENT_CONTROL,
@@ -189,6 +195,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER}) // Requires a full user. Don't run for work profile.
     public void testOnMediaKeyEventSessionChangedListener_noSession_passesEmptyPackageAndNullToken()
             throws InterruptedException {
         getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(
@@ -223,6 +230,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testOnMediaKeyEventSessionChangedListener_noPermission_throwsSecurityException() {
         MediaKeyEventSessionListener keyEventSessionListener = new MediaKeyEventSessionListener();
         assertThrows(
@@ -236,6 +244,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER}) // Requires a full user. Don't run for work profile.
     public void testOnMediaKeyEventDispatchedListener() throws Exception {
         getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(
                 Manifest.permission.MEDIA_CONTENT_CONTROL,
@@ -277,21 +286,6 @@
                 .await(WAIT_MS, TimeUnit.MILLISECONDS)).isFalse();
     }
 
-    @Test
-    @UiThreadTest
-    @FrameworkSpecificTest
-    public void testAddOnActiveSessionsListener() throws Exception {
-        assertThrows("Expected NPE for call to addOnActiveSessionsChangedListener",
-                NullPointerException.class,
-                () -> mSessionManager.addOnActiveSessionsChangedListener(null, null));
-
-        MediaSessionManager.OnActiveSessionsChangedListener listener = controllers -> {};
-
-        assertThrows("Expected security exception for call to addOnActiveSessionsChangedListener",
-                SecurityException.class,
-                () -> mSessionManager.addOnActiveSessionsChangedListener(listener, null));
-    }
-
     private void assertKeyEventEquals(KeyEvent lhs, int keyCode, int action, int repeatCount) {
         assertThat(lhs.getKeyCode() == keyCode
                 && lhs.getAction() == action
@@ -307,6 +301,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER}) // Requires a full user. Don't run for work profile.
     public void testSetOnVolumeKeyLongPressListener() throws Exception {
         Context context = getInstrumentation().getTargetContext();
         if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)
@@ -348,6 +343,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER}) // Requires a full user. Don't run for work profile.
     public void testSetOnMediaKeyListener() throws Exception {
         Handler handler = createHandlerWithScheduledLooperQuit();
         MediaSession session = new MediaSession(getInstrumentation().getTargetContext(), TAG);
@@ -410,6 +406,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testRemoteUserInfo() throws Exception {
         final Context context = getInstrumentation().getTargetContext();
         Handler handler = createHandlerWithScheduledLooperQuit();
@@ -458,6 +455,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetSession2Tokens() throws Exception {
         final Context context = getInstrumentation().getTargetContext();
         Handler handler = createHandlerWithScheduledLooperQuit();
@@ -483,6 +481,7 @@
 
     @Ignore // TODO(b/291800179): Diagnose flakiness and re-enable.
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetSession2TokensWithTwoSessions() throws Exception {
         final Context context = getInstrumentation().getTargetContext();
         Handler handler = createHandlerWithScheduledLooperQuit();
@@ -532,6 +531,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testAddAndRemoveSession2TokensListener() throws Exception {
         final Context context = getInstrumentation().getTargetContext();
         Handler handler = createHandlerWithScheduledLooperQuit();
@@ -562,6 +562,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSession2TokensNotChangedBySession1() throws Exception {
         final Context context = getInstrumentation().getTargetContext();
         Handler handler = createHandlerWithScheduledLooperQuit();
@@ -582,6 +583,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCustomClassConfigValuesAreValid() throws Exception {
         Context context = getInstrumentation().getTargetContext();
         String customMediaKeyDispatcher = context.getString(
@@ -603,6 +605,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testIsTrustedForMediaControl_withEnabledNotificationListener() throws Exception {
         List<String> packageNames = getEnabledNotificationListenerPackages();
         for (String packageName : packageNames) {
@@ -616,6 +619,7 @@
 
     @Test
     @FrameworkSpecificTest
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testIsTrustedForMediaControl_withInvalidUid() throws Exception {
         List<String> packageNames = getEnabledNotificationListenerPackages();
         for (String packageName : packageNames) {
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionManagerUiThreadTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionManagerUiThreadTest.java
new file mode 100644
index 0000000..44f9624
--- /dev/null
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionManagerUiThreadTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2024 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.media.bettertogether.cts;
+
+import static org.junit.Assert.assertThrows;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.media.session.MediaSessionManager;
+import android.platform.test.annotations.AppModeFull;
+
+import androidx.test.annotation.UiThreadTest;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import com.android.compatibility.common.util.FrameworkSpecificTest;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for {@link MediaSessionManager} that need to be run on the UIThread and can't be run with
+ * Bedstead. Normally {@link MediaSessionManagerTest} should be used instead.
+ */
+@AppModeFull(reason = "TODO: evaluate and port to instant")
+@RunWith(AndroidJUnit4.class)
+public class MediaSessionManagerUiThreadTest {
+
+    private MediaSessionManager mSessionManager;
+
+    @Before
+    public void setUp() {
+        mSessionManager =
+                (MediaSessionManager)
+                        getInstrumentation()
+                                .getTargetContext()
+                                .getSystemService(Context.MEDIA_SESSION_SERVICE);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        getInstrumentation().getUiAutomation().dropShellPermissionIdentity();
+    }
+
+    @Test
+    @UiThreadTest
+    @FrameworkSpecificTest
+    public void testAddOnActiveSessionsListener_invalidMethodArguments_throwsException() {
+        assertThrows(
+                "Expected NPE for call to addOnActiveSessionsChangedListener",
+                NullPointerException.class,
+                () ->
+                        mSessionManager.addOnActiveSessionsChangedListener(
+                                /* sessionListener= */ null, /* notificationListener= */ null));
+
+        MediaSessionManager.OnActiveSessionsChangedListener listener = controllers -> {};
+
+        assertThrows(
+                "Expected security exception for call to addOnActiveSessionsChangedListener",
+                SecurityException.class,
+                () ->
+                        mSessionManager.addOnActiveSessionsChangedListener(
+                                listener, /* notificationListener= */ null));
+    }
+
+    private Instrumentation getInstrumentation() {
+        return InstrumentationRegistry.getInstrumentation();
+    }
+}
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionTest.java
index 207004e..3fb5cb8 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/MediaSessionTest.java
@@ -61,9 +61,11 @@
 import android.text.TextUtils;
 import android.view.KeyEvent;
 
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
 import com.android.compatibility.common.util.FrameworkSpecificTest;
 
 import org.junit.After;
@@ -82,7 +84,7 @@
 
 @FrameworkSpecificTest
 @AppModeFull(reason = "TODO: evaluate and port to instant")
-@RunWith(AndroidJUnit4.class)
+@RunWith(BedsteadJUnit4.class)
 public class MediaSessionTest {
     // The maximum time to wait for an operation that is expected to succeed.
     private static final long TIME_OUT_MS = 3000L;
@@ -172,6 +174,7 @@
      * initialized correctly.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCreateSession() throws Exception {
         assertThat(mSession.getSessionToken()).isNotNull();
         assertWithMessage("New session should not be active").that(mSession.isActive()).isFalse();
@@ -183,6 +186,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     // Needed for assertThat(sessionToken.equals(mSession)).isFalse().
     @SuppressWarnings("EqualsIncompatibleType")
     public void testSessionTokenEquals() {
@@ -208,6 +212,7 @@
      * Tests MediaSession.Token created in the constructor of MediaSession.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSessionToken() throws Exception {
         MediaSession.Token sessionToken = mSession.getSessionToken();
 
@@ -236,6 +241,7 @@
      * controller.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testConfigureSession() throws Exception {
         MediaController controller = mSession.getController();
         controller.registerCallback(mCallback, mHandler);
@@ -377,6 +383,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void setMediaSession_withInaccessibleUri_uriCleared() throws Exception {
         createCloneProfile();
         Assume.assumeTrue(mCloneProfileId.isPresent());
@@ -410,6 +417,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void setMediaSession_withUri_uriExists() throws Exception {
         String testMediaUri = "content://media/external/images/media/";
         MediaController controller = mSession.getController();
@@ -442,6 +450,7 @@
      */
     @Ignore // TODO(b/291800179): Diagnose flakiness and re-enable.
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetMediaButtonReceiver_broadcastReceiver() throws Exception {
         Intent intent = new Intent(mContext.getApplicationContext(),
                 MediaButtonBroadcastReceiver.class);
@@ -493,6 +502,7 @@
      * Test whether media button receiver can be a explicit service.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetMediaButtonReceiver_service() throws Exception {
         Intent intent = new Intent(mContext.getApplicationContext(),
                 MediaButtonReceiverService.class);
@@ -545,6 +555,7 @@
      * {@link MediaSession#setMediaButtonReceiver(PendingIntent)} with implicit intent.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetMediaButtonReceiver_implicitIntent() throws Exception {
         // Note: No such broadcast receiver exists.
         Intent intent = new Intent("android.media.bettertogether.cts.ACTION_MEDIA_TEST");
@@ -568,6 +579,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetMediaButtonReceiver_withNull_doesNotThrow() {
         try {
             mSession.setMediaButtonReceiver(null);
@@ -582,6 +594,7 @@
      */
     @Ignore // TODO(b/291800179): Diagnose flakiness and re-enable.
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetMediaButtonBroadcastReceiver_broadcastReceiver() throws Exception {
         // Play a sound so this session can get the priority.
         Utils.assertMediaPlaybackStarted(getContext());
@@ -629,6 +642,7 @@
      * Test public APIs of {@link VolumeProvider}.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testVolumeProvider() {
         VolumeProvider vp = new VolumeProvider(VolumeProvider.VOLUME_CONTROL_RELATIVE,
                 TEST_MAX_VOLUME, TEST_CURRENT_VOLUME, TEST_VOLUME_CONTROL_ID) {};
@@ -642,6 +656,7 @@
      * Test {@link MediaSession#setPlaybackToLocal} and {@link MediaSession#setPlaybackToRemote}.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testPlaybackToLocalAndRemote() throws Exception {
         MediaController controller = mSession.getController();
         controller.registerCallback(mCallback, mHandler);
@@ -709,6 +724,7 @@
      * Test {@link MediaSession.Callback#onMediaButtonEvent}.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testCallbackOnMediaButtonEvent() throws Exception {
         MediaSessionCallback sessionCallback = new MediaSessionCallback();
         mSession.setCallback(sessionCallback, new Handler(Looper.getMainLooper()));
@@ -823,6 +839,7 @@
      * once {@code setCallback(null)} is done.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetCallbackWithNull() throws Exception {
         MediaSessionCallback sessionCallback = new MediaSessionCallback();
         mSession.setCallback(sessionCallback, mHandler);
@@ -859,6 +876,7 @@
      * See: b/36669550
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testReleaseNoCrashWithMultipleSessions() throws Exception {
         // Start a media playback for this app to receive media key events.
         Utils.assertMediaPlaybackStarted(getContext());
@@ -896,6 +914,7 @@
      * Tests {@link MediaSession.QueueItem}.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testQueueItem() {
         MediaDescription.Builder descriptionBuilder = new MediaDescription.Builder()
                 .setMediaId("media-id")
@@ -933,6 +952,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testQueueItemEquals() {
         MediaDescription.Builder descriptionBuilder = new MediaDescription.Builder()
                 .setMediaId("media-id")
@@ -960,6 +980,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSessionInfoWithFrameworkParcelable() {
         final String testKey = "test_key";
         final AudioAttributes frameworkParcelable = new AudioAttributes.Builder().build();
@@ -984,6 +1005,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSessionInfoWithCustomParcelable() {
         final String testKey = "test_key";
         final MediaSession2Test.CustomParcelable customParcelable =
@@ -1011,6 +1033,7 @@
      * See MediaSessionService#SESSION_CREATION_LIMIT_PER_UID
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSessionCreationLimit() {
         List<MediaSession> sessions = new ArrayList<>();
         try {
@@ -1032,6 +1055,7 @@
      * does not decrement current session count multiple times.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSessionCreationLimitWithMediaSessionRelease() {
         List<MediaSession> sessions = new ArrayList<>();
         MediaSession sessionToReleaseMultipleTimes = null;
@@ -1061,6 +1085,7 @@
      * Check that calling {@link MediaSession2#close()} does not decrement current session count.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSessionCreationLimitWithMediaSession2Release() {
         List<MediaSession> sessions = new ArrayList<>();
         try {
@@ -1087,6 +1112,7 @@
      * on the remote process due to binder buffer overflow.
      */
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSeriesOfSetQueue() throws Exception {
         int numberOfCalls = 100;
         int queueSize = 1_000;
@@ -1112,6 +1138,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetQueueWithLargeNumberOfItems() throws Exception {
         int queueSize = 500_000;
         List<QueueItem> queue = new ArrayList<>();
@@ -1134,6 +1161,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testSetQueueWithEmptyQueue() throws Exception {
         try (RemoteService.Invoker invoker = new RemoteService.Invoker(mContext,
                 MediaSessionTestService.class, TEST_SET_QUEUE)) {
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/Session2CommandGroupTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/Session2CommandGroupTest.java
index ed7a570..611fd30 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/Session2CommandGroupTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/Session2CommandGroupTest.java
@@ -22,18 +22,19 @@
 import android.media.Session2CommandGroup;
 import android.os.Parcel;
 
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.SmallTest;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
+
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import java.util.Set;
 
-/**
- * Tests {@link android.media.Session2CommandGroup}.
- */
-@RunWith(AndroidJUnit4.class)
+/** Tests {@link android.media.Session2CommandGroup}. */
+@RunWith(BedsteadJUnit4.class)
 @SmallTest
 public class Session2CommandGroupTest {
     private static final int TEST_COMMAND_CODE_1 = 10000;
@@ -41,6 +42,7 @@
     private static final int TEST_COMMAND_CODE_3 = 10002;
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testHasCommand() {
         Session2Command testCommand = new Session2Command(TEST_COMMAND_CODE_1);
         Session2CommandGroup.Builder builder = new Session2CommandGroup.Builder()
@@ -52,6 +54,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetCommands() {
         Session2Command command1 = new Session2Command(TEST_COMMAND_CODE_1);
         Session2Command command2 = new Session2Command(TEST_COMMAND_CODE_2);
@@ -65,6 +68,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testDescribeContents() {
         final int expected = 0;
         Session2Command command = new Session2Command(TEST_COMMAND_CODE_1);
@@ -75,6 +79,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testWriteToParcel() {
         Session2CommandGroup.Builder builder = new Session2CommandGroup.Builder()
                 .addCommand(new Session2Command(TEST_COMMAND_CODE_1))
@@ -90,6 +95,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testBuilder() {
         Session2CommandGroup.Builder builder = new Session2CommandGroup.Builder()
                 .addCommand(new Session2Command(TEST_COMMAND_CODE_1));
@@ -100,6 +106,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testAddAndRemoveCommand() {
         Session2Command testCommand1 = new Session2Command(TEST_COMMAND_CODE_1);
         Session2Command testCommand2 = new Session2Command(TEST_COMMAND_CODE_2);
diff --git a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/Session2CommandTest.java b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/Session2CommandTest.java
index acbb261..0953ce3 100644
--- a/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/Session2CommandTest.java
+++ b/tests/tests/media/bettertogether/src/android/media/bettertogether/cts/Session2CommandTest.java
@@ -24,17 +24,18 @@
 import android.os.Bundle;
 import android.os.Parcel;
 
-import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.filters.SmallTest;
 
+import com.android.bedstead.harrier.BedsteadJUnit4;
+import com.android.bedstead.harrier.UserType;
+import com.android.bedstead.harrier.annotations.UserTest;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-/**
- * Tests {@link android.media.Session2Command}.
- */
-@RunWith(AndroidJUnit4.class)
+/** Tests {@link android.media.Session2Command}. */
+@RunWith(BedsteadJUnit4.class)
 @SmallTest
 public class Session2CommandTest {
     private static final int TEST_COMMAND_CODE = 10000;
@@ -50,18 +51,21 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testConstructorWithCommandCodeCustom() {
         assertThrows(IllegalArgumentException.class,
                 () -> new Session2Command(Session2Command.COMMAND_CODE_CUSTOM));
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testConstructorWithNullAction() {
         assertThrows(IllegalArgumentException.class,
                 () -> new Session2Command(null, null));
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetCommandCode() {
         Session2Command commandWithCode = new Session2Command(TEST_COMMAND_CODE);
         assertThat(commandWithCode.getCommandCode()).isEqualTo(TEST_COMMAND_CODE);
@@ -73,6 +77,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetCustomAction() {
         Session2Command commandWithCode = new Session2Command(TEST_COMMAND_CODE);
         assertThat(commandWithCode.getCustomAction()).isNull();
@@ -83,6 +88,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetCustomExtras() {
         Session2Command commandWithCode = new Session2Command(TEST_COMMAND_CODE);
         assertThat(commandWithCode.getCustomExtras()).isNull();
@@ -93,6 +99,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testDescribeContents() {
         final int expected = 0;
         Session2Command command = new Session2Command(TEST_COMMAND_CODE);
@@ -100,6 +107,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testWriteToParcel() {
         Session2Command command = new Session2Command(TEST_CUSTOM_ACTION, null);
         Parcel dest = Parcel.obtain();
@@ -111,6 +119,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testEquals() {
         Session2Command commandWithCode1 = new Session2Command(TEST_COMMAND_CODE);
         Session2Command commandWithCode2 = new Session2Command(TEST_COMMAND_CODE);
@@ -124,6 +133,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testHashCode() {
         Session2Command commandWithCode1 = new Session2Command(TEST_COMMAND_CODE);
         Session2Command commandWithCode2 = new Session2Command(TEST_COMMAND_CODE);
@@ -131,6 +141,7 @@
     }
 
     @Test
+    @UserTest({UserType.INITIAL_USER, UserType.WORK_PROFILE})
     public void testGetResultCodeAndData() {
         Session2Command.Result result = new Session2Command.Result(TEST_RESULT_CODE,
                 mTestResultData);