Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +4 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.policy; import static com.android.systemui.Dependency.BG_LOOPER_NAME; import static com.android.systemui.Dependency.MAIN_LOOPER_NAME; import android.annotation.Nullable; import android.app.ActivityManager; Loading Loading @@ -67,16 +68,18 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa private boolean mEnabled; private int mConnectionState = BluetoothAdapter.STATE_DISCONNECTED; private final H mHandler = new H(Looper.getMainLooper()); private final H mHandler; private int mState; /** */ @Inject public BluetoothControllerImpl(Context context, @Named(BG_LOOPER_NAME) Looper bgLooper, @Named(MAIN_LOOPER_NAME) Looper mainLooper, @Nullable LocalBluetoothManager localBluetoothManager) { mLocalBluetoothManager = localBluetoothManager; mBgHandler = new Handler(bgLooper); mHandler = new H(mainLooper); if (mLocalBluetoothManager != null) { mLocalBluetoothManager.getEventManager().registerCallback(this); mLocalBluetoothManager.getProfileManager().addServiceListener(this); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java +8 −33 Original line number Diff line number Diff line Loading @@ -27,7 +27,6 @@ import static org.mockito.Mockito.when; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.os.Looper; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; Loading Loading @@ -77,6 +76,7 @@ public class BluetoothControllerImplTest extends SysuiTestCase { .thenReturn(mock(LocalBluetoothProfileManager.class)); mBluetoothControllerImpl = new BluetoothControllerImpl(mContext, mTestableLooper.getLooper(), mTestableLooper.getLooper(), mMockBluetoothManager); } Loading Loading @@ -109,18 +109,13 @@ public class BluetoothControllerImplTest extends SysuiTestCase { 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()); // Trigger the state getting. assertEquals(BluetoothDevice.BOND_NONE, mBluetoothControllerImpl.getBondState(device)); mTestableLooper.processMessages(1); mainLooper.processAllMessages(); mTestableLooper.processAllMessages(); assertEquals(BluetoothDevice.BOND_BONDED, mBluetoothControllerImpl.getBondState(device)); verify(callback).onBluetoothDevicesChanged(); mainLooper.destroy(); } @Test Loading @@ -130,20 +125,15 @@ public class BluetoothControllerImplTest extends SysuiTestCase { 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()); // Trigger the state getting. assertEquals(BluetoothProfile.STATE_DISCONNECTED, mBluetoothControllerImpl.getMaxConnectionState(device)); mTestableLooper.processMessages(1); mainLooper.processAllMessages(); mTestableLooper.processAllMessages(); assertEquals(BluetoothProfile.STATE_CONNECTED, mBluetoothControllerImpl.getMaxConnectionState(device)); verify(callback).onBluetoothDevicesChanged(); mainLooper.destroy(); } @Test Loading @@ -153,19 +143,11 @@ public class BluetoothControllerImplTest extends SysuiTestCase { 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(); } mTestableLooper.processAllMessages(); } @Test Loading Loading @@ -217,15 +199,8 @@ public class BluetoothControllerImplTest extends SysuiTestCase { mBluetoothControllerImpl.onAclConnectionStateChanged(device, BluetoothProfile.STATE_CONNECTED); // Grab the main looper, we'll need it later. TestableLooper mainLooper = new TestableLooper(Looper.getMainLooper()); try { mTestableLooper.processAllMessages(); mainLooper.processAllMessages(); } finally { mainLooper.destroy(); } assertTrue(mBluetoothControllerImpl.isBluetoothConnected()); verify(callback, atLeastOnce()).onBluetoothStateChange(anyBoolean()); } Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +4 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.systemui.statusbar.policy; import static com.android.systemui.Dependency.BG_LOOPER_NAME; import static com.android.systemui.Dependency.MAIN_LOOPER_NAME; import android.annotation.Nullable; import android.app.ActivityManager; Loading Loading @@ -67,16 +68,18 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa private boolean mEnabled; private int mConnectionState = BluetoothAdapter.STATE_DISCONNECTED; private final H mHandler = new H(Looper.getMainLooper()); private final H mHandler; private int mState; /** */ @Inject public BluetoothControllerImpl(Context context, @Named(BG_LOOPER_NAME) Looper bgLooper, @Named(MAIN_LOOPER_NAME) Looper mainLooper, @Nullable LocalBluetoothManager localBluetoothManager) { mLocalBluetoothManager = localBluetoothManager; mBgHandler = new Handler(bgLooper); mHandler = new H(mainLooper); if (mLocalBluetoothManager != null) { mLocalBluetoothManager.getEventManager().registerCallback(this); mLocalBluetoothManager.getProfileManager().addServiceListener(this); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java +8 −33 Original line number Diff line number Diff line Loading @@ -27,7 +27,6 @@ import static org.mockito.Mockito.when; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.os.Looper; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; Loading Loading @@ -77,6 +76,7 @@ public class BluetoothControllerImplTest extends SysuiTestCase { .thenReturn(mock(LocalBluetoothProfileManager.class)); mBluetoothControllerImpl = new BluetoothControllerImpl(mContext, mTestableLooper.getLooper(), mTestableLooper.getLooper(), mMockBluetoothManager); } Loading Loading @@ -109,18 +109,13 @@ public class BluetoothControllerImplTest extends SysuiTestCase { 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()); // Trigger the state getting. assertEquals(BluetoothDevice.BOND_NONE, mBluetoothControllerImpl.getBondState(device)); mTestableLooper.processMessages(1); mainLooper.processAllMessages(); mTestableLooper.processAllMessages(); assertEquals(BluetoothDevice.BOND_BONDED, mBluetoothControllerImpl.getBondState(device)); verify(callback).onBluetoothDevicesChanged(); mainLooper.destroy(); } @Test Loading @@ -130,20 +125,15 @@ public class BluetoothControllerImplTest extends SysuiTestCase { 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()); // Trigger the state getting. assertEquals(BluetoothProfile.STATE_DISCONNECTED, mBluetoothControllerImpl.getMaxConnectionState(device)); mTestableLooper.processMessages(1); mainLooper.processAllMessages(); mTestableLooper.processAllMessages(); assertEquals(BluetoothProfile.STATE_CONNECTED, mBluetoothControllerImpl.getMaxConnectionState(device)); verify(callback).onBluetoothDevicesChanged(); mainLooper.destroy(); } @Test Loading @@ -153,19 +143,11 @@ public class BluetoothControllerImplTest extends SysuiTestCase { 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(); } mTestableLooper.processAllMessages(); } @Test Loading Loading @@ -217,15 +199,8 @@ public class BluetoothControllerImplTest extends SysuiTestCase { mBluetoothControllerImpl.onAclConnectionStateChanged(device, BluetoothProfile.STATE_CONNECTED); // Grab the main looper, we'll need it later. TestableLooper mainLooper = new TestableLooper(Looper.getMainLooper()); try { mTestableLooper.processAllMessages(); mainLooper.processAllMessages(); } finally { mainLooper.destroy(); } assertTrue(mBluetoothControllerImpl.isBluetoothConnected()); verify(callback, atLeastOnce()).onBluetoothStateChange(anyBoolean()); } Loading