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

Commit 597e8993 authored by Paul Colta's avatar Paul Colta
Browse files

HDMI: Cancel standby delay runnable on one touch play

Users can press a button from the bottom sheet and switch inputs before
the runnable DelayedStandbyOnActiveSourceLostRunnable finished facing a
possible focus stealing issue.

Test: atest com.android.server.hdmi
Bug: 376496005
Flag: EXEMPT bugfix
Change-Id: I5b3cf00ac1b4ea06e79f857c1a087fd89c19e958
parent 22061481
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3178,6 +3178,10 @@ public class HdmiControlService extends SystemService {
        HdmiCecLocalDeviceSource source = playback();
        if (source == null) {
            source = audioSystem();
        } else {
            // Cancel an existing timer to send the device to sleep since OTP was triggered.
            playback().mDelayedStandbyOnActiveSourceLostHandler
                    .removeCallbacksAndMessages(null);
        }

        if (source == null) {
+55 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.HdmiPortInfo;
import android.hardware.hdmi.IHdmiControlCallback;
import android.hardware.tv.cec.V1_0.SendMessageResult;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.test.TestLooper;
@@ -2675,6 +2676,60 @@ public class HdmiCecLocalDevicePlaybackTest {
        assertThat(mPowerManager.isInteractive()).isTrue();
    }

    @Test
    public void onActiveSourceLost_oneTouchPlay_noStandbyAfterTimeout() {
        mHdmiCecLocalDevicePlayback.mService.getHdmiCecConfig().setStringValue(
                HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
                HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW);
        mHdmiCecLocalDevicePlayback.setActiveSource(mPlaybackLogicalAddress,
                mPlaybackPhysicalAddress, "HdmiCecLocalDevicePlaybackTest");
        mPowerManager.setInteractive(true);
        mNativeWrapper.clearResultMessages();
        mTestLooper.dispatchAll();

        HdmiCecMessage activeSourceFromTv =
                HdmiCecMessageBuilder.buildActiveSource(ADDR_TV, 0x0000);
        HdmiCecMessage activeSourceFromPlayback =
                HdmiCecMessageBuilder.buildActiveSource(mPlaybackLogicalAddress,
                        mPlaybackPhysicalAddress);

        assertThat(mHdmiCecLocalDevicePlayback.handleActiveSource(activeSourceFromTv))
                .isEqualTo(Constants.HANDLED);
        assertThat(mHdmiCecLocalDevicePlayback.getActiveSource().logicalAddress).isEqualTo(ADDR_TV);
        mTestLooper.dispatchAll();

        // Pop-up is triggered.
        mTestLooper.moveTimeForward(POPUP_AFTER_ACTIVE_SOURCE_LOST_DELAY_MS);
        mTestLooper.dispatchAll();
        // RequestActiveSourceAction is triggered and TV confirms active source.
        mNativeWrapper.onCecMessage(activeSourceFromTv);
        mTestLooper.dispatchAll();

        assertThat(mIsOnActiveSourceLostPopupActive).isTrue();
        mHdmiControlService.oneTouchPlay(new IHdmiControlCallback() {
            @Override
            public void onComplete(int result) throws RemoteException {
            }

            @Override
            public IBinder asBinder() {
                return null;
            }
        });
        mTestLooper.dispatchAll();

        assertThat(mIsOnActiveSourceLostPopupActive).isFalse();
        assertThat(mNativeWrapper.getResultMessages().contains(activeSourceFromPlayback)).isTrue();
        assertThat(mHdmiCecLocalDevicePlayback.getActiveSource().logicalAddress)
                .isEqualTo(mPlaybackLogicalAddress);
        assertThat(mHdmiCecLocalDevicePlayback.getActiveSource().physicalAddress)
                .isEqualTo(mPlaybackPhysicalAddress);
        mTestLooper.moveTimeForward(STANDBY_AFTER_ACTIVE_SOURCE_LOST_DELAY_MS);
        mTestLooper.dispatchAll();

        assertThat(mPowerManager.isInteractive()).isTrue();
    }

    @Test
    public void handleRoutingChange_addressNotAllocated_removeActiveSourceAction() {
        long allocationDelay = TimeUnit.SECONDS.toMillis(60);