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

Commit 8b1aed02 authored by Iris Yang's avatar Iris Yang
Browse files

Take the snapshot if the thumbnail cache returns empty.

To avoid Recents thumbnail being empty, a snapshot is triggered if no
cache exists.

Bug: 191272693
Test: manually test with Exo (Host apps on virtual display.) to check if
the Recents displays non-empty thumbnail.

Change-Id: I2a898d5127e18e6209ff236d3a72aa22c2a0ca82
parent a41398ef
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -263,9 +263,12 @@ interface IActivityTaskManager {
     * @param taskId the id of the task to retrieve the sAutoapshots for
     * @param isLowResolution if set, if the snapshot needs to be loaded from disk, this will load
     *                          a reduced resolution of it, which is much faster
     * @param takeSnapshotIfNeeded if set, call {@link #takeTaskSnapshot} to trigger the snapshot
                                   if no cache exists.
     * @return a graphic buffer representing a screenshot of a task
     */
    android.window.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution);
    android.window.TaskSnapshot getTaskSnapshot(
            int taskId, boolean isLowResolution, boolean takeSnapshotIfNeeded);

    /**
     * @param taskId the id of the task to take a snapshot of
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public class PipUtils {
        if (taskId <= 0) return null;
        try {
            return ActivityTaskManager.getService().getTaskSnapshot(
                    taskId, isLowResolution);
                    taskId, isLowResolution, false /* takeSnapshotIfNeeded */);
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to get task snapshot, taskId=" + taskId, e);
            return null;
+4 −2
Original line number Diff line number Diff line
@@ -137,12 +137,14 @@ public class ActivityManagerWrapper {
    }

    /**
     * @return the task snapshot for the given {@param taskId}.
     * @return a {@link ThumbnailData} with {@link TaskSnapshot} for the given {@param taskId}.
     *         The snapshot will be triggered if no cached {@link TaskSnapshot} exists.
     */
    public @NonNull ThumbnailData getTaskThumbnail(int taskId, boolean isLowResolution) {
        TaskSnapshot snapshot = null;
        try {
            snapshot = getService().getTaskSnapshot(taskId, isLowResolution);
            snapshot = getService().getTaskSnapshot(taskId, isLowResolution,
                    true /* takeSnapshotIfNeeded */);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to retrieve task snapshot", e);
        }
+10 −4
Original line number Diff line number Diff line
@@ -3668,7 +3668,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
    }

    @Override
    public TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution) {
    public TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution,
            boolean takeSnapshotIfNeeded) {
        mAmInternal.enforceCallingPermission(READ_FRAME_BUFFER, "getTaskSnapshot()");
        final long ident = Binder.clearCallingIdentity();
        try {
@@ -3682,8 +3683,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                }
            }
            // Don't call this while holding the lock as this operation might hit the disk.
            return mWindowManager.mTaskSnapshotController.getSnapshot(taskId, task.mUserId,
                    true /* restoreFromDisk */, isLowResolution);
            TaskSnapshot taskSnapshot = mWindowManager.mTaskSnapshotController.getSnapshot(taskId,
                    task.mUserId, true /* restoreFromDisk */, isLowResolution);
            if (taskSnapshot == null && takeSnapshotIfNeeded) {
                taskSnapshot = takeTaskSnapshot(taskId);
            }
            return taskSnapshot;
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
@@ -6656,7 +6661,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        @Override
        public TaskSnapshot getTaskSnapshotBlocking(
                int taskId, boolean isLowResolution) {
            return ActivityTaskManagerService.this.getTaskSnapshot(taskId, isLowResolution);
            return ActivityTaskManagerService.this.getTaskSnapshot(taskId, isLowResolution,
                    false /* takeSnapshotIfNeeded */);
        }

        @Override
+1 −1
Original line number Diff line number Diff line
@@ -1332,7 +1332,7 @@ public class RecentTasksTest extends WindowTestsBase {
        });
        assertSecurityException(expectCallable,
                () -> mAtm.startActivityFromRecents(0, new Bundle()));
        assertSecurityException(expectCallable, () -> mAtm.getTaskSnapshot(0, true));
        assertSecurityException(expectCallable, () -> mAtm.getTaskSnapshot(0, true, false));
        assertSecurityException(expectCallable, () -> mAtm.registerTaskStackListener(null));
        assertSecurityException(expectCallable,
                () -> mAtm.unregisterTaskStackListener(null));