Merge "[Settings] Remove the intent receiver due to the register exception" into udc-dev
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.android.settings.network;
|
||||
|
||||
import static com.android.internal.telephony.TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
public class DefaultSubscriptionReceiver extends BroadcastReceiver {
|
||||
|
||||
private Context mContext;
|
||||
private DefaultSubscriptionListener mListener;
|
||||
|
||||
public DefaultSubscriptionReceiver(Context context, DefaultSubscriptionListener listener) {
|
||||
mContext = context;
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void registerReceiver() {
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
|
||||
filter.addAction(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
|
||||
filter.addAction(ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED);
|
||||
filter.addAction(SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED);
|
||||
mContext.registerReceiver(this, filter);
|
||||
}
|
||||
|
||||
public void unRegisterReceiver() {
|
||||
mContext.unregisterReceiver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED.equals(action)) {
|
||||
mListener.onDefaultDataChanged(SubscriptionManager.getDefaultDataSubscriptionId());
|
||||
} else if (SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED.equals(action)) {
|
||||
mListener.onDefaultSubInfoChanged(SubscriptionManager.getDefaultSubscriptionId());
|
||||
} else if (TelephonyManager.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED.equals(action)) {
|
||||
mListener.onDefaultVoiceChanged(SubscriptionManager.getDefaultVoiceSubscriptionId());
|
||||
} else if (SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED.equals(action)) {
|
||||
mListener.onDefaultSmsChanged(SubscriptionManager.getDefaultSmsSubscriptionId());
|
||||
}
|
||||
}
|
||||
|
||||
public interface DefaultSubscriptionListener {
|
||||
default void onDefaultSubInfoChanged(int defaultSubId) {
|
||||
}
|
||||
default void onDefaultDataChanged(int defaultDataSubId) {
|
||||
}
|
||||
default void onDefaultVoiceChanged(int defaultVoiceSubId) {
|
||||
}
|
||||
default void onDefaultSmsChanged(int defaultSmsSubId) {
|
||||
}
|
||||
}
|
||||
}
|
@@ -27,9 +27,7 @@ import static com.android.settings.network.InternetUpdater.INTERNET_WIFI;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -45,9 +43,7 @@ import com.android.settings.widget.SummaryUpdater;
|
||||
import com.android.settings.wifi.WifiSummaryUpdater;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity;
|
||||
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||
import com.android.settingslib.mobile.dataservice.UiccInfoEntity;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -60,7 +56,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class InternetPreferenceController extends AbstractPreferenceController implements
|
||||
LifecycleObserver, SummaryUpdater.OnSummaryChangeListener,
|
||||
InternetUpdater.InternetChangeListener, MobileNetworkRepository.MobileNetworkCallback {
|
||||
InternetUpdater.InternetChangeListener, MobileNetworkRepository.MobileNetworkCallback,
|
||||
DefaultSubscriptionReceiver.DefaultSubscriptionListener {
|
||||
|
||||
public static final String KEY = "internet_settings";
|
||||
|
||||
@@ -71,6 +68,8 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private MobileNetworkRepository mMobileNetworkRepository;
|
||||
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
|
||||
private int mDefaultDataSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
private DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
|
||||
|
||||
@VisibleForTesting
|
||||
static Map<Integer, Integer> sIconMap = new HashMap<>();
|
||||
@@ -102,6 +101,7 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
mInternetType = mInternetUpdater.getInternetType();
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
|
||||
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
@@ -160,6 +160,8 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mMobileNetworkRepository.updateEntity();
|
||||
mSummaryHelper.register(true);
|
||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
||||
mDefaultDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
|
||||
}
|
||||
|
||||
/** @OnLifecycleEvent(ON_PAUSE) */
|
||||
@@ -167,6 +169,7 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
public void onPause() {
|
||||
mMobileNetworkRepository.removeRegister(this);
|
||||
mSummaryHelper.register(false);
|
||||
mDataSubscriptionChangedReceiver.unRegisterReceiver();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,11 +215,11 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
if (subInfo.isActiveDataSubscriptionId) {
|
||||
activeSubInfo = subInfo;
|
||||
}
|
||||
if (subInfo.isDefaultDataSubscription) {
|
||||
if (subInfo.getSubId() == getDefaultDataSubscriptionId()) {
|
||||
defaultSubInfo = subInfo;
|
||||
}
|
||||
}
|
||||
if (activeSubInfo == null) {
|
||||
if (activeSubInfo == null || defaultSubInfo == null) {
|
||||
return;
|
||||
}
|
||||
activeSubInfo = activeSubInfo.isSubscriptionVisible ? activeSubInfo : defaultSubInfo;
|
||||
@@ -237,9 +240,20 @@ public class InternetPreferenceController extends AbstractPreferenceController i
|
||||
return mSubInfoEntityList;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getDefaultDataSubscriptionId() {
|
||||
return mDefaultDataSubId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||
mSubInfoEntityList = subInfoEntityList;
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefaultDataChanged(int defaultDataSubId) {
|
||||
mDefaultDataSubId = defaultDataSubId;
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
|
@@ -18,14 +18,9 @@ package com.android.settings.network;
|
||||
import static android.telephony.SubscriptionManager.PROFILE_CLASS_PROVISIONING;
|
||||
import static android.telephony.UiccSlotInfo.CARD_STATE_INFO_PRESENT;
|
||||
|
||||
import static com.android.internal.telephony.TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
@@ -99,7 +94,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
private AirplaneModeObserver mAirplaneModeObserver;
|
||||
private Uri mAirplaneModeSettingUri;
|
||||
private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private IntentFilter mFilter = new IntentFilter();
|
||||
private Map<Integer, MobileDataContentObserver> mDataContentObserverMap = new HashMap<>();
|
||||
private int mPhysicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||
private int mLogicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
|
||||
@@ -112,12 +106,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
private Map<Integer, SubscriptionInfo> mSubscriptionInfoMap = new ArrayMap<>();
|
||||
private Map<Integer, TelephonyManager> mTelephonyManagerMap = new HashMap<>();
|
||||
private Map<Integer, PhoneCallStateTelephonyCallback> mTelephonyCallbackMap = new HashMap<>();
|
||||
private BroadcastReceiver mDataSubscriptionChangedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
onSubscriptionsChanged();
|
||||
}
|
||||
};
|
||||
|
||||
@NonNull
|
||||
public static MobileNetworkRepository getInstance(Context context) {
|
||||
synchronized (sInstanceLock) {
|
||||
@@ -143,10 +132,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
mMobileNetworkInfoDao = mMobileNetworkDatabase.mMobileNetworkInfoDao();
|
||||
mAirplaneModeObserver = new AirplaneModeObserver(new Handler(Looper.getMainLooper()));
|
||||
mAirplaneModeSettingUri = Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON);
|
||||
mFilter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
|
||||
mFilter.addAction(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED);
|
||||
mFilter.addAction(ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED);
|
||||
mFilter.addAction(SubscriptionManager.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED);
|
||||
}
|
||||
|
||||
private class AirplaneModeObserver extends ContentObserver {
|
||||
@@ -188,7 +173,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(),
|
||||
this);
|
||||
mAirplaneModeObserver.register(mContext);
|
||||
mContext.registerReceiver(mDataSubscriptionChangedReceiver, mFilter);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "addRegister done");
|
||||
}
|
||||
@@ -271,7 +255,6 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
if (sCallbacks.isEmpty()) {
|
||||
mSubscriptionManager.removeOnSubscriptionsChangedListener(this);
|
||||
mAirplaneModeObserver.unRegister(mContext);
|
||||
mContext.unregisterReceiver(mDataSubscriptionChangedReceiver);
|
||||
mDataContentObserverMap.forEach((id, observer) -> {
|
||||
observer.unRegister(mContext);
|
||||
});
|
||||
@@ -524,16 +507,11 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
|
||||
SubscriptionUtil.getFormattedPhoneNumber(context, subInfo),
|
||||
firstRemovableSubInfo == null ? false
|
||||
: firstRemovableSubInfo.getSubscriptionId() == subId,
|
||||
String.valueOf(SubscriptionUtil.getDefaultSimConfig(context, subId)),
|
||||
SubscriptionUtil.isDefaultSubscription(context, subId),
|
||||
mSubscriptionManager.isValidSubscriptionId(subId),
|
||||
mSubscriptionManager.isUsableSubscriptionId(subId),
|
||||
mSubscriptionManager.isActiveSubscriptionId(subId),
|
||||
true /*availableSubInfo*/,
|
||||
mSubscriptionManager.getDefaultVoiceSubscriptionId() == subId,
|
||||
mSubscriptionManager.getDefaultSmsSubscriptionId() == subId,
|
||||
mSubscriptionManager.getDefaultDataSubscriptionId() == subId,
|
||||
mSubscriptionManager.getDefaultSubscriptionId() == subId,
|
||||
mSubscriptionManager.getActiveDataSubscriptionId() == subId);
|
||||
}
|
||||
}
|
||||
|
@@ -38,14 +38,13 @@ import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity;
|
||||
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||
import com.android.settingslib.mobile.dataservice.UiccInfoEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkProviderCallsSmsController extends AbstractPreferenceController implements
|
||||
LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback {
|
||||
LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback,
|
||||
DefaultSubscriptionReceiver.DefaultSubscriptionListener {
|
||||
|
||||
private static final String TAG = "NetworkProviderCallsSmsController";
|
||||
private static final String KEY = "calls_and_sms";
|
||||
@@ -58,6 +57,9 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private MobileNetworkRepository mMobileNetworkRepository;
|
||||
private List<SubscriptionInfoEntity> mSubInfoEntityList;
|
||||
private int mDefaultVoiceSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
private int mDefaultSmsSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
private DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
|
||||
|
||||
/**
|
||||
* The summary text and click behavior of the "Calls & SMS" item on the
|
||||
@@ -73,6 +75,7 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
== View.LAYOUT_DIRECTION_RTL;
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
|
||||
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
@@ -83,11 +86,15 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mMobileNetworkRepository.updateEntity();
|
||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
||||
mDefaultVoiceSubId = SubscriptionManager.getDefaultVoiceSubscriptionId();
|
||||
mDefaultSmsSubId = SubscriptionManager.getDefaultSmsSubscriptionId();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Event.ON_PAUSE)
|
||||
public void onPause() {
|
||||
mMobileNetworkRepository.removeRegister(this);
|
||||
mDataSubscriptionChangedReceiver.unRegisterReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,16 +152,16 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
protected CharSequence getPreferredStatus(SubscriptionInfoEntity subInfo, int subsSize,
|
||||
int subId) {
|
||||
String status = "";
|
||||
boolean isDataPreferred = subInfo.isDefaultVoiceSubscription;
|
||||
boolean isSmsPreferred = subInfo.isDefaultSmsSubscription;
|
||||
boolean isCallPreferred = subInfo.getSubId() == getDefaultVoiceSubscriptionId();
|
||||
boolean isSmsPreferred = subInfo.getSubId() == getDefaultSmsSubscriptionId();
|
||||
|
||||
if (!subInfo.isValidSubscription || !isInService(subId)) {
|
||||
status = setSummaryResId(subsSize > 1 ? R.string.calls_sms_unavailable :
|
||||
R.string.calls_sms_temp_unavailable);
|
||||
} else {
|
||||
if (isDataPreferred && isSmsPreferred) {
|
||||
if (isCallPreferred && isSmsPreferred) {
|
||||
status = setSummaryResId(R.string.calls_sms_preferred);
|
||||
} else if (isDataPreferred) {
|
||||
} else if (isCallPreferred) {
|
||||
status = setSummaryResId(R.string.calls_sms_calls_preferred);
|
||||
} else if (isSmsPreferred) {
|
||||
status = setSummaryResId(R.string.calls_sms_sms_preferred);
|
||||
@@ -226,4 +233,26 @@ public class NetworkProviderCallsSmsController extends AbstractPreferenceControl
|
||||
mSubInfoEntityList = activeSubInfoList;
|
||||
update();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getDefaultVoiceSubscriptionId() {
|
||||
return mDefaultVoiceSubId;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getDefaultSmsSubscriptionId() {
|
||||
return mDefaultSmsSubId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefaultVoiceChanged(int defaultVoiceSubId) {
|
||||
mDefaultVoiceSubId = defaultVoiceSubId;
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefaultSmsChanged(int defaultSmsSubId) {
|
||||
mDefaultSmsSubId = defaultSmsSubId;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,6 @@ import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
@@ -38,16 +37,15 @@ import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
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;
|
||||
import java.util.Map;
|
||||
|
||||
public class NetworkProviderSimListController extends AbstractPreferenceController implements
|
||||
LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback {
|
||||
LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback,
|
||||
DefaultSubscriptionReceiver.DefaultSubscriptionListener {
|
||||
private static final String TAG = "NetworkProviderSimListCtrl";
|
||||
private static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
|
||||
private static final String KEY_PREFERENCE_SIM = "provider_model_sim_list";
|
||||
@@ -58,6 +56,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private MobileNetworkRepository mMobileNetworkRepository;
|
||||
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
|
||||
private DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
|
||||
|
||||
public NetworkProviderSimListController(Context context, Lifecycle lifecycle,
|
||||
LifecycleOwner lifecycleOwner) {
|
||||
@@ -66,6 +65,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
||||
mPreferences = new ArrayMap<>();
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
|
||||
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
@@ -74,11 +74,13 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
||||
mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mMobileNetworkRepository.updateEntity();
|
||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_PAUSE)
|
||||
public void onPause() {
|
||||
mMobileNetworkRepository.removeRegister(this);
|
||||
mDataSubscriptionChangedReceiver.unRegisterReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,7 +132,8 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
||||
|
||||
public CharSequence getSummary(SubscriptionInfoEntity subInfo, CharSequence displayName) {
|
||||
if (subInfo.isActiveSubscriptionId) {
|
||||
CharSequence config = subInfo.defaultSimConfig;
|
||||
CharSequence config = SubscriptionUtil.getDefaultSimConfig(mContext,
|
||||
subInfo.getSubId());
|
||||
CharSequence summary = mContext.getResources().getString(
|
||||
R.string.sim_category_active_sim);
|
||||
if (config == "") {
|
||||
@@ -185,4 +188,22 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
||||
refreshSummary(mPreferenceCategory);
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefaultDataChanged(int defaultDataSubId) {
|
||||
refreshSummary(mPreferenceCategory);
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefaultVoiceChanged(int defaultVoiceSubId) {
|
||||
refreshSummary(mPreferenceCategory);
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefaultSmsChanged(int defaultSmsSubId) {
|
||||
refreshSummary(mPreferenceCategory);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
@@ -40,10 +40,12 @@ public class CallsDefaultSubscriptionController extends DefaultSubscriptionContr
|
||||
|
||||
@Override
|
||||
protected int getDefaultSubscriptionId() {
|
||||
int defaultCallSubId = SubscriptionManager.getDefaultVoiceSubscriptionId();
|
||||
for (SubscriptionInfoEntity subInfo : mSubInfoEntityList) {
|
||||
if (subInfo.isActiveSubscriptionId && subInfo.isDefaultVoiceSubscription) {
|
||||
int subId = subInfo.getSubId();
|
||||
if (subInfo.isActiveSubscriptionId && subId == defaultCallSubId) {
|
||||
mSubscriptionInfoEntity = subInfo;
|
||||
return Integer.parseInt(subInfo.subId);
|
||||
return subId;
|
||||
}
|
||||
}
|
||||
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
@@ -36,11 +36,10 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.DefaultSubscriptionReceiver;
|
||||
import com.android.settings.network.MobileNetworkRepository;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
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;
|
||||
@@ -52,7 +51,8 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class DefaultSubscriptionController extends TelephonyBasePreferenceController
|
||||
implements LifecycleObserver, Preference.OnPreferenceChangeListener,
|
||||
MobileNetworkRepository.MobileNetworkCallback {
|
||||
MobileNetworkRepository.MobileNetworkCallback,
|
||||
DefaultSubscriptionReceiver.DefaultSubscriptionListener {
|
||||
private static final String TAG = "DefaultSubController";
|
||||
|
||||
protected ListPreference mPreference;
|
||||
@@ -60,6 +60,7 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
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 =
|
||||
@@ -76,6 +77,7 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
mIsRtlMode = context.getResources().getConfiguration().getLayoutDirection()
|
||||
== View.LAYOUT_DIRECTION_RTL;
|
||||
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
|
||||
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
@@ -110,12 +112,13 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
// Can not get default subId from database until get the callback, add register by subId
|
||||
// later.
|
||||
mMobileNetworkRepository.addRegisterBySubId(getDefaultSubscriptionId());
|
||||
|
||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_PAUSE)
|
||||
public void onPause() {
|
||||
mMobileNetworkRepository.removeRegister(this);
|
||||
mDataSubscriptionChangedReceiver.unRegisterReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -308,4 +311,16 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere
|
||||
updateEntries();
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefaultVoiceChanged(int defaultVoiceSubId) {
|
||||
updateEntries();
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefaultSmsChanged(int defaultSmsSubId) {
|
||||
updateEntries();
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
}
|
||||
|
@@ -20,8 +20,6 @@ import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
@@ -36,13 +34,11 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.network.MobileDataContentObserver;
|
||||
import com.android.settings.network.MobileNetworkRepository;
|
||||
import com.android.settings.wifi.WifiPickerTrackerHelper;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
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;
|
||||
@@ -234,13 +230,14 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon
|
||||
public void onActiveSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||
mSubscriptionInfoEntityList = subInfoEntityList;
|
||||
mSubscriptionInfoEntityList.forEach(entity -> {
|
||||
if (Integer.parseInt(entity.subId) == mSubId) {
|
||||
if (entity.getSubId() == mSubId) {
|
||||
mSubscriptionInfoEntity = entity;
|
||||
}
|
||||
});
|
||||
int subId = mSubscriptionInfoEntity.getSubId();
|
||||
if (mSubscriptionInfoEntity != null
|
||||
&& mSubscriptionInfoEntity.isDefaultDataSubscription) {
|
||||
mDefaultSubId = Integer.parseInt(mSubscriptionInfoEntity.subId);
|
||||
&& subId == SubscriptionManager.getDefaultDataSubscriptionId()) {
|
||||
mDefaultSubId = subId;
|
||||
}
|
||||
update();
|
||||
refreshSummary(mPreference);
|
||||
|
@@ -1011,7 +1011,7 @@ public class MobileNetworkUtils {
|
||||
private static CharSequence getPreferredCallStatus(Context context,
|
||||
SubscriptionInfoEntity subInfo) {
|
||||
String status = "";
|
||||
if (subInfo.isDefaultVoiceSubscription) {
|
||||
if (subInfo.getSubId() == SubscriptionManager.getDefaultVoiceSubscriptionId()) {
|
||||
status = setSummaryResId(context, R.string.calls_sms_preferred);
|
||||
}
|
||||
|
||||
@@ -1021,7 +1021,7 @@ public class MobileNetworkUtils {
|
||||
private static CharSequence getPreferredSmsStatus(Context context,
|
||||
SubscriptionInfoEntity subInfo) {
|
||||
String status = "";
|
||||
if (subInfo.isDefaultSmsSubscription) {
|
||||
if (subInfo.getSubId() == SubscriptionManager.getDefaultSmsSubscriptionId()) {
|
||||
status = setSummaryResId(context, R.string.calls_sms_preferred);
|
||||
}
|
||||
|
||||
|
@@ -44,10 +44,12 @@ public class SmsDefaultSubscriptionController extends DefaultSubscriptionControl
|
||||
|
||||
@Override
|
||||
protected int getDefaultSubscriptionId() {
|
||||
int defaultSmsSubId = SubscriptionManager.getDefaultSmsSubscriptionId();
|
||||
for (SubscriptionInfoEntity subInfo : mSubInfoEntityList) {
|
||||
if (subInfo.isActiveSubscriptionId && subInfo.isDefaultSmsSubscription) {
|
||||
int subId = subInfo.getSubId();
|
||||
if (subInfo.isActiveSubscriptionId && subId == defaultSmsSubId) {
|
||||
mSubscriptionInfoEntity = subInfo;
|
||||
return Integer.parseInt(subInfo.subId);
|
||||
return subId;
|
||||
}
|
||||
}
|
||||
return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
|
Reference in New Issue
Block a user