diff --git a/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
index 382a61e146a305c3a9d779c083cb3f4ddcc73b92..131a4aa12e7b389c2a9995bf32376d657cb50918 100644
--- a/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
+++ b/android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
@@ -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)) {
diff --git a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java
index 2a9648920e216883a4a1056827b8ad1dc5fc06ce..632bdb30a984837ce89f97507e1c1050a58b3d27 100644
--- a/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java
+++ b/android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java
@@ -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