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

Commit 48efdda7 authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Fix issue with race when updating/using layout algorithm." into...

Merge "Merge "Fix issue with race when updating/using layout algorithm." into oc-mr1-dev am: 5c53c6c6 am: 366f83c9"
parents 7a517282 7ce8e3b8
Loading
Loading
Loading
Loading
+64 −82
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static android.view.View.MeasureSpec;
import android.app.ActivityManager;
import android.app.ActivityManager.TaskSnapshot;
import android.app.ActivityOptions;
import android.app.ActivityOptions.OnAnimationFinishedListener;
import android.app.ActivityOptions.OnAnimationStartedListener;
import android.content.ActivityNotFoundException;
import android.content.Context;
@@ -36,6 +35,7 @@ import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.SystemClock;
import android.util.ArraySet;
import android.util.Log;
import android.util.MutableBoolean;
import android.util.Pair;
@@ -76,6 +76,7 @@ import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
import com.android.systemui.recents.model.RecentsTaskLoadPlan;
import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.recents.model.Task;
import com.android.systemui.recents.model.Task.TaskKey;
import com.android.systemui.recents.model.TaskGrouping;
import com.android.systemui.recents.model.TaskStack;
import com.android.systemui.recents.model.ThumbnailData;
@@ -110,6 +111,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    // duration, then we will toggle recents after this duration.
    private final static int FAST_ALT_TAB_DELAY_MS = 225;

    private final static ArraySet<TaskKey> EMPTY_SET = new ArraySet<>();

    public final static String RECENTS_PACKAGE = "com.android.systemui";
    public final static String RECENTS_ACTIVITY = "com.android.systemui.recents.RecentsActivity";

@@ -129,39 +132,38 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
            // Preloads the next task
            RecentsConfiguration config = Recents.getConfiguration();
            if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) {

                // Load the next task only if we aren't svelte
                SystemServicesProxy ssp = Recents.getSystemServices();
                ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getRunningTask();
                RecentsTaskLoader loader = Recents.getTaskLoader();
                RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
                loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */);
                TaskStack stack = plan.getTaskStack();
                RecentsActivityLaunchState launchState = new RecentsActivityLaunchState();
                RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options();

                // This callback is made when a new activity is launched and the old one is paused
                // so ignore the current activity and try and preload the thumbnail for the
                // previous one.
                VisibilityReport visibilityReport;
                synchronized (mDummyStackView) {
                    mDummyStackView.getStack().removeAllTasks(false /* notifyStackChanges */);
                    mDummyStackView.setTasks(plan.getTaskStack(), false /* allowNotify */);
                    updateDummyStackViewLayout(plan.getTaskStack(),
                synchronized (mBackgroundLayoutAlgorithm) {
                    // This callback is made when a new activity is launched and the old one is
                    // paused so ignore the current activity and try and preload the thumbnail for
                    // the previous one.
                    updateDummyStackViewLayout(mBackgroundLayoutAlgorithm, stack,
                            getWindowRect(null /* windowRectOverride */));

                    // Launched from app is always the worst case (in terms of how many
                    // thumbnails/tasks visible)
                    RecentsActivityLaunchState launchState = new RecentsActivityLaunchState();
                    launchState.launchedFromApp = true;
                    mDummyStackView.updateLayoutAlgorithm(true /* boundScroll */, launchState);
                    visibilityReport = mDummyStackView.computeStackVisibilityReport();
                }
                    mBackgroundLayoutAlgorithm.update(plan.getTaskStack(), EMPTY_SET, launchState);
                    VisibilityReport visibilityReport =
                            mBackgroundLayoutAlgorithm.computeStackVisibilityReport(
                                    stack.getStackTasks());

                RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options();
                    launchOpts.runningTaskId = runningTaskInfo != null ? runningTaskInfo.id : -1;
                    launchOpts.numVisibleTasks = visibilityReport.numVisibleTasks;
                    launchOpts.numVisibleTaskThumbnails = visibilityReport.numVisibleThumbnails;
                    launchOpts.onlyLoadForCache = true;
                    launchOpts.onlyLoadPausedActivities = true;
                    launchOpts.loadThumbnails = true;
                }
                loader.loadTasks(mContext, plan, launchOpts);
            }
        }
@@ -230,17 +232,15 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    boolean mLaunchedWhileDocking;

    // Task launching
    Rect mTaskStackBounds = new Rect();
    Rect mTmpBounds = new Rect();
    TaskViewTransform mTmpTransform = new TaskViewTransform();
    int mStatusBarHeight;
    int mNavBarHeight;
    int mNavBarWidth;
    int mTaskBarHeight;

    // Header (for transition)
    TaskViewHeader mHeaderBar;
    final Object mHeaderBarLock = new Object();
    protected TaskStackView mDummyStackView;
    private TaskStackView mDummyStackView;
    private TaskStackLayoutAlgorithm mBackgroundLayoutAlgorithm;

    // Variables to keep track of if we need to start recents after binding
    protected boolean mTriggeredFromAltTab;
