Merge "Create util for VoicemailProviderSetting operations." into lmp-mr1-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c086376..61eaa2c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -542,6 +542,11 @@
             </intent-filter>
         </activity>
 
+        <activity android:name="com.android.phone.settings.VoicemailSettingsActivity"
+            android:label="@string/voicemail"
+            android:theme="@style/DialerSettingsLight">
+        </activity>
+
         <!-- BroadcastReceiver for receiving Intents from Notification mechanism. -->
         <receiver android:name="PhoneGlobals$NotificationBroadcastReceiver" android:exported="false">
             <intent-filter>
diff --git a/res/values-mcc310-mnc004/config.xml b/res/values-mcc310-mnc004/config.xml
new file mode 100755
index 0000000..bbe9e7b
--- /dev/null
+++ b/res/values-mcc310-mnc004/config.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- Phone app resources that may need to be customized
+     for different hardware or product builds. -->
+<resources>
+    <!-- Flag indicating if dtmf tone type is enabled -->
+    <bool name="support_swap_after_merge" translatable="false">false</bool>
+</resources>
diff --git a/res/values-mcc311-mnc480/config.xml b/res/values-mcc311-mnc480/config.xml
old mode 100644
new mode 100755
index 7c269e0..df95aa4
--- a/res/values-mcc311-mnc480/config.xml
+++ b/res/values-mcc311-mnc480/config.xml
@@ -19,4 +19,5 @@
 <resources>
     <!-- Flag indicating if dtmf tone type is enabled -->
     <bool name="dtmf_type_enabled">true</bool>
+    <bool name="support_swap_after_merge" translatable="false">false</bool>
 </resources>
diff --git a/res/values/config.xml b/res/values/config.xml
old mode 100644
new mode 100755
index cd82234..881762d
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -149,4 +149,7 @@
 
     <!-- Allows the telephony HFA logic to run even if we're not in setup wizard. -->
     <bool name="config_allow_hfa_outside_of_setup_wizard">true</bool>
+
+    <!-- After a CDMA conference call is merged, the swap button should be displayed. -->
+    <bool name="support_swap_after_merge" translatable="false">true</bool>
 </resources>
