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

Commit 64dbd2d4 authored by Chienyuan's avatar Chienyuan Committed by android-build-merger
Browse files

Merge changes I9da57d50,I8779be58 am: 061946aa

am: f9a28c48

Change-Id: I7cb7f39f589ec887727f6d61c36ced5d97262b51
parents 8ca0adee f9a28c48
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -1011,9 +1011,6 @@ public class HeadsetStateMachine extends StateMachine {
        @Override
        public void enter() {
            super.enter();
            if (mConnectingTimestampMs == Long.MIN_VALUE) {
                mConnectingTimestampMs = SystemClock.uptimeMillis();
            }
            if (mPrevState == mConnecting) {
                // Reset AG indicator subscriptions, HF can set this later using AT+BIA command
                updateAgIndicatorEnableState(DEFAULT_AG_INDICATOR_ENABLE_STATE);
@@ -1880,19 +1877,15 @@ public class HeadsetStateMachine extends StateMachine {
    private void processAtBind(String atString, BluetoothDevice device) {
        log("processAtBind: " + atString);

        // Parse the AT String to find the Indicator Ids that are supported
        int indId = 0;
        int iter = 0;
        int iter1 = 0;
        for (String id : atString.split(",")) {

        while (iter < atString.length()) {
            iter1 = findChar(',', atString, iter);
            String id = atString.substring(iter, iter1);
            int indId;

            try {
                indId = Integer.valueOf(id);
                indId = Integer.parseInt(id);
            } catch (NumberFormatException e) {
                Log.e(TAG, Log.getStackTraceString(new Throwable()));
                continue;
            }

            switch (indId) {
@@ -1908,8 +1901,6 @@ public class HeadsetStateMachine extends StateMachine {
                    log("Invalid HF Indicator Received");
                    break;
            }

            iter = iter1 + 1; // move past comma
        }
    }

+69 −0
Original line number Diff line number Diff line
@@ -940,6 +940,75 @@ public class HeadsetStateMachineTest {
        verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).disconnectAudio(mTestDevice);
    }

    /**
     * A test to verfiy that we correctly handles AT+BIND event with driver safety case from HF
     */
    @Test
    public void testAtBindWithDriverSafetyEventWhenConnecting() {
        setUpConnectingState();

        String atString = "1";
        mHeadsetStateMachine.sendMessage(HeadsetStateMachine.STACK_EVENT,
                new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_BIND, atString, mTestDevice));
        ArgumentCaptor<Intent> intentArgument = ArgumentCaptor.forClass(Intent.class);
        verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBroadcast(
                intentArgument.capture(), eq(HeadsetService.BLUETOOTH_PERM));
        verify(mHeadsetService, times(1)).sendBroadcast(any(), any());
        Assert.assertEquals(mTestDevice, intentArgument.getValue().getExtra(
                BluetoothDevice.EXTRA_DEVICE, null));
        Assert.assertEquals(HeadsetHalConstants.HF_INDICATOR_ENHANCED_DRIVER_SAFETY,
                intentArgument.getValue().getIntExtra(
                        BluetoothHeadset.EXTRA_HF_INDICATORS_IND_ID, -1));
        Assert.assertEquals(-1, intentArgument.getValue().getIntExtra(
                BluetoothHeadset.EXTRA_HF_INDICATORS_IND_VALUE, -2));
    }

    /**
     * A test to verfiy that we correctly handles AT+BIND event with battery level case from HF
     */
    @Test
    public void testAtBindEventWithBatteryLevelEventWhenConnecting() {
        setUpConnectingState();

        String atString = "2";
        mHeadsetStateMachine.sendMessage(HeadsetStateMachine.STACK_EVENT,
                new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_BIND, atString, mTestDevice));
        ArgumentCaptor<Intent> intentArgument = ArgumentCaptor.forClass(Intent.class);
        verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBroadcast(
                intentArgument.capture(), eq(HeadsetService.BLUETOOTH_PERM));
        verify(mHeadsetService, times(1)).sendBroadcast(any(), any());
        Assert.assertEquals(mTestDevice, intentArgument.getValue().getExtra(
                BluetoothDevice.EXTRA_DEVICE, null));
        Assert.assertEquals(HeadsetHalConstants.HF_INDICATOR_BATTERY_LEVEL_STATUS,
                intentArgument.getValue().getIntExtra(
                        BluetoothHeadset.EXTRA_HF_INDICATORS_IND_ID, -1));
        Assert.assertEquals(-1, intentArgument.getValue().getIntExtra(
                BluetoothHeadset.EXTRA_HF_INDICATORS_IND_VALUE, -2));
    }

    /**
     * A test to verfiy that we correctly handles AT+BIND event with error case from HF
     */
    @Test
    public void testAtBindEventWithErrorEventWhenConnecting() {
        setUpConnectingState();

        String atString = "err,A,123,,1";
        mHeadsetStateMachine.sendMessage(HeadsetStateMachine.STACK_EVENT,
                new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_BIND, atString, mTestDevice));
        ArgumentCaptor<Intent> intentArgument = ArgumentCaptor.forClass(Intent.class);
        verify(mHeadsetService, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).sendBroadcast(
                intentArgument.capture(), eq(HeadsetService.BLUETOOTH_PERM));
        verify(mHeadsetService, times(1)).sendBroadcast(any(), any());
        Assert.assertEquals(mTestDevice, intentArgument.getValue().getExtra(
                BluetoothDevice.EXTRA_DEVICE, null));
        Assert.assertEquals(HeadsetHalConstants.HF_INDICATOR_ENHANCED_DRIVER_SAFETY,
                intentArgument.getValue().getIntExtra(
                        BluetoothHeadset.EXTRA_HF_INDICATORS_IND_ID, -1));
        Assert.assertEquals(-1, intentArgument.getValue().getIntExtra(
                BluetoothHeadset.EXTRA_HF_INDICATORS_IND_VALUE, -2));
    }

    /**
     * Setup Connecting State
     * @return number of times mHeadsetService.sendBroadcastAsUser() has been invoked