Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 832e8eda authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "[Audiosharing] Register/unregister callback on service connection" into main

parents 3c7007a6 9b9e68b9
Loading
Loading
Loading
Loading
+70 −10
Original line number Diff line number Diff line
@@ -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,7 +100,9 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile
                    }

                    mProfileManager.callServiceConnectedListeners();
                    if (!mIsProfileReady) {
                        mIsProfileReady = true;
                        registerServiceCallBack(mExecutor, mAssistantCallback);
                        if (DEBUG) {
                            Log.d(
                                    TAG,
@@ -106,7 +110,9 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile
                                            + mCachedCallbackExecutorMap);
                        }
                        mCachedCallbackExecutorMap.forEach(
                            (callback, executor) -> registerServiceCallBack(executor, callback));
                                (callback, executor) -> registerServiceCallBack(executor,
                                        callback));
                    }
                }

                @Override
@@ -119,9 +125,62 @@ public class LocalBluetoothLeBroadcastAssistant implements LocalBluetoothProfile
                        Log.d(TAG, "Bluetooth service disconnected");
                    }
                    mProfileManager.callServiceDisconnectedListeners();
                    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);