Fixes for broken saved surface

- Reset and restore the visibility flags and hasSurface states when
  surface is saved or restored. When the surface is in saved stated,
  we have to make the rest of the system believe that the window has
  no surface.

- Set app windows to 'mExiting' when we start a transistion because
  window manager changes the visibility of the app. We can't rely on
  receiving a relayoutWindow from the app to invisible. We need to
  mark it exiting so that when the transition is done, the surfaces
  get removed (or saved if possible) promptly.

- We need to save the surface if the app token is the last one in
  a task, regardless of whether it's visible, this means the whole
  task is going into background. But if the app has another visible
  token on top of it, we don't need to save it. For example one
  activity launches another activity, in this case we don't want to
  save the surface of the activity on the bottom.

bug: 26573100

Change-Id: Id845f87b30cda1cebcc12ad2ac8dbf19a068a86e
6 files changed