Merge "Fix issue where GSM conference is held in makeRoomForOutgoingCall." into mnc-dev
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index a4f62be..8ec5202 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -590,9 +590,19 @@
 
         Log.v(this, "startOutgoingCall found accounts = " + accounts);
 
-        if (mForegroundCall != null && mForegroundCall.getTargetPhoneAccount() != null) {
+        if (mForegroundCall != null) {
+            Call ongoingCall = mForegroundCall;
             // If there is an ongoing call, use the same phone account to place this new call.
-            phoneAccountHandle = mForegroundCall.getTargetPhoneAccount();
+            // If the ongoing call is a conference call, we fetch the phone account from the
+            // child calls because we don't have targetPhoneAccount set on Conference calls.
+            // TODO: Set targetPhoneAccount for all conference calls (b/23035408).
+            if (ongoingCall.getTargetPhoneAccount() == null &&
+                    !ongoingCall.getChildCalls().isEmpty()) {
+                ongoingCall = ongoingCall.getChildCalls().get(0);
+            }
+            if (ongoingCall.getTargetPhoneAccount() != null) {
+                phoneAccountHandle = ongoingCall.getTargetPhoneAccount();
+            }
         }
 
         // Only dial with the requested phoneAccount if it is still valid. Otherwise treat this call
diff --git a/src/com/android/server/telecom/PhoneAccountRegistrar.java b/src/com/android/server/telecom/PhoneAccountRegistrar.java
index d500eda..a18fcc0 100644
--- a/src/com/android/server/telecom/PhoneAccountRegistrar.java
+++ b/src/com/android/server/telecom/PhoneAccountRegistrar.java
@@ -121,7 +121,7 @@
 
     private static final String FILE_NAME = "phone-account-registrar-state.xml";
     @VisibleForTesting
-    public static final int EXPECTED_STATE_VERSION = 7;
+    public static final int EXPECTED_STATE_VERSION = 8;
 
     /** Keep in sync with the same in SipSettings.java */
     private static final String SIP_SHARED_PREFERENCES = "SIP_PREFERENCES";
@@ -1259,6 +1259,18 @@
                         enabled = true;
                     }
                 }
+                if (version < 8) {
+                    // Migrate the SIP account handle ids to use SIP username instead of SIP URI.
+                    if (accountHandle.getComponentName().equals(sipComponentName)) {
+                        Uri accountUri = Uri.parse(accountHandle.getId());
+                        if (accountUri.getScheme() != null &&
+                            accountUri.getScheme().equals(PhoneAccount.SCHEME_SIP)) {
+                            accountHandle = new PhoneAccountHandle(accountHandle.getComponentName(),
+                                    accountUri.getSchemeSpecificPart(),
+                                    accountHandle.getUserHandle());
+                        }
+                    }
+                }
 
                 PhoneAccount.Builder builder = PhoneAccount.builder(accountHandle, label)
                         .setAddress(address)