diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index 0807ee97d1..7ab9ef3acf 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -749,4 +749,9 @@ public class TaskbarManager { 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 096f8791ae..cd4e78b3d3 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.launcher3.util.TestUtil 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 @@ class TaskbarUnitTestRule( } } + 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 @@ class TaskbarUnitTestRule( @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 7daa142d39..b8b0b5d1e1 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 @@ package com.android.launcher3.taskbar.rules 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 @@ class TaskbarUnitTestRuleTest { } } + @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. *