Use current fullscreen opaque window as insets control target

This fixes stats bar blinking when switching from an app that hides
status bar to another that shows status bar. It is caused by the
TopFullscreenOpaqueWindow in DisplayPolicy will be updated according
to visibility. There may be an intermediate state that the insets
control target is still the previous window, then the transient
showing bar will be hidden a while.

It is tempting to make canAffectSystemUiFlags accept the activity
with mVisibleRequested=true so TopFullscreenOpaqueWindow can be
updated earlier. But that will break status bar hiding animation
when switching from an app that shows the bar to another that hides
the bar.

Also fix:
 - The original insets source is modified when getting insets state
   for client because the default "new InsetsState" will reuse the
   given insets sources.
 - Redundant invocation of updateBarControlTarget when calling
   abortTransient from updateBarControlTarget.

Fixes: 168023253
Bug: 160458371
Test: InsetsPolicyTest#testControlsForDispatch_topAppHidesStatusBar
Change-Id: I60f29dba81b0273a189ddd0a48a2e84155177f5b
Merged-In: I60f29dba81b0273a189ddd0a48a2e84155177f5b
5 files changed