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

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

Merge "Refactor snapshot access between from cache and disk." into main

parents f33dd0ba c262b2c1
Loading
Loading
Loading
Loading
+13 −1
Original line number Original line Diff line number Diff line
@@ -77,6 +77,8 @@ public class TaskSnapshot implements Parcelable {
    private final ColorSpace mColorSpace;
    private final ColorSpace mColorSpace;
    private int mInternalReferences;
    private int mInternalReferences;


    /** Keep in cache, doesn't need reference. */
    public static final int REFERENCE_NONE = 0;
    /** This snapshot object is being broadcast. */
    /** This snapshot object is being broadcast. */
    public static final int REFERENCE_BROADCAST = 1;
    public static final int REFERENCE_BROADCAST = 1;
    /** This snapshot object is in the cache. */
    /** This snapshot object is in the cache. */
@@ -85,11 +87,16 @@ public class TaskSnapshot implements Parcelable {
    public static final int REFERENCE_PERSIST = 1 << 2;
    public static final int REFERENCE_PERSIST = 1 << 2;
    /** This snapshot object is being used for content suggestion. */
    /** This snapshot object is being used for content suggestion. */
    public static final int REFERENCE_CONTENT_SUGGESTION = 1 << 3;
    public static final int REFERENCE_CONTENT_SUGGESTION = 1 << 3;
    /** This snapshot object will be passing to external process. Keep the snapshot reference after
     * writeToParcel*/
    public static final int REFERENCE_WRITE_TO_PARCEL = 1 << 4;
    @IntDef(flag = true, prefix = { "REFERENCE_" }, value = {
    @IntDef(flag = true, prefix = { "REFERENCE_" }, value = {
            REFERENCE_NONE,
            REFERENCE_BROADCAST,
            REFERENCE_BROADCAST,
            REFERENCE_CACHE,
            REFERENCE_CACHE,
            REFERENCE_PERSIST,
            REFERENCE_PERSIST,
            REFERENCE_CONTENT_SUGGESTION
            REFERENCE_CONTENT_SUGGESTION,
            REFERENCE_WRITE_TO_PARCEL
    })
    })
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    public @interface ReferenceFlags {}
    public @interface ReferenceFlags {}
@@ -309,6 +316,11 @@ public class TaskSnapshot implements Parcelable {
        dest.writeBoolean(mIsTranslucent);
        dest.writeBoolean(mIsTranslucent);
        dest.writeBoolean(mHasImeSurface);
        dest.writeBoolean(mHasImeSurface);
        dest.writeInt(mUiMode);
        dest.writeInt(mUiMode);
        synchronized (this) {
            if ((mInternalReferences & REFERENCE_WRITE_TO_PARCEL) != 0) {
                removeReference(REFERENCE_WRITE_TO_PARCEL);
            }
        }
    }
    }


    @Override
    @Override
+2 −3
Original line number Original line Diff line number Diff line
@@ -2406,9 +2406,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            return false;
            return false;
        }
        }


        final TaskSnapshot snapshot =
        final TaskSnapshot snapshot = mWmService.mTaskSnapshotController.getSnapshot(task.mTaskId,
                mWmService.mTaskSnapshotController.getSnapshot(task.mTaskId, task.mUserId,
                false /* isLowResolution */);
                        false /* restoreFromDisk */, false /* isLowResolution */);
        final int type = getStartingWindowType(newTask, taskSwitch, processRunning,
        final int type = getStartingWindowType(newTask, taskSwitch, processRunning,
                allowTaskSnapshot, activityCreated, activityAllDrawn, snapshot);
                allowTaskSnapshot, activityCreated, activityAllDrawn, snapshot);


