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

Commit 59fcf00c authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Reject ANDROID AT command if the first param is not String" am: 8ab129fd

parents 29049d4e 8ab129fd
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1991,6 +1991,12 @@ public class HeadsetStateMachine extends StateMachine {

            Object[] args = generateArgs(arg);

            if (!(args[0] instanceof String)) {
                Log.w(TAG, "Incorrect type of Android AT command!");
                mNativeInterface.atResponseCode(device, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
                return true;
            }

            String type = (String) args[0];

            if (type.equals(BluetoothSinkAudioPolicy.HFP_SET_SINK_AUDIO_POLICY_ID)) {
+30 −14
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.storage.DatabaseManager;
@@ -56,7 +55,6 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import org.hamcrest.core.IsInstanceOf;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -1442,22 +1440,40 @@ public class HeadsetStateMachineTest {
    @Test
    public void testCheckAndProcessAndroidAt() {
        // Commands that will be handled
        int counter_ok = 0;
        int counter_error = 0;
        Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt(
            "+ANDROID=?" , mTestDevice));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode(
                mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt(
            "+ANDROID=SINKAUDIOPOLICY,1,1,1" , mTestDevice));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).atResponseCode(
                mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt(
            "+ANDROID=SINKAUDIOPOLICY,100,100,100" , mTestDevice));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(3)).atResponseCode(
                mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt(
            "+ANDROID=SINKAUDIOPOLICY,1,2,3,4,5" , mTestDevice));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode(
                mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_error))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
        Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt("+ANDROID=1", mTestDevice));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_error))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
        Assert.assertTrue(
                mHeadsetStateMachine.checkAndProcessAndroidAt("+ANDROID=1,2", mTestDevice));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_error))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
        Assert.assertTrue(
                mHeadsetStateMachine.checkAndProcessAndroidAt("+ANDROID=1,2,3", mTestDevice));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_error))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
        Assert.assertTrue(
                mHeadsetStateMachine.checkAndProcessAndroidAt(
                        "+ANDROID=1,2,3,4,5,6,7", mTestDevice));
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_error))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);

        // Commands with correct format but will not be handled
        Assert.assertFalse(mHeadsetStateMachine.checkAndProcessAndroidAt(
@@ -1474,10 +1490,10 @@ public class HeadsetStateMachineTest {
            "RANDOM FORMAT" , mTestDevice));

        // Check no any AT result was sent for the failed ones
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(3)).atResponseCode(
                mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode(
                mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(counter_ok))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0);
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(counter_error))
                .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0);
    }

    @Test