Merge "Do not hold lock when trying to get snapshot" into qt-dev

am: beee882cdf

Change-Id: Ib05ead915b0e84cef8d837c02d9e7ed04a57fa31
This commit is contained in:
Jorim Jaggi
2019-06-05 03:12:30 -07:00
committed by android-build-merger
5 changed files with 28 additions and 21 deletions

View File

@@ -98,7 +98,7 @@ public final class ContentSuggestionsPerUserService extends
RemoteContentSuggestionsService service = getRemoteServiceLocked();
if (service != null) {
ActivityManager.TaskSnapshot snapshot =
mActivityTaskManagerInternal.getTaskSnapshot(taskId, false);
mActivityTaskManagerInternal.getTaskSnapshotNoRestore(taskId, false);
GraphicBuffer snapshotBuffer = null;
int colorSpaceId = 0;
if (snapshot != null) {

View File

@@ -559,7 +559,7 @@ public abstract class ActivityTaskManagerInternal {
/**
* Gets bitmap snapshot of the provided task id.
*/
public abstract ActivityManager.TaskSnapshot getTaskSnapshot(int taskId,
public abstract ActivityManager.TaskSnapshot getTaskSnapshotNoRestore(int taskId,
boolean reducedResolution);
/** Returns true if uid is considered foreground for activity start purposes. */

View File

@@ -4521,22 +4521,27 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
enforceCallerIsRecentsOrHasPermission(READ_FRAME_BUFFER, "getTaskSnapshot()");
final long ident = Binder.clearCallingIdentity();
try {
final TaskRecord task;
synchronized (mGlobalLock) {
task = mRootActivityContainer.anyTaskForId(taskId,
MATCH_TASK_IN_STACKS_OR_RECENT_TASKS);
if (task == null) {
Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found");
return null;
}
}
// Don't call this while holding the lock as this operation might hit the disk.
return task.getSnapshot(reducedResolution);
return getTaskSnapshot(taskId, reducedResolution, true /* restoreFromDisk */);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
private ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution,
boolean restoreFromDisk) {
final TaskRecord task;
synchronized (mGlobalLock) {
task = mRootActivityContainer.anyTaskForId(taskId,
MATCH_TASK_IN_STACKS_OR_RECENT_TASKS);
if (task == null) {
Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found");
return null;
}
}
// Don't call this while holding the lock as this operation might hit the disk.
return task.getSnapshot(reducedResolution, restoreFromDisk);
}
@Override
public void setDisablePreviewScreenshots(IBinder token, boolean disable) {
synchronized (mGlobalLock) {
@@ -7419,10 +7424,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
@Override
public ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) {
synchronized (mGlobalLock) {
return ActivityTaskManagerService.this.getTaskSnapshot(taskId, reducedResolution);
}
public ActivityManager.TaskSnapshot getTaskSnapshotNoRestore(int taskId,
boolean reducedResolution) {
return ActivityTaskManagerService.this.getTaskSnapshot(taskId, reducedResolution,
false /* restoreFromDisk */);
}
@Override

View File

@@ -851,11 +851,12 @@ class TaskRecord extends ConfigurationContainer {
/**
* DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
*/
TaskSnapshot getSnapshot(boolean reducedResolution) {
TaskSnapshot getSnapshot(boolean reducedResolution, boolean restoreFromDisk) {
// TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
// synchronized between AM and WM.
return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution);
return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution,
restoreFromDisk);
}
void touchActiveTime() {

View File

@@ -3551,8 +3551,9 @@ public class WindowManagerService extends IWindowManager.Stub
return true;
}
public TaskSnapshot getTaskSnapshot(int taskId, int userId, boolean reducedResolution) {
return mTaskSnapshotController.getSnapshot(taskId, userId, true /* restoreFromDisk */,
public TaskSnapshot getTaskSnapshot(int taskId, int userId, boolean reducedResolution,
boolean restoreFromDisk) {
return mTaskSnapshotController.getSnapshot(taskId, userId, restoreFromDisk,
reducedResolution);
}