Merge "Fix blocked number edit text direction and gravity"
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
index 4800832..3c334ca 100644
--- a/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
+++ b/src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java
@@ -73,12 +73,14 @@
                                         "Lost BluetoothHeadset service. " +
                                                 "Removing all tracked devices.");
                                 lostServiceDevices = mHfpDevicesByAddress;
+                                mBluetoothRouteManager.onActiveDeviceChanged(null, false);
                             } else if (profile == BluetoothProfile.HEARING_AID) {
                                 mBluetoothHearingAidService = null;
                                 Log.i(BluetoothDeviceManager.this,
                                         "Lost BluetoothHearingAid service. " +
                                                 "Removing all tracked devices.");
                                 lostServiceDevices = mHearingAidDevicesByAddress;
+                                mBluetoothRouteManager.onActiveDeviceChanged(null, true);
                             } else {
                                 return;
                             }
diff --git a/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java b/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
index 9fd97f8..2129ffa 100644
--- a/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
+++ b/tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java
@@ -40,6 +40,7 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.ArgumentMatchers.nullable;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.never;
@@ -161,6 +162,7 @@
                 buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true));
         serviceListenerUnderTest.onServiceDisconnected(BluetoothProfile.HEADSET);
 
+        verify(mRouteManager).onActiveDeviceChanged(isNull(), eq(false));
         verify(mRouteManager).onDeviceLost(device1.getAddress());
         verify(mRouteManager).onDeviceLost(device3.getAddress());
         verify(mRouteManager, never()).onDeviceLost(device2.getAddress());
@@ -170,6 +172,25 @@
 
     @SmallTest
     @Test
+    public void testHearingAidServiceDisconnect() {
+        receiverUnderTest.onReceive(mContext,
+                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1, false));
+        receiverUnderTest.onReceive(mContext,
+                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device3, false));
+        receiverUnderTest.onReceive(mContext,
+                buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device2, true));
+        serviceListenerUnderTest.onServiceDisconnected(BluetoothProfile.HEARING_AID);
+
+        verify(mRouteManager).onActiveDeviceChanged(isNull(), eq(true));
+        verify(mRouteManager).onDeviceLost(device2.getAddress());
+        verify(mRouteManager, never()).onDeviceLost(device1.getAddress());
+        verify(mRouteManager, never()).onDeviceLost(device3.getAddress());
+        assertNull(mBluetoothDeviceManager.getHearingAidService());
+        assertEquals(2, mBluetoothDeviceManager.getNumConnectedDevices());
+    }
+
+    @SmallTest
+    @Test
     public void testConnectDisconnectAudioHeadset() {
         receiverUnderTest.onReceive(mContext,
                 buildConnectionActionIntent(BluetoothHeadset.STATE_CONNECTED, device1, false));