Use display of parent window if available

In case the app uses attrs.token on display 2 but the context
is display 1. E.g.
  var wm = display1Context.getSystemService(WindowManager)
  wm.addView(paramForDisplay2)
Then attrs.token should have a higher priority to choose the target
display. Otherwise the add-window will fail because it tries to
find the display2 window from display1.

Note that getDisplayContentOrCreate only accepts token that maps to
a WindowToken. e.g. from
 ActivityRecord.Token (Activity#getActivityToken)
   -> ActivityRecord (extends WindowToken)
 or IBinder -> WindowToken

So if the given attrs.token specifies View#getWindowToken (sub-window),
it won't be able to find the corresponding WindowToken from
DisplayContent#mTokenMap.

The View#getWindowToken is the IWindow of ViewRootImpl. So it can be
found from WMS#mWindowMap (IWindow -> WindowState). Then it is enough
to know the target display even if the given display id is wrong.

Bug: 338376012
Flag: EXEMPT bugfix
Test: atest WindowManagerServiceTests# \
      testAddWindowWithSubWindowTypeByWindowContext
Change-Id: I992389c089d7401cf42a981227b51e92bc7c3436
2 files changed