Loading android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -406,6 +406,20 @@ class ActiveDeviceManager { resetState(); } /** * Get the {@link Looper} for the handler thread. This is used in testing and helper * objects * * @return {@link Looper} for the handler thread */ @VisibleForTesting public Looper getHandlerLooper() { if (mHandlerThread == null) { return null; } return mHandlerThread.getLooper(); } private void setA2dpActiveDevice(BluetoothDevice device) { if (DBG) { Log.d(TAG, "setA2dpActiveDevice(" + device + ")"); Loading android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java +13 −8 Original line number Diff line number Diff line Loading @@ -154,7 +154,8 @@ public class ActiveDeviceManagerTest { a2dpActiveDeviceChanged(mA2dpDevice); // Don't call mA2dpService.setActiveDevice() verify(mA2dpService, after(TIMEOUT_MS).times(1)).setActiveDevice(mA2dpDevice); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mA2dpService, times(1)).setActiveDevice(mA2dpDevice); Assert.assertEquals(mA2dpDevice, mActiveDeviceManager.getA2dpActiveDevice()); } Loading Loading @@ -204,7 +205,8 @@ public class ActiveDeviceManagerTest { headsetActiveDeviceChanged(mHeadsetDevice); // Don't call mHeadsetService.setActiveDevice() verify(mHeadsetService, after(TIMEOUT_MS).times(1)).setActiveDevice(mHeadsetDevice); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mHeadsetService, times(1)).setActiveDevice(mHeadsetDevice); Assert.assertEquals(mHeadsetDevice, mActiveDeviceManager.getHfpActiveDevice()); } Loading Loading @@ -238,8 +240,9 @@ public class ActiveDeviceManagerTest { a2dpConnected(mA2dpHeadsetDevice); headsetConnected(mA2dpHeadsetDevice); verify(mA2dpService, timeout(TIMEOUT_MS).times(0)).setActiveDevice(mA2dpHeadsetDevice); verify(mHeadsetService, timeout(TIMEOUT_MS).times(0)).setActiveDevice(mA2dpHeadsetDevice); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mA2dpService, never()).setActiveDevice(mA2dpHeadsetDevice); verify(mHeadsetService, never()).setActiveDevice(mA2dpHeadsetDevice); } /** Loading @@ -254,9 +257,10 @@ public class ActiveDeviceManagerTest { a2dpConnected(mA2dpHeadsetDevice); a2dpActiveDeviceChanged(mA2dpHeadsetDevice); verify(mHearingAidService, timeout(TIMEOUT_MS)).setActiveDevice(isNull()); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mHearingAidService).setActiveDevice(isNull()); // Don't call mA2dpService.setActiveDevice() verify(mA2dpService, timeout(TIMEOUT_MS).times(0)).setActiveDevice(mA2dpHeadsetDevice); verify(mA2dpService, never()).setActiveDevice(mA2dpHeadsetDevice); Assert.assertEquals(mA2dpHeadsetDevice, mActiveDeviceManager.getA2dpActiveDevice()); Assert.assertEquals(null, mActiveDeviceManager.getHearingAidActiveDevice()); } Loading @@ -273,9 +277,10 @@ public class ActiveDeviceManagerTest { headsetConnected(mA2dpHeadsetDevice); headsetActiveDeviceChanged(mA2dpHeadsetDevice); verify(mHearingAidService, timeout(TIMEOUT_MS)).setActiveDevice(isNull()); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mHearingAidService).setActiveDevice(isNull()); // Don't call mHeadsetService.setActiveDevice() verify(mHeadsetService, timeout(TIMEOUT_MS).times(0)).setActiveDevice(mA2dpHeadsetDevice); verify(mHeadsetService, never()).setActiveDevice(mA2dpHeadsetDevice); Assert.assertEquals(mA2dpHeadsetDevice, mActiveDeviceManager.getHfpActiveDevice()); Assert.assertEquals(null, mActiveDeviceManager.getHearingAidActiveDevice()); } Loading android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java +5 −2 Original line number Diff line number Diff line Loading @@ -66,6 +66,9 @@ public class PhonePolicyTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); // Stub A2DP and HFP when(mHeadsetService.connect(any(BluetoothDevice.class))).thenReturn(true); when(mA2dpService.connect(any(BluetoothDevice.class))).thenReturn(true); // Prepare the TestUtils TestUtils.setAdapterService(mAdapterService); // Configure the maximum connected audio devices Loading Loading @@ -213,8 +216,8 @@ public class PhonePolicyTest { mPhonePolicy.getBroadcastReceiver().onReceive(null /* context */, intent); // This device should be set to auto connect while the first device is reset to ON verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setPriority(bondedDevices[0], BluetoothProfile.PRIORITY_ON); verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).setPriority( bondedDevices[0], BluetoothProfile.PRIORITY_ON); verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setPriority(bondedDevices[1], BluetoothProfile.PRIORITY_AUTO_CONNECT); verify(mHeadsetService, never()).setPriority(eq(bondedDevices[3]), anyInt()); Loading Loading
android/app/src/com/android/bluetooth/btservice/ActiveDeviceManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -406,6 +406,20 @@ class ActiveDeviceManager { resetState(); } /** * Get the {@link Looper} for the handler thread. This is used in testing and helper * objects * * @return {@link Looper} for the handler thread */ @VisibleForTesting public Looper getHandlerLooper() { if (mHandlerThread == null) { return null; } return mHandlerThread.getLooper(); } private void setA2dpActiveDevice(BluetoothDevice device) { if (DBG) { Log.d(TAG, "setA2dpActiveDevice(" + device + ")"); Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/ActiveDeviceManagerTest.java +13 −8 Original line number Diff line number Diff line Loading @@ -154,7 +154,8 @@ public class ActiveDeviceManagerTest { a2dpActiveDeviceChanged(mA2dpDevice); // Don't call mA2dpService.setActiveDevice() verify(mA2dpService, after(TIMEOUT_MS).times(1)).setActiveDevice(mA2dpDevice); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mA2dpService, times(1)).setActiveDevice(mA2dpDevice); Assert.assertEquals(mA2dpDevice, mActiveDeviceManager.getA2dpActiveDevice()); } Loading Loading @@ -204,7 +205,8 @@ public class ActiveDeviceManagerTest { headsetActiveDeviceChanged(mHeadsetDevice); // Don't call mHeadsetService.setActiveDevice() verify(mHeadsetService, after(TIMEOUT_MS).times(1)).setActiveDevice(mHeadsetDevice); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mHeadsetService, times(1)).setActiveDevice(mHeadsetDevice); Assert.assertEquals(mHeadsetDevice, mActiveDeviceManager.getHfpActiveDevice()); } Loading Loading @@ -238,8 +240,9 @@ public class ActiveDeviceManagerTest { a2dpConnected(mA2dpHeadsetDevice); headsetConnected(mA2dpHeadsetDevice); verify(mA2dpService, timeout(TIMEOUT_MS).times(0)).setActiveDevice(mA2dpHeadsetDevice); verify(mHeadsetService, timeout(TIMEOUT_MS).times(0)).setActiveDevice(mA2dpHeadsetDevice); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mA2dpService, never()).setActiveDevice(mA2dpHeadsetDevice); verify(mHeadsetService, never()).setActiveDevice(mA2dpHeadsetDevice); } /** Loading @@ -254,9 +257,10 @@ public class ActiveDeviceManagerTest { a2dpConnected(mA2dpHeadsetDevice); a2dpActiveDeviceChanged(mA2dpHeadsetDevice); verify(mHearingAidService, timeout(TIMEOUT_MS)).setActiveDevice(isNull()); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mHearingAidService).setActiveDevice(isNull()); // Don't call mA2dpService.setActiveDevice() verify(mA2dpService, timeout(TIMEOUT_MS).times(0)).setActiveDevice(mA2dpHeadsetDevice); verify(mA2dpService, never()).setActiveDevice(mA2dpHeadsetDevice); Assert.assertEquals(mA2dpHeadsetDevice, mActiveDeviceManager.getA2dpActiveDevice()); Assert.assertEquals(null, mActiveDeviceManager.getHearingAidActiveDevice()); } Loading @@ -273,9 +277,10 @@ public class ActiveDeviceManagerTest { headsetConnected(mA2dpHeadsetDevice); headsetActiveDeviceChanged(mA2dpHeadsetDevice); verify(mHearingAidService, timeout(TIMEOUT_MS)).setActiveDevice(isNull()); TestUtils.waitForLooperToFinishScheduledTask(mActiveDeviceManager.getHandlerLooper()); verify(mHearingAidService).setActiveDevice(isNull()); // Don't call mHeadsetService.setActiveDevice() verify(mHeadsetService, timeout(TIMEOUT_MS).times(0)).setActiveDevice(mA2dpHeadsetDevice); verify(mHeadsetService, never()).setActiveDevice(mA2dpHeadsetDevice); Assert.assertEquals(mA2dpHeadsetDevice, mActiveDeviceManager.getHfpActiveDevice()); Assert.assertEquals(null, mActiveDeviceManager.getHearingAidActiveDevice()); } Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/PhonePolicyTest.java +5 −2 Original line number Diff line number Diff line Loading @@ -66,6 +66,9 @@ public class PhonePolicyTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); // Stub A2DP and HFP when(mHeadsetService.connect(any(BluetoothDevice.class))).thenReturn(true); when(mA2dpService.connect(any(BluetoothDevice.class))).thenReturn(true); // Prepare the TestUtils TestUtils.setAdapterService(mAdapterService); // Configure the maximum connected audio devices Loading Loading @@ -213,8 +216,8 @@ public class PhonePolicyTest { mPhonePolicy.getBroadcastReceiver().onReceive(null /* context */, intent); // This device should be set to auto connect while the first device is reset to ON verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setPriority(bondedDevices[0], BluetoothProfile.PRIORITY_ON); verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).setPriority( bondedDevices[0], BluetoothProfile.PRIORITY_ON); verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).setPriority(bondedDevices[1], BluetoothProfile.PRIORITY_AUTO_CONNECT); verify(mHeadsetService, never()).setPriority(eq(bondedDevices[3]), anyInt()); Loading