From 548cc04bf67eadac6f49f11c93dabb7689a95a63 Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Tue, 12 Jul 2022 21:54:17 +0800 Subject: [PATCH] [LeAudioBroadcast] avoid the system register mBroadcastCallback again There is a "java.lang.IllegalArgumentException: This callback has already been registered". The system did not disconnect and notifiy service connect, and it caused the system register the callback again. Bug: 238374344 Bug: 234312198 Test: build pass. Change-Id: Iaec1d9d9458add983f3a06f5c30414bce3ce5be5 --- .../bluetooth/LocalBluetoothLeBroadcast.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java index bf9debf5cccea..bf6975714acd2 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java @@ -87,9 +87,11 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { if (DEBUG) { Log.d(TAG, "Bluetooth service connected"); } - mService = (BluetoothLeBroadcast) proxy; - mIsProfileReady = true; - registerServiceCallBack(mExecutor, mBroadcastCallback); + if(!mIsProfileReady) { + mService = (BluetoothLeBroadcast) proxy; + mIsProfileReady = true; + registerServiceCallBack(mExecutor, mBroadcastCallback); + } } @Override @@ -97,8 +99,10 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { if (DEBUG) { Log.d(TAG, "Bluetooth service disconnected"); } - mIsProfileReady = false; - unregisterServiceCallBack(mBroadcastCallback); + if(mIsProfileReady) { + mIsProfileReady = false; + unregisterServiceCallBack(mBroadcastCallback); + } } };