Loading android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +5 −2 Original line number Original line Diff line number Diff line Loading @@ -343,7 +343,8 @@ public class HeadsetClientStateMachine extends StateMachine { mPendingAction = new Pair<Integer, Object>(NO_ACTION, 0); mPendingAction = new Pair<Integer, Object>(NO_ACTION, 0); } } private void addQueuedAction(int action) { @VisibleForTesting void addQueuedAction(int action) { addQueuedAction(action, 0); addQueuedAction(action, 0); } } Loading Loading @@ -2197,7 +2198,7 @@ public class HeadsetClientStateMachine extends StateMachine { logD("setAudioPolicy: " + policies); logD("setAudioPolicy: " + policies); mHsClientAudioPolicy = policies; mHsClientAudioPolicy = policies; if (mAudioPolicyRemoteSupported != BluetoothStatusCodes.FEATURE_SUPPORTED) { if (getAudioPolicyRemoteSupported() != BluetoothStatusCodes.FEATURE_SUPPORTED) { Log.e(TAG, "Audio Policy feature not supported!"); Log.e(TAG, "Audio Policy feature not supported!"); return; return; } } Loading @@ -2205,7 +2206,9 @@ public class HeadsetClientStateMachine extends StateMachine { if (!mNativeInterface.sendAndroidAt(mCurrentDevice, if (!mNativeInterface.sendAndroidAt(mCurrentDevice, "+ANDROID=" + createMaskString(policies))) { "+ANDROID=" + createMaskString(policies))) { Log.e(TAG, "ERROR: Couldn't send call audio policies"); Log.e(TAG, "ERROR: Couldn't send call audio policies"); return; } } addQueuedAction(SEND_ANDROID_AT_COMMAND); } } private boolean queryRemoteSupportedFeatures() { private boolean queryRemoteSupportedFeatures() { Loading android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java +16 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.bluetooth.BluetoothAssignedNumbers; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothSinkAudioPolicy; import android.bluetooth.BluetoothSinkAudioPolicy; import android.bluetooth.BluetoothStatusCodes; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; Loading Loading @@ -1103,8 +1104,23 @@ public class HeadsetClientStateMachineTest { .setInBandRingtonePolicy(BluetoothSinkAudioPolicy.POLICY_ALLOWED) .setInBandRingtonePolicy(BluetoothSinkAudioPolicy.POLICY_ALLOWED) .build(); .build(); // Test if not support audio policy feature mHeadsetClientStateMachine.setAudioPolicyRemoteSupported(false); mHeadsetClientStateMachine.setAudioPolicy(dummyAudioPolicy); verify(mNativeInterface, never()).sendAndroidAt(mTestDevice, "+ANDROID=1,1,2,1"); Assert.assertEquals(0, mHeadsetClientStateMachine.mQueuedActions.size()); // Test setAudioPolicy mHeadsetClientStateMachine.setAudioPolicyRemoteSupported(true); mHeadsetClientStateMachine.setAudioPolicy(dummyAudioPolicy); mHeadsetClientStateMachine.setAudioPolicy(dummyAudioPolicy); verify(mNativeInterface).sendAndroidAt(mTestDevice, "+ANDROID=1,1,2,1"); verify(mNativeInterface).sendAndroidAt(mTestDevice, "+ANDROID=1,1,2,1"); Assert.assertEquals(1, mHeadsetClientStateMachine.mQueuedActions.size()); mHeadsetClientStateMachine.mQueuedActions.clear(); // Test if fail to sendAndroidAt doReturn(false).when(mNativeInterface).sendAndroidAt(anyObject(), anyString()); mHeadsetClientStateMachine.setAudioPolicy(dummyAudioPolicy); Assert.assertEquals(0, mHeadsetClientStateMachine.mQueuedActions.size()); } } @Test @Test Loading Loading
android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +5 −2 Original line number Original line Diff line number Diff line Loading @@ -343,7 +343,8 @@ public class HeadsetClientStateMachine extends StateMachine { mPendingAction = new Pair<Integer, Object>(NO_ACTION, 0); mPendingAction = new Pair<Integer, Object>(NO_ACTION, 0); } } private void addQueuedAction(int action) { @VisibleForTesting void addQueuedAction(int action) { addQueuedAction(action, 0); addQueuedAction(action, 0); } } Loading Loading @@ -2197,7 +2198,7 @@ public class HeadsetClientStateMachine extends StateMachine { logD("setAudioPolicy: " + policies); logD("setAudioPolicy: " + policies); mHsClientAudioPolicy = policies; mHsClientAudioPolicy = policies; if (mAudioPolicyRemoteSupported != BluetoothStatusCodes.FEATURE_SUPPORTED) { if (getAudioPolicyRemoteSupported() != BluetoothStatusCodes.FEATURE_SUPPORTED) { Log.e(TAG, "Audio Policy feature not supported!"); Log.e(TAG, "Audio Policy feature not supported!"); return; return; } } Loading @@ -2205,7 +2206,9 @@ public class HeadsetClientStateMachine extends StateMachine { if (!mNativeInterface.sendAndroidAt(mCurrentDevice, if (!mNativeInterface.sendAndroidAt(mCurrentDevice, "+ANDROID=" + createMaskString(policies))) { "+ANDROID=" + createMaskString(policies))) { Log.e(TAG, "ERROR: Couldn't send call audio policies"); Log.e(TAG, "ERROR: Couldn't send call audio policies"); return; } } addQueuedAction(SEND_ANDROID_AT_COMMAND); } } private boolean queryRemoteSupportedFeatures() { private boolean queryRemoteSupportedFeatures() { Loading
android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java +16 −0 Original line number Original line Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.bluetooth.BluetoothAssignedNumbers; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothSinkAudioPolicy; import android.bluetooth.BluetoothSinkAudioPolicy; import android.bluetooth.BluetoothStatusCodes; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.Context; import android.content.Intent; import android.content.Intent; Loading Loading @@ -1103,8 +1104,23 @@ public class HeadsetClientStateMachineTest { .setInBandRingtonePolicy(BluetoothSinkAudioPolicy.POLICY_ALLOWED) .setInBandRingtonePolicy(BluetoothSinkAudioPolicy.POLICY_ALLOWED) .build(); .build(); // Test if not support audio policy feature mHeadsetClientStateMachine.setAudioPolicyRemoteSupported(false); mHeadsetClientStateMachine.setAudioPolicy(dummyAudioPolicy); verify(mNativeInterface, never()).sendAndroidAt(mTestDevice, "+ANDROID=1,1,2,1"); Assert.assertEquals(0, mHeadsetClientStateMachine.mQueuedActions.size()); // Test setAudioPolicy mHeadsetClientStateMachine.setAudioPolicyRemoteSupported(true); mHeadsetClientStateMachine.setAudioPolicy(dummyAudioPolicy); mHeadsetClientStateMachine.setAudioPolicy(dummyAudioPolicy); verify(mNativeInterface).sendAndroidAt(mTestDevice, "+ANDROID=1,1,2,1"); verify(mNativeInterface).sendAndroidAt(mTestDevice, "+ANDROID=1,1,2,1"); Assert.assertEquals(1, mHeadsetClientStateMachine.mQueuedActions.size()); mHeadsetClientStateMachine.mQueuedActions.clear(); // Test if fail to sendAndroidAt doReturn(false).when(mNativeInterface).sendAndroidAt(anyObject(), anyString()); mHeadsetClientStateMachine.setAudioPolicy(dummyAudioPolicy); Assert.assertEquals(0, mHeadsetClientStateMachine.mQueuedActions.size()); } } @Test @Test Loading