Merge changes I07d964b9,Ifa5928e1 into udc-dev

* changes:
  Fix flicker in SIM card page
  Clean up DefaultSubscriptionController.getSummary
This commit is contained in:
Chaohui Wang
2023-05-09 09:02:19 +00:00
committed by Android (Google) Code Review
4 changed files with 74 additions and 196 deletions

View File

@@ -26,25 +26,17 @@ import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
public class CallsDefaultSubscriptionController extends DefaultSubscriptionController {
private SubscriptionInfoEntity mSubscriptionInfoEntity;
public CallsDefaultSubscriptionController(Context context, String preferenceKey,
Lifecycle lifecycle, LifecycleOwner lifecycleOwner) {
super(context, preferenceKey, lifecycle, lifecycleOwner);
}
@Override
protected SubscriptionInfoEntity getDefaultSubscriptionInfo() {
return mSubscriptionInfoEntity;
}
@Override
protected int getDefaultSubscriptionId() {
int defaultCallSubId = SubscriptionManager.getDefaultVoiceSubscriptionId();
for (SubscriptionInfoEntity subInfo : mSubInfoEntityList) {
int subId = subInfo.getSubId();
if (subInfo.isActiveSubscriptionId && subId == defaultCallSubId) {
mSubscriptionInfoEntity = subInfo;
return subId;
}
}

View File

@@ -19,11 +19,7 @@ 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.SubscriptionManager;
import android.view.View;
@@ -57,15 +53,10 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
protected ListPreference mPreference;
protected SubscriptionManager mManager;
protected TelecomManager mTelecomManager;
protected MobileNetworkRepository mMobileNetworkRepository;
protected LifecycleOwner mLifecycleOwner;
private DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
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");
private boolean mIsRtlMode;
List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
@@ -84,10 +75,6 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
}
}
/** @return SubscriptionInfo for the default subscription for the service, or null if there
* isn't one. */
protected abstract SubscriptionInfoEntity getDefaultSubscriptionInfo();
/** @return the id of the default subscription for the service, or
* SubscriptionManager.INVALID_SUBSCRIPTION_ID if there isn't one. */
protected abstract int getDefaultSubscriptionId();
@@ -125,6 +112,8 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
// Set a summary placeholder to reduce flicker.
mPreference.setSummaryProvider(pref -> mContext.getString(R.string.summary_placeholder));
updateEntries();
}
@@ -133,31 +122,11 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
// Currently, cannot use ListPreference.setSummary() when the summary contains user
// generated string, because ListPreference.getSummary() is using String.format() to format
// the summary when the summary is set by ListPreference.setSummary().
if (preference != null) {
if (preference != null && !mSubInfoEntityList.isEmpty()) {
preference.setSummaryProvider(pref -> getSummary());
}
}
@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 SubscriptionInfoEntity info = getDefaultSubscriptionInfo();
if (info != null) {
// display subscription based account
return info.uniqueName;
} else {
if (isAskEverytimeSupported()) {
return mContext.getString(R.string.calls_and_sms_ask_every_time);
} else {
return "";
}
}
}
@VisibleForTesting
void updateEntries() {
if (mPreference == null) {
@@ -179,6 +148,7 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
final ArrayList<CharSequence> displayNames = new ArrayList<>();
final ArrayList<CharSequence> subscriptionIds = new ArrayList<>();
List<SubscriptionInfoEntity> list = getSubscriptionInfoList();
if (list.isEmpty()) return;
if (list.size() == 1) {
mPreference.setEnabled(false);
@@ -218,76 +188,6 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
}
}
/**
* Get default calling account
*
* @return current calling account {@link PhoneAccountHandle}
*/
public PhoneAccountHandle getDefaultCallingAccountHandle() {
final PhoneAccountHandle currentSelectPhoneAccount =
getTelecomManager().getUserSelectedOutgoingPhoneAccount();
if (currentSelectPhoneAccount == null) {
return null;
}
final List<PhoneAccountHandle> accountHandles =
getTelecomManager().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;
}
@VisibleForTesting
TelecomManager getTelecomManager() {
if (mTelecomManager == null) {
mTelecomManager = mContext.getSystemService(TelecomManager.class);
}
return mTelecomManager;
}
@VisibleForTesting
PhoneAccount getPhoneAccount(PhoneAccountHandle handle) {
return getTelecomManager().getPhoneAccount(handle);
}
/**
* Check if calling account bind to subscription
*
* @param handle {@link PhoneAccountHandle} for specific calling account
*/
public boolean isCallingAccountBindToSubscription(PhoneAccountHandle handle) {
final PhoneAccount account = getPhoneAccount(handle);
if (account == null) {
return false;
}
return account.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 = null;
final PhoneAccount account = getPhoneAccount(handle);
if (account != null) {
label = account.getLabel();
}
if (label != null) {
label = mContext.getPackageManager().getUserBadgedLabel(label, handle.getUserHandle());
}
return (label != null) ? label : "";
}
@VisibleForTesting
protected List<SubscriptionInfoEntity> getSubscriptionInfoList() {
return mSubInfoEntityList;

View File

@@ -17,7 +17,6 @@
package com.android.settings.network.telephony;
import android.content.Context;
import android.telecom.PhoneAccountHandle;
import android.telephony.SubscriptionManager;
import androidx.lifecycle.LifecycleOwner;
@@ -28,7 +27,6 @@ import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
public class SmsDefaultSubscriptionController extends DefaultSubscriptionController {
private final boolean mIsAskEverytimeSupported;
private SubscriptionInfoEntity mSubscriptionInfoEntity;
public SmsDefaultSubscriptionController(Context context, String preferenceKey,
Lifecycle lifecycle, LifecycleOwner lifecycleOwner) {
@@ -37,18 +35,12 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl
.getBoolean(com.android.internal.R.bool.config_sms_ask_every_time_support);
}
@Override
protected SubscriptionInfoEntity getDefaultSubscriptionInfo() {
return mSubscriptionInfoEntity;
}
@Override
protected int getDefaultSubscriptionId() {
int defaultSmsSubId = SubscriptionManager.getDefaultSmsSubscriptionId();
for (SubscriptionInfoEntity subInfo : mSubInfoEntityList) {
int subId = subInfo.getSubId();
if (subInfo.isActiveSubscriptionId && subId == defaultSmsSubId) {
mSubscriptionInfoEntity = subInfo;
return subId;
}
}
@@ -65,12 +57,6 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl
return mIsAskEverytimeSupported;
}
@Override
public PhoneAccountHandle getDefaultCallingAccountHandle() {
// Not supporting calling account override by VoIP
return null;
}
@Override
public CharSequence getSummary() {
return MobileNetworkUtils.getPreferredStatus(isRtlMode(), mContext, false,