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

Commit a1ededd0 authored by Winson's avatar Winson
Browse files

Launch state/config change audit. (Part 1)

- Fixing issue with onResume logic being run even when the window focus
  is changing.  This only needs to be run when we are launching into 
  Recents again.
- Removed a bunch of launch state flags that are no longer necessary 
  because of changes to configuration handling.  This reduces the work
  that we have to do on resize, etc.
- Decoupled the resume with the stack-update, which fixes a couple 
  issues where we were updating the layout unexpectedly.
- Fixed an issue where we were not updating the nav bar scrims on 
  configuration change
- Fixing margin start/end regression in header bar
- Fixing small issue with paddings being scaled beyond their base size
- Fixing issue where the clip state was not properly getting reset 
  causing lots of overdraw.

Change-Id: I9aeb191a99ff23807b3f5d905f6480b10157a060
parent a3631b6c
Loading
Loading
Loading
Loading
+89 −53
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ 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.TaskStack;
import com.android.systemui.recents.views.AnimationProps;
import com.android.systemui.recents.views.RecentsView;
import com.android.systemui.recents.views.SystemBarScrimViews;
import com.android.systemui.statusbar.BaseStatusBar;
@@ -285,6 +286,9 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        registerReceiver(mSystemBroadcastReceiver, filter);

        getWindow().addPrivateFlags(LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION);

        // Reload the stack view
        reloadStackView();
    }

    @Override
