From d434dcbfc9407baad28b6b40fea75b1b6050ad7e Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Wed, 6 Jan 2016 17:18:44 +0100 Subject: When creating docked stack, use SnapAlgorithm To make sure the bounds snapped to a snap position are set from the very beginning. Change-Id: I0ebc463926dd17e0deeefc211b097f28a6456b96 --- .../internal/policy/DividerSnapAlgorithm.java | 6 +++++ .../core/java/com/android/server/wm/TaskStack.java | 27 ++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/core/java/com/android/internal/policy/DividerSnapAlgorithm.java b/core/java/com/android/internal/policy/DividerSnapAlgorithm.java index e79f1b8a3133..fdf5f8419ba0 100644 --- a/core/java/com/android/internal/policy/DividerSnapAlgorithm.java +++ b/core/java/com/android/internal/policy/DividerSnapAlgorithm.java @@ -62,6 +62,7 @@ public class DividerSnapAlgorithm { private final SnapTarget mDismissStartTarget; private final SnapTarget mDismissEndTarget; + private final SnapTarget mMiddleTarget; public DividerSnapAlgorithm(Resources res, float minFlingVelocityPxPerSecond, int displayWidth, int displayHeight, int dividerSize, boolean isHorizontalDivision, @@ -80,6 +81,7 @@ public class DividerSnapAlgorithm { mLastSplitTarget = mTargets.get(mTargets.size() - 2); mDismissStartTarget = mTargets.get(0); mDismissEndTarget = mTargets.get(mTargets.size() - 1); + mMiddleTarget = mTargets.get(mTargets.size() / 2); } public SnapTarget calculateSnapTarget(int position, float velocity) { @@ -215,6 +217,10 @@ public class DividerSnapAlgorithm { SnapTarget.FLAG_NONE)); } + public SnapTarget getMiddleTarget() { + return mMiddleTarget; + } + /** * Represents a snap target for the divider. */ diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java index e75780f6a095..572aa20e9b47 100644 --- a/services/core/java/com/android/server/wm/TaskStack.java +++ b/services/core/java/com/android/server/wm/TaskStack.java @@ -38,6 +38,7 @@ import java.util.ArrayList; import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT; import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; +import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.view.WindowManager.DOCKED_BOTTOM; import static android.view.WindowManager.DOCKED_INVALID; import static android.view.WindowManager.DOCKED_LEFT; @@ -539,20 +540,32 @@ public class TaskStack implements DimLayer.DimLayerUser { outBounds.set(mService.mDockedStackCreateBounds); return; } - // The initial bounds of the docked stack when it is created half the screen space and - // its bounds can be adjusted after that. The bounds of all other stacks are adjusted - // to occupy whatever screen space the docked stack isn't occupying. + + // The initial bounds of the docked stack when it is created about half the screen space + // and its bounds can be adjusted after that. The bounds of all other stacks are + // adjusted to occupy whatever screen space the docked stack isn't occupying. + final DisplayInfo di = mDisplayContent.getDisplayInfo(); + mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight, + mTmpRect2); + final int position = new DividerSnapAlgorithm(mService.mContext.getResources(), + 0 /* minFlingVelocityPxPerSecond */, + di.logicalWidth, + di.logicalHeight, + dockDividerWidth, + mService.mCurConfiguration.orientation == ORIENTATION_PORTRAIT, + mTmpRect2).getMiddleTarget().position; + if (dockOnTopOrLeft) { if (splitHorizontally) { - outBounds.right = displayRect.centerX() - dockDividerWidth / 2; + outBounds.right = position; } else { - outBounds.bottom = displayRect.centerY() - dockDividerWidth / 2; + outBounds.bottom = position; } } else { if (splitHorizontally) { - outBounds.left = displayRect.centerX() + dockDividerWidth / 2; + outBounds.left = position - dockDividerWidth; } else { - outBounds.top = displayRect.centerY() + dockDividerWidth / 2; + outBounds.top = position - dockDividerWidth; } } return; -- cgit v1.2.3-59-g8ed1b From a0fdeec66caa4d70786c7f6f31f79a24eef9da10 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Thu, 7 Jan 2016 14:42:28 +0100 Subject: Reenable task preloading in recents Make sure to call the task stack changed listener only when app visibilities changed. This fixes the problem of too many callbacks when just focusing another activity. Bug: 26420341 Change-Id: I55d96ec367f7461be1f3e35bc0d12ae4b050ece0 --- .../SystemUI/src/com/android/systemui/recents/RecentsImpl.java | 5 +---- services/core/java/com/android/server/am/ActivityStack.java | 9 +++++++-- .../core/java/com/android/server/am/ActivityStackSupervisor.java | 6 ++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java index ddeb8dcecf17..60a2ee5711ce 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java @@ -110,9 +110,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements /** Preloads the next task */ public void run() { - // TODO: Temporarily skip this if multi stack is enabled - /* - RecentsConfiguration config = RecentsConfiguration.getInstance(); + RecentsConfiguration config = Recents.getConfiguration(); if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) { RecentsTaskLoader loader = Recents.getTaskLoader(); SystemServicesProxy ssp = Recents.getSystemServices(); @@ -134,7 +132,6 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub implements launchOpts.onlyLoadPausedActivities = true; loader.loadTasks(mContext, plan, launchOpts); } - */ } } diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 312e309e3950..1f5c980fdb36 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -1179,8 +1179,12 @@ final class ActivityStack { prev.cpuTimeAtResume = 0; // reset it } - // Notfiy when the task stack has changed - mService.notifyTaskStackChangedLocked(); + // Notify when the task stack has changed, but only if visibilities changed (not just + // focus). + if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause) { + mService.notifyTaskStackChangedLocked(); + mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; + } } private void addToStopping(ActivityRecord r) { @@ -1257,6 +1261,7 @@ final class ActivityStack { ActivityContainer container = containers.get(containerNdx); container.setVisible(visible); } + mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; } // Find the first visible activity above the passed activity and if it is translucent return it diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index c634e0e6a6ac..7481a30b13aa 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -398,6 +398,12 @@ public final class ActivityStackSupervisor implements DisplayListener { } private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); + /** + * Used to keep track whether app visibilities got changed since the last pause. Useful to + * determine whether to invoke the task stack change listener after pausing. + */ + boolean mAppVisibilitiesChangedSinceLastPause; + /** * Description of a request to start a new activity, which has been held * due to app switches being disabled. -- cgit v1.2.3-59-g8ed1b