From 0613af358741484d4a06724cf18ea0df1a273dbb Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 4 Mar 2021 14:18:41 -0800 Subject: [PATCH] Add some logging for failure to get recents Bug: 177472267 Test: Presubmit Change-Id: I64a01ef076a58bc3118840ff3171177f61edc3f5 --- .../android/quickstep/RecentTasksList.java | 32 ++++++++++++++++++- .../com/android/quickstep/RecentsModel.java | 10 ++++++ .../fallback/FallbackRecentsView.java | 6 ++++ .../android/quickstep/views/RecentsView.java | 23 +++++++++++++ .../quickstep/FallbackRecentsTest.java | 17 ++++++++-- .../launcher3/testing/TestProtocol.java | 1 + 6 files changed, 86 insertions(+), 3 deletions(-) diff --git a/quickstep/src/com/android/quickstep/RecentTasksList.java b/quickstep/src/com/android/quickstep/RecentTasksList.java index 1c5dc4c829..2f1538bf5a 100644 --- a/quickstep/src/com/android/quickstep/RecentTasksList.java +++ b/quickstep/src/com/android/quickstep/RecentTasksList.java @@ -22,10 +22,12 @@ import android.annotation.TargetApi; import android.app.ActivityManager; import android.os.Build; import android.os.Process; +import android.util.Log; import android.util.SparseBooleanArray; import androidx.annotation.VisibleForTesting; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.util.LooperExecutor; import com.android.systemui.shared.recents.model.Task; import com.android.systemui.shared.system.ActivityManagerWrapper; @@ -51,6 +53,9 @@ public class RecentTasksList extends TaskStackChangeListener { // The list change id, increments as the task list changes in the system private int mChangeId; + // Whether we are currently updating the tasks in the background (up to when the result is + // posted back on the main thread) + private boolean mLoadingTasksInBackground; private TaskLoadResult mResultsBg = INVALID_RESULT; private TaskLoadResult mResultsUi = INVALID_RESULT; @@ -64,6 +69,11 @@ public class RecentTasksList extends TaskStackChangeListener { mActivityManagerWrapper.registerTaskStackListener(this); } + @VisibleForTesting + public boolean isLoadingTasksInBackground() { + return mLoadingTasksInBackground; + } + /** * Fetches the task keys skipping any local cache. */ @@ -83,6 +93,10 @@ public class RecentTasksList extends TaskStackChangeListener { * @return The change id of the current task list */ public synchronized int getTasks(boolean loadKeysOnly, Consumer> callback) { + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "getTasks: keysOnly=" + loadKeysOnly + + " callback=" + callback); + } final int requestLoadId = mChangeId; if (mResultsUi.isValidForRequest(requestLoadId, loadKeysOnly)) { // The list is up to date, send the callback on the next frame, @@ -90,22 +104,38 @@ public class RecentTasksList extends TaskStackChangeListener { if (callback != null) { // Copy synchronously as the changeId might change by next frame ArrayList result = copyOf(mResultsUi); - mMainThreadExecutor.post(() -> callback.accept(result)); + mMainThreadExecutor.post(() -> { + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "getTasks: no new tasks"); + } + callback.accept(result); + }); } return requestLoadId; } // Kick off task loading in the background + mLoadingTasksInBackground = true; UI_HELPER_EXECUTOR.execute(() -> { + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "getTasks: loading in bg start"); + } if (!mResultsBg.isValidForRequest(requestLoadId, loadKeysOnly)) { mResultsBg = loadTasksInBackground(Integer.MAX_VALUE, requestLoadId, loadKeysOnly); } + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "getTasks: loading in bg end"); + } TaskLoadResult loadResult = mResultsBg; mMainThreadExecutor.execute(() -> { + mLoadingTasksInBackground = false; mResultsUi = loadResult; if (callback != null) { ArrayList result = copyOf(mResultsUi); + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "getTasks: callback w/ bg results"); + } callback.accept(result); } }); diff --git a/quickstep/src/com/android/quickstep/RecentsModel.java b/quickstep/src/com/android/quickstep/RecentsModel.java index d47217b770..ba24e6a6c7 100644 --- a/quickstep/src/com/android/quickstep/RecentsModel.java +++ b/quickstep/src/com/android/quickstep/RecentsModel.java @@ -28,6 +28,8 @@ import android.os.Build; import android.os.Process; import android.os.UserHandle; +import androidx.annotation.VisibleForTesting; + import com.android.launcher3.icons.IconProvider; import com.android.launcher3.util.Executors.SimpleThreadFactory; import com.android.launcher3.util.MainThreadInitializedObject; @@ -101,6 +103,14 @@ public class RecentsModel extends TaskStackChangeListener { return mTaskList.isTaskListValid(changeId); } + /** + * @return Whether the task list is currently updating in the background + */ + @VisibleForTesting + public boolean isLoadingTasksInBackground() { + return mTaskList.isLoadingTasksInBackground(); + } + /** * Finds and returns the task key associated with the given task id. * diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java index 8f2356c696..13f6137fb1 100644 --- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java +++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsView.java @@ -24,9 +24,11 @@ import android.app.ActivityManager.RunningTaskInfo; import android.content.Context; import android.os.Build; import android.util.AttributeSet; +import android.util.Log; import com.android.launcher3.anim.PendingAnimation; import com.android.launcher3.statemanager.StateManager.StateListener; +import com.android.launcher3.testing.TestProtocol; import com.android.quickstep.FallbackActivityInterface; import com.android.quickstep.GestureState; import com.android.quickstep.RecentsActivity; @@ -120,6 +122,10 @@ public class FallbackRecentsView extends RecentsView // as well. This tile is never shown as we have setCurrentTaskHidden, but allows use to // track the index of the next task appropriately, as if we are switching on any other app. if (mHomeTaskInfo != null && mHomeTaskInfo.taskId == mRunningTaskId && !tasks.isEmpty()) { + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, + "FallbackRecentsView.applyLoadPlan: running task is home"); + } // Check if the task list has running task boolean found = false; for (Task t : tasks) { diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 78910ceddd..f5c1b87264 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -72,6 +72,7 @@ import android.text.StaticLayout; import android.text.TextPaint; import android.util.AttributeSet; import android.util.FloatProperty; +import android.util.Log; import android.util.SparseBooleanArray; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; @@ -104,6 +105,7 @@ import com.android.launcher3.compat.AccessibilityManagerCompat; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.statehandlers.DepthController; import com.android.launcher3.statemanager.StatefulActivity; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.touch.PagedOrientationHandler; import com.android.launcher3.touch.PagedOrientationHandler.CurveProperties; import com.android.launcher3.util.DynamicResource; @@ -823,6 +825,12 @@ public abstract class RecentsView extends PagedView } protected void applyLoadPlan(ArrayList tasks) { + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "applyLoadPlan: taskCount=" + tasks.size()); + for (Task t : tasks) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "\t" + t); + } + } if (mPendingAnimation != null) { mPendingAnimation.addEndListener(success -> applyLoadPlan(tasks)); return; @@ -884,12 +892,21 @@ public abstract class RecentsView extends PagedView resetTaskVisuals(); onTaskStackUpdated(); updateEnabledOverlays(); + + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "applyLoadPlan: taskViewCount=" + + getTaskViewCount()); + } } private boolean isModal() { return mTaskModalness > 0; } + public boolean isLoadingTasks() { + return mModel.isLoadingTasksInBackground(); + } + private void removeTasksViewsAndClearAllButton() { for (int i = getTaskViewCount() - 1; i >= 0; i--) { removeView(getTaskViewAt(i)); @@ -900,6 +917,12 @@ public abstract class RecentsView extends PagedView } public int getTaskViewCount() { + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "getTaskViewCount:" + + " numChildren=" + getChildCount() + + " start=" + mTaskViewStartIndex + + " clearAll=" + indexOfChild(mClearAllButton)); + } int taskViewCount = getChildCount() - mTaskViewStartIndex; if (indexOfChild(mClearAllButton) != -1) { taskViewCount--; diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index 2e7e6e05ed..713fd074be 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -42,6 +42,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.RemoteException; +import android.util.Log; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; @@ -55,6 +56,7 @@ import com.android.launcher3.tapl.LauncherInstrumentation; import com.android.launcher3.tapl.OverviewTask; import com.android.launcher3.tapl.TestHelpers; import com.android.launcher3.testcomponent.TestCommandReceiver; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.util.Wait; import com.android.launcher3.util.rule.FailureWatcher; import com.android.quickstep.views.RecentsView; @@ -172,9 +174,15 @@ public class FallbackRecentsTest { protected T getFromRecents(Function f) { if (!TestHelpers.isInLauncherProcess()) return null; + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "getFromRecents"); + } Object[] result = new Object[1]; Wait.atMost("Failed to get from recents", () -> MAIN_EXECUTOR.submit(() -> { RecentsActivity activity = RecentsActivity.ACTIVITY_TRACKER.getCreatedActivity(); + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "activity=" + activity); + } if (activity == null) { return false; } @@ -200,8 +208,13 @@ public class FallbackRecentsTest { () -> mLauncher.getRecentTasks().size() >= 3, DEFAULT_ACTIVITY_TIMEOUT, mLauncher); BaseOverview overview = mLauncher.getBackground().switchToOverview(); - executeOnRecents(recents -> - assertTrue("Don't have at least 3 tasks", getTaskCount(recents) >= 3)); + executeOnRecents(recents -> { + if (TestProtocol.sDebugTracing) { + Log.d(TestProtocol.GET_RECENTS_FAILED, "isLoading=" + + recents.getOverviewPanel().isLoadingTasks()); + } + assertTrue("Don't have at least 3 tasks", getTaskCount(recents) >= 3); + }); // Test flinging forward and backward. overview.flingForward(); diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 72bbc43dbe..914772dfac 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -107,4 +107,5 @@ public final class TestProtocol { public static final String NO_SWIPE_TO_HOME = "b/158017601"; public static final String WORK_PROFILE_REMOVED = "b/159671700"; public static final String TIS_NO_EVENTS = "b/180915942"; + public static final String GET_RECENTS_FAILED = "b/177472267"; }