Show error message when inputting invalid audio sharing password.
Test: atest Bug: b/356071394 Flag: com.android.settingslib.flags.enable_le_audio_sharing Change-Id: I6e1ff6d32175ad6e4286db922645d608a2708c45
This commit is contained in:
@@ -35,6 +35,17 @@
|
||||
android:layout_marginEnd="20dp"
|
||||
android:minHeight="48dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/edit_alert_message"
|
||||
style="?android:attr/textAppearanceSmall"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:visibility="gone"
|
||||
android:text="@string/audio_streams_main_page_password_dialog_format_alert"
|
||||
android:textColor="?android:attr/colorError" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@@ -13725,8 +13725,10 @@
|
||||
<string name="audio_streams_main_page_password_dialog_join_button">Listen to stream</string>
|
||||
<!-- Le audio streams main page qr code scanner summary [CHAR LIMIT=NONE] -->
|
||||
<string name="audio_streams_main_page_qr_code_scanner_summary">Scan an audio stream QR code to listen with <xliff:g example="LE headset" id="device_name">%1$s</xliff:g></string>
|
||||
<!-- Le audio streams password dialog [CHAR LIMIT=NONE] -->
|
||||
<!-- Le audio streams password dialog not editable message [CHAR LIMIT=NONE] -->
|
||||
<string name="audio_streams_main_page_password_dialog_cannot_edit">Can\u0027t edit password while sharing. To change the password, first turn off audio sharing.</string>
|
||||
<!-- Le audio streams password dialog password format alert [CHAR LIMIT=NONE] -->
|
||||
<string name="audio_streams_main_page_password_dialog_format_alert">Your password must contain 4-16 characters and use only letters, numbers and symbols</string>
|
||||
<!-- Text for audio sharing qrcode scanner [CHAR LIMIT=none]-->
|
||||
<string name="audio_streams_qr_code_scanner_label">QR code scanner</string>
|
||||
<!-- Learn more link for audio sharing qrcode [CHAR LIMIT=none]-->
|
||||
|
@@ -41,6 +41,7 @@ public class AudioSharingPasswordPreference extends ValidatedEditTextPreference
|
||||
@Nullable private EditText mEditText;
|
||||
@Nullable private CheckBox mCheckBox;
|
||||
@Nullable private View mDialogMessage;
|
||||
@Nullable private View mEditTextFormatAlert;
|
||||
private boolean mEditable = true;
|
||||
|
||||
interface OnDialogEventListener {
|
||||
@@ -77,6 +78,7 @@ public class AudioSharingPasswordPreference extends ValidatedEditTextPreference
|
||||
mEditText = view.findViewById(android.R.id.edit);
|
||||
mCheckBox = view.findViewById(R.id.audio_sharing_stream_password_checkbox);
|
||||
mDialogMessage = view.findViewById(android.R.id.message);
|
||||
mEditTextFormatAlert = view.findViewById(R.id.edit_alert_message);
|
||||
|
||||
if (mEditText == null || mCheckBox == null || mDialogMessage == null) {
|
||||
Log.w(TAG, "onBindDialogView() : Invalid layout");
|
||||
@@ -123,6 +125,14 @@ public class AudioSharingPasswordPreference extends ValidatedEditTextPreference
|
||||
mDialogMessage.setVisibility(editable ? GONE : VISIBLE);
|
||||
}
|
||||
|
||||
void showEditTextFormatAlert(boolean show) {
|
||||
if (mEditTextFormatAlert == null) {
|
||||
Log.w(TAG, "showEditTextFormatAlert() : Invalid layout");
|
||||
return;
|
||||
}
|
||||
mEditTextFormatAlert.setVisibility(show ? VISIBLE : GONE);
|
||||
}
|
||||
|
||||
void setChecked(boolean checked) {
|
||||
if (mCheckBox == null) {
|
||||
Log.w(TAG, "setChecked() : Invalid layout");
|
||||
|
@@ -136,7 +136,11 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont
|
||||
|
||||
@Override
|
||||
public boolean isTextValid(String value) {
|
||||
return mAudioSharingPasswordValidator.isTextValid(value);
|
||||
boolean isValid = mAudioSharingPasswordValidator.isTextValid(value);
|
||||
if (mPreference != null) {
|
||||
mPreference.showEditTextFormatAlert(!isValid);
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -320,16 +320,37 @@ public class AudioSharingPasswordPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void idTextValid_emptyString() {
|
||||
public void isTextValid_emptyString() {
|
||||
boolean valid = mController.isTextValid("");
|
||||
|
||||
assertThat(valid).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void idTextValid_validPassword() {
|
||||
public void isTextValid_emptyString_showEditTextFormatAlert() {
|
||||
mController.displayPreference(mScreen);
|
||||
ShadowLooper.idleMainLooper();
|
||||
boolean valid = mController.isTextValid("");
|
||||
|
||||
assertThat(valid).isFalse();
|
||||
verify(mPreference).showEditTextFormatAlert(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isTextValid_validPassword() {
|
||||
boolean valid = mController.isTextValid(BROADCAST_PASSWORD);
|
||||
|
||||
assertThat(valid).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isTextValid_validPassword_hideEditTextFormatAlert() {
|
||||
mController.displayPreference(mScreen);
|
||||
ShadowLooper.idleMainLooper();
|
||||
boolean valid = mController.isTextValid(BROADCAST_PASSWORD);
|
||||
|
||||
assertThat(valid).isTrue();
|
||||
verify(mPreference).showEditTextFormatAlert(false);
|
||||
}
|
||||
}
|
||||
|
@@ -71,10 +71,12 @@ public class AudioSharingPasswordPreferenceTest {
|
||||
var editText = view.findViewById(android.R.id.edit);
|
||||
var checkBox = view.findViewById(R.id.audio_sharing_stream_password_checkbox);
|
||||
var dialogMessage = view.findViewById(android.R.id.message);
|
||||
var editTextAlertMessage = view.findViewById(R.id.edit_alert_message);
|
||||
|
||||
assertThat(editText).isNotNull();
|
||||
assertThat(checkBox).isNotNull();
|
||||
assertThat(dialogMessage).isNotNull();
|
||||
assertThat(editTextAlertMessage).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,6 +149,34 @@ public class AudioSharingPasswordPreferenceTest {
|
||||
assertThat(checkBox.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showEditTextFormatAlert_show() {
|
||||
View view =
|
||||
LayoutInflater.from(mContext).inflate(R.layout.audio_sharing_password_dialog, null);
|
||||
mPreference.onBindDialogView(view);
|
||||
|
||||
var editTextAlertMessage = view.findViewById(R.id.edit_alert_message);
|
||||
|
||||
mPreference.showEditTextFormatAlert(true);
|
||||
|
||||
assertThat(editTextAlertMessage).isNotNull();
|
||||
assertThat(editTextAlertMessage.getVisibility()).isEqualTo(VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showEditTextFormatAlert_hide() {
|
||||
View view =
|
||||
LayoutInflater.from(mContext).inflate(R.layout.audio_sharing_password_dialog, null);
|
||||
mPreference.onBindDialogView(view);
|
||||
|
||||
var editTextAlertMessage = view.findViewById(R.id.edit_alert_message);
|
||||
|
||||
mPreference.showEditTextFormatAlert(false);
|
||||
|
||||
assertThat(editTextAlertMessage).isNotNull();
|
||||
assertThat(editTextAlertMessage.getVisibility()).isEqualTo(GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDialogEventListener_onClick_positiveButton() {
|
||||
AudioSharingPasswordPreference.OnDialogEventListener listener =
|
||||
|
Reference in New Issue
Block a user