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

Commit 592f2a04 authored by Yuyang Huang's avatar Yuyang Huang Committed by Gerrit Code Review
Browse files

Merge "Sending service availability and signal strength in +CIND response...

Merge "Sending service availability and signal strength in +CIND response during non-VOIP call even if there is no service." into main
parents 6c46436b 47045a42
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -1926,8 +1926,10 @@ public class HeadsetStateMachine extends StateMachine {
    }

    private void processAtCind(BluetoothDevice device) {
        int call, callSetup;
        logi("processAtCind: for device=" + device);
        final HeadsetPhoneState phoneState = mSystemInterface.getHeadsetPhoneState();
        int call, callSetup;
        int service = phoneState.getCindService(), signal = phoneState.getCindSignal();

        /* Handsfree carkits expect that +CIND is properly responded to
         Hence we ensure that a proper response is sent
@@ -1941,8 +1943,36 @@ public class HeadsetStateMachine extends StateMachine {
            callSetup = phoneState.getNumHeldCall();
        }

        mNativeInterface.cindResponse(device, phoneState.getCindService(), call, callSetup,
                phoneState.getCallState(), phoneState.getCindSignal(), phoneState.getCindRoam(),
        if (Flags.pretendNetworkService()) {
            logd("processAtCind: pretendNetworkService enabled");
            boolean isCallOngoing =
                    (phoneState.getNumActiveCall() > 0)
                            || (phoneState.getNumHeldCall() > 0)
                            || phoneState.getCallState() == HeadsetHalConstants.CALL_STATE_ALERTING
                            || phoneState.getCallState() == HeadsetHalConstants.CALL_STATE_DIALING
                            || phoneState.getCallState() == HeadsetHalConstants.CALL_STATE_INCOMING;
            if ((isCallOngoing
                    && (!mHeadsetService.isVirtualCallStarted())
                    && (phoneState.getCindService()
                            == HeadsetHalConstants.NETWORK_STATE_NOT_AVAILABLE))) {
                logi(
                        "processAtCind: If regular call is in progress/active/held while no network"
                            + " during BT-ON, pretend service availability and signal strength");
                service = HeadsetHalConstants.NETWORK_STATE_AVAILABLE;
                signal = 3;
            } else {
                service = phoneState.getCindService();
                signal = phoneState.getCindSignal();
            }
        }
        mNativeInterface.cindResponse(
                device,
                service,
                call,
                callSetup,
                phoneState.getCallState(),
                signal,
                phoneState.getCindRoam(),
                phoneState.getCindBatteryCharge());
    }

+40 −0
Original line number Diff line number Diff line
@@ -1015,6 +1015,46 @@ public class HeadsetStateMachineTest {
        verify(mSystemInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS)).hangupCall(mTestDevice);
    }

    /** A test to verify that we correctly send CIND response when a call is in progress */
    @Test
    @RequiresFlagsEnabled(Flags.FLAG_PRETEND_NETWORK_SERVICE)
    public void testCindEventWhenCallIsInProgress() {
        when(mPhoneState.getCindService())
                .thenReturn(HeadsetHalConstants.NETWORK_STATE_NOT_AVAILABLE);
        when(mHeadsetService.isVirtualCallStarted()).thenReturn(false);
        when(mPhoneState.getNumActiveCall()).thenReturn(1);

        setUpAudioOnState();

        mHeadsetStateMachine.sendMessage(
                HeadsetStateMachine.STACK_EVENT,
                new HeadsetStackEvent(HeadsetStackEvent.EVENT_TYPE_AT_CIND, mTestDevice));
        // wait state machine to process the message
        if (Flags.pretendNetworkService()) {
            verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                    .cindResponse(
                            eq(mTestDevice),
                            eq(HeadsetHalConstants.NETWORK_STATE_AVAILABLE),
                            anyInt(),
                            anyInt(),
                            anyInt(),
                            anyInt(),
                            anyInt(),
                            anyInt());
        } else {
            verify(mNativeInterface, timeout(ASYNC_CALL_TIMEOUT_MILLIS))
                    .cindResponse(
                            eq(mTestDevice),
                            eq(HeadsetHalConstants.NETWORK_STATE_NOT_AVAILABLE),
                            anyInt(),
                            anyInt(),
                            anyInt(),
                            anyInt(),
                            anyInt(),
                            anyInt());
        }
    }

    /**
     * A test to verify that we correctly handles key pressed event from a HSP headset
     */