Loading android/app/src/com/android/bluetooth/bas/BatteryStateMachine.java +16 −7 Original line number Diff line number Diff line Loading @@ -223,14 +223,16 @@ public class BatteryStateMachine extends StateMachine { return false; } if (mBluetoothGatt == null) { if (mGattCallback == null) { mGattCallback = new GattCallback(); } if (mBluetoothGatt != null) { Log.w(TAG, "Trying connectGatt with existing BluetoothGatt instance."); mBluetoothGatt.close(); } mBluetoothGatt = mDevice.connectGatt(service, /*autoConnect=*/false, mGattCallback, TRANSPORT_AUTO, /*opportunistic=*/true, PHY_LE_1M_MASK | PHY_LE_2M_MASK, getHandler()); } else { mBluetoothGatt.connect(); } return mBluetoothGatt != null; } Loading @@ -256,6 +258,11 @@ public class BatteryStateMachine extends StateMachine { log(TAG, "Enter (" + mDevice + "): " + messageWhatToString( getCurrentMessage().what)); if (mBluetoothGatt != null) { mBluetoothGatt.close(); mBluetoothGatt = null; } if (mLastConnectionState != BluetoothProfile.STATE_DISCONNECTED) { // Don't broadcast during startup dispatchConnectionStateChanged(mLastConnectionState, Loading Loading @@ -575,7 +582,9 @@ public class BatteryStateMachine extends StateMachine { int batteryLevel = value[0] & 0xFF; BatteryService service = mServiceRef.get(); if (service != null) { service.handleBatteryChanged(mDevice, batteryLevel); } } } } android/app/tests/unit/src/com/android/bluetooth/bas/BatteryStateMachineTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.bluetooth.bas; import static android.bluetooth.BluetoothGatt.GATT_SUCCESS; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.after; Loading Loading @@ -157,6 +158,7 @@ public class BatteryStateMachineTest { // Check that we are in Disconnected state Assert.assertThat(mBatteryStateMachine.getCurrentState(), IsInstanceOf.instanceOf(BatteryStateMachine.Disconnected.class)); assertNull(mBatteryStateMachine.mBluetoothGatt); } @Test Loading Loading
android/app/src/com/android/bluetooth/bas/BatteryStateMachine.java +16 −7 Original line number Diff line number Diff line Loading @@ -223,14 +223,16 @@ public class BatteryStateMachine extends StateMachine { return false; } if (mBluetoothGatt == null) { if (mGattCallback == null) { mGattCallback = new GattCallback(); } if (mBluetoothGatt != null) { Log.w(TAG, "Trying connectGatt with existing BluetoothGatt instance."); mBluetoothGatt.close(); } mBluetoothGatt = mDevice.connectGatt(service, /*autoConnect=*/false, mGattCallback, TRANSPORT_AUTO, /*opportunistic=*/true, PHY_LE_1M_MASK | PHY_LE_2M_MASK, getHandler()); } else { mBluetoothGatt.connect(); } return mBluetoothGatt != null; } Loading @@ -256,6 +258,11 @@ public class BatteryStateMachine extends StateMachine { log(TAG, "Enter (" + mDevice + "): " + messageWhatToString( getCurrentMessage().what)); if (mBluetoothGatt != null) { mBluetoothGatt.close(); mBluetoothGatt = null; } if (mLastConnectionState != BluetoothProfile.STATE_DISCONNECTED) { // Don't broadcast during startup dispatchConnectionStateChanged(mLastConnectionState, Loading Loading @@ -575,7 +582,9 @@ public class BatteryStateMachine extends StateMachine { int batteryLevel = value[0] & 0xFF; BatteryService service = mServiceRef.get(); if (service != null) { service.handleBatteryChanged(mDevice, batteryLevel); } } } }
android/app/tests/unit/src/com/android/bluetooth/bas/BatteryStateMachineTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.bluetooth.bas; import static android.bluetooth.BluetoothGatt.GATT_SUCCESS; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.after; Loading Loading @@ -157,6 +158,7 @@ public class BatteryStateMachineTest { // Check that we are in Disconnected state Assert.assertThat(mBatteryStateMachine.getCurrentState(), IsInstanceOf.instanceOf(BatteryStateMachine.Disconnected.class)); assertNull(mBatteryStateMachine.mBluetoothGatt); } @Test Loading