Loading src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java +4 −1 Original line number Diff line number Diff line Loading @@ -160,6 +160,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro + ", reason = " + reason); mBluetoothDeviceUpdater.forceUpdate(); AudioSharingUtils.updateActiveDeviceIfNeeded(mLocalBtManager); } @Override Loading Loading @@ -204,6 +205,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro + ", reason = " + reason); mBluetoothDeviceUpdater.forceUpdate(); AudioSharingUtils.updateActiveDeviceIfNeeded(mLocalBtManager); } @Override Loading Loading @@ -299,7 +301,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro mPreferenceGroup.setVisible(false); mAudioSharingSettingsPreference.setVisible(false); if (isAvailable() && mBluetoothDeviceUpdater != null) { if (isAvailable()) { mBluetoothDeviceUpdater.setPrefContext(screen.getContext()); mBluetoothDeviceUpdater.forceUpdate(); } Loading @@ -309,6 +311,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro public int getAvailabilityStatus() { return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH) && Flags.enableLeAudioSharing() && mBluetoothDeviceUpdater != null ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE; } Loading src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java +1 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController + sourceId + ", reason = " + reason); AudioSharingUtils.updateActiveDeviceIfNeeded(mBtManager); } @Override Loading src/com/android/settings/connecteddevice/audiosharing/AudioSharingUtils.java +31 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.connecteddevice.audiosharing; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastReceiveState; Loading Loading @@ -89,11 +90,11 @@ public class AudioSharingUtils { * @return A list of ordered connected devices eligible for the audio sharing. The active device * is placed in the first place if it exists. */ public static ArrayList<CachedBluetoothDevice> buildOrderedConnectedLeadDevices( public static List<CachedBluetoothDevice> buildOrderedConnectedLeadDevices( LocalBluetoothManager localBtManager, Map<Integer, List<CachedBluetoothDevice>> groupedConnectedDevices, boolean filterByInSharing) { ArrayList<CachedBluetoothDevice> orderedDevices = new ArrayList<>(); List<CachedBluetoothDevice> orderedDevices = new ArrayList<>(); LocalBluetoothLeBroadcastAssistant assistant = localBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); if (assistant == null) return orderedDevices; Loading Loading @@ -234,4 +235,32 @@ public class AudioSharingUtils { ThreadUtils.postOnMainThread( () -> Toast.makeText(context, message, Toast.LENGTH_LONG).show()); } /** Automatically update active device if needed. */ public static void updateActiveDeviceIfNeeded(LocalBluetoothManager localBtManager) { if (localBtManager == null) return; Map<Integer, List<CachedBluetoothDevice>> groupedConnectedDevices = fetchConnectedDevicesByGroupId(localBtManager); List<CachedBluetoothDevice> devicesInSharing = buildOrderedConnectedLeadDevices( localBtManager, groupedConnectedDevices, /* filterByInSharing= */ true); if (devicesInSharing.isEmpty()) return; List<BluetoothDevice> devices = BluetoothAdapter.getDefaultAdapter().getMostRecentlyConnectedDevices(); CachedBluetoothDevice targetDevice = null; int targetDeviceIdx = -1; for (CachedBluetoothDevice device : devicesInSharing) { if (devices.contains(device.getDevice())) { int idx = devices.indexOf(device.getDevice()); if (idx > targetDeviceIdx) { targetDeviceIdx = idx; targetDevice = device; } } } if (targetDevice != null && !isActiveLeAudioDevice(targetDevice)) { Log.d(TAG, "Set active device: " + targetDevice.getDevice().getAnonymizedAddress()); targetDevice.setActive(); } } } Loading
src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java +4 −1 Original line number Diff line number Diff line Loading @@ -160,6 +160,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro + ", reason = " + reason); mBluetoothDeviceUpdater.forceUpdate(); AudioSharingUtils.updateActiveDeviceIfNeeded(mLocalBtManager); } @Override Loading Loading @@ -204,6 +205,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro + ", reason = " + reason); mBluetoothDeviceUpdater.forceUpdate(); AudioSharingUtils.updateActiveDeviceIfNeeded(mLocalBtManager); } @Override Loading Loading @@ -299,7 +301,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro mPreferenceGroup.setVisible(false); mAudioSharingSettingsPreference.setVisible(false); if (isAvailable() && mBluetoothDeviceUpdater != null) { if (isAvailable()) { mBluetoothDeviceUpdater.setPrefContext(screen.getContext()); mBluetoothDeviceUpdater.forceUpdate(); } Loading @@ -309,6 +311,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro public int getAvailabilityStatus() { return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH) && Flags.enableLeAudioSharing() && mBluetoothDeviceUpdater != null ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE; } Loading
src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarController.java +1 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController + sourceId + ", reason = " + reason); AudioSharingUtils.updateActiveDeviceIfNeeded(mBtManager); } @Override Loading
src/com/android/settings/connecteddevice/audiosharing/AudioSharingUtils.java +31 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.settings.connecteddevice.audiosharing; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastReceiveState; Loading Loading @@ -89,11 +90,11 @@ public class AudioSharingUtils { * @return A list of ordered connected devices eligible for the audio sharing. The active device * is placed in the first place if it exists. */ public static ArrayList<CachedBluetoothDevice> buildOrderedConnectedLeadDevices( public static List<CachedBluetoothDevice> buildOrderedConnectedLeadDevices( LocalBluetoothManager localBtManager, Map<Integer, List<CachedBluetoothDevice>> groupedConnectedDevices, boolean filterByInSharing) { ArrayList<CachedBluetoothDevice> orderedDevices = new ArrayList<>(); List<CachedBluetoothDevice> orderedDevices = new ArrayList<>(); LocalBluetoothLeBroadcastAssistant assistant = localBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); if (assistant == null) return orderedDevices; Loading Loading @@ -234,4 +235,32 @@ public class AudioSharingUtils { ThreadUtils.postOnMainThread( () -> Toast.makeText(context, message, Toast.LENGTH_LONG).show()); } /** Automatically update active device if needed. */ public static void updateActiveDeviceIfNeeded(LocalBluetoothManager localBtManager) { if (localBtManager == null) return; Map<Integer, List<CachedBluetoothDevice>> groupedConnectedDevices = fetchConnectedDevicesByGroupId(localBtManager); List<CachedBluetoothDevice> devicesInSharing = buildOrderedConnectedLeadDevices( localBtManager, groupedConnectedDevices, /* filterByInSharing= */ true); if (devicesInSharing.isEmpty()) return; List<BluetoothDevice> devices = BluetoothAdapter.getDefaultAdapter().getMostRecentlyConnectedDevices(); CachedBluetoothDevice targetDevice = null; int targetDeviceIdx = -1; for (CachedBluetoothDevice device : devicesInSharing) { if (devices.contains(device.getDevice())) { int idx = devices.indexOf(device.getDevice()); if (idx > targetDeviceIdx) { targetDeviceIdx = idx; targetDevice = device; } } } if (targetDevice != null && !isActiveLeAudioDevice(targetDevice)) { Log.d(TAG, "Set active device: " + targetDevice.getDevice().getAnonymizedAddress()); targetDevice.setActive(); } } }