Merge changes from topics "launcher_nav_changes", "nav-bar-mode-fw-overlay-ub-launcher3-master" into ub-launcher3-master

* changes:
  Use system recent tasks stabilization
  Use own context instead of app context to get overlay resources
  Updating to nav bar mode
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
index e8d4c19..15072a2 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/WindowTransformSwipeHandler.java
@@ -851,16 +851,6 @@
             Interpolator interpolator, GestureEndTarget target, PointF velocityPxPerMs) {
         mGestureEndTarget = target;
 
-        if (mGestureEndTarget.canBeContinued) {
-            // Because we might continue this gesture, e.g. for consecutive quick switch, we need to
-            // stabilize the task list so that tasks don't rearrange in the middle of the gesture.
-            RecentsModel.INSTANCE.get(mContext).startStabilizationSession();
-        } else if (mGestureEndTarget.isLauncher) {
-            // Otherwise, if we're going to home or overview,
-            // we reset the tasks to a consistent start state.
-            RecentsModel.INSTANCE.get(mContext).endStabilizationSession();
-        }
-
         if (mGestureEndTarget == HOME) {
             HomeAnimationFactory homeAnimFactory;
             if (mActivity != null) {
@@ -1003,10 +993,12 @@
         // Launch the task user scrolled to (mRecentsView.getNextPage()).
         if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
             // We finish recents animation inside launchTask() when live tile is enabled.
-            mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(false);
+            mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(false /* animate */,
+                    true /* freezeTaskList */);
         } else {
             mRecentsAnimationWrapper.finish(true /* toRecents */, () -> {
-                mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(false);
+                mRecentsView.getTaskViewAt(mRecentsView.getNextPage()).launchTask(
+                        false /* animate */, true /* freezeTaskList */);
             });
         }
         TOUCH_INTERACTION_LOG.addLog("finishRecentsAnimation", false);
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
index eb17e3e..6ba89c9 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java
@@ -250,7 +250,11 @@
     }
 
     public void launchTask(boolean animate) {
-        launchTask(animate, (result) -> {
+        launchTask(animate, false /* freezeTaskList */);
+    }
+
+    public void launchTask(boolean animate, boolean freezeTaskList) {
+        launchTask(animate, freezeTaskList, (result) -> {
             if (!result) {
                 notifyTaskLaunchFailed(TAG);
             }
@@ -259,25 +263,33 @@
 
     public void launchTask(boolean animate, Consumer<Boolean> resultCallback,
             Handler resultCallbackHandler) {
+        launchTask(animate, false /* freezeTaskList */, resultCallback, resultCallbackHandler);
+    }
+
+    public void launchTask(boolean animate, boolean freezeTaskList, Consumer<Boolean> resultCallback,
+            Handler resultCallbackHandler) {
         if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
             if (isRunningTask()) {
                 getRecentsView().finishRecentsAnimation(false /* toRecents */,
                         () -> resultCallbackHandler.post(() -> resultCallback.accept(true)));
             } else {
-                launchTaskInternal(animate, resultCallback, resultCallbackHandler);
+                launchTaskInternal(animate, freezeTaskList, resultCallback, resultCallbackHandler);
             }
         } else {
-            launchTaskInternal(animate, resultCallback, resultCallbackHandler);
+            launchTaskInternal(animate, freezeTaskList, resultCallback, resultCallbackHandler);
         }
     }
 
-    private void launchTaskInternal(boolean animate, Consumer<Boolean> resultCallback,
-            Handler resultCallbackHandler) {
+    private void launchTaskInternal(boolean animate, boolean freezeTaskList,
+            Consumer<Boolean> resultCallback, Handler resultCallbackHandler) {
         if (mTask != null) {
             final ActivityOptions opts;
             if (animate) {
                 opts = ((BaseDraggingActivity) fromContext(getContext()))
                         .getActivityLaunchOptions(this);
+                if (freezeTaskList) {
+                    ActivityOptionsCompat.setFreezeRecentTasksList(opts);
+                }
                 ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(mTask.key,
                         opts, resultCallback, resultCallbackHandler);
             } else {
@@ -288,6 +300,9 @@
                         resultCallbackHandler.post(() -> resultCallback.accept(true));
                     }
                 }, resultCallbackHandler);
+                if (freezeTaskList) {
+                    ActivityOptionsCompat.setFreezeRecentTasksList(opts);
+                }
                 ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(mTask.key,
                         opts, (success) -> {
                             if (resultCallback != null && !success) {
diff --git a/quickstep/src/com/android/quickstep/NavBarModeOverlayResourceObserver.java b/quickstep/src/com/android/quickstep/NavBarModeOverlayResourceObserver.java
new file mode 100644
index 0000000..3136632
--- /dev/null
+++ b/quickstep/src/com/android/quickstep/NavBarModeOverlayResourceObserver.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2019 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 com.android.quickstep;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.Resources;
+import android.util.Log;
+
+import com.android.systemui.shared.system.QuickStepContract;
+
+/**
+ * Observer for the resource config that specifies the navigation bar mode.
+ */
+public class NavBarModeOverlayResourceObserver extends BroadcastReceiver {
+
+    private static final String TAG = "NavBarModeOverlayResourceObserver";
+
+    private final String ACTION_OVERLAY_CHANGED = "android.intent.action.OVERLAY_CHANGED";
+    private static final String NAV_BAR_INTERACTION_MODE_RES_NAME =
+            "config_navBarInteractionMode";
+
+    private final Context mContext;
+    private final OnChangeListener mOnChangeListener;
+
+    public NavBarModeOverlayResourceObserver(Context context, OnChangeListener listener) {
+        mContext = context;
+        mOnChangeListener = listener;
+    }
+
+    public void register() {
+        IntentFilter filter = new IntentFilter(ACTION_OVERLAY_CHANGED);
+        filter.addDataScheme("package");
+        mContext.registerReceiver(this, filter);
+    }
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        mOnChangeListener.onNavBarModeChanged(getSystemIntegerRes(context,
+                NAV_BAR_INTERACTION_MODE_RES_NAME));
+    }
+
+    public interface OnChangeListener {
+        void onNavBarModeChanged(int mode);
+    }
+
+    public static boolean isSwipeUpModeEnabled(Context context) {
+        return QuickStepContract.isSwipeUpMode(getSystemIntegerRes(context,
+                NAV_BAR_INTERACTION_MODE_RES_NAME));
+    }
+
+    public static boolean isEdgeToEdgeModeEnabled(Context context) {
+        return QuickStepContract.isGesturalMode(getSystemIntegerRes(context,
+                NAV_BAR_INTERACTION_MODE_RES_NAME));
+    }
+
+    public static boolean isLegacyModeEnabled(Context context) {
+        return QuickStepContract.isLegacyMode(getSystemIntegerRes(context,
+                NAV_BAR_INTERACTION_MODE_RES_NAME));
+    }
+
+    private static int getSystemIntegerRes(Context context, String resName) {
+        Resources res = context.getResources();
+        int resId = res.getIdentifier(resName, "integer", "android");
+
+        if (resId != 0) {
+            return res.getInteger(resId);
+        } else {
+            Log.e(TAG, "Failed to get system resource ID. Incompatible framework version?");
+            return -1;
+        }
+    }
+}
\ No newline at end of file
diff --git a/quickstep/src/com/android/quickstep/OverviewInteractionState.java b/quickstep/src/com/android/quickstep/OverviewInteractionState.java
index a0ab301..903701d 100644
--- a/quickstep/src/com/android/quickstep/OverviewInteractionState.java
+++ b/quickstep/src/com/android/quickstep/OverviewInteractionState.java
@@ -15,7 +15,6 @@
  */
 package com.android.quickstep;
 
-import static com.android.quickstep.SwipeUpSetting.newSwipeUpSettingsObserver;
 import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_QUICK_SCRUB;
 import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_SWIPE_UP;
 import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON;
@@ -28,10 +27,11 @@
 
 import com.android.launcher3.Utilities;
 import com.android.launcher3.allapps.DiscoveryBounce;
+import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.util.MainThreadInitializedObject;
-import com.android.launcher3.util.SecureSettingsObserver;
 import com.android.launcher3.util.UiThreadHelper;
 import com.android.systemui.shared.recents.ISystemUiProxy;
+import com.android.systemui.shared.system.QuickStepContract;
 
 import androidx.annotation.WorkerThread;
 
@@ -58,7 +58,8 @@
     private static final int MSG_SET_BACK_BUTTON_ALPHA = 201;
     private static final int MSG_SET_SWIPE_UP_ENABLED = 202;
 
-    private final SecureSettingsObserver mSwipeUpSettingObserver;
+    // TODO: Discriminate between swipe up and edge to edge
+    private final NavBarModeOverlayResourceObserver mSwipeUpSettingObserver;
 
     private final Context mContext;
     private final Handler mUiHandler;
@@ -66,7 +67,7 @@
 
     // These are updated on the background thread
     private ISystemUiProxy mISystemUiProxy;
-    private boolean mSwipeUpEnabled = true;
+    private boolean mSwipeUpEnabled;
     private float mBackButtonAlpha = 1;
 
     private Runnable mOnSwipeUpSettingChangedListener;
@@ -80,15 +81,15 @@
         mUiHandler = new Handler(this::handleUiMessage);
         mBgHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleBgMessage);
 
-        if (SwipeUpSetting.isSwipeUpSettingAvailable()) {
-            mSwipeUpSettingObserver =
-                    newSwipeUpSettingsObserver(context, this::notifySwipeUpSettingChanged);
+        mSwipeUpEnabled = NavBarModeOverlayResourceObserver.isSwipeUpModeEnabled(mContext)
+                || NavBarModeOverlayResourceObserver.isEdgeToEdgeModeEnabled(mContext);
+        if (SwipeUpSetting.isSystemNavigationSettingAvailable()) {
+            mSwipeUpSettingObserver = new NavBarModeOverlayResourceObserver(context,
+                    this::notifySwipeUpSettingChanged);
             mSwipeUpSettingObserver.register();
-            mSwipeUpEnabled = mSwipeUpSettingObserver.getValue();
             resetHomeBounceSeenOnQuickstepEnabledFirstTime();
         } else {
             mSwipeUpSettingObserver = null;
-            mSwipeUpEnabled = SwipeUpSetting.isSwipeUpEnabledDefaultValue();
         }
     }
 
@@ -175,7 +176,13 @@
         }
     }
 
-    private void notifySwipeUpSettingChanged(boolean swipeUpEnabled) {
+    private void notifySwipeUpSettingChanged(int mode) {
+        boolean swipeUpEnabled = !QuickStepContract.isLegacyMode(mode);
+        boolean gesturalEnabled = QuickStepContract.isGesturalMode(mode);
+
+        FeatureFlags.SWIPE_HOME.updateStorage(mContext, gesturalEnabled);
+        FeatureFlags.ENABLE_ASSISTANT_GESTURE.updateStorage(mContext, gesturalEnabled);
+
         mUiHandler.removeMessages(MSG_SET_SWIPE_UP_ENABLED);
         mUiHandler.obtainMessage(MSG_SET_SWIPE_UP_ENABLED, swipeUpEnabled ? 1 : 0, 0).
                 sendToTarget();
diff --git a/quickstep/src/com/android/quickstep/RecentTasksList.java b/quickstep/src/com/android/quickstep/RecentTasksList.java
index e15a3f1..06a36c9 100644
--- a/quickstep/src/com/android/quickstep/RecentTasksList.java
+++ b/quickstep/src/com/android/quickstep/RecentTasksList.java
@@ -44,7 +44,6 @@
     private final KeyguardManagerCompat mKeyguardManager;
     private final MainThreadExecutor mMainThreadExecutor;
     private final BackgroundExecutor mBgThreadExecutor;
-    private final TaskListStabilizer mStabilizer = new TaskListStabilizer();
 
     // The list change id, increments as the task list changes in the system
     private int mChangeId;
@@ -74,14 +73,6 @@
         });
     }
 
-    public void startStabilizationSession() {
-        mStabilizer.startStabilizationSession();
-    }
-
-    public void endStabilizationSession() {
-        mStabilizer.endStabilizationSession();
-    }
-
     /**
      * Asynchronously fetches the list of recent tasks, reusing cached list if available.
      *
@@ -93,7 +84,7 @@
         final int requestLoadId = mChangeId;
         Runnable resultCallback = callback == null
                 ? () -> { }
-                : () -> callback.accept(mStabilizer.reorder(mTasks));
+                : () -> callback.accept(mTasks);
 
         if (mLastLoadedId == mChangeId && (!mLastLoadHadKeysOnly || loadKeysOnly)) {
             // The list is up to date, callback with the same list
diff --git a/quickstep/src/com/android/quickstep/RecentsModel.java b/quickstep/src/com/android/quickstep/RecentsModel.java
index 56bc8570..a65bc33 100644
--- a/quickstep/src/com/android/quickstep/RecentsModel.java
+++ b/quickstep/src/com/android/quickstep/RecentsModel.java
@@ -90,14 +90,6 @@
         return mThumbnailCache;
     }
 
-    public void startStabilizationSession() {
-        mTaskList.startStabilizationSession();
-    }
-
-    public void endStabilizationSession() {
-        mTaskList.endStabilizationSession();
-    }
-
     /**
      * Fetches the list of recent tasks.
      *
diff --git a/quickstep/src/com/android/quickstep/SwipeUpSetting.java b/quickstep/src/com/android/quickstep/SwipeUpSetting.java
index 381ab9f..7f830f9 100644
--- a/quickstep/src/com/android/quickstep/SwipeUpSetting.java
+++ b/quickstep/src/com/android/quickstep/SwipeUpSetting.java
@@ -16,23 +16,18 @@
 
 package com.android.quickstep;
 
-import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
-
-import android.content.Context;
 import android.content.res.Resources;
 import android.util.Log;
 
-import com.android.launcher3.util.SecureSettingsObserver;
-import com.android.launcher3.util.SecureSettingsObserver.OnChangeListener;
-
 public final class SwipeUpSetting {
     private static final String TAG = "SwipeUpSetting";
 
     private static final String SWIPE_UP_SETTING_AVAILABLE_RES_NAME =
             "config_swipe_up_gesture_setting_available";
 
-    private static final String SWIPE_UP_ENABLED_DEFAULT_RES_NAME =
-            "config_swipe_up_gesture_default";
+    public static boolean isSystemNavigationSettingAvailable() {
+        return getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME);
+    }
 
     private static boolean getSystemBooleanRes(String resName) {
         Resources res = Resources.getSystem();
@@ -45,18 +40,4 @@
             return false;
         }
     }
-
-    public static boolean isSwipeUpSettingAvailable() {
-        return getSystemBooleanRes(SWIPE_UP_SETTING_AVAILABLE_RES_NAME);
-    }
-
-    public static boolean isSwipeUpEnabledDefaultValue() {
-        return getSystemBooleanRes(SWIPE_UP_ENABLED_DEFAULT_RES_NAME);
-    }
-
-    public static SecureSettingsObserver newSwipeUpSettingsObserver(Context context,
-            OnChangeListener listener) {
-        return new SecureSettingsObserver(context.getContentResolver(), listener,
-                SWIPE_UP_SETTING_NAME, isSwipeUpEnabledDefaultValue() ? 1 : 0);
-    }
 }
diff --git a/quickstep/src/com/android/quickstep/TaskListStabilizer.java b/quickstep/src/com/android/quickstep/TaskListStabilizer.java
deleted file mode 100644
index 4c63f81..0000000
--- a/quickstep/src/com/android/quickstep/TaskListStabilizer.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2019 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 com.android.quickstep;
-
-import android.app.ActivityManager.RecentTaskInfo;
-import android.content.ComponentName;
-import android.os.Process;
-import android.os.SystemClock;
-
-import com.android.launcher3.util.IntArray;
-import com.android.systemui.shared.recents.model.Task;
-import com.android.systemui.shared.recents.model.Task.TaskKey;
-import com.android.systemui.shared.system.ActivityManagerWrapper;
-import com.android.systemui.shared.system.TaskStackChangeListener;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Keeps the task list stable during quick switch gestures. So if you swipe right to switch from app
- * A to B, you can then swipe right again to get to app C or left to get back to A.
- */
-public class TaskListStabilizer {
-
-    private static final long TASK_CACHE_TIMEOUT_MS = 5000;
-
-    private final TaskStackChangeListener mTaskStackListener = new TaskStackChangeListener() {
-
-        @Override
-        public void onTaskCreated(int taskId, ComponentName componentName) {
-            endStabilizationSession();
-        }
-
-        @Override
-        public void onTaskRemoved(int taskId) {
-            endStabilizationSession();
-        }
-    };
-
-    // Task ids ordered based on recency, 0th index is the least recent task
-    private final IntArray mSystemOrder;
-    private final IntArray mStabilizedOrder;
-
-    // Wrapper objects used for sorting tasks
-    private final ArrayList<TaskWrapper> mTaskWrappers = new ArrayList<>();
-
-    private boolean mInStabilizationSession;
-    private long mSessionStartTime;
-
-    public TaskListStabilizer() {
-        // Initialize the task ids map
-        List<RecentTaskInfo> rawTasks = ActivityManagerWrapper.getInstance().getRecentTasks(
-                Integer.MAX_VALUE, Process.myUserHandle().getIdentifier());
-        mSystemOrder = new IntArray(rawTasks.size());
-        for (RecentTaskInfo info : rawTasks) {
-            mSystemOrder.add(new TaskKey(info).id);
-        }
-        // We will lazily copy the task id's from mSystemOrder when a stabilization session starts.
-        mStabilizedOrder = new IntArray(rawTasks.size());
-
-        ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
-    }
-
-    public synchronized void startStabilizationSession() {
-        if (!mInStabilizationSession) {
-            mStabilizedOrder.clear();
-            mStabilizedOrder.addAll(mSystemOrder);
-        }
-        mInStabilizationSession = true;
-        mSessionStartTime = SystemClock.uptimeMillis();
-    }
-
-    public synchronized void endStabilizationSession() {
-        mInStabilizationSession = false;
-    }
-
-    public synchronized ArrayList<Task> reorder(ArrayList<Task> tasks) {
-        mSystemOrder.clear();
-        for (Task task : tasks) {
-            mSystemOrder.add(task.key.id);
-        }
-
-        if ((SystemClock.uptimeMillis() - mSessionStartTime) > TASK_CACHE_TIMEOUT_MS) {
-            endStabilizationSession();
-        }
-
-        if (!mInStabilizationSession) {
-            return tasks;
-        }
-
-        // Ensure that we have enough wrappers
-        int taskCount = tasks.size();
-        for (int i = taskCount - mTaskWrappers.size(); i > 0; i--) {
-            mTaskWrappers.add(new TaskWrapper());
-        }
-
-        List<TaskWrapper> listToSort = mTaskWrappers.size() == taskCount
-                ? mTaskWrappers : mTaskWrappers.subList(0, taskCount);
-        int missingTaskIndex = -taskCount;
-
-        for (int i = 0; i < taskCount; i++){
-            TaskWrapper wrapper = listToSort.get(i);
-            wrapper.task = tasks.get(i);
-            wrapper.index = mStabilizedOrder.indexOf(wrapper.task.key.id);
-
-            // Ensure that missing tasks are put in the front, in the order they appear in the
-            // original list
-            if (wrapper.index < 0) {
-                wrapper.index = missingTaskIndex;
-                missingTaskIndex++;
-            }
-        }
-        Collections.sort(listToSort);
-
-        ArrayList<Task> result = new ArrayList<>(taskCount);
-        for (int i = 0; i < taskCount; i++) {
-            result.add(listToSort.get(i).task);
-        }
-        return result;
-    }
-
-    private static class TaskWrapper implements Comparable<TaskWrapper> {
-        Task task;
-        int index;
-
-        @Override
-        public int compareTo(TaskWrapper other) {
-            return Integer.compare(index, other.index);
-        }
-    }
-}
diff --git a/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java b/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java
index f89842a..12bd0ca 100644
--- a/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java
+++ b/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java
@@ -16,25 +16,29 @@
 
 package com.android.quickstep;
 
+import static androidx.test.InstrumentationRegistry.getInstrumentation;
+
 import static com.android.quickstep.QuickStepOnOffRule.Mode.BOTH;
 import static com.android.quickstep.QuickStepOnOffRule.Mode.OFF;
 import static com.android.quickstep.QuickStepOnOffRule.Mode.ON;
-import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
+import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_2BUTTON_OVERLAY;
+import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_3BUTTON_OVERLAY;
+import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_GESTURAL_OVERLAY;
 
-import static org.junit.Assert.assertTrue;
-
-import android.provider.Settings;
+import android.content.Context;
 import android.util.Log;
 
-import androidx.test.InstrumentationRegistry;
+import androidx.test.uiautomator.UiDevice;
 
 import com.android.launcher3.tapl.LauncherInstrumentation;
 import com.android.launcher3.tapl.TestHelpers;
+import com.android.systemui.shared.system.QuickStepContract;
 
 import org.junit.rules.TestRule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
+import java.io.IOException;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -76,53 +80,59 @@
             return new Statement() {
                 @Override
                 public void evaluate() throws Throwable {
-                    if (SwipeUpSetting.isSwipeUpSettingAvailable()) {
-                        try {
-                            if (mode == ON || mode == BOTH) {
-                                evaluateWithQuickstepOn();
-                            }
-                            if (mode == OFF || mode == BOTH) {
-                                evaluateWithQuickstepOff();
-                            }
-                        } finally {
-                            setSwipeUpSetting(null);
+                    final Context context = getInstrumentation().getContext();
+                    final String prevOverlayPkg = QuickStepContract.isGesturalMode(context)
+                            ? NAV_BAR_MODE_GESTURAL_OVERLAY
+                            : QuickStepContract.isSwipeUpMode(context)
+                                    ? NAV_BAR_MODE_2BUTTON_OVERLAY
+                                    : NAV_BAR_MODE_3BUTTON_OVERLAY;
+                    try {
+                        if (mode == ON || mode == BOTH) {
+                            evaluateWithQuickstepOn();
                         }
-                    } else {
-                        // Execute without changing the setting, if the requested mode is
-                        // compatible.
-                        final boolean swipeUpEnabledDefaultValue =
-                                SwipeUpSetting.isSwipeUpEnabledDefaultValue();
-                        if (mode == BOTH ||
-                                mode == ON && swipeUpEnabledDefaultValue ||
-                                mode == OFF && !swipeUpEnabledDefaultValue) {
-                            evaluateWithoutChangingSetting(base);
+                        if (mode == OFF || mode == BOTH) {
+                            evaluateWithQuickstepOff();
                         }
+                    } finally {
+                        setActiveOverlay(prevOverlayPkg);
                     }
                 }
 
-                public void setSwipeUpSetting(String value) {
-                    Log.d(TAG, "setSwipeUpSetting: " + value);
-                    assertTrue("Couldn't change Quickstep mode",
-                            Settings.Secure.putString(
-                                    InstrumentationRegistry.getInstrumentation().getTargetContext().
-                                            getContentResolver(),
-                                    SWIPE_UP_SETTING_NAME,
-                                    value));
-                }
-
                 public void evaluateWithoutChangingSetting(Statement base) throws Throwable {
                     base.evaluate();
                 }
 
                 private void evaluateWithQuickstepOff() throws Throwable {
-                    setSwipeUpSetting("0");
+                    setActiveOverlay(NAV_BAR_MODE_3BUTTON_OVERLAY);
                     evaluateWithoutChangingSetting(base);
                 }
 
                 private void evaluateWithQuickstepOn() throws Throwable {
-                    setSwipeUpSetting("1");
+                    setActiveOverlay(NAV_BAR_MODE_2BUTTON_OVERLAY);
                     base.evaluate();
                 }
+
+                private void setActiveOverlay(String overlayPackage) {
+                    setOverlayPackageEnabled(NAV_BAR_MODE_3BUTTON_OVERLAY,
+                            overlayPackage == NAV_BAR_MODE_3BUTTON_OVERLAY);
+                    setOverlayPackageEnabled(NAV_BAR_MODE_2BUTTON_OVERLAY,
+                            overlayPackage == NAV_BAR_MODE_2BUTTON_OVERLAY);
+                    setOverlayPackageEnabled(NAV_BAR_MODE_GESTURAL_OVERLAY,
+                            overlayPackage == NAV_BAR_MODE_GESTURAL_OVERLAY);
+
+                    // TODO: Wait until nav bar mode has applied
+                }
+
+                private void setOverlayPackageEnabled(String overlayPackage, boolean enable) {
+                    Log.d(TAG, "setOverlayPackageEnabled: " + overlayPackage + " " + enable);
+                    final String action = enable ? "enable" : "disable";
+                    try {
+                        UiDevice.getInstance(getInstrumentation()).executeShellCommand(
+                                "cmd overlay " + action + " " + overlayPackage);
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
             };
         } else {
             return base;
diff --git a/src/com/android/launcher3/config/BaseFlags.java b/src/com/android/launcher3/config/BaseFlags.java
index c260fa3..106d901 100644
--- a/src/com/android/launcher3/config/BaseFlags.java
+++ b/src/com/android/launcher3/config/BaseFlags.java
@@ -180,7 +180,7 @@
             currentValue = getFromStorage(context, defaultValue);
         }
 
-        void updateStorage(Context context, boolean value) {
+        public void updateStorage(Context context, boolean value) {
             SharedPreferences.Editor editor = context.getSharedPreferences(FLAGS_PREF_NAME,
                     Context.MODE_PRIVATE).edit();
             if (value == defaultValue) {
@@ -272,7 +272,7 @@
         }
 
         @Override
-        void updateStorage(Context context, boolean value) {
+        public void updateStorage(Context context, boolean value) {
             if (contentResolver == null) {
                 return;
             }
diff --git a/tests/Android.mk b/tests/Android.mk
index b9b703d..ca7395a 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -35,8 +35,8 @@
         ../src/com/android/launcher3/TestProtocol.java
 endif
 
-LOCAL_SDK_VERSION := current
 LOCAL_MODULE := ub-launcher-aosp-tapl
+LOCAL_SDK_VERSION := current
 
 include $(BUILD_STATIC_JAVA_LIBRARY)
 
@@ -47,18 +47,18 @@
 
 LOCAL_MODULE_TAGS := tests
 LOCAL_STATIC_JAVA_LIBRARIES := \
-	androidx.test.runner \
-	androidx.test.rules \
-	androidx.test.uiautomator_uiautomator \
-	mockito-target-minus-junit4
+    androidx.test.runner \
+    androidx.test.rules \
+    androidx.test.uiautomator_uiautomator \
+    mockito-target-minus-junit4
 
 ifneq (,$(wildcard frameworks/base))
-  LOCAL_PRIVATE_PLATFORM_APIS := true
-  LOCAL_STATIC_JAVA_LIBRARIES += launcher-aosp-tapl
+    LOCAL_PRIVATE_PLATFORM_APIS := true
+    LOCAL_STATIC_JAVA_LIBRARIES += launcher-aosp-tapl
 else
-  LOCAL_SDK_VERSION := 28
-  LOCAL_MIN_SDK_VERSION := 21
-  LOCAL_STATIC_JAVA_LIBRARIES += ub-launcher-aosp-tapl
+    LOCAL_SDK_VERSION := 28
+    LOCAL_MIN_SDK_VERSION := 21
+    LOCAL_STATIC_JAVA_LIBRARIES += ub-launcher-aosp-tapl
 endif
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 19b368f..fd6ddce 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -17,20 +17,19 @@
 package com.android.launcher3.tapl;
 
 import static com.android.launcher3.TestProtocol.BACKGROUND_APP_STATE_ORDINAL;
-import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
 
 import android.app.ActivityManager;
 import android.app.Instrumentation;
 import android.app.UiAutomation;
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.graphics.Point;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Parcelable;
 import android.os.SystemClock;
-import android.provider.Settings;
 import android.util.Log;
 import android.view.InputDevice;
 import android.view.MotionEvent;
@@ -48,7 +47,7 @@
 import androidx.test.uiautomator.Until;
 
 import com.android.launcher3.TestProtocol;
-import com.android.quickstep.SwipeUpSetting;
+import com.android.systemui.shared.system.QuickStepContract;
 
 import org.junit.Assert;
 
@@ -175,13 +174,15 @@
     }
 
     private boolean isSwipeUpEnabled() {
-        final boolean swipeUpEnabledDefaultValue = SwipeUpSetting.isSwipeUpEnabledDefaultValue();
-        return SwipeUpSetting.isSwipeUpSettingAvailable() ?
-                Settings.Secure.getInt(
-                        mInstrumentation.getTargetContext().getContentResolver(),
-                        SWIPE_UP_SETTING_NAME,
-                        swipeUpEnabledDefaultValue ? 1 : 0) == 1 :
-                swipeUpEnabledDefaultValue;
+        final Context baseContext = mInstrumentation.getTargetContext();
+        try {
+            // Workaround, use constructed context because both the instrumentation context and the
+            // app context are not constructed with resources that take overlays into account
+            Context ctx = baseContext.createPackageContext(getLauncherPackageName(), 0);
+            return !QuickStepContract.isLegacyMode(ctx);
+        } catch (PackageManager.NameNotFoundException e) {
+            return false;
+        }
     }
 
     static void log(String message) {