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

Commit d964109a authored by Chelsea Hao's avatar Chelsea Hao Committed by Android (Google) Code Review
Browse files

Merge "Allow only password between 4 to 16 character." into main

parents 73196499 0f73d15b
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -18,9 +18,12 @@ package com.android.settings.connecteddevice.audiosharing.audiostreams;

import android.app.AlertDialog;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

@@ -109,6 +112,20 @@ class SyncedState extends AudioStreamStateHandler {
                                    controller.handleSourceAddRequest(preference, metadata);
                                })
                        .create();
        EditText editText = layout.requireViewById(R.id.broadcast_edit_text);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
                        .setEnabled(s.length() >= 4 && s.length() <= 16);
            }
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
            @Override
            public void afterTextChanged(Editable s) {}
        });
        alertDialog.show();
        Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        positiveButton.setEnabled(false);
    }
}
+13 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.preference.Preference;
@@ -59,6 +60,8 @@ import org.robolectric.shadows.ShadowLooper;
        })
public class SyncedStateTest {
    @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
    private static final String INVALID_PASSWORD = "PAS";
    private static final String VALID_PASSWORD = "PASSWORD";
    private static final String ENCRYPTED_METADATA =
            "BLUETOOTH:UUID:184F;BN:VGVzdA==;AT:1;AD:00A1A1A1A1A1;BI:1E240;BC:VGVzdENvZGU=;"
                    + "MD:BgNwVGVzdA==;AS:1;PI:A0;NS:1;BS:3;NB:2;SM:BQNUZXN0BARlbmc=;;";
@@ -143,15 +146,24 @@ public class SyncedStateTest {

        Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
        assertThat(positiveButton).isNotNull();
        assertThat(positiveButton.isEnabled()).isFalse();
        assertThat(positiveButton.getText().toString())
                .isEqualTo(
                        mMockContext.getString(R.string.bluetooth_connect_access_dialog_positive));

        ShadowAlertDialog shadowDialog = Shadow.extract(dialog);
        EditText editText = shadowDialog.getView().findViewById(R.id.broadcast_edit_text);
        assertThat(editText).isNotNull();
        editText.setText(VALID_PASSWORD);
        assertThat(positiveButton.isEnabled()).isTrue();
        editText.setText(INVALID_PASSWORD);
        assertThat(positiveButton.isEnabled()).isFalse();

        editText.setText(VALID_PASSWORD);
        positiveButton.callOnClick();
        ShadowLooper.idleMainLooper();
        verify(mMockController).handleSourceAddRequest(any(), any());

        ShadowAlertDialog shadowDialog = Shadow.extract(dialog);
        TextView title = shadowDialog.getView().findViewById(R.id.broadcast_name_text);
        assertThat(title).isNotNull();
        assertThat(title.getText().toString()).isEqualTo(BROADCAST_TITLE);