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

Commit a429e470 authored by Roman Birg's avatar Roman Birg Committed by Ricardo Cerqueira
Browse files

SystemUI: bail out of recents-to-home animation when losing focus



In the case when recents is animating out, and an application happens to
immediately add a view to the window manager, the recents view would
lose its focus, but the animations would continue to run, breaking the
behavior in certain cases.

Bail out of the recents activity and override the pending transition to
be disabled to not distrubt the newly added window.

Ref: CYNGNOS-1136

Change-Id: I5998a9dcf21b1369473f04ea4d867c5f2543d6df
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 26c932ea
Loading
Loading
Loading
Loading
+28 −2
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
    // Runnable to be executed after we paused ourselves
    Runnable mAfterPauseRunnable;

    private ReferenceCountedTrigger mExitTrigger;

    /**
     * A common Runnable to finish Recents either by calling finish() (with a custom animation) or
     * launching Home with some ActivityOptions.  Generally we always launch home when we exit
@@ -95,6 +97,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
    class FinishRecentsRunnable implements Runnable {
        Intent mLaunchIntent;
        ActivityOptions mLaunchOpts;
        boolean mAbort = false;

        /**
         * Creates a finish runnable that starts the specified intent, using the given
@@ -105,8 +108,15 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
            mLaunchOpts = opts;
        }

        public void setAbort(boolean run) {
            this.mAbort = run;
        }

        @Override
        public void run() {
            if (mAbort) {
                return;
            }
            // Finish Recents
            if (mLaunchIntent != null) {
                try {
@@ -317,13 +327,26 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        return false;
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (!hasFocus && mExitTrigger != null && mExitTrigger.getCount() > 0) {
            // we are animating recents out and the window has lost focus during the
            // animation. we need to stop everything we're doing now and get out
            // without any animations (since we were already animating)
            mFinishLaunchHomeRunnable.setAbort(true);
            finish();
            overridePendingTransition(0, 0);
        }
    }

    /** Dismisses Recents directly to Home. */
    void dismissRecentsToHomeRaw(boolean animated) {
        if (animated) {
            ReferenceCountedTrigger exitTrigger = new ReferenceCountedTrigger(this,
            mExitTrigger = new ReferenceCountedTrigger(this,
                    null, mFinishLaunchHomeRunnable, null);
            mRecentsView.startExitToHomeAnimation(
                    new ViewAnimation.TaskViewExitContext(exitTrigger));
                    new ViewAnimation.TaskViewExitContext(mExitTrigger));
        } else {
            mFinishLaunchHomeRunnable.run();
        }
@@ -458,6 +481,9 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
    @Override
    protected void onStop() {
        super.onStop();

        mExitTrigger = null;

        MetricsLogger.hidden(this, MetricsLogger.OVERVIEW_ACTIVITY);
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        SystemServicesProxy ssp = loader.getSystemServicesProxy();