Loading src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +13 −1 Original line number Diff line number Diff line Loading @@ -29,8 +29,13 @@ import com.android.server.telecom.BluetoothAdapterProxy; import com.android.server.telecom.BluetoothHeadsetProxy; import com.android.server.telecom.TelecomSystem; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; public class BluetoothDeviceManager { private final BluetoothProfile.ServiceListener mBluetoothProfileServiceListener = Loading Loading @@ -60,7 +65,14 @@ public class BluetoothDeviceManager { try { synchronized (mLock) { mBluetoothHeadsetService = null; Log.i(BluetoothDeviceManager.this, "Lost BluetoothHeadset service."); Log.i(BluetoothDeviceManager.this, "Lost BluetoothHeadset service. " + "Removing all tracked devices."); List<BluetoothDevice> devicesToRemove = new LinkedList<>( mConnectedDevicesByAddress.values()); mConnectedDevicesByAddress.clear(); for (BluetoothDevice device : devicesToRemove) { mBluetoothRouteManager.onDeviceLost(device); } } } finally { Log.endSession(); Loading tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,20 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { mBluetoothDeviceManager.getMostRecentlyConnectedDevice(device3.getAddress())); } @SmallTest public void testHeadsetServiceDisconnect() { receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1)); receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2)); serviceListenerUnderTest.onServiceDisconnected(0); verify(mRouteManager).onDeviceLost(device1); verify(mRouteManager).onDeviceLost(device2); assertNull(mBluetoothDeviceManager.getHeadsetService()); assertEquals(0, mBluetoothDeviceManager.getNumConnectedDevices()); } private Intent buildConnectionActionIntent(int state, BluetoothDevice device) { Intent i = new Intent(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); i.putExtra(BluetoothHeadset.EXTRA_STATE, state); Loading Loading
src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +13 −1 Original line number Diff line number Diff line Loading @@ -29,8 +29,13 @@ import com.android.server.telecom.BluetoothAdapterProxy; import com.android.server.telecom.BluetoothHeadsetProxy; import com.android.server.telecom.TelecomSystem; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; public class BluetoothDeviceManager { private final BluetoothProfile.ServiceListener mBluetoothProfileServiceListener = Loading Loading @@ -60,7 +65,14 @@ public class BluetoothDeviceManager { try { synchronized (mLock) { mBluetoothHeadsetService = null; Log.i(BluetoothDeviceManager.this, "Lost BluetoothHeadset service."); Log.i(BluetoothDeviceManager.this, "Lost BluetoothHeadset service. " + "Removing all tracked devices."); List<BluetoothDevice> devicesToRemove = new LinkedList<>( mConnectedDevicesByAddress.values()); mConnectedDevicesByAddress.clear(); for (BluetoothDevice device : devicesToRemove) { mBluetoothRouteManager.onDeviceLost(device); } } } finally { Log.endSession(); Loading
tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,20 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase { mBluetoothDeviceManager.getMostRecentlyConnectedDevice(device3.getAddress())); } @SmallTest public void testHeadsetServiceDisconnect() { receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1)); receiverUnderTest.onReceive(mContext, buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2)); serviceListenerUnderTest.onServiceDisconnected(0); verify(mRouteManager).onDeviceLost(device1); verify(mRouteManager).onDeviceLost(device2); assertNull(mBluetoothDeviceManager.getHeadsetService()); assertEquals(0, mBluetoothDeviceManager.getNumConnectedDevices()); } private Intent buildConnectionActionIntent(int state, BluetoothDevice device) { Intent i = new Intent(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); i.putExtra(BluetoothHeadset.EXTRA_STATE, state); Loading