Merge "Fixed accessibility issues in Wi-Fi SSID view" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
22e2cd594e
@@ -16,11 +16,13 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/l_wifidialog"
|
android:id="@+id/l_wifidialog"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="8dip">
|
android:paddingBottom="8dip"
|
||||||
|
android:theme="@style/Theme.AppCompat.DayNight">
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/wep_warning_layout"
|
<LinearLayout android:id="@+id/wep_warning_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -50,30 +52,34 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/wifi_item">
|
style="@style/wifi_item">
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
style="@style/wifi_item_label"
|
|
||||||
android:text="@string/wifi_ssid"
|
|
||||||
android:textDirection="locale"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<EditText android:id="@+id/ssid"
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:layout_width="0dp"
|
android:id="@+id/ssid_layout"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_weight="1"
|
android:layout_height="wrap_content"
|
||||||
style="@style/wifi_item_edit_content"
|
android:layout_weight="1"
|
||||||
android:hint="@string/wifi_ssid_hint"
|
android:hint="@string/wifi_ssid"
|
||||||
android:singleLine="true"
|
android:theme="@style/Theme.Settings"
|
||||||
android:inputType="textNoSuggestions"/>
|
android:textDirection="locale"
|
||||||
|
app:endIconMode="clear_text"
|
||||||
|
app:errorEnabled="true">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/ssid"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="textNoSuggestions"
|
||||||
|
android:singleLine="true"/>
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/ssid_scanner_button"
|
android:id="@+id/ssid_scanner_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:minWidth="@dimen/min_tap_target_size"
|
android:minWidth="@dimen/min_tap_target_size"
|
||||||
android:minHeight="@dimen/min_tap_target_size"
|
android:minHeight="@dimen/min_tap_target_size"
|
||||||
android:background="?android:attr/selectableItemBackground"
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
@@ -234,6 +234,9 @@ public class AddNetworkFragment extends InstrumentedFragment implements WifiConf
|
|||||||
|
|
||||||
activity.getSystemService(WifiManager.class).save(config, saveListener);
|
activity.getSystemService(WifiManager.class).save(config, saveListener);
|
||||||
} else {
|
} else {
|
||||||
|
if (!mUIController.canFinish()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(WIFI_CONFIG_KEY, config);
|
intent.putExtra(WIFI_CONFIG_KEY, config);
|
||||||
activity.setResult(Activity.RESULT_OK, intent);
|
activity.setResult(Activity.RESULT_OK, intent);
|
||||||
|
@@ -77,6 +77,7 @@ import com.android.settings.utils.AndroidKeystoreAliasLoader;
|
|||||||
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController;
|
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController;
|
||||||
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
|
import com.android.settings.wifi.details2.WifiPrivacyPreferenceController2;
|
||||||
import com.android.settings.wifi.dpp.WifiDppUtils;
|
import com.android.settings.wifi.dpp.WifiDppUtils;
|
||||||
|
import com.android.settings.wifi.utils.SsidInputGroup;
|
||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
import com.android.wifi.flags.Flags;
|
import com.android.wifi.flags.Flags;
|
||||||
@@ -228,7 +229,7 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
private final boolean mHideMeteredAndPrivacy;
|
private final boolean mHideMeteredAndPrivacy;
|
||||||
private final WifiManager mWifiManager;
|
private final WifiManager mWifiManager;
|
||||||
private final AndroidKeystoreAliasLoader mAndroidKeystoreAliasLoader;
|
private final AndroidKeystoreAliasLoader mAndroidKeystoreAliasLoader;
|
||||||
private TextView mSsidView;
|
private SsidInputGroup mSsidInputGroup;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
@@ -298,6 +299,7 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
wepWarningLayout.setVisibility(View.VISIBLE);
|
wepWarningLayout.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mSsidInputGroup = new SsidInputGroup(mContext, mView, R.id.ssid_layout, R.id.ssid);
|
||||||
mSsidScanButton = (ImageButton) mView.findViewById(R.id.ssid_scanner_button);
|
mSsidScanButton = (ImageButton) mView.findViewById(R.id.ssid_scanner_button);
|
||||||
mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
|
mIpSettingsSpinner = (Spinner) mView.findViewById(R.id.ip_settings);
|
||||||
mIpSettingsSpinner.setOnItemSelectedListener(this);
|
mIpSettingsSpinner.setOnItemSelectedListener(this);
|
||||||
@@ -544,13 +546,13 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
&& !isValidSaePassword(mPasswordView.getText().toString())))) {
|
&& !isValidSaePassword(mPasswordView.getText().toString())))) {
|
||||||
passwordInvalid = true;
|
passwordInvalid = true;
|
||||||
}
|
}
|
||||||
if ((mSsidView != null && mSsidView.length() == 0)
|
if ((mWifiEntry == null || !mWifiEntry.isSaved()) && passwordInvalid) {
|
||||||
// If WifiEntry is not saved, apply passwordInvalid check
|
// If WifiEntry is not saved, apply passwordInvalid check
|
||||||
|| ((mWifiEntry == null || !mWifiEntry.isSaved()) && passwordInvalid
|
enabled = false;
|
||||||
// If WifiEntry is saved (modifying network) and password is changed, apply
|
} else if (mWifiEntry != null && mWifiEntry.isSaved() && passwordInvalid
|
||||||
// Invalid password check
|
&& mPasswordView.length() > 0) {
|
||||||
|| mWifiEntry != null && mWifiEntry.isSaved() && passwordInvalid
|
// If WifiEntry is saved (modifying network) and password is changed, apply
|
||||||
&& mPasswordView.length() > 0)) {
|
// Invalid password check
|
||||||
enabled = false;
|
enabled = false;
|
||||||
} else {
|
} else {
|
||||||
enabled = ipAndProxyFieldsAreValid();
|
enabled = ipAndProxyFieldsAreValid();
|
||||||
@@ -586,16 +588,21 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean canFinish() {
|
||||||
|
if (!mSsidInputGroup.validate()) {
|
||||||
|
Log.w(TAG, "Can't finish because SSID is invalid!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void showWarningMessagesIfAppropriate() {
|
void showWarningMessagesIfAppropriate() {
|
||||||
mView.findViewById(R.id.no_user_cert_warning).setVisibility(View.GONE);
|
mView.findViewById(R.id.no_user_cert_warning).setVisibility(View.GONE);
|
||||||
mView.findViewById(R.id.no_domain_warning).setVisibility(View.GONE);
|
mView.findViewById(R.id.no_domain_warning).setVisibility(View.GONE);
|
||||||
mView.findViewById(R.id.ssid_too_long_warning).setVisibility(View.GONE);
|
mView.findViewById(R.id.ssid_too_long_warning).setVisibility(View.GONE);
|
||||||
|
|
||||||
if (mSsidView != null) {
|
if (WifiUtils.isSSIDTooLong(mSsidInputGroup.getText())) {
|
||||||
final String ssid = mSsidView.getText().toString();
|
mView.findViewById(R.id.ssid_too_long_warning).setVisibility(View.VISIBLE);
|
||||||
if (WifiUtils.isSSIDTooLong(ssid)) {
|
|
||||||
mView.findViewById(R.id.ssid_too_long_warning).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mEapCaCertSpinner != null
|
if (mEapCaCertSpinner != null
|
||||||
&& mView.findViewById(R.id.l_ca_cert).getVisibility() != View.GONE) {
|
&& mView.findViewById(R.id.l_ca_cert).getVisibility() != View.GONE) {
|
||||||
@@ -628,7 +635,7 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
WifiConfiguration config;
|
WifiConfiguration config;
|
||||||
if (mWifiEntry == null) {
|
if (mWifiEntry == null) {
|
||||||
config = new WifiConfiguration();
|
config = new WifiConfiguration();
|
||||||
config.SSID = "\"" + mSsidView.getText().toString() + "\"";
|
config.SSID = "\"" + mSsidInputGroup.getText() + "\"";
|
||||||
// If the user adds a network manually, assume that it is hidden.
|
// If the user adds a network manually, assume that it is hidden.
|
||||||
config.hiddenSSID = mHiddenSettingsSpinner.getSelectedItemPosition() == HIDDEN_NETWORK;
|
config.hiddenSSID = mHiddenSettingsSpinner.getSelectedItemPosition() == HIDDEN_NETWORK;
|
||||||
} else if (mWifiEntry.isSaved()) {
|
} else if (mWifiEntry.isSaved()) {
|
||||||
@@ -1823,8 +1830,7 @@ public class WifiConfigController2 implements TextWatcher,
|
|||||||
private void configureSecuritySpinner() {
|
private void configureSecuritySpinner() {
|
||||||
mConfigUi.setTitle(R.string.wifi_add_network);
|
mConfigUi.setTitle(R.string.wifi_add_network);
|
||||||
|
|
||||||
mSsidView = (TextView) mView.findViewById(R.id.ssid);
|
mSsidInputGroup.addTextChangedListener(this);
|
||||||
mSsidView.addTextChangedListener(this);
|
|
||||||
mSecuritySpinner = ((Spinner) mView.findViewById(R.id.security));
|
mSecuritySpinner = ((Spinner) mView.findViewById(R.id.security));
|
||||||
mSecuritySpinner.setOnItemSelectedListener(this);
|
mSecuritySpinner.setOnItemSelectedListener(this);
|
||||||
|
|
||||||
|
34
src/com/android/settings/wifi/utils/SsidInputGroup.kt
Normal file
34
src/com/android/settings/wifi/utils/SsidInputGroup.kt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.wifi.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.View
|
||||||
|
import com.android.settings.R
|
||||||
|
|
||||||
|
/** TextInputGroup for Wi-Fi SSID. */
|
||||||
|
class SsidInputGroup(private val context: Context, view: View, layoutId: Int, editTextId: Int) :
|
||||||
|
TextInputGroup(view, layoutId, editTextId) {
|
||||||
|
|
||||||
|
fun validate(): Boolean {
|
||||||
|
if (getText().isEmpty()) {
|
||||||
|
setError(context.getString(R.string.wifi_ssid_hint))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
68
src/com/android/settings/wifi/utils/TextInputGroup.kt
Normal file
68
src/com/android/settings/wifi/utils/TextInputGroup.kt
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.wifi.utils
|
||||||
|
|
||||||
|
import android.text.Editable
|
||||||
|
import android.text.TextWatcher
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.EditText
|
||||||
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
|
|
||||||
|
/** A widget that wraps the relationship work between a TextInputLayout and an EditText. */
|
||||||
|
open class TextInputGroup(
|
||||||
|
private val view: View,
|
||||||
|
private val layoutId: Int,
|
||||||
|
private val editTextId: Int,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val View.layout: TextInputLayout?
|
||||||
|
get() = findViewById(layoutId)
|
||||||
|
|
||||||
|
private val View.editText: EditText?
|
||||||
|
get() = findViewById(editTextId)
|
||||||
|
|
||||||
|
private val textWatcher =
|
||||||
|
object : TextWatcher {
|
||||||
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
|
||||||
|
|
||||||
|
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
|
||||||
|
|
||||||
|
override fun afterTextChanged(s: Editable?) {
|
||||||
|
view.layout?.isErrorEnabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
addTextChangedListener(textWatcher)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addTextChangedListener(watcher: TextWatcher) {
|
||||||
|
view.editText?.addTextChangedListener(watcher)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getText(): String {
|
||||||
|
return view.editText?.text?.toString() ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setText(text: String) {
|
||||||
|
view.editText?.setText(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setError(errorMessage: String?) {
|
||||||
|
view.layout?.apply { error = errorMessage }
|
||||||
|
}
|
||||||
|
}
|
@@ -193,15 +193,6 @@ public class WifiConfigController2Test {
|
|||||||
.isEqualTo(View.GONE);
|
.isEqualTo(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isSubmittable_noSSID_shouldReturnFalse() {
|
|
||||||
createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
|
|
||||||
final TextView ssid = mView.findViewById(R.id.ssid);
|
|
||||||
assertThat(ssid).isNotNull();
|
|
||||||
ssid.setText("");
|
|
||||||
assertThat(mController.isSubmittable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSubmittable_longPsk_shouldReturnFalse() {
|
public void isSubmittable_longPsk_shouldReturnFalse() {
|
||||||
createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
|
createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
|
||||||
@@ -1048,6 +1039,24 @@ public class WifiConfigController2Test {
|
|||||||
verify(mController.mEapAnonymousView, never()).setText(any(String.class));
|
verify(mController.mEapAnonymousView, never()).setText(any(String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void canFinish_ssidIsEmpty_returnFalse() {
|
||||||
|
createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
|
||||||
|
TextView ssid = mView.findViewById(R.id.ssid);
|
||||||
|
ssid.setText("");
|
||||||
|
|
||||||
|
assertThat(mController.canFinish()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void canFinish_ssidIsGood_returnTrue() {
|
||||||
|
createController(null, WifiConfigUiBase2.MODE_CONNECT, false);
|
||||||
|
TextView ssid = mView.findViewById(R.id.ssid);
|
||||||
|
ssid.setText(GOOD_SSID);
|
||||||
|
|
||||||
|
assertThat(mController.canFinish()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
private void setUpModifyingSavedCertificateConfigController(String savedCaCertificate,
|
private void setUpModifyingSavedCertificateConfigController(String savedCaCertificate,
|
||||||
String savedUserCertificate) {
|
String savedUserCertificate) {
|
||||||
final WifiConfiguration mockWifiConfig = spy(new WifiConfiguration());
|
final WifiConfiguration mockWifiConfig = spy(new WifiConfiguration());
|
||||||
|
Reference in New Issue
Block a user