Reduce outgoing call jankiness

OutgoingCallBroadcaster is an activity that waits for applications like
to repond to the NEW_OUTGOING_CALL ordered broadcast.

OutgoingCallBroadcaster displays itself as a completely black activity
with a spinner (if it takes very long) until it gets a response.

When the response finally comes in, it finishes the activity and starts
the in-call UI.

Problem:
   Now that the UI is in a different process, there is a flash on the
   screen between the time the OutgoingcallBroadcaster finishes() and
   the new UI starts up

Fix:
  Introduce a 2-second delay from when we kick off the new UI until the
  OutgoingCallBroadcaster calls finish().

Change-Id: I63fcc96a7ce876ffecdf9cbad9491b502837929d
(cherry picked from commit edb9496a779366a574367f5397e0dc60b0f2027f)
diff --git a/src/com/android/phone/OutgoingCallBroadcaster.java b/src/com/android/phone/OutgoingCallBroadcaster.java
index fbec3a9..b9aea52 100644
--- a/src/com/android/phone/OutgoingCallBroadcaster.java
+++ b/src/com/android/phone/OutgoingCallBroadcaster.java
@@ -95,7 +95,11 @@
 
     /** Note message codes < 100 are reserved for the PhoneApp. */
     private static final int EVENT_OUTGOING_CALL_TIMEOUT = 101;
+    private static final int EVENT_DELAYED_FINISH = 102;
+
     private static final int OUTGOING_CALL_TIMEOUT_THRESHOLD = 2000; // msec
+    private static final int DELAYED_FINISH_TIME = 2000; // msec
+
     /**
      * ProgressBar object with "spinner" style, which will be shown if we take more than
      * {@link #EVENT_OUTGOING_CALL_TIMEOUT} msec to handle the incoming Intent.
@@ -107,6 +111,8 @@
             if (msg.what == EVENT_OUTGOING_CALL_TIMEOUT) {
                 Log.i(TAG, "Outgoing call takes too long. Showing the spinner.");
                 mWaitingSpinner.setVisibility(View.VISIBLE);
+            } else if (msg.what == EVENT_DELAYED_FINISH) {
+                finish();
             } else {
                 Log.wtf(TAG, "Unknown message id: " + msg.what);
             }
@@ -114,6 +120,14 @@
     };
 
     /**
+     * Starts the delayed finish() of OutgoingCallBroadcaster in order to give the UI
+     * some time to start up.
+     */
+    private void startDelayedFinish() {
+        mHandler.sendEmptyMessageDelayed(EVENT_DELAYED_FINISH, DELAYED_FINISH_TIME);
+    }
+
+    /**
      * OutgoingCallReceiver finishes NEW_OUTGOING_CALL broadcasts, starting
      * the InCallScreen if the broadcast has not been canceled, possibly with
      * a modified phone number and optional provider info (uri + package name + remote views.)
@@ -126,7 +140,11 @@
             mHandler.removeMessages(EVENT_OUTGOING_CALL_TIMEOUT);
             doReceive(context, intent);
             if (DBG) Log.v(TAG, "OutgoingCallReceiver is going to finish the Activity itself.");
-            finish();
+
+            // We cannot finish the activity immediately here because it would cause the temporary
+            // black screen of OutgoingBroadcaster to go away and we need it to stay up until the
+            // UI (in a different process) has time to come up.
+            startDelayedFinish();
         }
 
         public void doReceive(Context context, Intent intent) {