@@ -297,15 +301,17 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
    }

    @Override
    public void onEnterAnimationComplete() {
        super.onEnterAnimationComplete();
        EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
    }
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

    @Override
    protected void onResume() {
        super.onResume();
        // Reload the stack view
        reloadStackView();
    }

    /**
     * Reloads the stack views upon launching Recents.
     */
    private void reloadStackView() {
        // If the Recents component has preloaded a load plan, then use that to prevent
        // reconstructing the task stack
        RecentsTaskLoader loader = Recents.getTaskLoader();
@@ -328,38 +334,21 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
        loader.loadTasks(this, loadPlan, loadOpts);
        TaskStack stack = loadPlan.getTaskStack();
        mRecentsView.onResume(mIsVisible, false /* multiWindowChange */, stack);
        mRecentsView.onReload(mIsVisible, stack.getTaskCount() == 0);
        mRecentsView.updateStack(stack);

        // Animate the SystemUI scrims into view
        Task launchTarget = stack.getLaunchTarget();
        int taskCount = stack.getTaskCount();
        int launchTaskIndexInStack = launchTarget != null
                ? stack.indexOfStackTask(launchTarget)
                : 0;
        boolean hasNavBarScrim = (taskCount > 0) && !config.hasTransposedNavBar;
        // Update the nav bar scrim, but defer the animation until the enter-window event
        boolean animateNavBarScrim = !launchState.launchedWhileDocking;
        mScrimViews.prepareEnterRecentsAnimation(hasNavBarScrim, animateNavBarScrim);
        updateNavBarScrim(animateNavBarScrim, null);

        // If this is a new instance from a configuration change, then we have to manually trigger
        // the enter animation state, or if recents was relaunched by AM, without going through
        // the normal mechanisms
        // If this is a new instance relaunched by AM, without going through the normal mechanisms,
        // then we have to manually trigger the enter animation state
        boolean wasLaunchedByAm = !launchState.launchedFromHome &&
                !launchState.launchedFromApp;
        if (launchState.launchedHasConfigurationChanged || wasLaunchedByAm) {
        if (wasLaunchedByAm) {
            EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
        }

        mRecentsView.getViewTreeObserver().addOnPreDrawListener(
                new ViewTreeObserver.OnPreDrawListener() {

                    @Override
                    public boolean onPreDraw() {
                        mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this);
                        EventBus.getDefault().post(new RecentsDrawnEvent());
                        return true;
                    }
                });

        // Keep track of whether we launched from the nav bar button or via alt-tab
        if (launchState.launchedWithAltTab) {
            MetricsLogger.count(this, "overview_trigger_alttab", 1);
@@ -369,6 +358,10 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD

        // Keep track of whether we launched from an app or from home
        if (launchState.launchedFromApp) {
            Task launchTarget = stack.getLaunchTarget();
            int launchTaskIndexInStack = launchTarget != null
                    ? stack.indexOfStackTask(launchTarget)
                    : 0;
            MetricsLogger.count(this, "overview_source_app", 1);
            // If from an app, track the stack index of the app in the stack (for affiliated tasks)
            MetricsLogger.histogram(this, "overview_source_app_index", launchTaskIndexInStack);
@@ -377,12 +370,36 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        }

        // Keep track of the total stack task count
        int taskCount = mRecentsView.getStack().getTaskCount();
        MetricsLogger.histogram(this, "overview_task_count", taskCount);

        // After we have resumed, set the visible state until the next onStop() call
        mIsVisible = true;
    }

    @Override
    public void onEnterAnimationComplete() {
        super.onEnterAnimationComplete();
        EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
    }

    @Override
    protected void onResume() {
        super.onResume();

        // Notify of the next draw
        mRecentsView.getViewTreeObserver().addOnPreDrawListener(
                new ViewTreeObserver.OnPreDrawListener() {

                    @Override
                    public boolean onPreDraw() {
                        mRecentsView.getViewTreeObserver().removeOnPreDrawListener(this);
                        EventBus.getDefault().post(new RecentsDrawnEvent());
                        return true;
                    }
                });
    }

    @Override
    protected void onPause() {
        super.onPause();
@@ -395,9 +412,36 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Update the nav bar for the current orientation
        updateNavBarScrim(false /* animateNavBarScrim */, AnimationProps.IMMEDIATE);

        EventBus.getDefault().send(new ConfigurationChangedEvent());
    }

    @Override
    public void onMultiWindowChanged(boolean inMultiWindow) {
        super.onMultiWindowChanged(inMultiWindow);
        EventBus.getDefault().send(new ConfigurationChangedEvent());

        if (mRecentsView != null) {
            // Reload the task stack completely
            RecentsConfiguration config = Recents.getConfiguration();
            RecentsActivityLaunchState launchState = config.getLaunchState();
            RecentsTaskLoader loader = Recents.getTaskLoader();
            RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this);
            loader.preloadTasks(loadPlan, -1 /* topTaskId */, false /* isTopTaskHome */);

            RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
            loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks;
            loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
            loader.loadTasks(this, loadPlan, loadOpts);

            mRecentsView.updateStack(loadPlan.getTaskStack());
        }

        EventBus.getDefault().send(new MultiWindowStateChangedEvent(inMultiWindow));
    }

    @Override
    protected void onStop() {
        super.onStop();
@@ -453,28 +497,6 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        }
    }

    @Override
    public void onMultiWindowChanged(boolean inMultiWindow) {
        super.onMultiWindowChanged(inMultiWindow);
        EventBus.getDefault().send(new ConfigurationChangedEvent());

        // Reload the task stack completely
        RecentsConfiguration config = Recents.getConfiguration();
        RecentsActivityLaunchState launchState = config.getLaunchState();
        RecentsTaskLoader loader = Recents.getTaskLoader();
        RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this);
        loader.preloadTasks(loadPlan, -1 /* topTaskId */, false /* isTopTaskHome */);

        RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options();
        loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks;
        loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails;
        loader.loadTasks(this, loadPlan, loadOpts);

        mRecentsView.onResume(mIsVisible, true /* multiWindowChange */, loadPlan.getTaskStack());

        EventBus.getDefault().send(new MultiWindowStateChangedEvent(inMultiWindow));
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
@@ -697,4 +719,18 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD
        });
        return true;
    }

    /**
     * Updates the nav bar scrim.
     */
    private void updateNavBarScrim(boolean animateNavBarScrim, AnimationProps animation) {
        // Animate the SystemUI scrims into view
        SystemServicesProxy ssp = Recents.getSystemServices();
        int taskCount = mRecentsView.getStack().getTaskCount();
        boolean hasNavBarScrim = (taskCount > 0) && !ssp.hasTransposedNavBar();
        mScrimViews.prepareEnterRecentsAnimation(hasNavBarScrim, animateNavBarScrim);
        if (animateNavBarScrim && animation != null) {
            mScrimViews.animateNavBarScrimVisibility(true, animation);
        }
    }
}
+0 −7
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@ public class RecentsActivityLaunchState {
    public boolean launchedFromApp;
    public boolean launchedFromAppDocked;
    public boolean launchedFromHome;
    public boolean launchedReuseTaskStackViews;
    public boolean launchedHasConfigurationChanged;
    public boolean launchedViaDragGesture;
    public boolean launchedWhileDocking;
    public int launchedToTaskId;
@@ -45,7 +43,6 @@ public class RecentsActivityLaunchState {
        launchedFromAppDocked = false;
        launchedToTaskId = -1;
        launchedWithAltTab = false;
        launchedHasConfigurationChanged = false;
        launchedViaDragGesture = false;
        launchedWhileDocking = false;
    }
@@ -53,10 +50,6 @@ public class RecentsActivityLaunchState {
    /** Called when the configuration has changed, and we want to reset any configuration specific
     * members. */
    public void updateOnConfigurationChange() {
        // Reset this flag on configuration change to ensure that we recreate new task views
        launchedReuseTaskStackViews = false;
        // Set this flag to indicate that the configuration has changed since Recents last launched
        launchedHasConfigurationChanged = true;
        launchedViaDragGesture = false;
        launchedWhileDocking = false;
    }
+0 −12
Original line number Diff line number Diff line
@@ -47,11 +47,6 @@ public class RecentsConfiguration {
    // Launch states
    public RecentsActivityLaunchState mLaunchState = new RecentsActivityLaunchState();

    // TODO: Values determined by the current context, needs to be refactored into something that is
    //       agnostic of the activity context, but still calculable from the Recents component for
    //       the transition into recents
    public boolean hasTransposedNavBar;

    // Since the positions in Recents has to be calculated globally (before the RecentsActivity
    // starts), we need to calculate some resource values ourselves, instead of relying on framework
    // resources.
@@ -78,13 +73,6 @@ public class RecentsConfiguration {
        isXLargeScreen = smallestWidth >= (int) (screenDensity * XLARGE_SCREEN_MIN_DP);
    }

    /**
     * Updates the configuration based on the current state of the system
     */
    void update(Rect systemInsets) {
        hasTransposedNavBar = systemInsets.right > 0;
    }

    /**
     * Returns the activity launch state.
     * TODO: This will be refactored out of RecentsConfiguration.
+1 −11
Original line number Diff line number Diff line
@@ -140,7 +140,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    protected Context mContext;
    protected Handler mHandler;
    TaskStackListenerImpl mTaskStackListener;
    protected boolean mCanReuseTaskStackViews = true;
    boolean mDraggingInRecents;
    boolean mLaunchedWhileDocking;

@@ -209,8 +208,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
    public void onConfigurationChanged() {
        reloadHeaderBarLayout();
        updateHeaderBarLayout(null /* stack */);
        // Don't reuse task stack views if the configuration changes
        mCanReuseTaskStackViews = false;
        Recents.getConfiguration().updateOnConfigurationChange();
    }

@@ -592,9 +589,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        calculateWindowStableInsets(systemInsets, windowRect);
        windowRect.offsetTo(0, 0);

        // Update the configuration for the current state
        Recents.getConfiguration().update(systemInsets);

        TaskStackLayoutAlgorithm stackLayout = mDummyStackView.getStackAlgorithm();
        stackLayout.getTaskStackBounds(windowRect, systemInsets.top, systemInsets.right,
                mTaskStackBounds);
@@ -605,8 +599,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        if (stack != null) {
            stackLayout.initialize(windowRect, taskStackBounds,
                    TaskStackLayoutAlgorithm.StackState.getStackStateForStack(stack));
            mDummyStackView.setTasks(stack, false /* notifyStackChanges */,
                    false /* relayoutTaskStack */, false /* multiWindowChange */);
            mDummyStackView.setTasks(stack, false /* allowNotifyStackChanges */);
        }
        Rect taskViewBounds = stackLayout.getUntransformedTaskViewBounds();
        if (!taskViewBounds.equals(mLastTaskViewBounds)) {
@@ -862,10 +855,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        launchState.launchedToTaskId = (topTask != null) ? topTask.id : -1;
        launchState.launchedFromAppDocked = mLaunchedWhileDocking;
        launchState.launchedWithAltTab = mTriggeredFromAltTab;
        launchState.launchedReuseTaskStackViews = mCanReuseTaskStackViews;
        launchState.launchedNumVisibleTasks = stackVr.numVisibleTasks;
        launchState.launchedNumVisibleThumbnails = stackVr.numVisibleThumbnails;
        launchState.launchedHasConfigurationChanged = false;
        launchState.launchedViaDragGesture = mDraggingInRecents;
        launchState.launchedWhileDocking = mLaunchedWhileDocking;

@@ -915,7 +906,6 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener
        } else {
            mContext.startActivityAsUser(intent, UserHandle.CURRENT);
        }
        mCanReuseTaskStackViews = true;
        EventBus.getDefault().send(new RecentsActivityStartingEvent());
    }

+10 −0
Original line number Diff line number Diff line
@@ -1064,6 +1064,16 @@ public class SystemServicesProxy {
        }
    }

    /**
     * Returns whether the device has a transposed nav bar (on the right of the screen) in the
     * current display orientation.
     */
    public boolean hasTransposedNavBar() {
        Rect insets = new Rect();
        getStableInsets(insets);
        return insets.right > 0;
    }

    private final class H extends Handler {
        private static final int ON_TASK_STACK_CHANGED = 1;
        private static final int ON_ACTIVITY_PINNED = 2;
Loading