Preventing cases where an app can be stopped while entering PiP.

- Ensure that we clear the timeouts on the old stack and reschedule
  them on the new stack when moving an activity to a new stack,
  otherwise the pause timeout from the old stack will cause onStop()
  to be called.
- When adding an activity to the stopping list for processing, prevent
  scheduling an idle immediately in case an activity tries to enter
  picture-in-picture when handling onUserLeaveHint().  In that case,
  schedule an idle after the default idle delay instead.
- In addition, when resuming a resumeWhilePausing activity, prevent the
  activity idle to trigger pausing activities to be immediately put into
  a stopped state.  This was a race between the handling of pause/resume
  that would cause a pip activity to get onStop() even if it called enter
  pip on pause. Instead, when processing an idle from the activity or
  from an immediate idle scheduled by the system, we defer processing
  pausing activities until a later idle (that it reschedules).

Test: android.server.cts.ActivityManagerPinnedStackTests
Test: #testEnterPipWithResumeWhilePausingActivityNoStop

Change-Id: I375369a800b7fadaa57d6e00e0564bc3ee338979
Signed-off-by: Winson Chung <winsonc@google.com>
4 files changed