When waiting for activity to finish don't reset

In cases where the client is waiting for an activity to launch
(startActivityMayWait()) it is a bad idea to clear
ActivityRecord.displayStartTime when going into the pause state. If
displayStartTime is cleared before the activity is displayed,
the client will never be released.

This fix keeps pause from clearing displayStartTime if any client
is waiting for the activity to be displayed.

Fixes bug 10095558. But not a permanent fix, startActivityMayWait()
should not be called by any production code.

Change-Id: I7cbdcb04256f4a26233867c52aedd3bc4151adc3
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 8d27c5c..3571b40 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -620,7 +620,13 @@
     }
 
     void clearLaunchTime(ActivityRecord r) {
-        r.displayStartTime = r.fullyDrawnStartTime = 0;
+        // Make sure that there is no activity waiting for this to launch.
+        if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) {
+            r.displayStartTime = r.fullyDrawnStartTime = 0;
+        } else {
+            mStackSupervisor.removeTimeoutsForActivityLocked(r);
+            mStackSupervisor.scheduleIdleTimeoutLocked(r);
+        }
     }
 
     void awakeFromSleepingLocked() {