From d9b78ebc973909dd11006da61f41819289132007 Mon Sep 17 00:00:00 2001 From: tom hsu Date: Wed, 5 Feb 2025 23:54:17 -0800 Subject: [PATCH] Fix crash due to over limited length. Flag: EXEMPT bug fix Fix: b/388404115 Test: Manual test (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:a66f9dc3629586c3543952566f05f1b720dfa50c) Merged-In: I5c72c3c9ca9cb2e4058959abc5a0b4fdd60907bf Change-Id: I5c72c3c9ca9cb2e4058959abc5a0b4fdd60907bf --- res/layout/dialog_mobile_network_rename.xml | 2 +- res/values/integers.xml | 2 ++ .../RenameMobileNetworkDialogFragment.java | 14 +++++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/res/layout/dialog_mobile_network_rename.xml b/res/layout/dialog_mobile_network_rename.xml index 2c583d3bc9e..41ac001eed4 100644 --- a/res/layout/dialog_mobile_network_rename.xml +++ b/res/layout/dialog_mobile_network_rename.xml @@ -45,7 +45,7 @@ android:layout_height="wrap_content" android:inputType="text" android:paddingTop="@dimen/sim_label_padding" - android:maxLength="50" + android:maxLength="@integer/sim_label_max_length" android:singleLine="true"/> 3 2147483647 + + 50 diff --git a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java index ebc5575146e..73f80f688c7 100644 --- a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java +++ b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java @@ -165,9 +165,9 @@ public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragmen } final CharSequence displayName = SubscriptionUtil.getUniqueSubscriptionDisplayName( info, getContext()); - mNameView.setText(displayName); if (!TextUtils.isEmpty(displayName)) { - mNameView.setSelection(displayName.length()); + mNameView.setSelection(Math.min(displayName.length(), + getResources().getInteger(R.integer.sim_label_max_length))); } mColorSpinner = view.findViewById(R.id.color_spinner); @@ -176,7 +176,7 @@ public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragmen mColorSpinner.setAdapter(adapter); mColorSpinner.setSelection(getSimColorIndex(info.getIconTint())); - if(Flags.isDualSimOnboardingEnabled()){ + if (Flags.isDualSimOnboardingEnabled()) { return; } @@ -293,10 +293,10 @@ public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragmen } /* - * Get the color index from previous color that defined in Android OS - * (frameworks/base/core/res/res/values/arrays.xml). If can't find the color, continue to look - * for it in the new color plattee. If not, give it the first index. - */ + * Get the color index from previous color that defined in Android OS + * (frameworks/base/core/res/res/values/arrays.xml). If can't find the color, continue to look + * for it in the new color plattee. If not, give it the first index. + */ private int getSimColorIndex(int color) { int index = -1;