diff options
| author | 2022-03-01 13:10:49 -0800 | |
|---|---|---|
| committer | 2022-04-01 02:24:22 +0000 | |
| commit | c901b0b863d591721772fb8d8cbadd8cee699af9 (patch) | |
| tree | df6e041875860c37f063449bd9f523ee495ccf59 | |
| parent | 58d9786a640b919ba00cc94b9c0303be6b8d51b2 (diff) | |
Truncate operator name to fit into SystemProp size
Test: manual
Bug: 210502588
Change-Id: I59a87fa256a9be54755199034e138a63d89f0885
| -rw-r--r-- | telephony/java/android/telephony/TelephonyManager.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index a5adf52051b9..b4825153bf0a 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -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); + } } } |