Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5af8f39 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge changes from topics "launcher_nav_changes",...

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
parents 522cc2ff a5354e02
Loading
Loading
Loading
Loading
+4 −12
Original line number Diff line number Diff line
@@ -851,16 +851,6 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
            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 @@ public class WindowTransformSwipeHandler<T extends BaseDraggingActivity>
        // 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);
+20 −5
Original line number Diff line number Diff line
@@ -250,7 +250,11 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
    }

    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 class TaskView extends FrameLayout implements PageCallbacks, Reusable {

    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 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
                        resultCallbackHandler.post(() -> resultCallback.accept(true));
                    }
                }, resultCallbackHandler);
                if (freezeTaskList) {
                    ActivityOptionsCompat.setFreezeRecentTasksList(opts);
                }
                ActivityManagerWrapper.getInstance().startActivityFromRecentsAsync(mTask.key,
                        opts, (success) -> {
                            if (resultCallback != null && !success) {
+89 −0
Original line number Diff line number Diff line
/*
 * 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
+17 −10
Original line number Diff line number Diff line
@@ -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 android.util.Log;

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 @@ public class OverviewInteractionState {
    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 @@ public class OverviewInteractionState {

    // 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 @@ public class OverviewInteractionState {
        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 @@ public class OverviewInteractionState {
        }
    }

    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();
+1 −10
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ public class RecentTasksList extends TaskStackChangeListener {
    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 class RecentTasksList extends TaskStackChangeListener {
        });
    }

    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 @@ public class RecentTasksList extends TaskStackChangeListener {
        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
Loading