Loading android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java +13 −5 Original line number Diff line number Diff line Loading @@ -457,6 +457,14 @@ public class BassClientStateMachine extends StateMachine { mNoStopScanOffload = false; } private void resetBluetoothGatt() { // cleanup mBluetoothGatt if (mBluetoothGatt != null) { mBluetoothGatt.close(); mBluetoothGatt = null; } } private BluetoothLeBroadcastMetadata getBroadcastMetadataFromBaseData(BaseData baseData, BluetoothDevice device) { return getBroadcastMetadataFromBaseData(baseData, device, false); Loading Loading @@ -1261,6 +1269,7 @@ public class BassClientStateMachine extends StateMachine { transitionTo(mConnected); } else { Log.w(TAG, "Connection failed to " + mDevice); resetBluetoothGatt(); transitionTo(mDisconnected); } break; Loading @@ -1271,6 +1280,7 @@ public class BassClientStateMachine extends StateMachine { Log.e(TAG, "Unknown device timeout " + device); break; } resetBluetoothGatt(); transitionTo(mDisconnected); break; case PSYNC_ACTIVE_TIMEOUT: Loading Loading @@ -1527,11 +1537,7 @@ public class BassClientStateMachine extends StateMachine { Log.w(TAG, "device is already connected to Bass" + mDevice); } else { Log.w(TAG, "unexpected disconnected from " + mDevice); // cleanup mBluetoothGatt if (mBluetoothGatt != null) { mBluetoothGatt.close(); mBluetoothGatt = null; } resetBluetoothGatt(); cancelActiveSync(null); transitionTo(mDisconnected); } Loading Loading @@ -1812,6 +1818,8 @@ public class BassClientStateMachine extends StateMachine { Log.w(TAG, "should never happen from this state"); } else { Log.w(TAG, "Unexpected disconnection " + mDevice); resetBluetoothGatt(); cancelActiveSync(null); transitionTo(mDisconnected); } break; Loading android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientStateMachineTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -919,7 +919,12 @@ public class BassClientStateMachineTest { Message msg = mBassClientStateMachine.obtainMessage(CONNECTION_STATE_CHANGED); msg.obj = BluetoothProfile.STATE_CONNECTING; BassClientStateMachine.BluetoothGattTestableWrapper btGatt = Mockito.mock(BassClientStateMachine.BluetoothGattTestableWrapper.class); mBassClientStateMachine.mBluetoothGatt = btGatt; sendMessageAndVerifyTransition(msg, BassClientStateMachine.Disconnected.class); verify(btGatt).close(); assertNull(mBassClientStateMachine.mBluetoothGatt); } @Test Loading @@ -941,8 +946,13 @@ public class BassClientStateMachineTest { TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper()); verify(mBassClientService, never()).sendBroadcast(any(Intent.class), anyString(), any()); BassClientStateMachine.BluetoothGattTestableWrapper btGatt = Mockito.mock(BassClientStateMachine.BluetoothGattTestableWrapper.class); mBassClientStateMachine.mBluetoothGatt = btGatt; Message msg = mBassClientStateMachine.obtainMessage(CONNECT_TIMEOUT, mTestDevice); sendMessageAndVerifyTransition(msg, BassClientStateMachine.Disconnected.class); verify(btGatt).close(); assertNull(mBassClientStateMachine.mBluetoothGatt); } @Test Loading Loading @@ -991,9 +1001,14 @@ public class BassClientStateMachineTest { TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper()); verify(mBassClientService, never()).sendBroadcast(any(Intent.class), anyString(), any()); BassClientStateMachine.BluetoothGattTestableWrapper btGatt = Mockito.mock(BassClientStateMachine.BluetoothGattTestableWrapper.class); mBassClientStateMachine.mBluetoothGatt = btGatt; Message noneConnectedMsg = mBassClientStateMachine.obtainMessage(CONNECTION_STATE_CHANGED); noneConnectedMsg.obj = BluetoothProfile.STATE_DISCONNECTING; sendMessageAndVerifyTransition(noneConnectedMsg, BassClientStateMachine.Disconnected.class); verify(btGatt).close(); assertNull(mBassClientStateMachine.mBluetoothGatt); } @Test Loading Loading @@ -1379,11 +1394,16 @@ public class BassClientStateMachineTest { TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper()); verify(mBassClientService, never()).sendBroadcast(any(Intent.class), anyString(), any()); BassClientStateMachine.BluetoothGattTestableWrapper btGatt = Mockito.mock(BassClientStateMachine.BluetoothGattTestableWrapper.class); mBassClientStateMachine.mBluetoothGatt = btGatt; Message msgToNoneConnectedState = mBassClientStateMachine.obtainMessage(CONNECTION_STATE_CHANGED); msgToNoneConnectedState.obj = BluetoothProfile.STATE_DISCONNECTING; sendMessageAndVerifyTransition( msgToNoneConnectedState, BassClientStateMachine.Disconnected.class); verify(btGatt).close(); assertNull(mBassClientStateMachine.mBluetoothGatt); } /** Loading Loading
android/app/src/com/android/bluetooth/bass_client/BassClientStateMachine.java +13 −5 Original line number Diff line number Diff line Loading @@ -457,6 +457,14 @@ public class BassClientStateMachine extends StateMachine { mNoStopScanOffload = false; } private void resetBluetoothGatt() { // cleanup mBluetoothGatt if (mBluetoothGatt != null) { mBluetoothGatt.close(); mBluetoothGatt = null; } } private BluetoothLeBroadcastMetadata getBroadcastMetadataFromBaseData(BaseData baseData, BluetoothDevice device) { return getBroadcastMetadataFromBaseData(baseData, device, false); Loading Loading @@ -1261,6 +1269,7 @@ public class BassClientStateMachine extends StateMachine { transitionTo(mConnected); } else { Log.w(TAG, "Connection failed to " + mDevice); resetBluetoothGatt(); transitionTo(mDisconnected); } break; Loading @@ -1271,6 +1280,7 @@ public class BassClientStateMachine extends StateMachine { Log.e(TAG, "Unknown device timeout " + device); break; } resetBluetoothGatt(); transitionTo(mDisconnected); break; case PSYNC_ACTIVE_TIMEOUT: Loading Loading @@ -1527,11 +1537,7 @@ public class BassClientStateMachine extends StateMachine { Log.w(TAG, "device is already connected to Bass" + mDevice); } else { Log.w(TAG, "unexpected disconnected from " + mDevice); // cleanup mBluetoothGatt if (mBluetoothGatt != null) { mBluetoothGatt.close(); mBluetoothGatt = null; } resetBluetoothGatt(); cancelActiveSync(null); transitionTo(mDisconnected); } Loading Loading @@ -1812,6 +1818,8 @@ public class BassClientStateMachine extends StateMachine { Log.w(TAG, "should never happen from this state"); } else { Log.w(TAG, "Unexpected disconnection " + mDevice); resetBluetoothGatt(); cancelActiveSync(null); transitionTo(mDisconnected); } break; Loading
android/app/tests/unit/src/com/android/bluetooth/bass_client/BassClientStateMachineTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -919,7 +919,12 @@ public class BassClientStateMachineTest { Message msg = mBassClientStateMachine.obtainMessage(CONNECTION_STATE_CHANGED); msg.obj = BluetoothProfile.STATE_CONNECTING; BassClientStateMachine.BluetoothGattTestableWrapper btGatt = Mockito.mock(BassClientStateMachine.BluetoothGattTestableWrapper.class); mBassClientStateMachine.mBluetoothGatt = btGatt; sendMessageAndVerifyTransition(msg, BassClientStateMachine.Disconnected.class); verify(btGatt).close(); assertNull(mBassClientStateMachine.mBluetoothGatt); } @Test Loading @@ -941,8 +946,13 @@ public class BassClientStateMachineTest { TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper()); verify(mBassClientService, never()).sendBroadcast(any(Intent.class), anyString(), any()); BassClientStateMachine.BluetoothGattTestableWrapper btGatt = Mockito.mock(BassClientStateMachine.BluetoothGattTestableWrapper.class); mBassClientStateMachine.mBluetoothGatt = btGatt; Message msg = mBassClientStateMachine.obtainMessage(CONNECT_TIMEOUT, mTestDevice); sendMessageAndVerifyTransition(msg, BassClientStateMachine.Disconnected.class); verify(btGatt).close(); assertNull(mBassClientStateMachine.mBluetoothGatt); } @Test Loading Loading @@ -991,9 +1001,14 @@ public class BassClientStateMachineTest { TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper()); verify(mBassClientService, never()).sendBroadcast(any(Intent.class), anyString(), any()); BassClientStateMachine.BluetoothGattTestableWrapper btGatt = Mockito.mock(BassClientStateMachine.BluetoothGattTestableWrapper.class); mBassClientStateMachine.mBluetoothGatt = btGatt; Message noneConnectedMsg = mBassClientStateMachine.obtainMessage(CONNECTION_STATE_CHANGED); noneConnectedMsg.obj = BluetoothProfile.STATE_DISCONNECTING; sendMessageAndVerifyTransition(noneConnectedMsg, BassClientStateMachine.Disconnected.class); verify(btGatt).close(); assertNull(mBassClientStateMachine.mBluetoothGatt); } @Test Loading Loading @@ -1379,11 +1394,16 @@ public class BassClientStateMachineTest { TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper()); verify(mBassClientService, never()).sendBroadcast(any(Intent.class), anyString(), any()); BassClientStateMachine.BluetoothGattTestableWrapper btGatt = Mockito.mock(BassClientStateMachine.BluetoothGattTestableWrapper.class); mBassClientStateMachine.mBluetoothGatt = btGatt; Message msgToNoneConnectedState = mBassClientStateMachine.obtainMessage(CONNECTION_STATE_CHANGED); msgToNoneConnectedState.obj = BluetoothProfile.STATE_DISCONNECTING; sendMessageAndVerifyTransition( msgToNoneConnectedState, BassClientStateMachine.Disconnected.class); verify(btGatt).close(); assertNull(mBassClientStateMachine.mBluetoothGatt); } /** Loading