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

Commit 2b7f2aee authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Migrate screen capture code to ScreenCapture file

Test: ScreenshotTests
Bug: 242714168
Change-Id: I8061f1717cc4e293ee07672d6d415c2c36010ccd
parent 4653017c
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.view.WindowAnimationFrameStats;
import android.view.WindowContentFrameStats;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.IAccessibilityManager;
import android.window.ScreenCapture;

import libcore.io.IoUtils;

@@ -220,13 +221,13 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
            int width = crop.width();
            int height = crop.height();
            final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
            final SurfaceControl.DisplayCaptureArgs captureArgs =
                    new SurfaceControl.DisplayCaptureArgs.Builder(displayToken)
            final ScreenCapture.DisplayCaptureArgs captureArgs =
                    new ScreenCapture.DisplayCaptureArgs.Builder(displayToken)
                            .setSourceCrop(crop)
                            .setSize(width, height)
                            .build();
            final SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer =
                    SurfaceControl.captureDisplay(captureArgs);
            final ScreenCapture.ScreenshotHardwareBuffer screenshotBuffer =
                    ScreenCapture.captureDisplay(captureArgs);
            return screenshotBuffer == null ? null : screenshotBuffer.asBitmap();
        } finally {
            Binder.restoreCallingIdentity(identity);
@@ -242,11 +243,11 @@ public final class UiAutomationConnection extends IUiAutomationConnection.Stub {
            throwIfNotConnectedLocked();
        }

        SurfaceControl.ScreenshotHardwareBuffer captureBuffer;
        ScreenCapture.ScreenshotHardwareBuffer captureBuffer;
        final long identity = Binder.clearCallingIdentity();
        try {
            captureBuffer = SurfaceControl.captureLayers(
                    new SurfaceControl.LayerCaptureArgs.Builder(surfaceControl)
            captureBuffer = ScreenCapture.captureLayers(
                    new ScreenCapture.LayerCaptureArgs.Builder(surfaceControl)
                            .setChildrenOnly(false)
                            .build());
        } finally {
+3 −3
Original line number Diff line number Diff line
@@ -28,9 +28,9 @@ import android.util.Slog;
import android.util.SparseArray;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.SurfaceControl;
import android.view.SurfaceControl.Transaction;
import android.window.DisplayWindowPolicyController;
import android.window.ScreenCapture;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -118,7 +118,7 @@ public abstract class DisplayManagerInternal {
     * @param displayId The display id to take the screenshot of.
     * @return The buffer or null if we have failed.
     */
    public abstract SurfaceControl.ScreenshotHardwareBuffer systemScreenshot(int displayId);
    public abstract ScreenCapture.ScreenshotHardwareBuffer systemScreenshot(int displayId);

    /**
     * General screenshot functionality that excludes secure layers and applies appropriate
@@ -127,7 +127,7 @@ public abstract class DisplayManagerInternal {
     * @param displayId The display id to take the screenshot of.
     * @return The buffer or null if we have failed.
     */
    public abstract SurfaceControl.ScreenshotHardwareBuffer userScreenshot(int displayId);
    public abstract ScreenCapture.ScreenshotHardwareBuffer userScreenshot(int displayId);

    /**
     * Returns information about the specified logical display.
+4 −3
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ import android.view.WindowLayout;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.window.ClientWindowFrames;
import android.window.ScreenCapture;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.HandlerCaller;
@@ -1989,9 +1990,9 @@ public abstract class WallpaperService extends Service {
                cleanUpScreenshotSurfaceControl();
            }

            SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer =
                    SurfaceControl.captureLayers(
                            new SurfaceControl.LayerCaptureArgs.Builder(mSurfaceControl)
            ScreenCapture.ScreenshotHardwareBuffer screenshotBuffer =
                    ScreenCapture.captureLayers(
                            new ScreenCapture.LayerCaptureArgs.Builder(mSurfaceControl)
                                    // Needed because SurfaceFlinger#validateScreenshotPermissions
                                    // uses this parameter to check whether a caller only attempts
                                    // to screenshot itself when call doesn't come from the system.
+1 −526

File changed.

Preview size limit exceeded, changes collapsed.

+571 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading