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

Commit 5675f018 authored by Winson Chung's avatar Winson Chung
Browse files

DO NOT MERGE. Don't use visibility flags to determine whether to dismiss Recents. (Bug 18802531)

We can use our normal visibility check to dismiss Recents when the screen is off,
since the system broadcast can occur after the activity is stopped.  We should use
the same mechanism we use to test visibility when launching Recents and just see
if it is the top most activity.

Change-Id: Ib9c01e78fd9221c4fb0ffcc80a01a0c58fb96836
parent b018399a
Loading
Loading
Loading
Loading
+12 −43
Original line number Diff line number Diff line
@@ -86,8 +86,8 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
    final static int sMinToggleDelay = 350;

    final static String sToggleRecentsAction = "com.android.systemui.recents.SHOW_RECENTS";
    final static String sRecentsPackage = "com.android.systemui";
    final static String sRecentsActivity = "com.android.systemui.recents.RecentsActivity";
    public final static String sRecentsPackage = "com.android.systemui";
    public final static String sRecentsActivity = "com.android.systemui.recents.RecentsActivity";

    /**
     * An implementation of ITaskStackListener, that allows us to listen for changes to the system
@@ -111,10 +111,11 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
        public void run() {
            RecentsConfiguration config = RecentsConfiguration.getInstance();
            if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) {
                ActivityManager.RunningTaskInfo runningTaskInfo = getTopMostTask();
                RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
                SystemServicesProxy ssp = loader.getSystemServicesProxy();
                ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getTopMostTask();

                // Load the next task only if we aren't svelte
                RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
                RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
                loader.preloadTasks(plan, true /* isTopTaskHome */);
                RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options();
