[sf] fix crash when taking a screenshot

If a screenshot is requested immediately after it was created,
there might be a chance the layer does not exist in the main
thread data structures. This can happen if the screenshot
request is handled before main thread can create layers
added from the binder thread. Make sure we don't crash
when taking a screenshot by checking if the layer exists before
checking if it's secure.

Fixes: 312545483
Test: presubmit
Test: atest com.android.server.wm.ZOrderingTests#testImeScreenshotLayer
Change-Id: If765794e0fd9eb6c2bc2c65d8bc4c7523d905fa6
1 file changed