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

Commit 2d978fcf authored by Shijian Li's avatar Shijian Li
Browse files

Handle external call updates during ringing in InCallWakeLockController.

In b/215559767, we changed the logic so that, for an HFP call, we firtly
mark them as a regular call, so that telecom stack will keep ringing.
And only if the user decided to pick up the call, we mark the external
call property depending on where this call is picked up. However,
telecom stack didn't consider that the call's external state would be
changed during ringing phase, so:

1. onCallAdded - The call is not an external call, so the telecom stack
   holds the wakelock and keeps ringing.
2. onCallStateChanged - The call is picked up, but since now the call is
   marked as external. We are not releasing the wake lock.

This patch captures the external call state change, and trigger
handleWakeLock again.

Bug: 220283618
Test: atest TelecomUnitTests:com.android.server.telecom.tests.InCallWakeLockControllerTest
Change-Id: If7861a8cbcaf7fbbc37c71d63d5f378c4e2e80cd
(cherry picked from commit 259aa4ec)
parent e6f35e8e
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -60,10 +60,18 @@ public class InCallWakeLockController extends CallsManagerListenerBase {
        handleWakeLock();
    }

    @Override
    public void onExternalCallChanged(Call call, boolean isExternalCall) {
        // In case a call changes its external call state during ringing, we need to trigger
        // the wake lock update correspondingly. External call is handled by another device
        // and should not hold a wake lock on the local device.
        handleWakeLock();
    }

    private void handleWakeLock() {
        // We grab a full lock as long as there exists a ringing call.
        Call ringingCall = mCallsManager.getRingingOrSimulatedRingingCall();
        if (ringingCall != null) {
        if (ringingCall != null && !ringingCall.isExternalCall()) {
            mTelecomWakeLock.acquire();
            Log.i(this, "Acquiring full wake lock");
        } else {
+31 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.telecom.tests;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.never;
@@ -128,4 +129,34 @@ public class InCallWakeLockControllerTest extends TelecomTestCase {

        verify(mWakeLockAdapter, never()).acquire();
    }

    @SmallTest
    @Test
    public void testExternalCallStateChangeDuringRinging() throws Exception {
        // A call is ringing on the local device directly.
        when(mCallsManager.getRingingOrSimulatedRingingCall()).thenReturn(mCall);
        when(mCall.isExternalCall()).thenReturn(false);

        mInCallWakeLockController.onCallAdded(mCall);

        verify(mWakeLockAdapter).acquire();

        // The call then becomes an external call during ringing. The wake lock should be
        // released.
        reset(mWakeLockAdapter);
        when(mWakeLockAdapter.isHeld()).thenReturn(true);
        when(mCall.isExternalCall()).thenReturn(true);

        mInCallWakeLockController.onExternalCallChanged(mCall, /* isExternalCall= */ true);

        verify(mWakeLockAdapter).release(0);

        // The call then is pulled to the device, wake up the device and acquire the wake lock.
        reset(mWakeLockAdapter);
        when(mCall.isExternalCall()).thenReturn(false);

        mInCallWakeLockController.onExternalCallChanged(mCall, /* isExternalCall= */ true);

        verify(mWakeLockAdapter).acquire();
    }
}