Merge "Fixed accessibility issues in Wi-Fi SSID view for SUW" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
fb74cf60eb
@@ -545,13 +545,13 @@ public class WifiConfigController implements TextWatcher,
|
||||
&& !isValidSaePassword(mPasswordView.getText().toString())))) {
|
||||
passwordInvalid = true;
|
||||
}
|
||||
if ((mSsidView != null && mSsidView.length() == 0)
|
||||
// If Accesspoint is not saved, apply passwordInvalid check
|
||||
|| ((mAccessPoint == null || !mAccessPoint.isSaved()) && passwordInvalid
|
||||
// If AccessPoint is saved (modifying network) and password is changed, apply
|
||||
// Invalid password check
|
||||
|| mAccessPoint != null && mAccessPoint.isSaved() && passwordInvalid
|
||||
&& mPasswordView.length() > 0)) {
|
||||
if ((mAccessPoint == null || !mAccessPoint.isSaved()) && passwordInvalid) {
|
||||
// If Accesspoint is not saved, apply passwordInvalid check
|
||||
enabled = false;
|
||||
} else if (mAccessPoint != null && mAccessPoint.isSaved() && passwordInvalid
|
||||
&& mPasswordView.length() > 0) {
|
||||
// If AccessPoint is saved (modifying network) and password is changed, apply
|
||||
// Invalid password check
|
||||
enabled = false;
|
||||
} else {
|
||||
enabled = ipAndProxyFieldsAreValid();
|
||||
|
@@ -28,6 +28,8 @@ import android.widget.TextView;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.wifi.utils.SsidInputGroup;
|
||||
import com.android.settings.wifi.utils.WifiDialogHelper;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
@@ -62,6 +64,7 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase,
|
||||
private View mView;
|
||||
private WifiConfigController mController;
|
||||
private boolean mHideSubmitButton;
|
||||
private WifiDialogHelper mDialogHelper;
|
||||
|
||||
/**
|
||||
* Creates a WifiDialog with no additional style. It displays as a dialog above the current
|
||||
@@ -115,6 +118,9 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase,
|
||||
if (mAccessPoint == null) {
|
||||
mController.hideForgetButton();
|
||||
}
|
||||
|
||||
mDialogHelper = new WifiDialogHelper(this,
|
||||
new SsidInputGroup(getContext(), mView, R.id.ssid_layout, R.id.ssid));
|
||||
}
|
||||
|
||||
@SuppressWarnings("MissingSuperCall") // TODO: Fix me
|
||||
@@ -155,9 +161,6 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase,
|
||||
public void onClick(DialogInterface dialogInterface, int id) {
|
||||
if (mListener != null) {
|
||||
switch (id) {
|
||||
case BUTTON_SUBMIT:
|
||||
mListener.onSubmit(this);
|
||||
break;
|
||||
case BUTTON_FORGET:
|
||||
if (WifiUtils.isNetworkLockedDown(getContext(), mAccessPoint.getConfig())) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(),
|
||||
@@ -170,6 +173,11 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase,
|
||||
}
|
||||
}
|
||||
|
||||
/** Return true to tell the parent activity to call onSubmit before onDismiss. */
|
||||
public boolean shouldSubmitBeforeFinish() {
|
||||
return mDialogHelper.isPositive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMode() {
|
||||
return mMode;
|
||||
|
@@ -346,6 +346,9 @@ public class WifiDialogActivity extends ObservableActivity implements WifiDialog
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface) {
|
||||
mDialog2 = null;
|
||||
if (mDialog != null && mDialog.shouldSubmitBeforeFinish()) {
|
||||
onSubmit(mDialog);
|
||||
}
|
||||
mDialog = null;
|
||||
finish();
|
||||
}
|
||||
|
49
src/com/android/settings/wifi/utils/AlertDialogHelper.kt
Normal file
49
src/com/android/settings/wifi/utils/AlertDialogHelper.kt
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.DialogInterface
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
|
||||
open class AlertDialogHelper(val alertDialog: AlertDialog) {
|
||||
|
||||
var isPositive = false
|
||||
|
||||
init {
|
||||
alertDialog.setOnShowListener {
|
||||
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE)?.setOnClickListener {
|
||||
onPositiveButtonClicked()
|
||||
} ?: Log.e(TAG, "Can't get the positive button!")
|
||||
}
|
||||
}
|
||||
|
||||
open fun onPositiveButtonClicked() {
|
||||
if (!canDismiss()) {
|
||||
Log.w(TAG, "Can't dismiss dialog!")
|
||||
return
|
||||
}
|
||||
isPositive = true
|
||||
alertDialog.dismiss()
|
||||
}
|
||||
|
||||
open fun canDismiss() = true
|
||||
|
||||
companion object {
|
||||
const val TAG = "AlertDialogHelper"
|
||||
}
|
||||
}
|
36
src/com/android/settings/wifi/utils/WifiDialogHelper.kt
Normal file
36
src/com/android/settings/wifi/utils/WifiDialogHelper.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.util.Log
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
|
||||
class WifiDialogHelper(
|
||||
alertDialog: AlertDialog,
|
||||
private val ssidInputGroup: SsidInputGroup? = null,
|
||||
) : AlertDialogHelper(alertDialog) {
|
||||
|
||||
override fun canDismiss(): Boolean {
|
||||
val isValid = ssidInputGroup?.validate() ?: true
|
||||
if (!isValid) Log.w(TAG, "SSID is invalid!")
|
||||
return isValid
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "WifiDialogHelper"
|
||||
}
|
||||
}
|
@@ -145,14 +145,6 @@ public class WifiConfigControllerTest {
|
||||
.isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSubmittable_noSSID_shouldReturnFalse() {
|
||||
final TextView ssid = mView.findViewById(R.id.ssid);
|
||||
assertThat(ssid).isNotNull();
|
||||
ssid.setText("");
|
||||
assertThat(mController.isSubmittable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSubmittable_longPsk_shouldReturnFalse() {
|
||||
final TextView password = mView.findViewById(R.id.password);
|
||||
|
@@ -349,4 +349,14 @@ public class WifiDialogActivityTest {
|
||||
|
||||
verify(mActivity).dismissDialog();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDismiss_shouldSubmitBeforeFinish_callOnSubmit() {
|
||||
mActivity.mDialog = mWifiDialog;
|
||||
when(mWifiDialog.shouldSubmitBeforeFinish()).thenReturn(true);
|
||||
|
||||
mActivity.onDismiss(mWifiDialog);
|
||||
|
||||
verify(mActivity).onSubmit(mWifiDialog);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user