Loading android/app/src/com/android/bluetooth/mapclient/MceStateMachine.java +4 −3 Original line number Diff line number Diff line Loading @@ -99,7 +99,8 @@ class MceStateMachine extends StateMachine { private static final String TAG = "MceSM"; private static final Boolean DBG = MapClientService.DBG; private static final int TIMEOUT = 10000; private static final int DISCONNECT_TIMEOUT = 3000; private static final int CONNECT_TIMEOUT = 10000; private static final int MAX_MESSAGES = 20; private static final int MSG_CONNECT = 1; private static final int MSG_DISCONNECT = 2; Loading Loading @@ -449,7 +450,7 @@ class MceStateMachine extends StateMachine { // When commanded to connect begin SDP to find the MAS server. mDevice.sdpSearch(BluetoothUuid.MAS); sendMessageDelayed(MSG_CONNECTING_TIMEOUT, TIMEOUT); sendMessageDelayed(MSG_CONNECTING_TIMEOUT, CONNECT_TIMEOUT); } @Override Loading Loading @@ -924,7 +925,7 @@ class MceStateMachine extends StateMachine { if (mMasClient != null) { mMasClient.makeRequest(new RequestSetNotificationRegistration(false)); mMasClient.shutdown(); sendMessageDelayed(MSG_DISCONNECTING_TIMEOUT, TIMEOUT); sendMessageDelayed(MSG_DISCONNECTING_TIMEOUT, DISCONNECT_TIMEOUT); } else { // MAP was never connected transitionTo(mDisconnected); Loading android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java +59 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ public class MapClientStateMachineTest { private static final String TAG = "MapStateMachineTest"; private static final int ASYNC_CALL_TIMEOUT_MILLIS = 100; private static final int DISCONNECT_TIMEOUT = 3000; @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); private BluetoothAdapter mAdapter; Loading Loading @@ -261,6 +262,64 @@ public class MapClientStateMachineTest { mMceStateMachine.setMessageStatus("123456789AB", BluetoothMapClient.READ)); } /** * Test disconnect */ @Test public void testDisconnect() { setupSdpRecordReceipt(); doAnswer(invocation -> { mMceStateMachine.sendMessage(MceStateMachine.MSG_MAS_DISCONNECTED); return null; }).when(mMockMasClient).shutdown(); Message msg = Message.obtain(mHandler, MceStateMachine.MSG_MAS_CONNECTED); mMceStateMachine.sendMessage(msg); // Wait until the message is processed and a broadcast request is sent to // to MapClientService to change // state from STATE_CONNECTING to STATE_CONNECTED verify(mMockMapClientService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_CONNECTED, mMceStateMachine.getState()); mMceStateMachine.disconnect(); verify(mMockMapClientService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(4)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTED, mMceStateMachine.getState()); } /** * Test disconnect timeout */ @Test public void testDisconnectTimeout() { setupSdpRecordReceipt(); Message msg = Message.obtain(mHandler, MceStateMachine.MSG_MAS_CONNECTED); mMceStateMachine.sendMessage(msg); // Wait until the message is processed and a broadcast request is sent to // to MapClientService to change // state from STATE_CONNECTING to STATE_CONNECTED verify(mMockMapClientService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_CONNECTED, mMceStateMachine.getState()); mMceStateMachine.disconnect(); verify(mMockMapClientService, after(DISCONNECT_TIMEOUT / 2).times(3)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTING, mMceStateMachine.getState()); verify(mMockMapClientService, timeout(DISCONNECT_TIMEOUT).times(4)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTED, mMceStateMachine.getState()); } private void setupSdpRecordReceipt() { // Perform first part of MAP connection logic. verify(mMockMapClientService, Loading Loading
android/app/src/com/android/bluetooth/mapclient/MceStateMachine.java +4 −3 Original line number Diff line number Diff line Loading @@ -99,7 +99,8 @@ class MceStateMachine extends StateMachine { private static final String TAG = "MceSM"; private static final Boolean DBG = MapClientService.DBG; private static final int TIMEOUT = 10000; private static final int DISCONNECT_TIMEOUT = 3000; private static final int CONNECT_TIMEOUT = 10000; private static final int MAX_MESSAGES = 20; private static final int MSG_CONNECT = 1; private static final int MSG_DISCONNECT = 2; Loading Loading @@ -449,7 +450,7 @@ class MceStateMachine extends StateMachine { // When commanded to connect begin SDP to find the MAS server. mDevice.sdpSearch(BluetoothUuid.MAS); sendMessageDelayed(MSG_CONNECTING_TIMEOUT, TIMEOUT); sendMessageDelayed(MSG_CONNECTING_TIMEOUT, CONNECT_TIMEOUT); } @Override Loading Loading @@ -924,7 +925,7 @@ class MceStateMachine extends StateMachine { if (mMasClient != null) { mMasClient.makeRequest(new RequestSetNotificationRegistration(false)); mMasClient.shutdown(); sendMessageDelayed(MSG_DISCONNECTING_TIMEOUT, TIMEOUT); sendMessageDelayed(MSG_DISCONNECTING_TIMEOUT, DISCONNECT_TIMEOUT); } else { // MAP was never connected transitionTo(mDisconnected); Loading
android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java +59 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ public class MapClientStateMachineTest { private static final String TAG = "MapStateMachineTest"; private static final int ASYNC_CALL_TIMEOUT_MILLIS = 100; private static final int DISCONNECT_TIMEOUT = 3000; @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); private BluetoothAdapter mAdapter; Loading Loading @@ -261,6 +262,64 @@ public class MapClientStateMachineTest { mMceStateMachine.setMessageStatus("123456789AB", BluetoothMapClient.READ)); } /** * Test disconnect */ @Test public void testDisconnect() { setupSdpRecordReceipt(); doAnswer(invocation -> { mMceStateMachine.sendMessage(MceStateMachine.MSG_MAS_DISCONNECTED); return null; }).when(mMockMasClient).shutdown(); Message msg = Message.obtain(mHandler, MceStateMachine.MSG_MAS_CONNECTED); mMceStateMachine.sendMessage(msg); // Wait until the message is processed and a broadcast request is sent to // to MapClientService to change // state from STATE_CONNECTING to STATE_CONNECTED verify(mMockMapClientService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_CONNECTED, mMceStateMachine.getState()); mMceStateMachine.disconnect(); verify(mMockMapClientService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(4)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTED, mMceStateMachine.getState()); } /** * Test disconnect timeout */ @Test public void testDisconnectTimeout() { setupSdpRecordReceipt(); Message msg = Message.obtain(mHandler, MceStateMachine.MSG_MAS_CONNECTED); mMceStateMachine.sendMessage(msg); // Wait until the message is processed and a broadcast request is sent to // to MapClientService to change // state from STATE_CONNECTING to STATE_CONNECTED verify(mMockMapClientService, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_CONNECTED, mMceStateMachine.getState()); mMceStateMachine.disconnect(); verify(mMockMapClientService, after(DISCONNECT_TIMEOUT / 2).times(3)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTING, mMceStateMachine.getState()); verify(mMockMapClientService, timeout(DISCONNECT_TIMEOUT).times(4)).sendBroadcast( mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM)); Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTED, mMceStateMachine.getState()); } private void setupSdpRecordReceipt() { // Perform first part of MAP connection logic. verify(mMockMapClientService, Loading