summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jacky Kao <jackykao@google.com> 2020-04-22 00:19:35 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-04-22 00:19:35 +0000
commit538ee89f2b836f941a31ecbcc1d4b433d94cc1dc (patch)
tree6bdead05e74e7ca13a4cf907302a5ea481970256
parent64c55e7e8a5ed610a90d43fc3777f1495b174e6f (diff)
parent333de4e7c30fd524928085bd0128db7266113b8d (diff)
Merge "Obtain correct screenshot based on device orientation" into rvc-dev
-rw-r--r--core/java/android/hardware/display/DisplayManagerInternal.java12
-rw-r--r--services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java3
-rw-r--r--services/core/java/com/android/server/display/DisplayManagerService.java56
-rw-r--r--services/core/java/com/android/server/wm/ScreenRotationAnimation.java2
4 files changed, 51 insertions, 22 deletions
diff --git a/core/java/android/hardware/display/DisplayManagerInternal.java b/core/java/android/hardware/display/DisplayManagerInternal.java
index 462110f5a795..ad9bf0745779 100644
--- a/core/java/android/hardware/display/DisplayManagerInternal.java
+++ b/core/java/android/hardware/display/DisplayManagerInternal.java
@@ -65,21 +65,23 @@ public abstract class DisplayManagerInternal {
public abstract boolean isProximitySensorAvailable();
/**
- * Take a screenshot of the specified display and return a buffer.
+ * Screenshot for internal system-only use such as rotation, etc. This method includes
+ * secure layers and the result should never be exposed to non-system applications.
+ * This method does not apply any rotation and provides the output in natural orientation.
*
* @param displayId The display id to take the screenshot of.
* @return The buffer or null if we have failed.
*/
- public abstract SurfaceControl.ScreenshotGraphicBuffer screenshot(int displayId);
+ public abstract SurfaceControl.ScreenshotGraphicBuffer systemScreenshot(int displayId);
/**
- * Take a screenshot without secure layer of the specified display and return a buffer.
+ * General screenshot functionality that excludes secure layers and applies appropriate
+ * rotation that the device is currently in.
*
* @param displayId The display id to take the screenshot of.
* @return The buffer or null if we have failed.
*/
- public abstract SurfaceControl.ScreenshotGraphicBuffer screenshotWithoutSecureLayer(
- int displayId);
+ public abstract SurfaceControl.ScreenshotGraphicBuffer userScreenshot(int displayId);
/**
* Returns information about the specified logical display.
diff --git a/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java b/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
index 132b6927badd..da9bdf3262d5 100644
--- a/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
+++ b/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java
@@ -1023,8 +1023,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
try {
mMainHandler.post(PooledLambda.obtainRunnable((nonArg) -> {
final ScreenshotGraphicBuffer screenshotBuffer = LocalServices
- .getService(DisplayManagerInternal.class)
- .screenshotWithoutSecureLayer(displayId);
+ .getService(DisplayManagerInternal.class).userScreenshot(displayId);
if (screenshotBuffer != null) {
sendScreenshotSuccess(screenshotBuffer, callback);
} else {
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index b4f7cdbd5694..02d499fbd81f 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -28,6 +28,8 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SHOUL
import static android.hardware.display.DisplayViewport.VIEWPORT_EXTERNAL;
import static android.hardware.display.DisplayViewport.VIEWPORT_INTERNAL;
import static android.hardware.display.DisplayViewport.VIEWPORT_VIRTUAL;
+import static android.view.Surface.ROTATION_270;
+import static android.view.Surface.ROTATION_90;
import android.Manifest;
import android.annotation.NonNull;
@@ -1363,8 +1365,7 @@ public final class DisplayManagerService extends SystemService {
return null;
}
- private SurfaceControl.ScreenshotGraphicBuffer screenshotInternal(int displayId,
- boolean captureSecureLayer) {
+ private SurfaceControl.ScreenshotGraphicBuffer systemScreenshotInternal(int displayId) {
synchronized (mSyncRoot) {
final IBinder token = getDisplayToken(displayId);
if (token == null) {
@@ -1376,15 +1377,42 @@ public final class DisplayManagerService extends SystemService {
}
final DisplayInfo displayInfo = logicalDisplay.getDisplayInfoLocked();
- if (captureSecureLayer) {
- return SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(token, new Rect(),
- displayInfo.getNaturalWidth(), displayInfo.getNaturalHeight(),
- false /* useIdentityTransform */, 0 /* rotation */);
- } else {
- return SurfaceControl.screenshotToBuffer(token, new Rect(),
- displayInfo.getNaturalWidth(), displayInfo.getNaturalHeight(),
- false /* useIdentityTransform */, 0 /* rotation */);
+ return SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(token, new Rect(),
+ displayInfo.getNaturalWidth(), displayInfo.getNaturalHeight(),
+ false /* useIdentityTransform */, 0 /* rotation */);
+ }
+ }
+
+ private SurfaceControl.ScreenshotGraphicBuffer userScreenshotInternal(int displayId) {
+ synchronized (mSyncRoot) {
+ final IBinder token = getDisplayToken(displayId);
+ if (token == null) {
+ return null;
+ }
+ final LogicalDisplay logicalDisplay = mLogicalDisplays.get(displayId);
+ if (logicalDisplay == null) {
+ return null;
+ }
+
+ final DisplayInfo displayInfo = logicalDisplay.getDisplayInfoLocked();
+ // Takes screenshot based on current device orientation.
+ final Display display = DisplayManagerGlobal.getInstance()
+ .getRealDisplay(displayId);
+ if (display == null) {
+ return null;
}
+ final Point displaySize = new Point();
+ display.getRealSize(displaySize);
+
+ int rotation = displayInfo.rotation;
+ // TODO (b/153382624) : This workaround solution would be removed after
+ // SurfaceFlinger fixes the inconsistency with rotation direction issue.
+ if (rotation == ROTATION_90 || rotation == ROTATION_270) {
+ rotation = (rotation == ROTATION_90) ? ROTATION_270 : ROTATION_90;
+ }
+
+ return SurfaceControl.screenshotToBuffer(token, new Rect(), displaySize.x,
+ displaySize.y, false /* useIdentityTransform */, rotation /* rotation */);
}
}
@@ -2502,13 +2530,13 @@ public final class DisplayManagerService extends SystemService {
}
@Override
- public SurfaceControl.ScreenshotGraphicBuffer screenshot(int displayId) {
- return screenshotInternal(displayId, true);
+ public SurfaceControl.ScreenshotGraphicBuffer systemScreenshot(int displayId) {
+ return systemScreenshotInternal(displayId);
}
@Override
- public SurfaceControl.ScreenshotGraphicBuffer screenshotWithoutSecureLayer(int displayId) {
- return screenshotInternal(displayId, false);
+ public SurfaceControl.ScreenshotGraphicBuffer userScreenshot(int displayId) {
+ return userScreenshotInternal(displayId);
}
@Override
diff --git a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
index 9d44cad70281..86e081854597 100644
--- a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -212,7 +212,7 @@ class ScreenRotationAnimation {
final Surface surface = mService.mSurfaceFactory.get();
surface.copyFrom(mScreenshotLayer);
SurfaceControl.ScreenshotGraphicBuffer gb =
- mService.mDisplayManagerInternal.screenshot(displayId);
+ mService.mDisplayManagerInternal.systemScreenshot(displayId);
if (gb != null) {
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER,
"ScreenRotationAnimation#getMedianBorderLuma");