From 50f8f639df24f484d5493bafbfa66c7c5ecffbd5 Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Wed, 21 Sep 2022 13:28:27 +0800 Subject: [LE Broadcast]Fix the crash in the BluetoothLeBroadcast constructor The onServiceConnected is called, but the constructor is not finished. Bug: 247058040 Test: build pass. local test and don't encounter the crash Change-Id: I806446a893fd3ca18ee926b0bc7d2ceed2717902 --- .../android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java index 123c01b6e12f..79fb56602328 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java @@ -210,13 +210,15 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { LocalBluetoothLeBroadcast(Context context) { mExecutor = Executors.newSingleThreadExecutor(); - BluetoothAdapter.getDefaultAdapter(). - getProfileProxy(context, mServiceListener, BluetoothProfile.LE_AUDIO_BROADCAST); mBuilder = new BluetoothLeAudioContentMetadata.Builder(); mContentResolver = context.getContentResolver(); Handler handler = new Handler(Looper.getMainLooper()); mSettingsObserver = new BroadcastSettingsObserver(handler); updateBroadcastInfoFromContentProvider(); + + // Before registering callback, the constructor should finish creating the all of variables. + BluetoothAdapter.getDefaultAdapter() + .getProfileProxy(context, mServiceListener, BluetoothProfile.LE_AUDIO_BROADCAST); } /** -- cgit v1.2.3-59-g8ed1b