Loading src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +21 −9 Original line number Diff line number Diff line Loading @@ -1311,15 +1311,10 @@ public class HeadsetClientStateMachine extends StateMachine { mService.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM); break; case StackEvent.EVENT_TYPE_VR_STATE_CHANGED: if (mVoiceRecognitionActive != event.valueInt) { int oldState = mVoiceRecognitionActive; mVoiceRecognitionActive = event.valueInt; intent = new Intent(BluetoothHeadsetClient.ACTION_AG_EVENT); intent.putExtra(BluetoothHeadsetClient.EXTRA_VOICE_RECOGNITION, broadcastVoiceRecognitionStateChanged(event.device, oldState, mVoiceRecognitionActive); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, event.device); mService.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM); } break; case StackEvent.EVENT_TYPE_CALL: case StackEvent.EVENT_TYPE_CALLSETUP: Loading Loading @@ -1365,14 +1360,20 @@ public class HeadsetClientStateMachine extends StateMachine { break; case VOICE_RECOGNITION_START: if (event.valueInt == AT_OK) { oldState = mVoiceRecognitionActive; mVoiceRecognitionActive = HeadsetClientHalConstants.VR_STATE_STARTED; broadcastVoiceRecognitionStateChanged(event.device, oldState, mVoiceRecognitionActive); } break; case VOICE_RECOGNITION_STOP: if (event.valueInt == AT_OK) { oldState = mVoiceRecognitionActive; mVoiceRecognitionActive = HeadsetClientHalConstants.VR_STATE_STOPPED; broadcastVoiceRecognitionStateChanged(event.device, oldState, mVoiceRecognitionActive); } break; default: Loading Loading @@ -1421,6 +1422,17 @@ public class HeadsetClientStateMachine extends StateMachine { return HANDLED; } private void broadcastVoiceRecognitionStateChanged(BluetoothDevice device, int oldState, int newState) { if (oldState == newState) { return; } Intent intent = new Intent(BluetoothHeadsetClient.ACTION_AG_EVENT); intent.putExtra(BluetoothHeadsetClient.EXTRA_VOICE_RECOGNITION, newState); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); mService.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM); } // in Connected state private void processConnectionEvent(int state, BluetoothDevice device) { switch (state) { Loading tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java +56 −0 Original line number Diff line number Diff line package com.android.bluetooth.hfpclient; import static com.android.bluetooth.hfpclient.HeadsetClientStateMachine.AT_OK; import static com.android.bluetooth.hfpclient.HeadsetClientStateMachine.VOICE_RECOGNITION_START; import static com.android.bluetooth.hfpclient.HeadsetClientStateMachine.VOICE_RECOGNITION_STOP; import static org.mockito.Mockito.*; Loading Loading @@ -562,4 +564,58 @@ public class HeadsetClientStateMachineTest { final String vendorResponseArgument = "2"; runUnsupportedVendorEvent(vendorId, vendorResponseCode, vendorResponseArgument); } /** * Test voice recognition state change broadcast. */ @MediumTest @Test public void testVoiceRecognitionStateChange() { // Setup connection state machine to be in connected state when(mHeadsetClientService.getConnectionPolicy(any(BluetoothDevice.class))).thenReturn( BluetoothProfile.CONNECTION_POLICY_ALLOWED); when(mNativeInterface.startVoiceRecognition(any(byte[].class))).thenReturn(true); when(mNativeInterface.stopVoiceRecognition(any(byte[].class))).thenReturn(true); int expectedBroadcastIndex = 1; expectedBroadcastIndex = setUpHfpClientConnection(expectedBroadcastIndex); expectedBroadcastIndex = setUpServiceLevelConnection(expectedBroadcastIndex); // Simulate a voice recognition start mHeadsetClientStateMachine.sendMessage(VOICE_RECOGNITION_START); // Signal that the complete list of actions was received. StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_CMD_RESULT); event.device = mTestDevice; event.valueInt = AT_OK; mHeadsetClientStateMachine.sendMessage(StackEvent.STACK_EVENT, event); expectedBroadcastIndex = verifyVoiceRecognitionBroadcast(expectedBroadcastIndex, HeadsetClientHalConstants.VR_STATE_STARTED); // Simulate a voice recognition stop mHeadsetClientStateMachine.sendMessage(VOICE_RECOGNITION_STOP); // Signal that the complete list of actions was received. event = new StackEvent(StackEvent.EVENT_TYPE_CMD_RESULT); event.device = mTestDevice; event.valueInt = AT_OK; mHeadsetClientStateMachine.sendMessage(StackEvent.STACK_EVENT, event); verifyVoiceRecognitionBroadcast(expectedBroadcastIndex, HeadsetClientHalConstants.VR_STATE_STOPPED); } private int verifyVoiceRecognitionBroadcast(int expectedBroadcastIndex, int expectedState) { // Validate broadcast intent ArgumentCaptor<Intent> intentArgument = ArgumentCaptor.forClass(Intent.class); verify(mHeadsetClientService, timeout(STANDARD_WAIT_MILLIS).times(expectedBroadcastIndex)) .sendBroadcast(intentArgument.capture(), anyString()); Assert.assertEquals(BluetoothHeadsetClient.ACTION_AG_EVENT, intentArgument.getValue().getAction()); int state = intentArgument.getValue().getIntExtra( BluetoothHeadsetClient.EXTRA_VOICE_RECOGNITION, -1); Assert.assertEquals(expectedState, state); return expectedBroadcastIndex + 1; } } Loading
src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +21 −9 Original line number Diff line number Diff line Loading @@ -1311,15 +1311,10 @@ public class HeadsetClientStateMachine extends StateMachine { mService.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM); break; case StackEvent.EVENT_TYPE_VR_STATE_CHANGED: if (mVoiceRecognitionActive != event.valueInt) { int oldState = mVoiceRecognitionActive; mVoiceRecognitionActive = event.valueInt; intent = new Intent(BluetoothHeadsetClient.ACTION_AG_EVENT); intent.putExtra(BluetoothHeadsetClient.EXTRA_VOICE_RECOGNITION, broadcastVoiceRecognitionStateChanged(event.device, oldState, mVoiceRecognitionActive); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, event.device); mService.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM); } break; case StackEvent.EVENT_TYPE_CALL: case StackEvent.EVENT_TYPE_CALLSETUP: Loading Loading @@ -1365,14 +1360,20 @@ public class HeadsetClientStateMachine extends StateMachine { break; case VOICE_RECOGNITION_START: if (event.valueInt == AT_OK) { oldState = mVoiceRecognitionActive; mVoiceRecognitionActive = HeadsetClientHalConstants.VR_STATE_STARTED; broadcastVoiceRecognitionStateChanged(event.device, oldState, mVoiceRecognitionActive); } break; case VOICE_RECOGNITION_STOP: if (event.valueInt == AT_OK) { oldState = mVoiceRecognitionActive; mVoiceRecognitionActive = HeadsetClientHalConstants.VR_STATE_STOPPED; broadcastVoiceRecognitionStateChanged(event.device, oldState, mVoiceRecognitionActive); } break; default: Loading Loading @@ -1421,6 +1422,17 @@ public class HeadsetClientStateMachine extends StateMachine { return HANDLED; } private void broadcastVoiceRecognitionStateChanged(BluetoothDevice device, int oldState, int newState) { if (oldState == newState) { return; } Intent intent = new Intent(BluetoothHeadsetClient.ACTION_AG_EVENT); intent.putExtra(BluetoothHeadsetClient.EXTRA_VOICE_RECOGNITION, newState); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); mService.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM); } // in Connected state private void processConnectionEvent(int state, BluetoothDevice device) { switch (state) { Loading
tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java +56 −0 Original line number Diff line number Diff line package com.android.bluetooth.hfpclient; import static com.android.bluetooth.hfpclient.HeadsetClientStateMachine.AT_OK; import static com.android.bluetooth.hfpclient.HeadsetClientStateMachine.VOICE_RECOGNITION_START; import static com.android.bluetooth.hfpclient.HeadsetClientStateMachine.VOICE_RECOGNITION_STOP; import static org.mockito.Mockito.*; Loading Loading @@ -562,4 +564,58 @@ public class HeadsetClientStateMachineTest { final String vendorResponseArgument = "2"; runUnsupportedVendorEvent(vendorId, vendorResponseCode, vendorResponseArgument); } /** * Test voice recognition state change broadcast. */ @MediumTest @Test public void testVoiceRecognitionStateChange() { // Setup connection state machine to be in connected state when(mHeadsetClientService.getConnectionPolicy(any(BluetoothDevice.class))).thenReturn( BluetoothProfile.CONNECTION_POLICY_ALLOWED); when(mNativeInterface.startVoiceRecognition(any(byte[].class))).thenReturn(true); when(mNativeInterface.stopVoiceRecognition(any(byte[].class))).thenReturn(true); int expectedBroadcastIndex = 1; expectedBroadcastIndex = setUpHfpClientConnection(expectedBroadcastIndex); expectedBroadcastIndex = setUpServiceLevelConnection(expectedBroadcastIndex); // Simulate a voice recognition start mHeadsetClientStateMachine.sendMessage(VOICE_RECOGNITION_START); // Signal that the complete list of actions was received. StackEvent event = new StackEvent(StackEvent.EVENT_TYPE_CMD_RESULT); event.device = mTestDevice; event.valueInt = AT_OK; mHeadsetClientStateMachine.sendMessage(StackEvent.STACK_EVENT, event); expectedBroadcastIndex = verifyVoiceRecognitionBroadcast(expectedBroadcastIndex, HeadsetClientHalConstants.VR_STATE_STARTED); // Simulate a voice recognition stop mHeadsetClientStateMachine.sendMessage(VOICE_RECOGNITION_STOP); // Signal that the complete list of actions was received. event = new StackEvent(StackEvent.EVENT_TYPE_CMD_RESULT); event.device = mTestDevice; event.valueInt = AT_OK; mHeadsetClientStateMachine.sendMessage(StackEvent.STACK_EVENT, event); verifyVoiceRecognitionBroadcast(expectedBroadcastIndex, HeadsetClientHalConstants.VR_STATE_STOPPED); } private int verifyVoiceRecognitionBroadcast(int expectedBroadcastIndex, int expectedState) { // Validate broadcast intent ArgumentCaptor<Intent> intentArgument = ArgumentCaptor.forClass(Intent.class); verify(mHeadsetClientService, timeout(STANDARD_WAIT_MILLIS).times(expectedBroadcastIndex)) .sendBroadcast(intentArgument.capture(), anyString()); Assert.assertEquals(BluetoothHeadsetClient.ACTION_AG_EVENT, intentArgument.getValue().getAction()); int state = intentArgument.getValue().getIntExtra( BluetoothHeadsetClient.EXTRA_VOICE_RECOGNITION, -1); Assert.assertEquals(expectedState, state); return expectedBroadcastIndex + 1; } }