@@ -272,8 +273,8 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
    }
    void hideRecents(boolean triggeredFromAltTab, boolean triggeredFromHomeKey) {
        if (mBootCompleted) {
            ActivityManager.RunningTaskInfo topTask = getTopMostTask();
            if (topTask != null && isRecentsTopMost(topTask, null)) {
            ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask();
            if (topTask != null && mSystemServicesProxy.isRecentsTopMost(topTask, null)) {
                // Notify recents to hide itself
                Intent intent = createLocalBroadcastIntent(mContext, ACTION_HIDE_RECENTS_ACTIVITY);
                intent.putExtra(EXTRA_TRIGGERED_FROM_ALT_TAB, triggeredFromAltTab);
@@ -336,7 +337,7 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
        // Return early if there are no tasks
        if (stack.getTaskCount() == 0) return;

        ActivityManager.RunningTaskInfo runningTask = getTopMostTask();
        ActivityManager.RunningTaskInfo runningTask = mSystemServicesProxy.getTopMostTask();
        // Return early if there is no running task (can't determine affiliated tasks in this case)
        if (runningTask == null) return;
        // Return early if the running task is in the home stack (optimization)
@@ -480,38 +481,6 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
        }
    }

    /** Gets the top task. */
    ActivityManager.RunningTaskInfo getTopMostTask() {
        SystemServicesProxy ssp = mSystemServicesProxy;
        List<ActivityManager.RunningTaskInfo> tasks = ssp.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            return tasks.get(0);
        }
        return null;
    }

    /** Returns whether the recents is currently running */
    boolean isRecentsTopMost(ActivityManager.RunningTaskInfo topTask, AtomicBoolean isHomeTopMost) {
        SystemServicesProxy ssp = mSystemServicesProxy;
        if (topTask != null) {
            ComponentName topActivity = topTask.topActivity;

            // Check if the front most activity is recents
            if (topActivity.getPackageName().equals(sRecentsPackage) &&
                    topActivity.getClassName().equals(sRecentsActivity)) {
                if (isHomeTopMost != null) {
                    isHomeTopMost.set(false);
                }
                return true;
            }

            if (isHomeTopMost != null) {
                isHomeTopMost.set(ssp.isInHomeStack(topTask.id));
            }
        }
        return false;
    }

    /** Toggles the recents activity */
    void toggleRecentsActivity() {
        // If the user has toggled it too quickly, then just eat up the event here (it's better than
@@ -523,9 +492,9 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta

        // If Recents is the front most activity, then we should just communicate with it directly
        // to launch the first task or dismiss itself
        ActivityManager.RunningTaskInfo topTask = getTopMostTask();
        ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask();
        AtomicBoolean isTopTaskHome = new AtomicBoolean(true);
        if (topTask != null && isRecentsTopMost(topTask, isTopTaskHome)) {
        if (topTask != null && mSystemServicesProxy.isRecentsTopMost(topTask, isTopTaskHome)) {
            // Notify recents to toggle itself
            Intent intent = createLocalBroadcastIntent(mContext, ACTION_TOGGLE_RECENTS_ACTIVITY);
            mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
@@ -540,9 +509,9 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
    /** Starts the recents activity if it is not already running */
    void startRecentsActivity() {
        // Check if the top task is in the home stack, and start the recents activity
        ActivityManager.RunningTaskInfo topTask = getTopMostTask();
        ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask();
        AtomicBoolean isTopTaskHome = new AtomicBoolean(true);
        if (topTask == null || !isRecentsTopMost(topTask, isTopTaskHome)) {
        if (topTask == null || !mSystemServicesProxy.isRecentsTopMost(topTask, isTopTaskHome)) {
            startRecentsActivity(topTask, isTopTaskHome.get());
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -65,7 +65,8 @@ public class Constants {
        }

        public static class TaskStackView {
            public static final int TaskStackOverscrollRange = 150;
            public static final int TaskStackMinOverscrollRange = 32;
            public static final int TaskStackMaxOverscrollRange = 128;
            public static final int FilterStartDelay = 25;
        }
    }
+4 −5
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        DebugOverlayView.DebugOverlayViewCallbacks {

    RecentsConfiguration mConfig;
    boolean mVisible;
    long mLastTabKeyEventTime;

    // Top level views
@@ -315,7 +314,8 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView

    /** Dismisses recents if we are already visible and the intent is to toggle the recents view */
    boolean dismissRecentsToFocusedTaskOrHome(boolean checkFilteredStackState) {
        if (mVisible) {
        SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
        if (ssp.isRecentsTopMost(ssp.getTopMostTask(), null)) {
            // If we currently have filtered stacks, then unfilter those first
            if (checkFilteredStackState &&
                mRecentsView.unfilterFilteredStacks()) return true;
@@ -349,7 +349,8 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView

    /** Dismisses Recents directly to Home if we currently aren't transitioning. */
    boolean dismissRecentsToHome(boolean animated) {
        if (mVisible) {
        SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
        if (ssp.isRecentsTopMost(ssp.getTopMostTask(), null)) {
            // Return to Home
            dismissRecentsToHomeRaw(animated);
            return true;
@@ -429,7 +430,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
    @Override
    protected void onStart() {
        super.onStart();
        mVisible = true;
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        SystemServicesProxy ssp = loader.getSystemServicesProxy();
        AlternateRecentsComponent.notifyVisibilityChanged(this, ssp, true);
@@ -457,7 +457,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
    @Override
    protected void onStop() {
        super.onStop();
        mVisible = false;
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        SystemServicesProxy ssp = loader.getSystemServicesProxy();
        AlternateRecentsComponent.notifyVisibilityChanged(this, ssp, false);
+33 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.view.SurfaceControl;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import com.android.systemui.R;
import com.android.systemui.recents.AlternateRecentsComponent;
import com.android.systemui.recents.Constants;

import java.io.IOException;
@@ -66,6 +67,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Acts as a shim around the real system services that we need to access data from, and provides
@@ -217,6 +219,37 @@ public class SystemServicesProxy {
        return mAm.getRunningTasks(numTasks);
    }

    /** Returns the top task. */
    public ActivityManager.RunningTaskInfo getTopMostTask() {
        List<ActivityManager.RunningTaskInfo> tasks = getRunningTasks(1);
        if (!tasks.isEmpty()) {
            return tasks.get(0);
        }
        return null;
    }

    /** Returns whether the recents is currently running */
    public boolean isRecentsTopMost(ActivityManager.RunningTaskInfo topTask,
            AtomicBoolean isHomeTopMost) {
        if (topTask != null) {
            ComponentName topActivity = topTask.topActivity;

            // Check if the front most activity is recents
            if (topActivity.getPackageName().equals(AlternateRecentsComponent.sRecentsPackage) &&
                    topActivity.getClassName().equals(AlternateRecentsComponent.sRecentsActivity)) {
                if (isHomeTopMost != null) {
                    isHomeTopMost.set(false);
                }
                return true;
            }

            if (isHomeTopMost != null) {
                isHomeTopMost.set(isInHomeStack(topTask.id));
            }
        }
        return false;
    }

    /** Returns whether the specified task is in the home stack */
    public boolean isInHomeStack(int taskId) {
        if (mAm == null) return false;
+10 −9
Original line number Diff line number Diff line
@@ -273,20 +273,21 @@ class TaskStackViewTouchHandler implements SwipeHelper.Callback {
                break;
            }
            case MotionEvent.ACTION_UP: {
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                int velocity = (int) velocityTracker.getYVelocity(mActivePointerId);
                mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                int velocity = (int) mVelocityTracker.getYVelocity(mActivePointerId);
                if (mIsScrolling && (Math.abs(velocity) > mMinimumVelocity)) {
                    int overscrollRange = (int) (Math.min(1f,
                            Math.abs((float) velocity / mMaximumVelocity)) *
                            Constants.Values.TaskStackView.TaskStackOverscrollRange);
                    // Fling scroll
                    mScroller.mScroller.fling(0, mScroller.progressToScrollRange(mScroller.getStackScroll()),
                    float overscrollRangePct = Math.abs((float) velocity / mMaximumVelocity);
                    int overscrollRange = (int) (Math.min(1f, overscrollRangePct) *
                            (Constants.Values.TaskStackView.TaskStackMaxOverscrollRange -
                            Constants.Values.TaskStackView.TaskStackMinOverscrollRange));
                    mScroller.mScroller.fling(0,
                            mScroller.progressToScrollRange(mScroller.getStackScroll()),
                            0, velocity,
                            0, 0,
                            mScroller.progressToScrollRange(mSv.mLayoutAlgorithm.mMinScrollP),
                            mScroller.progressToScrollRange(mSv.mLayoutAlgorithm.mMaxScrollP),
                            0, overscrollRange);
                            0, Constants.Values.TaskStackView.TaskStackMinOverscrollRange +
                                    overscrollRange);
                    // Invalidate to kick off computeScroll
                    mSv.invalidate();
                } else if (mScroller.isScrollOutOfBounds()) {