Merge "Fix npe when broadcast code is null." into main
This commit is contained in:
@@ -13975,13 +13975,15 @@
|
||||
<string name="audio_sharing_share_with_button_label">Share with <xliff:g example="My buds" id="device_name">%1$s</xliff:g></string>
|
||||
<!-- Text for audio sharing close button [CHAR LIMIT=none]-->
|
||||
<string name="audio_sharing_close_button_label">Close</string>
|
||||
<!-- Content for audio sharing share dialog with no device, ask users to connect device [CHAR LIMIT=none]-->
|
||||
<!-- Content for audio sharing share dialog with no second device, ask users to connect device [CHAR LIMIT=none]-->
|
||||
<string name="audio_sharing_dialog_connect_device_content">Connect another pair of compatible headphones, or share your stream\'s name and password with the other person</string>
|
||||
<!-- Content for audio sharing share dialog with no device, ask users to scan qr code [CHAR LIMIT=none]-->
|
||||
<!-- Content for audio sharing share dialog with no second device, ask users to scan qr code [CHAR LIMIT=none]-->
|
||||
<string name="audio_sharing_dialog_qr_code_content">Let others scan this code and listen to your audio\n\nStream name: <xliff:g example="Pixel 8" id="stream_name">%1$s</xliff:g>\nPassword: <xliff:g example="123456" id="password">%2$s</xliff:g></string>
|
||||
<!-- Content for audio sharing share dialog with no device, ask users to pair new device [CHAR LIMIT=none]-->
|
||||
<!-- Content for audio sharing share dialog with no second device and no password, ask users to scan qr code [CHAR LIMIT=none]-->
|
||||
<string name="audio_sharing_dialog_qr_code_content_no_password">Let others scan this code and listen to your audio\n\nStream name: <xliff:g example="Pixel 8" id="stream_name">%1$s</xliff:g></string>
|
||||
<!-- Content for audio sharing share dialog with no second device, ask users to pair new device [CHAR LIMIT=none]-->
|
||||
<string name="audio_sharing_dialog_pair_new_device_content">or pair another set of compatible headphones</string>
|
||||
<!-- Content for audio sharing share dialog with no device, ask users to pair device [CHAR LIMIT=none]-->
|
||||
<!-- Content for audio sharing share dialog with no second device, ask users to pair device [CHAR LIMIT=none]-->
|
||||
<string name="audio_sharing_dialog_pair_device_content">Pair another set of compatible headphones, or share your audio stream QR code with the other person</string>
|
||||
<!-- Text for sharing audio sharing state [CHAR LIMIT=none]-->
|
||||
<string name="audio_sharing_sharing_label">Sharing audio</string>
|
||||
|
@@ -186,14 +186,17 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
|
||||
Drawable qrCodeDrawable = metadata == null ? null : getQrCodeDrawable(metadata,
|
||||
getContext()).orElse(null);
|
||||
if (qrCodeDrawable != null) {
|
||||
String broadcastName =
|
||||
metadata.getBroadcastName() == null ? "" : metadata.getBroadcastName();
|
||||
boolean hasPassword = metadata.getBroadcastCode() != null
|
||||
&& metadata.getBroadcastCode().length > 0;
|
||||
String message = hasPassword ? getString(
|
||||
R.string.audio_sharing_dialog_qr_code_content, broadcastName,
|
||||
new String(metadata.getBroadcastCode(), StandardCharsets.UTF_8)) :
|
||||
getString(R.string.audio_sharing_dialog_qr_code_content_no_password,
|
||||
broadcastName);
|
||||
builder.setCustomImage(qrCodeDrawable)
|
||||
.setCustomMessage(
|
||||
getString(
|
||||
R.string.audio_sharing_dialog_qr_code_content,
|
||||
metadata.getBroadcastName(),
|
||||
new String(
|
||||
metadata.getBroadcastCode(),
|
||||
StandardCharsets.UTF_8)))
|
||||
.setCustomMessage(message)
|
||||
.setCustomMessage2(R.string.audio_sharing_dialog_pair_new_device_content)
|
||||
.setCustomNegativeButton(R.string.audio_streams_dialog_close,
|
||||
v -> onCancelClick());
|
||||
|
@@ -93,8 +93,14 @@ public class AudioSharingDialogFragmentTest {
|
||||
private static final String METADATA_STR =
|
||||
"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=;;";
|
||||
private static final String METADATA_STR_NO_PASSWORD =
|
||||
"BLUETOOTH:UUID:184F;BN:SG9ja2V5;AT:0;AD:AABBCC001122;BI:DE51E9;SQ:1;AS:1;PI:FFFF;"
|
||||
+ "NS:1;BS:1;NB:1;;";
|
||||
private static final BluetoothLeBroadcastMetadata METADATA =
|
||||
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(METADATA_STR);
|
||||
private static final BluetoothLeBroadcastMetadata METADATA_NO_PASSWORD =
|
||||
BluetoothLeBroadcastMetadataExt.INSTANCE.convertToBroadcastMetadata(
|
||||
METADATA_STR_NO_PASSWORD);
|
||||
|
||||
private Fragment mParent;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
@@ -290,6 +296,50 @@ public class AudioSharingDialogFragmentTest {
|
||||
assertThat(dialog.isShowing()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_noExtraConnectedDevice_hasMetadataNoPassword_showCancelButton() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
AtomicBoolean isCancelBtnClicked = new AtomicBoolean(false);
|
||||
AudioSharingDialogFragment.show(
|
||||
mParent,
|
||||
new ArrayList<>(),
|
||||
METADATA_NO_PASSWORD,
|
||||
new AudioSharingDialogFragment.DialogEventListener() {
|
||||
@Override
|
||||
public void onCancelClick() {
|
||||
isCancelBtnClicked.set(true);
|
||||
}
|
||||
},
|
||||
TEST_EVENT_DATA_LIST);
|
||||
shadowMainLooper().idle();
|
||||
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||
assertThat(dialog).isNotNull();
|
||||
ImageView image = dialog.findViewById(R.id.description_image);
|
||||
assertThat(image).isNotNull();
|
||||
TextView text = dialog.findViewById(R.id.description_text);
|
||||
assertThat(text).isNotNull();
|
||||
assertThat(METADATA_NO_PASSWORD).isNotNull();
|
||||
assertThat(text.getText().toString()).isEqualTo(
|
||||
mParent.getString(R.string.audio_sharing_dialog_qr_code_content_no_password,
|
||||
METADATA_NO_PASSWORD.getBroadcastName()));
|
||||
TextView textBottom = dialog.findViewById(R.id.description_text_2);
|
||||
assertThat(textBottom).isNotNull();
|
||||
assertThat(textBottom.getText().toString()).isEqualTo(
|
||||
mParent.getString(R.string.audio_sharing_dialog_pair_new_device_content));
|
||||
Button cancelBtn = dialog.findViewById(R.id.negative_btn);
|
||||
assertThat(cancelBtn).isNotNull();
|
||||
cancelBtn.performClick();
|
||||
shadowMainLooper().idle();
|
||||
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(
|
||||
any(Context.class),
|
||||
eq(SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_NEGATIVE_BTN_CLICKED),
|
||||
eq(TEST_EVENT_DATA));
|
||||
assertThat(isCancelBtnClicked.get()).isTrue();
|
||||
assertThat(dialog.isShowing()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateDialog_flagOn_singleExtraConnectedDevice() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
|
||||
|
Reference in New Issue
Block a user