From 41cdecca3d80da4bcdf99a3ce76cb7f081460772 Mon Sep 17 00:00:00 2001 From: govenliu Date: Wed, 10 Jul 2019 17:29:16 +0800 Subject: [PATCH] [Wi-Fi] EAP method AKA' did not pronounced as AKA prime. Spinner did not use ttsspan to store the display string so AKA' just pronounced as AKA. To fix it, use charsequence array, which each specific array item have the ttsSpan to store the string for TTS engine. Bug: 119929832 Test: Set a 3-texts array and check if the specific array item replacement mechanism work correctly or not. Change-Id: I8e7d10da99a3f3503e1019687c45cf40070d0045 --- res/layout/wifi_dialog.xml | 3 +- res/values/arrays.xml | 12 +++ .../settings/wifi/WifiConfigController.java | 86 +++++++++++++++++-- .../wifi/WifiConfigControllerTest.java | 40 +++++++++ 4 files changed, 131 insertions(+), 10 deletions(-) diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml index 8302f4d90a6..b9a910bd2fd 100644 --- a/res/layout/wifi_dialog.xml +++ b/res/layout/wifi_dialog.xml @@ -138,8 +138,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/wifi_item_spinner" - android:prompt="@string/wifi_eap_method" - android:entries="@array/wifi_eap_method" /> + android:prompt="@string/wifi_eap_method" /> AKA\' + + + + AKA\' + + + + + + AKA prime + + PEAP diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java index 26b4d3b7d5a..dc84201132f 100644 --- a/src/com/android/settings/wifi/WifiConfigController.java +++ b/src/com/android/settings/wifi/WifiConfigController.java @@ -40,6 +40,7 @@ import android.security.Credentials; import android.security.KeyStore; import android.text.Editable; import android.text.InputType; +import android.text.SpannableString; import android.text.TextUtils; import android.text.TextWatcher; import android.util.Log; @@ -122,9 +123,9 @@ public class WifiConfigController implements TextWatcher, /* Phase2 methods supported by PEAP are limited */ - private ArrayAdapter mPhase2PeapAdapter; + private ArrayAdapter mPhase2PeapAdapter; /* Full list of phase2 methods */ - private ArrayAdapter mPhase2FullAdapter; + private ArrayAdapter mPhase2FullAdapter; // e.g. AccessPoint.SECURITY_NONE @VisibleForTesting @@ -145,7 +146,7 @@ public class WifiConfigController implements TextWatcher, private TextView mEapDomainView; private Spinner mPhase2Spinner; // Associated with mPhase2Spinner, one of mPhase2FullAdapter or mPhase2PeapAdapter - private ArrayAdapter mPhase2Adapter; + private ArrayAdapter mPhase2Adapter; private Spinner mEapUserCertSpinner; private TextView mEapIdentityView; private TextView mEapAnonymousView; @@ -218,17 +219,16 @@ public class WifiConfigController implements TextWatcher, mLevels = res.getStringArray(R.array.wifi_signal); if (Utils.isWifiOnly(mContext) || !mContext.getResources().getBoolean( com.android.internal.R.bool.config_eap_sim_based_auth_supported)) { - mPhase2PeapAdapter = new ArrayAdapter( + mPhase2PeapAdapter = new ArrayAdapter( mContext, android.R.layout.simple_spinner_item, res.getStringArray(R.array.wifi_peap_phase2_entries)); } else { - mPhase2PeapAdapter = new ArrayAdapter( - mContext, android.R.layout.simple_spinner_item, - res.getStringArray(R.array.wifi_peap_phase2_entries_with_sim_auth)); + mPhase2PeapAdapter = getSpinnerArrayWithEapMethodsTts( + R.array.wifi_peap_phase2_entries_with_sim_auth); } mPhase2PeapAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - mPhase2FullAdapter = new ArrayAdapter( + mPhase2FullAdapter = new ArrayAdapter( mContext, android.R.layout.simple_spinner_item, res.getStringArray(R.array.wifi_phase2_entries)); mPhase2FullAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); @@ -991,6 +991,12 @@ public class WifiConfigController implements TextWatcher, spinnerAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item); mEapMethodSpinner.setAdapter(spinnerAdapter); + } else { + final ArrayAdapter wifispinnerAdapter = + getSpinnerArrayWithEapMethodsTts(R.array.wifi_eap_method); + wifispinnerAdapter.setDropDownViewResource( + android.R.layout.simple_spinner_dropdown_item); + mEapMethodSpinner.setAdapter(wifispinnerAdapter); } mPhase2Spinner = (Spinner) mView.findViewById(R.id.phase2); mPhase2Spinner.setOnItemSelectedListener(this); @@ -1579,4 +1585,68 @@ public class WifiConfigController implements TextWatcher, ((CheckBox) mView.findViewById(R.id.wifi_advanced_togglebox)) .setOnCheckedChangeListener(this); } + + /** + * For each target string in {@code targetStringArray} try to find if it appears in {@code + * originalStringArray}, if found then use the corresponding string, which have the same index + * of the target string in {@code replacementStringArray}, to replace it. And finally return the + * whole new string array back to caller. + */ + @VisibleForTesting + CharSequence[] findAndReplaceTargetStrings(CharSequence originalStringArray[], + CharSequence targetStringArray[], CharSequence replacementStringArray[]) { + // The length of the targetStringArray and replacementStringArray should be the same, each + // item in the targetStringArray should have a 1:1 mapping to replacementStringArray, so + // just return the original string if the lengths are different. + if (targetStringArray.length != replacementStringArray.length) { + return originalStringArray; + } + + final CharSequence[] returnEntries = new CharSequence[originalStringArray.length]; + for (int i = 0; i < originalStringArray.length; i++) { + returnEntries[i] = originalStringArray[i]; + for (int j = 0; j < targetStringArray.length; j++) { + if (TextUtils.equals(originalStringArray[i], targetStringArray[j])) { + returnEntries[i] = replacementStringArray[j]; + } + } + } + return returnEntries; + } + + /** + * This function is to span the TTS strings to each EAP method items in the + * spinner to have detail TTS content for the TTS engine usage. + */ + private ArrayAdapter getSpinnerArrayWithEapMethodsTts(int resid) { + final Resources res = mContext.getResources(); + CharSequence[] sourceStrings = res.getStringArray( + resid); + CharSequence[] targetStrings = res.getStringArray( + R.array.wifi_eap_method_target_strings); + CharSequence[] ttsStrings = res.getStringArray( + R.array.wifi_eap_method_tts_strings); + + // Replace the target strings with tts strings and save all in a new array. + final CharSequence[] newTtsSourceStrings = findAndReplaceTargetStrings( + sourceStrings, targetStrings, ttsStrings); + + // Build new ttsspan text arrays for talkback. + final CharSequence[] accessibilityArray = createAccessibleEntries( + sourceStrings, newTtsSourceStrings); + + // Return a new ArrayAdapter with the new talkback array. + return new ArrayAdapter( + mContext, android.R.layout.simple_spinner_item, accessibilityArray); + } + + private SpannableString[] createAccessibleEntries(CharSequence entries[], + CharSequence[] contentDescriptions) { + final SpannableString[] accessibleEntries = new SpannableString[entries.length]; + for (int i = 0; i < entries.length; i++) { + accessibleEntries[i] = com.android.settings.Utils.createAccessibleSequence(entries[i], + contentDescriptions[i].toString()); + } + return accessibleEntries; + } } diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java index b16d90088cf..7acf1f0c4d0 100644 --- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java +++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; +import android.content.res.Resources; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.ServiceSpecificException; @@ -445,4 +446,43 @@ public class WifiConfigControllerTest { WifiConfiguration config = mController.getConfig(); assertThat(config.macRandomizationSetting).isEqualTo(WifiConfiguration.RANDOMIZATION_NONE); } + + @Test + public void replaceTtsString_whenTargetMatched_shouldSuccess() { + final CharSequence[] display = {"PEAP", "AKA1", "AKA2'"}; + final CharSequence[] target = {"AKA1", "AKA2'"}; + final CharSequence[] ttsString = {"AKA1_TTS", "AKA2_TTS"}; + + final CharSequence[] resultTts = mController.findAndReplaceTargetStrings(display, target, + ttsString); + + assertThat(resultTts[0]).isEqualTo("PEAP"); + assertThat(resultTts[1]).isEqualTo("AKA1_TTS"); + assertThat(resultTts[2]).isEqualTo("AKA2_TTS"); + } + + @Test + public void replaceTtsString_whenNoTargetStringMatched_originalStringShouldNotChanged() { + final CharSequence[] display = {"PEAP", "AKA1", "AKA2"}; + final CharSequence[] target = {"WEP1", "WEP2'"}; + final CharSequence[] ttsString = {"WEP1_TTS", "WEP2_TTS"}; + + final CharSequence[] resultTts = mController.findAndReplaceTargetStrings(display, target, + ttsString); + + assertThat(resultTts[0]).isEqualTo("PEAP"); + assertThat(resultTts[1]).isEqualTo("AKA1"); + assertThat(resultTts[2]).isEqualTo("AKA2"); + } + + @Test + public void checktEapMethodTargetAndTtsArraylength_shouldHaveSameCount() { + final Resources resources = mContext.getResources(); + final String[] targetStringArray = resources.getStringArray( + R.array.wifi_eap_method_target_strings); + final String[] ttsStringArray = resources.getStringArray( + R.array.wifi_eap_method_tts_strings); + + assertThat(targetStringArray.length).isEqualTo(ttsStringArray.length); + } }