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

Commit 42d5bddc authored by Matt Casey's avatar Matt Casey Committed by Android (Google) Code Review
Browse files

Merge "Make insets and bounds immutable." into main

parents 6a718bcc 50dc7179
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -255,11 +255,11 @@ public class LegacyScreenshotController implements InteractiveScreenshotHandler
        Assert.isMainThread();

        mCurrentRequestCallback = requestCallback;
        Rect bounds = screenshot.getOriginalScreenBounds();
        if (screenshot.getType() == WindowManager.TAKE_SCREENSHOT_FULLSCREEN
                && screenshot.getBitmap() == null) {
            Rect bounds = getFullScreenRect();
            bounds = getFullScreenRect();
            screenshot.setBitmap(mImageCapture.captureDisplay(mDisplay.getDisplayId(), bounds));
            screenshot.setScreenBounds(bounds);
        }

        if (screenshot.getBitmap() == null) {
@@ -325,22 +325,22 @@ public class LegacyScreenshotController implements InteractiveScreenshotHandler

        boolean showFlash;
        if (screenshot.getType() == WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE) {
            if (screenshot.getScreenBounds() != null
                    && aspectRatiosMatch(screenshot.getBitmap(), screenshot.getInsets(),
                    screenshot.getScreenBounds())) {
            if (bounds != null
                    && aspectRatiosMatch(screenshot.getBitmap(), screenshot.getOriginalInsets(),
                    bounds)) {
                showFlash = false;
            } else {
                showFlash = true;
                screenshot.setInsets(Insets.NONE);
                screenshot.setScreenBounds(new Rect(0, 0, screenshot.getBitmap().getWidth(),
                        screenshot.getBitmap().getHeight()));
                bounds = new Rect(0, 0, screenshot.getBitmap().getWidth(),
                        screenshot.getBitmap().getHeight());
            }
        } else {
            showFlash = true;
        }

        final Rect animationBounds = bounds;
        mViewProxy.prepareEntranceAnimation(
                () -> startAnimation(screenshot.getScreenBounds(), showFlash,
                () -> startAnimation(animationBounds, showFlash,
                        () -> mMessageContainerController.onScreenshotTaken(screenshot)));

        mViewProxy.setScreenshot(screenshot);
+11 −8
Original line number Diff line number Diff line
@@ -175,7 +175,6 @@ internal constructor(
        if (screenshot.type == TAKE_SCREENSHOT_FULLSCREEN && screenshot.bitmap == null) {
            val bounds = fullScreenRect
            screenshot.bitmap = imageCapture.captureDisplay(display.displayId, bounds)
            screenshot.screenBounds = bounds
        }

        val currentBitmap = screenshot.bitmap
@@ -238,23 +237,27 @@ internal constructor(

        window.attachWindow()

        var bounds =
            screenshot.originalScreenBounds ?: Rect(0, 0, currentBitmap.width, currentBitmap.height)

        val showFlash: Boolean
        if (screenshot.type == TAKE_SCREENSHOT_PROVIDED_IMAGE) {
            if (aspectRatiosMatch(currentBitmap, screenshot.insets, screenshot.screenBounds)) {
            if (
                aspectRatiosMatch(
                    currentBitmap,
                    screenshot.originalInsets,
                    screenshot.originalScreenBounds,
                )
            ) {
                showFlash = false
            } else {
                showFlash = true
                screenshot.insets = Insets.NONE
                screenshot.screenBounds = Rect(0, 0, currentBitmap.width, currentBitmap.height)
                bounds = Rect(0, 0, currentBitmap.width, currentBitmap.height)
            }
        } else {
            showFlash = true
        }

        // screenshot.screenBounds is expected to be non-null in all cases at this point
        val bounds =
            screenshot.screenBounds ?: Rect(0, 0, currentBitmap.width, currentBitmap.height)

        viewProxy.prepareEntranceAnimation {
            startAnimation(bounds, showFlash) {
                messageContainerController.onScreenshotTaken(screenshot)
+6 −6
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ data class ScreenshotData(
    val userHandle: UserHandle,
    /** ComponentName of the top-most app in the screenshot. */
    val topComponent: ComponentName?,
    var screenBounds: Rect?,
    val taskId: Int,
    var insets: Insets,
    val originalScreenBounds: Rect?,
    val originalInsets: Insets,
    var bitmap: Bitmap?,
    val displayId: Int,
) {
@@ -42,9 +42,9 @@ data class ScreenshotData(
                source = request.source,
                userHandle = UserHandle.of(request.userId),
                topComponent = request.topComponent,
                screenBounds = request.boundsInScreen,
                originalScreenBounds = request.boundsInScreen,
                taskId = request.taskId,
                insets = request.insets,
                originalInsets = request.insets,
                bitmap = request.bitmap,
                displayId = displayId,
            )
@@ -61,9 +61,9 @@ data class ScreenshotData(
                source = source,
                userHandle = userHandle,
                topComponent = topComponent,
                screenBounds = null,
                originalScreenBounds = null,
                taskId = 0,
                insets = Insets.NONE,
                originalInsets = Insets.NONE,
                bitmap = bitmap,
                displayId = Display.DEFAULT_DISPLAY,
            )
+2 −2
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ class PolicyRequestProcessor(
            userHandle = owner,
            taskId = taskId,
            topComponent = componentName,
            screenBounds = taskBounds,
            originalScreenBounds = taskBounds,
        )
    }

@@ -159,7 +159,7 @@ class PolicyRequestProcessor(
            bitmap = screenshot,
            userHandle = owner,
            topComponent = componentName,
            screenBounds = Rect(0, 0, screenshot?.width ?: 0, screenshot?.height ?: 0),
            originalScreenBounds = Rect(0, 0, screenshot?.width ?: 0, screenshot?.height ?: 0),
            taskId = taskId ?: -1,
        )
    }
+2 −2
Original line number Diff line number Diff line
@@ -53,8 +53,8 @@ class ScreenshotDataTest {

        assertThat(data.source).isEqualTo(source)
        assertThat(data.type).isEqualTo(type)
        assertThat(data.screenBounds).isEqualTo(bounds)
        assertThat(data.insets).isEqualTo(insets)
        assertThat(data.originalScreenBounds).isEqualTo(bounds)
        assertThat(data.originalInsets).isEqualTo(insets)
        assertThat(data.taskId).isEqualTo(taskId)
        assertThat(data.userHandle).isEqualTo(UserHandle.of(userId))
        assertThat(data.topComponent).isEqualTo(component)
Loading