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

Commit 0635de29 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing Launcher assumption from OverviewCommand, so that it works with

fallback activity

Bug: 75979063
Change-Id: I3a851f6ce4725cee590eac9004eff1180f3780bb
parent 9bf5113e
Loading
Loading
Loading
Loading
+38 −61
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
 */
package com.android.quickstep;

import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;

@@ -35,11 +34,8 @@ import android.view.ViewConfiguration;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.states.InternalStateHandler;
import com.android.quickstep.ActivityControlHelper.ActivityInitListener;
import com.android.quickstep.ActivityControlHelper.FallbackActivityControllerHelper;
import com.android.quickstep.ActivityControlHelper.LauncherActivityControllerHelper;
@@ -54,7 +50,7 @@ import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
 * Helper class to handle various atomic commands for switching between Overview.
 */
@TargetApi(Build.VERSION_CODES.P)
public class OverviewCommandHelper extends InternalStateHandler {
public class OverviewCommandHelper {

    private static final long RECENTS_LAUNCH_DURATION = 200;

@@ -95,68 +91,45 @@ public class OverviewCommandHelper extends InternalStateHandler {
        homeIntent.setComponent(launcher).setPackage(null);
    }

    private void openRecents() {
        Intent intent = addToIntent(new Intent(homeIntent));
        mContext.startActivity(intent);
        initWhenReady();
    }

    public void onOverviewToggle() {
        // If currently screen pinning, do not enter overview
        if (ActivityManagerWrapper.getInstance().isScreenPinningActive()) {
        if (mAM.isScreenPinningActive()) {
            return;
        }

        ActivityManagerWrapper.getInstance().closeSystemWindows("recentapps");
        mAM.closeSystemWindows("recentapps");
        mMainThreadExecutor.execute(new RecentsActivityCommand<>());
    }

    public void onOverviewShown() {
        getLauncher().runOnUiThread(() -> {
                    if (isOverviewAlmostVisible()) {
                        final RecentsView rv = getLauncher().getOverviewPanel();
                        rv.snapToTaskAfterNext();
                    } else {
                        openRecents();
                    }
                }
        );
        mMainThreadExecutor.execute(new ShowRecentsCommand());
    }

    private boolean isOverviewAlmostVisible() {
        if (clearReference()) {
            return true;
        }
        if (!mAM.getRunningTask().topActivity.equals(launcher)) {
            return false;
    public ActivityControlHelper getActivityControlHelper() {
        if (DEBUG_START_FALLBACK_ACTIVITY) {
            return new FallbackActivityControllerHelper();
        } else {
            return new LauncherActivityControllerHelper();
        }
        Launcher launcher = getLauncher();
        return launcher != null && launcher.isStarted() && launcher.isInState(OVERVIEW);
    }

    private Launcher getLauncher() {
        return (Launcher) LauncherAppState.getInstance(mContext).getModel().getCallback();
    }
    private class ShowRecentsCommand extends RecentsActivityCommand {

        @Override
    protected boolean init(Launcher launcher, boolean alreadyOnHome) {
        AbstractFloatingView.closeAllOpenViews(launcher, alreadyOnHome);
        launcher.getStateManager().goToState(OVERVIEW, alreadyOnHome);
        clearReference();
        protected boolean handleCommand(long elapsedTime) {
            RecentsView recents = mHelper.getVisibleRecentsView();
            if (recents != null) {
                recents.snapToTaskAfterNext();
                return true;
            } else {
                return false;
            }

    public ActivityControlHelper getActivityControlHelper() {
        if (DEBUG_START_FALLBACK_ACTIVITY) {
            return new FallbackActivityControllerHelper();
        } else {
            return new LauncherActivityControllerHelper();
        }
    }

    private class RecentsActivityCommand<T extends BaseDraggingActivity> implements Runnable {

        private final ActivityControlHelper<T> mHelper;
        protected final ActivityControlHelper<T> mHelper;
        private final long mCreateTime;
        private final int mRunningTaskId;

@@ -166,7 +139,7 @@ public class OverviewCommandHelper extends InternalStateHandler {
        public RecentsActivityCommand() {
            mHelper = getActivityControlHelper();
            mCreateTime = SystemClock.elapsedRealtime();
            mRunningTaskId = ActivityManagerWrapper.getInstance().getRunningTask().id;
            mRunningTaskId = mAM.getRunningTask().id;

            // Preload the plan
            mRecentsModel.loadTasks(mRunningTaskId, null);
@@ -177,20 +150,7 @@ public class OverviewCommandHelper extends InternalStateHandler {
            long elapsedTime = mCreateTime - mLastToggleTime;
            mLastToggleTime = mCreateTime;

            // TODO: We need to fix this case with PIP, when an activity first enters PIP, it shows
            //       the menu activity which takes window focus, preventing the right condition from
            //       being run below
            RecentsView recents = mHelper.getVisibleRecentsView();
            if (recents != null) {
                // Launch the next task
                recents.showNextTask();
            } else {
                if (elapsedTime < ViewConfiguration.getDoubleTapTimeout()) {
                    // The user tried to launch back into overview too quickly, either after
                    // launching an app, or before overview has actually shown, just ignore for now
                    return;
                }

            if (!handleCommand(elapsedTime)) {
                // Start overview
                if (mHelper.switchToRecentsIfVisible()) {
                    SysuiEventLogger.writeDummyRecentsTransition(0);
@@ -203,6 +163,23 @@ public class OverviewCommandHelper extends InternalStateHandler {
            }
        }

        protected boolean handleCommand(long elapsedTime) {
            // TODO: We need to fix this case with PIP, when an activity first enters PIP, it shows
            //       the menu activity which takes window focus, preventing the right condition from
            //       being run below
            RecentsView recents = mHelper.getVisibleRecentsView();
            if (recents != null) {
                // Launch the next task
                recents.showNextTask();
                return true;
            } else if (elapsedTime < ViewConfiguration.getDoubleTapTimeout()) {
                // The user tried to launch back into overview too quickly, either after
                // launching an app, or before overview has actually shown, just ignore for now
                return true;
            }
            return false;
        }

        private boolean onActivityReady(T activity, Boolean wasVisible) {
            activity.<RecentsView>getOverviewPanel().setCurrentTask(mRunningTaskId);
            AbstractFloatingView.closeAllOpenViews(activity, wasVisible);
+0 −5
Original line number Diff line number Diff line
@@ -831,11 +831,6 @@ public abstract class RecentsView<T extends BaseActivity>
        snapToPageRelative(1);
    }

    public void launchNextTask() {
        final TaskView nextTask = (TaskView) getChildAt(getNextPage());
        nextTask.launchTask(true);
    }

    public void setContentAlpha(float alpha) {
        if (mContentAlpha == alpha) {
            return;