Merge "Remove Phone Account Preferences; moved to Telephony." into lmp-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1fcfd23..5026fae 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -200,15 +200,6 @@
             </intent-filter>
         </activity>
 
-        <activity android:name=".PhoneAccountPreferencesActivity"
-                  android:label="@string/phone_account_preferences_title"
-                  android:configChanges="orientation|screenSize|keyboardHidden"
-                  android:exported="true">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-            </intent-filter>
-        </activity>
-
         <activity android:name=".ErrorDialogActivity"
                 android:configChanges="orientation|screenSize|keyboardHidden"
                 android:excludeFromRecents="true"
diff --git a/res/layout/phone_account_preferences.xml b/res/layout/phone_account_preferences.xml
deleted file mode 100644
index caf2a47..0000000
--- a/res/layout/phone_account_preferences.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?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.
--->
-
-<LinearLayout
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        android:orientation="vertical"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent">
-    <fragment
-            android:id="@+id/preferences_fragment"
-            class="com.android.telecomm.PhoneAccountPreferencesActivity$PreferencesFragment"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content" />
-</LinearLayout>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d50d830..9ecc6bb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -76,21 +76,6 @@
         a text response. [CHAR LIMIT=40] -->
     <string name="respond_via_sms_confirmation_format">Message sent to <xliff:g id="phone_number">%s</xliff:g>.</string>
 
-    <!-- Title for phone accounts settings screen -->
-    <string name="phone_account_preferences_title">Phone account settings</string>
-
-    <!-- Title for setting to select default outgoing phone account -->
-    <string name="default_outgoing_account_title">Default outgoing account</string>
-
-    <!-- Title for setting to select SIM call manager account -->
-    <string name="sim_call_manager_account">Wi-Fi calling account</string>
-
-    <!-- Indication to "ask every time" for accounts when making a call -->
-    <string name="account_ask_every_time">Ask every time</string>
-
-    <!-- Indication to not use a SIM call manager -->
-    <string name="do_not_use_sim_call_manager">Do not use Wi-Fi calling</string>
-
     <!-- Message indicating that the user is not allowed to make non-emergency outgoing phone calls
          due to a user restriction -->
     <string name="outgoing_call_not_allowed">This user is not allowed to make non-emergency phone calls</string>
