diff options
author | 2024-10-11 02:49:01 +0000 | |
---|---|---|
committer | 2024-10-11 02:49:01 +0000 | |
commit | 832e8edacf5e53e7ef1da6aa0e189ed3e7ee450d (patch) | |
tree | a1f1dcb9d9754dbc285f4f5e937f249aeb5c20f3 | |
parent | 3c7007a602684e686f01646f73de92ebae758ad4 (diff) | |
parent | 9b9e68b92194f8cc8c1ffdc3ce9593ff0ec12451 (diff) |
Merge "[Audiosharing] Register/unregister callback on service connection" into main
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java | 80 |
1 files changed, 70 insertions, 10 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java index c9f9d1be9c15..a4c5a00dc53e 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcastAssistant.java @@ -42,6 +42,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; +import java.util.concurrent.Executors; /** * LocalBluetoothLeBroadcastAssistant provides an interface between the Settings app and the @@ -63,6 +64,7 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile private BluetoothLeBroadcastMetadata mBluetoothLeBroadcastMetadata; private BluetoothLeBroadcastMetadata.Builder mBuilder; private boolean mIsProfileReady; + private Executor mExecutor; // Cached assistant callbacks being register before service is connected. private final Map<BluetoothLeBroadcastAssistant.Callback, Executor> mCachedCallbackExecutorMap = new ConcurrentHashMap<>(); @@ -98,15 +100,19 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile } mProfileManager.callServiceConnectedListeners(); - mIsProfileReady = true; - if (DEBUG) { - Log.d( - TAG, - "onServiceConnected, register mCachedCallbackExecutorMap = " - + mCachedCallbackExecutorMap); + if (!mIsProfileReady) { + mIsProfileReady = true; + registerServiceCallBack(mExecutor, mAssistantCallback); + if (DEBUG) { + Log.d( + TAG, + "onServiceConnected, register mCachedCallbackExecutorMap = " + + mCachedCallbackExecutorMap); + } + mCachedCallbackExecutorMap.forEach( + (callback, executor) -> registerServiceCallBack(executor, + callback)); } - mCachedCallbackExecutorMap.forEach( - (callback, executor) -> registerServiceCallBack(executor, callback)); } @Override @@ -119,9 +125,62 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile Log.d(TAG, "Bluetooth service disconnected"); } mProfileManager.callServiceDisconnectedListeners(); - mIsProfileReady = false; - mCachedCallbackExecutorMap.clear(); + if (mIsProfileReady) { + mIsProfileReady = false; + unregisterServiceCallBack(mAssistantCallback); + mCachedCallbackExecutorMap.clear(); + } + } + }; + + private final BluetoothLeBroadcastAssistant.Callback mAssistantCallback = + new BluetoothLeBroadcastAssistant.Callback() { + @Override + public void onSourceAdded(@NonNull BluetoothDevice sink, int sourceId, int reason) { } + + @Override + public void onSearchStarted(int reason) {} + + @Override + public void onSearchStartFailed(int reason) {} + + @Override + public void onSearchStopped(int reason) {} + + @Override + public void onSearchStopFailed(int reason) {} + + @Override + public void onSourceFound(@NonNull BluetoothLeBroadcastMetadata source) {} + + @Override + public void onSourceAddFailed( + @NonNull BluetoothDevice sink, + @NonNull BluetoothLeBroadcastMetadata source, + int reason) {} + + @Override + public void onSourceModified( + @NonNull BluetoothDevice sink, int sourceId, int reason) {} + + @Override + public void onSourceModifyFailed( + @NonNull BluetoothDevice sink, int sourceId, int reason) {} + + @Override + public void onSourceRemoved( + @NonNull BluetoothDevice sink, int sourceId, int reason) {} + + @Override + public void onSourceRemoveFailed( + @NonNull BluetoothDevice sink, int sourceId, int reason) {} + + @Override + public void onReceiveStateChanged( + @NonNull BluetoothDevice sink, + int sourceId, + @NonNull BluetoothLeBroadcastReceiveState state) {} }; public LocalBluetoothLeBroadcastAssistant( @@ -130,6 +189,7 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile LocalBluetoothProfileManager profileManager) { mProfileManager = profileManager; mDeviceManager = deviceManager; + mExecutor = Executors.newSingleThreadExecutor(); BluetoothAdapter.getDefaultAdapter() .getProfileProxy( context, mServiceListener, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT); |