[Settings Telephony] Carrier name API replacement
Replacing TelephonyManager.getNetworkOperatorName() by Obtaining carrier name from SubscriptionInfo.getCarrierName(). TelephonyManager.getNetworkOperatorName() only be used when there's no SubscriptionInfo can be found. Bug: b/140443508 Test: Manual testing atest MobileNetworkUtilsTest atest OpenNetworkSelectPagePreferenceControllerTest Change-Id: I7a86395c86d31fe2ba54c04ac16b1a0ebfc843f3
This commit is contained in:
@@ -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;
|
||||
@@ -162,6 +163,6 @@ public class MobileNetworkPreferenceController extends AbstractPreferenceControl
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mTelephonyManager.getNetworkOperatorName();
|
||||
return MobileNetworkUtils.getCurrentCarrierNameForDisplay(mContext);
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
*/
|
||||
@@ -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)
|
||||
|
@@ -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);
|
||||
}
|
||||
@@ -108,4 +108,4 @@ public class OpenNetworkSelectPagePreferenceController extends
|
||||
public void onNetworkSelectModeChanged() {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user