Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +7 −4 Original line number Diff line number Diff line Loading @@ -296,12 +296,15 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void run() { mBondState = mDevice.get().getBondState(); mMaxConnectionState = mDevice.get().getMaxConnectionState(); CachedBluetoothDevice device = mDevice.get(); if (device != null) { mBondState = device.getBondState(); mMaxConnectionState = device.getMaxConnectionState(); mUiHandler.removeMessages(H.MSG_PAIRED_DEVICES_CHANGED); mUiHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); } } } private final class H extends Handler { private final ArrayList<BluetoothController.Callback> mCallbacks = new ArrayList<>(); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -137,4 +137,26 @@ public class BluetoothControllerImplTest extends SysuiTestCase { verify(callback).onBluetoothDevicesChanged(); mainLooper.destroy(); } @Test public void testNullAsync_DoesNotCrash() throws Exception { CachedBluetoothDevice device = mock(CachedBluetoothDevice.class); when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED); BluetoothController.Callback callback = mock(BluetoothController.Callback.class); mBluetoothControllerImpl.addCallback(callback); // Grab the main looper, we'll need it later. TestableLooper mainLooper = new TestableLooper(Looper.getMainLooper()); try { // Trigger the state getting. assertEquals(BluetoothProfile.STATE_DISCONNECTED, mBluetoothControllerImpl.getMaxConnectionState(null)); mTestableLooper.processMessages(1); mainLooper.processAllMessages(); } finally { mainLooper.destroy(); } } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +7 −4 Original line number Diff line number Diff line Loading @@ -296,12 +296,15 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void run() { mBondState = mDevice.get().getBondState(); mMaxConnectionState = mDevice.get().getMaxConnectionState(); CachedBluetoothDevice device = mDevice.get(); if (device != null) { mBondState = device.getBondState(); mMaxConnectionState = device.getMaxConnectionState(); mUiHandler.removeMessages(H.MSG_PAIRED_DEVICES_CHANGED); mUiHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); } } } private final class H extends Handler { private final ArrayList<BluetoothController.Callback> mCallbacks = new ArrayList<>(); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -137,4 +137,26 @@ public class BluetoothControllerImplTest extends SysuiTestCase { verify(callback).onBluetoothDevicesChanged(); mainLooper.destroy(); } @Test public void testNullAsync_DoesNotCrash() throws Exception { CachedBluetoothDevice device = mock(CachedBluetoothDevice.class); when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED); BluetoothController.Callback callback = mock(BluetoothController.Callback.class); mBluetoothControllerImpl.addCallback(callback); // Grab the main looper, we'll need it later. TestableLooper mainLooper = new TestableLooper(Looper.getMainLooper()); try { // Trigger the state getting. assertEquals(BluetoothProfile.STATE_DISCONNECTED, mBluetoothControllerImpl.getMaxConnectionState(null)); mTestableLooper.processMessages(1); mainLooper.processAllMessages(); } finally { mainLooper.destroy(); } } }