diff --git a/res/xml/voicemail_settings.xml b/res/xml/voicemail_settings.xml
new file mode 100644
index 0000000..f4679e5
--- /dev/null
+++ b/res/xml/voicemail_settings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+    android:title="@string/voicemail">
+
+    <!-- Temporary placeholder until prefs are migrated from Call Settings. -->
+    <Preference android:title="@string/voicemail" />
+
+</PreferenceScreen>
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsActivity.java b/src/com/android/phone/settings/PhoneAccountSettingsActivity.java
index 14add68..71ae8cf 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsActivity.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsActivity.java
@@ -1,4 +1,4 @@
-/*
+/**
  * Copyright (C) 2014 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,12 +20,8 @@
 import android.preference.PreferenceActivity;
 import android.view.MenuItem;
 
-import com.android.internal.telephony.PhoneConstants;
-import com.android.phone.PhoneGlobals;
 import com.android.phone.R;
 
-// TODO: Convert FeatureCallSettings into a preference fragment based activity, and load the
-// PhoneAccountSettings fragment directly instead of starting this PreferenceActivity.
 public class PhoneAccountSettingsActivity extends PreferenceActivity {
 
     @Override
@@ -39,8 +35,7 @@
 
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
-        final int itemId = item.getItemId();
-        if (itemId == android.R.id.home) {
+        if (item.getItemId() == android.R.id.home) {
             onBackPressed();
             return true;
         }
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index 20fc108..5f5a32e 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -82,7 +82,7 @@
             getPreferenceScreen().removeAll();
         }
 
-        addPreferencesFromResource(com.android.phone.R.xml.phone_account_settings);
+        addPreferencesFromResource(R.xml.phone_account_settings);
 
         TelephonyManager telephonyManager =
                 (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
diff --git a/src/com/android/phone/settings/VoicemailSettingsActivity.java b/src/com/android/phone/settings/VoicemailSettingsActivity.java
new file mode 100644
index 0000000..a94c27a
--- /dev/null
+++ b/src/com/android/phone/settings/VoicemailSettingsActivity.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.phone.settings;
+
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+import android.view.MenuItem;
+
+import com.android.phone.R;
+
+public class VoicemailSettingsActivity extends PreferenceActivity {
+
+    @Override
+    protected void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        getActionBar().setTitle(R.string.voicemail);
+        getFragmentManager().beginTransaction().replace(
+                android.R.id.content, new VoicemailSettingsFragment()).commit();
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        if (item.getItemId() == android.R.id.home) {
+            onBackPressed();
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+}
diff --git a/src/com/android/phone/settings/VoicemailSettingsFragment.java b/src/com/android/phone/settings/VoicemailSettingsFragment.java
new file mode 100644
index 0000000..fef3e8c
--- /dev/null
+++ b/src/com/android/phone/settings/VoicemailSettingsFragment.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.phone.settings;
+
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+import com.android.phone.R;
+
+public class VoicemailSettingsFragment extends PreferenceFragment {
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        addPreferencesFromResource(R.xml.voicemail_settings);
+    }
+}
diff --git a/src/com/android/services/telephony/CdmaConference.java b/src/com/android/services/telephony/CdmaConference.java
old mode 100644
new mode 100755
index c77557f..5372548
--- a/src/com/android/services/telephony/CdmaConference.java
+++ b/src/com/android/services/telephony/CdmaConference.java
@@ -16,6 +16,8 @@
 
 package com.android.services.telephony;
 
+import android.content.Context;
+import android.content.res.Resources;
 import android.telecom.Conference;
 import android.telecom.Connection;
 import android.telecom.PhoneAccountHandle;
@@ -23,6 +25,8 @@
 
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallStateException;
+import com.android.phone.PhoneGlobals;
+import com.android.phone.common.R;
 
 import java.util.List;
 
@@ -82,7 +86,9 @@
         // Can only merge once
         mCapabilities &= ~PhoneCapabilities.MERGE_CONFERENCE;
         // Once merged, swap is enabled.
-        mCapabilities |= PhoneCapabilities.SWAP_CONFERENCE;
+        if (isSwapSupportedAfterMerge()){
+            mCapabilities |= PhoneCapabilities.SWAP_CONFERENCE;
+        }
         updateCapabilities();
         sendFlash();
     }
@@ -149,6 +155,27 @@
         return null;
     }
 
+    /**
+     * Return whether network support swap after merge conference call.
+     *
+     * @return true to support, false not support.
+     */
+    private final boolean isSwapSupportedAfterMerge()
+    {
+        boolean supportSwapAfterMerge = true;
+        Context context = PhoneGlobals.getInstance();
+
+        if (context != null) {
+            Resources r = context.getResources();
+            if (r != null) {
+                supportSwapAfterMerge = r.getBoolean(R.bool.support_swap_after_merge);
+                Log.d(this, "Current network support swap after call merged capability is "
+                        + supportSwapAfterMerge);
+            }
+        }
+        return supportSwapAfterMerge;
+    }
+
     private com.android.internal.telephony.Connection getOriginalConnection(Connection connection) {
         if (connection instanceof CdmaConnection) {
             return ((CdmaConnection) connection).getOriginalConnection();
diff --git a/src/com/android/services/telephony/ConferenceParticipantConnection.java b/src/com/android/services/telephony/ConferenceParticipantConnection.java
index a1ed6a3..7874404 100644
--- a/src/com/android/services/telephony/ConferenceParticipantConnection.java
+++ b/src/com/android/services/telephony/ConferenceParticipantConnection.java
@@ -50,7 +50,7 @@
         mParentConnection = parentConnection;
         setAddress(participant.getHandle(), PhoneConstants.PRESENTATION_ALLOWED);
         setCallerDisplayName(participant.getDisplayName(), PhoneConstants.PRESENTATION_ALLOWED);
-        updateState(participant.getState());
+
         mEndpoint = participant.getEndpoint();
         setCapabilities();
     }
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index f50db0c..ef63068 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -60,6 +60,16 @@
             R.drawable.ic_multi_sim4
     };
 
+    private final static int[] colors = {
+        0xff00796b,
+        0xff3367d6,
+        0xff303f9f,
+        0xff7b1fa2,
+        0xffc2185b,
+        0xffc53929
+    };
+
+
     // This icon is the one that is used when the Slot ID that we have for a particular SIM
     // is not supported, i.e. SubscriptionManager.INVALID_SLOT_ID or the 5th SIM in a phone.
     private final static int defaultPhoneAccountIcon =  R.drawable.ic_multi_sim;
@@ -124,9 +134,8 @@
                     subDisplayName = record.displayName;
                     slotId = record.slotId;
 
-                    // Assign a "fake" color while the underlying Telephony stuff is refactored
-                    // Assign PhoneAccount.NO_COLOR to first slot so single-SIM phones are unchanged
-                    color = slotId == 0? PhoneAccount.NO_COLOR : makeFakeColor(subId);
+                    // Assign a "fake" color while the underlying Telephony stuff is refactored.
+                    color = makeFakeColor(subId);
                 }
 
                 String slotIdString;
@@ -180,11 +189,6 @@
     }
 
     private int makeFakeColor(long subId) {
-        int[] colors = new int[] {
-                0xff0000,
-                0x00ff00,
-                0x0000ff,
-        };
         return colors[((int) subId) % colors.length];
     }
 
diff --git a/src/com/android/services/telephony/TelephonyConference.java b/src/com/android/services/telephony/TelephonyConference.java
index fdb7261..54529bb 100644
--- a/src/com/android/services/telephony/TelephonyConference.java
+++ b/src/com/android/services/telephony/TelephonyConference.java
@@ -71,7 +71,7 @@
     @Override
     public void onSeparate(Connection connection) {
         com.android.internal.telephony.Connection radioConnection =
-                getOriginalConnection(connection, "onSeparate");
+                getOriginalConnection(connection);
         try {
             radioConnection.separate();
         } catch (CallStateException e) {
@@ -129,9 +129,28 @@
         }
     }
 
