Loading android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java +51 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothLeAudio; import android.bluetooth.BluetoothProfile; import android.content.BroadcastReceiver; import android.content.Context; Loading @@ -40,6 +41,7 @@ import android.util.Log; import com.android.bluetooth.a2dp.A2dpService; import com.android.bluetooth.hearingaid.HearingAidService; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.le_audio.LeAudioService; import com.android.internal.annotations.VisibleForTesting; import java.util.LinkedList; Loading Loading @@ -112,6 +114,7 @@ class ActiveDeviceManager { private static final int MESSAGE_HFP_ACTION_CONNECTION_STATE_CHANGED = 4; private static final int MESSAGE_HFP_ACTION_ACTIVE_DEVICE_CHANGED = 5; private static final int MESSAGE_HEARING_AID_ACTION_ACTIVE_DEVICE_CHANGED = 6; private static final int MESSAGE_LE_AUDIO_ACTION_ACTIVE_DEVICE_CHANGED = 7; private final AdapterService mAdapterService; private final ServiceFactory mFactory; Loading @@ -125,6 +128,7 @@ class ActiveDeviceManager { private BluetoothDevice mA2dpActiveDevice = null; private BluetoothDevice mHfpActiveDevice = null; private BluetoothDevice mHearingAidActiveDevice = null; private BluetoothDevice mLeAudioActiveDevice = null; // Broadcast receiver for all changes private final BroadcastReceiver mReceiver = new BroadcastReceiver() { Loading Loading @@ -160,6 +164,10 @@ class ActiveDeviceManager { mHandler.obtainMessage(MESSAGE_HEARING_AID_ACTION_ACTIVE_DEVICE_CHANGED, intent).sendToTarget(); break; case BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED: mHandler.obtainMessage(MESSAGE_LE_AUDIO_ACTION_ACTIVE_DEVICE_CHANGED, intent).sendToTarget(); break; default: Log.e(TAG, "Received unexpected intent, action=" + action); break; Loading Loading @@ -241,6 +249,7 @@ class ActiveDeviceManager { } if (device != null && !Objects.equals(mA2dpActiveDevice, device)) { setHearingAidActiveDevice(null); setLeAudioActiveDevice(null); } // Just assign locally the new value mA2dpActiveDevice = device; Loading Loading @@ -300,6 +309,7 @@ class ActiveDeviceManager { } if (device != null && !Objects.equals(mHfpActiveDevice, device)) { setHearingAidActiveDevice(null); setLeAudioActiveDevice(null); } // Just assign locally the new value mHfpActiveDevice = device; Loading @@ -319,9 +329,28 @@ class ActiveDeviceManager { if (device != null) { setA2dpActiveDevice(null); setHfpActiveDevice(null); setLeAudioActiveDevice(null); } } break; case MESSAGE_LE_AUDIO_ACTION_ACTIVE_DEVICE_CHANGED: { Intent intent = (Intent) msg.obj; BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (DBG) { Log.d(TAG, "handleMessage(MESSAGE_LE_AUDIO_ACTION_ACTIVE_DEVICE_CHANGED): " + "device= " + device); } // Just assign locally the new value if (device != null && !Objects.equals(mLeAudioActiveDevice, device)) { setA2dpActiveDevice(null); setHfpActiveDevice(null); setHearingAidActiveDevice(null); } mLeAudioActiveDevice = device; } break; } } } Loading Loading @@ -390,6 +419,7 @@ class ActiveDeviceManager { filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED); filter.addAction(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED); filter.addAction(BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED); mAdapterService.registerReceiver(mReceiver, filter); mAudioManager.registerAudioDeviceCallback(mAudioManagerAudioDeviceCallback, mHandler); Loading Loading @@ -466,6 +496,20 @@ class ActiveDeviceManager { mHearingAidActiveDevice = device; } private void setLeAudioActiveDevice(BluetoothDevice device) { if (DBG) { Log.d(TAG, "setLeAudioActiveDevice(" + device + ")"); } final LeAudioService leAudioService = mFactory.getLeAudioService(); if (leAudioService == null) { return; } if (!leAudioService.setActiveDevice(device)) { return; } mLeAudioActiveDevice = device; } private void resetState() { mA2dpConnectedDevices.clear(); mA2dpActiveDevice = null; Loading @@ -474,6 +518,7 @@ class ActiveDeviceManager { mHfpActiveDevice = null; mHearingAidActiveDevice = null; mLeAudioActiveDevice = null; } @VisibleForTesting Loading @@ -496,6 +541,11 @@ class ActiveDeviceManager { return mHearingAidActiveDevice; } @VisibleForTesting BluetoothDevice getLeAudioActiveDevice() { return mLeAudioActiveDevice; } /** * Called when a wired audio device is connected. * It might be called multiple times each time a wired audio device is connected. Loading @@ -509,5 +559,6 @@ class ActiveDeviceManager { setA2dpActiveDevice(null); setHfpActiveDevice(null); setHearingAidActiveDevice(null); setLeAudioActiveDevice(null); } } android/app/src/com/android/bluetooth/btservice/AdapterService.java +36 −1 Original line number Diff line number Diff line Loading @@ -110,6 +110,7 @@ import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hfpclient.HeadsetClientService; import com.android.bluetooth.hid.HidDeviceService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.le_audio.LeAudioService; import com.android.bluetooth.map.BluetoothMapService; import com.android.bluetooth.mapclient.MapClientService; import com.android.bluetooth.pan.PanService; Loading Loading @@ -298,6 +299,7 @@ public class AdapterService extends Service { private SapService mSapService; private VolumeControlService mVolumeControlService; private CsipSetCoordinatorService mCsipSetCoordinatorService; private LeAudioService mLeAudioService; private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver; Loading Loading @@ -974,6 +976,9 @@ public class AdapterService extends Service { if (profile == BluetoothProfile.CSIP_SET_COORDINATOR) { return Utils.arrayContains(remoteDeviceUuids, BluetoothUuid.COORDINATED_SET); } if (profile == BluetoothProfile.LE_AUDIO) { return Utils.arrayContains(remoteDeviceUuids, BluetoothUuid.LE_AUDIO); } Log.e(TAG, "isSupported: Unexpected profile passed in to function: " + profile); return false; Loading Loading @@ -1033,6 +1038,10 @@ public class AdapterService extends Service { > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { return true; } if (mLeAudioService != null && mLeAudioService.getConnectionPolicy(device) > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { return true; } return false; } Loading Loading @@ -1124,7 +1133,13 @@ public class AdapterService extends Service { Log.i(TAG, "connectEnabledProfiles: Connecting Coordinated Set Profile"); mCsipSetCoordinatorService.connect(device); } if (mLeAudioService != null && isSupported(localDeviceUuids, remoteDeviceUuids, BluetoothProfile.LE_AUDIO, device) && mLeAudioService.getConnectionPolicy(device) > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { Log.i(TAG, "connectEnabledProfiles: Connecting LeAudio profile (BAP)"); mLeAudioService.connect(device); } return BluetoothStatusCodes.SUCCESS; } Loading Loading @@ -1163,6 +1178,7 @@ public class AdapterService extends Service { mSapService = SapService.getSapService(); mVolumeControlService = VolumeControlService.getVolumeControlService(); mCsipSetCoordinatorService = CsipSetCoordinatorService.getCsipSetCoordinatorService(); mLeAudioService = LeAudioService.getLeAudioService(); } private boolean isAvailable() { Loading Loading @@ -2839,6 +2855,13 @@ public class AdapterService extends Service { return false; } if (mLeAudioService != null && (device == null || mLeAudioService.getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_ALLOWED)) { Log.i(TAG, "setActiveDevice: Setting active Le Audio device " + device); mLeAudioService.setActiveDevice(device); } if (setA2dp && mA2dpService != null && (device == null || mA2dpService.getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_ALLOWED)) { Loading Loading @@ -3012,6 +3035,13 @@ public class AdapterService extends Service { device, BluetoothProfile.CONNECTION_POLICY_ALLOWED); numProfilesConnected++; } if (mLeAudioService != null && isSupported(localDeviceUuids, remoteDeviceUuids, BluetoothProfile.LE_AUDIO, device)) { Log.i(TAG, "connectAllEnabledProfiles: Connecting LeAudio profile (BAP)"); mLeAudioService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED); numProfilesConnected++; } Log.i(TAG, "connectAllEnabledProfiles: Number of Profiles Connected: " + numProfilesConnected); Loading Loading @@ -3109,6 +3139,11 @@ public class AdapterService extends Service { Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Coordinater Set Profile"); mCsipSetCoordinatorService.disconnect(device); } if (mLeAudioService != null && mLeAudioService.getConnectionState(device) == BluetoothProfile.STATE_CONNECTED) { Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting LeAudio profile (BAP)"); mLeAudioService.disconnect(device); } return BluetoothStatusCodes.SUCCESS; } Loading android/app/src/com/android/bluetooth/btservice/ServiceFactory.java +5 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.bluetooth.hearingaid.HearingAidService; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hid.HidDeviceService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.le_audio.LeAudioService; import com.android.bluetooth.mcp.McpService; import com.android.bluetooth.pan.PanService; Loading Loading @@ -51,6 +52,10 @@ public class ServiceFactory { return HearingAidService.getHearingAidService(); } public LeAudioService getLeAudioService() { return LeAudioService.getLeAudioService(); } public AvrcpTargetService getAvrcpTargetService() { return AvrcpTargetService.get(); } Loading Loading
android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java +51 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothLeAudio; import android.bluetooth.BluetoothProfile; import android.content.BroadcastReceiver; import android.content.Context; Loading @@ -40,6 +41,7 @@ import android.util.Log; import com.android.bluetooth.a2dp.A2dpService; import com.android.bluetooth.hearingaid.HearingAidService; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.le_audio.LeAudioService; import com.android.internal.annotations.VisibleForTesting; import java.util.LinkedList; Loading Loading @@ -112,6 +114,7 @@ class ActiveDeviceManager { private static final int MESSAGE_HFP_ACTION_CONNECTION_STATE_CHANGED = 4; private static final int MESSAGE_HFP_ACTION_ACTIVE_DEVICE_CHANGED = 5; private static final int MESSAGE_HEARING_AID_ACTION_ACTIVE_DEVICE_CHANGED = 6; private static final int MESSAGE_LE_AUDIO_ACTION_ACTIVE_DEVICE_CHANGED = 7; private final AdapterService mAdapterService; private final ServiceFactory mFactory; Loading @@ -125,6 +128,7 @@ class ActiveDeviceManager { private BluetoothDevice mA2dpActiveDevice = null; private BluetoothDevice mHfpActiveDevice = null; private BluetoothDevice mHearingAidActiveDevice = null; private BluetoothDevice mLeAudioActiveDevice = null; // Broadcast receiver for all changes private final BroadcastReceiver mReceiver = new BroadcastReceiver() { Loading Loading @@ -160,6 +164,10 @@ class ActiveDeviceManager { mHandler.obtainMessage(MESSAGE_HEARING_AID_ACTION_ACTIVE_DEVICE_CHANGED, intent).sendToTarget(); break; case BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED: mHandler.obtainMessage(MESSAGE_LE_AUDIO_ACTION_ACTIVE_DEVICE_CHANGED, intent).sendToTarget(); break; default: Log.e(TAG, "Received unexpected intent, action=" + action); break; Loading Loading @@ -241,6 +249,7 @@ class ActiveDeviceManager { } if (device != null && !Objects.equals(mA2dpActiveDevice, device)) { setHearingAidActiveDevice(null); setLeAudioActiveDevice(null); } // Just assign locally the new value mA2dpActiveDevice = device; Loading Loading @@ -300,6 +309,7 @@ class ActiveDeviceManager { } if (device != null && !Objects.equals(mHfpActiveDevice, device)) { setHearingAidActiveDevice(null); setLeAudioActiveDevice(null); } // Just assign locally the new value mHfpActiveDevice = device; Loading @@ -319,9 +329,28 @@ class ActiveDeviceManager { if (device != null) { setA2dpActiveDevice(null); setHfpActiveDevice(null); setLeAudioActiveDevice(null); } } break; case MESSAGE_LE_AUDIO_ACTION_ACTIVE_DEVICE_CHANGED: { Intent intent = (Intent) msg.obj; BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (DBG) { Log.d(TAG, "handleMessage(MESSAGE_LE_AUDIO_ACTION_ACTIVE_DEVICE_CHANGED): " + "device= " + device); } // Just assign locally the new value if (device != null && !Objects.equals(mLeAudioActiveDevice, device)) { setA2dpActiveDevice(null); setHfpActiveDevice(null); setHearingAidActiveDevice(null); } mLeAudioActiveDevice = device; } break; } } } Loading Loading @@ -390,6 +419,7 @@ class ActiveDeviceManager { filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED); filter.addAction(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED); filter.addAction(BluetoothLeAudio.ACTION_LE_AUDIO_ACTIVE_DEVICE_CHANGED); mAdapterService.registerReceiver(mReceiver, filter); mAudioManager.registerAudioDeviceCallback(mAudioManagerAudioDeviceCallback, mHandler); Loading Loading @@ -466,6 +496,20 @@ class ActiveDeviceManager { mHearingAidActiveDevice = device; } private void setLeAudioActiveDevice(BluetoothDevice device) { if (DBG) { Log.d(TAG, "setLeAudioActiveDevice(" + device + ")"); } final LeAudioService leAudioService = mFactory.getLeAudioService(); if (leAudioService == null) { return; } if (!leAudioService.setActiveDevice(device)) { return; } mLeAudioActiveDevice = device; } private void resetState() { mA2dpConnectedDevices.clear(); mA2dpActiveDevice = null; Loading @@ -474,6 +518,7 @@ class ActiveDeviceManager { mHfpActiveDevice = null; mHearingAidActiveDevice = null; mLeAudioActiveDevice = null; } @VisibleForTesting Loading @@ -496,6 +541,11 @@ class ActiveDeviceManager { return mHearingAidActiveDevice; } @VisibleForTesting BluetoothDevice getLeAudioActiveDevice() { return mLeAudioActiveDevice; } /** * Called when a wired audio device is connected. * It might be called multiple times each time a wired audio device is connected. Loading @@ -509,5 +559,6 @@ class ActiveDeviceManager { setA2dpActiveDevice(null); setHfpActiveDevice(null); setHearingAidActiveDevice(null); setLeAudioActiveDevice(null); } }
android/app/src/com/android/bluetooth/btservice/AdapterService.java +36 −1 Original line number Diff line number Diff line Loading @@ -110,6 +110,7 @@ import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hfpclient.HeadsetClientService; import com.android.bluetooth.hid.HidDeviceService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.le_audio.LeAudioService; import com.android.bluetooth.map.BluetoothMapService; import com.android.bluetooth.mapclient.MapClientService; import com.android.bluetooth.pan.PanService; Loading Loading @@ -298,6 +299,7 @@ public class AdapterService extends Service { private SapService mSapService; private VolumeControlService mVolumeControlService; private CsipSetCoordinatorService mCsipSetCoordinatorService; private LeAudioService mLeAudioService; private BinderCallsStats.SettingsObserver mBinderCallsSettingsObserver; Loading Loading @@ -974,6 +976,9 @@ public class AdapterService extends Service { if (profile == BluetoothProfile.CSIP_SET_COORDINATOR) { return Utils.arrayContains(remoteDeviceUuids, BluetoothUuid.COORDINATED_SET); } if (profile == BluetoothProfile.LE_AUDIO) { return Utils.arrayContains(remoteDeviceUuids, BluetoothUuid.LE_AUDIO); } Log.e(TAG, "isSupported: Unexpected profile passed in to function: " + profile); return false; Loading Loading @@ -1033,6 +1038,10 @@ public class AdapterService extends Service { > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { return true; } if (mLeAudioService != null && mLeAudioService.getConnectionPolicy(device) > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { return true; } return false; } Loading Loading @@ -1124,7 +1133,13 @@ public class AdapterService extends Service { Log.i(TAG, "connectEnabledProfiles: Connecting Coordinated Set Profile"); mCsipSetCoordinatorService.connect(device); } if (mLeAudioService != null && isSupported(localDeviceUuids, remoteDeviceUuids, BluetoothProfile.LE_AUDIO, device) && mLeAudioService.getConnectionPolicy(device) > BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { Log.i(TAG, "connectEnabledProfiles: Connecting LeAudio profile (BAP)"); mLeAudioService.connect(device); } return BluetoothStatusCodes.SUCCESS; } Loading Loading @@ -1163,6 +1178,7 @@ public class AdapterService extends Service { mSapService = SapService.getSapService(); mVolumeControlService = VolumeControlService.getVolumeControlService(); mCsipSetCoordinatorService = CsipSetCoordinatorService.getCsipSetCoordinatorService(); mLeAudioService = LeAudioService.getLeAudioService(); } private boolean isAvailable() { Loading Loading @@ -2839,6 +2855,13 @@ public class AdapterService extends Service { return false; } if (mLeAudioService != null && (device == null || mLeAudioService.getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_ALLOWED)) { Log.i(TAG, "setActiveDevice: Setting active Le Audio device " + device); mLeAudioService.setActiveDevice(device); } if (setA2dp && mA2dpService != null && (device == null || mA2dpService.getConnectionPolicy(device) == BluetoothProfile.CONNECTION_POLICY_ALLOWED)) { Loading Loading @@ -3012,6 +3035,13 @@ public class AdapterService extends Service { device, BluetoothProfile.CONNECTION_POLICY_ALLOWED); numProfilesConnected++; } if (mLeAudioService != null && isSupported(localDeviceUuids, remoteDeviceUuids, BluetoothProfile.LE_AUDIO, device)) { Log.i(TAG, "connectAllEnabledProfiles: Connecting LeAudio profile (BAP)"); mLeAudioService.setConnectionPolicy(device, BluetoothProfile.CONNECTION_POLICY_ALLOWED); numProfilesConnected++; } Log.i(TAG, "connectAllEnabledProfiles: Number of Profiles Connected: " + numProfilesConnected); Loading Loading @@ -3109,6 +3139,11 @@ public class AdapterService extends Service { Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting Coordinater Set Profile"); mCsipSetCoordinatorService.disconnect(device); } if (mLeAudioService != null && mLeAudioService.getConnectionState(device) == BluetoothProfile.STATE_CONNECTED) { Log.i(TAG, "disconnectAllEnabledProfiles: Disconnecting LeAudio profile (BAP)"); mLeAudioService.disconnect(device); } return BluetoothStatusCodes.SUCCESS; } Loading
android/app/src/com/android/bluetooth/btservice/ServiceFactory.java +5 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.bluetooth.hearingaid.HearingAidService; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hid.HidDeviceService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.le_audio.LeAudioService; import com.android.bluetooth.mcp.McpService; import com.android.bluetooth.pan.PanService; Loading Loading @@ -51,6 +52,10 @@ public class ServiceFactory { return HearingAidService.getHearingAidService(); } public LeAudioService getLeAudioService() { return LeAudioService.getLeAudioService(); } public AvrcpTargetService getAvrcpTargetService() { return AvrcpTargetService.get(); } Loading