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

Commit 6a38fca2 authored by Winson Chung's avatar Winson Chung
Browse files

Prevent unnecessary reordering of the home stack

- Just cancel the recents animation in-place when handling the home button
  to prevent it from being repositioned to the bottom (which stops home)
  and then starting it again (which restarts it)

Bug: 74405472
Test: Press home from an app, ensure launcher stop is only called once
Change-Id: Id41aa2f77c01767cc2c35445458b8f2db81200fc
parent a6855037
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ Landroid/app/AppOpsManager$PackageOps;->getOps()Ljava/util/List;
Landroid/app/AppOpsManager$PackageOps;->getPackageName()Ljava/lang/String;
Landroid/app/AppOpsManager$PackageOps;->getUid()I
Landroid/app/IActivityController$Stub;-><init>()V
Landroid/app/IActivityManager;->cancelRecentsAnimation()V
Landroid/app/IActivityManager;->cancelRecentsAnimation(Z)V
Landroid/app/IActivityManager;->cancelTaskWindowTransition(I)V
Landroid/app/IActivityManager;->closeSystemDialogs(Ljava/lang/String;)V
Landroid/app/IActivityManager;->getCurrentUser()Landroid/content/pm/UserInfo;
+1 −1
Original line number Diff line number Diff line
@@ -450,7 +450,7 @@ interface IActivityManager {
            in Intent intent, in String resolvedType, in Bundle options, int userId);
    void startRecentsActivity(in Intent intent, in IAssistDataReceiver assistDataReceiver,
            in IRecentsAnimationRunner recentsAnimationRunner);
    void cancelRecentsAnimation();
    void cancelRecentsAnimation(boolean restoreHomeStackPosition);
    int startActivityFromRecents(int taskId, in Bundle options);
    Bundle getActivityOptions(in IBinder token);
    List<IBinder> getAppTasks(in String callingPackage);
+2 −2
Original line number Diff line number Diff line
@@ -258,9 +258,9 @@ public class ActivityManagerWrapper {
    /**
     * Cancels the remote recents animation started from {@link #startRecentsActivity}.
     */
    public void cancelRecentsAnimation() {
    public void cancelRecentsAnimation(boolean restoreHomeStackPosition) {
        try {
            ActivityManager.getService().cancelRecentsAnimation();
            ActivityManager.getService().cancelRecentsAnimation(restoreHomeStackPosition);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to cancel recents animation", e);
        }
+7 −2
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider.ButtonI
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.statusbar.VibratorHelper;

import static android.view.KeyEvent.KEYCODE_HOME;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_CLICK;
import static android.view.accessibility.AccessibilityNodeInfo.ACTION_LONG_CLICK;

@@ -270,8 +271,12 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
                if (mCode != 0) {
                    if (doIt) {
                        // If there was a pending remote recents animation, then we need to
                        // cancel the animation now before we handle the button itself
                        ActivityManagerWrapper.getInstance().cancelRecentsAnimation();
                        // cancel the animation now before we handle the button itself. In the case
                        // where we are going home and the recents animation has already started,
                        // just cancel the recents animation, leaving the home stack in place
                        boolean isHomeKey = mCode == KEYCODE_HOME;
                        ActivityManagerWrapper.getInstance().cancelRecentsAnimation(!isHomeKey);

                        sendEvent(KeyEvent.ACTION_UP, 0);
                        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
                    } else {
+6 −3
Original line number Diff line number Diff line
@@ -204,6 +204,8 @@ import static android.view.WindowManager.TRANSIT_NONE;
import static android.view.WindowManager.TRANSIT_TASK_IN_PLACE;
import static android.view.WindowManager.TRANSIT_TASK_OPEN;
import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT;
import static com.android.server.wm.RecentsAnimationController.REORDER_MOVE_HOME_TO_ORIGINAL_POSITION;
import static com.android.server.wm.RecentsAnimationController.REORDER_KEEP_HOME_IN_PLACE;
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
import static org.xmlpull.v1.XmlPullParser.START_TAG;
@@ -257,7 +259,6 @@ import android.app.WaitResult;
import android.app.WindowConfiguration.ActivityType;
import android.app.WindowConfiguration.WindowingMode;
import android.app.admin.DevicePolicyCache;
import android.app.admin.DevicePolicyManager;
import android.app.assist.AssistContent;
import android.app.assist.AssistStructure;
import android.app.backup.IBackupManager;
@@ -5225,12 +5226,14 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public void cancelRecentsAnimation() {
    public void cancelRecentsAnimation(boolean restoreHomeStackPosition) {
        enforceCallerIsRecentsOrHasPermission(MANAGE_ACTIVITY_STACKS, "cancelRecentsAnimation()");
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (this) {
                mWindowManager.cancelRecentsAnimation();
                mWindowManager.cancelRecentsAnimation(restoreHomeStackPosition
                        ? REORDER_MOVE_HOME_TO_ORIGINAL_POSITION
                        : REORDER_KEEP_HOME_IN_PLACE);
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
Loading