diff --git a/res/xml/phone_account_preferences.xml b/res/xml/phone_account_preferences.xml
deleted file mode 100644
index 23313a1..0000000
--- a/res/xml/phone_account_preferences.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?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.
--->
-
-<!-- Settings screen for selecting which PhoneAccountHandle to use by default
-     for making outgoing phone calls -->
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
-     android:title="@string/phone_account_preferences_title">
-    <com.android.telecomm.AccountSelectionPreference
-            android:key="default_outgoing_account"
-            android:title="@string/default_outgoing_account_title"
-            android:defaultValue=""
-            android:persistent="false" />
-    <com.android.telecomm.AccountSelectionPreference
-            android:key="sim_call_manager_account"
-            android:title="@string/sim_call_manager_account"
-            android:defaultValue=""
-            android:persistent="false" />
-</PreferenceScreen>
diff --git a/src/com/android/telecomm/AccountSelectionPreference.java b/src/com/android/telecomm/AccountSelectionPreference.java
deleted file mode 100644
index e7c2bc0..0000000
--- a/src/com/android/telecomm/AccountSelectionPreference.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.telecomm;
-
-import android.content.Context;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.telecomm.PhoneAccountHandle;
-import android.util.AttributeSet;
-
-import java.util.List;
-import java.util.Objects;
-
-public class AccountSelectionPreference extends ListPreference implements
-        Preference.OnPreferenceChangeListener {
-
-    public interface AccountSelectionListener {
-        boolean onAccountSelected(AccountSelectionPreference pref, PhoneAccountHandle account);
-    }
-
-    private AccountSelectionListener mListener;
-    private PhoneAccountHandle[] mAccounts;
-    private String[] mEntryValues;
-    private CharSequence[] mEntries;
-
-    public AccountSelectionPreference(Context context) {
-        super(context);
-        setOnPreferenceChangeListener(this);
-    }
-
-    public AccountSelectionPreference(Context context, AttributeSet attrs) {
-        super(context, attrs);
-        setOnPreferenceChangeListener(this);
-    }
-
-    public void setListener(AccountSelectionListener listener) {
-        mListener = listener;
-    }
-
-    public void setModel(
-            PhoneAccountRegistrar registrar,
-            List<PhoneAccountHandle> accountsList,
-            PhoneAccountHandle currentSelection,
-            CharSequence nullSelectionString) {
-        mAccounts = accountsList.toArray(new PhoneAccountHandle[accountsList.size()]);
-        mEntryValues = new String[mAccounts.length + 1];
-        mEntries = new CharSequence[mAccounts.length + 1];
-
-        int selectedIndex = mAccounts.length;  // Points to nullSelectionString by default
-        int i = 0;
-        for ( ; i < mAccounts.length; i++) {
-            CharSequence label = registrar.getPhoneAccount(mAccounts[i]).getLabel();
-            mEntries[i] = label == null ? null : label.toString();
-            mEntryValues[i] = Integer.toString(i);
-            if (Objects.equals(currentSelection, mAccounts[i])) {
-                selectedIndex = i;
-            }
-        }
-        mEntryValues[i] = Integer.toString(i);
-        mEntries[i] = nullSelectionString;
-
-        setEntryValues(mEntryValues);
-        setEntries(mEntries);
-        setValueIndex(selectedIndex);
-        setSummary(mEntries[selectedIndex]);
-    }
-
-    @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
-        if (mListener != null) {
-            int index = Integer.parseInt((String) newValue);
-            PhoneAccountHandle account = index < mAccounts.length ? mAccounts[index] : null;
-            if (mListener.onAccountSelected(this, account)) {
-                setSummary(mEntries[index]);
-                return true;
-            }
-        }
-        return false;
-    }
-}
diff --git a/src/com/android/telecomm/PhoneAccountPreferencesActivity.java b/src/com/android/telecomm/PhoneAccountPreferencesActivity.java
deleted file mode 100644
index 7b64631..0000000
--- a/src/com/android/telecomm/PhoneAccountPreferencesActivity.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.telecomm;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.preference.PreferenceFragment;
-import android.telecomm.PhoneAccount;
-import android.telecomm.PhoneAccountHandle;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class PhoneAccountPreferencesActivity extends Activity {
-
-    private static final String KEY_DEFAULT_OUTGOING_ACCOUNT = "default_outgoing_account";
-    private static final String KEY_SIM_CALL_MANAGER_ACCOUNT = "sim_call_manager_account";
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.phone_account_preferences);
-    }
-
-    public static class PreferencesFragment extends PreferenceFragment
-            implements AccountSelectionPreference.AccountSelectionListener {
-        private AccountSelectionPreference mDefaultOutgoingAccount;
-        private AccountSelectionPreference mSimCallManagerAccount;
-
-        @Override
-        public void onCreate(Bundle savedInstanceState) {
-            super.onCreate(savedInstanceState);
-
-            addPreferencesFromResource(R.xml.phone_account_preferences);
-
-            mDefaultOutgoingAccount = (AccountSelectionPreference)
-                    findPreference(KEY_DEFAULT_OUTGOING_ACCOUNT);
-            mSimCallManagerAccount = (AccountSelectionPreference)
-                    findPreference(KEY_SIM_CALL_MANAGER_ACCOUNT);
-
-            PhoneAccountRegistrar registrar = TelecommApp.getInstance().getPhoneAccountRegistrar();
-
-            mDefaultOutgoingAccount.setModel(
-                    registrar,
-                    registrar.getOutgoingPhoneAccounts(),
-                    registrar.getUserSelectedOutgoingPhoneAccount(),
-                    getString(R.string.account_ask_every_time));
-
-            mSimCallManagerAccount.setModel(
-                    registrar,
-                    registrar.getAllConnectionManagerPhoneAccounts(),
-                    registrar.getSimCallManager(),
-                    getString(R.string.do_not_use_sim_call_manager));
-
-            mDefaultOutgoingAccount.setListener(this);
-            mSimCallManagerAccount.setListener(this);
-        }
-
-        @Override
-        public boolean onAccountSelected(
-                AccountSelectionPreference p, PhoneAccountHandle account) {
-            PhoneAccountRegistrar registrar = TelecommApp.getInstance().getPhoneAccountRegistrar();
-            if (p == mDefaultOutgoingAccount) {
-                registrar.setDefaultOutgoingPhoneAccount(account);
-                return true;
-            } else if (p == mSimCallManagerAccount) {
-                registrar.setSimCallManager(account);
-                return true;
-            }
-            return false;
-        }
-    }
-}
diff --git a/src/com/android/telecomm/PhoneAccountRegistrar.java b/src/com/android/telecomm/PhoneAccountRegistrar.java
index f7652d7..74cdf90 100644
--- a/src/com/android/telecomm/PhoneAccountRegistrar.java
+++ b/src/com/android/telecomm/PhoneAccountRegistrar.java
@@ -147,7 +147,7 @@
         return null;
     }
 
