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

Commit cebd109a authored by Jacky Kao's avatar Jacky Kao Committed by Android (Google) Code Review
Browse files

Merge "Obtain correct screenshot based on device orientation"

parents d0d39664 4b4eec78
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -65,21 +65,23 @@ public abstract class DisplayManagerInternal {
    public abstract boolean isProximitySensorAvailable();
    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.
     * @param displayId The display id to take the screenshot of.
     * @return The buffer or null if we have failed.
     * @return The buffer or null if we have failed.
     */
     */
    public abstract SurfaceControl.ScreenshotHardwareBuffer screenshot(int displayId);
    public abstract SurfaceControl.ScreenshotHardwareBuffer 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.
     * @param displayId The display id to take the screenshot of.
     * @return The buffer or null if we have failed.
     * @return The buffer or null if we have failed.
     */
     */
    public abstract SurfaceControl.ScreenshotHardwareBuffer screenshotWithoutSecureLayers(
    public abstract SurfaceControl.ScreenshotHardwareBuffer userScreenshot(int displayId);
            int displayId);


    /**
    /**
     * Returns information about the specified logical display.
     * Returns information about the specified logical display.
+1 −2
Original line number Original line Diff line number Diff line
@@ -1022,8 +1022,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
        try {
        try {
            mMainHandler.post(PooledLambda.obtainRunnable((nonArg) -> {
            mMainHandler.post(PooledLambda.obtainRunnable((nonArg) -> {
                final ScreenshotHardwareBuffer screenshotBuffer = LocalServices
                final ScreenshotHardwareBuffer screenshotBuffer = LocalServices
                        .getService(DisplayManagerInternal.class)
                        .getService(DisplayManagerInternal.class).userScreenshot(displayId);
                        .screenshotWithoutSecureLayers(displayId);
                if (screenshotBuffer != null) {
                if (screenshotBuffer != null) {
                    sendScreenshotSuccess(screenshotBuffer, callback);
                    sendScreenshotSuccess(screenshotBuffer, callback);
                } else {
                } else {
+42 −15
Original line number Original line Diff line number Diff line
@@ -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_EXTERNAL;
import static android.hardware.display.DisplayViewport.VIEWPORT_INTERNAL;
import static android.hardware.display.DisplayViewport.VIEWPORT_INTERNAL;
import static android.hardware.display.DisplayViewport.VIEWPORT_VIRTUAL;
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.Manifest;
import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -1363,8 +1365,7 @@ public final class DisplayManagerService extends SystemService {
        return null;
        return null;
    }
    }


    private SurfaceControl.ScreenshotHardwareBuffer screenshotInternal(int displayId,
    private SurfaceControl.ScreenshotHardwareBuffer systemScreenshotInternal(int displayId) {
            boolean captureSecureLayer) {
        synchronized (mSyncRoot) {
        synchronized (mSyncRoot) {
            final IBinder token = getDisplayToken(displayId);
            final IBinder token = getDisplayToken(displayId);
            if (token == null) {
            if (token == null) {
@@ -1376,16 +1377,43 @@ public final class DisplayManagerService extends SystemService {
            }
            }


            final DisplayInfo displayInfo = logicalDisplay.getDisplayInfoLocked();
            final DisplayInfo displayInfo = logicalDisplay.getDisplayInfoLocked();
            if (captureSecureLayer) {
            return SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(token, new Rect(),
            return SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(token, new Rect(),
                    displayInfo.getNaturalWidth(), displayInfo.getNaturalHeight(),
                    displayInfo.getNaturalWidth(), displayInfo.getNaturalHeight(),
                    false /* useIdentityTransform */, 0 /* rotation */);
                    false /* useIdentityTransform */, 0 /* rotation */);
            } else {
                return SurfaceControl.screenshotToBuffer(token, new Rect(),
                        displayInfo.getNaturalWidth(), displayInfo.getNaturalHeight(),
                        false /* useIdentityTransform */, 0 /* rotation */);
        }
        }
    }
    }

    private SurfaceControl.ScreenshotHardwareBuffer 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 */);
        }
    }
    }


    @VisibleForTesting
    @VisibleForTesting
@@ -2502,14 +2530,13 @@ public final class DisplayManagerService extends SystemService {
        }
        }


        @Override
        @Override
        public SurfaceControl.ScreenshotHardwareBuffer screenshot(int displayId) {
        public SurfaceControl.ScreenshotHardwareBuffer systemScreenshot(int displayId) {
            return screenshotInternal(displayId, true);
            return systemScreenshotInternal(displayId);
        }
        }


        @Override
        @Override
        public SurfaceControl.ScreenshotHardwareBuffer screenshotWithoutSecureLayers(
        public SurfaceControl.ScreenshotHardwareBuffer userScreenshot(int displayId) {
                int displayId) {
            return userScreenshotInternal(displayId);
            return screenshotInternal(displayId, false);
        }
        }


        @Override
        @Override
+1 −1
Original line number Original line Diff line number Diff line
@@ -212,7 +212,7 @@ class ScreenRotationAnimation {
            final Surface surface = mService.mSurfaceFactory.get();
            final Surface surface = mService.mSurfaceFactory.get();
            surface.copyFrom(mScreenshotLayer);
            surface.copyFrom(mScreenshotLayer);
            SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer =
            SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer =
                    mService.mDisplayManagerInternal.screenshot(displayId);
                    mService.mDisplayManagerInternal.systemScreenshot(displayId);
            if (screenshotBuffer != null) {
            if (screenshotBuffer != null) {
                Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER,
                Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER,
                        "ScreenRotationAnimation#getMedianBorderLuma");
                        "ScreenRotationAnimation#getMedianBorderLuma");