Add annotation to simulate RTL in tests.

Flag: TEST_ONLY
Bug: 230027385
Test: go/testedequals
Change-Id: Idc4ca404179359a6dc4fac160b7a865c5709f137
diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
index 0807ee9..7ab9ef3 100644
--- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
+++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
@@ -749,4 +749,9 @@
 
     private final DeviceProfile.OnDeviceProfileChangeListener mDebugActivityDeviceProfileChanged =
             dp -> debugWhyTaskbarNotDestroyed("mActivity onDeviceProfileChanged");
+
+    @VisibleForTesting
+    public Context getWindowContext() {
+        return mContext;
+    }
 }
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRule.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRule.kt
index 096f879..cd4e78b 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRule.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRule.kt
@@ -37,6 +37,7 @@
 import com.android.quickstep.AllAppsActionManager
 import java.lang.reflect.Field
 import java.lang.reflect.ParameterizedType
+import java.util.Locale
 import java.util.Optional
 import org.junit.Assume.assumeTrue
 import org.junit.rules.TestRule
@@ -119,6 +120,15 @@
                         }
                     }
 
+                if (description.getAnnotation(ForceRtl::class.java) != null) {
+                    // Needs to be set on window context instead of sandbox context, because it does
+                    // does not propagate between them. However, this change will impact created
+                    // TaskbarActivityContext instances, since they wrap the window context.
+                    taskbarManager.windowContext.resources.configuration.setLayoutDirection(
+                        RTL_LOCALE
+                    )
+                }
+
                 try {
                     TaskbarViewController.enableModelLoadingForTests(false)
 
@@ -191,4 +201,11 @@
     @Retention(AnnotationRetention.RUNTIME)
     @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
     annotation class NavBarKidsMode
+
+    /** Forces RTL UI for tests. */
+    @Retention(AnnotationRetention.RUNTIME)
+    @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
+    annotation class ForceRtl
 }
+
+private val RTL_LOCALE = Locale.of("ar", "XB")
diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRuleTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRuleTest.kt
index 7daa142..b8b0b5d 100644
--- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRuleTest.kt
+++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/rules/TaskbarUnitTestRuleTest.kt
@@ -19,11 +19,13 @@
 import android.platform.test.annotations.DisableFlags
 import android.platform.test.annotations.EnableFlags
 import android.platform.test.flag.junit.SetFlagsRule
+import com.android.launcher3.Utilities
 import com.android.launcher3.taskbar.TaskbarActivityContext
 import com.android.launcher3.taskbar.TaskbarKeyguardController
 import com.android.launcher3.taskbar.TaskbarManager
 import com.android.launcher3.taskbar.TaskbarStashController
 import com.android.launcher3.taskbar.bubbles.BubbleBarController
+import com.android.launcher3.taskbar.rules.TaskbarUnitTestRule.ForceRtl
 import com.android.launcher3.taskbar.rules.TaskbarUnitTestRule.InjectController
 import com.android.launcher3.taskbar.rules.TaskbarUnitTestRule.NavBarKidsMode
 import com.android.launcher3.taskbar.rules.TaskbarUnitTestRule.UserSetupMode
@@ -197,6 +199,14 @@
         }
     }
 
+    @Test
+    fun testForceRtlAnnotation_setsActivityContextLayoutDirection() {
+        @ForceRtl class Rtl
+        onSetup(description = Description.createSuiteDescription(Rtl::class.java)) {
+            assertThat(Utilities.isRtl(activityContext.resources)).isTrue()
+        }
+    }
+
     /**
      * Executes [runTest] after the [testRule] setup phase completes.
      *