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

Commit ed0a3c23 authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Android (Google) Code Review
Browse files

Merge "Record task snapshot before shutdown." into main

parents e5d7a587 721952cf
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -417,6 +417,17 @@ flag {
    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 {
    name: "predictive_back_three_button_nav"
    namespace: "systemui"
+4 −1
Original line number Diff line number Diff line
@@ -2856,7 +2856,10 @@ class RootWindowContainer extends WindowContainer<DisplayContent>

    void prepareForShutdown() {
        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 Diff line number Diff line
@@ -64,6 +64,7 @@ class SnapshotPersistQueue {
    private boolean mStarted;
    private final Object mLock = new Object();
    private final UserManagerInternal mUserManagerInternal;
    private boolean mShutdown;

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