Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a00c81c1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Change thumbnail/icon to get the image rather than updating it" into main

parents 9ec1bc48 551927c6
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -245,11 +245,20 @@ public final class KeyboardQuickSwitchController implements
        }

        void updateThumbnailInBackground(Task task, Consumer<ThumbnailData> callback) {
            mModel.getThumbnailCache().updateThumbnailInBackground(task, callback);
            mModel.getThumbnailCache().getThumbnailInBackground(task,
                    thumbnailData -> {
                        task.thumbnail = thumbnailData;
                        callback.accept(thumbnailData);
                    });
        }

        void updateIconInBackground(Task task, Consumer<Task> callback) {
            mModel.getIconCache().updateIconInBackground(task, callback);
            mModel.getIconCache().getIconInBackground(task, (icon, contentDescription, title) -> {
                task.icon = icon;
                task.titleDescription = contentDescription;
                task.title = title;
                callback.accept(task);
            });
        }

        void onCloseComplete() {
+10 −5
Original line number Diff line number Diff line
@@ -24,11 +24,9 @@ import com.android.launcher3.util.CancellableTask
import com.android.quickstep.RecentsModel
import com.android.quickstep.util.DesktopTask
import com.android.quickstep.util.GroupTask
import com.android.systemui.shared.recents.model.Task
import com.android.window.flags.Flags.enableDesktopWindowingMode
import com.android.window.flags.Flags.enableDesktopWindowingTaskbarRunningApps
import java.io.PrintWriter
import java.util.function.Consumer

/**
 * Provides recent apps functionality, when the Taskbar Recent Apps section is enabled. Behavior:
@@ -185,9 +183,16 @@ class TaskbarRecentAppsController(

        for (groupTask in shownTasks) {
            for (task in groupTask.tasks) {
                val callback =
                    Consumer<Task> { controllers.taskbarViewController.onTaskUpdated(it) }
                val cancellableTask = recentsModel.iconCache.updateIconInBackground(task, callback)
                val cancellableTask =
                    recentsModel.iconCache.getIconInBackground(task) {
                        icon,
                        contentDescription,
                        title ->
                        task.icon = icon
                        task.titleDescription = contentDescription
                        task.title = title
                        controllers.taskbarViewController.onTaskUpdated(task)
                    }
                if (cancellableTask != null) {
                    iconLoadRequests.add(cancellableTask)
                }
+12 −7
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import com.android.systemui.shared.recents.model.Task.TaskKey;
import com.android.systemui.shared.system.PackageManagerWrapper;

import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * Manages the caching of task icons and related data.
@@ -103,21 +102,21 @@ public class TaskIconCache implements DisplayInfoChangeListener {
     * @param callback The callback to receive the task after its data has been populated.
     * @return A cancelable handle to the request
     */
    public CancellableTask updateIconInBackground(Task task, Consumer<Task> callback) {
    public CancellableTask getIconInBackground(Task task, GetTaskIconCallback callback) {
        Preconditions.assertUIThread();
        if (task.icon != null) {
            // Nothing to load, the icon is already loaded
            callback.accept(task);
            callback.onTaskIconReceived(task.icon, task.titleDescription, task.title);
            return null;
        }
        CancellableTask<TaskCacheEntry> request = new CancellableTask<>(
                () -> getCacheEntry(task),
                MAIN_EXECUTOR,
                result -> {
                    task.icon = result.icon;
                    task.titleDescription = result.contentDescription;
                    task.title = result.title;
                    callback.accept(task);
                    callback.onTaskIconReceived(
                            result.icon,
                            result.contentDescription,
                            result.title);
                    dispatchIconUpdate(task.key.id);
                }
        );
@@ -280,6 +279,12 @@ public class TaskIconCache implements DisplayInfoChangeListener {
        public String title = "";
    }

    /** Callback used when retrieving app icons from cache. */
    public interface GetTaskIconCallback {
        /** Called when task icon is retrieved. */
        void onTaskIconReceived(Drawable icon, String contentDescription, String title);
    }

    void registerTaskVisualsChangeListener(TaskVisualsChangeListener newListener) {
        mTaskVisualsChangeListener = newListener;
    }
+5 −9
Original line number Diff line number Diff line
@@ -131,8 +131,7 @@ public class TaskThumbnailCache implements TaskThumbnailDataSource {
        Preconditions.assertUIThread();
        // Fetch the thumbnail for this task and put it in the cache
        if (task.thumbnail == null) {
            updateThumbnailInBackground(task.key, lowResolution,
                    t -> task.thumbnail = t);
            getThumbnailInBackground(task.key, lowResolution, t -> task.thumbnail = t);
        }
    }

@@ -145,13 +144,13 @@ public class TaskThumbnailCache implements TaskThumbnailDataSource {
    }

    /**
     * Asynchronously fetches the icon and other task data for the given {@param task}.
     * Asynchronously fetches the thumbnail for the given {@code task}.
     *
     * @param callback The callback to receive the task after its data has been populated.
     * @return A cancelable handle to the request
     */
    @Override
    public CancellableTask<ThumbnailData> updateThumbnailInBackground(
    public CancellableTask<ThumbnailData> getThumbnailInBackground(
            Task task, @NonNull Consumer<ThumbnailData> callback) {
        Preconditions.assertUIThread();

@@ -164,10 +163,7 @@ public class TaskThumbnailCache implements TaskThumbnailDataSource {
            return null;
        }

        return updateThumbnailInBackground(task.key, !mHighResLoadingState.isEnabled(), t -> {
            task.thumbnail = t;
            callback.accept(t);
        });
        return getThumbnailInBackground(task.key, !mHighResLoadingState.isEnabled(), callback);
    }

    /**
@@ -187,7 +183,7 @@ public class TaskThumbnailCache implements TaskThumbnailDataSource {
        return newSize > oldSize;
    }

    private CancellableTask<ThumbnailData> updateThumbnailInBackground(TaskKey key,
    private CancellableTask<ThumbnailData> getThumbnailInBackground(TaskKey key,
            boolean lowResolution, Consumer<ThumbnailData> callback) {
        Preconditions.assertUIThread();

+4 −8
Original line number Diff line number Diff line
@@ -67,14 +67,15 @@ class TasksRepository(
        this.visibleTaskIds.value = visibleTaskIdList.toSet()
    }

    /** Flow wrapper for [TaskThumbnailDataSource.updateThumbnailInBackground] api */
    /** Flow wrapper for [TaskThumbnailDataSource.getThumbnailInBackground] api */
    private fun getThumbnailDataRequest(task: Task): ThumbnailDataRequest =
        flow {
                emit(task.key.id to task.thumbnail)
                val thumbnailDataResult: ThumbnailData? =
                    suspendCancellableCoroutine { continuation ->
                        val cancellableTask =
                            taskThumbnailDataSource.updateThumbnailInBackground(task) {
                            taskThumbnailDataSource.getThumbnailInBackground(task) {
                                task.thumbnail = it
                                continuation.resume(it)
                            }
                        continuation.invokeOnCancellation { cancellableTask?.cancel() }
@@ -94,12 +95,7 @@ class TasksRepository(
                tasks.filter { it.key.id in visibleIds }
            }
        val visibleThumbnailDataRequests: Flow<List<ThumbnailDataRequest>> =
            visibleTasks.map {
                it.map { visibleTask ->
                    val taskCopy = Task(visibleTask).apply { thumbnail = visibleTask.thumbnail }
                    getThumbnailDataRequest(taskCopy)
                }
            }
            visibleTasks.map { visibleTasksList -> visibleTasksList.map(::getThumbnailDataRequest) }
        return visibleThumbnailDataRequests.flatMapLatest {
            thumbnailRequestFlows: List<ThumbnailDataRequest> ->
            if (thumbnailRequestFlows.isEmpty()) {
Loading