Fix npe when broadcast code is null.

Test: atest
Bug: b/381775542
Flag: com.android.settingslib.flags.enable_le_audio_sharing
Change-Id: Id342a4b3ce26927d5ae76c866da07763bf8fbfbe
This commit is contained in:
chelseahao
2025-02-13 15:18:28 +08:00
committed by Chelsea Hao
parent 87a4a3dec8
commit af4b7112f0
3 changed files with 66 additions and 11 deletions

View File

@@ -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());