Loading src/com/android/settings/network/ProviderModelSlice.java +18 −9 Original line number Diff line number Diff line Loading @@ -173,22 +173,31 @@ public class ProviderModelSlice extends WifiSlice { if (!SubscriptionManager.isUsableSubscriptionId(defaultSubId)) { return; // No subscription - do nothing. } boolean requestConnectCarrier = !intent.hasExtra(EXTRA_TOGGLE_STATE); // Enable the mobile data always if the user requests to connect to the carrier network. boolean newState = requestConnectCarrier ? true : intent.getBooleanExtra(EXTRA_TOGGLE_STATE, mHelper.isMobileDataEnabled()); boolean isToggleAction = intent.hasExtra(EXTRA_TOGGLE_STATE); boolean newState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, mHelper.isMobileDataEnabled()); if (isToggleAction) { // The ToggleAction is used to set mobile data enabled. MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState, false /* disableOtherSubscriptions */); } doCarrierNetworkAction(isToggleAction, newState); } private void doCarrierNetworkAction(boolean isToggleAction, boolean isDataEnabled) { final NetworkProviderWorker worker = getWorker(); if (worker == null) { return; } if (requestConnectCarrier) { if (isToggleAction) { worker.setCarrierNetworkEnabled(isDataEnabled); return; } if (MobileNetworkUtils.isMobileDataEnabled(mContext)) { worker.connectCarrierNetwork(); } else { worker.setCarrierNetworkEnabled(newState); } } Loading src/com/android/settings/network/SubscriptionsPreferenceController.java +1 −1 Original line number Diff line number Diff line Loading @@ -498,7 +498,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl @VisibleForTesting public void connectCarrierNetwork() { if (mTelephonyManager == null || !mTelephonyManager.isDataEnabled()) { if (!MobileNetworkUtils.isMobileDataEnabled(mContext)) { return; } if (mWifiPickerTrackerHelper != null) { Loading src/com/android/settings/network/telephony/MobileNetworkUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -293,6 +293,22 @@ public class MobileNetworkUtils { && isCurrentCountrySupported(context))); } /** * Return {@code true} if mobile data is enabled */ public static boolean isMobileDataEnabled(Context context) { final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); if (!telephonyManager.isDataEnabled()) { // Check if the data is enabled on the second SIM in the case of dual SIM. final TelephonyManager tmDefaultData = telephonyManager.createForSubscriptionId( SubscriptionManager.getDefaultDataSubscriptionId()); if (tmDefaultData == null || !tmDefaultData.isDataEnabled()) { return false; } } return true; } /** * Set whether to enable data for {@code subId}, also whether to disable data for other * subscription Loading tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -371,6 +371,7 @@ public class ProviderModelSliceTest { @Test public void onNotifyChange_intentPrimaryAction_shouldConnectCarrierNetwork() { when(mTelephonyManager.isDataEnabled()).thenReturn(true); Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent(); mMockProviderModelSlice.onNotifyChange(intent); Loading Loading
src/com/android/settings/network/ProviderModelSlice.java +18 −9 Original line number Diff line number Diff line Loading @@ -173,22 +173,31 @@ public class ProviderModelSlice extends WifiSlice { if (!SubscriptionManager.isUsableSubscriptionId(defaultSubId)) { return; // No subscription - do nothing. } boolean requestConnectCarrier = !intent.hasExtra(EXTRA_TOGGLE_STATE); // Enable the mobile data always if the user requests to connect to the carrier network. boolean newState = requestConnectCarrier ? true : intent.getBooleanExtra(EXTRA_TOGGLE_STATE, mHelper.isMobileDataEnabled()); boolean isToggleAction = intent.hasExtra(EXTRA_TOGGLE_STATE); boolean newState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, mHelper.isMobileDataEnabled()); if (isToggleAction) { // The ToggleAction is used to set mobile data enabled. MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState, false /* disableOtherSubscriptions */); } doCarrierNetworkAction(isToggleAction, newState); } private void doCarrierNetworkAction(boolean isToggleAction, boolean isDataEnabled) { final NetworkProviderWorker worker = getWorker(); if (worker == null) { return; } if (requestConnectCarrier) { if (isToggleAction) { worker.setCarrierNetworkEnabled(isDataEnabled); return; } if (MobileNetworkUtils.isMobileDataEnabled(mContext)) { worker.connectCarrierNetwork(); } else { worker.setCarrierNetworkEnabled(newState); } } Loading
src/com/android/settings/network/SubscriptionsPreferenceController.java +1 −1 Original line number Diff line number Diff line Loading @@ -498,7 +498,7 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl @VisibleForTesting public void connectCarrierNetwork() { if (mTelephonyManager == null || !mTelephonyManager.isDataEnabled()) { if (!MobileNetworkUtils.isMobileDataEnabled(mContext)) { return; } if (mWifiPickerTrackerHelper != null) { Loading
src/com/android/settings/network/telephony/MobileNetworkUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -293,6 +293,22 @@ public class MobileNetworkUtils { && isCurrentCountrySupported(context))); } /** * Return {@code true} if mobile data is enabled */ public static boolean isMobileDataEnabled(Context context) { final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); if (!telephonyManager.isDataEnabled()) { // Check if the data is enabled on the second SIM in the case of dual SIM. final TelephonyManager tmDefaultData = telephonyManager.createForSubscriptionId( SubscriptionManager.getDefaultDataSubscriptionId()); if (tmDefaultData == null || !tmDefaultData.isDataEnabled()) { return false; } } return true; } /** * Set whether to enable data for {@code subId}, also whether to disable data for other * subscription Loading
tests/unit/src/com/android/settings/network/ProviderModelSliceTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -371,6 +371,7 @@ public class ProviderModelSliceTest { @Test public void onNotifyChange_intentPrimaryAction_shouldConnectCarrierNetwork() { when(mTelephonyManager.isDataEnabled()).thenReturn(true); Intent intent = mMockProviderModelSlice.getBroadcastIntent(mContext).getIntent(); mMockProviderModelSlice.onNotifyChange(intent); Loading