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

Commit dbd04bb6 authored by Rob Carr's avatar Rob Carr Committed by Android (Google) Code Review
Browse files

Merge "Exclude secure layers from most screenshots taken by the system server."

parents a6cc5626 5c52b139
Loading
Loading
Loading
Loading
+25 −2
Original line number Original line Diff line number Diff line
@@ -88,7 +88,8 @@ public final class SurfaceControl implements Parcelable {
    private static native void nativeDisconnect(long nativeObject);
    private static native void nativeDisconnect(long nativeObject);


    private static native GraphicBuffer nativeScreenshot(IBinder displayToken,
    private static native GraphicBuffer nativeScreenshot(IBinder displayToken,
            Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation);
            Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation,
            boolean captureSecureLayers);
    private static native GraphicBuffer nativeCaptureLayers(IBinder layerHandleToken,
    private static native GraphicBuffer nativeCaptureLayers(IBinder layerHandleToken,
            Rect sourceCrop, float frameScale);
            Rect sourceCrop, float frameScale);


@@ -1853,7 +1854,29 @@ public final class SurfaceControl implements Parcelable {
            throw new IllegalArgumentException("displayToken must not be null");
            throw new IllegalArgumentException("displayToken must not be null");
        }
        }


        return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation);
        return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation,
                false /* captureSecureLayers */);
    }

    /**
     * Like screenshotToBuffer, but if the caller is AID_SYSTEM, allows
     * for the capture of secure layers. This is used for the screen rotation
     * animation where the system server takes screenshots but does
     * not persist them or allow them to leave the server. However in other
     * cases in the system server, we mostly want to omit secure layers
     * like when we take a screenshot on behalf of the assistant.
     *
     * @hide
     */
    public static GraphicBuffer screenshotToBufferWithSecureLayersUnsafe(IBinder display,
            Rect sourceCrop, int width, int height, boolean useIdentityTransform,
            int rotation) {
        if (display == null) {
            throw new IllegalArgumentException("displayToken must not be null");
        }

        return nativeScreenshot(display, sourceCrop, width, height, useIdentityTransform, rotation,
                true /* captureSecureLayers */);
    }
    }


    private static void rotateCropForSF(Rect crop, int rot) {
    private static void rotateCropForSF(Rect crop, int rot) {
+5 −5
Original line number Original line Diff line number Diff line
@@ -205,7 +205,7 @@ static Rect rectFromObj(JNIEnv* env, jobject rectObj) {


static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
        jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
        jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
        bool useIdentityTransform, int rotation) {
        bool useIdentityTransform, int rotation, bool captureSecureLayers) {
    sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
    sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
    if (displayToken == NULL) {
    if (displayToken == NULL) {
        return NULL;
        return NULL;
@@ -215,7 +215,7 @@ static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
    status_t res = ScreenshotClient::capture(displayToken, ui::Dataspace::V0_SRGB,
    status_t res = ScreenshotClient::capture(displayToken, ui::Dataspace::V0_SRGB,
            ui::PixelFormat::RGBA_8888,
            ui::PixelFormat::RGBA_8888,
            sourceCrop, width, height,
            sourceCrop, width, height,
                                             useIdentityTransform, rotation, &buffer);
            useIdentityTransform, rotation, captureSecureLayers, &buffer);
    if (res != NO_ERROR) {
    if (res != NO_ERROR) {
        return NULL;
        return NULL;
    }
    }
@@ -1232,7 +1232,7 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeSetOverrideScalingMode },
            (void*)nativeSetOverrideScalingMode },
    {"nativeGetHandle", "(J)Landroid/os/IBinder;",
    {"nativeGetHandle", "(J)Landroid/os/IBinder;",
            (void*)nativeGetHandle },
            (void*)nativeGetHandle },
    {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZI)Landroid/graphics/GraphicBuffer;",
    {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIZIZ)Landroid/graphics/GraphicBuffer;",
            (void*)nativeScreenshot },
            (void*)nativeScreenshot },
    {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
    {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
            (void*)nativeCaptureLayers },
            (void*)nativeCaptureLayers },
+10 −1
Original line number Original line Diff line number Diff line
@@ -37,7 +37,9 @@ import android.content.pm.ParceledListSlice;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.ColorSpace;
import android.graphics.ColorSpace;
import android.graphics.GraphicBuffer;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.hardware.SensorManager;
import android.hardware.SensorManager;
import android.hardware.display.AmbientBrightnessDayStats;
import android.hardware.display.AmbientBrightnessDayStats;
import android.hardware.display.BrightnessChangeEvent;
import android.hardware.display.BrightnessChangeEvent;
@@ -1277,7 +1279,14 @@ public final class DisplayManagerService extends SystemService {
        if (token == null) {
        if (token == null) {
            return false;
            return false;
        }
        }
        SurfaceControl.screenshot(token, outSurface);
        final GraphicBuffer gb = SurfaceControl.screenshotToBufferWithSecureLayersUnsafe(
                token, new Rect(), 0 /* width */, 0 /* height */, false /* useIdentityTransform */,
                0 /* rotation */);
        try {
            outSurface.attachAndQueueBuffer(gb);
        } catch (RuntimeException e) {
            Slog.w(TAG, "Failed to take screenshot - " + e.getMessage());
        }
        return true;
        return true;
    }
    }