diff options
| author | 2022-07-29 06:18:29 +0000 | |
|---|---|---|
| committer | 2022-07-29 06:18:29 +0000 | |
| commit | e2d4dcf0e5a827231424e4fad5ac9466beff6b7a (patch) | |
| tree | 3deb5324fd7158900401b264981683d3fe210aad | |
| parent | f52b49886c3ad3a62109b704300e015c61674a8f (diff) | |
| parent | f77dbb4c4a7da5fdbff8fea555dc95f3827befef (diff) | |
Merge "[LeBroadcast] Fix the NullPointerException for launching dialog" into tm-qpr-dev
3 files changed, 31 insertions, 3 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java index bf6975714acd..01d581ed28db 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java @@ -303,6 +303,18 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { } public BluetoothLeBroadcastMetadata getLatestBluetoothLeBroadcastMetadata() { + if (mService == null) { + Log.d(TAG, "The BluetoothLeBroadcast is null"); + return null; + } + if (mBluetoothLeBroadcastMetadata == null) { + final List<BluetoothLeBroadcastMetadata> metadataList = + mService.getAllBroadcastMetadata(); + mBluetoothLeBroadcastMetadata = metadataList.stream() + .filter(i -> i.getBroadcastId() == mBroadcastId) + .findFirst() + .orElse(null); + } return mBluetoothLeBroadcastMetadata; } @@ -372,7 +384,12 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { } public LocalBluetoothLeBroadcastMetadata getLocalBluetoothLeBroadcastMetaData() { - return new LocalBluetoothLeBroadcastMetadata(mBluetoothLeBroadcastMetadata); + final BluetoothLeBroadcastMetadata metadata = getLatestBluetoothLeBroadcastMetadata(); + if (metadata == null) { + Log.d(TAG, "The BluetoothLeBroadcastMetadata is null."); + return null; + } + return new LocalBluetoothLeBroadcastMetadata(metadata); } public boolean isProfileReady() { diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java index 0d5cab688d72..4ef98cf13a00 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java @@ -101,6 +101,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements private int mListMaxHeight; private WallpaperColors mWallpaperColors; private Executor mExecutor; + private boolean mShouldLaunchLeBroadcastDialog; MediaOutputBaseAdapter mAdapter; @@ -399,7 +400,9 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements } public void handleLeBroadcastStarted() { - startLeBroadcastDialog(); + // Waiting for the onBroadcastMetadataChanged. The UI launchs the broadcast dialog when + // the metadata is ready. + mShouldLaunchLeBroadcastDialog = true; } public void handleLeBroadcastStartFailed() { @@ -409,10 +412,15 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements } public void handleLeBroadcastMetadataChanged() { + if (mShouldLaunchLeBroadcastDialog) { + startLeBroadcastDialog(); + mShouldLaunchLeBroadcastDialog = false; + } refresh(); } public void handleLeBroadcastStopped() { + mShouldLaunchLeBroadcastDialog = false; refresh(); } diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java index 7e3275da8c31..52dbfe572474 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java @@ -62,6 +62,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.Utils; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; +import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastMetadata; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.media.InfoMediaManager; import com.android.settingslib.media.LocalMediaManager; @@ -834,7 +835,9 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, Log.d(TAG, "getBroadcastMetadata: LE Audio Broadcast is null"); return ""; } - return broadcast.getLocalBluetoothLeBroadcastMetaData().convertToQrCodeString(); + final LocalBluetoothLeBroadcastMetadata metadata = + broadcast.getLocalBluetoothLeBroadcastMetaData(); + return metadata != null ? metadata.convertToQrCodeString() : ""; } boolean isActiveRemoteDevice(@NonNull MediaDevice device) { |