Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae7acae2 authored by chelseahao's avatar chelseahao Committed by Chelsea Hao
Browse files

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
parent 75e2dc4b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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"
+3 −1
Original line number Diff line number Diff line
@@ -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]-->
+10 −0
Original line number Diff line number Diff line
@@ -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");
+5 −1
Original line number Diff line number Diff line
@@ -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
+23 −2
Original line number Diff line number Diff line
@@ -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 isTextValid_emptyString_showEditTextFormatAlert() {
        mController.displayPreference(mScreen);
        ShadowLooper.idleMainLooper();
        boolean valid = mController.isTextValid("");

        assertThat(valid).isFalse();
        verify(mPreference).showEditTextFormatAlert(true);
    }

    @Test
    public void idTextValid_validPassword() {
    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);
    }
}
Loading