Reorganize phone account settings.
+ Added new fragment for phone account settings.
+ Added new activity for phone account settings, which launches this
fragment. I would have prefered to specify a fragment on the
PreferenceScreen in call_feature_setting.xml, but I couldn't get it
to work so I dispatch an intent to start a new activity instead. I
think the preferred option doesn't work because CallFeatureSetting
is still stuck in the old PreferenceActivity model.
+ Added new activity to the manifest file.
+ Moved the default outgoing call, call assistant, and "use SIP
calling settings" into new PhoneAccountSettingsFragment.
- Deleting code for implementing those in CallFeaturesSetting.
+ Added code to AccountSelectionPreference to disable updating of the
summary, and firing and event after the value has been changed when
an account is selected.
Bug: 17487262
Change-Id: I126806ef8e70f8323a7ff143863dacffeb502eaa
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 9daf7c4..d1bb25a 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -34,7 +34,6 @@
import android.database.Cursor;
import android.media.AudioManager;
import android.media.RingtoneManager;
-import android.net.sip.SipManager;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
@@ -63,7 +62,6 @@
import com.android.internal.telephony.PhoneConstants;
import com.android.phone.common.util.SettingsUtil;
import com.android.phone.settings.AccountSelectionPreference;
-import com.android.services.telephony.sip.SipSharedPreferences;
import com.android.services.telephony.sip.SipUtil;
import java.lang.String;
@@ -77,11 +75,10 @@
/**
* Top level "Call settings" UI; see res/xml/call_feature_setting.xml
*
- * This preference screen is the root of the "Call settings" hierarchy
- * available from the Phone app; the settings here let you control various
- * features related to phone calls (including voicemail settings, SIP
- * settings, the "Respond via SMS" feature, and others.) It's used only
- * on voice-capable phone devices.
+ * This preference screen is the root of the "Call settings" hierarchy available from the Phone
+ * app; the settings here let you control various features related to phone calls (including
+ * voicemail settings, the "Respond via SMS" feature, and others.) It's used only on
+ * voice-capable phone devices.
*
* Note that this activity is part of the package com.android.phone, even
* though you reach it from the "Phone" app (i.e. DialtactsActivity) which
@@ -90,17 +87,15 @@
* For the "Mobile network settings" screen under the main Settings app,
* See {@link MobileNetworkSettings}.
*
- * TODO: Settings should be split into PreferenceFragments where possible (ie. voicemail, SIP).
+ * TODO: Settings should be split into PreferenceFragments where possible (ie. voicemail).
*
* @see com.android.phone.MobileNetworkSettings
*/
public class CallFeaturesSetting extends PreferenceActivity
implements DialogInterface.OnClickListener,
Preference.OnPreferenceChangeListener,
- Preference.OnPreferenceClickListener,
EditPhoneNumberPreference.OnDialogClosedListener,
- EditPhoneNumberPreference.GetDefaultNumberListener,
- AccountSelectionPreference.AccountSelectionListener {
+ EditPhoneNumberPreference.GetDefaultNumberListener {
private static final String LOG_TAG = "CallFeaturesSetting";
private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
@@ -184,14 +179,9 @@
private static final String VM_NUMBERS_SHARED_PREFERENCES_NAME = "vm_numbers";
- private static final String BUTTON_SIP_CALL_OPTIONS = "sip_call_options_key";
- private static final String BUTTON_SIP_CALL_OPTIONS_WIFI_ONLY =
- "sip_call_options_wifi_only_key";
- private static final String SIP_SETTINGS_PREFERENCE_SCREEN_KEY =
- "sip_settings_preference_screen_key";
-
private static final String DEFAULT_OUTGOING_ACCOUNT_KEY = "default_outgoing_account";
- private static final String WIFI_CALL_MANAGER_ACCOUNT_KEY = "wifi_call_manager_account";
+ private static final String PHONE_ACCOUNT_SETTINGS_KEY =
+ "phone_account_settings_preference_screen";
private Intent mContactListIntent;
@@ -213,7 +203,6 @@
private Phone mPhone;
private AudioManager mAudioManager;
- private SipManager mSipManager;
private static final int VM_NOCHANGE_ERROR = 400;
private static final int VM_RESPONSE_ERROR = 500;
@@ -260,16 +249,12 @@
private CheckBoxPreference mButtonHAC;
private ListPreference mButtonDTMF;
private ListPreference mButtonTTY;
- private ListPreference mButtonSipCallOptions;
- private Preference mWifiCallOptionsPreference;
- private Preference mWifiCallAccountPreference;
+ private Preference mPhoneAccountSettingsPreference;
private ListPreference mVoicemailProviders;
private PreferenceScreen mVoicemailSettings;
private Preference mVoicemailNotificationRingtone;
private CheckBoxPreference mVoicemailNotificationVibrate;
- private SipSharedPreferences mSipSharedPreferences;
private AccountSelectionPreference mDefaultOutgoingAccount;
- private AccountSelectionPreference mSimCallManagerAccount;
private class VoiceMailProvider {
public VoiceMailProvider(String name, Intent intent) {
@@ -580,50 +565,12 @@
mChangingVMorFwdDueToProviderChange = true;
saveVoiceMailAndForwardingNumber(newProviderKey, newProviderSettings);
}
- } else if (preference == mButtonSipCallOptions) {
- handleSipCallOptionsChange(objValue);
}
// always let the preference setting proceed.
return true;
}
@Override
- public boolean onPreferenceClick(Preference preference) {
- if (preference == mWifiCallOptionsPreference || preference == mWifiCallAccountPreference) {
- handleWifiCallSettingsClick(preference);
- }
- return true;
- }
-
- @Override
- public boolean onAccountSelected(AccountSelectionPreference pref, PhoneAccountHandle account) {
- TelecomManager telecomManager = TelecomManager.from(this);
- if (pref == mDefaultOutgoingAccount) {
- telecomManager.setUserSelectedOutgoingPhoneAccount(account);
- return true;
- } else if (pref == mSimCallManagerAccount) {
- telecomManager.setSimCallManager(account);
- return true;
- }
- return false;
- }
-
- /**
- * Called just prior to showing an AccountSelection dialog to re-populate the model of the
- * AccountSelection dialog.
- *
- * @param pref The account selection preference dialog being shown.
- */
- @Override
- public void onAccountSelectionDialogShow(AccountSelectionPreference pref) {
- if (pref == mDefaultOutgoingAccount) {
- populateDefaultOutgoingAccountsModel();
- } else if (pref == mSimCallManagerAccount) {
- populateSimCallManagerAccountsModel();
- }
- }
-
- @Override
public void onDialogClosed(EditPhoneNumberPreference preference, int buttonClicked) {
if (DBG) log("onPreferenceClick: request preference click on dialog close: " +
buttonClicked);
@@ -1550,14 +1497,6 @@
}
};
- ActionBar actionBar = getActionBar();
- if (actionBar != null) {
- // android.R.id.home will be triggered in onOptionsItemSelected()
- actionBar.setDisplayShowHomeEnabled(true);
- actionBar.setDisplayHomeAsUpEnabled(true);
- actionBar.setDisplayShowTitleEnabled(true);
- }
-
// Show the voicemail preference in onResume if the calling intent specifies the
// ACTION_ADD_VOICEMAIL action.
mShowVoicemailPreference = (icicle == null) &&
@@ -1565,45 +1504,14 @@
}
private void initPhoneAccountPreferences() {
- mDefaultOutgoingAccount = (AccountSelectionPreference)
- findPreference(DEFAULT_OUTGOING_ACCOUNT_KEY);
- mSimCallManagerAccount = (AccountSelectionPreference)
- findPreference(WIFI_CALL_MANAGER_ACCOUNT_KEY);
+ mPhoneAccountSettingsPreference = findPreference(PHONE_ACCOUNT_SETTINGS_KEY);
TelecomManager telecomManager = TelecomManager.from(this);
- int allPhoneAccountsCount = telecomManager.getAllPhoneAccountsCount();
- // Show the phone accounts preference if there are is more than one phone account
- if (allPhoneAccountsCount > 1) {
- populateDefaultOutgoingAccountsModel();
-
- mDefaultOutgoingAccount.setListener(this);
- } else {
- getPreferenceScreen().removePreference(mDefaultOutgoingAccount);
- }
-
- List<PhoneAccountHandle> simCallManagers = telecomManager.getSimCallManagers();
- if (!simCallManagers.isEmpty()) {
- populateSimCallManagerAccountsModel();
- mSimCallManagerAccount.setListener(this);
- } else {
- getPreferenceScreen().removePreference(mSimCallManagerAccount);
- }
- }
-
- private void createSipCallSettings() {
- // Add Internet call settings.
- if (SipUtil.isVoipSupported(this)) {
- mSipManager = SipManager.newInstance(this);
- mSipSharedPreferences = new SipSharedPreferences(this);
- addPreferencesFromResource(
- com.android.services.telephony.sip.R.xml.sip_settings_category);
- mButtonSipCallOptions = getSipCallOptionPreference();
- mButtonSipCallOptions.setOnPreferenceChangeListener(this);
- mButtonSipCallOptions.setValueIndex(
- mButtonSipCallOptions.findIndexOfValue(
- mSipSharedPreferences.getSipCallOption()));
- mButtonSipCallOptions.setSummary(mButtonSipCallOptions.getEntry());
+ if (telecomManager.getAllPhoneAccountsCount() <= 1
+ && telecomManager.getSimCallManagers().isEmpty()
+ && !SipUtil.isVoipSupported(this)) {
+ getPreferenceScreen().removePreference(mPhoneAccountSettingsPreference);
}
}
@@ -1612,24 +1520,6 @@
return pm.resolveActivity(intent, PackageManager.GET_ACTIVITIES) != null;
}
- // Gets the call options for SIP depending on whether SIP is allowed only
- // on Wi-Fi only; also make the other options preference invisible.
- private ListPreference getSipCallOptionPreference() {
- ListPreference wifiAnd3G = (ListPreference)
- findPreference(BUTTON_SIP_CALL_OPTIONS);
- ListPreference wifiOnly = (ListPreference)
- findPreference(BUTTON_SIP_CALL_OPTIONS_WIFI_ONLY);
- PreferenceScreen sipSettings = (PreferenceScreen)
- getPreferenceScreen().findPreference(SIP_SETTINGS_PREFERENCE_SCREEN_KEY);
- if (SipManager.isSipWifiOnly(this)) {
- sipSettings.removePreference(wifiAnd3G);
- return wifiOnly;
- } else {
- sipSettings.removePreference(wifiOnly);
- return wifiAnd3G;
- }
- }
-
@Override
protected void onResume() {
super.onResume();
@@ -1756,19 +1646,13 @@
updateVoiceNumberField();
mVMProviderSettingsForced = false;
- createSipCallSettings();
- if (isAirplaneModeOn()) {
- Preference sipSettings = findPreference(SIP_SETTINGS_PREFERENCE_SCREEN_KEY);
- PreferenceScreen screen = getPreferenceScreen();
- int count = screen.getPreferenceCount();
- for (int i = 0 ; i < count ; ++i) {
- Preference pref = screen.getPreference(i);
- if (pref != sipSettings) pref.setEnabled(false);
- }
- return;
+ if (SipUtil.isVoipSupported(this)) {
+ addPreferencesFromResource(
+ com.android.services.telephony.sip.R.xml.sip_settings_category);
}
+
if (mButtonDTMF != null) {
int dtmf = Settings.System.getInt(getContentResolver(),
Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, Constants.DTMF_TONE_TYPE_NORMAL);
@@ -1860,23 +1744,6 @@
}
}
- private void handleSipCallOptionsChange(Object objValue) {
- String option = objValue.toString();
- mSipSharedPreferences.setSipCallOption(option);
- mButtonSipCallOptions.setValueIndex(
- mButtonSipCallOptions.findIndexOfValue(option));
- mButtonSipCallOptions.setSummary(mButtonSipCallOptions.getEntry());
- }
-
- private void handleWifiCallSettingsClick(Preference preference) {
- Intent intent = preference.getIntent();
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- // TODO - Restrict to a (the?) blessed Wi-Fi calling app.
-
- Bundle noAnimations = ActivityOptions.makeCustomAnimation(this, 0, 0).toBundle();
- startActivity(intent, noAnimations);
- }
-
private void updatePreferredTtyModeSummary(int TtyMode) {
String [] txts = getResources().getStringArray(R.array.tty_mode_entries);
switch(TtyMode) {
@@ -2138,42 +2005,6 @@
}
/**
- * Populates the phone accounts which could potentially be selected as the default.
- */
- private void populateDefaultOutgoingAccountsModel() {
- if (mDefaultOutgoingAccount == null ) {
- return;
- }
-
- TelecomManager telecomManager = TelecomManager.from(this);
- List<PhoneAccountHandle> callCapablePhoneAccounts =
- telecomManager.getCallCapablePhoneAccounts();
- mDefaultOutgoingAccount.setModel(
- telecomManager,
- callCapablePhoneAccounts,
- telecomManager.getUserSelectedOutgoingPhoneAccount(),
- getString(R.string.phone_accounts_ask_every_time));
- }
-
- /**
- * Populates the phone accounts which could potentially be selected as the default sim call
- * manager.
- */
- private void populateSimCallManagerAccountsModel() {
- if (mSimCallManagerAccount == null) {
- return;
- }
-
- TelecomManager telecomManager = TelecomManager.from(this);
- List<PhoneAccountHandle> simCallManagers = telecomManager.getSimCallManagers();
- mSimCallManagerAccount.setModel(
- telecomManager,
- simCallManagers,
- telecomManager.getSimCallManager(),
- getString(R.string.wifi_calling_do_not_use));
- }
-
- /**
* Deletes settings for the specified provider.
*/
private void deleteSettingsForVoicemailProvider(String key) {
diff --git a/src/com/android/phone/settings/AccountSelectionPreference.java b/src/com/android/phone/settings/AccountSelectionPreference.java
index 2995cf4..7d1ede8 100644
--- a/src/com/android/phone/settings/AccountSelectionPreference.java
+++ b/src/com/android/phone/settings/AccountSelectionPreference.java
@@ -38,6 +38,7 @@
public interface AccountSelectionListener {
boolean onAccountSelected(AccountSelectionPreference pref, PhoneAccountHandle account);
void onAccountSelectionDialogShow(AccountSelectionPreference pref);
+ void onAccountChanged(AccountSelectionPreference pref);
}
private final Context mContext;
@@ -45,11 +46,10 @@
private PhoneAccountHandle[] mAccounts;
private String[] mEntryValues;
private CharSequence[] mEntries;
+ private boolean mShowSelectionInSummary = true;
public AccountSelectionPreference(Context context) {
- super(context);
- mContext = context;
- setOnPreferenceChangeListener(this);
+ this(context, null);
}
public AccountSelectionPreference(Context context, AttributeSet attrs) {
@@ -62,6 +62,10 @@
mListener = listener;
}
+ public void setShowSelectionInSummary(boolean value) {
+ mShowSelectionInSummary = value;
+ }
+
public void setModel(
TelecomManager telecomManager,
List<PhoneAccountHandle> accountsList,
@@ -88,7 +92,9 @@
setEntryValues(mEntryValues);
setEntries(mEntries);
setValueIndex(selectedIndex);
- setSummary(mEntries[selectedIndex]);
+ if (mShowSelectionInSummary) {
+ setSummary(mEntries[selectedIndex]);
+ }
}
@Override
@@ -97,7 +103,13 @@
int index = Integer.parseInt((String) newValue);
PhoneAccountHandle account = index < mAccounts.length ? mAccounts[index] : null;
if (mListener.onAccountSelected(this, account)) {
- setSummary(mEntries[index]);
+ if (mShowSelectionInSummary) {
+ setSummary(mEntries[index]);
+ }
+ if (index != findIndexOfValue(getValue())) {
+ setValueIndex(index);
+ mListener.onAccountChanged(this);
+ }
return true;
}
}
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsActivity.java b/src/com/android/phone/settings/PhoneAccountSettingsActivity.java
new file mode 100644
index 0000000..da6a92c
--- /dev/null
+++ b/src/com/android/phone/settings/PhoneAccountSettingsActivity.java
@@ -0,0 +1,49 @@
+/*
+ * 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.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
+ protected void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ getActionBar().setTitle(R.string.phone_account_settings);
+ getFragmentManager().beginTransaction().replace(
+ android.R.id.content, new PhoneAccountSettingsFragment()).commit();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ final int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ onBackPressed();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+}
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
new file mode 100644
index 0000000..fb6365e
--- /dev/null
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -0,0 +1,237 @@
+package com.android.phone.settings;
+
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.net.sip.SipManager;
+import android.net.sip.SipProfile;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceFragment;
+import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
+import android.util.Log;
+
+import com.android.phone.R;
+import com.android.services.telephony.sip.SipSharedPreferences;
+import com.android.services.telephony.sip.SipUtil;
+
+import java.util.List;
+
+public class PhoneAccountSettingsFragment extends PreferenceFragment
+ implements Preference.OnPreferenceChangeListener,
+ Preference.OnPreferenceClickListener,
+ AccountSelectionPreference.AccountSelectionListener {
+
+ private static final Intent CONNECTION_SERVICE_CONFIGURE_INTENT =
+ new Intent(TelecomManager.ACTION_CONNECTION_SERVICE_CONFIGURE)
+ .addCategory(Intent.CATEGORY_DEFAULT);
+
+ private static final String DEFAULT_OUTGOING_ACCOUNT_KEY = "default_outgoing_account";
+
+ private static final String CONFIGURE_CALL_ASSISTANT_PREF_KEY =
+ "wifi_calling_configure_call_assistant_preference";
+ private static final String CALL_ASSISTANT_CATEGORY_PREF_KEY =
+ "phone_accounts_call_assistant_settings_category_key";
+ private static final String SELECT_CALL_ASSISTANT_PREF_KEY =
+ "wifi_calling_call_assistant_preference";
+
+ private static final String SIP_SETTINGS_CATEGORY_PREF_KEY = "phone_accounts_sip_settings_key";
+ private static final String USE_SIP_PREF_KEY = "use_sip_calling_options_key";
+
+ private String LOG_TAG = PhoneAccountSettingsFragment.class.getSimpleName();
+
+ private TelecomManager mTelecomManager;
+
+ private AccountSelectionPreference mDefaultOutgoingAccount;
+ private AccountSelectionPreference mSelectCallAssistant;
+ private Preference mConfigureCallAssistant;
+
+ private ListPreference mUseSipCalling;
+ private SipSharedPreferences mSipSharedPreferences;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ mTelecomManager = TelecomManager.from(getActivity());
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ if (getPreferenceScreen() != null) {
+ getPreferenceScreen().removeAll();
+ }
+
+ addPreferencesFromResource(com.android.phone.R.xml.phone_account_settings);
+
+ if (mTelecomManager.getAllPhoneAccountsCount() > 1) {
+ mDefaultOutgoingAccount = (AccountSelectionPreference)
+ getPreferenceScreen().findPreference(DEFAULT_OUTGOING_ACCOUNT_KEY);
+ mDefaultOutgoingAccount.setListener(this);
+ updateDefaultOutgoingAccountsModel();
+ } else {
+ getPreferenceScreen().removePreference(mDefaultOutgoingAccount);
+ }
+
+ if (!mTelecomManager.getSimCallManagers().isEmpty()) {
+ mSelectCallAssistant = (AccountSelectionPreference)
+ getPreferenceScreen().findPreference(SELECT_CALL_ASSISTANT_PREF_KEY);
+ mSelectCallAssistant.setListener(this);
+ mSelectCallAssistant.setDialogTitle(
+ R.string.wifi_calling_select_call_assistant_summary);
+
+ mConfigureCallAssistant =
+ getPreferenceScreen().findPreference(CONFIGURE_CALL_ASSISTANT_PREF_KEY);
+ mConfigureCallAssistant.setOnPreferenceClickListener(this);
+ updateCallAssistantModel();
+ } else {
+ getPreferenceScreen().removePreference(
+ getPreferenceScreen().findPreference(CALL_ASSISTANT_CATEGORY_PREF_KEY));
+ }
+
+ if (SipUtil.isVoipSupported(getActivity())) {
+ mSipSharedPreferences = new SipSharedPreferences(getActivity());
+
+ mUseSipCalling = (ListPreference)
+ getPreferenceScreen().findPreference(USE_SIP_PREF_KEY);
+ mUseSipCalling.setEntries(!SipManager.isSipWifiOnly(getActivity())
+ ? R.array.sip_call_options_wifi_only_entries
+ : R.array.sip_call_options_entries);
+ mUseSipCalling.setOnPreferenceChangeListener(this);
+ mUseSipCalling.setValueIndex(
+ mUseSipCalling.findIndexOfValue(mSipSharedPreferences.getSipCallOption()));
+ mUseSipCalling.setSummary(mUseSipCalling.getEntry());
+ } else {
+ getPreferenceScreen().removePreference(
+ getPreferenceScreen().findPreference(SIP_SETTINGS_CATEGORY_PREF_KEY));
+ }
+ }
+
+ /**
+ * Handles changes to the preferences, namely the switch which controls whether to use the call
+ * assistant or not.
+ *
+ * @param pref The preference changed.
+ * @param objValue The changed value.
+ * @return True if the preference change has been handled, and false otherwise.
+ */
+ @Override
+ public boolean onPreferenceChange(Preference pref, Object objValue) {
+ if (pref == mUseSipCalling) {
+ String option = objValue.toString();
+ mSipSharedPreferences.setSipCallOption(option);
+ mUseSipCalling.setValueIndex(mUseSipCalling.findIndexOfValue(option));
+ mUseSipCalling.setSummary(mUseSipCalling.getEntry());
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference pref) {
+ if (pref == mConfigureCallAssistant) {
+ try {
+ startActivity(CONNECTION_SERVICE_CONFIGURE_INTENT);
+ } catch (ActivityNotFoundException e) {
+ Log.d(LOG_TAG, "Could not resolve telecom connection service configure intent.");
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Handles a phone account selection, namely when a call assistant has been selected.
+ *
+ * @param pref The account selection preference which triggered the account selected event.
+ * @param account The account selected.
+ * @return True if the account selection has been handled, and false otherwise.
+ */
+ @Override
+ public boolean onAccountSelected(AccountSelectionPreference pref, PhoneAccountHandle account) {
+ if (pref == mDefaultOutgoingAccount) {
+ mTelecomManager.setUserSelectedOutgoingPhoneAccount(account);
+ return true;
+ } else if (pref == mSelectCallAssistant) {
+ mTelecomManager.setSimCallManager(account);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Repopulate the dialog to pick up changes before showing.
+ *
+ * @param pref The account selection preference dialog being shown.
+ */
+ @Override
+ public void onAccountSelectionDialogShow(AccountSelectionPreference pref) {
+ if (pref == mDefaultOutgoingAccount) {
+ updateDefaultOutgoingAccountsModel();
+ } else if (pref == mSelectCallAssistant) {
+ updateCallAssistantModel();
+ }
+ }
+
+ /**
+ * Update the configure preference summary when the call assistant changes.
+ */
+ @Override
+ public void onAccountChanged(AccountSelectionPreference pref) {
+ if (pref == mSelectCallAssistant) {
+ updateConfigureCallAssistantSummary();
+ }
+ }
+
+ /**
+ * Queries the telcomm manager to update the default outgoing account selection preference
+ * with the list of outgoing accounts and the current default outgoing account.
+ */
+ private void updateDefaultOutgoingAccountsModel() {
+ mDefaultOutgoingAccount.setModel(
+ mTelecomManager,
+ mTelecomManager.getCallCapablePhoneAccounts(),
+ mTelecomManager.getUserSelectedOutgoingPhoneAccount(),
+ getString(R.string.phone_accounts_ask_every_time));
+ }
+
+ /**
+ * Queries the telecomm manager to update the account selection preference with the list of
+ * call assistants, and the currently selected call assistant.
+ */
+ public void updateCallAssistantModel() {
+ List<PhoneAccountHandle> simCallManagers = mTelecomManager.getSimCallManagers();
+ mSelectCallAssistant.setModel(
+ mTelecomManager,
+ simCallManagers,
+ mTelecomManager.getSimCallManager(),
+ getString(R.string.wifi_calling_do_not_use_call_assistant));
+
+ updateConfigureCallAssistantSummary();
+ }
+
+ /**
+ * Updates the summary on the "configure call assistant" preference. If it is the last entry,
+ * show the summary for when no call assistant is selected. Otherwise, display the currently
+ * selected call assistant.
+ */
+ private void updateConfigureCallAssistantSummary() {
+ if (mSelectCallAssistant.getEntries().length - 1
+ == mSelectCallAssistant.findIndexOfValue(mSelectCallAssistant.getValue())) {
+ mConfigureCallAssistant.setSummary(
+ R.string.wifi_calling_call_assistant_configure_no_selection);
+ mConfigureCallAssistant.setEnabled(false);
+ } else {
+ mConfigureCallAssistant.setSummary(null);
+ mConfigureCallAssistant.setEnabled(true);
+ }
+ }
+}