@@ -259,6 +259,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    public RecentsImpl(Context context) {
        mContext = context;
        mHandler = new Handler();
        mBackgroundLayoutAlgorithm = new TaskStackLayoutAlgorithm(context, null);

        // Initialize the static foreground thread
        ForegroundThread.get();
@@ -288,8 +289,9 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener

    public void onConfigurationChanged() {
        reloadResources();
        synchronized (mDummyStackView) {
        mDummyStackView.reloadOnConfigurationChange();
        synchronized (mBackgroundLayoutAlgorithm) {
            mBackgroundLayoutAlgorithm.reloadOnConfigurationChange(mContext);
        }
    }

@@ -698,12 +700,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    private void reloadResources() {
        Resources res = mContext.getResources();

        mStatusBarHeight = res.getDimensionPixelSize(
                com.android.internal.R.dimen.status_bar_height);
        mNavBarHeight = res.getDimensionPixelSize(
                com.android.internal.R.dimen.navigation_bar_height);
        mNavBarWidth = res.getDimensionPixelSize(
                com.android.internal.R.dimen.navigation_bar_width);
        mTaskBarHeight = TaskStackLayoutAlgorithm.getDimensionForDevice(mContext,
                R.dimen.recents_task_view_header_height,
                R.dimen.recents_task_view_header_height,
@@ -719,7 +715,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        mHeaderBar.setLayoutDirection(res.getConfiguration().getLayoutDirection());
    }

    private void updateDummyStackViewLayout(TaskStack stack, Rect windowRect) {
    private void updateDummyStackViewLayout(TaskStackLayoutAlgorithm stackLayout,
            TaskStack stack, Rect windowRect) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        Rect displayRect = ssp.getDisplayRect();
        Rect systemInsets = new Rect();
@@ -735,20 +732,16 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        calculateWindowStableInsets(systemInsets, windowRect, displayRect);
        windowRect.offsetTo(0, 0);

        synchronized (mDummyStackView) {
            TaskStackLayoutAlgorithm stackLayout = mDummyStackView.getStackAlgorithm();

        // Rebind the header bar and draw it for the transition
        stackLayout.setSystemInsets(systemInsets);
        if (stack != null) {
            stackLayout.getTaskStackBounds(displayRect, windowRect, systemInsets.top,
                        systemInsets.left, systemInsets.right, mTaskStackBounds);
                    systemInsets.left, systemInsets.right, mTmpBounds);
            stackLayout.reset();
                stackLayout.initialize(displayRect, windowRect, mTaskStackBounds,
            stackLayout.initialize(displayRect, windowRect, mTmpBounds,
                    TaskStackLayoutAlgorithm.StackState.getStackStateForStack(stack));
        }
    }
    }

    private Rect getWindowRect(Rect windowRectOverride) {
       return windowRectOverride != null
@@ -768,10 +761,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    private void updateHeaderBarLayout(TaskStack stack, Rect windowRectOverride) {
        Rect windowRect = getWindowRect(windowRectOverride);
        int taskViewWidth = 0;
        boolean useGridLayout = false;
        synchronized (mDummyStackView) {
            useGridLayout = mDummyStackView.useGridLayout();
            updateDummyStackViewLayout(stack, windowRect);
        boolean useGridLayout = mDummyStackView.useGridLayout();
        updateDummyStackViewLayout(mDummyStackView.getStackAlgorithm(), stack, windowRect);
        if (stack != null) {
            TaskStackLayoutAlgorithm stackLayout = mDummyStackView.getStackAlgorithm();
            mDummyStackView.getStack().removeAllTasks(false /* notifyStackChanges */);
@@ -790,7 +781,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
                }
            }
        }
        }

        if (stack != null && taskViewWidth > 0) {
            synchronized (mHeaderBarLock) {
@@ -870,18 +860,12 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        final boolean isLowRamDevice = Recents.getConfiguration().isLowRamDevice;
        if (runningTask != null && runningTask.stackId == FREEFORM_WORKSPACE_STACK_ID) {
            ArrayList<AppTransitionAnimationSpec> specs = new ArrayList<>();
            ArrayList<Task> tasks;
            TaskStackLayoutAlgorithm stackLayout;
            TaskStackViewScroller stackScroller;

            synchronized (mDummyStackView) {
                tasks = mDummyStackView.getStack().getStackTasks();
                stackLayout = mDummyStackView.getStackAlgorithm();
                stackScroller = mDummyStackView.getScroller();
            ArrayList<Task> tasks = mDummyStackView.getStack().getStackTasks();
            TaskStackLayoutAlgorithm stackLayout = mDummyStackView.getStackAlgorithm();
            TaskStackViewScroller stackScroller = mDummyStackView.getScroller();

            mDummyStackView.updateLayoutAlgorithm(true /* boundScroll */);
            mDummyStackView.updateToInitialState();
            }

            for (int i = tasks.size() - 1; i >= 0; i--) {
                Task task = tasks.get(i);
@@ -1044,10 +1028,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        updateHeaderBarLayout(stack, windowOverrideRect);

        // Prepare the dummy stack for the transition
        TaskStackLayoutAlgorithm.VisibilityReport stackVr;
        synchronized (mDummyStackView) {
            stackVr = mDummyStackView.computeStackVisibilityReport();
        }
        TaskStackLayoutAlgorithm.VisibilityReport stackVr =
                mDummyStackView.computeStackVisibilityReport();

        // Update the remaining launch state
        launchState.launchedNumVisibleTasks = stackVr.numVisibleTasks;
+1 −2
Original line number Diff line number Diff line
@@ -354,7 +354,6 @@ public class TaskStackLayoutAlgorithm {
    TaskViewTransform mFrontOfStackTransform = new TaskViewTransform();

    public TaskStackLayoutAlgorithm(Context context, TaskStackLayoutAlgorithmCallbacks cb) {
        Resources res = context.getResources();
        mContext = context;
        mCb = cb;
        mFreeformLayoutAlgorithm = new FreeformWorkspaceLayoutAlgorithm(context);
@@ -519,7 +518,7 @@ public class TaskStackLayoutAlgorithm {
     * Computes the minimum and maximum scroll progress values and the progress values for each task
     * in the stack.
     */
    void update(TaskStack stack, ArraySet<Task.TaskKey> ignoreTasksSet,
    public void update(TaskStack stack, ArraySet<Task.TaskKey> ignoreTasksSet,
            RecentsActivityLaunchState launchState) {
        SystemServicesProxy ssp = Recents.getSystemServices();