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

Commit 08aa1722 authored by Yiyi Shen's avatar Yiyi Shen
Browse files

[Audiosharing] Use onBroadcastToUnicastFallbackGroupChanged callback

Flag: com.android.settingslib.flags.adopt_primary_group_management_api_v2
Test: atest
Bug: 397568136

Change-Id: I18f6eb2028a95b25f7a3a5742aa9456e06c21955
parent 4dc8d326
Loading
Loading
Loading
Loading
+56 −7
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothLeAudioCodecStatus;
import android.bluetooth.BluetoothLeBroadcastAssistant;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
@@ -82,6 +84,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
    }

    @Nullable private final LocalBluetoothManager mBtManager;
    @Nullable private final LeAudioProfile mLeAudio;
    @Nullable private final BluetoothEventManager mEventManager;
    @Nullable private final ContentResolver mContentResolver;
    @Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant;
@@ -148,6 +151,30 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
                        int sourceId,
                        @NonNull BluetoothLeBroadcastReceiveState state) {}
            };
    @VisibleForTesting
    final BluetoothLeAudio.Callback mLeAudioCallback = new BluetoothLeAudio.Callback() {
        @Override
        public void onBroadcastToUnicastFallbackGroupChanged(int groupId) {
            if (!Flags.adoptPrimaryGroupManagementApiV2()) return;
            Log.d(TAG, "onBroadcastToUnicastFallbackGroupChanged, group id = " + groupId);
            var unused =
                    ThreadUtils.postOnBackgroundThread(
                            AudioSharingCallAudioPreferenceController.this::updateSummary);
        }

        @Override
        public void onCodecConfigChanged(int i,
                @NonNull BluetoothLeAudioCodecStatus bluetoothLeAudioCodecStatus) {}

        @Override
        public void onGroupNodeAdded(@NonNull BluetoothDevice bluetoothDevice, int i) {}

        @Override
        public void onGroupNodeRemoved(@NonNull BluetoothDevice bluetoothDevice, int i) {}

        @Override
        public void onGroupStatusChanged(int i, int i1) {}
    };

    public AudioSharingCallAudioPreferenceController(Context context) {
        super(context, PREF_KEY);
@@ -155,6 +182,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
        LocalBluetoothProfileManager profileManager =
                mBtManager == null ? null : mBtManager.getProfileManager();
        mEventManager = mBtManager == null ? null : mBtManager.getEventManager();
        mLeAudio = profileManager == null ? null : profileManager.getLeAudioProfile();
        mAssistant =
                profileManager == null
                        ? null
@@ -173,6 +201,8 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP

        @Override
        public void onChange(boolean selfChange) {
            if (Flags.adoptPrimaryGroupManagementApiV2()) return;
            // TODO: remove content observer once switch to API
            Log.d(TAG, "onChange, fallback device group id has been changed");
            var unused =
                    ThreadUtils.postOnBackgroundThread(
@@ -289,7 +319,8 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
            Log.d(TAG, "Skip registerCallbacks(). Feature is not available.");
            return;
        }
        if (mEventManager == null || mContentResolver == null || mAssistant == null) {
        if (mEventManager == null || mAssistant == null || (Flags.adoptPrimaryGroupManagementApiV2()
                ? mLeAudio == null : mContentResolver == null)) {
            Log.d(
                    TAG,
                    "Skip registerCallbacks(). Init is not ready: eventManager = "
@@ -301,10 +332,19 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
        if (!mCallbacksRegistered.get()) {
            Log.d(TAG, "registerCallbacks()");
            mEventManager.registerCallback(this);
            if (Flags.adoptPrimaryGroupManagementApiV2()) {
                if (mLeAudio != null) { // To pass nullability pre-submit
                    mLeAudio.registerCallback(mExecutor, mLeAudioCallback);
                }
            } else {
                if (mContentResolver != null) { // To pass nullability pre-submit
                    mContentResolver.registerContentObserver(
                    Settings.Secure.getUriFor(BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                            Settings.Secure.getUriFor(
                                    BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                            false,
                            mSettingsObserver);
                }
            }
            mAssistant.registerServiceCallBack(mExecutor, mBroadcastAssistantCallback);
            mIsAudioModeOngoingCall.set(isAudioModeOngoingCall(mContext));
            mCallbacksRegistered.set(true);
@@ -316,14 +356,23 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
            Log.d(TAG, "Skip unregisterCallbacks(). Feature is not available.");
            return;
        }
        if (mEventManager == null || mContentResolver == null || mAssistant == null) {
        if (mEventManager == null || mAssistant == null || (Flags.adoptPrimaryGroupManagementApiV2()
                ? mLeAudio == null : mContentResolver == null)) {
            Log.d(TAG, "Skip unregisterCallbacks(). Init is not ready.");
            return;
        }
        if (mCallbacksRegistered.get()) {
            Log.d(TAG, "unregisterCallbacks()");
            mEventManager.unregisterCallback(this);
            if (Flags.adoptPrimaryGroupManagementApiV2()) {
                if (mLeAudio != null) { // To pass nullability pre-submit
                    mLeAudio.unregisterCallback(mLeAudioCallback);
                }
            } else {
                if (mContentResolver != null) { // To pass nullability pre-submit
                    mContentResolver.unregisterContentObserver(mSettingsObserver);
                }
            }
            mAssistant.unregisterServiceCallBack(mBroadcastAssistantCallback);
            mCallbacksRegistered.set(false);
        }
+60 −10
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.EXTRA_
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothLeAudioCodecStatus;
import android.bluetooth.BluetoothLeBroadcastAssistant;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
@@ -90,6 +92,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
    @Nullable private final CachedBluetoothDeviceManager mDeviceManager;
    @Nullable private final BluetoothEventManager mEventManager;
    @Nullable private final LocalBluetoothProfileManager mProfileManager;
    @Nullable private final LeAudioProfile mLeAudio;
    @Nullable private final LocalBluetoothLeBroadcast mBroadcast;
    @Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant;
    @Nullable private final ContentResolver mContentResolver;
@@ -103,7 +106,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
    private AtomicBoolean mIsAudioModeOngoingCall = new AtomicBoolean(false);

    @VisibleForTesting
    BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
    final BluetoothLeBroadcastAssistant.Callback mBroadcastAssistantCallback =
            new BluetoothLeBroadcastAssistant.Callback() {
                @Override
                public void onSearchStarted(int reason) {}
@@ -193,10 +196,37 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
                        @NonNull BluetoothLeBroadcastReceiveState state) {}
            };

    @VisibleForTesting
    final BluetoothLeAudio.Callback mLeAudioCallback = new BluetoothLeAudio.Callback() {
        @Override
        public void onBroadcastToUnicastFallbackGroupChanged(int groupId) {
            if (!Flags.adoptPrimaryGroupManagementApiV2()) return;
            Log.d(TAG, "onBroadcastToUnicastFallbackGroupChanged, group id = " + groupId);
            if (mBluetoothDeviceUpdater != null) {
                mBluetoothDeviceUpdater.refreshPreference();
            }
        }

        @Override
        public void onCodecConfigChanged(int i,
                @NonNull BluetoothLeAudioCodecStatus bluetoothLeAudioCodecStatus) {}

        @Override
        public void onGroupNodeAdded(@NonNull BluetoothDevice bluetoothDevice, int i) {}

        @Override
        public void onGroupNodeRemoved(@NonNull BluetoothDevice bluetoothDevice, int i) {}

        @Override
        public void onGroupStatusChanged(int i, int i1) {}
    };

    @VisibleForTesting
    ContentObserver mSettingsObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
        @Override
        public void onChange(boolean selfChange) {
            if (Flags.adoptPrimaryGroupManagementApiV2()) return;
            // TODO: remove content observer once switch to API
            Log.d(TAG, "onChange, primary group id has been changed, refresh list");
            if (mBluetoothDeviceUpdater != null) {
                mBluetoothDeviceUpdater.refreshPreference();
@@ -210,6 +240,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
        mEventManager = mBtManager == null ? null : mBtManager.getEventManager();
        mDeviceManager = mBtManager == null ? null : mBtManager.getCachedDeviceManager();
        mProfileManager = mBtManager == null ? null : mBtManager.getProfileManager();
        mLeAudio = mProfileManager == null ? null : mProfileManager.getLeAudioProfile();
        mBroadcast = mProfileManager == null ? null : mProfileManager.getLeAudioBroadcastProfile();
        mAssistant =
                mProfileManager == null
@@ -235,8 +266,9 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
            if (mEventManager == null
                    || mAssistant == null
                    || mDialogHandler == null
                    || mContentResolver == null
                    || mBluetoothDeviceUpdater == null) {
                    || mBluetoothDeviceUpdater == null
                    || (Flags.adoptPrimaryGroupManagementApiV2() ? mLeAudio == null
                    : mContentResolver == null)) {
                Log.d(TAG, "Skip onStart(), profile is not ready.");
                return;
            }
@@ -244,10 +276,19 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
            mEventManager.registerCallback(this);
            mAssistant.registerServiceCallBack(mExecutor, mBroadcastAssistantCallback);
            mDialogHandler.registerCallbacks(mExecutor);
            if (Flags.adoptPrimaryGroupManagementApiV2()) {
                if (mLeAudio != null) { // To pass nullability pre-submit
                    mLeAudio.registerCallback(mExecutor, mLeAudioCallback);
                }
            } else {
                if (mContentResolver != null) { // To pass nullability pre-submit
                    mContentResolver.registerContentObserver(
                    Settings.Secure.getUriFor(BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                            Settings.Secure.getUriFor(
                                    BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                            false,
                            mSettingsObserver);
                }
            }
            mBluetoothDeviceUpdater.registerCallback();
            mBluetoothDeviceUpdater.refreshPreference();
            mIsAudioModeOngoingCall.set(isAudioModeOngoingCall(mContext));
@@ -268,8 +309,9 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
            if (mEventManager == null
                    || mAssistant == null
                    || mDialogHandler == null
                    || mContentResolver == null
                    || mBluetoothDeviceUpdater == null) {
                    || mBluetoothDeviceUpdater == null
                    || (Flags.adoptPrimaryGroupManagementApiV2() ? mLeAudio == null
                    : mContentResolver == null)) {
                Log.d(TAG, "Skip onStop(), profile is not ready.");
                return;
            }
@@ -277,7 +319,15 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro
            mEventManager.unregisterCallback(this);
            mAssistant.unregisterServiceCallBack(mBroadcastAssistantCallback);
            mDialogHandler.unregisterCallbacks();
            if (Flags.adoptPrimaryGroupManagementApiV2()) {
                if (mLeAudio != null) { // To pass nullability pre-submit
                    mLeAudio.unregisterCallback(mLeAudioCallback);
                }
            } else {
                if (mContentResolver != null) { // To pass nullability pre-submit
                    mContentResolver.unregisterContentObserver(mSettingsObserver);
                }
            }
            mBluetoothDeviceUpdater.unregisterCallback();
        });
    }
+60 −7
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.settings.connecteddevice.audiosharing;
import android.annotation.IntRange;
import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothLeAudioCodecStatus;
import android.bluetooth.BluetoothLeBroadcastAssistant;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
@@ -46,10 +48,12 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LeAudioProfile;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.bluetooth.VolumeControlProfile;
import com.android.settingslib.flags.Flags;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -65,6 +69,7 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre

    @Nullable private final LocalBluetoothManager mBtManager;
    @Nullable private final LocalBluetoothProfileManager mProfileManager;
    @Nullable private final LeAudioProfile mLeAudio;
    @Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant;
    @Nullable private final VolumeControlProfile mVolumeControl;
    @Nullable private final ContentResolver mContentResolver;
@@ -173,10 +178,37 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
                        @NonNull BluetoothLeBroadcastReceiveState state) {}
            };

    @VisibleForTesting
    final BluetoothLeAudio.Callback mLeAudioCallback = new BluetoothLeAudio.Callback() {
        @Override
        public void onBroadcastToUnicastFallbackGroupChanged(int groupId) {
            if (!Flags.adoptPrimaryGroupManagementApiV2()) return;
            Log.d(TAG, "onBroadcastToUnicastFallbackGroupChanged, group id = " + groupId);
            for (AudioSharingDeviceVolumePreference preference : mVolumePreferences) {
                int order = getPreferenceOrderForDevice(preference.getCachedDevice());
                AudioSharingUtils.postOnMainThread(mContext, () -> preference.setOrder(order));
            }
        }

        @Override
        public void onCodecConfigChanged(int i,
                @NonNull BluetoothLeAudioCodecStatus bluetoothLeAudioCodecStatus) {}

        @Override
        public void onGroupNodeAdded(@NonNull BluetoothDevice bluetoothDevice, int i) {}

        @Override
        public void onGroupNodeRemoved(@NonNull BluetoothDevice bluetoothDevice, int i) {}

        @Override
        public void onGroupStatusChanged(int i, int i1) {}
    };

    public AudioSharingDeviceVolumeGroupController(Context context) {
        super(context, KEY);
        mBtManager = Utils.getLocalBtManager(mContext);
        mProfileManager = mBtManager == null ? null : mBtManager.getProfileManager();
        mLeAudio = mProfileManager == null ? null : mProfileManager.getLeAudioProfile();
        mAssistant =
                mProfileManager == null
                        ? null
@@ -194,6 +226,8 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre

        @Override
        public void onChange(boolean selfChange) {
            if (Flags.adoptPrimaryGroupManagementApiV2()) return;
            // TODO: remove content observer once switch to API
            Log.d(TAG, "onChange, fallback device group id has been changed");
            for (AudioSharingDeviceVolumePreference preference : mVolumePreferences) {
                int order = getPreferenceOrderForDevice(preference.getCachedDevice());
@@ -358,7 +392,8 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
        if (mAssistant == null
                || mVolumeControl == null
                || mBluetoothDeviceUpdater == null
                || mContentResolver == null
                || (Flags.adoptPrimaryGroupManagementApiV2() ? mLeAudio == null
                : mContentResolver == null)
                || !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
            Log.d(TAG, "Skip registerCallbacks(). Profile is not ready.");
            return;
@@ -369,10 +404,19 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
            mVolumeControl.registerCallback(mExecutor, mVolumeControlCallback);
            mBluetoothDeviceUpdater.registerCallback();
            mBluetoothDeviceUpdater.refreshPreference();
            if (Flags.adoptPrimaryGroupManagementApiV2()) {
                if (mLeAudio != null) { // To pass nullability pre-submit
                    mLeAudio.registerCallback(mExecutor, mLeAudioCallback);
                }
            } else {
                if (mContentResolver != null) { // To pass nullability pre-submit
                    mContentResolver.registerContentObserver(
                    Settings.Secure.getUriFor(BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                            Settings.Secure.getUriFor(
                                    BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                            false,
                            mSettingsObserver);
                }
            }
            mCallbacksRegistered.set(true);
        }
    }
@@ -385,7 +429,8 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
        if (mAssistant == null
                || mVolumeControl == null
                || mBluetoothDeviceUpdater == null
                || mContentResolver == null
                || (Flags.adoptPrimaryGroupManagementApiV2() ? mLeAudio == null
                : mContentResolver == null)
                || !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
            Log.d(TAG, "Skip unregisterCallbacks(). Profile is not ready.");
            return;
@@ -395,7 +440,15 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre
            mAssistant.unregisterServiceCallBack(mBroadcastAssistantCallback);
            mVolumeControl.unregisterCallback(mVolumeControlCallback);
            mBluetoothDeviceUpdater.unregisterCallback();
            if (Flags.adoptPrimaryGroupManagementApiV2()) {
                if (mLeAudio != null) { // To pass nullability pre-submit
                    mLeAudio.unregisterCallback(mLeAudioCallback);
                }
            } else {
                if (mContentResolver != null) { // To pass nullability pre-submit
                    mContentResolver.unregisterContentObserver(mSettingsObserver);
                }
            }
            mValueMap.clear();
            mCallbacksRegistered.set(false);
        }
+7 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.settingslib.bluetooth.VolumeControlProfile;
import com.android.settingslib.flags.Flags;

import java.util.ArrayList;
import java.util.Comparator;
@@ -342,6 +343,12 @@ public class AudioSharingUtils {
        if (assistant == null || !assistant.isProfileReady()) {
            return false;
        }
        if (Flags.adoptPrimaryGroupManagementApiV2()) {
            LeAudioProfile leAudio = profileManager.getLeAudioProfile();
            if (leAudio == null || !leAudio.isProfileReady()) {
                return false;
            }
        }
        VolumeControlProfile vc = profileManager.getVolumeControlProfile();
        return vc != null && vc.isProfileReady();
    }
+43 −3
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothCsipSetCoordinator;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothLeBroadcastAssistant;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
@@ -174,6 +175,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
        when(mBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast);
        when(mBtProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant);
        when(mBtProfileManager.getVolumeControlProfile()).thenReturn(mVolumeControl);
        when(mLeaProfile.isProfileReady()).thenReturn(true);
        when(mBroadcast.isProfileReady()).thenReturn(true);
        when(mAssistant.isProfileReady()).thenReturn(true);
        when(mVolumeControl.isProfileReady()).thenReturn(true);
@@ -222,13 +224,15 @@ public class AudioSharingCallAudioPreferenceControllerTest {
                                BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                        false,
                        mContentObserver);
        verify(mLeaProfile, never()).registerCallback(any(), any(BluetoothLeAudio.Callback.class));
        verify(mAssistant, never())
                .registerServiceCallBack(any(), any(BluetoothLeBroadcastAssistant.Callback.class));
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    public void onStart_flagOn_registerCallback() {
    @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
    public void onStart_flagOn_registerCallbackIncludingContentObserver() {
        mController.onStart(mLifecycleOwner);
        verify(mBtEventManager).registerCallback(mController);
        verify(mContentResolver)
@@ -237,6 +241,24 @@ public class AudioSharingCallAudioPreferenceControllerTest {
                                BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                        false,
                        mContentObserver);
        verify(mLeaProfile, never()).registerCallback(any(), any(BluetoothLeAudio.Callback.class));
        verify(mAssistant)
                .registerServiceCallBack(any(), any(BluetoothLeBroadcastAssistant.Callback.class));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2})
    public void onStart_flagOn_registerCallbackIncludingLeaProfile() {
        mController.onStart(mLifecycleOwner);
        verify(mBtEventManager).registerCallback(mController);
        verify(mContentResolver, never())
                .registerContentObserver(
                        Settings.Secure.getUriFor(
                                BluetoothUtils.getPrimaryGroupIdUriForBroadcast()),
                        false,
                        mContentObserver);
        verify(mLeaProfile).registerCallback(any(), any(BluetoothLeAudio.Callback.class));
        verify(mAssistant)
                .registerServiceCallBack(any(), any(BluetoothLeBroadcastAssistant.Callback.class));
    }
@@ -248,6 +270,7 @@ public class AudioSharingCallAudioPreferenceControllerTest {
        mController.onStop(mLifecycleOwner);
        verify(mBtEventManager, never()).unregisterCallback(mController);
        verify(mContentResolver, never()).unregisterContentObserver(mContentObserver);
        verify(mLeaProfile, never()).registerCallback(any(), any(BluetoothLeAudio.Callback.class));
        verify(mAssistant, never())
                .unregisterServiceCallBack(any(BluetoothLeBroadcastAssistant.Callback.class));
    }
@@ -259,17 +282,33 @@ public class AudioSharingCallAudioPreferenceControllerTest {
        mController.onStop(mLifecycleOwner);
        verify(mBtEventManager, never()).unregisterCallback(mController);
        verify(mContentResolver, never()).unregisterContentObserver(mContentObserver);
        verify(mLeaProfile, never()).registerCallback(any(), any(BluetoothLeAudio.Callback.class));
        verify(mAssistant, never())
                .unregisterServiceCallBack(any(BluetoothLeBroadcastAssistant.Callback.class));
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    public void onStop_flagOn_registered_unregisterCallback() {
    @DisableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2)
    public void onStop_flagOn_registered_unregisterCallbackIncludingContentObserver() {
        mController.setCallbacksRegistered(true);
        mController.onStop(mLifecycleOwner);
        verify(mBtEventManager).unregisterCallback(mController);
        verify(mContentResolver).unregisterContentObserver(mContentObserver);
        verify(mLeaProfile, never()).unregisterCallback(any(BluetoothLeAudio.Callback.class));
        verify(mAssistant)
                .unregisterServiceCallBack(any(BluetoothLeBroadcastAssistant.Callback.class));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING,
            Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API_V2})
    public void onStop_flagOn_registered_unregisterCallbackIncludingLeaProfile() {
        mController.setCallbacksRegistered(true);
        mController.onStop(mLifecycleOwner);
        verify(mBtEventManager).unregisterCallback(mController);
        verify(mContentResolver, never()).unregisterContentObserver(mContentObserver);
        verify(mLeaProfile).unregisterCallback(any(BluetoothLeAudio.Callback.class));
        verify(mAssistant)
                .unregisterServiceCallBack(any(BluetoothLeBroadcastAssistant.Callback.class));
    }
@@ -367,7 +406,8 @@ public class AudioSharingCallAudioPreferenceControllerTest {
        shadowOf(Looper.getMainLooper()).idle();
        mPreference.setSummary("test");

        mContentObserver.onChange(true);
        mController.mLeAudioCallback.onBroadcastToUnicastFallbackGroupChanged(
                TEST_DEVICE_GROUP_ID1);
        shadowOf(Looper.getMainLooper()).idle();
        assertThat(mPreference.getSummary().toString())
                .isEqualTo(
Loading