Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c901b0b8 authored by Ling Ma's avatar Ling Ma
Browse files

Truncate operator name to fit into SystemProp size

Test: manual
Bug: 210502588
Change-Id: I59a87fa256a9be54755199034e138a63d89f0885
parent 58d9786a
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -11487,7 +11487,25 @@ public class TelephonyManager {
        if (SubscriptionManager.isValidPhoneId(phoneId)) {
            List<String> newList = updateTelephonyProperty(
                    TelephonyProperties.operator_alpha(), phoneId, name);
            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);
            }
        }
    }