diff --git a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java index 183de7f64c8..bb56c509373 100644 --- a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java @@ -23,7 +23,6 @@ import android.util.Log; import androidx.preference.Preference; import com.android.settings.connecteddevice.DevicePreferenceCallback; -import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; @@ -77,7 +76,7 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater // It would show in Available Devices group if the audio sharing flag is disabled or // the device is not in the audio sharing session. if (cachedDevice.isConnectedLeAudioDevice()) { - if (AudioSharingUtils.isFeatureEnabled() + if (BluetoothUtils.isAudioSharingEnabled() && BluetoothUtils.hasConnectedBroadcastSource( cachedDevice, mLocalBtManager)) { Log.d( diff --git a/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java b/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java index 420fb970f11..c67995a2456 100644 --- a/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java +++ b/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java @@ -45,7 +45,6 @@ import com.android.settings.bluetooth.BluetoothDevicePreference; import com.android.settings.bluetooth.BluetoothDeviceUpdater; import com.android.settings.bluetooth.Utils; import com.android.settings.connecteddevice.audiosharing.AudioSharingDialogHandler; -import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils; import com.android.settings.core.BasePreferenceController; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.overlay.FeatureFactory; @@ -180,7 +179,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle super(context, KEY); mBtManager = Utils.getLocalBtManager(mContext); mExecutor = Executors.newSingleThreadExecutor(); - if (AudioSharingUtils.isFeatureEnabled()) { + if (BluetoothUtils.isAudioSharingEnabled()) { mBroadcast = mBtManager == null ? null @@ -201,7 +200,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle Log.d(TAG, "onStart() Bluetooth is not supported on this device"); return; } - if (AudioSharingUtils.isFeatureEnabled()) { + if (BluetoothUtils.isAudioSharingEnabled()) { registerAudioSharingCallbacks(); } mBtManager.getEventManager().registerCallback(this); @@ -217,7 +216,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle Log.d(TAG, "onStop() Bluetooth is not supported on this device"); return; } - if (AudioSharingUtils.isFeatureEnabled()) { + if (BluetoothUtils.isAudioSharingEnabled()) { unregisterAudioSharingCallbacks(); } if (mBluetoothDeviceUpdater != null) { @@ -279,7 +278,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle public void onDeviceClick(Preference preference) { final CachedBluetoothDevice cachedDevice = ((BluetoothDevicePreference) preference).getBluetoothDevice(); - if (AudioSharingUtils.isFeatureEnabled() && mDialogHandler != null) { + if (BluetoothUtils.isAudioSharingEnabled() && mDialogHandler != null) { mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ true); FeatureFactory.getFeatureFactory().getMetricsFeatureProvider() .action(mContext, SettingsEnums.ACTION_MEDIA_DEVICE_CLICK); @@ -295,7 +294,7 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle fragment.getContext(), AvailableMediaDeviceGroupController.this, fragment.getMetricsCategory()); - if (AudioSharingUtils.isFeatureEnabled()) { + if (BluetoothUtils.isAudioSharingEnabled()) { mDialogHandler = new AudioSharingDialogHandler(mContext, fragment); } } @@ -342,8 +341,8 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle if (isAudioModeOngoingCall(mContext)) { // in phone call titleResId = R.string.connected_device_call_device_title; - } else if (AudioSharingUtils.isFeatureEnabled() - && AudioSharingUtils.isBroadcasting(mBtManager)) { + } else if (BluetoothUtils.isAudioSharingEnabled() + && BluetoothUtils.isBroadcasting(mBtManager)) { // without phone call, in audio sharing titleResId = R.string.audio_sharing_media_device_group_title; } else { diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java index 27001d6e071..5184176e8fa 100644 --- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java +++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java @@ -28,13 +28,13 @@ import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.Utils; import com.android.settings.connecteddevice.audiosharing.AudioSharingDevicePreferenceController; -import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils; import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.SurveyFeatureProvider; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.slices.SlicePreferenceController; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.HearingAidStatsLogUtils; import com.android.settingslib.search.SearchIndexable; @@ -87,7 +87,7 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment { + ", action : " + action); } - if (AudioSharingUtils.isFeatureEnabled()) { + if (BluetoothUtils.isAudioSharingEnabled()) { use(AudioSharingDevicePreferenceController.class).init(this); } use(AvailableMediaDeviceGroupController.class).init(this); diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingActivity.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingActivity.java index 1ec53f94981..08b21a1e79c 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingActivity.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingActivity.java @@ -19,12 +19,13 @@ package com.android.settings.connecteddevice.audiosharing; import android.os.Bundle; import com.android.settings.SettingsActivity; +import com.android.settingslib.bluetooth.BluetoothUtils; public class AudioSharingActivity extends SettingsActivity { @Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); - if (!AudioSharingUtils.isFeatureEnabled()) { + if (!BluetoothUtils.isAudioSharingEnabled()) { finish(); } } diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBasePreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBasePreferenceController.java index e933e417ef5..96c5d453dcd 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBasePreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBasePreferenceController.java @@ -29,6 +29,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.bluetooth.Utils; import com.android.settings.core.BasePreferenceController; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; @@ -54,7 +55,7 @@ public abstract class AudioSharingBasePreferenceController extends BasePreferenc @Override public int getAvailabilityStatus() { - return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java index 21eb4d13d0a..60a8a1329f7 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java @@ -55,7 +55,7 @@ public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) { // If device is LE audio device and has a broadcast source, // it would show in audio sharing devices group. - if (AudioSharingUtils.isFeatureEnabled() + if (BluetoothUtils.isAudioSharingEnabled() && cachedDevice.isConnectedLeAudioDevice() && BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mLocalBtManager)) { isFilterMatched = true; diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioDialogFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioDialogFragment.java index 5e0ec0766d1..fa9f94d83c4 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioDialogFragment.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioDialogFragment.java @@ -29,6 +29,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; +import com.android.settingslib.bluetooth.BluetoothUtils; import java.util.List; @@ -36,6 +37,7 @@ import java.util.List; public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragment { private static final String TAG = "CallsAndAlarmsDialog"; private static final String BUNDLE_KEY_DEVICE_ITEMS = "bundle_key_device_items"; + private static final String BUNDLE_KEY_CHECKED_ITEM_INDEX = "bundle_key_checked_index"; // The host creates an instance of this dialog fragment must implement this interface to receive // event callbacks. @@ -65,8 +67,9 @@ public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragm public static void show( @NonNull Fragment host, @NonNull List deviceItems, + int checkedItemIndex, @NonNull DialogEventListener listener) { - if (!AudioSharingUtils.isFeatureEnabled()) return; + if (!BluetoothUtils.isAudioSharingEnabled()) return; final FragmentManager manager; try { manager = host.getChildFragmentManager(); @@ -78,6 +81,7 @@ public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragm if (manager.findFragmentByTag(TAG) == null) { final Bundle bundle = new Bundle(); bundle.putParcelableList(BUNDLE_KEY_DEVICE_ITEMS, deviceItems); + bundle.putInt(BUNDLE_KEY_CHECKED_ITEM_INDEX, checkedItemIndex); final AudioSharingCallAudioDialogFragment dialog = new AudioSharingCallAudioDialogFragment(); dialog.setArguments(bundle); @@ -91,6 +95,7 @@ public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragm Bundle arguments = requireArguments(); List deviceItems = arguments.getParcelable(BUNDLE_KEY_DEVICE_ITEMS, List.class); + int checkedItemIndex = arguments.getInt(BUNDLE_KEY_CHECKED_ITEM_INDEX, -1); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) .setTitle(R.string.audio_sharing_call_audio_title); @@ -98,18 +103,11 @@ public class AudioSharingCallAudioDialogFragment extends InstrumentedDialogFragm Log.d(TAG, "Create dialog error: null deviceItems"); return builder.create(); } - int checkedItem = -1; - for (AudioSharingDeviceItem item : deviceItems) { - int fallbackActiveGroupId = AudioSharingUtils.getFallbackActiveGroupId(getContext()); - if (item.getGroupId() == fallbackActiveGroupId) { - checkedItem = deviceItems.indexOf(item); - } - } String[] choices = deviceItems.stream().map(AudioSharingDeviceItem::getName).toArray(String[]::new); builder.setSingleChoiceItems( choices, - checkedItem, + checkedItemIndex, (dialog, which) -> { if (sListener != null) { sListener.onItemClick(deviceItems.get(which)); diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceController.java index 6ba7183e897..33c1a6c6cb6 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceController.java @@ -16,8 +16,6 @@ package com.android.settings.connecteddevice.audiosharing; -import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID; - import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothCsipSetCoordinator; @@ -197,13 +195,15 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP } updateDeviceItemsInSharingSession(); if (!mDeviceItemsInSharingSession.isEmpty()) { + int checkedItemIndex = getActiveItemIndex(mDeviceItemsInSharingSession); AudioSharingCallAudioDialogFragment.show( mFragment, mDeviceItemsInSharingSession, + checkedItemIndex, (AudioSharingDeviceItem item) -> { int currentGroupId = - AudioSharingUtils.getFallbackActiveGroupId( - mContext); + BluetoothUtils.getPrimaryGroupIdForBroadcast( + mContext.getContentResolver()); if (item.getGroupId() == currentGroupId) { Log.d( TAG, @@ -220,7 +220,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP TAG, "Set fallback active device: " + lead.getDevice() - .getAnonymizedAddress()); + .getAnonymizedAddress()); lead.setActive(); logCallAudioDeviceChange(currentGroupId, lead); } else { @@ -300,7 +300,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP Log.d(TAG, "registerCallbacks()"); mEventManager.registerCallback(this); mContentResolver.registerContentObserver( - Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID), + Settings.Secure.getUriFor(BluetoothUtils.getPrimaryGroupIdUriForBroadcast()), false, mSettingsObserver); mAssistant.registerServiceCallBack(mExecutor, mBroadcastAssistantCallback); @@ -347,7 +347,8 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP */ private void updateSummary() { updateDeviceItemsInSharingSession(); - int fallbackActiveGroupId = AudioSharingUtils.getFallbackActiveGroupId(mContext); + int fallbackActiveGroupId = BluetoothUtils.getPrimaryGroupIdForBroadcast( + mContext.getContentResolver()); if (fallbackActiveGroupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) { for (AudioSharingDeviceItem item : mDeviceItemsInSharingSession) { if (item.getGroupId() == fallbackActiveGroupId) { @@ -386,6 +387,18 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP mBtManager, mGroupedConnectedDevices, /* filterByInSharing= */ true); } + private int getActiveItemIndex(List deviceItems) { + int checkedItemIndex = -1; + int fallbackActiveGroupId = + BluetoothUtils.getPrimaryGroupIdForBroadcast(mContext.getContentResolver()); + for (AudioSharingDeviceItem item : deviceItems) { + if (item.getGroupId() == fallbackActiveGroupId) { + return deviceItems.indexOf(item); + } + } + return checkedItemIndex; + } + @VisibleForTesting void logCallAudioDeviceChange(int currentGroupId, CachedBluetoothDevice target) { var unused = @@ -393,7 +406,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP () -> { ChangeCallAudioType type = ChangeCallAudioType.UNKNOWN; if (mCacheManager != null) { - int targetDeviceGroupId = AudioSharingUtils.getGroupId(target); + int targetDeviceGroupId = BluetoothUtils.getGroupId(target); List mostRecentDevices = BluetoothAdapter.getDefaultAdapter() .getMostRecentlyConnectedDevices(); @@ -405,7 +418,7 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP mCacheManager.findDevice(device); int groupId = cachedDevice != null - ? AudioSharingUtils.getGroupId(cachedDevice) + ? BluetoothUtils.getGroupId(cachedDevice) : BluetoothCsipSetCoordinator.GROUP_ID_INVALID; if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) { if (groupId == targetDeviceGroupId) { diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCompatibilityPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCompatibilityPreferenceController.java index 42a90387714..52df1d33a0d 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCompatibilityPreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCompatibilityPreferenceController.java @@ -34,6 +34,7 @@ import com.android.settings.R; import com.android.settings.bluetooth.Utils; import com.android.settings.core.TogglePreferenceController; import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; @@ -154,7 +155,7 @@ public class AudioSharingCompatibilityPreferenceController extends TogglePrefere @Override public int getAvailabilityStatus() { - return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override @@ -242,7 +243,7 @@ public class AudioSharingCompatibilityPreferenceController extends TogglePrefere var unused = ThreadUtils.postOnBackgroundThread( () -> { - boolean isBroadcasting = AudioSharingUtils.isBroadcasting(mBtManager); + boolean isBroadcasting = BluetoothUtils.isBroadcasting(mBtManager); AudioSharingUtils.postOnMainThread( mContext, () -> { diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingConfirmDialogFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingConfirmDialogFragment.java index 61b1df104eb..3750cf1ebbe 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingConfirmDialogFragment.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingConfirmDialogFragment.java @@ -29,6 +29,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; +import com.android.settingslib.bluetooth.BluetoothUtils; public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragment { private static final String TAG = "AudioSharingConfirmDialog"; @@ -44,7 +45,7 @@ public class AudioSharingConfirmDialogFragment extends InstrumentedDialogFragmen * @param host The Fragment this dialog will be hosted. */ public static void show(Fragment host) { - if (!AudioSharingUtils.isFeatureEnabled()) return; + if (!BluetoothUtils.isAudioSharingEnabled()) return; final FragmentManager manager; try { manager = host.getChildFragmentManager(); diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java index cc883fe57c1..a0c0b44a888 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java @@ -296,7 +296,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro @Override public int getAvailabilityStatus() { - return AudioSharingUtils.isFeatureEnabled() && mBluetoothDeviceUpdater != null + return BluetoothUtils.isAudioSharingEnabled() && mBluetoothDeviceUpdater != null ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE; } diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java index 0fbb8924e19..2e935391522 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java @@ -67,7 +67,7 @@ public class AudioSharingDeviceVolumeControlUpdater extends BluetoothDeviceUpdat // If device is LE audio device and in a sharing session on current sharing device, // it would show in volume control group. if (cachedDevice.isConnectedLeAudioDevice() - && AudioSharingUtils.isBroadcasting(mBtManager) + && BluetoothUtils.isBroadcasting(mBtManager) && BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mBtManager)) { isFilterMatched = true; } @@ -103,11 +103,11 @@ public class AudioSharingDeviceVolumeControlUpdater extends BluetoothDeviceUpdat @Override public void onStopTrackingTouch(SeekBar seekBar) { int progress = seekBar.getProgress(); - int groupId = AudioSharingUtils.getGroupId(cachedDevice); + int groupId = BluetoothUtils.getGroupId(cachedDevice); if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID && groupId - == AudioSharingUtils.getFallbackActiveGroupId( - mContext)) { + == BluetoothUtils.getPrimaryGroupIdForBroadcast( + mContext.getContentResolver())) { // Set media stream volume for primary buds, audio manager will // update all buds volume in the audio sharing. setAudioManagerStreamVolume(progress); diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java index ee2ba7bb2e3..48b04b4b58c 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupController.java @@ -16,8 +16,6 @@ package com.android.settings.connecteddevice.audiosharing; -import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID; - import android.annotation.IntRange; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; @@ -91,11 +89,11 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre ? null : mBtManager.getCachedDeviceManager().findDevice(device); if (cachedDevice == null) return; - int groupId = AudioSharingUtils.getGroupId(cachedDevice); + int groupId = BluetoothUtils.getGroupId(cachedDevice); mValueMap.put(groupId, volume); for (AudioSharingDeviceVolumePreference preference : mVolumePreferences) { if (preference.getCachedDevice() != null - && AudioSharingUtils.getGroupId(preference.getCachedDevice()) + && BluetoothUtils.getGroupId(preference.getCachedDevice()) == groupId) { // If the callback return invalid volume, try to // get the volume from AudioManager.STREAM_MUSIC @@ -256,7 +254,7 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre volumePref.setOrder(getPreferenceOrderForDevice(cachedDevice)); mVolumePreferences.add(volumePref); if (volumePref.getProgress() > 0) return; - int volume = mValueMap.getOrDefault(AudioSharingUtils.getGroupId(cachedDevice), -1); + int volume = mValueMap.getOrDefault(BluetoothUtils.getGroupId(cachedDevice), -1); // If the volume is invalid, try to get the volume from AudioManager.STREAM_MUSIC int finalVolume = getAudioVolumeIfNeeded(volume); Log.d( @@ -369,7 +367,7 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre mVolumeControl.registerCallback(mExecutor, mVolumeControlCallback); mBluetoothDeviceUpdater.registerCallback(); mContentResolver.registerContentObserver( - Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID), + Settings.Secure.getUriFor(BluetoothUtils.getPrimaryGroupIdUriForBroadcast()), false, mSettingsObserver); mCallbacksRegistered.set(true); @@ -415,10 +413,10 @@ public class AudioSharingDeviceVolumeGroupController extends AudioSharingBasePre } private int getPreferenceOrderForDevice(@NonNull CachedBluetoothDevice cachedDevice) { - int groupId = AudioSharingUtils.getGroupId(cachedDevice); + int groupId = BluetoothUtils.getGroupId(cachedDevice); // The fallback device rank first among the audio sharing device list. return (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID - && groupId == AudioSharingUtils.getFallbackActiveGroupId(mContext)) + && groupId == BluetoothUtils.getPrimaryGroupIdForBroadcast(mContentResolver)) ? 0 : 1; } diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragment.java index f00cf7326dd..6f62ed9d4fc 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragment.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragment.java @@ -31,6 +31,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.google.common.collect.Iterables; @@ -76,7 +77,7 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment { @NonNull List deviceItems, @NonNull DialogEventListener listener, @NonNull Pair[] eventData) { - if (!AudioSharingUtils.isFeatureEnabled()) return; + if (!BluetoothUtils.isAudioSharingEnabled()) return; final FragmentManager manager; try { manager = host.getChildFragmentManager(); diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandler.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandler.java index 81d7979f878..472cb440063 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandler.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandler.java @@ -263,7 +263,7 @@ public class AudioSharingDialogHandler { if (isBroadcasting) { // If another device within the same is already in the sharing session, add source to // the device automatically. - int groupId = AudioSharingUtils.getGroupId(cachedDevice); + int groupId = BluetoothUtils.getGroupId(cachedDevice); if (groupedDevices.containsKey(groupId) && groupedDevices.get(groupId).stream() .anyMatch( @@ -355,8 +355,8 @@ public class AudioSharingDialogHandler { for (List devices : groupedDevices.values()) { // Use random device in the group within the sharing session to represent the group. CachedBluetoothDevice device = devices.get(0); - if (AudioSharingUtils.getGroupId(device) - == AudioSharingUtils.getGroupId(cachedDevice)) { + if (BluetoothUtils.getGroupId(device) + == BluetoothUtils.getGroupId(cachedDevice)) { continue; } deviceItems.add(AudioSharingUtils.buildAudioSharingDeviceItem(device)); @@ -435,7 +435,7 @@ public class AudioSharingDialogHandler { /** Close opening dialogs for le audio device */ public void closeOpeningDialogsForLeaDevice(@NonNull CachedBluetoothDevice cachedDevice) { if (mHostFragment == null) return; - int groupId = AudioSharingUtils.getGroupId(cachedDevice); + int groupId = BluetoothUtils.getGroupId(cachedDevice); List fragments; try { fragments = mHostFragment.getChildFragmentManager().getFragments(); @@ -447,7 +447,7 @@ public class AudioSharingDialogHandler { CachedBluetoothDevice device = getCachedBluetoothDeviceFromDialog(fragment); if (device != null && groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID - && AudioSharingUtils.getGroupId(device) == groupId) { + && BluetoothUtils.getGroupId(device) == groupId) { Log.d(TAG, "Remove staled opening dialog for group " + groupId); ((DialogFragment) fragment).dismiss(); logDialogDismissEvent(fragment); diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDisconnectDialogFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDisconnectDialogFragment.java index 66e327b1389..7d9164449aa 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDisconnectDialogFragment.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDisconnectDialogFragment.java @@ -32,6 +32,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.utils.ThreadUtils; @@ -83,7 +84,7 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag @NonNull CachedBluetoothDevice newDevice, @NonNull DialogEventListener listener, @NonNull Pair[] eventData) { - if (!AudioSharingUtils.isFeatureEnabled()) return; + if (!BluetoothUtils.isAudioSharingEnabled()) return; final FragmentManager manager; try { manager = host.getChildFragmentManager(); @@ -93,8 +94,8 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag } AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG); if (dialog != null) { - int newGroupId = AudioSharingUtils.getGroupId(newDevice); - if (sNewDevice != null && newGroupId == AudioSharingUtils.getGroupId(sNewDevice)) { + int newGroupId = BluetoothUtils.getGroupId(newDevice); + if (sNewDevice != null && newGroupId == BluetoothUtils.getGroupId(sNewDevice)) { Log.d( TAG, String.format( diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingJoinDialogFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingJoinDialogFragment.java index 9afa1864454..95712411627 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingJoinDialogFragment.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingJoinDialogFragment.java @@ -32,6 +32,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.R; import com.android.settings.bluetooth.Utils; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import java.util.List; @@ -58,7 +59,7 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment { @Override public int getMetricsCategory() { - return AudioSharingUtils.isBroadcasting(Utils.getLocalBtManager(getContext())) + return BluetoothUtils.isBroadcasting(Utils.getLocalBtManager(getContext())) ? SettingsEnums.DIALOG_AUDIO_SHARING_ADD_DEVICE : SettingsEnums.DIALOG_START_AUDIO_SHARING; } @@ -80,7 +81,7 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment { @NonNull CachedBluetoothDevice newDevice, @NonNull DialogEventListener listener, @NonNull Pair[] eventData) { - if (!AudioSharingUtils.isFeatureEnabled()) return; + if (!BluetoothUtils.isAudioSharingEnabled()) return; final FragmentManager manager; try { manager = host.getChildFragmentManager(); diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingNamePreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingNamePreferenceController.java index 894ba487014..a1a969840d2 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingNamePreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingNamePreferenceController.java @@ -16,7 +16,7 @@ package com.android.settings.connecteddevice.audiosharing; -import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.isBroadcasting; +import static com.android.settingslib.bluetooth.BluetoothUtils.isBroadcasting; import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothLeBroadcast; @@ -174,7 +174,7 @@ public class AudioSharingNamePreferenceController extends BasePreferenceControll @Override public int getAvailabilityStatus() { - return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceController.java index 14930e11a6a..9a27a93c9f6 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPasswordPreferenceController.java @@ -16,7 +16,7 @@ package com.android.settings.connecteddevice.audiosharing; -import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.isBroadcasting; +import static com.android.settingslib.bluetooth.BluetoothUtils.isBroadcasting; import android.app.settings.SettingsEnums; import android.content.ContentResolver; @@ -39,6 +39,7 @@ import com.android.settings.bluetooth.Utils; import com.android.settings.core.BasePreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settings.widget.ValidatedEditTextPreference; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; @@ -112,7 +113,7 @@ public class AudioSharingPasswordPreferenceController extends BasePreferenceCont @Override public int getAvailabilityStatus() { - return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPlaySoundPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPlaySoundPreferenceController.java index 11b195c47dd..59494db6b90 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPlaySoundPreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPlaySoundPreferenceController.java @@ -33,6 +33,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; public class AudioSharingPlaySoundPreferenceController @@ -56,7 +57,7 @@ public class AudioSharingPlaySoundPreferenceController @Override public int getAvailabilityStatus() { - return (mRingtone != null && AudioSharingUtils.isFeatureEnabled()) + return (mRingtone != null && BluetoothUtils.isAudioSharingEnabled()) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPreferenceController.java index 02448892243..3c078efa597 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPreferenceController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingPreferenceController.java @@ -34,6 +34,7 @@ import com.android.settings.bluetooth.Utils; import com.android.settings.core.BasePreferenceController; import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.BluetoothEventManager; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.utils.ThreadUtils; @@ -134,12 +135,12 @@ public class AudioSharingPreferenceController extends BasePreferenceController @Override public int getAvailabilityStatus() { - return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override public CharSequence getSummary() { - return AudioSharingUtils.isBroadcasting(mBtManager) + return BluetoothUtils.isBroadcasting(mBtManager) ? mContext.getString(R.string.audio_sharing_summary_on) : mContext.getString(R.string.audio_sharing_summary_off); } diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingReceiver.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingReceiver.java index 2b976d2dd48..b43a544e4d6 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingReceiver.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingReceiver.java @@ -32,6 +32,7 @@ import androidx.core.app.NotificationCompat; import com.android.settings.R; import com.android.settings.bluetooth.Utils; import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; @@ -48,7 +49,7 @@ public class AudioSharingReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (!AudioSharingUtils.isFeatureEnabled()) { + if (!BluetoothUtils.isAudioSharingEnabled()) { Log.w(TAG, "Skip handling received intent, flag is off."); return; } diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingStopDialogFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingStopDialogFragment.java index d026fa72055..5b71f5163e9 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingStopDialogFragment.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingStopDialogFragment.java @@ -32,6 +32,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.utils.ThreadUtils; @@ -80,7 +81,7 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment { @NonNull CachedBluetoothDevice newDevice, @NonNull DialogEventListener listener, @NonNull Pair[] eventData) { - if (!AudioSharingUtils.isFeatureEnabled()) return; + if (!BluetoothUtils.isAudioSharingEnabled()) return; final FragmentManager manager; try { manager = host.getChildFragmentManager(); @@ -90,9 +91,9 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment { } AlertDialog dialog = AudioSharingDialogHelper.getDialogIfShowing(manager, TAG); if (dialog != null) { - int newGroupId = AudioSharingUtils.getGroupId(newDevice); + int newGroupId = BluetoothUtils.getGroupId(newDevice); if (sCachedDevice != null - && newGroupId == AudioSharingUtils.getGroupId(sCachedDevice)) { + && newGroupId == BluetoothUtils.getGroupId(sCachedDevice)) { Log.d( TAG, String.format( diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java index 97055661686..60b2ee507cd 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java @@ -23,7 +23,6 @@ import android.bluetooth.BluetoothLeBroadcast; import android.bluetooth.BluetoothLeBroadcastAssistant; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothLeBroadcastReceiveState; -import android.bluetooth.BluetoothProfile; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -45,6 +44,7 @@ import com.android.settings.bluetooth.Utils; import com.android.settings.core.BasePreferenceController; import com.android.settings.overlay.FeatureFactory; import com.android.settings.widget.SettingsMainSwitchBar; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; @@ -327,7 +327,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController return; } mSwitchBar.setEnabled(false); - boolean isBroadcasting = AudioSharingUtils.isBroadcasting(mBtManager); + boolean isBroadcasting = BluetoothUtils.isBroadcasting(mBtManager); if (isChecked) { if (isBroadcasting) { Log.d(TAG, "Skip startAudioSharing, already broadcasting."); @@ -339,10 +339,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController if (FeatureFlagUtils.isEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST) - && mAssistant - .getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED}) - .isEmpty()) { + && mAssistant.getAllConnectedDevices().isEmpty()) { // Pop up dialog to ask users to connect at least one lea buds before audio sharing. AudioSharingUtils.postOnMainThread( mContext, @@ -368,7 +365,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController @Override public int getAvailabilityStatus() { - return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override @@ -483,7 +480,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController var unused = ThreadUtils.postOnBackgroundThread( () -> { - boolean isBroadcasting = AudioSharingUtils.isBroadcasting(mBtManager); + boolean isBroadcasting = BluetoothUtils.isBroadcasting(mBtManager); boolean isStateReady = isBluetoothOn() && AudioSharingUtils.isAudioSharingProfileReady( diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingUtils.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingUtils.java index 29f605c94a4..50f9c9a8cc9 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingUtils.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingUtils.java @@ -22,14 +22,10 @@ import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtil import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.MetricKey.METRIC_KEY_SOURCE_PAGE_ID; import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.MetricKey.METRIC_KEY_USER_TRIGGERED; -import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastMetadata; -import android.bluetooth.BluetoothProfile; -import android.bluetooth.BluetoothStatusCodes; import android.content.Context; -import android.provider.Settings; import android.util.Log; import android.util.Pair; import android.widget.Toast; @@ -44,10 +40,8 @@ import com.android.settingslib.bluetooth.LeAudioProfile; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.LocalBluetoothManager; -import com.android.settingslib.bluetooth.LocalBluetoothProfile; 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.HashMap; @@ -56,8 +50,6 @@ import java.util.Map; import java.util.stream.Collectors; public class AudioSharingUtils { - public static final String SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID = - "bluetooth_le_broadcast_fallback_active_group_id"; private static final String TAG = "AudioSharingUtils"; private static final boolean DEBUG = BluetoothUtils.D; @@ -89,9 +81,7 @@ public class AudioSharingUtils { Log.d(TAG, "Skip fetchConnectedDevicesByGroupId due to assistant profile is null"); return groupedDevices; } - List connectedDevices = - assistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED}); + List connectedDevices = assistant.getAllConnectedDevices(); CachedBluetoothDeviceManager cacheManager = localBtManager.getCachedDeviceManager(); for (BluetoothDevice device : connectedDevices) { CachedBluetoothDevice cachedDevice = cacheManager.findDevice(device); @@ -99,7 +89,7 @@ public class AudioSharingUtils { Log.d(TAG, "Skip device due to not being cached: " + device.getAnonymizedAddress()); continue; } - int groupId = getGroupId(cachedDevice); + int groupId = BluetoothUtils.getGroupId(cachedDevice); if (groupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) { Log.d( TAG, @@ -230,7 +220,7 @@ public class AudioSharingUtils { CachedBluetoothDevice cachedDevice) { return new AudioSharingDeviceItem( cachedDevice.getName(), - getGroupId(cachedDevice), + BluetoothUtils.getGroupId(cachedDevice), isActiveLeAudioDevice(cachedDevice)); } @@ -250,16 +240,6 @@ public class AudioSharingUtils { .execute(() -> Toast.makeText(context, message, Toast.LENGTH_LONG).show()); } - /** Returns if the le audio sharing is enabled. */ - public static boolean isFeatureEnabled() { - BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); - return Flags.enableLeAudioSharing() - && adapter.isLeAudioBroadcastSourceSupported() - == BluetoothStatusCodes.FEATURE_SUPPORTED - && adapter.isLeAudioBroadcastAssistantSupported() - == BluetoothStatusCodes.FEATURE_SUPPORTED; - } - /** Add source to target sinks. */ public static void addSourceToTargetSinks( List sinks, @Nullable LocalBluetoothManager localBtManager) { @@ -289,9 +269,7 @@ public class AudioSharingUtils { Log.d(TAG, "skip addSourceToTargetDevices: There is no broadcastMetadata."); return; } - List connectedDevices = - assistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED}); + List connectedDevices = assistant.getAllConnectedDevices(); for (BluetoothDevice sink : sinks) { if (connectedDevices.contains(sink)) { Log.d( @@ -312,14 +290,6 @@ public class AudioSharingUtils { } } - /** Returns if the broadcast is on-going. */ - public static boolean isBroadcasting(@Nullable LocalBluetoothManager manager) { - if (manager == null) return false; - LocalBluetoothLeBroadcast broadcast = - manager.getProfileManager().getLeAudioBroadcastProfile(); - return broadcast != null && broadcast.isEnabled(null); - } - /** Stops the latest broadcast. */ public static void stopBroadcasting(@Nullable LocalBluetoothManager manager) { if (manager == null) { @@ -335,37 +305,6 @@ public class AudioSharingUtils { } } - /** - * Get CSIP group id for {@link CachedBluetoothDevice}. - * - *

If CachedBluetoothDevice#getGroupId is invalid, fetch group id from - * LeAudioProfile#getGroupId. - */ - public static int getGroupId(CachedBluetoothDevice cachedDevice) { - int groupId = cachedDevice.getGroupId(); - String anonymizedAddress = cachedDevice.getDevice().getAnonymizedAddress(); - if (groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) { - Log.d(TAG, "getGroupId by CSIP profile for device: " + anonymizedAddress); - return groupId; - } - for (LocalBluetoothProfile profile : cachedDevice.getProfiles()) { - if (profile instanceof LeAudioProfile) { - Log.d(TAG, "getGroupId by LEA profile for device: " + anonymizedAddress); - return ((LeAudioProfile) profile).getGroupId(cachedDevice.getDevice()); - } - } - Log.d(TAG, "getGroupId return invalid id for device: " + anonymizedAddress); - return BluetoothCsipSetCoordinator.GROUP_ID_INVALID; - } - - /** Get the fallback active group id from SettingsProvider. */ - public static int getFallbackActiveGroupId(@NonNull Context context) { - return Settings.Secure.getInt( - context.getContentResolver(), - SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID, - BluetoothCsipSetCoordinator.GROUP_ID_INVALID); - } - /** Post the runnable to main thread. */ public static void postOnMainThread(@NonNull Context context, @NonNull Runnable runnable) { context.getMainExecutor().execute(runnable); diff --git a/src/com/android/settings/connecteddevice/audiosharing/StreamSettingsCategoryController.java b/src/com/android/settings/connecteddevice/audiosharing/StreamSettingsCategoryController.java index e9953a515c3..40f86d0d81b 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/StreamSettingsCategoryController.java +++ b/src/com/android/settings/connecteddevice/audiosharing/StreamSettingsCategoryController.java @@ -33,6 +33,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.bluetooth.Utils; import com.android.settings.core.BasePreferenceController; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; @@ -90,7 +91,7 @@ public class StreamSettingsCategoryController extends BasePreferenceController @Override public int getAvailabilityStatus() { - return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + return BluetoothUtils.isAudioSharingEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialog.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialog.java index 148c776f0a5..4c17a7cbd5a 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialog.java +++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialog.java @@ -23,7 +23,6 @@ import android.app.Dialog; import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastMetadata; -import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -36,10 +35,10 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.bluetooth.Utils; import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment; -import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils; import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { @@ -211,7 +210,7 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { } private int getDialogId(boolean hasMetadata, boolean hasConnectedDevice) { - if (!AudioSharingUtils.isFeatureEnabled()) { + if (!BluetoothUtils.isAudioSharingEnabled()) { return SettingsEnums.DIALOG_AUDIO_STREAM_CONFIRM_FEATURE_UNSUPPORTED; } if (!hasConnectedDevice) { @@ -233,9 +232,7 @@ public class AudioStreamConfirmDialog extends InstrumentedDialogFragment { if (assistant == null) { return null; } - var devices = - assistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED}); + var devices = assistant.getAllConnectedDevices(); return devices.isEmpty() ? null : devices.get(0); } diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogActivity.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogActivity.java index 88e2322ec1f..3437524d995 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogActivity.java +++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogActivity.java @@ -25,6 +25,7 @@ import androidx.annotation.Nullable; import com.android.settings.SettingsActivity; import com.android.settings.bluetooth.Utils; import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; public class AudioStreamConfirmDialogActivity extends SettingsActivity @@ -49,7 +50,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity @Override protected void createUiFromIntent(@Nullable Bundle savedState, Intent intent) { - if (AudioSharingUtils.isFeatureEnabled() + if (BluetoothUtils.isAudioSharingEnabled() && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { Log.d(TAG, "createUiFromIntent() : supported but not ready, skip createUiFromIntent"); mSavedState = savedState; @@ -66,7 +67,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity @Override public void onStart() { - if (AudioSharingUtils.isFeatureEnabled() + if (BluetoothUtils.isAudioSharingEnabled() && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { Log.d(TAG, "onStart() : supported but not ready, listen to service ready"); if (mProfileManager != null) { @@ -86,7 +87,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity @Override public void onServiceConnected() { - if (AudioSharingUtils.isFeatureEnabled() + if (BluetoothUtils.isAudioSharingEnabled() && AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { if (mProfileManager != null) { mProfileManager.removeServiceListener(this); diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamMediaService.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamMediaService.java index ad358ed5437..d5be2bb63fc 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamMediaService.java +++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamMediaService.java @@ -43,9 +43,9 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.bluetooth.Utils; -import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.bluetooth.BluetoothCallback; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; @@ -122,7 +122,7 @@ public class AudioStreamMediaService extends Service { @Override public void onCreate() { - if (!AudioSharingUtils.isFeatureEnabled()) { + if (!BluetoothUtils.isAudioSharingEnabled()) { return; } @@ -172,7 +172,7 @@ public class AudioStreamMediaService extends Service { public void onDestroy() { Log.d(TAG, "onDestroy()"); super.onDestroy(); - if (!AudioSharingUtils.isFeatureEnabled()) { + if (!BluetoothUtils.isAudioSharingEnabled()) { return; } if (mLocalBtManager != null) { diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelper.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelper.java index 6e335a0971c..215b677aa2c 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelper.java +++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelper.java @@ -26,7 +26,6 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeAudioContentMetadata; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothLeBroadcastReceiveState; -import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.Intent; import android.util.Log; @@ -277,9 +276,7 @@ public class AudioStreamsHelper { Log.w(TAG, "getConnectedBluetoothDevices(): LeBroadcastAssistant is null!"); return emptyList(); } - List connectedDevices = - leBroadcastAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED}); + List connectedDevices = leBroadcastAssistant.getAllConnectedDevices(); Optional cachedBluetoothDevice = inSharingOnly ? getCachedBluetoothDeviceInSharing(manager) diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioDialogFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioDialogFragmentTest.java index 51ed899957b..ceafcf0a538 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioDialogFragmentTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioDialogFragmentTest.java @@ -99,7 +99,7 @@ public class AudioSharingCallAudioDialogFragmentTest { mParent = new Fragment(); FragmentController.setupFragment( mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null); - AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), (item) -> {}); + AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), -1, (item) -> {}); shadowMainLooper().idle(); AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog).isNull(); @@ -109,7 +109,7 @@ public class AudioSharingCallAudioDialogFragmentTest { public void onCreateDialog_unattachedFragment_dialogNotExist() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mParent = new Fragment(); - AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), (item) -> {}); + AudioSharingCallAudioDialogFragment.show(mParent, new ArrayList<>(), -1, (item) -> {}); shadowMainLooper().idle(); AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog).isNull(); @@ -138,7 +138,7 @@ public class AudioSharingCallAudioDialogFragmentTest { ArrayList deviceItemList = new ArrayList<>(); deviceItemList.add(TEST_DEVICE_ITEM1); deviceItemList.add(TEST_DEVICE_ITEM2); - AudioSharingCallAudioDialogFragment.show(mParent, deviceItemList, (item) -> {}); + AudioSharingCallAudioDialogFragment.show(mParent, deviceItemList, 0, (item) -> {}); shadowMainLooper().idle(); AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog).isNotNull(); diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceControllerTest.java index c72b5a5138f..87ae3d5431f 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingCallAudioPreferenceControllerTest.java @@ -16,7 +16,6 @@ package com.android.settings.connecteddevice.audiosharing; -import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID; import static com.android.settings.core.BasePreferenceController.AVAILABLE; import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; @@ -64,6 +63,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settings.testutils.shadow.ShadowThreadUtils; import com.android.settingslib.bluetooth.BluetoothEventManager; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; @@ -197,7 +197,8 @@ public class AudioSharingCallAudioPreferenceControllerTest { verify(mBtEventManager, never()).registerCallback(mController); verify(mContentResolver, never()) .registerContentObserver( - Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID), + Settings.Secure.getUriFor( + BluetoothUtils.getPrimaryGroupIdUriForBroadcast()), false, mContentObserver); verify(mAssistant, never()) @@ -211,7 +212,8 @@ public class AudioSharingCallAudioPreferenceControllerTest { verify(mBtEventManager).registerCallback(mController); verify(mContentResolver) .registerContentObserver( - Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID), + Settings.Secure.getUriFor( + BluetoothUtils.getPrimaryGroupIdUriForBroadcast()), false, mContentObserver); verify(mAssistant) @@ -319,9 +321,7 @@ public class AudioSharingCallAudioPreferenceControllerTest { public void onProfileConnectionStateChanged_noDeviceInSharing_updateSummary() { Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); when(mBroadcast.isEnabled(any())).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of()); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); mController.displayPreference(mScreen); mPreference.setSummary("test"); mController.onProfileConnectionStateChanged( @@ -340,9 +340,7 @@ public class AudioSharingCallAudioPreferenceControllerTest { when(mCachedDevice1.getName()).thenReturn(TEST_DEVICE_NAME1); when(mCacheManager.findDevice(mDevice1)).thenReturn(mCachedDevice1); when(mBroadcast.isEnabled(any())).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of(mDevice1)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mController.displayPreference(mScreen); mContentObserver.onChange(true); @@ -369,8 +367,7 @@ public class AudioSharingCallAudioPreferenceControllerTest { when(mCacheManager.findDevice(mDevice2)).thenReturn(mCachedDevice2); when(mCacheManager.findDevice(mDevice3)).thenReturn(mCachedDevice3); when(mBroadcast.isEnabled(any())).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) + when(mAssistant.getAllConnectedDevices()) .thenReturn(ImmutableList.of(mDevice1, mDevice2, mDevice3)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mController.displayPreference(mScreen); @@ -389,9 +386,7 @@ public class AudioSharingCallAudioPreferenceControllerTest { when(mCachedDevice1.getName()).thenReturn(TEST_DEVICE_NAME1); when(mCacheManager.findDevice(mDevice1)).thenReturn(mCachedDevice1); when(mBroadcast.isEnabled(any())).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of(mDevice1)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mController.displayPreference(mScreen); shadowOf(Looper.getMainLooper()).idle(); @@ -403,9 +398,7 @@ public class AudioSharingCallAudioPreferenceControllerTest { Settings.Secure.putInt( mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); when(mBroadcast.isEnabled(any())).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of()); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); mController.displayPreference(mScreen); shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreference.getSummary().toString()).isEmpty(); @@ -429,9 +422,7 @@ public class AudioSharingCallAudioPreferenceControllerTest { when(mCacheManager.findDevice(mDevice2)).thenReturn(mCachedDevice2); mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(List.of(mDevice1, mDevice2)); when(mBroadcast.isEnabled(any())).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of(mDevice1, mDevice2)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1, mDevice2)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mController.init(mParentFragment); mController.displayPreference(mScreen); @@ -521,18 +512,14 @@ public class AudioSharingCallAudioPreferenceControllerTest { Settings.Secure.putInt( mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); when(mBroadcast.isEnabled(any())).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of()); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); mController.displayPreference(mScreen); shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreference.getSummary().toString()).isEmpty(); // onReceiveStateChanged will update summary Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of(mDevice1)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mController.mBroadcastAssistantCallback.onReceiveStateChanged( mDevice1, /* sourceId= */ 1, mState); @@ -552,17 +539,13 @@ public class AudioSharingCallAudioPreferenceControllerTest { Settings.Secure.putInt( mContentResolver, TEST_SETTINGS_KEY, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); when(mBroadcast.isEnabled(any())).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of()); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); mController.displayPreference(mScreen); shadowOf(Looper.getMainLooper()).idle(); assertThat(mPreference.getSummary().toString()).isEmpty(); Settings.Secure.putInt(mContentResolver, TEST_SETTINGS_KEY, TEST_DEVICE_GROUP_ID1); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of(mDevice1)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1)); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mController.mBroadcastAssistantCallback.onSearchStarted(/* reason= */ 1); mController.mBroadcastAssistantCallback.onSearchStartFailed(/* reason= */ 1); diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupControllerTest.java index f2f0a2f31f6..d8c663f6dc2 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeGroupControllerTest.java @@ -16,8 +16,6 @@ package com.android.settings.connecteddevice.audiosharing; -import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID; - import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -59,6 +57,7 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settings.testutils.shadow.ShadowThreadUtils; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; @@ -208,7 +207,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest { .registerCallback(any(Executor.class), any(BluetoothVolumeControl.Callback.class)); verify(mContentResolver, never()) .registerContentObserver( - Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID), + Settings.Secure.getUriFor( + BluetoothUtils.getPrimaryGroupIdUriForBroadcast()), false, mContentObserver); } @@ -223,11 +223,9 @@ public class AudioSharingDeviceVolumeGroupControllerTest { verify(mDeviceUpdater).registerCallback(); verify(mVolumeControl) .registerCallback(any(Executor.class), any(BluetoothVolumeControl.Callback.class)); - verify(mContentResolver) - .registerContentObserver( - Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID), - false, - mContentObserver); + verify(mContentResolver).registerContentObserver( + Settings.Secure.getUriFor(BluetoothUtils.getPrimaryGroupIdUriForBroadcast()), false, + mContentObserver); } @Test @@ -242,7 +240,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest { .registerCallback(any(Executor.class), any(BluetoothVolumeControl.Callback.class)); verify(mContentResolver) .registerContentObserver( - Settings.Secure.getUriFor(SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID), + Settings.Secure.getUriFor( + BluetoothUtils.getPrimaryGroupIdUriForBroadcast()), false, mContentObserver); } @@ -317,7 +316,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest { @Test public void onDeviceAdded_rankFallbackDeviceOnTop() { Settings.Secure.putInt( - mContentResolver, SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID, TEST_DEVICE_GROUP_ID2); + mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(), + TEST_DEVICE_GROUP_ID2); when(mPreference1.getProgress()).thenReturn(TEST_VOLUME_VALUE); when(mPreference2.getProgress()).thenReturn(TEST_VOLUME_VALUE); mController.setPreferenceGroup(mPreferenceGroup); @@ -427,7 +427,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest { @Test public void settingsObserverOnChange_updatePreferenceOrder() { Settings.Secure.putInt( - mContentResolver, SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID, TEST_DEVICE_GROUP_ID2); + mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(), + TEST_DEVICE_GROUP_ID2); when(mPreference1.getProgress()).thenReturn(TEST_VOLUME_VALUE); when(mPreference2.getProgress()).thenReturn(TEST_VOLUME_VALUE); mController.setPreferenceGroup(mPreferenceGroup); @@ -435,8 +436,8 @@ public class AudioSharingDeviceVolumeGroupControllerTest { mController.onDeviceAdded(mPreference2); shadowOf(Looper.getMainLooper()).idle(); - Settings.Secure.putInt( - mContentResolver, SETTINGS_KEY_FALLBACK_DEVICE_GROUP_ID, TEST_DEVICE_GROUP_ID1); + Settings.Secure.putInt(mContentResolver, BluetoothUtils.getPrimaryGroupIdUriForBroadcast(), + TEST_DEVICE_GROUP_ID1); mContentObserver.onChange(true); shadowOf(Looper.getMainLooper()).idle(); diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandlerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandlerTest.java index e71e876baea..1bff78bc7c2 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandlerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandlerTest.java @@ -35,7 +35,6 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcast; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothLeBroadcastReceiveState; -import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothStatusCodes; import android.content.Context; import android.os.Looper; @@ -187,9 +186,7 @@ public class AudioSharingDialogHandlerTest { public void handleUserTriggeredNonLeaDeviceConnected_noSharing_setActive() { setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice2); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -200,9 +197,7 @@ public class AudioSharingDialogHandlerTest { public void handleUserTriggeredNonLeaDeviceConnected_sharing_showStopDialog() { setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice2); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -239,9 +234,7 @@ public class AudioSharingDialogHandlerTest { public void handleUserTriggeredLeaDeviceConnected_noSharingNoTwoLeaDevices_setActive() { setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice1); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -254,9 +247,7 @@ public class AudioSharingDialogHandlerTest { when(mCachedDevice1.getGroupId()).thenReturn(-1); when(mLeAudioProfile.getGroupId(mDevice1)).thenReturn(-1); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -269,9 +260,7 @@ public class AudioSharingDialogHandlerTest { public void handleUserTriggeredLeaDeviceConnected_noSharingTwoLeaDevices_showJoinDialog() { setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -314,9 +303,7 @@ public class AudioSharingDialogHandlerTest { public void handleUserTriggeredLeaDeviceConnected_sharing_showJoinDialog() { setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of()); when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState)); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); @@ -361,9 +348,7 @@ public class AudioSharingDialogHandlerTest { handleUserTriggeredLeaDeviceConnected_sharingWithTwoLeaDevices_showDisconnectDialog() { setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3, mDevice4); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of()); when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState)); when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState)); @@ -407,9 +392,7 @@ public class AudioSharingDialogHandlerTest { public void handleNonLeaDeviceConnected_noSharing_doNothing() { setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice2); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); @@ -420,9 +403,7 @@ public class AudioSharingDialogHandlerTest { public void handleNonLeaDeviceConnected_sharing_showStopDialog() { setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice1); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); @@ -459,9 +440,7 @@ public class AudioSharingDialogHandlerTest { public void handleLeaDeviceConnected_noSharingNoTwoLeaDevices_doNothing() { setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice1); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); @@ -474,9 +453,7 @@ public class AudioSharingDialogHandlerTest { when(mCachedDevice1.getGroupId()).thenReturn(-1); when(mLeAudioProfile.getGroupId(mDevice1)).thenReturn(-1); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); @@ -489,9 +466,7 @@ public class AudioSharingDialogHandlerTest { public void handleLeaDeviceConnected_noSharingTwoLeaDevices_showJoinDialog() { setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); @@ -534,9 +509,7 @@ public class AudioSharingDialogHandlerTest { public void handleLeaDeviceConnected_sharing_showJoinDialog() { setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of()); when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState)); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false); @@ -580,9 +553,7 @@ public class AudioSharingDialogHandlerTest { public void handleLeaDeviceConnected_sharingWithTwoLeaDevices_showDisconnectDialog() { setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3, mDevice4); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of()); when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState)); when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState)); @@ -627,9 +598,7 @@ public class AudioSharingDialogHandlerTest { // Show join dialog setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -661,9 +630,7 @@ public class AudioSharingDialogHandlerTest { // Show disconnect dialog setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3, mDevice4); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of()); when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState)); when(mAssistant.getAllSources(mDevice4)).thenReturn(ImmutableList.of(mState)); @@ -697,9 +664,7 @@ public class AudioSharingDialogHandlerTest { // Show stop dialog setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice1); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -721,9 +686,7 @@ public class AudioSharingDialogHandlerTest { public void closeOpeningDialogsOtherThan() { setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(mDevice3)).thenReturn(ImmutableList.of(mState)); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -733,9 +696,7 @@ public class AudioSharingDialogHandlerTest { .containsExactly(AudioSharingStopDialogFragment.tag()); deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); @@ -769,9 +730,7 @@ public class AudioSharingDialogHandlerTest { public void onBroadcastStartFailed_logAction() { setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); @@ -797,9 +756,7 @@ public class AudioSharingDialogHandlerTest { public void onPlaybackStarted_addSource() { setUpBroadcast(false); ImmutableList deviceList = ImmutableList.of(mDevice1, mDevice3); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); @@ -825,9 +782,7 @@ public class AudioSharingDialogHandlerTest { public void onBroadcastStopFailed_logAction() { setUpBroadcast(true); ImmutableList deviceList = ImmutableList.of(mDevice1); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(deviceList); + when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mState)); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java index d68b68bcc78..bfb4f2f754c 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java @@ -378,9 +378,7 @@ public class AudioSharingSwitchBarControllerTest { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true); when(mBtnView.isEnabled()).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of()); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); doNothing().when(mBroadcast).startPrivateBroadcast(); mController.onCheckedChanged(mBtnView, /* isChecked= */ true); assertThat(mSwitchBar.isChecked()).isFalse(); @@ -392,9 +390,7 @@ public class AudioSharingSwitchBarControllerTest { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, false); when(mBtnView.isEnabled()).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of()); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); doNothing().when(mBroadcast).startPrivateBroadcast(); mController.onCheckedChanged(mBtnView, /* isChecked= */ true); verify(mBroadcast).startPrivateBroadcast(); @@ -405,9 +401,7 @@ public class AudioSharingSwitchBarControllerTest { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true); when(mBtnView.isEnabled()).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of(mDevice1)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice1)); doNothing().when(mBroadcast).startPrivateBroadcast(); mController.onCheckedChanged(mBtnView, /* isChecked= */ true); verify(mBroadcast).startPrivateBroadcast(); @@ -437,9 +431,7 @@ public class AudioSharingSwitchBarControllerTest { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true); when(mBtnView.isEnabled()).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of(mDevice2, mDevice1)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice2, mDevice1)); doNothing().when(mBroadcast).startPrivateBroadcast(); mController = new AudioSharingSwitchBarController( @@ -469,9 +461,7 @@ public class AudioSharingSwitchBarControllerTest { FeatureFlagUtils.setEnabled( mContext, FeatureFlagUtils.SETTINGS_NEED_CONNECTED_BLE_DEVICE_FOR_BROADCAST, true); when(mBtnView.isEnabled()).thenReturn(true); - when(mAssistant.getDevicesMatchingConnectionStates( - new int[] {BluetoothProfile.STATE_CONNECTED})) - .thenReturn(ImmutableList.of(mDevice2, mDevice1)); + when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of(mDevice2, mDevice1)); doNothing().when(mBroadcast).startPrivateBroadcast(); mController.onCheckedChanged(mBtnView, /* isChecked= */ true); verify(mBroadcast).startPrivateBroadcast(); diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogTest.java index 601c4327090..e00a146244d 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamConfirmDialogTest.java @@ -219,7 +219,7 @@ public class AudioStreamConfirmDialogTest { public void showDialog_noMetadata() { List devices = new ArrayList<>(); devices.add(mBluetoothDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(DEVICE_NAME); FragmentController.setupFragment( @@ -267,7 +267,7 @@ public class AudioStreamConfirmDialogTest { public void showDialog_invalidMetadata() { List devices = new ArrayList<>(); devices.add(mBluetoothDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(DEVICE_NAME); Intent intent = new Intent(); @@ -318,7 +318,7 @@ public class AudioStreamConfirmDialogTest { public void showDialog_confirmListen() { List devices = new ArrayList<>(); devices.add(mBluetoothDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mBluetoothDevice.getAlias()).thenReturn(""); Intent intent = new Intent(); diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelperTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelperTest.java index 66ef5fbdc62..b91866bf326 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelperTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsHelperTest.java @@ -91,7 +91,7 @@ public class AudioStreamsHelperTest { @Test public void addSource_noDevice_doNothing() { - when(mAssistant.getDevicesMatchingConnectionStates(any())) + when(mAssistant.getAllConnectedDevices()) .thenReturn(Collections.emptyList()); mHelper.addSource(mMetadata); @@ -102,7 +102,7 @@ public class AudioStreamsHelperTest { public void addSource_hasDevice() { List devices = new ArrayList<>(); devices.add(mDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice); when(mCachedDevice.getDevice()).thenReturn(mDevice); when(mCachedDevice.getGroupId()).thenReturn(GROUP_ID); @@ -114,7 +114,7 @@ public class AudioStreamsHelperTest { @Test public void removeSource_noDevice_doNothing() { - when(mAssistant.getDevicesMatchingConnectionStates(any())) + when(mAssistant.getAllConnectedDevices()) .thenReturn(Collections.emptyList()); mHelper.removeSource(BROADCAST_ID_1); @@ -125,7 +125,7 @@ public class AudioStreamsHelperTest { public void removeSource_noConnectedSource_doNothing() { List devices = new ArrayList<>(); devices.add(mDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class); when(source.getBroadcastId()).thenReturn(BROADCAST_ID_2); when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice); @@ -142,7 +142,7 @@ public class AudioStreamsHelperTest { public void removeSource_hasConnectedSource() { List devices = new ArrayList<>(); devices.add(mDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class); when(source.getBroadcastId()).thenReturn(BROADCAST_ID_2); when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice); @@ -164,7 +164,7 @@ public class AudioStreamsHelperTest { var memberDevice = mock(BluetoothDevice.class); devices.add(mDevice); devices.add(memberDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class); when(source.getBroadcastId()).thenReturn(BROADCAST_ID_2); when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice); @@ -196,7 +196,7 @@ public class AudioStreamsHelperTest { public void getAllConnectedSources_returnSource() { List devices = new ArrayList<>(); devices.add(mDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class); when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice); when(mCachedDevice.getDevice()).thenReturn(mDevice); @@ -222,7 +222,7 @@ public class AudioStreamsHelperTest { public void startMediaService_hasDevice() { List devices = new ArrayList<>(); devices.add(mDevice); - when(mAssistant.getDevicesMatchingConnectionStates(any())).thenReturn(devices); + when(mAssistant.getAllConnectedDevices()).thenReturn(devices); BluetoothLeBroadcastReceiveState source = mock(BluetoothLeBroadcastReceiveState.class); when(mDeviceManager.findDevice(any())).thenReturn(mCachedDevice); when(mCachedDevice.getDevice()).thenReturn(mDevice);