Added SKIP_SCREENSHOT flag for layers

The previous way to skip taking a layer in the screenshot was to set the
windowType to WINDOW_TYPE_DONT_SCREENSHOT. This is confusing since
skipping screenshots is not really related to window type. Instead, use
the new flag SKIP_SCREENSHOT that can be set when the layer is created
or in a transaction. This simplifies the behavior when deciding if the
layer should be screenshot.

This also fixes a bug where if the SKIP_SCREENSHOT flag was added after
creation, the layer would still be screenshot since the flag primaryDisplayOnly
was not changed.

This also makes it so the flag is inherited by the children. So if a
parent sets the flag, the children will also not be in the screenshot.

Test: ScreenCapture_test
Fixes: 168943350
Change-Id: I26d2b3d025d8daac17b303a96d5b54fc104f0d50
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 09ec819..b19e453 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -89,6 +89,8 @@
     if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
     if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
     if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
+    if (args.flags & ISurfaceComposerClient::eSkipScreenshot)
+        layerFlags |= layer_state_t::eLayerSkipScreenshot;
 
     mCurrentState.active_legacy.w = args.w;
     mCurrentState.active_legacy.h = args.h;
@@ -2658,6 +2660,16 @@
     }
 }
 
+bool Layer::getPrimaryDisplayOnly() const {
+    const State& s(mDrawingState);
+    if (s.flags & layer_state_t::eLayerSkipScreenshot) {
+        return true;
+    }
+
+    sp<Layer> parent = mDrawingParent.promote();
+    return parent == nullptr ? false : parent->getPrimaryDisplayOnly();
+}
+
 // ---------------------------------------------------------------------------
 
 }; // namespace android