Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b68482f3 authored by Eric Shih's avatar Eric Shih
Browse files

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
parent 85eb19f2
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -343,7 +343,8 @@ public class HeadsetClientStateMachine extends StateMachine {
        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 @@ public class HeadsetClientStateMachine extends StateMachine {
        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 @@ public class HeadsetClientStateMachine extends StateMachine {
        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() {
+16 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.bluetooth.BluetoothAssignedNumbers;
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 @@ public class HeadsetClientStateMachineTest {
                .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