[Settings] Apply the SettingsDataService to the SIM page, calls/smscontroller
Calls/SmsDefaultSubscriptionController Bug: 257197354 Test: atest DefaultSubscriptionControllerTest Change-Id: I67cb2d3aa5ef3c6751d90b96db27a062071c8113
This commit is contained in:
@@ -24,11 +24,11 @@ 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 android.view.View;
|
||||
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
@@ -36,8 +36,12 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.SubscriptionUtil;
|
||||
import com.android.settings.network.SubscriptionsChangeListener;
|
||||
import com.android.settings.network.MobileNetworkRepository;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.mobile.dataservice.DataServiceUtils;
|
||||
import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity;
|
||||
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||
import com.android.settingslib.mobile.dataservice.UiccInfoEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -49,13 +53,14 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class DefaultSubscriptionController extends TelephonyBasePreferenceController
|
||||
implements LifecycleObserver, Preference.OnPreferenceChangeListener,
|
||||
SubscriptionsChangeListener.SubscriptionsChangeListenerClient {
|
||||
MobileNetworkRepository.MobileNetworkCallback {
|
||||
private static final String TAG = "DefaultSubController";
|
||||
|
||||
protected SubscriptionsChangeListener mChangeListener;
|
||||
protected ListPreference mPreference;
|
||||
protected SubscriptionManager mManager;
|
||||
protected TelecomManager mTelecomManager;
|
||||
protected MobileNetworkRepository mMobileNetworkRepository;
|
||||
protected LifecycleOwner mLifecycleOwner;
|
||||
|
||||
private static final String EMERGENCY_ACCOUNT_HANDLE_ID = "E";
|
||||
private static final ComponentName PSTN_CONNECTION_SERVICE_COMPONENT =
|
||||
@@ -63,17 +68,24 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
"com.android.services.telephony.TelephonyConnectionService");
|
||||
private boolean mIsRtlMode;
|
||||
|
||||
public DefaultSubscriptionController(Context context, String preferenceKey) {
|
||||
List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
|
||||
|
||||
public DefaultSubscriptionController(Context context, String preferenceKey, Lifecycle lifecycle,
|
||||
LifecycleOwner lifecycleOwner) {
|
||||
super(context, preferenceKey);
|
||||
mManager = context.getSystemService(SubscriptionManager.class);
|
||||
mChangeListener = new SubscriptionsChangeListener(context, this);
|
||||
mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
|
||||
== View.LAYOUT_DIRECTION_RTL;
|
||||
mMobileNetworkRepository = MobileNetworkRepository.create(context, this);
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return SubscriptionInfo for the default subscription for the service, or null if there
|
||||
* isn't one. */
|
||||
protected abstract SubscriptionInfo getDefaultSubscriptionInfo();
|
||||
protected abstract SubscriptionInfoEntity getDefaultSubscriptionInfo();
|
||||
|
||||
/** @return the id of the default subscription for the service, or
|
||||
* SubscriptionManager.INVALID_SUBSCRIPTION_ID if there isn't one. */
|
||||
@@ -93,13 +105,13 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
|
||||
@OnLifecycleEvent(ON_RESUME)
|
||||
public void onResume() {
|
||||
mChangeListener.start();
|
||||
mMobileNetworkRepository.addRegister(mLifecycleOwner);
|
||||
updateEntries();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_PAUSE)
|
||||
public void onPause() {
|
||||
mChangeListener.stop();
|
||||
mMobileNetworkRepository.removeRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -126,10 +138,10 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
// display VoIP account in summary when configured through settings within dialer
|
||||
return getLabelFromCallingAccount(handle);
|
||||
}
|
||||
final SubscriptionInfo info = getDefaultSubscriptionInfo();
|
||||
final SubscriptionInfoEntity info = getDefaultSubscriptionInfo();
|
||||
if (info != null) {
|
||||
// display subscription based account
|
||||
return SubscriptionUtil.getUniqueSubscriptionDisplayName(info, mContext);
|
||||
return info.uniqueName;
|
||||
} else {
|
||||
if (isAskEverytimeSupported()) {
|
||||
return mContext.getString(R.string.calls_and_sms_ask_every_time);
|
||||
@@ -139,7 +151,8 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEntries() {
|
||||
@VisibleForTesting
|
||||
void updateEntries() {
|
||||
if (mPreference == null) {
|
||||
return;
|
||||
}
|
||||
@@ -154,30 +167,28 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
// getAvailabilityStatus returned CONDITIONALLY_UNAVAILABLE at the time.
|
||||
mPreference.setOnPreferenceChangeListener(this);
|
||||
|
||||
final List<SubscriptionInfo> subs = SubscriptionUtil.getActiveSubscriptions(mManager);
|
||||
|
||||
// We'll have one entry for each available subscription, plus one for a "ask me every
|
||||
// time" entry at the end.
|
||||
final ArrayList<CharSequence> displayNames = new ArrayList<>();
|
||||
final ArrayList<CharSequence> subscriptionIds = new ArrayList<>();
|
||||
List<SubscriptionInfoEntity> list = getSubscriptionInfoList();
|
||||
|
||||
if (subs.size() == 1) {
|
||||
if (list.size() == 1) {
|
||||
mPreference.setEnabled(false);
|
||||
mPreference.setSummaryProvider(pref ->
|
||||
SubscriptionUtil.getUniqueSubscriptionDisplayName(subs.get(0), mContext));
|
||||
mPreference.setSummaryProvider(pref -> list.get(0).uniqueName);
|
||||
return;
|
||||
}
|
||||
|
||||
final int serviceDefaultSubId = getDefaultSubscriptionId();
|
||||
boolean subIsAvailable = false;
|
||||
|
||||
for (SubscriptionInfo sub : subs) {
|
||||
if (sub.isOpportunistic()) {
|
||||
for (SubscriptionInfoEntity sub : list) {
|
||||
if (sub.isOpportunistic) {
|
||||
continue;
|
||||
}
|
||||
displayNames.add(SubscriptionUtil.getUniqueSubscriptionDisplayName(sub, mContext));
|
||||
final int subId = sub.getSubscriptionId();
|
||||
subscriptionIds.add(Integer.toString(subId));
|
||||
displayNames.add(sub.uniqueName);
|
||||
final int subId = Integer.parseInt(sub.subId);
|
||||
subscriptionIds.add(sub.subId);
|
||||
if (subId == serviceDefaultSubId) {
|
||||
subIsAvailable = true;
|
||||
}
|
||||
@@ -270,6 +281,11 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
return (label != null) ? label : "";
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected List<SubscriptionInfoEntity> getSubscriptionInfoList() {
|
||||
return mSubInfoEntityList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final int subscriptionId = Integer.parseInt((String) newValue);
|
||||
@@ -282,15 +298,29 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
|
||||
}
|
||||
|
||||
boolean isRtlMode() {
|
||||
return mIsRtlMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscriptionsChanged() {
|
||||
if (mPreference != null) {
|
||||
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActiveSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||
if (DataServiceUtils.shouldUpdateEntityList(mSubInfoEntityList, subInfoEntityList)) {
|
||||
mSubInfoEntityList = subInfoEntityList;
|
||||
updateEntries();
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isRtlMode() {
|
||||
return mIsRtlMode;
|
||||
@Override
|
||||
public void onAllUiccInfoChanged(List<UiccInfoEntity> uiccInfoEntityList) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAllMobileNetworkInfoChanged(
|
||||
List<MobileNetworkInfoEntity> mobileNetworkInfoEntityList) {
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user