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

Commit e8320129 authored by Winson Chung's avatar Winson Chung
Browse files

2/ Replace legacy start recents activity with preload activity

- This is the only usage of the existing recents animation logic,
  the non-preload logic will be removed in the following CL

Flag: EXEMPT cleaning up unused code
Bug: 359608026
Test: atest RecentsAnimationTests
Change-Id: I57574356d4604ccdc1a6a6007193410a688a8dfc
parent c906b847
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -68,7 +68,6 @@ import android.os.RemoteCallback;
import android.os.StrictMode;
import android.os.WorkSource;
import android.service.voice.IVoiceInteractionSession;
import android.view.IRecentsAnimationRunner;
import android.view.IRemoteAnimationRunner;
import android.view.RemoteAnimationDefinition;
import android.view.RemoteAnimationAdapter;
@@ -129,13 +128,12 @@ interface IActivityTaskManager {
    int startActivityFromGameSession(IApplicationThread caller, in String callingPackage,
            in String callingFeatureId, int callingPid, int callingUid, in Intent intent,
            int taskId, int userId);
    void startRecentsActivity(in Intent intent, in long eventTime,
            in IRecentsAnimationRunner recentsAnimationRunner);
    int startActivityFromRecents(int taskId, in Bundle options);
    int startActivityAsCaller(in IApplicationThread caller, in String callingPackage,
            in Intent intent, in String resolvedType, in IBinder resultTo, in String resultWho,
            int requestCode, int flags, in ProfilerInfo profilerInfo, in Bundle options,
            boolean ignoreTargetSecurity, int userId);
    void preloadRecentsActivity(in Intent intent);

    boolean isActivityStartAllowedOnDisplay(int displayId, in Intent intent, in String resolvedType,
            int userId);
@@ -167,7 +165,6 @@ interface IActivityTaskManager {
    /** Focuses the top task on a display if it isn't already focused. Used for Recents. */
    void focusTopTask(int displayId);

    void cancelRecentsAnimation(boolean restoreHomeRootTaskPosition);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.UPDATE_LOCK_TASK_PACKAGES)")
    void updateLockTaskPackages(int userId, in String[] packages);
    boolean isInLockTaskMode();
+4 −66
Original line number Diff line number Diff line
@@ -35,9 +35,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -45,9 +43,6 @@ import android.os.SystemClock;
import android.provider.Settings;
import android.util.Log;
import android.view.Display;
import android.view.IRecentsAnimationController;
import android.view.IRecentsAnimationRunner;
import android.view.RemoteAnimationTarget;
import android.window.TaskSnapshot;

import com.android.internal.app.IVoiceInteractionManagerService;
@@ -55,7 +50,6 @@ import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.ThumbnailData;

import java.util.List;
import java.util.function.Consumer;

public class ActivityManagerWrapper {

@@ -190,69 +184,13 @@ public class ActivityManagerWrapper {
    }

    /**
     * Starts the recents activity. The caller should manage the thread on which this is called.
     * Preloads the recents activity. The caller should manage the thread on which this is called.
     */
    public void startRecentsActivity(Intent intent, long eventTime,
            final RecentsAnimationListener animationHandler, final Consumer<Boolean> resultCallback,
            Handler resultCallbackHandler) {
        boolean result = startRecentsActivity(intent, eventTime, animationHandler);
        if (resultCallback != null && resultCallbackHandler != null) {
            resultCallbackHandler.post(new Runnable() {
                @Override
                public void run() {
                    resultCallback.accept(result);
                }
            });
        }
    }

    /**
     * Starts the recents activity. The caller should manage the thread on which this is called.
     */
    public boolean startRecentsActivity(
            Intent intent, long eventTime, RecentsAnimationListener animationHandler) {
    public void preloadRecentsActivity(Intent intent) {
        try {
            IRecentsAnimationRunner runner = null;
            if (animationHandler != null) {
                runner = new IRecentsAnimationRunner.Stub() {
                    @Override
                    public void onAnimationStart(IRecentsAnimationController controller,
                            RemoteAnimationTarget[] apps, RemoteAnimationTarget[] wallpapers,
                            Rect homeContentInsets, Rect minimizedHomeBounds,
                            Bundle extras) {
                        final RecentsAnimationControllerCompat controllerCompat =
                                new RecentsAnimationControllerCompat(controller);
                        animationHandler.onAnimationStart(controllerCompat, apps,
                                wallpapers, homeContentInsets, minimizedHomeBounds, extras);
                    }

                    @Override
                    public void onAnimationCanceled(int[] taskIds, TaskSnapshot[] taskSnapshots) {
                        animationHandler.onAnimationCanceled(
                                ThumbnailData.wrap(taskIds, taskSnapshots));
                    }

                    @Override
                    public void onTasksAppeared(RemoteAnimationTarget[] apps) {
                        animationHandler.onTasksAppeared(apps);
                    }
                };
            }
            getService().startRecentsActivity(intent, eventTime, runner);
            return true;
            getService().preloadRecentsActivity(intent);
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * Cancels the remote recents animation started from {@link #startRecentsActivity}.
     */
    public void cancelRecentsAnimation(boolean restoreHomeRootTaskPosition) {
        try {
            getService().cancelRecentsAnimation(restoreHomeRootTaskPosition);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to cancel recents animation", e);
            Log.w(TAG, "Failed to preload recents activity", e);
        }
    }

+5 −33
Original line number Diff line number Diff line
@@ -124,8 +124,6 @@ import static com.android.server.wm.ActivityTaskSupervisor.ON_TOP;
import static com.android.server.wm.ActivityTaskSupervisor.REMOVE_FROM_RECENTS;
import static com.android.server.wm.BackgroundActivityStartController.BalVerdict;
import static com.android.server.wm.LockTaskController.LOCK_TASK_AUTH_DONT_LOCK;
import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_IN_PLACE;
import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_TO_ORIGINAL_POSITION;
import static com.android.server.wm.RootWindowContainer.MATCH_ATTACHED_TASK_ONLY;
import static com.android.server.wm.RootWindowContainer.MATCH_ATTACHED_TASK_OR_RECENT_TASKS;
import static com.android.server.wm.Task.REPARENT_KEEP_ROOT_TASK_AT_FRONT;
@@ -241,7 +239,6 @@ import android.util.SparseArray;
import android.util.TimeUtils;
import android.util.proto.ProtoOutputStream;
import android.view.Display;
import android.view.IRecentsAnimationRunner;
import android.view.RemoteAnimationAdapter;
import android.view.RemoteAnimationDefinition;
import android.view.WindowManager;
@@ -1773,16 +1770,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    }

    /**
     * Start the recents activity to perform the recents animation.
     * Preload the recents activity.
     *
     * @param intent                 The intent to start the recents activity.
     * @param eventTime              When the (touch) event is triggered to start recents activity.
     * @param recentsAnimationRunner Pass {@code null} to only preload the activity.
     * @param intent The intent to preload the recents activity.
     */
    @Override
    public void startRecentsActivity(Intent intent, long eventTime,
            @Nullable IRecentsAnimationRunner recentsAnimationRunner) {
        enforceTaskPermission("startRecentsActivity()");
    public void preloadRecentsActivity(Intent intent) {
        enforceTaskPermission("preloadRecentsActivity()");
        final int callingPid = Binder.getCallingPid();
        final int callingUid = Binder.getCallingUid();
        final long origId = Binder.clearCallingIdentity();
@@ -1793,15 +1787,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                final int recentsUid = mRecentTasks.getRecentsComponentUid();
                final WindowProcessController caller = getProcessController(callingPid, callingUid);

                // Start a new recents animation
                final RecentsAnimation anim = new RecentsAnimation(this, mTaskSupervisor,
                        getActivityStartController(), mWindowManager, intent, recentsComponent,
                        recentsFeatureId, recentsUid, caller);
                if (recentsAnimationRunner == null) {
                anim.preloadRecentsActivity();
                } else {
                    anim.startRecentsActivity(recentsAnimationRunner, eventTime);
                }
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
@@ -2565,23 +2554,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
    }

    @Override
    public void cancelRecentsAnimation(boolean restoreHomeRootTaskPosition) {
        enforceTaskPermission("cancelRecentsAnimation()");
        final long callingUid = Binder.getCallingUid();
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                // Cancel the recents animation synchronously (do not hold the WM lock)
                mWindowManager.cancelRecentsAnimation(restoreHomeRootTaskPosition
                        ? REORDER_MOVE_TO_ORIGINAL_POSITION
                        : REORDER_KEEP_IN_PLACE, "cancelRecentsAnimation/uid=" + callingUid);
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }

    @Override
    public void startSystemLockTaskMode(int taskId) {
        enforceTaskPermission("startSystemLockTaskMode");
+0 −3
Original line number Diff line number Diff line
@@ -1481,9 +1481,6 @@ public class RecentTasksTest extends WindowTestsBase {
        assertSecurityException(expectCallable,
                () -> mAtm.unregisterTaskStackListener(null));
        assertSecurityException(expectCallable, () -> mAtm.cancelTaskWindowTransition(0));
        assertSecurityException(expectCallable, () -> mAtm.startRecentsActivity(null, 0,
                null));
        assertSecurityException(expectCallable, () -> mAtm.cancelRecentsAnimation(true));
        assertSecurityException(expectCallable, () -> mAtm.stopAppSwitches());
        assertSecurityException(expectCallable, () -> mAtm.resumeAppSwitches());
    }
+3 −276

File changed.

Preview size limit exceeded, changes collapsed.