diff --git a/res/layout/audio_sharing_password_dialog.xml b/res/layout/audio_sharing_password_dialog.xml index 2bdf505290d..a862f3b5110 100644 --- a/res/layout/audio_sharing_password_dialog.xml +++ b/res/layout/audio_sharing_password_dialog.xml @@ -35,6 +35,17 @@ android:layout_marginEnd="20dp" android:minHeight="48dp" /> + + Listen to stream Scan an audio stream QR code to listen with %1$s - + Can\u0027t edit password while sharing. To change the password, first turn off audio sharing. + + Your password must contain 4-16 characters and use only letters, numbers and symbols QR code scanner diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreference.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreference.java index e3bbfb7c6cb..17dcc7f017f 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreference.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreference.java @@ -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"); diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceController.java index 9a27a93c9f6..7cc8058117c 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceController.java @@ -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 diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceControllerTest.java index 5bfb9663e11..8885e41b657 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceControllerTest.java @@ -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); + } } diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceTest.java index 0b87e8ca25d..20b8319a7c0 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceTest.java @@ -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 =