Moving NavigationMode to display controller

Navigation mode affects display properties like bounds and
most listeners already had a similar display listener. This
will remove race conditions when managing the two events.

Bug: 221961069
Test: Presubmit
Change-Id: If7a22e006e6b969ecddf075001066809aa72995c
This commit is contained in:
Sunny Goyal
2022-03-04 10:49:01 -08:00
parent 1ffc81c7ba
commit 4403d078a6
31 changed files with 317 additions and 462 deletions
@@ -33,6 +33,7 @@ import androidx.test.uiautomator.UiDevice;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.FailureWatcher;
import com.android.systemui.shared.system.QuickStepContract;
@@ -71,8 +72,8 @@ public class NavigationModeSwitchRule implements TestRule {
private final LauncherInstrumentation mLauncher;
static final SysUINavigationMode SYS_UI_NAVIGATION_MODE =
SysUINavigationMode.INSTANCE.get(getInstrumentation().getTargetContext());
static final DisplayController DISPLAY_CONTROLLER =
DisplayController.INSTANCE.get(getInstrumentation().getTargetContext());
public NavigationModeSwitchRule(LauncherInstrumentation launcher) {
mLauncher = launcher;
@@ -138,7 +139,7 @@ public class NavigationModeSwitchRule implements TestRule {
private static LauncherInstrumentation.NavigationModel currentSysUiNavigationMode() {
return LauncherInstrumentation.getNavigationModel(
SysUINavigationMode.getMode(
DisplayController.getNavigationMode(
getInstrumentation().
getTargetContext()).
resValue);
@@ -159,18 +160,18 @@ public class NavigationModeSwitchRule implements TestRule {
if (currentSysUiNavigationMode() != expectedMode) {
final CountDownLatch latch = new CountDownLatch(1);
final Context targetContext = getInstrumentation().getTargetContext();
final SysUINavigationMode.NavigationModeChangeListener listener =
newMode -> {
if (LauncherInstrumentation.getNavigationModel(newMode.resValue)
final DisplayController.DisplayInfoChangeListener listener =
(context, info, flags) -> {
if (LauncherInstrumentation.getNavigationModel(info.navigationMode.resValue)
== expectedMode) {
latch.countDown();
}
};
targetContext.getMainExecutor().execute(() ->
SYS_UI_NAVIGATION_MODE.addModeChangeListener(listener));
DISPLAY_CONTROLLER.addChangeListener(listener));
latch.await(60, TimeUnit.SECONDS);
targetContext.getMainExecutor().execute(() ->
SYS_UI_NAVIGATION_MODE.removeModeChangeListener(listener));
DISPLAY_CONTROLLER.removeChangeListener(listener));
assertTrue(launcher, "Navigation mode didn't change to " + expectedMode,
currentSysUiNavigationMode() == expectedMode, description);
@@ -21,7 +21,7 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.android.quickstep.SysUINavigationMode.Mode.NO_BUTTON;
import static com.android.launcher3.util.DisplayController.NavigationMode.NO_BUTTON;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -39,7 +39,6 @@ import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.LauncherModelHelper;
import com.android.launcher3.util.ReflectionHelpers;
import com.android.quickstep.FallbackActivityInterface;
import com.android.quickstep.SysUINavigationMode;
import com.android.quickstep.SystemUiProxy;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams;
@@ -143,7 +142,6 @@ public class TaskViewSimulatorTest {
LauncherModelHelper helper = new LauncherModelHelper();
try {
helper.sandboxContext.allow(SystemUiProxy.INSTANCE);
helper.sandboxContext.allow(SysUINavigationMode.INSTANCE);
Display display = mock(Display.class);
doReturn(DEFAULT_DISPLAY).when(display).getDisplayId();