+    @Override
+    public Connection getPrimaryConnection() {
+        // Default to the first connection.
+        Connection primaryConnection = getConnections().get(0);
+
+        // Otherwise look for a connection where the radio connection states it is multiparty.
+        for (Connection connection : getConnections()) {
+            com.android.internal.telephony.Connection radioConnection =
+                    getOriginalConnection(connection);
+
+            if (radioConnection != null && radioConnection.isMultiparty()) {
+                primaryConnection = connection;
+                break;
+            }
+        }
+
+        return primaryConnection;
+    }
+
     private Call getMultipartyCallForConnection(Connection connection, String tag) {
         com.android.internal.telephony.Connection radioConnection =
-                getOriginalConnection(connection, tag);
+                getOriginalConnection(connection);
         if (radioConnection != null) {
             Call call = radioConnection.getCall();
             if (call != null && call.isMultiparty()) {
@@ -142,12 +161,11 @@
     }
 
     private com.android.internal.telephony.Connection getOriginalConnection(
-            Connection connection, String tag) {
+            Connection connection) {
 
         if (connection instanceof TelephonyConnection) {
             return ((TelephonyConnection) connection).getOriginalConnection();
         } else {
-            Log.e(this, null, "Non TelephonyConnection found in a TelephonyConference (%s)", tag);
             return null;
         }
     }
diff --git a/src/com/android/services/telephony/TelephonyConferenceController.java b/src/com/android/services/telephony/TelephonyConferenceController.java
index b64464d..892f3f9 100644
--- a/src/com/android/services/telephony/TelephonyConferenceController.java
+++ b/src/com/android/services/telephony/TelephonyConferenceController.java
@@ -28,6 +28,7 @@
 import android.telecom.ConferenceParticipant;
 import android.telecom.Connection;
 import android.telecom.DisconnectCause;
+import android.telecom.PhoneAccountHandle;
 
 import com.android.internal.telephony.Call;
 
@@ -65,10 +66,16 @@
          * @param participant The participant information.
          */
         @Override
-        public void onConferenceParticipantChanged(Connection c, ConferenceParticipant participant)
-        {
+        public void onConferenceParticipantChanged(Connection c,
+                ConferenceParticipant participant) {
+
+            if (c == null) {
+                return;
+            }
+            TelephonyConnection telephonyConnection = (TelephonyConnection) c;
+
             Log.v(this, "onConferenceParticipantChanged: %s", participant);
-            handleConferenceParticipantUpdate(c, participant);
+            handleConferenceParticipantUpdate(telephonyConnection, participant);
         }
     };
 
@@ -176,7 +183,7 @@
     }
 
     private void recalculateConference() {
-        Set<TelephonyConnection> conferencedConnections = new HashSet<>();
+        Set<Connection> conferencedConnections = new HashSet<>();
 
         for (TelephonyConnection connection : mTelephonyConnections) {
             com.android.internal.telephony.Connection radioConnection =
@@ -192,6 +199,12 @@
             }
         }
 
+        // Include conference participants in the list of conferenced connections.
+        for (ConferenceParticipantConnection participant :
+                mConferenceParticipantConnections.values()) {
+            conferencedConnections.add(participant);
+        }
+
         Log.d(this, "Recalculate conference calls %s %s.",
                 mTelephonyConference, conferencedConnections);
 
@@ -230,7 +243,7 @@
             }
 
             // Set the conference state to the same state as its child connections.
-            Connection conferencedConnection = mTelephonyConference.getConnections().get(0);
+            Connection conferencedConnection = mTelephonyConference.getPrimaryConnection();
             switch (conferencedConnection.getState()) {
                 case Connection.STATE_ACTIVE:
                     mTelephonyConference.setActive();
@@ -249,7 +262,7 @@
      * @param participant The conference participant.
      */
     private void handleConferenceParticipantUpdate(
-            Connection parent, ConferenceParticipant participant) {
+            TelephonyConnection parent, ConferenceParticipant participant) {
 
         Uri endpoint = participant.getEndpoint();
         if (!mConferenceParticipantConnections.containsKey(endpoint)) {
@@ -272,13 +285,20 @@
      * @param participant The conference participant information.
      */
     private void createConferenceParticipantConnection(
-            Connection parent, ConferenceParticipant participant) {
+            TelephonyConnection parent, ConferenceParticipant participant) {
 
+        // Create and add the new connection in holding state so that it does not become the
+        // active call.
         ConferenceParticipantConnection connection = new ConferenceParticipantConnection(
                 parent, participant);
         connection.addConnectionListener(mConnectionListener);
+        connection.updateState(Connection.STATE_HOLDING);
         mConferenceParticipantConnections.put(participant.getEndpoint(), connection);
+        PhoneAccountHandle phoneAccountHandle =
+                TelecomAccountRegistry.makePstnPhoneAccountHandle(parent.getPhone());
+        mConnectionService.addExistingConnection(phoneAccountHandle, connection);
 
-        // TODO: Inform telecom of the new participant.
+        // Recalculate to add to the conference and set its state appropriately.
+        recalculateConference();
     }
 }