summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jacky Kao <jackykao@google.com> 2020-02-05 05:53:34 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-02-05 05:53:34 +0000
commitdc50df397b4353883742cbcfc9fb4eaaef61ffa1 (patch)
treea894519dc792fcf9c6c6c545d07c1bb442ac314d
parentaa6753b9b17ad0627d1dde6eb589b0b27c238335 (diff)
parent3e33bedee01bc5e3b60b6d7df2e0ae31cf0cff05 (diff)
Merge "Changing the return type of takeScreenshot() (1/n)"
-rw-r--r--core/java/android/app/IUiAutomationConnection.aidl1
-rw-r--r--core/java/android/app/UiAutomation.java36
-rw-r--r--core/java/android/app/UiAutomationConnection.java22
-rw-r--r--core/java/android/view/accessibility/AccessibilityInteractionClient.java26
4 files changed, 50 insertions, 35 deletions
diff --git a/core/java/android/app/IUiAutomationConnection.aidl b/core/java/android/app/IUiAutomationConnection.aidl
index 80ba464851e0..8c3180b400ef 100644
--- a/core/java/android/app/IUiAutomationConnection.aidl
+++ b/core/java/android/app/IUiAutomationConnection.aidl
@@ -39,6 +39,7 @@ interface IUiAutomationConnection {
boolean injectInputEvent(in InputEvent event, boolean sync);
void syncInputTransactions();
boolean setRotation(int rotation);
+ Bitmap takeScreenshot(in Rect crop, int rotation);
boolean clearWindowContentFrameStats(int windowId);
WindowContentFrameStats getWindowContentFrameStats(int windowId);
void clearWindowAnimationFrameStats();
diff --git a/core/java/android/app/UiAutomation.java b/core/java/android/app/UiAutomation.java
index 35cf68737ccc..a9a06dabc049 100644
--- a/core/java/android/app/UiAutomation.java
+++ b/core/java/android/app/UiAutomation.java
@@ -27,7 +27,10 @@ import android.annotation.Nullable;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.graphics.Bitmap;
+import android.graphics.Point;
+import android.graphics.Rect;
import android.graphics.Region;
+import android.hardware.display.DisplayManagerGlobal;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
@@ -828,20 +831,39 @@ public final class UiAutomation {
}
/**
- * Takes a screenshot of the default display and returns it by {@link Bitmap.Config#HARDWARE}
- * format.
+ * Takes a screenshot.
*
* @return The screenshot bitmap on success, null otherwise.
*/
public Bitmap takeScreenshot() {
- final int connectionId;
synchronized (mLock) {
throwIfNotConnectedLocked();
- connectionId = mConnectionId;
}
- // Calling out without a lock held.
- return AccessibilityInteractionClient.getInstance()
- .takeScreenshot(connectionId, Display.DEFAULT_DISPLAY);
+ Display display = DisplayManagerGlobal.getInstance()
+ .getRealDisplay(Display.DEFAULT_DISPLAY);
+ Point displaySize = new Point();
+ display.getRealSize(displaySize);
+
+ int rotation = display.getRotation();
+
+ // Take the screenshot
+ Bitmap screenShot = null;
+ try {
+ // Calling out without a lock held.
+ screenShot = mUiAutomationConnection.takeScreenshot(
+ new Rect(0, 0, displaySize.x, displaySize.y), rotation);
+ if (screenShot == null) {
+ return null;
+ }
+ } catch (RemoteException re) {
+ Log.e(LOG_TAG, "Error while taking screnshot!", re);
+ return null;
+ }
+
+ // Optimization
+ screenShot.setHasAlpha(false);
+
+ return screenShot;
}
/**
diff --git a/core/java/android/app/UiAutomationConnection.java b/core/java/android/app/UiAutomationConnection.java
index 4fb974305e48..82e988109db8 100644
--- a/core/java/android/app/UiAutomationConnection.java
+++ b/core/java/android/app/UiAutomationConnection.java
@@ -21,6 +21,8 @@ import android.accessibilityservice.IAccessibilityServiceClient;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Rect;
import android.hardware.input.InputManager;
import android.os.Binder;
import android.os.IBinder;
@@ -178,6 +180,23 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
}
@Override
+ public Bitmap takeScreenshot(Rect crop, int rotation) {
+ synchronized (mLock) {
+ throwIfCalledByNotTrustedUidLocked();
+ throwIfShutdownLocked();
+ throwIfNotConnectedLocked();
+ }
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ int width = crop.width();
+ int height = crop.height();
+ return SurfaceControl.screenshot(crop, width, height, rotation);
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ }
+
+ @Override
public boolean clearWindowContentFrameStats(int windowId) throws RemoteException {
synchronized (mLock) {
throwIfCalledByNotTrustedUidLocked();
@@ -430,8 +449,7 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
info.setCapabilities(AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT
| AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_TOUCH_EXPLORATION
| AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_ENHANCED_WEB_ACCESSIBILITY
- | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS
- | AccessibilityServiceInfo.CAPABILITY_CAN_TAKE_SCREENSHOT);
+ | AccessibilityServiceInfo.CAPABILITY_CAN_REQUEST_FILTER_KEY_EVENTS);
try {
// Calling out with a lock held is fine since if the system
// process is gone the client calling in will be killed.
diff --git a/core/java/android/view/accessibility/AccessibilityInteractionClient.java b/core/java/android/view/accessibility/AccessibilityInteractionClient.java
index b9f08ada3152..b4c87953567b 100644
--- a/core/java/android/view/accessibility/AccessibilityInteractionClient.java
+++ b/core/java/android/view/accessibility/AccessibilityInteractionClient.java
@@ -20,7 +20,6 @@ import android.accessibilityservice.IAccessibilityServiceConnection;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
-import android.graphics.Bitmap;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
@@ -829,31 +828,6 @@ public final class AccessibilityInteractionClient
}
/**
- * Takes the screenshot of the specified display and returns it by bitmap format.
- *
- * @param connectionId The id of a connection for interacting with the system.
- * @param displayId The logic display id, use {@link Display#DEFAULT_DISPLAY} for
- * default display.
- * @return The screenshot bitmap on success, null otherwise.
- */
- public Bitmap takeScreenshot(int connectionId, int displayId) {
- Bitmap screenShot = null;
- try {
- IAccessibilityServiceConnection connection = getConnection(connectionId);
- if (connection != null) {
- screenShot = connection.takeScreenshot(displayId);
- } else {
- if (DEBUG) {
- Log.w(LOG_TAG, "No connection for connection id: " + connectionId);
- }
- }
- } catch (RemoteException re) {
- Log.w(LOG_TAG, "Error while calling remote takeScreenshot", re);
- }
- return screenShot;
- }
-
- /**
* Clears the result state.
*/
private void clearResultLocked() {