Merge "Take the snapshot if the thumbnail cache returns empty." into tm-qpr-dev

This commit is contained in:
Iris Yang
2022-07-01 05:52:34 +00:00
committed by Android (Google) Code Review
5 changed files with 20 additions and 9 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -3660,7 +3660,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 {
@@ -3674,8 +3675,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);
}
@@ -6648,7 +6653,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

View File

@@ -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));