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

Commit 2b093941 authored by Winson Chung's avatar Winson Chung
Browse files

Add support for swiping back to the shortcut that launched the activity



Bug: 129067201
Test: Open a shortcut on the workspace, go home

Change-Id: If5d3c3e8e93f09af50aa4994094657347890ef45
Signed-off-by: default avatarWinson Chung <winsonc@google.com>
parent 74aacfd4
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -26,10 +26,13 @@ import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SY

import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.app.ActivityOptions;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Binder;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.IBinder;
import android.view.View;

import androidx.annotation.Nullable;
@@ -37,6 +40,8 @@ import androidx.annotation.Nullable;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.model.WellbeingModel;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.proxy.ProxyActivityStarter;
import com.android.launcher3.proxy.StartActivityParams;
@@ -50,6 +55,7 @@ import com.android.launcher3.taskbar.TaskbarView;
import com.android.launcher3.uioverrides.RecentsViewStateController;
import com.android.launcher3.util.ActivityOptionsWrapper;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.ObjectWrapper;
import com.android.launcher3.util.UiThreadHelper;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.SysUINavigationMode;
@@ -67,6 +73,7 @@ import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.ActivityOptionsCompat;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Stream;

@@ -418,18 +425,38 @@ public abstract class BaseQuickstepLauncher extends Launcher
    }

    @Override
    public ActivityOptionsWrapper getActivityLaunchOptions(View v) {
    public ActivityOptionsWrapper getActivityLaunchOptions(View v, @Nullable ItemInfo item) {
        ActivityOptionsWrapper activityOptions =
                mAppTransitionManager.hasControlRemoteAppTransitionPermission()
                        ? mAppTransitionManager.getActivityLaunchOptions(this, v)
                        : super.getActivityLaunchOptions(v);
                        : super.getActivityLaunchOptions(v, item);
        if (mLastTouchUpTime > 0) {
            ActivityOptionsCompat.setLauncherSourceInfo(
                    activityOptions.options, mLastTouchUpTime);
        }
        addLaunchCookie(item, activityOptions.options);
        return activityOptions;
    }

    /**
     * Adds a new launch cookie for the activity launch of the given {@param info} if supported.
     */
    public void addLaunchCookie(ItemInfo info, ActivityOptions opts) {
        if (info == null) {
            return;
        }
        switch (info.itemType) {
            case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
            case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
            case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
                // Fall through and continue if it's an app or shortcut
                break;
            default:
                return;
        }
        opts.setLaunchCookie(ObjectWrapper.wrap(new Integer(info.id)));
    }

    public void setHintUserWillBeActive() {
        addActivityFlags(ACTIVITY_STATE_USER_WILL_BE_ACTIVE);
    }
+5 −2
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
@@ -1043,7 +1044,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
                interpolator, target, velocityPxPerMs));
    }

    protected abstract HomeAnimationFactory createHomeAnimationFactory(long duration);
    protected abstract HomeAnimationFactory createHomeAnimationFactory(
            ArrayList<IBinder> launchCookies, long duration);

    private final TaskStackChangeListener mActivityRestartListener = new TaskStackChangeListener() {
        @Override
@@ -1084,7 +1086,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            final RemoteAnimationTargetCompat runningTaskTarget = mRecentsAnimationTargets != null
                    ? mRecentsAnimationTargets.findTask(mGestureState.getRunningTaskId())
                    : null;
            HomeAnimationFactory homeAnimFactory = createHomeAnimationFactory(duration);
            HomeAnimationFactory homeAnimFactory = createHomeAnimationFactory(
                    runningTaskTarget.taskInfo.launchCookies, duration);
            mIsSwipingPipToHome = homeAnimFactory.supportSwipePipToHome()
                    && runningTaskTarget != null
                    && runningTaskTarget.taskInfo.pictureInPictureParams != null
+4 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.graphics.RectF;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
@@ -68,6 +69,7 @@ import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.UUID;
import java.util.function.Consumer;

@@ -126,7 +128,8 @@ public class FallbackSwipeHandler extends
    }

    @Override
    protected HomeAnimationFactory createHomeAnimationFactory(long duration) {
    protected HomeAnimationFactory createHomeAnimationFactory(ArrayList<IBinder> launchCookies,
            long duration) {
        mActiveAnimationFactory = new FallbackHomeAnimationFactory(duration);
        ActivityOptions options = ActivityOptions.makeCustomAnimation(mContext, 0, 0);
        Intent intent = new Intent(mGestureState.getHomeIntent());
+39 −12
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.RectF;
import android.os.IBinder;
import android.os.UserHandle;
import android.view.View;

@@ -47,6 +48,7 @@ import com.android.launcher3.anim.SpringAnimationBuilder;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.util.DynamicResource;
import com.android.launcher3.util.ObjectWrapper;
import com.android.launcher3.views.FloatingIconView;
import com.android.quickstep.util.AppCloseConfig;
import com.android.quickstep.util.RectFSpringAnim;
@@ -56,6 +58,8 @@ import com.android.quickstep.views.TaskView;
import com.android.systemui.plugins.ResourceProvider;
import com.android.systemui.shared.system.InputConsumerController;

import java.util.ArrayList;

/**
 * Temporary class to allow easier refactoring
 */
@@ -71,20 +75,12 @@ public class LauncherSwipeHandlerV2 extends


    @Override
    protected HomeAnimationFactory createHomeAnimationFactory(long duration) {
    protected HomeAnimationFactory createHomeAnimationFactory(ArrayList<IBinder> launchCookies,
            long duration) {
        HomeAnimationFactory homeAnimFactory;
        if (mActivity != null) {
            final TaskView runningTaskView = mRecentsView.getRunningTaskView();
            final View workspaceView;
            if (runningTaskView != null
                    && !mIsSwipingPipToHome
                    && runningTaskView.getTask().key.getComponent() != null) {
                workspaceView = mActivity.getWorkspace().getFirstMatchForAppClose(
                        runningTaskView.getTask().key.getComponent().getPackageName(),
                        UserHandle.of(runningTaskView.getTask().key.userId));
            } else {
                workspaceView = null;
            }
            final View workspaceView = findWorkspaceView(launchCookies,
                    mRecentsView.getRunningTaskView());
            boolean canUseWorkspaceView =
                    workspaceView != null && workspaceView.isAttachedToWindow();

@@ -232,6 +228,37 @@ public class LauncherSwipeHandlerV2 extends
        return homeAnimFactory;
    }

    /**
     * Returns the associated view on the workspace matching one of the launch cookies, or the app
     * associated with the running task.
     */
    @Nullable
    private View findWorkspaceView(ArrayList<IBinder> launchCookies, TaskView runningTaskView) {
        if (mIsSwipingPipToHome) {
            // Disable if swiping to PIP
            return null;
        }
        if (runningTaskView == null || runningTaskView.getTask() == null
                || runningTaskView.getTask().key.getComponent() == null) {
            // Disable if it's an invalid task
            return null;
        }

        // Find the associated item info for the launch cookie (if available)
        int launchCookieItemId = -1;
        for (IBinder cookie : launchCookies) {
            Integer itemId = ObjectWrapper.unwrap(cookie);
            if (itemId != null) {
                launchCookieItemId = itemId;
                break;
            }
        }

        return mActivity.getWorkspace().getFirstMatchForAppClose(launchCookieItemId,
                runningTaskView.getTask().key.getComponent().getPackageName(),
                UserHandle.of(runningTaskView.getTask().key.userId));
    }

    @Override
    protected void finishRecentsControllerToHome(Runnable callback) {
        mRecentsAnimationController.finish(
+5 −2
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import android.os.Handler;
import android.os.Looper;
import android.view.View;

import androidx.annotation.Nullable;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
@@ -48,6 +50,7 @@ import com.android.launcher3.WrappedLauncherAnimationRunner;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory;
import com.android.launcher3.statemanager.StateManager.StateHandler;
@@ -177,9 +180,9 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
    }

    @Override
    public ActivityOptionsWrapper getActivityLaunchOptions(final View v) {
    public ActivityOptionsWrapper getActivityLaunchOptions(final View v, @Nullable ItemInfo item) {
        if (!(v instanceof TaskView)) {
            return super.getActivityLaunchOptions(v);
            return super.getActivityLaunchOptions(v, item);
        }

        final TaskView taskView = (TaskView) v;
Loading