Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +20 −0 Original line number Diff line number Diff line Loading @@ -243,6 +243,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onBluetoothStateChanged(int bluetoothState) { if (DEBUG) Log.d(TAG, "BluetoothStateChanged=" + stateToString(bluetoothState)); mEnabled = bluetoothState == BluetoothAdapter.STATE_ON || bluetoothState == BluetoothAdapter.STATE_TURNING_ON; mState = bluetoothState; Loading @@ -252,6 +253,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onDeviceAdded(CachedBluetoothDevice cachedDevice) { if (DEBUG) Log.d(TAG, "DeviceAdded=" + cachedDevice.getAddress()); cachedDevice.registerCallback(this); updateConnected(); mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); Loading @@ -259,6 +261,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { if (DEBUG) Log.d(TAG, "DeviceDeleted=" + cachedDevice.getAddress()); mCachedState.remove(cachedDevice); updateConnected(); mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); Loading @@ -266,6 +269,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) { if (DEBUG) Log.d(TAG, "DeviceBondStateChanged=" + cachedDevice.getAddress()); mCachedState.remove(cachedDevice); updateConnected(); mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); Loading @@ -273,12 +277,28 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onDeviceAttributesChanged() { if (DEBUG) Log.d(TAG, "DeviceAttributesChanged"); updateConnected(); mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); } @Override public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { if (DEBUG) { Log.d(TAG, "ConnectionStateChanged=" + cachedDevice.getAddress() + " " + stateToString(state)); } mCachedState.remove(cachedDevice); updateConnected(); mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); } @Override public void onAclConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { if (DEBUG) { Log.d(TAG, "ACLConnectionStateChanged=" + cachedDevice.getAddress() + " " + stateToString(state)); } mCachedState.remove(cachedDevice); updateConnected(); mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,10 @@ package com.android.systemui.statusbar.policy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -198,4 +201,21 @@ public class BluetoothControllerImplTest extends SysuiTestCase { assertFalse(mBluetoothControllerImpl.isBluetoothConnecting()); assertFalse(mBluetoothControllerImpl.isBluetoothConnected()); } @Test public void testOnACLConnectionStateChange_updatesBluetoothStateOnConnection() { BluetoothController.Callback callback = mock(BluetoothController.Callback.class); mBluetoothControllerImpl.addCallback(callback); assertFalse(mBluetoothControllerImpl.isBluetoothConnected()); CachedBluetoothDevice device = mock(CachedBluetoothDevice.class); mDevices.add(device); when(device.isConnected()).thenReturn(true); when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED); reset(callback); mBluetoothControllerImpl.onAclConnectionStateChanged(device, BluetoothProfile.STATE_CONNECTED); assertTrue(mBluetoothControllerImpl.isBluetoothConnected()); verify(callback, atLeastOnce()).onBluetoothStateChange(anyBoolean()); } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java +20 −0 Original line number Diff line number Diff line Loading @@ -243,6 +243,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onBluetoothStateChanged(int bluetoothState) { if (DEBUG) Log.d(TAG, "BluetoothStateChanged=" + stateToString(bluetoothState)); mEnabled = bluetoothState == BluetoothAdapter.STATE_ON || bluetoothState == BluetoothAdapter.STATE_TURNING_ON; mState = bluetoothState; Loading @@ -252,6 +253,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onDeviceAdded(CachedBluetoothDevice cachedDevice) { if (DEBUG) Log.d(TAG, "DeviceAdded=" + cachedDevice.getAddress()); cachedDevice.registerCallback(this); updateConnected(); mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); Loading @@ -259,6 +261,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) { if (DEBUG) Log.d(TAG, "DeviceDeleted=" + cachedDevice.getAddress()); mCachedState.remove(cachedDevice); updateConnected(); mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); Loading @@ -266,6 +269,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) { if (DEBUG) Log.d(TAG, "DeviceBondStateChanged=" + cachedDevice.getAddress()); mCachedState.remove(cachedDevice); updateConnected(); mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); Loading @@ -273,12 +277,28 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa @Override public void onDeviceAttributesChanged() { if (DEBUG) Log.d(TAG, "DeviceAttributesChanged"); updateConnected(); mHandler.sendEmptyMessage(H.MSG_PAIRED_DEVICES_CHANGED); } @Override public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { if (DEBUG) { Log.d(TAG, "ConnectionStateChanged=" + cachedDevice.getAddress() + " " + stateToString(state)); } mCachedState.remove(cachedDevice); updateConnected(); mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); } @Override public void onAclConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { if (DEBUG) { Log.d(TAG, "ACLConnectionStateChanged=" + cachedDevice.getAddress() + " " + stateToString(state)); } mCachedState.remove(cachedDevice); updateConnected(); mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/BluetoothControllerImplTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,10 @@ package com.android.systemui.statusbar.policy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -198,4 +201,21 @@ public class BluetoothControllerImplTest extends SysuiTestCase { assertFalse(mBluetoothControllerImpl.isBluetoothConnecting()); assertFalse(mBluetoothControllerImpl.isBluetoothConnected()); } @Test public void testOnACLConnectionStateChange_updatesBluetoothStateOnConnection() { BluetoothController.Callback callback = mock(BluetoothController.Callback.class); mBluetoothControllerImpl.addCallback(callback); assertFalse(mBluetoothControllerImpl.isBluetoothConnected()); CachedBluetoothDevice device = mock(CachedBluetoothDevice.class); mDevices.add(device); when(device.isConnected()).thenReturn(true); when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED); reset(callback); mBluetoothControllerImpl.onAclConnectionStateChanged(device, BluetoothProfile.STATE_CONNECTED); assertTrue(mBluetoothControllerImpl.isBluetoothConnected()); verify(callback, atLeastOnce()).onBluetoothStateChange(anyBoolean()); } }