Truncate operator name to fit into SystemProp size

Test: manual
Bug: 210502588
Change-Id: I59a87fa256a9be54755199034e138a63d89f0885
This commit is contained in:
Ling Ma
2022-03-01 13:10:49 -08:00
parent 58d9786a64
commit c901b0b863

View File

@@ -11487,7 +11487,25 @@ public class TelephonyManager {
if (SubscriptionManager.isValidPhoneId(phoneId)) {
List<String> newList = updateTelephonyProperty(
TelephonyProperties.operator_alpha(), phoneId, name);
TelephonyProperties.operator_alpha(newList);
try {
TelephonyProperties.operator_alpha(newList);
} catch (IllegalArgumentException e) { //property value is longer than the byte limit
Log.e(TAG, "setNetworkOperatorNameForPhone: ", e);
int numberOfEntries = newList.size();
int maxOperatorLength = //save 1 byte for joiner " , "
(SystemProperties.PROP_VALUE_MAX - numberOfEntries) / numberOfEntries;
//examine and truncate every operator and retry
for (int i = 0; i < newList.size(); i++) {
if (newList.get(i) != null) {
newList.set(i, TextUtils
.truncateStringForUtf8Storage(newList.get(i), maxOperatorLength));
}
}
TelephonyProperties.operator_alpha(newList);
Log.e(TAG, "successfully truncated operator_alpha: " + newList);
}
}
}