From 55a9b544c9bf32c2689cef7dde74ad8865a190c6 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Fri, 26 Jun 2020 17:02:47 -0700 Subject: [PATCH] Using original taskInfo to create the taskKey instead of fake data Change-Id: Ie4e35b35484e0f6cb939febe6357b37381d81682 (cherry picked from commit fabfb3ae90524fef748ed35e6edf578a20789689) --- .../AppToOverviewAnimationProvider.java | 12 +++++---- .../quickstep/BaseSwipeUpHandlerV2.java | 2 +- .../quickstep/OverviewCommandHelper.java | 2 +- .../fallback/FallbackRecentsView.java | 9 ++++--- .../android/quickstep/views/RecentsView.java | 25 +++++++++---------- .../quickstep/RecentsActivityTest.java | 8 ++++-- .../com/android/quickstep/RecentsModel.java | 13 +++------- 7 files changed, 35 insertions(+), 36 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/AppToOverviewAnimationProvider.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/AppToOverviewAnimationProvider.java index de83caf162..9310685e30 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/AppToOverviewAnimationProvider.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/AppToOverviewAnimationProvider.java @@ -24,6 +24,7 @@ import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MOD import android.animation.Animator; import android.animation.AnimatorSet; +import android.app.ActivityManager.RunningTaskInfo; import android.util.Log; import android.view.animation.Interpolator; @@ -52,17 +53,17 @@ final class AppToOverviewAnimationProvider> extend private final BaseActivityInterface mActivityInterface; // The id of the currently running task that is transitioning to overview. - private final int mTargetTaskId; + private final RunningTaskInfo mTargetTask; private final RecentsAnimationDeviceState mDeviceState; private T mActivity; private RecentsView mRecentsView; AppToOverviewAnimationProvider( - BaseActivityInterface activityInterface, int targetTaskId, + BaseActivityInterface activityInterface, RunningTaskInfo targetTask, RecentsAnimationDeviceState deviceState) { mActivityInterface = activityInterface; - mTargetTaskId = targetTaskId; + mTargetTask = targetTask; mDeviceState = deviceState; } @@ -73,7 +74,7 @@ final class AppToOverviewAnimationProvider> extend * @param wasVisible true if it was visible before */ boolean onActivityReady(T activity, Boolean wasVisible) { - activity.getOverviewPanel().showCurrentTask(mTargetTaskId); + activity.getOverviewPanel().showCurrentTask(mTargetTask); AbstractFloatingView.closeAllOpenViews(activity, wasVisible); BaseActivityInterface.AnimationFactory factory = mActivityInterface.prepareRecentsUI( mDeviceState, @@ -122,7 +123,8 @@ final class AppToOverviewAnimationProvider> extend wallpaperTargets, MODE_CLOSING); // Use the top closing app to determine the insets for the animation - RemoteAnimationTargetCompat runningTaskTarget = targets.findTask(mTargetTaskId); + RemoteAnimationTargetCompat runningTaskTarget = mTargetTask == null ? null + : targets.findTask(mTargetTask.taskId); if (runningTaskTarget == null) { Log.e(TAG, "No closing app"); return pa.buildAnim(); diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandlerV2.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandlerV2.java index ca8741da82..92662b205d 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandlerV2.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/BaseSwipeUpHandlerV2.java @@ -421,7 +421,7 @@ public abstract class BaseSwipeUpHandlerV2, Q exte } protected void notifyGestureAnimationStartToRecents() { - mRecentsView.onGestureAnimationStart(mGestureState.getRunningTaskId()); + mRecentsView.onGestureAnimationStart(mGestureState.getRunningTask()); } private void launcherFrameDrawn() { diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java index 434a929b5c..4879db7897 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/OverviewCommandHelper.java @@ -165,7 +165,7 @@ public class OverviewCommandHelper { mActivityInterface = mOverviewComponentObserver.getActivityInterface(); mCreateTime = SystemClock.elapsedRealtime(); mAnimationProvider = new AppToOverviewAnimationProvider<>(mActivityInterface, - RecentsModel.getRunningTaskId(), mDeviceState); + ActivityManagerWrapper.getInstance().getRunningTask(), mDeviceState); // Preload the plan mRecentsModel.getTasks(null); diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java index d20bbe9780..ffe9d6aed9 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/fallback/FallbackRecentsView.java @@ -76,7 +76,7 @@ public class FallbackRecentsView extends RecentsView */ public void onGestureAnimationStartOnHome(RunningTaskInfo homeTaskInfo) { mHomeTaskInfo = homeTaskInfo; - onGestureAnimationStart(homeTaskInfo == null ? -1 : homeTaskInfo.taskId); + onGestureAnimationStart(homeTaskInfo); } /** @@ -107,14 +107,15 @@ public class FallbackRecentsView extends RecentsView } @Override - protected boolean shouldAddDummyTaskView(int runningTaskId) { - if (mHomeTaskInfo != null && mHomeTaskInfo.taskId == runningTaskId + protected boolean shouldAddDummyTaskView(RunningTaskInfo runningTaskInfo) { + if (mHomeTaskInfo != null && runningTaskInfo != null && + mHomeTaskInfo.taskId == runningTaskInfo.taskId && getTaskViewCount() == 0) { // Do not add a dummy task if we are running over home with empty recents, so that we // show the empty recents message instead of showing a dummy task and later removing it. return false; } - return super.shouldAddDummyTaskView(runningTaskId); + return super.shouldAddDummyTaskView(runningTaskInfo); } @Override diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java index 68b89758ef..1a9bb85e69 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java @@ -56,6 +56,7 @@ import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.annotation.TargetApi; import android.app.ActivityManager; +import android.app.ActivityManager.RunningTaskInfo; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -135,6 +136,7 @@ import com.android.quickstep.util.TransformParams; import com.android.systemui.plugins.ResourceProvider; import com.android.systemui.shared.recents.IPinnedStackAnimationListener; import com.android.systemui.shared.recents.model.Task; +import com.android.systemui.shared.recents.model.Task.TaskKey; import com.android.systemui.shared.recents.model.ThumbnailData; import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.LauncherEventUtil; @@ -147,7 +149,7 @@ import java.util.function.Consumer; /** * A list of recent tasks. */ -@TargetApi(Build.VERSION_CODES.P) +@TargetApi(Build.VERSION_CODES.R) public abstract class RecentsView extends PagedView implements Insettable, TaskThumbnailCache.HighResLoadingState.HighResLoadingStateChangedCallback, InvariantDeviceProfile.OnIDPChangeListener, TaskVisualsChangeListener, @@ -1039,10 +1041,10 @@ public abstract class RecentsView extends PagedView /** * Called when a gesture from an app is starting. */ - public void onGestureAnimationStart(int runningTaskId) { + public void onGestureAnimationStart(RunningTaskInfo runningTaskInfo) { // This needs to be called before the other states are set since it can create the task view mOrientationState.setGestureActive(true); - showCurrentTask(runningTaskId); + showCurrentTask(runningTaskInfo); setEnableFreeScroll(false); setEnableDrawingLiveTile(false); setRunningTaskHidden(true); @@ -1120,8 +1122,8 @@ public abstract class RecentsView extends PagedView /** * Returns true if we should add a dummy taskView for the running task id */ - protected boolean shouldAddDummyTaskView(int runningTaskId) { - return getTaskView(runningTaskId) == null; + protected boolean shouldAddDummyTaskView(RunningTaskInfo runningTaskInfo) { + return runningTaskInfo != null && getTaskView(runningTaskInfo.taskId) == null; } /** @@ -1130,8 +1132,8 @@ public abstract class RecentsView extends PagedView * All subsequent calls to reload will keep the task as the first item until {@link #reset()} * is called. Also scrolls the view to this task. */ - public void showCurrentTask(int runningTaskId) { - if (shouldAddDummyTaskView(runningTaskId)) { + public void showCurrentTask(RunningTaskInfo runningTaskInfo) { + if (shouldAddDummyTaskView(runningTaskInfo)) { boolean wasEmpty = getChildCount() == 0; // Add an empty view for now until the task plan is loaded and applied final TaskView taskView = mTaskViewPool.getView(); @@ -1141,10 +1143,7 @@ public abstract class RecentsView extends PagedView } // The temporary running task is only used for the duration between the start of the // gesture and the task list is loaded and applied - mTmpRunningTask = new Task(new Task.TaskKey(runningTaskId, 0, new Intent(), - new ComponentName(getContext(), getClass()), 0, 0), null, null, "", "", 0, 0, - false, true, false, false, new ActivityManager.TaskDescription(), 0, - new ComponentName("", ""), false); + mTmpRunningTask = Task.from(new TaskKey(runningTaskInfo), runningTaskInfo, false); taskView.bind(mTmpRunningTask, mOrientationState); // Measure and layout immediately so that the scroll values is updated instantly @@ -1155,7 +1154,7 @@ public abstract class RecentsView extends PagedView } boolean runningTaskTileHidden = mRunningTaskTileHidden; - setCurrentTask(runningTaskId); + setCurrentTask(runningTaskInfo == null ? -1 : runningTaskInfo.taskId); setCurrentPage(getRunningTaskIndex()); setRunningTaskViewShowScreenshot(false); setRunningTaskHidden(runningTaskTileHidden); @@ -1673,7 +1672,7 @@ public abstract class RecentsView extends PagedView : View.LAYOUT_DIRECTION_RTL); mClearAllButton.setRotation(mOrientationHandler.getDegreesRotated()); mActivity.getDragLayer().recreateControllers(); - boolean isInLandscape = mOrientationState.getTouchRotation() != 0 + boolean isInLandscape = mOrientationState.getTouchRotation() != ROTATION_0 || mOrientationState.getRecentsActivityRotation() != ROTATION_0; mActionsView.updateHiddenFlags(HIDDEN_NON_ZERO_ROTATION, !mOrientationState.canRecentsActivityRotate() && isInLandscape); diff --git a/quickstep/robolectric_tests/src/com/android/quickstep/RecentsActivityTest.java b/quickstep/robolectric_tests/src/com/android/quickstep/RecentsActivityTest.java index 93b64e666c..c148a4b6fe 100644 --- a/quickstep/robolectric_tests/src/com/android/quickstep/RecentsActivityTest.java +++ b/quickstep/robolectric_tests/src/com/android/quickstep/RecentsActivityTest.java @@ -17,6 +17,7 @@ package com.android.quickstep; import static com.android.launcher3.util.LauncherUIHelper.doLayout; +import android.app.ActivityManager.RunningTaskInfo; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; @@ -50,7 +51,7 @@ public class RecentsActivityTest { } @Test - public void testRecets_showCurrentTask() { + public void testRecents_showCurrentTask() { ActivityController controller = Robolectric.buildActivity(RecentsActivity.class); @@ -58,7 +59,10 @@ public class RecentsActivityTest { doLayout(activity); FallbackRecentsView frv = activity.getOverviewPanel(); - frv.showCurrentTask(22); + + RunningTaskInfo dummyTask = new RunningTaskInfo(); + dummyTask.taskId = 22; + frv.showCurrentTask(dummyTask); doLayout(activity); ThumbnailData thumbnailData = new ThumbnailData(); diff --git a/quickstep/src/com/android/quickstep/RecentsModel.java b/quickstep/src/com/android/quickstep/RecentsModel.java index 517501ad9c..6f54ba2935 100644 --- a/quickstep/src/com/android/quickstep/RecentsModel.java +++ b/quickstep/src/com/android/quickstep/RecentsModel.java @@ -92,15 +92,6 @@ public class RecentsModel extends TaskStackChangeListener { return mTaskList.getTasks(false /* loadKeysOnly */, callback); } - /** - * @return The task id of the running task, or -1 if there is no current running task. - */ - public static int getRunningTaskId() { - ActivityManager.RunningTaskInfo runningTask = - ActivityManagerWrapper.getInstance().getRunningTask(); - return runningTask != null ? runningTask.id : -1; - } - /** * @return Whether the provided {@param changeId} is the latest recent tasks list id. */ @@ -140,7 +131,9 @@ public class RecentsModel extends TaskStackChangeListener { } // Keep the cache up to date with the latest thumbnails - int runningTaskId = RecentsModel.getRunningTaskId(); + ActivityManager.RunningTaskInfo runningTask = + ActivityManagerWrapper.getInstance().getRunningTask(); + int runningTaskId = runningTask != null ? runningTask.id : -1; mTaskList.getTaskKeys(mThumbnailCache.getCacheSize(), tasks -> { for (Task task : tasks) { if (task.key.id == runningTaskId) {