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

Commit c9103fa7 authored by Roman Birg's avatar Roman Birg Committed by Abhisek Devkota
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 a12d8f96
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -39,7 +38,6 @@ import android.view.ViewStub;
import android.widget.Toast;

import com.android.systemui.R;
import com.android.systemui.recents.RecentsConfiguration;
import com.android.systemui.recents.misc.DebugTrigger;
import com.android.systemui.recents.misc.ReferenceCountedTrigger;
import com.android.systemui.recents.misc.SystemServicesProxy;
@@ -87,6 +85,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
    FinishRecentsRunnable mFinishLaunchHomeRunnable;

    private PhoneStatusBar mStatusBar;
    private ReferenceCountedTrigger mExitTrigger;

    /**
     * A common Runnable to finish Recents either by calling finish() (with a custom animation) or
@@ -98,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
@@ -108,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) {
                if (mLaunchOpts != null) {
@@ -355,13 +362,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();
        }
@@ -477,6 +497,9 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
    @Override
    protected void onStop() {
        super.onStop();

        mExitTrigger = null;

        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        SystemServicesProxy ssp = loader.getSystemServicesProxy();
        AlternateRecentsComponent.notifyVisibilityChanged(this, ssp, false);