Loading src/com/android/settings/network/telephony/DefaultSubscriptionController.java +74 −7 Original line number Diff line number Diff line Loading @@ -19,10 +19,21 @@ package com.android.settings.network.telephony; import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE; import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; import android.content.ComponentName; import android.content.Context; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settings.network.SubscriptionUtil; Loading @@ -31,13 +42,6 @@ import com.android.settings.network.SubscriptionsChangeListener; import java.util.ArrayList; import java.util.List; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; /** * This implements common controller functionality for a Preference letting the user see/change * what mobile network subscription is used by default for some service controlled by the Loading @@ -51,10 +55,17 @@ public abstract class DefaultSubscriptionController extends BasePreferenceContro protected SubscriptionsChangeListener mChangeListener; protected ListPreference mPreference; protected SubscriptionManager mManager; protected TelecomManager mTelecomManager; private static final String EMERGENCY_ACCOUNT_HANDLE_ID = "E"; private static final ComponentName PSTN_CONNECTION_SERVICE_COMPONENT = new ComponentName("com.android.phone", "com.android.services.telephony.TelephonyConnectionService"); public DefaultSubscriptionController(Context context, String preferenceKey) { super(context, preferenceKey); mManager = context.getSystemService(SubscriptionManager.class); mTelecomManager = mContext.getSystemService(TelecomManager.class); mChangeListener = new SubscriptionsChangeListener(context, this); } Loading Loading @@ -103,8 +114,14 @@ public abstract class DefaultSubscriptionController extends BasePreferenceContro @Override public CharSequence getSummary() { final PhoneAccountHandle handle = getDefaultCallingAccountHandle(); if ((handle != null) && (!isCallingAccountBindToSubscription(handle))) { // display VoIP account in summary when configured through settings within dialer return getLabelFromCallingAccount(handle); } final SubscriptionInfo info = getDefaultSubscriptionInfo(); if (info != null) { // display subscription based account return info.getDisplayName(); } else { return mContext.getString(R.string.calls_and_sms_ask_every_time); Loading Loading @@ -161,6 +178,56 @@ public abstract class DefaultSubscriptionController extends BasePreferenceContro } } /** * Get default calling account * * @return current calling account {@link PhoneAccountHandle} */ public PhoneAccountHandle getDefaultCallingAccountHandle() { final PhoneAccountHandle currentSelectPhoneAccount = mTelecomManager.getUserSelectedOutgoingPhoneAccount(); if (currentSelectPhoneAccount == null) { return null; } final List<PhoneAccountHandle> accountHandles = mTelecomManager.getCallCapablePhoneAccounts(false); final PhoneAccountHandle emergencyAccountHandle = new PhoneAccountHandle( PSTN_CONNECTION_SERVICE_COMPONENT, EMERGENCY_ACCOUNT_HANDLE_ID); if (currentSelectPhoneAccount.equals(emergencyAccountHandle)) { return null; } for (PhoneAccountHandle handle : accountHandles) { if (currentSelectPhoneAccount.equals(handle)) { return currentSelectPhoneAccount; } } return null; } /** * Check if calling account bind to subscription * * @param handle {@link PhoneAccountHandle} for specific calling account */ public boolean isCallingAccountBindToSubscription(PhoneAccountHandle handle) { return mTelecomManager.getPhoneAccount(handle) .hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION); } /** * Get label from calling account * * @param handle to get label from {@link PhoneAccountHandle} * @return label of calling account */ public CharSequence getLabelFromCallingAccount(PhoneAccountHandle handle) { CharSequence label = mTelecomManager.getPhoneAccount(handle).getLabel(); if (label != null) { label = mContext.getPackageManager().getUserBadgedLabel(label, handle.getUserHandle()); } return (label != null) ? label : ""; } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final int subscriptionId = Integer.parseInt((String) newValue); Loading src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java +7 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.network.telephony; import android.content.Context; import android.telecom.PhoneAccountHandle; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; Loading @@ -40,4 +41,10 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl protected void setDefaultSubscription(int subscriptionId) { mManager.setDefaultSmsSubId(subscriptionId); } @Override public PhoneAccountHandle getDefaultCallingAccountHandle() { // Not supporting calling account override by VoIP return null; } } Loading
src/com/android/settings/network/telephony/DefaultSubscriptionController.java +74 −7 Original line number Diff line number Diff line Loading @@ -19,10 +19,21 @@ package com.android.settings.network.telephony; import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE; import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; import android.content.ComponentName; import android.content.Context; import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.BasePreferenceController; import com.android.settings.network.SubscriptionUtil; Loading @@ -31,13 +42,6 @@ import com.android.settings.network.SubscriptionsChangeListener; import java.util.ArrayList; import java.util.List; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; /** * This implements common controller functionality for a Preference letting the user see/change * what mobile network subscription is used by default for some service controlled by the Loading @@ -51,10 +55,17 @@ public abstract class DefaultSubscriptionController extends BasePreferenceContro protected SubscriptionsChangeListener mChangeListener; protected ListPreference mPreference; protected SubscriptionManager mManager; protected TelecomManager mTelecomManager; private static final String EMERGENCY_ACCOUNT_HANDLE_ID = "E"; private static final ComponentName PSTN_CONNECTION_SERVICE_COMPONENT = new ComponentName("com.android.phone", "com.android.services.telephony.TelephonyConnectionService"); public DefaultSubscriptionController(Context context, String preferenceKey) { super(context, preferenceKey); mManager = context.getSystemService(SubscriptionManager.class); mTelecomManager = mContext.getSystemService(TelecomManager.class); mChangeListener = new SubscriptionsChangeListener(context, this); } Loading Loading @@ -103,8 +114,14 @@ public abstract class DefaultSubscriptionController extends BasePreferenceContro @Override public CharSequence getSummary() { final PhoneAccountHandle handle = getDefaultCallingAccountHandle(); if ((handle != null) && (!isCallingAccountBindToSubscription(handle))) { // display VoIP account in summary when configured through settings within dialer return getLabelFromCallingAccount(handle); } final SubscriptionInfo info = getDefaultSubscriptionInfo(); if (info != null) { // display subscription based account return info.getDisplayName(); } else { return mContext.getString(R.string.calls_and_sms_ask_every_time); Loading Loading @@ -161,6 +178,56 @@ public abstract class DefaultSubscriptionController extends BasePreferenceContro } } /** * Get default calling account * * @return current calling account {@link PhoneAccountHandle} */ public PhoneAccountHandle getDefaultCallingAccountHandle() { final PhoneAccountHandle currentSelectPhoneAccount = mTelecomManager.getUserSelectedOutgoingPhoneAccount(); if (currentSelectPhoneAccount == null) { return null; } final List<PhoneAccountHandle> accountHandles = mTelecomManager.getCallCapablePhoneAccounts(false); final PhoneAccountHandle emergencyAccountHandle = new PhoneAccountHandle( PSTN_CONNECTION_SERVICE_COMPONENT, EMERGENCY_ACCOUNT_HANDLE_ID); if (currentSelectPhoneAccount.equals(emergencyAccountHandle)) { return null; } for (PhoneAccountHandle handle : accountHandles) { if (currentSelectPhoneAccount.equals(handle)) { return currentSelectPhoneAccount; } } return null; } /** * Check if calling account bind to subscription * * @param handle {@link PhoneAccountHandle} for specific calling account */ public boolean isCallingAccountBindToSubscription(PhoneAccountHandle handle) { return mTelecomManager.getPhoneAccount(handle) .hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION); } /** * Get label from calling account * * @param handle to get label from {@link PhoneAccountHandle} * @return label of calling account */ public CharSequence getLabelFromCallingAccount(PhoneAccountHandle handle) { CharSequence label = mTelecomManager.getPhoneAccount(handle).getLabel(); if (label != null) { label = mContext.getPackageManager().getUserBadgedLabel(label, handle.getUserHandle()); } return (label != null) ? label : ""; } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final int subscriptionId = Integer.parseInt((String) newValue); Loading
src/com/android/settings/network/telephony/SmsDefaultSubscriptionController.java +7 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.network.telephony; import android.content.Context; import android.telecom.PhoneAccountHandle; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; Loading @@ -40,4 +41,10 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl protected void setDefaultSubscription(int subscriptionId) { mManager.setDefaultSmsSubId(subscriptionId); } @Override public PhoneAccountHandle getDefaultCallingAccountHandle() { // Not supporting calling account override by VoIP return null; } }