Fix startActivityAndWait bugs

- Send timeout message with a delay. The delay got lost when moving
from ActivityStack to ActivityStackSupervisor. Fixes bug 8687083.

- Remove waiting activities from list after they have been awoken.
Previously the list just got bigger and bigger.

Change-Id: Icb9e394db1eefa444e58c5416472017cac32298c
diff --git a/services/java/com/android/server/am/ActivityStackSupervisor.java b/services/java/com/android/server/am/ActivityStackSupervisor.java
index 528bf6f..82944a9 100644
--- a/services/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/java/com/android/server/am/ActivityStackSupervisor.java
@@ -438,7 +438,7 @@
     void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r,
             long thisTime, long totalTime) {
         for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) {
-            WaitResult w = mWaitingActivityLaunched.get(i);
+            WaitResult w = mWaitingActivityLaunched.remove(i);
             w.timeout = timeout;
             if (r != null) {
                 w.who = new ComponentName(r.info.packageName, r.info.name);
@@ -2182,7 +2182,8 @@
     }
 
     void scheduleIdleTimeoutLocked(ActivityRecord next) {
-        mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next).sendToTarget();
+        Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next);
+        mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT);
     }
 
     final void scheduleIdleLocked() {