Store isTrustedOverlay before returning early for hidden layers.

When a layer is hidden, we will still gather input info, but not
continue down the updateSnapshot method. Extracting isTrustedOverlay was
happening after so if the caller was a hidden spy window that also was a
trusted overlay, it would crash InputDispatcher since it would receive
the hidden windowInfo data with spy but not trusted overlay.

This fix moves the isTrustedOverlay extraction before the hidden check
so input info will contain trusted overlay info even if the window was
hidden

Test: LayerSnapshotTest#setTrustedOverlayForNonVisibleInput
Fixes: 304391559
Change-Id: Ie068c179635998e189814448062d86db0b089f40
diff --git a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
index 50dfcaa..fc4bb22 100644
--- a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
+++ b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp
@@ -861,4 +861,15 @@
     EXPECT_EQ(getSnapshot(1)->shadowSettings.length, SHADOW_RADIUS);
 }
 
+TEST_F(LayerSnapshotTest, setTrustedOverlayForNonVisibleInput) {
+    hideLayer(1);
+    setTrustedOverlay(1, true);
+    Region touch{Rect{0, 0, 1000, 1000}};
+    setTouchableRegion(1, touch);
+
+    UPDATE_AND_VERIFY(mSnapshotBuilder, {2});
+    EXPECT_TRUE(getSnapshot(1)->inputInfo.inputConfig.test(
+            gui::WindowInfo::InputConfig::TRUSTED_OVERLAY));
+}
+
 } // namespace android::surfaceflinger::frontend