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

Commit b6c4b82e authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Move TaskSnapshot into android.window package

Bug: 166736352
Test: build pass
Test: atest CtsWindowManagerDeviceTests
Change-Id: I7f03524f018ceb64c109fd9d78abeb0ea98b6ea5
parent 00da245b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.Is.is;

import android.app.ActivityManager;
import android.app.ActivityManager.TaskSnapshot;
import android.app.ActivityTaskManager;
import android.window.TaskSnapshot;
import android.app.IActivityTaskManager;
import android.content.ComponentName;
import android.content.Context;
+1 −3
Original line number Diff line number Diff line
@@ -25,5 +25,3 @@ parcelable ActivityManager.RunningServiceInfo;
parcelable ActivityManager.RunningTaskInfo;
/** @hide */
parcelable ActivityManager.TaskThumbnail;
 No newline at end of file
/** @hide */
parcelable ActivityManager.TaskSnapshot;
 No newline at end of file
+0 −345
Original line number Diff line number Diff line
@@ -2082,351 +2082,6 @@ public class ActivityManager {
        return ActivityTaskManager.getInstance().getTasks(maxNum);
    }

    /**
     * Represents a task snapshot.
     * @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 HardwareBuffer mSnapshot;
        /** Indicates whether task was in landscape or portrait */
        @Configuration.Orientation
        private final int mOrientation;
        /** See {@link android.view.Surface.Rotation} */
        @Surface.Rotation
        private int mRotation;
        /** The size of the snapshot before scaling */
        private final Point mTaskSize;
        private final Rect mContentInsets;
        // Whether this snapshot is a down-sampled version of the high resolution snapshot, used
        // mainly for loading snapshots quickly from disk when user is flinging fast
        private final boolean mIsLowResolution;
        // Whether or not the snapshot is a real snapshot or an app-theme generated snapshot due to
        // the task having a secure window or having previews disabled
        private final boolean mIsRealSnapshot;
        private final int mWindowingMode;
        private final @Appearance int mAppearance;
        private final boolean mIsTranslucent;
        // Must be one of the named color spaces, otherwise, always use SRGB color space.
        private final ColorSpace mColorSpace;

        public TaskSnapshot(long id,
                @NonNull ComponentName topActivityComponent, HardwareBuffer snapshot,
                @NonNull ColorSpace colorSpace, int orientation, int rotation, Point taskSize,
                Rect contentInsets, boolean isLowResolution, boolean isRealSnapshot,
                int windowingMode, @Appearance int appearance, boolean isTranslucent) {
            mId = id;
            mTopActivityComponent = topActivityComponent;
            mSnapshot = snapshot;
            mColorSpace = colorSpace.getId() < 0
                    ? ColorSpace.get(ColorSpace.Named.SRGB) : colorSpace;
            mOrientation = orientation;
            mRotation = rotation;
            mTaskSize = new Point(taskSize);
            mContentInsets = new Rect(contentInsets);
            mIsLowResolution = isLowResolution;
            mIsRealSnapshot = isRealSnapshot;
            mWindowingMode = windowingMode;
            mAppearance = appearance;
            mIsTranslucent = isTranslucent;
        }

        private TaskSnapshot(Parcel source) {
            mId = source.readLong();
            mTopActivityComponent = ComponentName.readFromParcel(source);
            mSnapshot = source.readParcelable(null /* classLoader */);
            int colorSpaceId = source.readInt();
            mColorSpace = colorSpaceId >= 0 && colorSpaceId < ColorSpace.Named.values().length
                    ? ColorSpace.get(ColorSpace.Named.values()[colorSpaceId])
                    : ColorSpace.get(ColorSpace.Named.SRGB);
            mOrientation = source.readInt();
            mRotation = source.readInt();
            mTaskSize = source.readParcelable(null /* classLoader */);
            mContentInsets = source.readParcelable(null /* classLoader */);
            mIsLowResolution = source.readBoolean();
            mIsRealSnapshot = source.readBoolean();
            mWindowingMode = source.readInt();
            mAppearance = source.readInt();
            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.
         */
        public ComponentName getTopActivityComponent() {
            return mTopActivityComponent;
        }

        /**
         * @return The graphic buffer representing the screenshot.
         *
         * Note: Prefer {@link #getHardwareBuffer}, which returns the internal object. This version
         * creates a new object.
         */
        @UnsupportedAppUsage
        public GraphicBuffer getSnapshot() {
            return GraphicBuffer.createFromHardwareBuffer(mSnapshot);
        }

        /**
         * @return The hardware buffer representing the screenshot.
         */
        public HardwareBuffer getHardwareBuffer() {
            return mSnapshot;
        }

        /**
         * @return The color space of hardware buffer representing the screenshot.
         */
        public ColorSpace getColorSpace() {
            return mColorSpace;
        }

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

        /**
         * @return The screen rotation the screenshot was taken in.
         */
        public int getRotation() {
            return mRotation;
        }

        /**
         * @return The size of the task at the point this snapshot was taken.
         */
        @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
        public Point getTaskSize() {
            return mTaskSize;
        }

        /**
         * @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.
         */
        @UnsupportedAppUsage
        public Rect getContentInsets() {
            return mContentInsets;
        }

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

        /**
         * @return Whether or not the snapshot is a real snapshot or an app-theme generated snapshot
         * due to the task having a secure window or having previews disabled.
         */
        @UnsupportedAppUsage
        public boolean isRealSnapshot() {
            return mIsRealSnapshot;
        }

        /**
         * @return Whether or not the snapshot is of a translucent app window (non-fullscreen or has
         * a non-opaque pixel format).
         */
        public boolean isTranslucent() {
            return mIsTranslucent;
        }

        /**
         * @return The windowing mode of the task when this snapshot was taken.
         */
        public int getWindowingMode() {
            return mWindowingMode;
        }

        /**
         * @return The {@link Appearance} flags for the top most visible fullscreen window at the
         *         time that the snapshot was taken.
         */
        public @Appearance int getAppearance() {
            return mAppearance;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeLong(mId);
            ComponentName.writeToParcel(mTopActivityComponent, dest);
            dest.writeParcelable(mSnapshot != null && !mSnapshot.isClosed() ? mSnapshot : null,
                    0);
            dest.writeInt(mColorSpace.getId());
            dest.writeInt(mOrientation);
            dest.writeInt(mRotation);
            dest.writeParcelable(mTaskSize, 0);
            dest.writeParcelable(mContentInsets, 0);
            dest.writeBoolean(mIsLowResolution);
            dest.writeBoolean(mIsRealSnapshot);
            dest.writeInt(mWindowingMode);
            dest.writeInt(mAppearance);
            dest.writeBoolean(mIsTranslucent);
        }

        @Override
        public String toString() {
            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()
                    + " mOrientation=" + mOrientation
                    + " mRotation=" + mRotation
                    + " mTaskSize=" + mTaskSize.toString()
                    + " mContentInsets=" + mContentInsets.toShortString()
                    + " mIsLowResolution=" + mIsLowResolution
                    + " mIsRealSnapshot=" + mIsRealSnapshot
                    + " mWindowingMode=" + mWindowingMode
                    + " mAppearance=" + mAppearance
                    + " mIsTranslucent=" + mIsTranslucent;
        }

        public static final @android.annotation.NonNull Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
            public TaskSnapshot createFromParcel(Parcel source) {
                return new TaskSnapshot(source);
            }
            public TaskSnapshot[] newArray(int size) {
                return new TaskSnapshot[size];
            }
        };

        /** Builder for a {@link TaskSnapshot} object */
        public static final class Builder {
            private long mId;
            private ComponentName mTopActivity;
            private HardwareBuffer mSnapshot;
            private ColorSpace mColorSpace;
            private int mOrientation;
            private int mRotation;
            private Point mTaskSize;
            private Rect mContentInsets;
            private boolean mIsRealSnapshot;
            private int mWindowingMode;
            private @Appearance int mAppearance;
            private boolean mIsTranslucent;
            private int mPixelFormat;

            public Builder setId(long id) {
                mId = id;
                return this;
            }

            public Builder setTopActivityComponent(ComponentName name) {
                mTopActivity = name;
                return this;
            }

            public Builder setSnapshot(HardwareBuffer buffer) {
                mSnapshot = buffer;
                return this;
            }

            public Builder setColorSpace(ColorSpace colorSpace) {
                mColorSpace = colorSpace;
                return this;
            }

            public Builder setOrientation(int orientation) {
                mOrientation = orientation;
                return this;
            }

            public Builder setRotation(int rotation) {
                mRotation = rotation;
                return this;
            }

            /**
             * Sets the original size of the task
             */
            public Builder setTaskSize(Point size) {
                mTaskSize = size;
                return this;
            }

            public Builder setContentInsets(Rect contentInsets) {
                mContentInsets = contentInsets;
                return this;
            }

            public Builder setIsRealSnapshot(boolean realSnapshot) {
                mIsRealSnapshot = realSnapshot;
                return this;
            }

            public Builder setWindowingMode(int windowingMode) {
                mWindowingMode = windowingMode;
                return this;
            }

            public Builder setAppearance(@Appearance int appearance) {
                mAppearance = appearance;
                return this;
            }

            public Builder setIsTranslucent(boolean isTranslucent) {
                mIsTranslucent = isTranslucent;
                return this;
            }

            public int getPixelFormat() {
                return mPixelFormat;
            }

            public Builder setPixelFormat(int pixelFormat) {
                mPixelFormat = pixelFormat;
                return this;
            }

            public TaskSnapshot build() {
                return new TaskSnapshot(
                        mId,
                        mTopActivity,
                        mSnapshot,
                        mColorSpace,
                        mOrientation,
                        mRotation,
                        mTaskSize,
                        mContentInsets,
                        // When building a TaskSnapshot with the Builder class, isLowResolution
                        // is always false. Low-res snapshots are only created when loading from
                        // disk.
                        false /* isLowResolution */,
                        mIsRealSnapshot,
                        mWindowingMode,
                        mAppearance,
                        mIsTranslucent);

            }
        }
    }

    /** @hide */
    @IntDef(flag = true, prefix = { "MOVE_TASK_" }, value = {
            MOVE_TASK_WITH_HOME,
+0 −8
Original line number Diff line number Diff line
@@ -543,14 +543,6 @@ interface IActivityManager {
    /** Cancels the window transitions for the given task. */
    @UnsupportedAppUsage
    void cancelTaskWindowTransition(int taskId);
    /**
     * @param taskId the id of the task to retrieve the sAutoapshots for
     * @param isLowResolution 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
     */
    @UnsupportedAppUsage
    ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution);
    void scheduleApplicationInfoChanged(in List<String> packageNames, int userId);
    void setPersistentVrThread(int tid);

+1 −1
Original line number Diff line number Diff line
@@ -308,7 +308,7 @@ interface IActivityTaskManager {
     *                          a reduced resolution of it, which is much faster
     * @return a graphic buffer representing a screenshot of a task
     */
    ActivityManager.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution);
    android.window.TaskSnapshot getTaskSnapshot(int taskId, boolean isLowResolution);

    /**
     * It should only be called from home activity to remove its outdated snapshot. The home
Loading