Loading android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -1991,6 +1991,12 @@ public class HeadsetStateMachine extends StateMachine { Object[] args = generateArgs(arg); 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]; String type = (String) args[0]; if (type.equals(BluetoothSinkAudioPolicy.HFP_SET_SINK_AUDIO_POLICY_ID)) { if (type.equals(BluetoothSinkAudioPolicy.HFP_SET_SINK_AUDIO_POLICY_ID)) { Loading android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java +30 −14 Original line number Original line Diff line number Diff line Loading @@ -48,7 +48,6 @@ import androidx.test.InstrumentationRegistry; import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.R; import com.android.bluetooth.TestUtils; import com.android.bluetooth.TestUtils; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.btservice.storage.DatabaseManager; Loading @@ -56,7 +55,6 @@ import com.android.bluetooth.btservice.storage.DatabaseManager; import org.hamcrest.core.IsInstanceOf; import org.hamcrest.core.IsInstanceOf; import org.junit.After; import org.junit.After; import org.junit.Assert; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; import org.junit.Before; import org.junit.Ignore; import org.junit.Ignore; import org.junit.Test; import org.junit.Test; Loading Loading @@ -1442,22 +1440,40 @@ public class HeadsetStateMachineTest { @Test @Test public void testCheckAndProcessAndroidAt() { public void testCheckAndProcessAndroidAt() { // Commands that will be handled // Commands that will be handled int counter_ok = 0; int counter_error = 0; Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( "+ANDROID=?" , mTestDevice)); "+ANDROID=?" , mTestDevice)); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( "+ANDROID=SINKAUDIOPOLICY,1,1,1" , mTestDevice)); "+ANDROID=SINKAUDIOPOLICY,1,1,1" , mTestDevice)); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( "+ANDROID=SINKAUDIOPOLICY,100,100,100" , mTestDevice)); "+ANDROID=SINKAUDIOPOLICY,100,100,100" , mTestDevice)); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(3)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( "+ANDROID=SINKAUDIOPOLICY,1,2,3,4,5" , mTestDevice)); "+ANDROID=SINKAUDIOPOLICY,1,2,3,4,5" , mTestDevice)); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_error)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0); .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 // Commands with correct format but will not be handled Assert.assertFalse(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertFalse(mHeadsetStateMachine.checkAndProcessAndroidAt( Loading @@ -1474,10 +1490,10 @@ public class HeadsetStateMachineTest { "RANDOM FORMAT" , mTestDevice)); "RANDOM FORMAT" , mTestDevice)); // Check no any AT result was sent for the failed ones // Check no any AT result was sent for the failed ones verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(3)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(counter_ok)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(counter_error)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0); } } @Test @Test Loading Loading
android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +6 −0 Original line number Original line Diff line number Diff line Loading @@ -1991,6 +1991,12 @@ public class HeadsetStateMachine extends StateMachine { Object[] args = generateArgs(arg); 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]; String type = (String) args[0]; if (type.equals(BluetoothSinkAudioPolicy.HFP_SET_SINK_AUDIO_POLICY_ID)) { if (type.equals(BluetoothSinkAudioPolicy.HFP_SET_SINK_AUDIO_POLICY_ID)) { Loading
android/app/tests/unit/src/com/android/bluetooth/hfp/HeadsetStateMachineTest.java +30 −14 Original line number Original line Diff line number Diff line Loading @@ -48,7 +48,6 @@ import androidx.test.InstrumentationRegistry; import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.R; import com.android.bluetooth.TestUtils; import com.android.bluetooth.TestUtils; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.btservice.storage.DatabaseManager; Loading @@ -56,7 +55,6 @@ import com.android.bluetooth.btservice.storage.DatabaseManager; import org.hamcrest.core.IsInstanceOf; import org.hamcrest.core.IsInstanceOf; import org.junit.After; import org.junit.After; import org.junit.Assert; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; import org.junit.Before; import org.junit.Ignore; import org.junit.Ignore; import org.junit.Test; import org.junit.Test; Loading Loading @@ -1442,22 +1440,40 @@ public class HeadsetStateMachineTest { @Test @Test public void testCheckAndProcessAndroidAt() { public void testCheckAndProcessAndroidAt() { // Commands that will be handled // Commands that will be handled int counter_ok = 0; int counter_error = 0; Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( "+ANDROID=?" , mTestDevice)); "+ANDROID=?" , mTestDevice)); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( "+ANDROID=SINKAUDIOPOLICY,1,1,1" , mTestDevice)); "+ANDROID=SINKAUDIOPOLICY,1,1,1" , mTestDevice)); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( "+ANDROID=SINKAUDIOPOLICY,100,100,100" , mTestDevice)); "+ANDROID=SINKAUDIOPOLICY,100,100,100" , mTestDevice)); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(3)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_ok)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertTrue(mHeadsetStateMachine.checkAndProcessAndroidAt( "+ANDROID=SINKAUDIOPOLICY,1,2,3,4,5" , mTestDevice)); "+ANDROID=SINKAUDIOPOLICY,1,2,3,4,5" , mTestDevice)); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(++counter_error)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0); .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 // Commands with correct format but will not be handled Assert.assertFalse(mHeadsetStateMachine.checkAndProcessAndroidAt( Assert.assertFalse(mHeadsetStateMachine.checkAndProcessAndroidAt( Loading @@ -1474,10 +1490,10 @@ public class HeadsetStateMachineTest { "RANDOM FORMAT" , mTestDevice)); "RANDOM FORMAT" , mTestDevice)); // Check no any AT result was sent for the failed ones // Check no any AT result was sent for the failed ones verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(3)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(counter_ok)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_OK, 0); verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(1)).atResponseCode( verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(counter_error)) mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0); .atResponseCode(mTestDevice, HeadsetHalConstants.AT_RESPONSE_ERROR, 0); } } @Test @Test Loading