+2 −1
Original line number Original line Diff line number Diff line
@@ -149,7 +149,8 @@ class ActivitySnapshotController extends AbsAppSnapshotController<ActivityRecord
        for (int i = activities.length - 1; i >= 0; --i) {
        for (int i = activities.length - 1; i >= 0; --i) {
            fileId ^= getSystemHashCode(activities[i]);
            fileId ^= getSystemHashCode(activities[i]);
        }
        }
        return tmpUsf.mFileId == fileId ? mCache.getSnapshot(tmpUsf.mActivityIds.get(0)) : null;
        return tmpUsf.mFileId == fileId
                ? mCache.getSnapshotInner(tmpUsf.mActivityIds.get(0)) : null;
    }
    }


    private void cleanUpUserFiles(int userId) {
    private void cleanUpUserFiles(int userId) {
+10 −6
Original line number Original line Diff line number Diff line
@@ -3996,15 +3996,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }
            }
            // Try to load snapshot from cache first, and add reference if the snapshot is in cache.
            // Try to load snapshot from cache first, and add reference if the snapshot is in cache.
            final TaskSnapshot snapshot = mWindowManager.mTaskSnapshotController.getSnapshot(taskId,
            final TaskSnapshot snapshot = mWindowManager.mTaskSnapshotController.getSnapshot(taskId,
                    task.mUserId, false /* restoreFromDisk */, isLowResolution);
                    isLowResolution, usage);
            if (snapshot != null) {
            if (snapshot != null) {
                snapshot.addReference(usage);
                return snapshot;
                return snapshot;
            }
            }
        }
        }
        // Don't call this while holding the lock as this operation might hit the disk.
        // Don't call this while holding the lock as this operation might hit the disk.
        return mWindowManager.mTaskSnapshotController.getSnapshot(taskId,
        return mWindowManager.mTaskSnapshotController.getSnapshotFromDisk(taskId,
                task.mUserId, true /* restoreFromDisk */, isLowResolution);
                task.mUserId,  isLowResolution, usage);
    }
    }


    @Override
    @Override
@@ -4020,10 +4019,15 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found");
                    Slog.w(TAG, "getTaskSnapshot: taskId=" + taskId + " not found");
                    return null;
                    return null;
                }
                }
                final TaskSnapshot snapshot = mWindowManager.mTaskSnapshotController.getSnapshot(
                        taskId, isLowResolution, TaskSnapshot.REFERENCE_WRITE_TO_PARCEL);
                if (snapshot != null) {
                    return snapshot;
                }
            }
            }
            // Don't call this while holding the lock as this operation might hit the disk.
            // Don't call this while holding the lock as this operation might hit the disk.
            return mWindowManager.mTaskSnapshotController.getSnapshot(taskId,
            return mWindowManager.mTaskSnapshotController.getSnapshotFromDisk(taskId,
                    task.mUserId, true /* restoreFromDisk */, isLowResolution);
                    task.mUserId, isLowResolution, TaskSnapshot.REFERENCE_WRITE_TO_PARCEL);
        } finally {
        } finally {
            Binder.restoreCallingIdentity(ident);
            Binder.restoreCallingIdentity(ident);
        }
        }
+1 −2
Original line number Original line Diff line number Diff line
@@ -2251,8 +2251,7 @@ class BackNavigationController {
        if (w.asTask() != null) {
        if (w.asTask() != null) {
            final Task task = w.asTask();
            final Task task = w.asTask();
            snapshot = task.mRootWindowContainer.mWindowManager.mTaskSnapshotController.getSnapshot(
            snapshot = task.mRootWindowContainer.mWindowManager.mTaskSnapshotController.getSnapshot(
                    task.mTaskId, task.mUserId, false /* restoreFromDisk */,
                    task.mTaskId, false /* isLowResolution */);
                    false /* isLowResolution */);
        } else {
        } else {
            ActivityRecord ar = w.asActivityRecord();
            ActivityRecord ar = w.asActivityRecord();
            if (ar == null && w.asTaskFragment() != null) {
            if (ar == null && w.asTaskFragment() != null) {
Loading