Loading core/java/android/view/SurfaceControl.java +24 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,8 @@ public class SurfaceControl implements Parcelable { boolean allLayers, boolean useIdentityTransform, int rotation); private static native GraphicBuffer nativeScreenshotToBuffer(IBinder displayToken, Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean allLayers, boolean useIdentityTransform, int rotation); boolean allLayers, boolean useIdentityTransform, int rotation, boolean captureSecureLayers); private static native void nativeScreenshot(IBinder displayToken, Surface consumer, Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean allLayers, boolean useIdentityTransform); Loading Loading @@ -1286,7 +1287,28 @@ public class SurfaceControl implements Parcelable { IBinder displayToken = SurfaceControl.getBuiltInDisplay( SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN); return nativeScreenshotToBuffer(displayToken, sourceCrop, width, height, minLayer, maxLayer, false, useIdentityTransform, rotation); minLayer, maxLayer, false, 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(Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean useIdentityTransform, int rotation) { IBinder displayToken = SurfaceControl.getBuiltInDisplay( SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN); return nativeScreenshotToBuffer(displayToken, sourceCrop, width, height, minLayer, maxLayer, false, useIdentityTransform, rotation, true /* captureSecureLayers */); } /** Loading core/jni/android_os_HwBlob.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ JHwBlob::JHwBlob(JNIEnv *env, jobject thiz, size_t size) mOwnsBuffer(true), mHandle(0) { if (size > 0) { mBuffer = malloc(size); mBuffer = calloc(size, 1); } } Loading core/jni/android_view_SurfaceControl.cpp +7 −5 Original line number Diff line number Diff line Loading @@ -160,7 +160,7 @@ static Rect rectFromObj(JNIEnv* env, jobject rectObj) { static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz, jobject displayTokenObj, jobject sourceCropObj, jint width, jint height, jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform, int rotation) { int rotation, bool captureSecureLayers) { sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); if (displayToken == NULL) { return NULL; Loading @@ -171,9 +171,10 @@ static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz, maxLayer = INT32_MAX; } sp<GraphicBuffer> buffer; bool capturedSecureLayers = false; status_t res = ScreenshotClient::capture(displayToken, sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform, rotation, &buffer); rotation, captureSecureLayers, &buffer, capturedSecureLayers); if (res != NO_ERROR) { return NULL; } Loading @@ -184,7 +185,8 @@ static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz, buffer->getHeight(), buffer->getPixelFormat(), (jint)buffer->getUsage(), (jlong)buffer.get()); (jlong)buffer.get(), capturedSecureLayers); } static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz, Loading Loading @@ -1026,7 +1028,7 @@ static const JNINativeMethod sSurfaceControlMethods[] = { {"nativeGetHandle", "(J)Landroid/os/IBinder;", (void*)nativeGetHandle }, {"nativeScreenshotToBuffer", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZIZ)Landroid/graphics/GraphicBuffer;", (void*)nativeScreenshotToBuffer }, {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;", (void*)nativeCaptureLayers }, Loading Loading @@ -1082,7 +1084,7 @@ int register_android_view_SurfaceControl(JNIEnv* env) jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer"); gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz); gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz, "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;"); "createFromExisting", "(IIIIJZ)Landroid/graphics/GraphicBuffer;"); return err; } Loading graphics/java/android/graphics/GraphicBuffer.java +33 −4 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ public class GraphicBuffer implements Parcelable { private final int mHeight; private final int mFormat; private final int mUsage; private final boolean mCapturedSecureLayers; // Note: do not rename, this field is used by native code private final long mNativeObject; Loading Loading @@ -82,14 +83,23 @@ public class GraphicBuffer implements Parcelable { } /** * Private use only. See {@link #create(int, int, int, int)}. * Private use only. See {@link #create(int, int, int, int, boolean)}. */ private GraphicBuffer(int width, int height, int format, int usage, long nativeObject) { private GraphicBuffer(int width, int height, int format, int usage, long nativeObject, boolean capturedSecureLayers) { mWidth = width; mHeight = height; mFormat = format; mUsage = usage; mNativeObject = nativeObject; mCapturedSecureLayers = capturedSecureLayers; } /** * Private use only. See {@link #create(int, int, int, int)}. */ private GraphicBuffer(int width, int height, int format, int usage, long nativeObject) { this(width, height, format, usage, nativeObject, false); } /** Loading @@ -97,14 +107,33 @@ public class GraphicBuffer implements Parcelable { * @hide */ public static GraphicBuffer createFromExisting(int width, int height, int format, int usage, long unwrappedNativeObject) { int format, int usage, long unwrappedNativeObject, boolean capturedSecureLayers) { long nativeObject = nWrapGraphicBuffer(unwrappedNativeObject); if (nativeObject != 0) { return new GraphicBuffer(width, height, format, usage, nativeObject); return new GraphicBuffer(width, height, format, usage, nativeObject, capturedSecureLayers); } return null; } /** * For SurfaceControl JNI. Provides and ignored value for capturedSecureLayers for backwards * compatibility * @hide */ public static GraphicBuffer createFromExisting(int width, int height, int format, int usage, long unwrappedNativeObject) { return createFromExisting(width, height, format, usage, unwrappedNativeObject, false); } /** * Returns true if the buffer contains visible secure layers. */ public boolean doesContainSecureLayers() { return mCapturedSecureLayers; } /** * Returns the width of this buffer in pixels. */ Loading services/core/java/com/android/server/wm/ScreenRotationAnimation.java +22 −4 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.server.wm.ScreenRotationAnimationProto.ANIMATION_RUNNI import static com.android.server.wm.ScreenRotationAnimationProto.STARTED; import android.content.Context; import android.graphics.GraphicBuffer; import android.graphics.Matrix; import android.graphics.Rect; import android.os.IBinder; Loading Loading @@ -285,10 +286,27 @@ class ScreenRotationAnimation { if (displayHandle != null) { Surface sur = new Surface(); sur.copyFrom(mSurfaceControl); SurfaceControl.screenshot(displayHandle, sur); GraphicBuffer gb = SurfaceControl.screenshotToBufferWithSecureLayersUnsafe( new Rect(), 0 /* width */, 0 /* height */, 0 /* minLayer */, 0 /* maxLayer */, false /* useIdentityTransform */, 0 /* rotation */); if (gb != null) { try { sur.attachAndQueueBuffer(gb); } catch (RuntimeException e) { Slog.w(TAG, "Failed to attach screenshot - " + e.getMessage()); } // If the screenshot contains secure layers, we have to make sure the // screenshot surface we display it in also has FLAG_SECURE so that // the user can not screenshot secure layers via the screenshot surface. if (gb.doesContainSecureLayers()) { t.setSecure(mSurfaceControl, true); } t.setLayer(mSurfaceControl, SCREEN_FREEZE_LAYER_SCREENSHOT); t.setAlpha(mSurfaceControl, 0); t.show(mSurfaceControl); } else { Slog.w(TAG, "Unable to take screenshot of display " + displayId); } sur.destroy(); } else { Slog.w(TAG, "Built-in display " + displayId + " is null."); Loading Loading
core/java/android/view/SurfaceControl.java +24 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,8 @@ public class SurfaceControl implements Parcelable { boolean allLayers, boolean useIdentityTransform, int rotation); private static native GraphicBuffer nativeScreenshotToBuffer(IBinder displayToken, Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean allLayers, boolean useIdentityTransform, int rotation); boolean allLayers, boolean useIdentityTransform, int rotation, boolean captureSecureLayers); private static native void nativeScreenshot(IBinder displayToken, Surface consumer, Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean allLayers, boolean useIdentityTransform); Loading Loading @@ -1286,7 +1287,28 @@ public class SurfaceControl implements Parcelable { IBinder displayToken = SurfaceControl.getBuiltInDisplay( SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN); return nativeScreenshotToBuffer(displayToken, sourceCrop, width, height, minLayer, maxLayer, false, useIdentityTransform, rotation); minLayer, maxLayer, false, 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(Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean useIdentityTransform, int rotation) { IBinder displayToken = SurfaceControl.getBuiltInDisplay( SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN); return nativeScreenshotToBuffer(displayToken, sourceCrop, width, height, minLayer, maxLayer, false, useIdentityTransform, rotation, true /* captureSecureLayers */); } /** Loading
core/jni/android_os_HwBlob.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ JHwBlob::JHwBlob(JNIEnv *env, jobject thiz, size_t size) mOwnsBuffer(true), mHandle(0) { if (size > 0) { mBuffer = malloc(size); mBuffer = calloc(size, 1); } } Loading
core/jni/android_view_SurfaceControl.cpp +7 −5 Original line number Diff line number Diff line Loading @@ -160,7 +160,7 @@ static Rect rectFromObj(JNIEnv* env, jobject rectObj) { static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz, jobject displayTokenObj, jobject sourceCropObj, jint width, jint height, jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform, int rotation) { int rotation, bool captureSecureLayers) { sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj); if (displayToken == NULL) { return NULL; Loading @@ -171,9 +171,10 @@ static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz, maxLayer = INT32_MAX; } sp<GraphicBuffer> buffer; bool capturedSecureLayers = false; status_t res = ScreenshotClient::capture(displayToken, sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform, rotation, &buffer); rotation, captureSecureLayers, &buffer, capturedSecureLayers); if (res != NO_ERROR) { return NULL; } Loading @@ -184,7 +185,8 @@ static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz, buffer->getHeight(), buffer->getPixelFormat(), (jint)buffer->getUsage(), (jlong)buffer.get()); (jlong)buffer.get(), capturedSecureLayers); } static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz, Loading Loading @@ -1026,7 +1028,7 @@ static const JNINativeMethod sSurfaceControlMethods[] = { {"nativeGetHandle", "(J)Landroid/os/IBinder;", (void*)nativeGetHandle }, {"nativeScreenshotToBuffer", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZIZ)Landroid/graphics/GraphicBuffer;", (void*)nativeScreenshotToBuffer }, {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;", (void*)nativeCaptureLayers }, Loading Loading @@ -1082,7 +1084,7 @@ int register_android_view_SurfaceControl(JNIEnv* env) jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer"); gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz); gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz, "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;"); "createFromExisting", "(IIIIJZ)Landroid/graphics/GraphicBuffer;"); return err; } Loading
graphics/java/android/graphics/GraphicBuffer.java +33 −4 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ public class GraphicBuffer implements Parcelable { private final int mHeight; private final int mFormat; private final int mUsage; private final boolean mCapturedSecureLayers; // Note: do not rename, this field is used by native code private final long mNativeObject; Loading Loading @@ -82,14 +83,23 @@ public class GraphicBuffer implements Parcelable { } /** * Private use only. See {@link #create(int, int, int, int)}. * Private use only. See {@link #create(int, int, int, int, boolean)}. */ private GraphicBuffer(int width, int height, int format, int usage, long nativeObject) { private GraphicBuffer(int width, int height, int format, int usage, long nativeObject, boolean capturedSecureLayers) { mWidth = width; mHeight = height; mFormat = format; mUsage = usage; mNativeObject = nativeObject; mCapturedSecureLayers = capturedSecureLayers; } /** * Private use only. See {@link #create(int, int, int, int)}. */ private GraphicBuffer(int width, int height, int format, int usage, long nativeObject) { this(width, height, format, usage, nativeObject, false); } /** Loading @@ -97,14 +107,33 @@ public class GraphicBuffer implements Parcelable { * @hide */ public static GraphicBuffer createFromExisting(int width, int height, int format, int usage, long unwrappedNativeObject) { int format, int usage, long unwrappedNativeObject, boolean capturedSecureLayers) { long nativeObject = nWrapGraphicBuffer(unwrappedNativeObject); if (nativeObject != 0) { return new GraphicBuffer(width, height, format, usage, nativeObject); return new GraphicBuffer(width, height, format, usage, nativeObject, capturedSecureLayers); } return null; } /** * For SurfaceControl JNI. Provides and ignored value for capturedSecureLayers for backwards * compatibility * @hide */ public static GraphicBuffer createFromExisting(int width, int height, int format, int usage, long unwrappedNativeObject) { return createFromExisting(width, height, format, usage, unwrappedNativeObject, false); } /** * Returns true if the buffer contains visible secure layers. */ public boolean doesContainSecureLayers() { return mCapturedSecureLayers; } /** * Returns the width of this buffer in pixels. */ Loading
services/core/java/com/android/server/wm/ScreenRotationAnimation.java +22 −4 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.server.wm.ScreenRotationAnimationProto.ANIMATION_RUNNI import static com.android.server.wm.ScreenRotationAnimationProto.STARTED; import android.content.Context; import android.graphics.GraphicBuffer; import android.graphics.Matrix; import android.graphics.Rect; import android.os.IBinder; Loading Loading @@ -285,10 +286,27 @@ class ScreenRotationAnimation { if (displayHandle != null) { Surface sur = new Surface(); sur.copyFrom(mSurfaceControl); SurfaceControl.screenshot(displayHandle, sur); GraphicBuffer gb = SurfaceControl.screenshotToBufferWithSecureLayersUnsafe( new Rect(), 0 /* width */, 0 /* height */, 0 /* minLayer */, 0 /* maxLayer */, false /* useIdentityTransform */, 0 /* rotation */); if (gb != null) { try { sur.attachAndQueueBuffer(gb); } catch (RuntimeException e) { Slog.w(TAG, "Failed to attach screenshot - " + e.getMessage()); } // If the screenshot contains secure layers, we have to make sure the // screenshot surface we display it in also has FLAG_SECURE so that // the user can not screenshot secure layers via the screenshot surface. if (gb.doesContainSecureLayers()) { t.setSecure(mSurfaceControl, true); } t.setLayer(mSurfaceControl, SCREEN_FREEZE_LAYER_SCREENSHOT); t.setAlpha(mSurfaceControl, 0); t.show(mSurfaceControl); } else { Slog.w(TAG, "Unable to take screenshot of display " + displayId); } sur.destroy(); } else { Slog.w(TAG, "Built-in display " + displayId + " is null."); Loading