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

Commit 4082aa2e authored by Jacky Kao's avatar Jacky Kao
Browse files

Drop the hardware buffer

Closing the hardware buffer after sending over to the requesting app,
and adding the document that the app developer has to close the buffer
ASAP.

Bug: 150174095
Test: atest AccessibilityTakeScreenshotTest
Change-Id: I8e759a7d83c0a9adfd1b37d0bbf515c9babde7a4
parent 979600dc
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -2400,6 +2400,10 @@ public abstract class AccessibilityService extends Service {


        /**
        /**
         * Gets the {@link HardwareBuffer} representing a memory buffer of the screenshot.
         * Gets the {@link HardwareBuffer} representing a memory buffer of the screenshot.
         * <p>
         * <strong>Note:</strong> The application should call {@link HardwareBuffer#close()} when
         * the buffer is no longer needed to free the underlying resources.
         * </p>
         *
         *
         * @return the hardware buffer
         * @return the hardware buffer
         */
         */
+15 −12
Original line number Original line Diff line number Diff line
@@ -1023,8 +1023,8 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
                                displaySize.x, displaySize.y, false,
                                displaySize.x, displaySize.y, false,
                                rotation);
                                rotation);
                final GraphicBuffer graphicBuffer = screenshotBuffer.getGraphicBuffer();
                final GraphicBuffer graphicBuffer = screenshotBuffer.getGraphicBuffer();
                final HardwareBuffer hardwareBuffer =
                try (HardwareBuffer hardwareBuffer =
                        HardwareBuffer.createFromGraphicBuffer(graphicBuffer);
                        HardwareBuffer.createFromGraphicBuffer(graphicBuffer)) {
                    final ParcelableColorSpace colorSpace =
                    final ParcelableColorSpace colorSpace =
                            new ParcelableColorSpace(screenshotBuffer.getColorSpace());
                            new ParcelableColorSpace(screenshotBuffer.getColorSpace());


@@ -1033,8 +1033,11 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
                    payload.putParcelable(KEY_ACCESSIBILITY_SCREENSHOT_HARDWAREBUFFER,
                    payload.putParcelable(KEY_ACCESSIBILITY_SCREENSHOT_HARDWAREBUFFER,
                            hardwareBuffer);
                            hardwareBuffer);
                    payload.putParcelable(KEY_ACCESSIBILITY_SCREENSHOT_COLORSPACE, colorSpace);
                    payload.putParcelable(KEY_ACCESSIBILITY_SCREENSHOT_COLORSPACE, colorSpace);
                payload.putLong(KEY_ACCESSIBILITY_SCREENSHOT_TIMESTAMP, SystemClock.uptimeMillis());
                    payload.putLong(KEY_ACCESSIBILITY_SCREENSHOT_TIMESTAMP,
                            SystemClock.uptimeMillis());
                    callback.sendResult(payload);
                    callback.sendResult(payload);
                    hardwareBuffer.close();
                }
            }, null).recycleOnUse());
            }, null).recycleOnUse());
        } finally {
        } finally {
            Binder.restoreCallingIdentity(identity);
            Binder.restoreCallingIdentity(identity);