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

Commit 3ce0539b authored by chaviw's avatar chaviw
Browse files

Screenshot secure layers in ColorFade

When taking a screenshot for ColorFade, allow the screenshot to capture
secure layers, but ensure the SurfaceControl is also marked as secure.
This is to ensure that the screenshot that contains the secure layer
can't itself be screenshotted.

Also cleaned up some unused SurfaceControl.screenshot methods that are
no longer used due to this change

Fixes: 155744498
Test: Turn screen off with secure layers on screen
Change-Id: I064a93f5210af696d52df21380801134b57acc9f
parent 3758432a
Loading
Loading
Loading
Loading
+1 −34
Original line number Original line Diff line number Diff line
@@ -49,7 +49,6 @@ import android.os.Build;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.Trace;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
import android.util.SparseIntArray;
import android.util.SparseIntArray;
@@ -1953,37 +1952,6 @@ public final class SurfaceControl implements Parcelable {
        return getPhysicalDisplayToken(physicalDisplayIds[0]);
        return getPhysicalDisplayToken(physicalDisplayIds[0]);
    }
    }


    /**
     * @see SurfaceControl#screenshot(IBinder, Surface, Rect, int, int, boolean, int)
     * @hide
     */
    public static void screenshot(IBinder display, Surface consumer) {
        screenshot(display, consumer, new Rect(), 0, 0, false, 0);
    }

    /**
     * Copy the current screen contents into the provided {@link Surface}
     *
     * @param consumer The {@link Surface} to take the screenshot into.
     * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)
     * @hide
     */
    public static void screenshot(IBinder display, Surface consumer, Rect sourceCrop, int width,
            int height, boolean useIdentityTransform, int rotation) {
        if (consumer == null) {
            throw new IllegalArgumentException("consumer must not be null");
        }

        final ScreenshotHardwareBuffer buffer = screenshotToBuffer(display, sourceCrop, width,
                height, useIdentityTransform, rotation);
        try {
            consumer.attachAndQueueBufferWithColorSpace(buffer.getHardwareBuffer(),
                    buffer.getColorSpace());
        } catch (RuntimeException e) {
            Log.w(TAG, "Failed to take screenshot - " + e.getMessage());
        }
    }

    /**
    /**
     * @see SurfaceControl#screenshot(Rect, int, int, boolean, int)}
     * @see SurfaceControl#screenshot(Rect, int, int, boolean, int)}
     * @hide
     * @hide
@@ -1999,8 +1967,7 @@ public final class SurfaceControl implements Parcelable {
     * a software Bitmap using {@link Bitmap#copy(Bitmap.Config, boolean)}
     * a software Bitmap using {@link Bitmap#copy(Bitmap.Config, boolean)}
     *
     *
     * CAVEAT: Versions of screenshot that return a {@link Bitmap} can be extremely slow; avoid use
     * CAVEAT: Versions of screenshot that return a {@link Bitmap} can be extremely slow; avoid use
     * unless absolutely necessary; prefer the versions that use a {@link Surface} such as
     * unless absolutely necessary; prefer the versions that use a {@link HardwareBuffer} such as
     * {@link SurfaceControl#screenshot(IBinder, Surface)} or {@link HardwareBuffer} such as
     * {@link SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}.
     * {@link SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}.
     *
     *
     * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}
     * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}
+16 −9
Original line number Original line Diff line number Diff line
@@ -491,7 +491,14 @@ final class ColorFade {


                mIsWideColor = SurfaceControl.getActiveColorMode(token)
                mIsWideColor = SurfaceControl.getActiveColorMode(token)
                        == Display.COLOR_MODE_DISPLAY_P3;
                        == Display.COLOR_MODE_DISPLAY_P3;
                SurfaceControl.screenshot(token, s);
                SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer =
                        mDisplayManagerInternal.systemScreenshot(mDisplayId);
                s.attachAndQueueBufferWithColorSpace(screenshotBuffer.getHardwareBuffer(),
                        screenshotBuffer.getColorSpace());

                if (screenshotBuffer.containsSecureLayers()) {
                    mTransaction.setSecure(mSurfaceControl, true).apply();
                }
                st.updateTexImage();
                st.updateTexImage();
                st.getTransformMatrix(mTexMatrix);
                st.getTransformMatrix(mTexMatrix);
            } finally {
            } finally {
@@ -586,7 +593,6 @@ final class ColorFade {
        }
        }


        if (mSurfaceControl == null) {
        if (mSurfaceControl == null) {
            Transaction t = new Transaction();
            try {
            try {
                final SurfaceControl.Builder builder = new SurfaceControl.Builder(mSurfaceSession)
                final SurfaceControl.Builder builder = new SurfaceControl.Builder(mSurfaceSession)
                        .setName("ColorFade")
                        .setName("ColorFade")
@@ -602,15 +608,16 @@ final class ColorFade {
                return false;
                return false;
            }
            }


            t.setLayerStack(mSurfaceControl, mDisplayLayerStack);
            mTransaction.setLayerStack(mSurfaceControl, mDisplayLayerStack);
            t.setWindowCrop(mSurfaceControl, mDisplayWidth, mDisplayHeight);
            mTransaction.setWindowCrop(mSurfaceControl, mDisplayWidth, mDisplayHeight);
            mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManagerInternal,
                    mDisplayId, mSurfaceControl);
            mSurfaceLayout.onDisplayTransaction(mTransaction);
            mTransaction.apply();

            mSurface = new Surface();
            mSurface = new Surface();
            mSurface.copyFrom(mSurfaceControl);
            mSurface.copyFrom(mSurfaceControl);


            mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManagerInternal,
                    mDisplayId, mSurfaceControl);
            mSurfaceLayout.onDisplayTransaction(t);
            t.apply();
        }
        }
        return true;
        return true;
    }
    }
@@ -652,7 +659,7 @@ final class ColorFade {
        if (mSurfaceControl != null) {
        if (mSurfaceControl != null) {
            mSurfaceLayout.dispose();
            mSurfaceLayout.dispose();
            mSurfaceLayout = null;
            mSurfaceLayout = null;
            new Transaction().remove(mSurfaceControl).apply();
            mTransaction.remove(mSurfaceControl).apply();
            mSurface.release();
            mSurface.release();
            mSurfaceControl = null;
            mSurfaceControl = null;
            mSurfaceVisible = false;
            mSurfaceVisible = false;