Loading src/com/android/settings/network/MobileNetworkRepository.java +15 −1 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions private Uri mAirplaneModeSettingUri; private MetricsFeatureProvider mMetricsFeatureProvider; private IntentFilter mFilter = new IntentFilter(); private MobileDataContentObserver mDataContentObserver; private int mPhysicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX; private int mLogicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX; Loading Loading @@ -125,6 +126,13 @@ 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); mDataContentObserver = new MobileDataContentObserver( new Handler(Looper.getMainLooper())); mDataContentObserver.setOnMobileDataChangedListener(() -> { mExecutor.execute(() -> { insertMobileNetworkInfo(context); }); }); mFilter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); mFilter.addAction(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED); mFilter.addAction(ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED); Loading Loading @@ -163,6 +171,9 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions public void addRegister(LifecycleOwner lifecycleOwner) { mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(), this); mAirplaneModeObserver.register(mContext); if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { mDataContentObserver.register(mContext, mSubId); } mContext.registerReceiver(mDataSubscriptionChangedReceiver, mFilter); observeAllSubInfo(lifecycleOwner); observeAllUiccInfo(lifecycleOwner); Loading @@ -170,6 +181,9 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions } public void removeRegister() { if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { mDataContentObserver.unRegister(mContext); } mAirplaneModeObserver.unRegister(mContext); if (mDataSubscriptionChangedReceiver != null) { mContext.unregisterReceiver(mDataSubscriptionChangedReceiver); Loading Loading @@ -404,7 +418,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions return new MobileNetworkInfoEntity(String.valueOf(mSubId), MobileNetworkUtils.isContactDiscoveryEnabled(context, mSubId), MobileNetworkUtils.isContactDiscoveryVisible(context, mSubId), MobileNetworkUtils.isMobileDataEnabled(context), mTelephonyManager.isDataEnabled(), MobileNetworkUtils.isCdmaOptions(context, mSubId), MobileNetworkUtils.isGsmOptions(context, mSubId), MobileNetworkUtils.isWorldMode(context, mSubId), Loading src/com/android/settings/network/NetworkProviderDownloadedSimListController.java +2 −4 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.settings.network.telephony.MobileNetworkUtils; 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.DataServiceUtils; import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity; import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity; import com.android.settingslib.mobile.dataservice.UiccInfoEntity; Loading Loading @@ -181,10 +182,7 @@ public class NetworkProviderDownloadedSimListController extends @Override public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) { if ((mSubInfoEntityList != null && (subInfoEntityList.isEmpty() || !subInfoEntityList.equals(mSubInfoEntityList))) || (!subInfoEntityList.isEmpty() && mSubInfoEntityList == null)) { Log.d(TAG, "subInfo list from framework is changed, update the subInfo entity list."); if (DataServiceUtils.shouldUpdateEntityList(mSubInfoEntityList, subInfoEntityList)) { mSubInfoEntityList = subInfoEntityList; mPreferenceCategory.setVisible(isAvailable()); update(); Loading src/com/android/settings/network/telephony/MobileDataPreferenceController.java +121 −35 Original line number Diff line number Diff line Loading @@ -16,14 +16,19 @@ package com.android.settings.network.telephony; 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.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.OnLifecycleEvent; import androidx.annotation.VisibleForTesting; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; Loading @@ -32,16 +37,22 @@ 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.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; 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; /** * Preference controller for "Mobile data" */ public class MobileDataPreferenceController extends TelephonyTogglePreferenceController implements LifecycleObserver, OnStart, OnStop { implements LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback { private static final String DIALOG_TAG = "MobileDataDialog"; Loading @@ -56,12 +67,26 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon boolean mNeedDialog; private WifiPickerTrackerHelper mWifiPickerTrackerHelper; protected MobileNetworkRepository mMobileNetworkRepository; protected LifecycleOwner mLifecycleOwner; private List<SubscriptionInfoEntity> mSubscriptionInfoEntityList = new ArrayList<>(); private List<MobileNetworkInfoEntity> mMobileNetworkInfoEntityList = new ArrayList<>(); private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; SubscriptionInfoEntity mSubscriptionInfoEntity; MobileNetworkInfoEntity mMobileNetworkInfoEntity; public MobileDataPreferenceController(Context context, String key) { public MobileDataPreferenceController(Context context, String key, Lifecycle lifecycle, LifecycleOwner lifecycleOwner, int subId) { super(context, key); mSubId = subId; mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mDataContentObserver = new MobileDataContentObserver(new Handler(Looper.getMainLooper())); mDataContentObserver.setOnMobileDataChangedListener(() -> updateState(mPreference)); mMobileNetworkRepository = MobileNetworkRepository.createBySubId(context, this, mSubId); mLifecycleOwner = lifecycleOwner; if (lifecycle != null) { lifecycle.addObserver(this); } } @Override Loading @@ -77,18 +102,14 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon mPreference = screen.findPreference(getPreferenceKey()); } @Override @OnLifecycleEvent(ON_START) public void onStart() { if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { mDataContentObserver.register(mContext, mSubId); } mMobileNetworkRepository.addRegister(mLifecycleOwner); } @Override @OnLifecycleEvent(ON_STOP) public void onStop() { if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { mDataContentObserver.unRegister(mContext); } mMobileNetworkRepository.removeRegister(); } @Override Loading Loading @@ -122,39 +143,47 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon @Override public boolean isChecked() { mTelephonyManager = getTelephonyManager(); return mTelephonyManager.isDataEnabled(); return mMobileNetworkInfoEntity == null ? false : mMobileNetworkInfoEntity.isMobileDataEnabled; } @Override public void updateState(Preference preference) { super.updateState(preference); if (isOpportunistic()) { preference.setEnabled(false); preference.setSummary(R.string.mobile_data_settings_summary_auto_switch); } else { preference.setEnabled(true); preference.setSummary(R.string.mobile_data_settings_summary); mPreference = (SwitchPreference) preference; update(); } private void update() { if (mSubscriptionInfoEntity == null || mPreference == null) { return; } if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { preference.setSelectable(false); preference.setSummary(R.string.mobile_data_settings_summary_unavailable); mPreference.setChecked(isChecked()); if (mSubscriptionInfoEntity.isOpportunistic) { mPreference.setEnabled(false); mPreference.setSummary(R.string.mobile_data_settings_summary_auto_switch); } else { preference.setSelectable(true); mPreference.setEnabled(true); mPreference.setSummary(R.string.mobile_data_settings_summary); } if (!mSubscriptionInfoEntity.isValidSubscription) { mPreference.setSelectable(false); mPreference.setSummary(R.string.mobile_data_settings_summary_unavailable); } else { mPreference.setSelectable(true); } private boolean isOpportunistic() { SubscriptionInfo info = mSubscriptionManager.getActiveSubscriptionInfo(mSubId); return info != null && info.isOpportunistic(); } public void init(FragmentManager fragmentManager, int subId) { public void init(FragmentManager fragmentManager, int subId, SubscriptionInfoEntity subInfoEntity, MobileNetworkInfoEntity networkInfoEntity) { mFragmentManager = fragmentManager; mSubId = subId; mTelephonyManager = null; mTelephonyManager = getTelephonyManager(); mSubscriptionInfoEntity = subInfoEntity; mMobileNetworkInfoEntity = networkInfoEntity; } private TelephonyManager getTelephonyManager() { Loading @@ -179,9 +208,8 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon final boolean enableData = !isChecked(); mTelephonyManager = getTelephonyManager(); final boolean isMultiSim = (mTelephonyManager.getActiveModemCount() > 1); final int defaultSubId = mSubscriptionManager.getDefaultDataSubscriptionId(); final boolean needToDisableOthers = mSubscriptionManager .isActiveSubscriptionId(defaultSubId) && defaultSubId != mSubId; final boolean needToDisableOthers = mDefaultSubId != mSubId; if (enableData && isMultiSim && needToDisableOthers) { mDialogType = MobileDataDialogFragment.TYPE_MULTI_SIM_DIALOG; return true; Loading @@ -194,4 +222,62 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon mSubId); dialogFragment.show(mFragmentManager, DIALOG_TAG); } @VisibleForTesting public void setSubscriptionInfoEntity(SubscriptionInfoEntity subscriptionInfoEntity) { mSubscriptionInfoEntity = subscriptionInfoEntity; } @VisibleForTesting public void setMobileNetworkInfoEntity(MobileNetworkInfoEntity mobileNetworkInfoEntity) { mMobileNetworkInfoEntity = mobileNetworkInfoEntity; } @Override public void onAirplaneModeChanged(boolean airplaneModeEnabled) { } @Override public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) { } @Override public void onActiveSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) { if (DataServiceUtils.shouldUpdateEntityList(mSubscriptionInfoEntityList, subInfoEntityList)) { mSubscriptionInfoEntityList = subInfoEntityList; mSubscriptionInfoEntityList.forEach(entity -> { if (Integer.parseInt(entity.subId) == mSubId) { mSubscriptionInfoEntity = entity; } }); if (mSubscriptionInfoEntity != null && mSubscriptionInfoEntity.isDefaultDataSubscription) { mDefaultSubId = Integer.parseInt(mSubscriptionInfoEntity.subId); } update(); refreshSummary(mPreference); } } @Override public void onAllUiccInfoChanged(List<UiccInfoEntity> uiccInfoEntityList) { } @Override public void onAllMobileNetworkInfoChanged( List<MobileNetworkInfoEntity> mobileNetworkInfoEntityList) { if (DataServiceUtils.shouldUpdateEntityList(mMobileNetworkInfoEntityList, mobileNetworkInfoEntityList)) { mMobileNetworkInfoEntityList = mobileNetworkInfoEntityList; mMobileNetworkInfoEntityList.forEach(entity -> { if (Integer.parseInt(entity.subId) == mSubId) { mMobileNetworkInfoEntity = entity; update(); refreshSummary(mPreference); return; } }); } } } src/com/android/settings/network/telephony/MobileNetworkSettings.java +14 −5 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme private static final String KEY_ROAMING_PREF = "button_roaming_key"; private static final String KEY_CALLS_PREF = "calls_preference"; private static final String KEY_SMS_PREF = "sms_preference"; private static final String KEY_MOBILE_DATA_PREF = "mobile_data_enable"; //String keys for preference lookup private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key"; Loading Loading @@ -175,7 +176,9 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme new CallsDefaultSubscriptionController(context, KEY_CALLS_PREF, getSettingsLifecycle(), this), new SmsDefaultSubscriptionController(context, KEY_SMS_PREF, getSettingsLifecycle(), this)); this), new MobileDataPreferenceController(context, KEY_MOBILE_DATA_PREF, getSettingsLifecycle(), this, mSubId)); } @Override Loading Loading @@ -231,10 +234,16 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme REQUEST_CODE_DELETE_SUBSCRIPTION); use(DisableSimFooterPreferenceController.class).init(mSubId); use(NrDisabledInDsdsFooterPreferenceController.class).init(mSubId); use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId); use(MobileDataPreferenceController.class).setWifiPickerTrackerHelper( final MobileDataPreferenceController mobileDataPreferenceController = use(MobileDataPreferenceController.class); if (mobileDataPreferenceController != null) { mobileDataPreferenceController.init(getFragmentManager(), mSubId, mSubscriptionInfoEntity, mMobileNetworkInfoEntity); mobileDataPreferenceController.setWifiPickerTrackerHelper( new WifiPickerTrackerHelper(getSettingsLifecycle(), context, null /* WifiPickerTrackerCallback */)); } final RoamingPreferenceController roamingPreferenceController = use(RoamingPreferenceController.class); Loading tests/componenttests/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ android_test { "androidx.test.runner", "androidx.test.rules", "androidx.test.ext.junit", "mockito-target", ], test_suites: ["device-tests"], Loading Loading
src/com/android/settings/network/MobileNetworkRepository.java +15 −1 Original line number Diff line number Diff line Loading @@ -88,6 +88,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions private Uri mAirplaneModeSettingUri; private MetricsFeatureProvider mMetricsFeatureProvider; private IntentFilter mFilter = new IntentFilter(); private MobileDataContentObserver mDataContentObserver; private int mPhysicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX; private int mLogicalSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX; Loading Loading @@ -125,6 +126,13 @@ 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); mDataContentObserver = new MobileDataContentObserver( new Handler(Looper.getMainLooper())); mDataContentObserver.setOnMobileDataChangedListener(() -> { mExecutor.execute(() -> { insertMobileNetworkInfo(context); }); }); mFilter.addAction(TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED); mFilter.addAction(SubscriptionManager.ACTION_DEFAULT_SUBSCRIPTION_CHANGED); mFilter.addAction(ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED); Loading Loading @@ -163,6 +171,9 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions public void addRegister(LifecycleOwner lifecycleOwner) { mSubscriptionManager.addOnSubscriptionsChangedListener(mContext.getMainExecutor(), this); mAirplaneModeObserver.register(mContext); if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { mDataContentObserver.register(mContext, mSubId); } mContext.registerReceiver(mDataSubscriptionChangedReceiver, mFilter); observeAllSubInfo(lifecycleOwner); observeAllUiccInfo(lifecycleOwner); Loading @@ -170,6 +181,9 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions } public void removeRegister() { if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { mDataContentObserver.unRegister(mContext); } mAirplaneModeObserver.unRegister(mContext); if (mDataSubscriptionChangedReceiver != null) { mContext.unregisterReceiver(mDataSubscriptionChangedReceiver); Loading Loading @@ -404,7 +418,7 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions return new MobileNetworkInfoEntity(String.valueOf(mSubId), MobileNetworkUtils.isContactDiscoveryEnabled(context, mSubId), MobileNetworkUtils.isContactDiscoveryVisible(context, mSubId), MobileNetworkUtils.isMobileDataEnabled(context), mTelephonyManager.isDataEnabled(), MobileNetworkUtils.isCdmaOptions(context, mSubId), MobileNetworkUtils.isGsmOptions(context, mSubId), MobileNetworkUtils.isWorldMode(context, mSubId), Loading
src/com/android/settings/network/NetworkProviderDownloadedSimListController.java +2 −4 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.settings.network.telephony.MobileNetworkUtils; 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.DataServiceUtils; import com.android.settingslib.mobile.dataservice.MobileNetworkInfoEntity; import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity; import com.android.settingslib.mobile.dataservice.UiccInfoEntity; Loading Loading @@ -181,10 +182,7 @@ public class NetworkProviderDownloadedSimListController extends @Override public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) { if ((mSubInfoEntityList != null && (subInfoEntityList.isEmpty() || !subInfoEntityList.equals(mSubInfoEntityList))) || (!subInfoEntityList.isEmpty() && mSubInfoEntityList == null)) { Log.d(TAG, "subInfo list from framework is changed, update the subInfo entity list."); if (DataServiceUtils.shouldUpdateEntityList(mSubInfoEntityList, subInfoEntityList)) { mSubInfoEntityList = subInfoEntityList; mPreferenceCategory.setVisible(isAvailable()); update(); Loading
src/com/android/settings/network/telephony/MobileDataPreferenceController.java +121 −35 Original line number Diff line number Diff line Loading @@ -16,14 +16,19 @@ package com.android.settings.network.telephony; 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.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.OnLifecycleEvent; import androidx.annotation.VisibleForTesting; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; Loading @@ -32,16 +37,22 @@ 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.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; 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; /** * Preference controller for "Mobile data" */ public class MobileDataPreferenceController extends TelephonyTogglePreferenceController implements LifecycleObserver, OnStart, OnStop { implements LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback { private static final String DIALOG_TAG = "MobileDataDialog"; Loading @@ -56,12 +67,26 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon boolean mNeedDialog; private WifiPickerTrackerHelper mWifiPickerTrackerHelper; protected MobileNetworkRepository mMobileNetworkRepository; protected LifecycleOwner mLifecycleOwner; private List<SubscriptionInfoEntity> mSubscriptionInfoEntityList = new ArrayList<>(); private List<MobileNetworkInfoEntity> mMobileNetworkInfoEntityList = new ArrayList<>(); private int mDefaultSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; SubscriptionInfoEntity mSubscriptionInfoEntity; MobileNetworkInfoEntity mMobileNetworkInfoEntity; public MobileDataPreferenceController(Context context, String key) { public MobileDataPreferenceController(Context context, String key, Lifecycle lifecycle, LifecycleOwner lifecycleOwner, int subId) { super(context, key); mSubId = subId; mSubscriptionManager = context.getSystemService(SubscriptionManager.class); mDataContentObserver = new MobileDataContentObserver(new Handler(Looper.getMainLooper())); mDataContentObserver.setOnMobileDataChangedListener(() -> updateState(mPreference)); mMobileNetworkRepository = MobileNetworkRepository.createBySubId(context, this, mSubId); mLifecycleOwner = lifecycleOwner; if (lifecycle != null) { lifecycle.addObserver(this); } } @Override Loading @@ -77,18 +102,14 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon mPreference = screen.findPreference(getPreferenceKey()); } @Override @OnLifecycleEvent(ON_START) public void onStart() { if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { mDataContentObserver.register(mContext, mSubId); } mMobileNetworkRepository.addRegister(mLifecycleOwner); } @Override @OnLifecycleEvent(ON_STOP) public void onStop() { if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { mDataContentObserver.unRegister(mContext); } mMobileNetworkRepository.removeRegister(); } @Override Loading Loading @@ -122,39 +143,47 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon @Override public boolean isChecked() { mTelephonyManager = getTelephonyManager(); return mTelephonyManager.isDataEnabled(); return mMobileNetworkInfoEntity == null ? false : mMobileNetworkInfoEntity.isMobileDataEnabled; } @Override public void updateState(Preference preference) { super.updateState(preference); if (isOpportunistic()) { preference.setEnabled(false); preference.setSummary(R.string.mobile_data_settings_summary_auto_switch); } else { preference.setEnabled(true); preference.setSummary(R.string.mobile_data_settings_summary); mPreference = (SwitchPreference) preference; update(); } private void update() { if (mSubscriptionInfoEntity == null || mPreference == null) { return; } if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { preference.setSelectable(false); preference.setSummary(R.string.mobile_data_settings_summary_unavailable); mPreference.setChecked(isChecked()); if (mSubscriptionInfoEntity.isOpportunistic) { mPreference.setEnabled(false); mPreference.setSummary(R.string.mobile_data_settings_summary_auto_switch); } else { preference.setSelectable(true); mPreference.setEnabled(true); mPreference.setSummary(R.string.mobile_data_settings_summary); } if (!mSubscriptionInfoEntity.isValidSubscription) { mPreference.setSelectable(false); mPreference.setSummary(R.string.mobile_data_settings_summary_unavailable); } else { mPreference.setSelectable(true); } private boolean isOpportunistic() { SubscriptionInfo info = mSubscriptionManager.getActiveSubscriptionInfo(mSubId); return info != null && info.isOpportunistic(); } public void init(FragmentManager fragmentManager, int subId) { public void init(FragmentManager fragmentManager, int subId, SubscriptionInfoEntity subInfoEntity, MobileNetworkInfoEntity networkInfoEntity) { mFragmentManager = fragmentManager; mSubId = subId; mTelephonyManager = null; mTelephonyManager = getTelephonyManager(); mSubscriptionInfoEntity = subInfoEntity; mMobileNetworkInfoEntity = networkInfoEntity; } private TelephonyManager getTelephonyManager() { Loading @@ -179,9 +208,8 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon final boolean enableData = !isChecked(); mTelephonyManager = getTelephonyManager(); final boolean isMultiSim = (mTelephonyManager.getActiveModemCount() > 1); final int defaultSubId = mSubscriptionManager.getDefaultDataSubscriptionId(); final boolean needToDisableOthers = mSubscriptionManager .isActiveSubscriptionId(defaultSubId) && defaultSubId != mSubId; final boolean needToDisableOthers = mDefaultSubId != mSubId; if (enableData && isMultiSim && needToDisableOthers) { mDialogType = MobileDataDialogFragment.TYPE_MULTI_SIM_DIALOG; return true; Loading @@ -194,4 +222,62 @@ public class MobileDataPreferenceController extends TelephonyTogglePreferenceCon mSubId); dialogFragment.show(mFragmentManager, DIALOG_TAG); } @VisibleForTesting public void setSubscriptionInfoEntity(SubscriptionInfoEntity subscriptionInfoEntity) { mSubscriptionInfoEntity = subscriptionInfoEntity; } @VisibleForTesting public void setMobileNetworkInfoEntity(MobileNetworkInfoEntity mobileNetworkInfoEntity) { mMobileNetworkInfoEntity = mobileNetworkInfoEntity; } @Override public void onAirplaneModeChanged(boolean airplaneModeEnabled) { } @Override public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) { } @Override public void onActiveSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) { if (DataServiceUtils.shouldUpdateEntityList(mSubscriptionInfoEntityList, subInfoEntityList)) { mSubscriptionInfoEntityList = subInfoEntityList; mSubscriptionInfoEntityList.forEach(entity -> { if (Integer.parseInt(entity.subId) == mSubId) { mSubscriptionInfoEntity = entity; } }); if (mSubscriptionInfoEntity != null && mSubscriptionInfoEntity.isDefaultDataSubscription) { mDefaultSubId = Integer.parseInt(mSubscriptionInfoEntity.subId); } update(); refreshSummary(mPreference); } } @Override public void onAllUiccInfoChanged(List<UiccInfoEntity> uiccInfoEntityList) { } @Override public void onAllMobileNetworkInfoChanged( List<MobileNetworkInfoEntity> mobileNetworkInfoEntityList) { if (DataServiceUtils.shouldUpdateEntityList(mMobileNetworkInfoEntityList, mobileNetworkInfoEntityList)) { mMobileNetworkInfoEntityList = mobileNetworkInfoEntityList; mMobileNetworkInfoEntityList.forEach(entity -> { if (Integer.parseInt(entity.subId) == mSubId) { mMobileNetworkInfoEntity = entity; update(); refreshSummary(mPreference); return; } }); } } }
src/com/android/settings/network/telephony/MobileNetworkSettings.java +14 −5 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme private static final String KEY_ROAMING_PREF = "button_roaming_key"; private static final String KEY_CALLS_PREF = "calls_preference"; private static final String KEY_SMS_PREF = "sms_preference"; private static final String KEY_MOBILE_DATA_PREF = "mobile_data_enable"; //String keys for preference lookup private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key"; Loading Loading @@ -175,7 +176,9 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme new CallsDefaultSubscriptionController(context, KEY_CALLS_PREF, getSettingsLifecycle(), this), new SmsDefaultSubscriptionController(context, KEY_SMS_PREF, getSettingsLifecycle(), this)); this), new MobileDataPreferenceController(context, KEY_MOBILE_DATA_PREF, getSettingsLifecycle(), this, mSubId)); } @Override Loading Loading @@ -231,10 +234,16 @@ public class MobileNetworkSettings extends AbstractMobileNetworkSettings impleme REQUEST_CODE_DELETE_SUBSCRIPTION); use(DisableSimFooterPreferenceController.class).init(mSubId); use(NrDisabledInDsdsFooterPreferenceController.class).init(mSubId); use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId); use(MobileDataPreferenceController.class).setWifiPickerTrackerHelper( final MobileDataPreferenceController mobileDataPreferenceController = use(MobileDataPreferenceController.class); if (mobileDataPreferenceController != null) { mobileDataPreferenceController.init(getFragmentManager(), mSubId, mSubscriptionInfoEntity, mMobileNetworkInfoEntity); mobileDataPreferenceController.setWifiPickerTrackerHelper( new WifiPickerTrackerHelper(getSettingsLifecycle(), context, null /* WifiPickerTrackerCallback */)); } final RoamingPreferenceController roamingPreferenceController = use(RoamingPreferenceController.class); Loading
tests/componenttests/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ android_test { "androidx.test.runner", "androidx.test.rules", "androidx.test.ext.junit", "mockito-target", ], test_suites: ["device-tests"], Loading