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

Commit 721952cf authored by wilsonshih's avatar wilsonshih
Browse files

Record task snapshot before shutdown.

Flag: com.android.window.flags.record_task_snapshots_before_shutdown
Bug: 376821232
Test: open app without close it, reboot device and verify the snapshot
can shown in recents.

Change-Id: I4bb4d17afd7f0233e8af970f87194db64ae87599
parent 2466f2d2
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -417,6 +417,17 @@ flag {
    bug: "362938401"
    bug: "362938401"
}
}


flag {
  name: "record_task_snapshots_before_shutdown"
  namespace: "windowing_frontend"
  description: "Record task snapshots before shutdown"
  bug: "376821232"
  is_fixed_read_only: true
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
flag {
    name: "predictive_back_three_button_nav"
    name: "predictive_back_three_button_nav"
    namespace: "systemui"
    namespace: "systemui"
+4 −1
Original line number Original line Diff line number Diff line
@@ -2856,7 +2856,10 @@ class RootWindowContainer extends WindowContainer<DisplayContent>


    void prepareForShutdown() {
    void prepareForShutdown() {
        for (int i = 0; i < getChildCount(); i++) {
        for (int i = 0; i < getChildCount(); i++) {
            createSleepToken("shutdown", getChildAt(i).mDisplayId);
            final int displayId = getChildAt(i).mDisplayId;
            mWindowManager.mSnapshotController.mTaskSnapshotController
                    .snapshotForShutdown(displayId);
            createSleepToken("shutdown", displayId);
        }
        }
    }
    }


+14 −1
Original line number Original line Diff line number Diff line
@@ -64,6 +64,7 @@ class SnapshotPersistQueue {
    private boolean mStarted;
    private boolean mStarted;
    private final Object mLock = new Object();
    private final Object mLock = new Object();
    private final UserManagerInternal mUserManagerInternal;
    private final UserManagerInternal mUserManagerInternal;
    private boolean mShutdown;


    SnapshotPersistQueue() {
    SnapshotPersistQueue() {
        mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
        mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
@@ -101,6 +102,16 @@ class SnapshotPersistQueue {
        }
        }
    }
    }


    /**
     * Write out everything in the queue because of shutdown.
     */
    void shutdown() {
        synchronized (mLock) {
            mShutdown = true;
            mLock.notifyAll();
        }
    }

    @VisibleForTesting
    @VisibleForTesting
    void waitForQueueEmpty() {
    void waitForQueueEmpty() {
        while (true) {
        while (true) {
@@ -193,8 +204,10 @@ class SnapshotPersistQueue {
                    if (isReadyToWrite) {
                    if (isReadyToWrite) {
                        next.write();
                        next.write();
                    }
                    }
                    if (!mShutdown) {
                        SystemClock.sleep(DELAY_MS);
                        SystemClock.sleep(DELAY_MS);
                    }
                    }
                }
                synchronized (mLock) {
                synchronized (mLock) {
                    final boolean writeQueueEmpty = mWriteQueue.isEmpty();
                    final boolean writeQueueEmpty = mWriteQueue.isEmpty();
                    if (!writeQueueEmpty && !mPaused) {
                    if (!writeQueueEmpty && !mPaused) {
+22 −0
Original line number Original line Diff line number Diff line
@@ -306,6 +306,28 @@ class TaskSnapshotController extends AbsAppSnapshotController<Task, TaskSnapshot
        mPersister.removeObsoleteFiles(persistentTaskIds, runningUserIds);
        mPersister.removeObsoleteFiles(persistentTaskIds, runningUserIds);
    }
    }


    /**
     * Record task snapshots before shutdown.
     */
    void snapshotForShutdown(int displayId) {
        if (!com.android.window.flags.Flags.recordTaskSnapshotsBeforeShutdown()) {
            return;
        }
        final DisplayContent displayContent = mService.mRoot.getDisplayContent(displayId);
        if (displayContent == null) {
            return;
        }
        displayContent.forAllLeafTasks(task -> {
            if (task.isVisible() && !task.isActivityTypeHome()) {
                final TaskSnapshot snapshot = captureSnapshot(task);
                if (snapshot != null) {
                    mPersister.persistSnapshot(task.mTaskId, task.mUserId, snapshot);
                }
            }
        }, true /* traverseTopToBottom */);
        mPersister.mSnapshotPersistQueue.shutdown();
    }

    /**
    /**
     * Called when screen is being turned off.
     * Called when screen is being turned off.
     */
     */