Get screenshot to exclude black cutout

Bug: b/112869712
Test: long press power button to take screenshots && adb shell screencap
&& apps to take screenshots and check
Change-Id: Ieb83373c9103f9847775eca5788358b567a05b24
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index ae39202..d80cdee 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -4824,6 +4824,16 @@
     const auto display = getDisplayDeviceLocked(displayToken);
     if (!display) return BAD_VALUE;
 
+    const Rect& dispScissor = display->getScissor();
+    if (!dispScissor.isEmpty()) {
+        sourceCrop.set(dispScissor);
+        // adb shell screencap will default reqWidth and reqHeight to zeros.
+        if (reqWidth == 0 || reqHeight == 0) {
+            reqWidth = uint32_t(dispScissor.width());
+            reqHeight = uint32_t(dispScissor.height());
+        }
+    }
+
     DisplayRenderArea renderArea(display, sourceCrop, reqHeight, reqWidth, rotation);
 
     auto traverseLayers = std::bind(std::mem_fn(&SurfaceFlinger::traverseLayersInDisplay), this,