summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yiyi Shen <yiyishen@google.com> 2025-03-18 19:54:50 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-18 19:54:50 -0700
commitc90913596461a4d1f463c03540b169280e5aae88 (patch)
tree5aedec6b3b719e4a454c37e7cec6b32e19a77e7a
parent8341d348d09241ad0cd4ade34f8307f68c8ba139 (diff)
parent999ae5d9a8f91c5190c368f32192b19befc79065 (diff)
Merge "[Audiosharing] Cache callbacks when service not ready" into main
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/LeAudioProfile.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LeAudioProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LeAudioProfile.java
index 155c7e6530aa..e46574cef917 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LeAudioProfile.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LeAudioProfile.java
@@ -37,9 +37,11 @@ import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.android.settingslib.R;
+import com.android.settingslib.flags.Flags;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
public class LeAudioProfile implements LocalBluetoothProfile {
@@ -59,6 +61,10 @@ public class LeAudioProfile implements LocalBluetoothProfile {
// Order of this profile in device profiles list
private static final int ORDINAL = 1;
+ // Cached callbacks being registered before service is connected.
+ private ConcurrentHashMap<BluetoothLeAudio.Callback, Executor>
+ mCachedCallbackExecutorMap = new ConcurrentHashMap<>();
+
// These callbacks run on the main thread.
private final class LeAudioServiceListener implements BluetoothProfile.ServiceListener {
@@ -88,7 +94,19 @@ public class LeAudioProfile implements LocalBluetoothProfile {
// Check current list of CachedDevices to see if any are hearing aid devices.
mDeviceManager.updateHearingAidsDevices();
mProfileManager.callServiceConnectedListeners();
- mIsProfileReady = true;
+ if (!mIsProfileReady) {
+ mIsProfileReady = true;
+ if (Flags.adoptPrimaryGroupManagementApiV2()) {
+ if (DEBUG) {
+ Log.d(
+ TAG,
+ "onServiceConnected, register mCachedCallbackExecutorMap = "
+ + mCachedCallbackExecutorMap);
+ }
+ mCachedCallbackExecutorMap.forEach(
+ (callback, executor) -> registerCallback(executor, callback));
+ }
+ }
}
public void onServiceDisconnected(int profile) {
@@ -96,7 +114,12 @@ public class LeAudioProfile implements LocalBluetoothProfile {
Log.d(TAG, "Bluetooth service disconnected");
}
mProfileManager.callServiceDisconnectedListeners();
- mIsProfileReady = false;
+ if (mIsProfileReady) {
+ mIsProfileReady = false;
+ if (Flags.adoptPrimaryGroupManagementApiV2()) {
+ mCachedCallbackExecutorMap.clear();
+ }
+ }
}
}
@@ -367,6 +390,9 @@ public class LeAudioProfile implements LocalBluetoothProfile {
@NonNull BluetoothLeAudio.Callback callback) {
if (mService == null) {
Log.w(TAG, "Proxy not attached to service. Cannot register callback.");
+ if (Flags.adoptPrimaryGroupManagementApiV2()) {
+ mCachedCallbackExecutorMap.putIfAbsent(callback, executor);
+ }
return;
}
mService.registerCallback(executor, callback);
@@ -384,6 +410,9 @@ public class LeAudioProfile implements LocalBluetoothProfile {
* callback is registered
*/
public void unregisterCallback(@NonNull BluetoothLeAudio.Callback callback) {
+ if (Flags.adoptPrimaryGroupManagementApiV2()) {
+ mCachedCallbackExecutorMap.remove(callback);
+ }
if (mService == null) {
Log.w(TAG, "Proxy not attached to service. Cannot unregister callback.");
return;