Bump activity stop timeout past ANR timeout.

Once the activity stop timeout is triggered we may destroy
surfaces triggering native crashes. Imagine though an
app that hung in onStop, and then receives (and fails to handle)
an input event. Since the stop timeout was started before the hang
the stop timeout is very likely to trigger before the ANR timeout
leading to difficult to account for crashes. By the same logic we
bump the toast removal timeout.

Test: Feed it to the monkeys.
Bug: 62536731
Change-Id: I8e357271cfaa9f4077bb5bc92fdbd4584a425e8b
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 4742575..906f52b 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -195,8 +195,12 @@
 
     // How long we wait for the activity to tell us it has stopped before
     // giving up.  This is a good amount of time because we really need this
-    // from the application in order to get its saved state.
-    private static final int STOP_TIMEOUT = 10 * 1000;
+    // from the application in order to get its saved state. Once the stop
+    // is complete we may start destroying client resources triggering
+    // crashes if the UI thread was hung. We put this timeout one second behind
+    // the ANR timeout so these situations will generate ANR instead of
+    // Surface lost or other errors.
+    private static final int STOP_TIMEOUT = 11 * 1000;
 
     // How long we wait until giving up on an activity telling us it has
     // finished destroying itself.
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index b9fb2e0..b911c7b 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -256,6 +256,9 @@
     static final int LONG_DELAY = PhoneWindowManager.TOAST_WINDOW_TIMEOUT;
     static final int SHORT_DELAY = 2000; // 2 seconds
 
+    // 1 second past the ANR timeout.
+    static final int FINISH_TOKEN_TIMEOUT = 11 * 1000;
+
     static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};
 
     static final long SNOOZE_UNTIL_UNSPECIFIED = -1;
@@ -4804,7 +4807,7 @@
     {
         mHandler.removeCallbacksAndMessages(token);
         Message m = Message.obtain(mHandler, MESSAGE_FINISH_TOKEN_TIMEOUT, token);
-        mHandler.sendMessageDelayed(m, 5);
+        mHandler.sendMessageDelayed(m, FINISH_TOKEN_TIMEOUT);
     }
 
     private void handleKillTokenTimeout(IBinder token)