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

Commit 35e3f53a authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Also store reduced resolution screenshots

In order to speed up loading time when scrolling through it
in recents. They will be used in recents in the next CL. Also, we
use JPG instead as loading JPG is much faster than PNG.

Test: TaskSnapshotPersisterLoaderTest
Test: TaskSnapshotCacheTest
Bug: 34829962
Change-Id: I4c74b26969ae459bd3b1a42707011a49f425abd9
parent c9c57d44
Loading
Loading
Loading
Loading
+36 −2
Original line number Diff line number Diff line
@@ -2177,31 +2177,62 @@ public class ActivityManager {
        private final GraphicBuffer mSnapshot;
        private final int mOrientation;
        private final Rect mContentInsets;
        private final boolean mReducedResolution;
        private final float mScale;

        public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets) {
        public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets,
                boolean reducedResolution, float scale) {
            mSnapshot = snapshot;
            mOrientation = orientation;
            mContentInsets = new Rect(contentInsets);
            mReducedResolution = reducedResolution;
            mScale = scale;
        }

        private TaskSnapshot(Parcel source) {
            mSnapshot = source.readParcelable(null /* classLoader */);
            mOrientation = source.readInt();
            mContentInsets = source.readParcelable(null /* classLoader */);
            mReducedResolution = source.readBoolean();
            mScale = source.readFloat();
        }

        /**
         * @return The graphic buffer representing the screenshot.
         */
        public GraphicBuffer getSnapshot() {
            return mSnapshot;
        }

        /**
         * @return The screen orientation the screenshot was taken in.
         */
        public int getOrientation() {
            return mOrientation;
        }

        /**
         * @return The system/content insets on the snapshot. These can be clipped off in order to
         *         remove any areas behind system bars in the snapshot.
         */
        public Rect getContentInsets() {
            return mContentInsets;
        }

        /**
         * @return Whether this snapshot is a down-sampled version of the full resolution.
         */
        public boolean isReducedResolution() {
            return mReducedResolution;
        }

        /**
         * @return The scale this snapshot was taken in.
         */
        public float getScale() {
            return mScale;
        }

        @Override
        public int describeContents() {
            return 0;
@@ -2212,12 +2243,15 @@ public class ActivityManager {
            dest.writeParcelable(mSnapshot, 0);
            dest.writeInt(mOrientation);
            dest.writeParcelable(mContentInsets, 0);
            dest.writeBoolean(mReducedResolution);
            dest.writeFloat(mScale);
        }

        @Override
        public String toString() {
            return "TaskSnapshot{mSnapshot=" + mSnapshot + " mOrientation=" + mOrientation
                    + " mContentInsets=" + mContentInsets.toShortString();
                    + " mContentInsets=" + mContentInsets.toShortString()
                    + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale;
        }

        public static final Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
+4 −1
Original line number Diff line number Diff line
@@ -600,9 +600,12 @@ interface IActivityManager {
    void cancelTaskThumbnailTransition(int taskId);

    /**
     * @param taskId the id of the task to retrieve the snapshots for
     * @param reducedResolution if set, if the snapshot needs to be loaded from disk, this will load
     *                          a reduced resolution of it, which is much faster
     * @return a graphic buffer representing a screenshot of a task
     */
    ActivityManager.TaskSnapshot getTaskSnapshot(int taskId);
    ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution);

    void scheduleApplicationInfoChanged(in List<String> packageNames, int userId);
    void setPersistentVrThread(int tid);
+2 −1
Original line number Diff line number Diff line
@@ -678,7 +678,8 @@ public class SystemServicesProxy {
        if (ActivityManager.ENABLE_TASK_SNAPSHOTS) {
            ActivityManager.TaskSnapshot snapshot = null;
            try {
                snapshot = ActivityManager.getService().getTaskSnapshot(taskId);
                snapshot = ActivityManager.getService().getTaskSnapshot(taskId,
                        false /* reducedResolution */);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed to retrieve snapshot", e);
            }
+2 −2
Original line number Diff line number Diff line
@@ -10028,7 +10028,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    @Override
    public TaskSnapshot getTaskSnapshot(int taskId) {
    public TaskSnapshot getTaskSnapshot(int taskId, boolean reducedResolution) {
        enforceCallingPermission(READ_FRAME_BUFFER, "getTaskSnapshot()");
        final long ident = Binder.clearCallingIdentity();
        try {
@@ -10042,7 +10042,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                }
            }
            // Don't call this while holding the lock as this operation might hit the disk.
            return task.getSnapshot();
            return task.getSnapshot(reducedResolution);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
+2 −2
Original line number Diff line number Diff line
@@ -737,11 +737,11 @@ final class TaskRecord extends ConfigurationContainer implements TaskWindowConta
    /**
     * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
     */
    TaskSnapshot getSnapshot() {
    TaskSnapshot getSnapshot(boolean reducedResolution) {

        // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
        // synchronized between AM and WM.
        return mService.mWindowManager.getTaskSnapshot(taskId, userId);
        return mService.mWindowManager.getTaskSnapshot(taskId, userId, reducedResolution);
    }

    void touchActiveTime() {
Loading