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

Commit 7a583b42 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Handle external call updates during ringing in InCallWakeLockController." into tm-dev

parents b6e0b838 2d978fcf
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();
    }
}