Loading src/com/android/settings/network/MobileNetworkPreferenceController.java +2 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.core.FeatureFlags; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.network.telephony.MobileNetworkActivity; import com.android.settings.network.telephony.MobileNetworkUtils; import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedPreference; import com.android.settingslib.Utils; Loading Loading @@ -162,6 +163,6 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl @Override public CharSequence getSummary() { return mTelephonyManager.getNetworkOperatorName(); return MobileNetworkUtils.getCurrentCarrierNameForDisplay(mContext); } } src/com/android/settings/network/telephony/MobileNetworkUtils.java +56 −0 Original line number Diff line number Diff line Loading @@ -535,4 +535,60 @@ public class MobileNetworkUtils { icons.setTintList(Utils.getColorAttr(context, android.R.attr.colorControlNormal)); return icons; } /** * This method is migrated from * {@link android.telephony.TelephonyManager.getNetworkOperatorName}. Which provides * * 1. Better support under multi-SIM environment. * 2. Similar design which aligned with operator name displayed in status bar */ public static CharSequence getCurrentCarrierNameForDisplay(Context context, int subId) { SubscriptionManager sm = context.getSystemService(SubscriptionManager.class); if (sm != null) { SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId); if (subInfo != null) { return subInfo.getCarrierName(); } } return getOperatorNameFromTelephonyManager(context); } public static CharSequence getCurrentCarrierNameForDisplay(Context context) { SubscriptionManager sm = context.getSystemService(SubscriptionManager.class); if (sm != null) { int subId = sm.getDefaultSubscriptionId(); SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId); if (subInfo != null) { return subInfo.getCarrierName(); } } return getOperatorNameFromTelephonyManager(context); } private static SubscriptionInfo getSubscriptionInfo(SubscriptionManager subManager, int subId) { List<SubscriptionInfo> subInfos = subManager.getAccessibleSubscriptionInfoList(); if (subInfos == null) { subInfos = subManager.getActiveSubscriptionInfoList(); } if (subInfos == null) { return null; } for (SubscriptionInfo subInfo : subInfos) { if (subInfo.getSubscriptionId() == subId) { return subInfo; } } return null; } private static String getOperatorNameFromTelephonyManager(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(TelephonyManager.class); if (tm == null) { return null; } return tm.getNetworkOperatorName(); } } src/com/android/settings/network/telephony/NetworkSelectSettings.java +4 −4 Original line number Diff line number Diff line Loading @@ -310,9 +310,8 @@ public class NetworkSelectSettings extends DashboardFragment { * 1. use {@code ServiceState#getNetworkRegistrationInfoList()} to get the currently * registered cellIdentity, wrap it into a CellInfo; * 2. set the signal strength level as strong; * 3. use {@link TelephonyManager#getNetworkOperatorName()} to get the title of the * previously connected network operator, since the CellIdentity got from step 1 only has * PLMN. * 3. get the title of the previously connected network operator, since the CellIdentity * got from step 1 only has PLMN. * - If the device has no data, we will remove the connected network operators list from the * screen. */ Loading @@ -333,7 +332,8 @@ public class NetworkSelectSettings extends DashboardFragment { if (cellInfo != null) { NetworkOperatorPreference pref = new NetworkOperatorPreference( cellInfo, getPrefContext(), mForbiddenPlmns, mShow4GForLTE); pref.setTitle(mTelephonyManager.getNetworkOperatorName()); pref.setTitle(MobileNetworkUtils.getCurrentCarrierNameForDisplay( getPrefContext(), mSubId)); pref.setSummary(R.string.network_connected); // Update the signal strength icon, since the default signalStrength value would be // zero (it would be quite confusing why the connected network has no signal) Loading src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -75,7 +75,7 @@ public class OpenNetworkSelectPagePreferenceController extends public CharSequence getSummary() { final ServiceState ss = mTelephonyManager.getServiceState(); if (ss != null && ss.getState() == ServiceState.STATE_IN_SERVICE) { return mTelephonyManager.getNetworkOperatorName(); return MobileNetworkUtils.getCurrentCarrierNameForDisplay(mContext, mSubId); } else { return mContext.getString(R.string.network_disconnected); } Loading tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; Loading Loading @@ -58,6 +59,10 @@ public class MobileNetworkUtilsTest { private static final String PACKAGE_NAME = "com.android.app"; private static final int SUB_ID_1 = 1; private static final int SUB_ID_2 = 2; private static final int SUB_ID_INVALID = -1; private static final String PLMN_FROM_TELEPHONY_MANAGER_API = "testPlmn"; private static final String PLMN_FROM_SUB_ID_1 = "testPlmnSub1"; private static final String PLMN_FROM_SUB_ID_2 = "testPlmnSub2"; @Mock private TelephonyManager mTelephonyManager; Loading Loading @@ -89,6 +94,7 @@ public class MobileNetworkUtilsTest { mContext = spy(RuntimeEnvironment.application); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2); Loading @@ -102,10 +108,17 @@ public class MobileNetworkUtilsTest { when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig); when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1); when(mSubscriptionInfo1.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_1); when(mSubscriptionInfo2.getSubscriptionId()).thenReturn(SUB_ID_2); when(mSubscriptionInfo2.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_2); when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true))).thenReturn( Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)); when(mSubscriptionManager.getAccessibleSubscriptionInfoList()).thenReturn( Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)); when(mTelephonyManager.getNetworkOperatorName()).thenReturn( PLMN_FROM_TELEPHONY_MANAGER_API); } @Test Loading Loading @@ -301,4 +314,24 @@ public class MobileNetworkUtilsTest { TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue(); } @Test public void getCurrentCarrierNameForDisplay_withoutValidSubId_returnNetworkOperatorName() { assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay( mContext, SUB_ID_INVALID)).isEqualTo(PLMN_FROM_TELEPHONY_MANAGER_API); } @Test public void getCurrentCarrierNameForDisplay_withValidSubId_returnCurrentCarrierName() { assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay( mContext, SUB_ID_1)).isEqualTo(PLMN_FROM_SUB_ID_1); assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay( mContext, SUB_ID_2)).isEqualTo(PLMN_FROM_SUB_ID_2); } @Test public void getCurrentCarrierNameForDisplay_withoutSubId_returnNotNull() { assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay( mContext)).isNotNull(); } } Loading
src/com/android/settings/network/MobileNetworkPreferenceController.java +2 −1 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.core.FeatureFlags; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.network.telephony.MobileNetworkActivity; import com.android.settings.network.telephony.MobileNetworkUtils; import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedPreference; import com.android.settingslib.Utils; Loading Loading @@ -162,6 +163,6 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl @Override public CharSequence getSummary() { return mTelephonyManager.getNetworkOperatorName(); return MobileNetworkUtils.getCurrentCarrierNameForDisplay(mContext); } }
src/com/android/settings/network/telephony/MobileNetworkUtils.java +56 −0 Original line number Diff line number Diff line Loading @@ -535,4 +535,60 @@ public class MobileNetworkUtils { icons.setTintList(Utils.getColorAttr(context, android.R.attr.colorControlNormal)); return icons; } /** * This method is migrated from * {@link android.telephony.TelephonyManager.getNetworkOperatorName}. Which provides * * 1. Better support under multi-SIM environment. * 2. Similar design which aligned with operator name displayed in status bar */ public static CharSequence getCurrentCarrierNameForDisplay(Context context, int subId) { SubscriptionManager sm = context.getSystemService(SubscriptionManager.class); if (sm != null) { SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId); if (subInfo != null) { return subInfo.getCarrierName(); } } return getOperatorNameFromTelephonyManager(context); } public static CharSequence getCurrentCarrierNameForDisplay(Context context) { SubscriptionManager sm = context.getSystemService(SubscriptionManager.class); if (sm != null) { int subId = sm.getDefaultSubscriptionId(); SubscriptionInfo subInfo = getSubscriptionInfo(sm, subId); if (subInfo != null) { return subInfo.getCarrierName(); } } return getOperatorNameFromTelephonyManager(context); } private static SubscriptionInfo getSubscriptionInfo(SubscriptionManager subManager, int subId) { List<SubscriptionInfo> subInfos = subManager.getAccessibleSubscriptionInfoList(); if (subInfos == null) { subInfos = subManager.getActiveSubscriptionInfoList(); } if (subInfos == null) { return null; } for (SubscriptionInfo subInfo : subInfos) { if (subInfo.getSubscriptionId() == subId) { return subInfo; } } return null; } private static String getOperatorNameFromTelephonyManager(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(TelephonyManager.class); if (tm == null) { return null; } return tm.getNetworkOperatorName(); } }
src/com/android/settings/network/telephony/NetworkSelectSettings.java +4 −4 Original line number Diff line number Diff line Loading @@ -310,9 +310,8 @@ public class NetworkSelectSettings extends DashboardFragment { * 1. use {@code ServiceState#getNetworkRegistrationInfoList()} to get the currently * registered cellIdentity, wrap it into a CellInfo; * 2. set the signal strength level as strong; * 3. use {@link TelephonyManager#getNetworkOperatorName()} to get the title of the * previously connected network operator, since the CellIdentity got from step 1 only has * PLMN. * 3. get the title of the previously connected network operator, since the CellIdentity * got from step 1 only has PLMN. * - If the device has no data, we will remove the connected network operators list from the * screen. */ Loading @@ -333,7 +332,8 @@ public class NetworkSelectSettings extends DashboardFragment { if (cellInfo != null) { NetworkOperatorPreference pref = new NetworkOperatorPreference( cellInfo, getPrefContext(), mForbiddenPlmns, mShow4GForLTE); pref.setTitle(mTelephonyManager.getNetworkOperatorName()); pref.setTitle(MobileNetworkUtils.getCurrentCarrierNameForDisplay( getPrefContext(), mSubId)); pref.setSummary(R.string.network_connected); // Update the signal strength icon, since the default signalStrength value would be // zero (it would be quite confusing why the connected network has no signal) Loading
src/com/android/settings/network/telephony/gsm/OpenNetworkSelectPagePreferenceController.java +2 −2 Original line number Diff line number Diff line Loading @@ -75,7 +75,7 @@ public class OpenNetworkSelectPagePreferenceController extends public CharSequence getSummary() { final ServiceState ss = mTelephonyManager.getServiceState(); if (ss != null && ss.getState() == ServiceState.STATE_IN_SERVICE) { return mTelephonyManager.getNetworkOperatorName(); return MobileNetworkUtils.getCurrentCarrierNameForDisplay(mContext, mSubId); } else { return mContext.getString(R.string.network_disconnected); } Loading
tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; Loading Loading @@ -58,6 +59,10 @@ public class MobileNetworkUtilsTest { private static final String PACKAGE_NAME = "com.android.app"; private static final int SUB_ID_1 = 1; private static final int SUB_ID_2 = 2; private static final int SUB_ID_INVALID = -1; private static final String PLMN_FROM_TELEPHONY_MANAGER_API = "testPlmn"; private static final String PLMN_FROM_SUB_ID_1 = "testPlmnSub1"; private static final String PLMN_FROM_SUB_ID_2 = "testPlmnSub2"; @Mock private TelephonyManager mTelephonyManager; Loading Loading @@ -89,6 +94,7 @@ public class MobileNetworkUtilsTest { mContext = spy(RuntimeEnvironment.application); when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager); when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(SUB_ID_1)).thenReturn(mTelephonyManager); when(mTelephonyManager.createForSubscriptionId(SUB_ID_2)).thenReturn(mTelephonyManager2); Loading @@ -102,10 +108,17 @@ public class MobileNetworkUtilsTest { when(mCarrierConfigManager.getConfigForSubId(SUB_ID_1)).thenReturn(mCarrierConfig); when(mSubscriptionInfo1.getSubscriptionId()).thenReturn(SUB_ID_1); when(mSubscriptionInfo1.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_1); when(mSubscriptionInfo2.getSubscriptionId()).thenReturn(SUB_ID_2); when(mSubscriptionInfo2.getCarrierName()).thenReturn(PLMN_FROM_SUB_ID_2); when(mSubscriptionManager.getActiveSubscriptionInfoList(eq(true))).thenReturn( Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)); when(mSubscriptionManager.getAccessibleSubscriptionInfoList()).thenReturn( Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)); when(mTelephonyManager.getNetworkOperatorName()).thenReturn( PLMN_FROM_TELEPHONY_MANAGER_API); } @Test Loading Loading @@ -301,4 +314,24 @@ public class MobileNetworkUtilsTest { TelephonyManager.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); assertThat(MobileNetworkUtils.shouldSpeciallyUpdateGsmCdma(mContext, SUB_ID_1)).isTrue(); } @Test public void getCurrentCarrierNameForDisplay_withoutValidSubId_returnNetworkOperatorName() { assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay( mContext, SUB_ID_INVALID)).isEqualTo(PLMN_FROM_TELEPHONY_MANAGER_API); } @Test public void getCurrentCarrierNameForDisplay_withValidSubId_returnCurrentCarrierName() { assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay( mContext, SUB_ID_1)).isEqualTo(PLMN_FROM_SUB_ID_1); assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay( mContext, SUB_ID_2)).isEqualTo(PLMN_FROM_SUB_ID_2); } @Test public void getCurrentCarrierNameForDisplay_withoutSubId_returnNotNull() { assertThat(MobileNetworkUtils.getCurrentCarrierNameForDisplay( mContext)).isNotNull(); } }