-    public void setDefaultOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
+    public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
         if (accountHandle == null) {
             // Asking to clear the default outgoing is a valid request
             mState.defaultOutgoing = null;
diff --git a/src/com/android/telecomm/TelecommServiceImpl.java b/src/com/android/telecomm/TelecommServiceImpl.java
index ef26085..93337a5 100644
--- a/src/com/android/telecomm/TelecommServiceImpl.java
+++ b/src/com/android/telecomm/TelecommServiceImpl.java
@@ -170,13 +170,23 @@
     }
 
     @Override
-    public void setDefaultOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
+    public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
+        try {
+            return mPhoneAccountRegistrar.getUserSelectedOutgoingPhoneAccount();
+        } catch (Exception e) {
+            Log.e(this, e, "getUserSelectedOutgoingPhoneAccount");
+            throw e;
+        }
+    }
+
+    @Override
+    public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
         enforceModifyPermission();
 
         try {
-            mPhoneAccountRegistrar.setDefaultOutgoingPhoneAccount(accountHandle);
+            mPhoneAccountRegistrar.setUserSelectedOutgoingPhoneAccount(accountHandle);
         } catch (Exception e) {
-            Log.e(this, e, "setDefaultOutgoingPhoneAccount");
+            Log.e(this, e, "setUserSelectedOutgoingPhoneAccount");
             throw e;
         }
     }
diff --git a/tests/src/com/android/telecomm/tests/unit/PhoneAccountRegistrarTest.java b/tests/src/com/android/telecomm/tests/unit/PhoneAccountRegistrarTest.java
index 3522153..41b7924 100644
--- a/tests/src/com/android/telecomm/tests/unit/PhoneAccountRegistrarTest.java
+++ b/tests/src/com/android/telecomm/tests/unit/PhoneAccountRegistrarTest.java
@@ -242,7 +242,7 @@
         // Establish initial conditions
         assertEquals(null, mRegistrar.getDefaultOutgoingPhoneAccount("tel"));
         PhoneAccountHandle h = new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id1");
-        mRegistrar.setDefaultOutgoingPhoneAccount(h);
+        mRegistrar.setUserSelectedOutgoingPhoneAccount(h);
         assertPhoneAccountHandleEquals(h, mRegistrar.getDefaultOutgoingPhoneAccount("tel"));
         // If account is un-registered, querying returns null
         mRegistrar.unregisterPhoneAccount(h);
@@ -251,10 +251,10 @@
         mRegistrar.registerPhoneAccount(makeQuickAccount("pkg0", "cls0", "id1", 99));
         assertPhoneAccountHandleEquals(h, mRegistrar.getDefaultOutgoingPhoneAccount("tel"));
         // De-register by setting to null
-        mRegistrar.setDefaultOutgoingPhoneAccount(null);
+        mRegistrar.setUserSelectedOutgoingPhoneAccount(null);
         assertEquals(null, mRegistrar.getDefaultOutgoingPhoneAccount("tel"));
         // If argument not have CALL_PROVIDER capability, this is a no-op
-        mRegistrar.setDefaultOutgoingPhoneAccount(
+        mRegistrar.setUserSelectedOutgoingPhoneAccount(
                 new PhoneAccountHandle(new ComponentName("pkg0", "cls0"), "id0"));
         assertEquals(null, mRegistrar.getDefaultOutgoingPhoneAccount("tel"));
         // If only have one account, it is the default