Merge "Inject main looper in BluetoothControllerImpl"
This commit is contained in:
committed by
Android (Google) Code Review
commit
1eb7851c9e
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
@@ -77,6 +76,7 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
|
||||
.thenReturn(mock(LocalBluetoothProfileManager.class));
|
||||
|
||||
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());
|
||||
// Trigger the state getting.
|
||||
assertEquals(BluetoothProfile.STATE_DISCONNECTED,
|
||||
mBluetoothControllerImpl.getMaxConnectionState(null));
|
||||
|
||||
try {
|
||||
// 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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user