Merge "[LeBroadcast] Fix the NullPointerException for launching dialog" into tm-qpr-dev am: e2d4dcf0e5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19378986

Change-Id: I778d41179531c7c1d267c6aa3720088340dc1e6f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
SongFerng Wang
2022-07-29 06:58:17 +00:00
committed by Automerger Merge Worker
3 changed files with 31 additions and 3 deletions

View File

@@ -303,6 +303,18 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
} }
public BluetoothLeBroadcastMetadata getLatestBluetoothLeBroadcastMetadata() { 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; return mBluetoothLeBroadcastMetadata;
} }
@@ -372,7 +384,12 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
} }
public LocalBluetoothLeBroadcastMetadata getLocalBluetoothLeBroadcastMetaData() { 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() { public boolean isProfileReady() {

View File

@@ -101,6 +101,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
private int mListMaxHeight; private int mListMaxHeight;
private WallpaperColors mWallpaperColors; private WallpaperColors mWallpaperColors;
private Executor mExecutor; private Executor mExecutor;
private boolean mShouldLaunchLeBroadcastDialog;
MediaOutputBaseAdapter mAdapter; MediaOutputBaseAdapter mAdapter;
@@ -399,7 +400,9 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
} }
public void handleLeBroadcastStarted() { public void handleLeBroadcastStarted() {
startLeBroadcastDialog(); // Waiting for the onBroadcastMetadataChanged. The UI launchs the broadcast dialog when
// the metadata is ready.
mShouldLaunchLeBroadcastDialog = true;
} }
public void handleLeBroadcastStartFailed() { public void handleLeBroadcastStartFailed() {
@@ -409,10 +412,15 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements
} }
public void handleLeBroadcastMetadataChanged() { public void handleLeBroadcastMetadataChanged() {
if (mShouldLaunchLeBroadcastDialog) {
startLeBroadcastDialog();
mShouldLaunchLeBroadcastDialog = false;
}
refresh(); refresh();
} }
public void handleLeBroadcastStopped() { public void handleLeBroadcastStopped() {
mShouldLaunchLeBroadcastDialog = false;
refresh(); refresh();
} }

View File

@@ -62,6 +62,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastMetadata;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.media.InfoMediaManager; import com.android.settingslib.media.InfoMediaManager;
import com.android.settingslib.media.LocalMediaManager; 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"); Log.d(TAG, "getBroadcastMetadata: LE Audio Broadcast is null");
return ""; return "";
} }
return broadcast.getLocalBluetoothLeBroadcastMetaData().convertToQrCodeString(); final LocalBluetoothLeBroadcastMetadata metadata =
broadcast.getLocalBluetoothLeBroadcastMetaData();
return metadata != null ? metadata.convertToQrCodeString() : "";
} }
boolean isActiveRemoteDevice(@NonNull MediaDevice device) { boolean isActiveRemoteDevice(@NonNull MediaDevice device) {