diff options
author | Fabian Kozynski <kozynski@google.com> | 2019-09-19 17:32:59 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-09-19 17:32:59 +0000 |
commit | 1eb7851c9e1933e1ebea7eecd4d4f6ebe0b2320a (patch) | |
tree | 4106ece4757c658d21c790c4e16af4f830dfc05b | |
parent | e6319649a873d80f1c49cb1de59a4138a416d231 (diff) | |
parent | fee2e21f55aa7b5aaf2ebb2eed3303e78cca0d7e (diff) |
Merge "Inject main looper in BluetoothControllerImpl"
2 files changed, 12 insertions, 34 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java index 40c3d9d19c16..0a2fb2e783a9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java @@ -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; @@ -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); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java index 766ad978f475..e629a4f03586 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java @@ -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; @@ -78,6 +77,7 @@ public class BluetoothControllerImplTest extends SysuiTestCase { mBluetoothControllerImpl = new BluetoothControllerImpl(mContext, mTestableLooper.getLooper(), + mTestableLooper.getLooper(), mMockBluetoothManager); } @@ -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 @@ -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 @@ -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)); + // Trigger the state getting. + assertEquals(BluetoothProfile.STATE_DISCONNECTED, + mBluetoothControllerImpl.getMaxConnectionState(null)); - mTestableLooper.processMessages(1); - mainLooper.processAllMessages(); - } finally { - mainLooper.destroy(); - } + mTestableLooper.processAllMessages(); } @Test @@ -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()); + mTestableLooper.processAllMessages(); - try { - mTestableLooper.processAllMessages(); - mainLooper.processAllMessages(); - } finally { - mainLooper.destroy(); - } assertTrue(mBluetoothControllerImpl.isBluetoothConnected()); verify(callback, atLeastOnce()).onBluetoothStateChange(anyBoolean()); } |