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

Commit ef6dea62 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add DisplayID to Screenshot Request." into main

parents 10790390 dc48f6ec
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

import java.util.Objects;
@@ -53,11 +54,12 @@ public class ScreenshotRequest implements Parcelable {
    private final Bitmap mBitmap;
    private final Rect mBoundsInScreen;
    private final Insets mInsets;
    private final int mDisplayId;

    private ScreenshotRequest(
            @WindowManager.ScreenshotType int type, @WindowManager.ScreenshotSource int source,
            ComponentName topComponent, int taskId, int userId,
            Bitmap bitmap, Rect boundsInScreen, Insets insets) {
            Bitmap bitmap, Rect boundsInScreen, Insets insets, int displayId) {
        mType = type;
        mSource = source;
        mTopComponent = topComponent;
@@ -66,6 +68,7 @@ public class ScreenshotRequest implements Parcelable {
        mBitmap = bitmap;
        mBoundsInScreen = boundsInScreen;
        mInsets = insets;
        mDisplayId = displayId;
    }

    ScreenshotRequest(Parcel in) {
@@ -77,6 +80,7 @@ public class ScreenshotRequest implements Parcelable {
        mBitmap = HardwareBitmapBundler.bundleToHardwareBitmap(in.readTypedObject(Bundle.CREATOR));
        mBoundsInScreen = in.readTypedObject(Rect.CREATOR);
        mInsets = in.readTypedObject(Insets.CREATOR);
        mDisplayId = in.readInt();
    }

    @WindowManager.ScreenshotType
@@ -113,6 +117,10 @@ public class ScreenshotRequest implements Parcelable {
        return mTopComponent;
    }

    public int getDisplayId() {
        return mDisplayId;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -128,6 +136,7 @@ public class ScreenshotRequest implements Parcelable {
        dest.writeTypedObject(HardwareBitmapBundler.hardwareBitmapToBundle(mBitmap), 0);
        dest.writeTypedObject(mBoundsInScreen, 0);
        dest.writeTypedObject(mInsets, 0);
        dest.writeInt(mDisplayId);
    }

    @NonNull
@@ -161,6 +170,7 @@ public class ScreenshotRequest implements Parcelable {
        private int mTaskId = INVALID_TASK_ID;
        private int mUserId = USER_NULL;
        private ComponentName mTopComponent;
        private int mDisplayId = Display.INVALID_DISPLAY;

        /**
         * Begin building a ScreenshotRequest.
@@ -193,7 +203,7 @@ public class ScreenshotRequest implements Parcelable {
            }

            return new ScreenshotRequest(mType, mSource, mTopComponent, mTaskId, mUserId, mBitmap,
                    mBoundsInScreen, mInsets);
                    mBoundsInScreen, mInsets, mDisplayId);
        }

        /**
@@ -255,6 +265,16 @@ public class ScreenshotRequest implements Parcelable {
            mInsets = insets;
            return this;
        }

        /**
         * Set the display ID for this request.
         *
         * @param displayId see {@link Display}
         */
        public Builder setDisplayId(int displayId) {
            mDisplayId = displayId;
            return this;
        }
    }

    /**
+5 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.graphics.Insets;
import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.os.Parcel;
import android.view.Display;

import androidx.test.runner.AndroidJUnit4;

@@ -64,10 +65,12 @@ public final class ScreenshotRequestTest {
        assertNull("Bitmap was expected to be null", out.getBitmap());
        assertNull("Bounds were expected to be null", out.getBoundsInScreen());
        assertEquals(Insets.NONE, out.getInsets());
        assertEquals(Display.INVALID_DISPLAY, out.getDisplayId());
    }

    @Test
    public void testProvidedScreenshot() {
        int displayId = 5;
        Bitmap bitmap = makeHardwareBitmap(50, 50);
        ScreenshotRequest in =
                new ScreenshotRequest.Builder(TAKE_SCREENSHOT_PROVIDED_IMAGE, SCREENSHOT_OTHER)
@@ -77,6 +80,7 @@ public final class ScreenshotRequestTest {
                        .setBitmap(bitmap)
                        .setBoundsOnScreen(new Rect(10, 10, 60, 60))
                        .setInsets(Insets.of(2, 3, 4, 5))
                        .setDisplayId(displayId)
                        .build();

        Parcel parcel = Parcel.obtain();
@@ -92,6 +96,7 @@ public final class ScreenshotRequestTest {
        assertTrue("Bitmaps should be equal", out.getBitmap().sameAs(bitmap));
        assertEquals(new Rect(10, 10, 60, 60), out.getBoundsInScreen());
        assertEquals(Insets.of(2, 3, 4, 5), out.getInsets());
        assertEquals(displayId, out.getDisplayId());
    }

    @Test