Loading src/com/android/settings/network/ProviderModelSliceHelper.java +92 −90 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.net.wifi.WifiManager; import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; Loading Loading @@ -75,8 +74,79 @@ public class ProviderModelSliceHelper { mTelephonyManager = context.getSystemService(TelephonyManager.class); } private static void log(String s) { Log.d(TAG, s); /** * @return whether there is the carrier item in the slice. */ public boolean hasCarrier() { if (isAirplaneModeEnabled() || mSubscriptionManager == null || mTelephonyManager == null || mSubscriptionManager.getDefaultDataSubscriptionId() == mSubscriptionManager.INVALID_SUBSCRIPTION_ID) { return false; } return true; } /** * @return whether the MobileData's is enabled. */ public boolean isMobileDataEnabled() { return mTelephonyManager.isDataEnabled(); } /** * To check the carrier data status. * * @return whether the carrier data is active. */ public boolean isDataSimActive() { return MobileNetworkUtils.activeNetworkIsCellular(mContext); } /** * @return whether the ServiceState's data state is in-service. */ public boolean isDataStateInService() { return mTelephonyManager.getDataState() == mTelephonyManager.DATA_CONNECTED; } /** * @return whether the ServiceState's voice state is in-service. */ public boolean isVoiceStateInService() { final ServiceState serviceState = mTelephonyManager.getServiceState(); return serviceState != null && serviceState.getState() == serviceState.STATE_IN_SERVICE; } /** * To get the signal bar icon with level. * * @return The Drawable which is a signal bar icon with level. */ public Drawable getDrawableWithSignalStrength() { final SignalStrength strength = mTelephonyManager.getSignalStrength(); int level = (strength == null) ? 0 : strength.getLevel(); int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS; if (mSubscriptionManager != null && shouldInflateSignalStrength( mSubscriptionManager.getDefaultDataSubscriptionId())) { level += 1; numLevels += 1; } return MobileNetworkUtils.getSignalStrengthIcon(mContext, level, numLevels, NO_CELL_DATA_TYPE_ICON, false); } /** * To update the telephony with subid. */ public void updateTelephony() { if (mSubscriptionManager == null || mSubscriptionManager.getDefaultDataSubscriptionId() == mSubscriptionManager.INVALID_SUBSCRIPTION_ID) { return; } mTelephonyManager = mTelephonyManager.createForSubscriptionId( mSubscriptionManager.getDefaultDataSubscriptionId()); } protected ListBuilder createListBuilder(Uri uri) { Loading @@ -97,19 +167,6 @@ public class ProviderModelSliceHelper { return item.isPresent() ? item.get() : null; } /** * @return whether there is the carrier item in the slice. */ public boolean hasCarrier() { if (isAirplaneModeEnabled() || mSubscriptionManager == null || mTelephonyManager == null || mSubscriptionManager.getDefaultDataSubscriptionId() == mSubscriptionManager.INVALID_SUBSCRIPTION_ID) { return false; } return true; } protected ListBuilder.RowBuilder createCarrierRow(String networkTypeDescription) { final String title = getMobileTitle(); final String summary = getMobileSummary(networkTypeDescription); Loading Loading @@ -142,49 +199,27 @@ public class ProviderModelSliceHelper { ListBuilder.ICON_IMAGE, mContext.getText(R.string.summary_placeholder)); } private PendingIntent getPrimaryAction(String intentAction) { final Intent intent = new Intent(intentAction) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_IMMUTABLE /* flags */); } private boolean shouldInflateSignalStrength(int subId) { return SignalStrengthUtil.shouldInflateSignalStrength(mContext, subId); } protected boolean isAirplaneModeEnabled() { return WirelessUtils.isAirplaneModeOn(mContext); } protected boolean isMobileDataEnabled() { if (mTelephonyManager == null) { return false; } return mTelephonyManager.isDataEnabled(); protected SubscriptionManager getSubscriptionManager() { return mSubscriptionManager; } /** * To check the carrier data status. * * @return whether the carrier data is active. */ public boolean isDataSimActive() { return isNoCarrierData() ? false : MobileNetworkUtils.activeNetworkIsCellular(mContext); private static void log(String s) { Log.d(TAG, s); } protected boolean isNoCarrierData() { if (mTelephonyManager == null) { return false; private PendingIntent getPrimaryAction(String intentAction) { final Intent intent = new Intent(intentAction) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_IMMUTABLE /* flags */); } boolean mobileDataOnAndNoData = isMobileDataEnabled() && mTelephonyManager.getDataState() != mTelephonyManager.DATA_CONNECTED; ServiceState serviceState = mTelephonyManager.getServiceState(); boolean mobileDataOffAndOutOfService = !isMobileDataEnabled() && serviceState != null && serviceState.getState() == serviceState.STATE_OUT_OF_SERVICE; log("mobileDataOnAndNoData: " + mobileDataOnAndNoData + ",mobileDataOffAndOutOfService: " + mobileDataOffAndOutOfService); return mobileDataOnAndNoData || mobileDataOffAndOutOfService; private boolean shouldInflateSignalStrength(int subId) { return SignalStrengthUtil.shouldInflateSignalStrength(mContext, subId); } @VisibleForTesting Loading @@ -194,7 +229,7 @@ public class ProviderModelSliceHelper { log("mTelephonyManager == null"); return drawable; } if (!isNoCarrierData()) { if (isDataStateInService() || isVoiceStateInService()) { Semaphore lock = new Semaphore(0); AtomicReference<Drawable> shared = new AtomicReference<>(); ThreadUtils.postOnMainThread(() -> { Loading @@ -213,35 +248,18 @@ public class ProviderModelSliceHelper { return drawable; } /** * To get the signal bar icon with level. * * @return The Drawable which is a signal bar icon with level. */ public Drawable getDrawableWithSignalStrength() { final SignalStrength strength = mTelephonyManager.getSignalStrength(); int level = (strength == null) ? 0 : strength.getLevel(); int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS; if (mSubscriptionManager != null && shouldInflateSignalStrength( mSubscriptionManager.getDefaultDataSubscriptionId())) { level += 1; numLevels += 1; private String getMobileSummary(String networkTypeDescription) { if (!isMobileDataEnabled()) { return mContext.getString(R.string.mobile_data_off_summary); } return MobileNetworkUtils.getSignalStrengthIcon(mContext, level, numLevels, NO_CELL_DATA_TYPE_ICON, false); if (!isDataStateInService()) { return mContext.getString(R.string.mobile_data_no_connection); } private String getMobileSummary(String networkTypeDescription) { final WifiManager wifiManager = mContext.getSystemService(WifiManager.class); String summary = networkTypeDescription; if (isDataSimActive()) { summary = mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.mobile_data_connection_active), networkTypeDescription); } else if (!isMobileDataEnabled()) { summary = mContext.getString(R.string.mobile_data_off_summary); } else if (!wifiManager.isWifiEnabled() && !isDataSimActive()) { summary = mContext.getString(R.string.mobile_data_no_connection); } return summary; } Loading @@ -260,26 +278,10 @@ public class ProviderModelSliceHelper { return title; } protected SubscriptionManager getSubscriptionManager() { return mSubscriptionManager; } private Set<String> getKeywords() { final String keywords = mContext.getString(R.string.keywords_internet); return Arrays.stream(TextUtils.split(keywords, ",")) .map(String::trim) .collect(Collectors.toSet()); } /** * To update the telephony with subid. */ public void updateTelephony() { if (mSubscriptionManager == null || mSubscriptionManager.getDefaultDataSubscriptionId() == mSubscriptionManager.INVALID_SUBSCRIPTION_ID) { return; } mTelephonyManager = mTelephonyManager.createForSubscriptionId( mSubscriptionManager.getDefaultDataSubscriptionId()); } } src/com/android/settings/panel/InternetConnectivityPanel.java +29 −13 Original line number Diff line number Diff line Loading @@ -301,21 +301,37 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve } final List<ScanResult> wifiList = mWifiManager.getScanResults(); if (wifiList != null && wifiList.size() == 0) { if (wifiList != null && wifiList.size() != 0) { return; } // Sub-Title: // show non_carrier_network_unavailable // - while Wi-Fi on + no Wi-Fi item // - while Wi-Fi on + no Wi-Fi item + mobile data off // show all_network_unavailable: // - while Wi-Fi on + no Wi-Fi item + no carrier // - while Wi-Fi on + no Wi-Fi item + no data capability // - while Wi-Fi on + no Wi-Fi item + no carrier item // - while Wi-Fi on + no Wi-Fi item + service is out of service // - while Wi-Fi on + no Wi-Fi item + mobile data on + no carrier data. log("No Wi-Fi item."); mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE; if (!mProviderModelSliceHelper.hasCarrier() || !mProviderModelSliceHelper.isDataSimActive()) { log("No carrier item or no carrier data."); || (!mProviderModelSliceHelper.isVoiceStateInService() && !mProviderModelSliceHelper.isDataStateInService())) { log("no carrier or service is out of service."); mSubtitle = SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE; return; } if (!mProviderModelSliceHelper.isMobileDataEnabled()) { log("mobile data off"); mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE; return; } if (!mProviderModelSliceHelper.isDataSimActive()) { log("no carrier data."); mSubtitle = SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE; return; } mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE; } private class NetworkProviderTelephonyCallback extends TelephonyCallback implements Loading tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java +0 −32 Original line number Diff line number Diff line Loading @@ -218,38 +218,6 @@ public class ProviderModelSliceHelperTest { assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle); } @Test public void isNoCarrierData_mobileDataOnAndNoData_returnTrue() { mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_DISCONNECTED, true); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isTrue(); } @Test public void isNoCarrierData_mobileDataOffAndOutOfService_returnTrue() { mockConnections(false, ServiceState.STATE_OUT_OF_SERVICE, "", mTelephonyManager.DATA_DISCONNECTED, true); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isTrue(); } @Test public void isNoCarrierData_mobileDataOnAndDataConnected_returnFalse() { mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_CONNECTED, true); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isFalse(); } @Test public void isNoCarrierData_mobileDataOffAndVoiceIsInService_returnFalse() { mockConnections(false, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_DISCONNECTED, true); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isFalse(); } @Test public void getMobileDrawable_noCarrierData_getMobileDrawable() throws Throwable { mockConnections(false, ServiceState.STATE_OUT_OF_SERVICE, "", Loading tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java +31 −7 Original line number Diff line number Diff line Loading @@ -129,7 +129,7 @@ public class InternetConnectivityPanelTest { @Test public void getSubTitle_apmOffWifiOnNoWifiListHasCarrierData_NonCarrierNetworkUnavailable() { List wifiList = new ArrayList<ScanResult>(); mockCondition(false, true, true, true, wifiList); mockCondition(false, true, true, true, true, true, wifiList); mPanel.updatePanelTitle(); Loading @@ -137,9 +137,29 @@ public class InternetConnectivityPanelTest { } @Test public void getSubTitle_apmOffWifiOnNoWifiListNoCarrierData_AllNetworkUnavailable() { public void getSubTitle_apmOffWifiOnNoWifiListNoCarrierItem_AllNetworkUnavailable() { List wifiList = new ArrayList<ScanResult>(); mockCondition(false, true, false, true, wifiList); mockCondition(false, false, false, false, false, true, wifiList); mPanel.updatePanelTitle(); assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE); } @Test public void getSubTitle_apmOffWifiOnNoWifiListNoDataSimActive_AllNetworkUnavailable() { List wifiList = new ArrayList<ScanResult>(); mockCondition(false, true, false, true, true, true, wifiList); mPanel.updatePanelTitle(); assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE); } @Test public void getSubTitle_apmOffWifiOnNoWifiListNoService_AllNetworkUnavailable() { List wifiList = new ArrayList<ScanResult>(); mockCondition(false, true, false, true, false, true, wifiList); mPanel.updatePanelTitle(); Loading @@ -151,7 +171,7 @@ public class InternetConnectivityPanelTest { List wifiList = new ArrayList<ScanResult>(); wifiList.add(new ScanResult()); wifiList.add(new ScanResult()); mockCondition(false, true, false, true, wifiList); mockCondition(false, true, false, true, true, true, wifiList); mPanel.updatePanelTitle(); Loading Loading @@ -184,7 +204,7 @@ public class InternetConnectivityPanelTest { @Test public void getSlices_providerModelDisabled_containsNecessarySlices() { mPanel.mIsProviderModelEnabled = false; final List<Uri> uris = mPanel.getSlices(); List<Uri> uris = mPanel.getSlices(); assertThat(uris).containsExactly( AirplaneModePreferenceController.SLICE_URI, Loading @@ -194,7 +214,7 @@ public class InternetConnectivityPanelTest { @Test public void getSlices_providerModelEnabled_containsNecessarySlices() { final List<Uri> uris = mPanel.getSlices(); List<Uri> uris = mPanel.getSlices(); assertThat(uris).containsExactly( CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI, Loading Loading @@ -291,10 +311,14 @@ public class InternetConnectivityPanelTest { } private void mockCondition(boolean airplaneMode, boolean hasCarrier, boolean isDataSimActive, boolean isWifiEnabled, List<ScanResult> wifiItems) { boolean isDataSimActive, boolean isMobileDataEnabled, boolean isServiceInService, boolean isWifiEnabled, List<ScanResult> wifiItems) { doReturn(airplaneMode).when(mInternetUpdater).isAirplaneModeOn(); when(mProviderModelSliceHelper.hasCarrier()).thenReturn(hasCarrier); when(mProviderModelSliceHelper.isDataSimActive()).thenReturn(isDataSimActive); when(mProviderModelSliceHelper.isMobileDataEnabled()).thenReturn(isMobileDataEnabled); when(mProviderModelSliceHelper.isDataStateInService()).thenReturn(isServiceInService); when(mProviderModelSliceHelper.isVoiceStateInService()).thenReturn(isServiceInService); doReturn(isWifiEnabled).when(mInternetUpdater).isWifiEnabled(); doReturn(wifiItems).when(mWifiManager).getScanResults(); } Loading Loading
src/com/android/settings/network/ProviderModelSliceHelper.java +92 −90 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.net.wifi.WifiManager; import android.telephony.ServiceState; import android.telephony.SignalStrength; import android.telephony.SubscriptionInfo; Loading Loading @@ -75,8 +74,79 @@ public class ProviderModelSliceHelper { mTelephonyManager = context.getSystemService(TelephonyManager.class); } private static void log(String s) { Log.d(TAG, s); /** * @return whether there is the carrier item in the slice. */ public boolean hasCarrier() { if (isAirplaneModeEnabled() || mSubscriptionManager == null || mTelephonyManager == null || mSubscriptionManager.getDefaultDataSubscriptionId() == mSubscriptionManager.INVALID_SUBSCRIPTION_ID) { return false; } return true; } /** * @return whether the MobileData's is enabled. */ public boolean isMobileDataEnabled() { return mTelephonyManager.isDataEnabled(); } /** * To check the carrier data status. * * @return whether the carrier data is active. */ public boolean isDataSimActive() { return MobileNetworkUtils.activeNetworkIsCellular(mContext); } /** * @return whether the ServiceState's data state is in-service. */ public boolean isDataStateInService() { return mTelephonyManager.getDataState() == mTelephonyManager.DATA_CONNECTED; } /** * @return whether the ServiceState's voice state is in-service. */ public boolean isVoiceStateInService() { final ServiceState serviceState = mTelephonyManager.getServiceState(); return serviceState != null && serviceState.getState() == serviceState.STATE_IN_SERVICE; } /** * To get the signal bar icon with level. * * @return The Drawable which is a signal bar icon with level. */ public Drawable getDrawableWithSignalStrength() { final SignalStrength strength = mTelephonyManager.getSignalStrength(); int level = (strength == null) ? 0 : strength.getLevel(); int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS; if (mSubscriptionManager != null && shouldInflateSignalStrength( mSubscriptionManager.getDefaultDataSubscriptionId())) { level += 1; numLevels += 1; } return MobileNetworkUtils.getSignalStrengthIcon(mContext, level, numLevels, NO_CELL_DATA_TYPE_ICON, false); } /** * To update the telephony with subid. */ public void updateTelephony() { if (mSubscriptionManager == null || mSubscriptionManager.getDefaultDataSubscriptionId() == mSubscriptionManager.INVALID_SUBSCRIPTION_ID) { return; } mTelephonyManager = mTelephonyManager.createForSubscriptionId( mSubscriptionManager.getDefaultDataSubscriptionId()); } protected ListBuilder createListBuilder(Uri uri) { Loading @@ -97,19 +167,6 @@ public class ProviderModelSliceHelper { return item.isPresent() ? item.get() : null; } /** * @return whether there is the carrier item in the slice. */ public boolean hasCarrier() { if (isAirplaneModeEnabled() || mSubscriptionManager == null || mTelephonyManager == null || mSubscriptionManager.getDefaultDataSubscriptionId() == mSubscriptionManager.INVALID_SUBSCRIPTION_ID) { return false; } return true; } protected ListBuilder.RowBuilder createCarrierRow(String networkTypeDescription) { final String title = getMobileTitle(); final String summary = getMobileSummary(networkTypeDescription); Loading Loading @@ -142,49 +199,27 @@ public class ProviderModelSliceHelper { ListBuilder.ICON_IMAGE, mContext.getText(R.string.summary_placeholder)); } private PendingIntent getPrimaryAction(String intentAction) { final Intent intent = new Intent(intentAction) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_IMMUTABLE /* flags */); } private boolean shouldInflateSignalStrength(int subId) { return SignalStrengthUtil.shouldInflateSignalStrength(mContext, subId); } protected boolean isAirplaneModeEnabled() { return WirelessUtils.isAirplaneModeOn(mContext); } protected boolean isMobileDataEnabled() { if (mTelephonyManager == null) { return false; } return mTelephonyManager.isDataEnabled(); protected SubscriptionManager getSubscriptionManager() { return mSubscriptionManager; } /** * To check the carrier data status. * * @return whether the carrier data is active. */ public boolean isDataSimActive() { return isNoCarrierData() ? false : MobileNetworkUtils.activeNetworkIsCellular(mContext); private static void log(String s) { Log.d(TAG, s); } protected boolean isNoCarrierData() { if (mTelephonyManager == null) { return false; private PendingIntent getPrimaryAction(String intentAction) { final Intent intent = new Intent(intentAction) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_IMMUTABLE /* flags */); } boolean mobileDataOnAndNoData = isMobileDataEnabled() && mTelephonyManager.getDataState() != mTelephonyManager.DATA_CONNECTED; ServiceState serviceState = mTelephonyManager.getServiceState(); boolean mobileDataOffAndOutOfService = !isMobileDataEnabled() && serviceState != null && serviceState.getState() == serviceState.STATE_OUT_OF_SERVICE; log("mobileDataOnAndNoData: " + mobileDataOnAndNoData + ",mobileDataOffAndOutOfService: " + mobileDataOffAndOutOfService); return mobileDataOnAndNoData || mobileDataOffAndOutOfService; private boolean shouldInflateSignalStrength(int subId) { return SignalStrengthUtil.shouldInflateSignalStrength(mContext, subId); } @VisibleForTesting Loading @@ -194,7 +229,7 @@ public class ProviderModelSliceHelper { log("mTelephonyManager == null"); return drawable; } if (!isNoCarrierData()) { if (isDataStateInService() || isVoiceStateInService()) { Semaphore lock = new Semaphore(0); AtomicReference<Drawable> shared = new AtomicReference<>(); ThreadUtils.postOnMainThread(() -> { Loading @@ -213,35 +248,18 @@ public class ProviderModelSliceHelper { return drawable; } /** * To get the signal bar icon with level. * * @return The Drawable which is a signal bar icon with level. */ public Drawable getDrawableWithSignalStrength() { final SignalStrength strength = mTelephonyManager.getSignalStrength(); int level = (strength == null) ? 0 : strength.getLevel(); int numLevels = SignalStrength.NUM_SIGNAL_STRENGTH_BINS; if (mSubscriptionManager != null && shouldInflateSignalStrength( mSubscriptionManager.getDefaultDataSubscriptionId())) { level += 1; numLevels += 1; private String getMobileSummary(String networkTypeDescription) { if (!isMobileDataEnabled()) { return mContext.getString(R.string.mobile_data_off_summary); } return MobileNetworkUtils.getSignalStrengthIcon(mContext, level, numLevels, NO_CELL_DATA_TYPE_ICON, false); if (!isDataStateInService()) { return mContext.getString(R.string.mobile_data_no_connection); } private String getMobileSummary(String networkTypeDescription) { final WifiManager wifiManager = mContext.getSystemService(WifiManager.class); String summary = networkTypeDescription; if (isDataSimActive()) { summary = mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.mobile_data_connection_active), networkTypeDescription); } else if (!isMobileDataEnabled()) { summary = mContext.getString(R.string.mobile_data_off_summary); } else if (!wifiManager.isWifiEnabled() && !isDataSimActive()) { summary = mContext.getString(R.string.mobile_data_no_connection); } return summary; } Loading @@ -260,26 +278,10 @@ public class ProviderModelSliceHelper { return title; } protected SubscriptionManager getSubscriptionManager() { return mSubscriptionManager; } private Set<String> getKeywords() { final String keywords = mContext.getString(R.string.keywords_internet); return Arrays.stream(TextUtils.split(keywords, ",")) .map(String::trim) .collect(Collectors.toSet()); } /** * To update the telephony with subid. */ public void updateTelephony() { if (mSubscriptionManager == null || mSubscriptionManager.getDefaultDataSubscriptionId() == mSubscriptionManager.INVALID_SUBSCRIPTION_ID) { return; } mTelephonyManager = mTelephonyManager.createForSubscriptionId( mSubscriptionManager.getDefaultDataSubscriptionId()); } }
src/com/android/settings/panel/InternetConnectivityPanel.java +29 −13 Original line number Diff line number Diff line Loading @@ -301,21 +301,37 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve } final List<ScanResult> wifiList = mWifiManager.getScanResults(); if (wifiList != null && wifiList.size() == 0) { if (wifiList != null && wifiList.size() != 0) { return; } // Sub-Title: // show non_carrier_network_unavailable // - while Wi-Fi on + no Wi-Fi item // - while Wi-Fi on + no Wi-Fi item + mobile data off // show all_network_unavailable: // - while Wi-Fi on + no Wi-Fi item + no carrier // - while Wi-Fi on + no Wi-Fi item + no data capability // - while Wi-Fi on + no Wi-Fi item + no carrier item // - while Wi-Fi on + no Wi-Fi item + service is out of service // - while Wi-Fi on + no Wi-Fi item + mobile data on + no carrier data. log("No Wi-Fi item."); mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE; if (!mProviderModelSliceHelper.hasCarrier() || !mProviderModelSliceHelper.isDataSimActive()) { log("No carrier item or no carrier data."); || (!mProviderModelSliceHelper.isVoiceStateInService() && !mProviderModelSliceHelper.isDataStateInService())) { log("no carrier or service is out of service."); mSubtitle = SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE; return; } if (!mProviderModelSliceHelper.isMobileDataEnabled()) { log("mobile data off"); mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE; return; } if (!mProviderModelSliceHelper.isDataSimActive()) { log("no carrier data."); mSubtitle = SUBTITLE_TEXT_ALL_CARRIER_NETWORK_UNAVAILABLE; return; } mSubtitle = SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE; } private class NetworkProviderTelephonyCallback extends TelephonyCallback implements Loading
tests/unit/src/com/android/settings/network/ProviderModelSliceHelperTest.java +0 −32 Original line number Diff line number Diff line Loading @@ -218,38 +218,6 @@ public class ProviderModelSliceHelperTest { assertThat(testRowBuild.getSubtitle()).isEqualTo(expectedSubtitle); } @Test public void isNoCarrierData_mobileDataOnAndNoData_returnTrue() { mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_DISCONNECTED, true); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isTrue(); } @Test public void isNoCarrierData_mobileDataOffAndOutOfService_returnTrue() { mockConnections(false, ServiceState.STATE_OUT_OF_SERVICE, "", mTelephonyManager.DATA_DISCONNECTED, true); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isTrue(); } @Test public void isNoCarrierData_mobileDataOnAndDataConnected_returnFalse() { mockConnections(true, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_CONNECTED, true); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isFalse(); } @Test public void isNoCarrierData_mobileDataOffAndVoiceIsInService_returnFalse() { mockConnections(false, ServiceState.STATE_IN_SERVICE, "", mTelephonyManager.DATA_DISCONNECTED, true); assertThat(mProviderModelSliceHelper.isNoCarrierData()).isFalse(); } @Test public void getMobileDrawable_noCarrierData_getMobileDrawable() throws Throwable { mockConnections(false, ServiceState.STATE_OUT_OF_SERVICE, "", Loading
tests/unit/src/com/android/settings/panel/InternetConnectivityPanelTest.java +31 −7 Original line number Diff line number Diff line Loading @@ -129,7 +129,7 @@ public class InternetConnectivityPanelTest { @Test public void getSubTitle_apmOffWifiOnNoWifiListHasCarrierData_NonCarrierNetworkUnavailable() { List wifiList = new ArrayList<ScanResult>(); mockCondition(false, true, true, true, wifiList); mockCondition(false, true, true, true, true, true, wifiList); mPanel.updatePanelTitle(); Loading @@ -137,9 +137,29 @@ public class InternetConnectivityPanelTest { } @Test public void getSubTitle_apmOffWifiOnNoWifiListNoCarrierData_AllNetworkUnavailable() { public void getSubTitle_apmOffWifiOnNoWifiListNoCarrierItem_AllNetworkUnavailable() { List wifiList = new ArrayList<ScanResult>(); mockCondition(false, true, false, true, wifiList); mockCondition(false, false, false, false, false, true, wifiList); mPanel.updatePanelTitle(); assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE); } @Test public void getSubTitle_apmOffWifiOnNoWifiListNoDataSimActive_AllNetworkUnavailable() { List wifiList = new ArrayList<ScanResult>(); mockCondition(false, true, false, true, true, true, wifiList); mPanel.updatePanelTitle(); assertThat(mPanel.getSubTitle()).isEqualTo(SUBTITLE_ALL_NETWORK_UNAVAILABLE); } @Test public void getSubTitle_apmOffWifiOnNoWifiListNoService_AllNetworkUnavailable() { List wifiList = new ArrayList<ScanResult>(); mockCondition(false, true, false, true, false, true, wifiList); mPanel.updatePanelTitle(); Loading @@ -151,7 +171,7 @@ public class InternetConnectivityPanelTest { List wifiList = new ArrayList<ScanResult>(); wifiList.add(new ScanResult()); wifiList.add(new ScanResult()); mockCondition(false, true, false, true, wifiList); mockCondition(false, true, false, true, true, true, wifiList); mPanel.updatePanelTitle(); Loading Loading @@ -184,7 +204,7 @@ public class InternetConnectivityPanelTest { @Test public void getSlices_providerModelDisabled_containsNecessarySlices() { mPanel.mIsProviderModelEnabled = false; final List<Uri> uris = mPanel.getSlices(); List<Uri> uris = mPanel.getSlices(); assertThat(uris).containsExactly( AirplaneModePreferenceController.SLICE_URI, Loading @@ -194,7 +214,7 @@ public class InternetConnectivityPanelTest { @Test public void getSlices_providerModelEnabled_containsNecessarySlices() { final List<Uri> uris = mPanel.getSlices(); List<Uri> uris = mPanel.getSlices(); assertThat(uris).containsExactly( CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI, Loading Loading @@ -291,10 +311,14 @@ public class InternetConnectivityPanelTest { } private void mockCondition(boolean airplaneMode, boolean hasCarrier, boolean isDataSimActive, boolean isWifiEnabled, List<ScanResult> wifiItems) { boolean isDataSimActive, boolean isMobileDataEnabled, boolean isServiceInService, boolean isWifiEnabled, List<ScanResult> wifiItems) { doReturn(airplaneMode).when(mInternetUpdater).isAirplaneModeOn(); when(mProviderModelSliceHelper.hasCarrier()).thenReturn(hasCarrier); when(mProviderModelSliceHelper.isDataSimActive()).thenReturn(isDataSimActive); when(mProviderModelSliceHelper.isMobileDataEnabled()).thenReturn(isMobileDataEnabled); when(mProviderModelSliceHelper.isDataStateInService()).thenReturn(isServiceInService); when(mProviderModelSliceHelper.isVoiceStateInService()).thenReturn(isServiceInService); doReturn(isWifiEnabled).when(mInternetUpdater).isWifiEnabled(); doReturn(wifiItems).when(mWifiManager).getScanResults(); } Loading