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

Commit 3b9bdcff authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Adds identifier to TaskSnapshot

This identifier is introduced to differentiate two task snapshots in
AiAi. Currently, the timestamp (in millis) is chosen as the identifier.

Bug: 136563752
Test: atest TaskSnapshotPersisterLoaderTest
Change-Id: I249511d1e4bb34a93d5db08d2b1cea3b1ee5d034
parent ba7fb6a5
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -1822,7 +1822,8 @@ public class ActivityManager {
     * @hide
     */
    public static class TaskSnapshot implements Parcelable {

        // Identifier of this snapshot
        private final long mId;
        // Top activity in task when snapshot was taken
        private final ComponentName mTopActivityComponent;
        private final GraphicBuffer mSnapshot;
@@ -1841,10 +1842,12 @@ public class ActivityManager {
        // Must be one of the named color spaces, otherwise, always use SRGB color space.
        private final ColorSpace mColorSpace;

        public TaskSnapshot(@NonNull ComponentName topActivityComponent, GraphicBuffer snapshot,
        public TaskSnapshot(long id,
                @NonNull ComponentName topActivityComponent, GraphicBuffer snapshot,
                @NonNull ColorSpace colorSpace, int orientation, Rect contentInsets,
                boolean reducedResolution, float scale, boolean isRealSnapshot, int windowingMode,
                int systemUiVisibility, boolean isTranslucent) {
            mId = id;
            mTopActivityComponent = topActivityComponent;
            mSnapshot = snapshot;
            mColorSpace = colorSpace.getId() < 0
@@ -1860,6 +1863,7 @@ public class ActivityManager {
        }

        private TaskSnapshot(Parcel source) {
            mId = source.readLong();
            mTopActivityComponent = ComponentName.readFromParcel(source);
            mSnapshot = source.readParcelable(null /* classLoader */);
            int colorSpaceId = source.readInt();
@@ -1876,6 +1880,13 @@ public class ActivityManager {
            mIsTranslucent = source.readBoolean();
        }

        /**
         * @return Identifier of this snapshot.
         */
        public long getId() {
            return mId;
        }

        /**
         * @return The top activity component for the task at the point this snapshot was taken.
         */
@@ -1970,6 +1981,7 @@ public class ActivityManager {

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeLong(mId);
            ComponentName.writeToParcel(mTopActivityComponent, dest);
            dest.writeParcelable(mSnapshot, 0);
            dest.writeInt(mColorSpace.getId());
@@ -1988,6 +2000,7 @@ public class ActivityManager {
            final int width = mSnapshot != null ? mSnapshot.getWidth() : 0;
            final int height = mSnapshot != null ? mSnapshot.getHeight() : 0;
            return "TaskSnapshot{"
                    + " mId=" + mId
                    + " mTopActivityComponent=" + mTopActivityComponent.flattenToShortString()
                    + " mSnapshot=" + mSnapshot + " (" + width + "x" + height + ")"
                    + " mColorSpace=" + mColorSpace.toString()
+3 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public class ThumbnailData {
    public int windowingMode;
    public int systemUiVisibility;
    public float scale;
    public long snapshotId;

    public ThumbnailData() {
        thumbnail = null;
@@ -49,6 +50,7 @@ public class ThumbnailData {
        isTranslucent = false;
        windowingMode = WINDOWING_MODE_UNDEFINED;
        systemUiVisibility = 0;
        snapshotId = 0;
    }

    public ThumbnailData(TaskSnapshot snapshot) {
@@ -61,5 +63,6 @@ public class ThumbnailData {
        isTranslucent = snapshot.isTranslucent();
        windowingMode = snapshot.getWindowingMode();
        systemUiVisibility = snapshot.getSystemUiVisibility();
        snapshotId = snapshot.getId();
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -33,4 +33,5 @@
     bool is_translucent = 9;
     string top_activity_component = 10;
     float scale = 11;
     int64 id = 12;
 }
+4 −1
Original line number Diff line number Diff line
@@ -310,6 +310,7 @@ class TaskSnapshotController {
        }
        final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE;
        return new TaskSnapshot(
                System.currentTimeMillis() /* id */,
                appWindowToken.mActivityComponent, screenshotBuffer.getGraphicBuffer(),
                screenshotBuffer.getColorSpace(),
                appWindowToken.getTask().getConfiguration().orientation,
@@ -404,7 +405,9 @@ class TaskSnapshotController {

        // Note, the app theme snapshot is never translucent because we enforce a non-translucent
        // color above
        return new TaskSnapshot(topChild.mActivityComponent, hwBitmap.createGraphicBufferHandle(),
        return new TaskSnapshot(
                System.currentTimeMillis() /* id */,
                topChild.mActivityComponent, hwBitmap.createGraphicBufferHandle(),
                hwBitmap.getColorSpace(), topChild.getTask().getConfiguration().orientation,
                getInsets(mainWindow), ActivityManager.isLowRamDeviceStatic() /* reduced */,
                mFullSnapshotScale, false /* isRealSnapshot */, task.getWindowingMode(),
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ class TaskSnapshotLoader {
            // For legacy snapshots, restore the scale based on the reduced resolution state
            final float legacyScale = reducedResolution ? mPersister.getReducedScale() : 1f;
            final float scale = Float.compare(proto.scale, 0f) != 0 ? proto.scale : legacyScale;
            return new TaskSnapshot(topActivityComponent, buffer, bitmap.getColorSpace(),
            return new TaskSnapshot(proto.id, topActivityComponent, buffer, bitmap.getColorSpace(),
                    proto.orientation,
                    new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom),
                    reducedResolution, scale, proto.isRealSnapshot, proto.windowingMode,
Loading