Merge "Drop the hardware buffer" into rvc-dev

This commit is contained in:
Jacky Kao
2020-03-03 02:50:40 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 11 deletions

View File

@@ -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
*/ */

View File

@@ -1023,18 +1023,21 @@ 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());
// Send back the result. // Send back the result.
final Bundle payload = new Bundle(); final Bundle payload = new Bundle();
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,
callback.sendResult(payload); SystemClock.uptimeMillis());
callback.sendResult(payload);
hardwareBuffer.close();
}
}, null).recycleOnUse()); }, null).recycleOnUse());
} finally { } finally {
Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity);