Adding support for dialer to bring incallUI to foreground.

Previously, the Dialer relied on
TelephonyManager.showCallScreenWithDialpad to bring the UI to the
foreground after the user selected "return to call in progress." This
was not updated for the split in-call-ui.

The fix adds a new API to CallHandlerService to bring the incallui to
the foreground.  This new API now gets called as part of
showCallScreenWithDialpad().

bug:10313347
Change-Id: Id95a1e266471970cf1295423ea720b0e1926325b
diff --git a/src/com/android/phone/CallHandlerServiceProxy.java b/src/com/android/phone/CallHandlerServiceProxy.java
index 12e039e..4ae8090 100644
--- a/src/com/android/phone/CallHandlerServiceProxy.java
+++ b/src/com/android/phone/CallHandlerServiceProxy.java
@@ -134,6 +134,18 @@
         }
     }
 
+    public void bringToForeground() {
+        // only support this call if the service is already connected.
+        if (mCallHandlerService != null && mCallModeler.hasLiveCall()) {
+            try {
+                if (DBG) Log.d(TAG, "bringToForeground");
+                mCallHandlerService.bringToForeground();
+            } catch (RemoteException e) {
+                Log.e(TAG, "Exception handling bringToForeground", e);
+            }
+        }
+    }
+
     /**
      * Sets up the connection with ICallHandlerService
      */
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 165ae67..42f7f8c 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -430,8 +430,6 @@
             // status bar icons and control other status bar behavior.
             notificationMgr = NotificationMgr.init(this);
 
-            phoneMgr = PhoneInterfaceManager.init(this, phone);
-
             mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);
 
             int phoneType = phone.getPhoneType();
@@ -525,6 +523,8 @@
             callHandlerServiceProxy = new CallHandlerServiceProxy(this, callModeler,
                     callCommandService, audioRouter);
 
+            phoneMgr = PhoneInterfaceManager.init(this, phone, callHandlerServiceProxy);
+
             // Create the CallNotifer singleton, which handles
             // asynchronous events from the telephony layer (like
             // launching the incoming-call UI when an incoming call comes
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index c65c4f8..c37fe07 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -72,6 +72,7 @@
     CallManager mCM;
     AppOpsManager mAppOps;
     MainThreadHandler mMainThreadHandler;
+    CallHandlerServiceProxy mCallHandlerService;
 
     /**
      * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
@@ -218,10 +219,11 @@
      * Initialize the singleton PhoneInterfaceManager instance.
      * This is only done once, at startup, from PhoneApp.onCreate().
      */
-    /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
+    /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone,
+            CallHandlerServiceProxy callHandlerService) {
         synchronized (PhoneInterfaceManager.class) {
             if (sInstance == null) {
-                sInstance = new PhoneInterfaceManager(app, phone);
+                sInstance = new PhoneInterfaceManager(app, phone, callHandlerService);
             } else {
                 Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance);
             }
@@ -230,12 +232,14 @@
     }
 
     /** Private constructor; @see init() */
-    private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
+    private PhoneInterfaceManager(PhoneGlobals app, Phone phone,
+            CallHandlerServiceProxy callHandlerService) {
         mApp = app;
         mPhone = phone;
         mCM = PhoneGlobals.getInstance().mCM;
         mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
         mMainThreadHandler = new MainThreadHandler();
+        mCallHandlerService = callHandlerService;
         publish();
     }
 
@@ -303,26 +307,10 @@
         }
         // If the phone isn't idle then go to the in-call screen
         long callingId = Binder.clearCallingIdentity();
-        try {
-            Intent intent;
-            if (specifyInitialDialpadState) {
-                intent = PhoneGlobals.createInCallIntent(initialDialpadState);
-            } else {
-                intent = PhoneGlobals.createInCallIntent();
-            }
-            try {
-                //mApp.startActivity(intent);
-            } catch (ActivityNotFoundException e) {
-                // It's possible that the in-call UI might not exist
-                // (like on non-voice-capable devices), although we
-                // shouldn't be trying to bring up the InCallScreen on
-                // devices like that in the first place!
-                Log.w(LOG_TAG, "showCallScreenInternal: "
-                      + "transition to InCallScreen failed; intent = " + intent);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
+
+        mCallHandlerService.bringToForeground();
+
+        Binder.restoreCallingIdentity(callingId);
         return true;
     }