Loading src/com/android/server/telecom/BluetoothAdapterProxy.java +8 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.telecom; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; Loading @@ -37,4 +38,11 @@ public class BluetoothAdapterProxy { } return mBluetoothAdapter.getProfileProxy(context, listener, profile); } public boolean setActiveDevice(BluetoothDevice device, int profiles) { if (mBluetoothAdapter == null) { return false; } return mBluetoothAdapter.setActiveDevice(device, profiles); } } src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +13 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.telecom.bluetooth; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHearingAid; Loading Loading @@ -119,9 +120,11 @@ public class BluetoothDeviceManager { private BluetoothHeadsetProxy mBluetoothHeadsetService; private BluetoothHearingAid mBluetoothHearingAidService; private BluetoothDevice mBluetoothHearingAidActiveDeviceCache; private BluetoothAdapterProxy mBluetoothAdapterProxy; public BluetoothDeviceManager(Context context, BluetoothAdapterProxy bluetoothAdapter) { if (bluetoothAdapter != null) { mBluetoothAdapterProxy = bluetoothAdapter; bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET); bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener, Loading Loading @@ -246,7 +249,8 @@ public class BluetoothDeviceManager { } else { for (BluetoothDevice device : mBluetoothHearingAidService.getActiveDevices()) { if (device != null) { mBluetoothHearingAidService.setActiveDevice(null); mBluetoothAdapterProxy.setActiveDevice(null, BluetoothAdapter.ACTIVE_DEVICE_ALL); } } } Loading @@ -269,15 +273,17 @@ public class BluetoothDeviceManager { Log.w(this, "Attempting to turn on audio when the hearing aid service is null"); return false; } return mBluetoothHearingAidService.setActiveDevice( mHearingAidDevicesByAddress.get(address)); return mBluetoothAdapterProxy.setActiveDevice( mHearingAidDevicesByAddress.get(address), BluetoothAdapter.ACTIVE_DEVICE_ALL); } else if (mHfpDevicesByAddress.containsKey(address)) { BluetoothDevice device = mHfpDevicesByAddress.get(address); if (mBluetoothHeadsetService == null) { Log.w(this, "Attempting to turn on audio when the headset service is null"); return false; } boolean success = mBluetoothHeadsetService.setActiveDevice(device); boolean success = mBluetoothAdapterProxy.setActiveDevice(device, BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL); if (!success) { Log.w(this, "Couldn't set active device to %s", address); return false; Loading @@ -304,7 +310,9 @@ public class BluetoothDeviceManager { public void restoreHearingAidDevice() { if (mBluetoothHearingAidActiveDeviceCache != null && mBluetoothHearingAidService != null) { mBluetoothHearingAidService.setActiveDevice(mBluetoothHearingAidActiveDeviceCache); mBluetoothAdapterProxy.setActiveDevice( mBluetoothHearingAidActiveDeviceCache, BluetoothAdapter.ACTIVE_DEVICE_ALL); mBluetoothHearingAidActiveDeviceCache = null; } } Loading tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +7 −8 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.telecom.tests; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHearingAid; Loading Loading @@ -215,12 +216,10 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { public void testConnectDisconnectAudioHeadset() { receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1, false)); when(mHeadsetProxy.setActiveDevice(nullable(BluetoothDevice.class))).thenReturn(true); when(mAdapterProxy.setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true); mBluetoothDeviceManager.connectAudio(device1.getAddress()); verify(mHeadsetProxy).setActiveDevice(device1); verify(mHeadsetProxy).connectAudio(); verify(mBluetoothHearingAid, never()).setActiveDevice(nullable(BluetoothDevice.class)); verify(mAdapterProxy).setActiveDevice(device1, BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL); verify(mAdapterProxy, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL)); mBluetoothDeviceManager.disconnectAudio(); verify(mHeadsetProxy).disconnectAudio(); } Loading @@ -231,14 +230,14 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true)); mBluetoothDeviceManager.connectAudio(device2.getAddress()); verify(mBluetoothHearingAid).setActiveDevice(device2); verify(mAdapterProxy).setActiveDevice(device2, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mHeadsetProxy, never()).connectAudio(); verify(mHeadsetProxy, never()).setActiveDevice(nullable(BluetoothDevice.class)); verify(mAdapterProxy, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL)); when(mBluetoothHearingAid.getActiveDevices()).thenReturn(Arrays.asList(device2, null)); mBluetoothDeviceManager.disconnectAudio(); verify(mBluetoothHearingAid).setActiveDevice(null); verify(mAdapterProxy).setActiveDevice(null, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mHeadsetProxy).disconnectAudio(); } Loading Loading
src/com/android/server/telecom/BluetoothAdapterProxy.java +8 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.telecom; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; Loading @@ -37,4 +38,11 @@ public class BluetoothAdapterProxy { } return mBluetoothAdapter.getProfileProxy(context, listener, profile); } public boolean setActiveDevice(BluetoothDevice device, int profiles) { if (mBluetoothAdapter == null) { return false; } return mBluetoothAdapter.setActiveDevice(device, profiles); } }
src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +13 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.telecom.bluetooth; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHearingAid; Loading Loading @@ -119,9 +120,11 @@ public class BluetoothDeviceManager { private BluetoothHeadsetProxy mBluetoothHeadsetService; private BluetoothHearingAid mBluetoothHearingAidService; private BluetoothDevice mBluetoothHearingAidActiveDeviceCache; private BluetoothAdapterProxy mBluetoothAdapterProxy; public BluetoothDeviceManager(Context context, BluetoothAdapterProxy bluetoothAdapter) { if (bluetoothAdapter != null) { mBluetoothAdapterProxy = bluetoothAdapter; bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET); bluetoothAdapter.getProfileProxy(context, mBluetoothProfileServiceListener, Loading Loading @@ -246,7 +249,8 @@ public class BluetoothDeviceManager { } else { for (BluetoothDevice device : mBluetoothHearingAidService.getActiveDevices()) { if (device != null) { mBluetoothHearingAidService.setActiveDevice(null); mBluetoothAdapterProxy.setActiveDevice(null, BluetoothAdapter.ACTIVE_DEVICE_ALL); } } } Loading @@ -269,15 +273,17 @@ public class BluetoothDeviceManager { Log.w(this, "Attempting to turn on audio when the hearing aid service is null"); return false; } return mBluetoothHearingAidService.setActiveDevice( mHearingAidDevicesByAddress.get(address)); return mBluetoothAdapterProxy.setActiveDevice( mHearingAidDevicesByAddress.get(address), BluetoothAdapter.ACTIVE_DEVICE_ALL); } else if (mHfpDevicesByAddress.containsKey(address)) { BluetoothDevice device = mHfpDevicesByAddress.get(address); if (mBluetoothHeadsetService == null) { Log.w(this, "Attempting to turn on audio when the headset service is null"); return false; } boolean success = mBluetoothHeadsetService.setActiveDevice(device); boolean success = mBluetoothAdapterProxy.setActiveDevice(device, BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL); if (!success) { Log.w(this, "Couldn't set active device to %s", address); return false; Loading @@ -304,7 +310,9 @@ public class BluetoothDeviceManager { public void restoreHearingAidDevice() { if (mBluetoothHearingAidActiveDeviceCache != null && mBluetoothHearingAidService != null) { mBluetoothHearingAidService.setActiveDevice(mBluetoothHearingAidActiveDeviceCache); mBluetoothAdapterProxy.setActiveDevice( mBluetoothHearingAidActiveDeviceCache, BluetoothAdapter.ACTIVE_DEVICE_ALL); mBluetoothHearingAidActiveDeviceCache = null; } } Loading
tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +7 −8 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.telecom.tests; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothHearingAid; Loading Loading @@ -215,12 +216,10 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { public void testConnectDisconnectAudioHeadset() { receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1, false)); when(mHeadsetProxy.setActiveDevice(nullable(BluetoothDevice.class))).thenReturn(true); when(mAdapterProxy.setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL))).thenReturn(true); mBluetoothDeviceManager.connectAudio(device1.getAddress()); verify(mHeadsetProxy).setActiveDevice(device1); verify(mHeadsetProxy).connectAudio(); verify(mBluetoothHearingAid, never()).setActiveDevice(nullable(BluetoothDevice.class)); verify(mAdapterProxy).setActiveDevice(device1, BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL); verify(mAdapterProxy, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_ALL)); mBluetoothDeviceManager.disconnectAudio(); verify(mHeadsetProxy).disconnectAudio(); } Loading @@ -231,14 +230,14 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true)); mBluetoothDeviceManager.connectAudio(device2.getAddress()); verify(mBluetoothHearingAid).setActiveDevice(device2); verify(mAdapterProxy).setActiveDevice(device2, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mHeadsetProxy, never()).connectAudio(); verify(mHeadsetProxy, never()).setActiveDevice(nullable(BluetoothDevice.class)); verify(mAdapterProxy, never()).setActiveDevice(nullable(BluetoothDevice.class), eq(BluetoothAdapter.ACTIVE_DEVICE_PHONE_CALL)); when(mBluetoothHearingAid.getActiveDevices()).thenReturn(Arrays.asList(device2, null)); mBluetoothDeviceManager.disconnectAudio(); verify(mBluetoothHearingAid).setActiveDevice(null); verify(mAdapterProxy).setActiveDevice(null, BluetoothAdapter.ACTIVE_DEVICE_ALL); verify(mHeadsetProxy).disconnectAudio(); } Loading