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

Commit 62764dfa authored by wilsonshih's avatar wilsonshih Committed by Wei Sheng Shih
Browse files

Add a reference to the snapshot when calling takeTaskSnapshot.

If takeTaskSnapshot is called multiple times for the same task during
or after a transition, the initially created snapshot can be replaced
by a later one before it is returned to the client. Adding a reference
ensures that the initial snapshot is not released before its parceling
is complete.

Flag: EXEMPT bugfix
Bug: 412389050
Test: Close the app using the gesture multiple times and verify that no
crashes occur.

Change-Id: Ie9b644bb64888f813b48e4c6de17977df8be769e
parent 8fee1444
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4105,8 +4105,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                // be retrieved by recents. While if updateCache is false, the real snapshot will
                // always be taken and the snapshot won't be put into SnapshotPersister.
                if (updateCache) {
                    supplier = mWindowManager.mTaskSnapshotController
                            .getRecordSnapshotSupplier(task);
                    supplier = mWindowManager.mTaskSnapshotController.getRecordSnapshotSupplier(
                            task, TaskSnapshot.REFERENCE_WRITE_TO_PARCEL);
                } else {
                    return mWindowManager.mTaskSnapshotController.snapshot(task);
                }
+9 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.wm;

import static android.window.TaskSnapshot.REFERENCE_NONE;

import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;

@@ -134,7 +136,7 @@ class TaskSnapshotController extends AbsAppSnapshotController<Task, TaskSnapshot
        if (shouldDisableSnapshots()) {
            return;
        }
        final SnapshotSupplier supplier = getRecordSnapshotSupplier(task);
        final SnapshotSupplier supplier = getRecordSnapshotSupplier(task, REFERENCE_NONE);
        if (supplier == null) {
            return;
        }
@@ -152,8 +154,12 @@ class TaskSnapshotController extends AbsAppSnapshotController<Task, TaskSnapshot
     * {@link AbsAppSnapshotController.SnapshotSupplier#handleSnapshot} to complete the entire
     * record request.
     */
    SnapshotSupplier getRecordSnapshotSupplier(Task task) {
    SnapshotSupplier getRecordSnapshotSupplier(Task task,
            @TaskSnapshot.ReferenceFlags int initialUsage) {
        return recordSnapshotInner(task, true /* allowAppTheme */, snapshot -> {
            if (initialUsage != REFERENCE_NONE) {
                snapshot.addReference(initialUsage);
            }
            if (!task.isActivityTypeHome()) {
                mPersister.persistSnapshot(task.mTaskId, task.mUserId, snapshot);
                task.onSnapshotChanged(snapshot);
@@ -166,7 +172,7 @@ class TaskSnapshotController extends AbsAppSnapshotController<Task, TaskSnapshot
     */
    @Nullable
    TaskSnapshot getSnapshot(int taskId, boolean isLowResolution) {
        return getSnapshot(taskId, false /* isLowResolution */, TaskSnapshot.REFERENCE_NONE);
        return getSnapshot(taskId, false /* isLowResolution */, REFERENCE_NONE);
    }

    /**