Merge "SurfaceFlinger: Add exclusion list for captureLayers." into qt-dev
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index ad2f65a..ec62e19 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -92,7 +92,7 @@
             Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation,
             boolean captureSecureLayers);
     private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder layerHandleToken,
-            Rect sourceCrop, float frameScale);
+            Rect sourceCrop, float frameScale, IBinder[] excludeLayers);
 
     private static native long nativeCreateTransaction();
     private static native long nativeGetNativeTransactionFinalizer();
@@ -1991,7 +1991,16 @@
      */
     public static ScreenshotGraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop,
             float frameScale) {
-        return nativeCaptureLayers(layerHandleToken, sourceCrop, frameScale);
+        return nativeCaptureLayers(layerHandleToken, sourceCrop, frameScale, null);
+    }
+
+    /**
+     * Like {@link captureLayers} but with an array of layer handles to exclude.
+     * @hide
+     */
+    public static ScreenshotGraphicBuffer captureLayersExcluding(IBinder layerHandleToken,
+            Rect sourceCrop, float frameScale, IBinder[] exclude) {
+        return nativeCaptureLayers(layerHandleToken, sourceCrop, frameScale, exclude);
     }
 
     /**
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index eb64fc4..c254266 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -270,7 +270,7 @@
 }
 
 static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
-        jobject sourceCropObj, jfloat frameScale) {
+        jobject sourceCropObj, jfloat frameScale, jobjectArray excludeArray) {
 
     sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
     if (layerHandle == NULL) {
@@ -282,11 +282,27 @@
         sourceCrop = rectFromObj(env, sourceCropObj);
     }
 
+    std::unordered_set<sp<IBinder>,ISurfaceComposer::SpHash<IBinder>> excludeHandles;
+    if (excludeArray != NULL) {
+        const jsize len = env->GetArrayLength(excludeArray);
+        excludeHandles.reserve(len);
+
+        for (jsize i = 0; i < len; i++) {
+            jobject obj = env->GetObjectArrayElement(excludeArray, i);
+            if (obj == nullptr) {
+                jniThrowNullPointerException(env, "Exclude layer is null");
+                return NULL;
+            }
+            sp<IBinder> excludeHandle = ibinderForJavaObject(env, obj);
+            excludeHandles.emplace(excludeHandle);
+        }
+    }
+
     sp<GraphicBuffer> buffer;
     const ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
     status_t res = ScreenshotClient::captureChildLayers(layerHandle, dataspace,
                                                         ui::PixelFormat::RGBA_8888, sourceCrop,
-                                                        frameScale, &buffer);
+                                                        excludeHandles, frameScale, &buffer);
     if (res != NO_ERROR) {
         return NULL;
     }
@@ -1354,7 +1370,7 @@
             "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
             (void*)nativeScreenshot },
     {"nativeCaptureLayers",
-            "(Landroid/os/IBinder;Landroid/graphics/Rect;F)"
+            "(Landroid/os/IBinder;Landroid/graphics/Rect;F[Landroid/os/IBinder;)"
             "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
             (void*)nativeCaptureLayers },
     {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",