Merge "[Settings] Sync summary of call preference with dialer"
This commit is contained in:
@@ -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_PAUSE;
|
||||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.telecom.PhoneAccount;
|
||||||
|
import android.telecom.PhoneAccountHandle;
|
||||||
|
import android.telecom.TelecomManager;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
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.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.network.SubscriptionUtil;
|
import com.android.settings.network.SubscriptionUtil;
|
||||||
@@ -31,13 +42,6 @@ import com.android.settings.network.SubscriptionsChangeListener;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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
|
* 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
|
* what mobile network subscription is used by default for some service controlled by the
|
||||||
@@ -51,10 +55,17 @@ public abstract class DefaultSubscriptionController extends BasePreferenceContro
|
|||||||
protected SubscriptionsChangeListener mChangeListener;
|
protected SubscriptionsChangeListener mChangeListener;
|
||||||
protected ListPreference mPreference;
|
protected ListPreference mPreference;
|
||||||
protected SubscriptionManager mManager;
|
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) {
|
public DefaultSubscriptionController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
mManager = context.getSystemService(SubscriptionManager.class);
|
mManager = context.getSystemService(SubscriptionManager.class);
|
||||||
|
mTelecomManager = mContext.getSystemService(TelecomManager.class);
|
||||||
mChangeListener = new SubscriptionsChangeListener(context, this);
|
mChangeListener = new SubscriptionsChangeListener(context, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +114,14 @@ public abstract class DefaultSubscriptionController extends BasePreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
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();
|
final SubscriptionInfo info = getDefaultSubscriptionInfo();
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
|
// display subscription based account
|
||||||
return info.getDisplayName();
|
return info.getDisplayName();
|
||||||
} else {
|
} else {
|
||||||
return mContext.getString(R.string.calls_and_sms_ask_every_time);
|
return mContext.getString(R.string.calls_and_sms_ask_every_time);
|
||||||
@@ -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
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final int subscriptionId = Integer.parseInt((String) newValue);
|
final int subscriptionId = Integer.parseInt((String) newValue);
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.network.telephony;
|
package com.android.settings.network.telephony;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.telecom.PhoneAccountHandle;
|
||||||
import android.telephony.SubscriptionInfo;
|
import android.telephony.SubscriptionInfo;
|
||||||
import android.telephony.SubscriptionManager;
|
import android.telephony.SubscriptionManager;
|
||||||
|
|
||||||
@@ -40,4 +41,10 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl
|
|||||||
protected void setDefaultSubscription(int subscriptionId) {
|
protected void setDefaultSubscription(int subscriptionId) {
|
||||||
mManager.setDefaultSmsSubId(subscriptionId);
|
mManager.setDefaultSmsSubId(subscriptionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PhoneAccountHandle getDefaultCallingAccountHandle() {
|
||||||
|
// Not supporting calling account override by VoIP
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user