From e1e20e11a758ee82753e8052773664823ca74746 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 2 Jun 2015 14:11:49 -0700 Subject: [PATCH] Fixing case where we were not preloading tasks correctly. - Should use the actual isTopTaskHome check when preloading. Bug: 21516523 Bug: 20882957 Change-Id: I60cf1e97f7704828426f72a45329c8c7b962a78c --- .../com/android/systemui/recents/Recents.java | 18 ++++++++++++------ .../recents/misc/SystemServicesProxy.java | 12 +++++------- .../recents/model/RecentsTaskLoadPlan.java | 10 +++------- .../systemui/recents/views/RecentsView.java | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/Recents.java b/packages/SystemUI/src/com/android/systemui/recents/Recents.java index c7026730b3b42..bbd3e609b5544 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/Recents.java +++ b/packages/SystemUI/src/com/android/systemui/recents/Recents.java @@ -35,6 +35,7 @@ import android.graphics.Rect; import android.os.Handler; import android.os.SystemClock; import android.os.UserHandle; +import android.util.MutableBoolean; import android.util.Pair; import android.view.Display; import android.view.LayoutInflater; @@ -57,7 +58,6 @@ import com.android.systemui.recents.views.TaskViewTransform; import com.android.systemui.statusbar.phone.PhoneStatusBar; import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicBoolean; /** * Annotation for a method that is only called from the primary user's SystemUI process and will be @@ -362,7 +362,12 @@ public class Recents extends SystemUI // RecentsActivity) RecentsTaskLoader loader = RecentsTaskLoader.getInstance(); sInstanceLoadPlan = loader.createLoadPlan(mContext); - sInstanceLoadPlan.preloadRawTasks(true); + + ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask(); + MutableBoolean isTopTaskHome = new MutableBoolean(true); + if (topTask != null && mSystemServicesProxy.isRecentsTopMost(topTask, isTopTaskHome)) { + sInstanceLoadPlan.preloadRawTasks(isTopTaskHome.value); + } } @Override @@ -546,7 +551,7 @@ public class Recents extends SystemUI // 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 = mSystemServicesProxy.getTopMostTask(); - AtomicBoolean isTopTaskHome = new AtomicBoolean(true); + MutableBoolean isTopTaskHome = new MutableBoolean(true); if (topTask != null && mSystemServicesProxy.isRecentsTopMost(topTask, isTopTaskHome)) { // Notify recents to toggle itself Intent intent = createLocalBroadcastIntent(mContext, ACTION_TOGGLE_RECENTS_ACTIVITY); @@ -555,7 +560,7 @@ public class Recents extends SystemUI return; } else { // Otherwise, start the recents activity - startRecentsActivity(topTask, isTopTaskHome.get()); + startRecentsActivity(topTask, isTopTaskHome.value); } } @@ -563,9 +568,9 @@ public class Recents extends SystemUI void startRecentsActivity() { // Check if the top task is in the home stack, and start the recents activity ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask(); - AtomicBoolean isTopTaskHome = new AtomicBoolean(true); + MutableBoolean isTopTaskHome = new MutableBoolean(true); if (topTask == null || !mSystemServicesProxy.isRecentsTopMost(topTask, isTopTaskHome)) { - startRecentsActivity(topTask, isTopTaskHome.get()); + startRecentsActivity(topTask, isTopTaskHome.value); } } @@ -654,6 +659,7 @@ public class Recents extends SystemUI if (task == null) { // If no task is specified or we can not find the task just use the front most one task = tasks.get(tasks.size() - 1); + runningTaskOut.copyFrom(task); } // Get the transform for the running task diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java index ca0f357ff46ce..272d39a7988ac 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java @@ -54,6 +54,7 @@ import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; import android.util.Log; +import android.util.MutableBoolean; import android.util.Pair; import android.util.SparseArray; import android.view.Display; @@ -67,12 +68,9 @@ import com.android.systemui.recents.Recents; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; 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 @@ -192,7 +190,7 @@ public class SystemServicesProxy { // Break early if we can't get a valid set of tasks if (tasks == null) { - return new ArrayList(); + return new ArrayList<>(); } boolean isFirstValidTask = true; @@ -235,7 +233,7 @@ public class SystemServicesProxy { /** Returns whether the recents is currently running */ public boolean isRecentsTopMost(ActivityManager.RunningTaskInfo topTask, - AtomicBoolean isHomeTopMost) { + MutableBoolean isHomeTopMost) { if (topTask != null) { ComponentName topActivity = topTask.topActivity; @@ -243,13 +241,13 @@ public class SystemServicesProxy { if (topActivity.getPackageName().equals(Recents.sRecentsPackage) && topActivity.getClassName().equals(Recents.sRecentsActivity)) { if (isHomeTopMost != null) { - isHomeTopMost.set(false); + isHomeTopMost.value = false; } return true; } if (isHomeTopMost != null) { - isHomeTopMost.set(isInHomeStack(topTask.id)); + isHomeTopMost.value = isInHomeStack(topTask.id); } } return false; diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java index 40cd211289def..f40c58dfdfeb0 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java +++ b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java @@ -104,13 +104,9 @@ public class RecentsTaskLoadPlan { if (mRawTasks == null) { preloadRawTasks(isTopTaskHome); } - int firstStackId = -1; int taskCount = mRawTasks.size(); for (int i = 0; i < taskCount; i++) { ActivityManager.RecentTaskInfo t = mRawTasks.get(i); - if (firstStackId < 0) { - firstStackId = t.stackId; - } // Compose the task key Task.TaskKey taskKey = new Task.TaskKey(t.persistentId, t.stackId, t.baseIntent, @@ -158,17 +154,17 @@ public class RecentsTaskLoadPlan { if (!mConfig.multiStackEnabled || Constants.DebugFlags.App.EnableMultiStackToSingleStack) { - firstStackId = 0; + int firstStackId = 0; ArrayList stackTasks = stacksTasks.get(firstStackId); if (stackTasks == null) { - stackTasks = new ArrayList(); + stackTasks = new ArrayList<>(); stacksTasks.put(firstStackId, stackTasks); } stackTasks.add(task); } else { ArrayList stackTasks = stacksTasks.get(t.stackId); if (stackTasks == null) { - stackTasks = new ArrayList(); + stackTasks = new ArrayList<>(); stacksTasks.put(t.stackId, stackTasks); } stackTasks.add(task); diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java index b3e6221eeac91..cec613cd33af4 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java @@ -550,7 +550,7 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV if (tv == null) { launchRunnable.run(); } else { - if (!task.group.isFrontMostTask(task)) { + if (task.group != null && !task.group.isFrontMostTask(task)) { // For affiliated tasks that are behind other tasks, we must animate the front cards // out of view before starting the task transition stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask);