Merge "[Audiosharing] Clean up dup codes" into main
This commit is contained in:
@@ -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(
|
||||
|
@@ -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 {
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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<AudioSharingDeviceItem> 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<AudioSharingDeviceItem> 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));
|
||||
|
@@ -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<AudioSharingDeviceItem> 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<BluetoothDevice> 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) {
|
||||
|
@@ -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,
|
||||
() -> {
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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<AudioSharingDeviceItem> deviceItems,
|
||||
@NonNull DialogEventListener listener,
|
||||
@NonNull Pair<Integer, Object>[] eventData) {
|
||||
if (!AudioSharingUtils.isFeatureEnabled()) return;
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
|
@@ -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<CachedBluetoothDevice> 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<Fragment> 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);
|
||||
|
@@ -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<Integer, Object>[] 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(
|
||||
|
@@ -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<Integer, Object>[] eventData) {
|
||||
if (!AudioSharingUtils.isFeatureEnabled()) return;
|
||||
if (!BluetoothUtils.isAudioSharingEnabled()) return;
|
||||
final FragmentManager manager;
|
||||
try {
|
||||
manager = host.getChildFragmentManager();
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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<Integer, Object>[] 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(
|
||||
|
@@ -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(
|
||||
|
@@ -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<BluetoothDevice> connectedDevices =
|
||||
assistant.getDevicesMatchingConnectionStates(
|
||||
new int[] {BluetoothProfile.STATE_CONNECTED});
|
||||
List<BluetoothDevice> 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<BluetoothDevice> sinks, @Nullable LocalBluetoothManager localBtManager) {
|
||||
@@ -289,9 +269,7 @@ public class AudioSharingUtils {
|
||||
Log.d(TAG, "skip addSourceToTargetDevices: There is no broadcastMetadata.");
|
||||
return;
|
||||
}
|
||||
List<BluetoothDevice> connectedDevices =
|
||||
assistant.getDevicesMatchingConnectionStates(
|
||||
new int[] {BluetoothProfile.STATE_CONNECTED});
|
||||
List<BluetoothDevice> 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}.
|
||||
*
|
||||
* <p>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);
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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) {
|
||||
|
@@ -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<BluetoothDevice> connectedDevices =
|
||||
leBroadcastAssistant.getDevicesMatchingConnectionStates(
|
||||
new int[] {BluetoothProfile.STATE_CONNECTED});
|
||||
List<BluetoothDevice> connectedDevices = leBroadcastAssistant.getAllConnectedDevices();
|
||||
Optional<CachedBluetoothDevice> cachedBluetoothDevice =
|
||||
inSharingOnly
|
||||
? getCachedBluetoothDeviceInSharing(manager)
|
||||
|
@@ -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<AudioSharingDeviceItem> 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();
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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();
|
||||
|
@@ -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();
|
||||
|
@@ -219,7 +219,7 @@ public class AudioStreamConfirmDialogTest {
|
||||
public void showDialog_noMetadata() {
|
||||
List<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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();
|
||||
|
@@ -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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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<BluetoothDevice> 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);
|
||||
|
Reference in New Issue
Block a user