Add OK into queue after sendAndroidAt
Add OK into queue after sending AT command and add unit test for it.
Bug: 270294700
Test: atest GoogleBluetoothInstrumentationTests
Tag: #feature
Change-Id: Iff0e846f0dfe4d8fb2349e7ac9e6118b24f95706
diff --git a/android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java b/android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
index f3d8f62..7d6c388 100644
--- a/android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
+++ b/android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
@@ -343,7 +343,8 @@
mPendingAction = new Pair<Integer, Object>(NO_ACTION, 0);
}
- private void addQueuedAction(int action) {
+ @VisibleForTesting
+ void addQueuedAction(int action) {
addQueuedAction(action, 0);
}
@@ -2197,7 +2198,7 @@
logD("setAudioPolicy: " + policies);
mHsClientAudioPolicy = policies;
- if (mAudioPolicyRemoteSupported != BluetoothStatusCodes.FEATURE_SUPPORTED) {
+ if (getAudioPolicyRemoteSupported() != BluetoothStatusCodes.FEATURE_SUPPORTED) {
Log.e(TAG, "Audio Policy feature not supported!");
return;
}
@@ -2205,7 +2206,9 @@
if (!mNativeInterface.sendAndroidAt(mCurrentDevice,
"+ANDROID=" + createMaskString(policies))) {
Log.e(TAG, "ERROR: Couldn't send call audio policies");
+ return;
}
+ addQueuedAction(SEND_ANDROID_AT_COMMAND);
}
private boolean queryRemoteSupportedFeatures() {
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java
index cda01f6..65df324 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachineTest.java
@@ -35,6 +35,7 @@
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothSinkAudioPolicy;
+import android.bluetooth.BluetoothStatusCodes;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
@@ -1103,8 +1104,23 @@
.setInBandRingtonePolicy(BluetoothSinkAudioPolicy.POLICY_ALLOWED)
.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);
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