Update foreground calls with child-parent call changes.

Bug: 17699262
Change-Id: I4de8bd876b142e2762a369a36ea2e7dcc7b84e65
diff --git a/src/com/android/server/telecom/BluetoothPhoneService.java b/src/com/android/server/telecom/BluetoothPhoneService.java
index 443e7c3..a2688a1 100644
--- a/src/com/android/server/telecom/BluetoothPhoneService.java
+++ b/src/com/android/server/telecom/BluetoothPhoneService.java
@@ -428,7 +428,8 @@
         Call ringingCall = callsManager.getRingingCall();
         Call heldCall = callsManager.getHeldCall();
 
-        Log.v(TAG, "Active: %s\nRinging: %s\nHeld: %s", activeCall, ringingCall, heldCall);
+        // TODO: Keeping as Log.i for now.  Move to Log.d after L release if BT proves stable.
+        Log.i(TAG, "Active: %s\nRinging: %s\nHeld: %s", activeCall, ringingCall, heldCall);
 
         if (chld == CHLD_TYPE_RELEASEHELD) {
             if (ringingCall != null) {
@@ -466,7 +467,7 @@
             }
         } else if (chld == CHLD_TYPE_ADDHELDTOCONF) {
             if (activeCall != null) {
-                if (activeCall != null && activeCall.can(PhoneCapabilities.MERGE_CONFERENCE)) {
+                if (activeCall.can(PhoneCapabilities.MERGE_CONFERENCE)) {
                     activeCall.mergeConference();
                     return true;
                 } else {
diff --git a/src/com/android/server/telecom/Call.java b/src/com/android/server/telecom/Call.java
index 85463eb..5e66850 100644
--- a/src/com/android/server/telecom/Call.java
+++ b/src/com/android/server/telecom/Call.java
@@ -353,8 +353,15 @@
             component = mConnectionService.getComponentName().flattenToShortString();
         }
 
-        return String.format(Locale.US, "[%s, %s, %s, %s, %d]", System.identityHashCode(this),
-                mState, component, Log.piiHandle(mHandle), getVideoState());
+        return String.format(Locale.US, "[%s, %s, %s, %s, %d, childs(%d), has_parent(%b), [%s]",
+                System.identityHashCode(this),
+                CallState.toString(mState),
+                component,
+                Log.piiHandle(mHandle),
+                getVideoState(),
+                getChildCalls().size(),
+                getParentCall() != null,
+                PhoneCapabilities.toString(getCallCapabilities()));
     }
 
     int getState() {
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 52c0b44..de53c05 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -254,6 +254,8 @@
 
     @Override
     public void onParentChanged(Call call) {
+        // parent-child relationship affects which call should be foreground, so do an update.
+        updateForegroundCall();
         for (CallsManagerListener listener : mListeners) {
             listener.onIsConferencedChanged(call);
         }
@@ -261,6 +263,8 @@
 
     @Override
     public void onChildrenChanged(Call call) {
+        // parent-child relationship affects which call should be foreground, so do an update.
+        updateForegroundCall();
         for (CallsManagerListener listener : mListeners) {
             listener.onIsConferencedChanged(call);
         }