Add some logging for failure to get recents

Bug: 177472267
Test: Presubmit
Change-Id: I64a01ef076a58bc3118840ff3171177f61edc3f5
This commit is contained in:
Winson Chung committed 2021-03-04 14:18:41 -08:00
1 parent 9cde419ee0
commit 0613af3587
6 files changed
+86 -3

No files matched your search

@@ -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<ArrayList<Task>> 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<Task> 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<Task> result = copyOf(mResultsUi);
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.GET_RECENTS_FAILED, "getTasks: callback w/ bg results");
}
callback.accept(result);
}
});