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

Commit 827e62a0 authored by Paul Colta's avatar Paul Colta Committed by Android (Google) Code Review
Browse files

Merge "HDMI: Cancel pending ActiveSourceAction on active source lost" into main

parents a3e59dc9 c896be22
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -197,6 +197,8 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
        boolean wasActiveSource = isActiveSource();
        super.setActiveSource(logicalAddress, physicalAddress, caller);
        if (wasActiveSource && !isActiveSource()) {
            // Prevent focus stealing when losing active source.
            removeAction(ActiveSourceAction.class);
            onActiveSourceLost();
        }
    }
+40 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class ActiveSourceActionTest {
    private TestLooper mTestLooper = new TestLooper();
    private ArrayList<HdmiCecLocalDevice> mLocalDevices = new ArrayList<>();
    private int mPhysicalAddress;
    private boolean mIsPowerStandby;

    @Before
    public void setUp() throws Exception {
@@ -68,12 +69,13 @@ public class ActiveSourceActionTest {
                        .hasSystemFeature(FEATURE_HDMI_CEC));
        mContextSpy = spy(new ContextWrapper(InstrumentationRegistry.getTargetContext()));

        mIsPowerStandby = false;
        FakeAudioFramework audioFramework = new FakeAudioFramework();
        mHdmiControlService = new HdmiControlService(mContextSpy, Collections.emptyList(),
                audioFramework.getAudioManager(), audioFramework.getAudioDeviceVolumeManager()) {
            @Override
            boolean isPowerStandby() {
                return false;
                return mIsPowerStandby;
            }

            @Override
@@ -151,4 +153,41 @@ public class ActiveSourceActionTest {
        assertThat(playbackDevice.getActiveSource().physicalAddress).isEqualTo(mPhysicalAddress);
        assertThat(playbackDevice.isActiveSource()).isTrue();
    }

    @Test
    public void onActiveSourceLost_removePendingActiveSourceAction() {
        HdmiCecLocalDevicePlayback playbackDevice = new HdmiCecLocalDevicePlayback(
                mHdmiControlService);
        playbackDevice.init();
        mLocalDevices.add(playbackDevice);
        mHdmiControlService.allocateLogicalAddress(mLocalDevices, INITIATED_BY_ENABLE_CEC);
        mIsPowerStandby = true;
        mTestLooper.dispatchAll();

        mNativeWrapper.clearResultMessages();
        mTestLooper.dispatchAll();

        int otherPlaybackLogicalAddress = playbackDevice.getDeviceInfo().getLogicalAddress()
                == Constants.ADDR_PLAYBACK_2
                ? Constants.ADDR_PLAYBACK_1 : Constants.ADDR_PLAYBACK_2;
        HdmiCecMessage activeSourceFromOtherDevice =
                HdmiCecMessageBuilder.buildActiveSource(
                        otherPlaybackLogicalAddress, 0x2200);
        HdmiCecMessage activeSourceFromDevice =
                HdmiCecMessageBuilder.buildActiveSource(
                        playbackDevice.getDeviceInfo().getLogicalAddress(), mPhysicalAddress);

        HdmiCecFeatureAction action = new com.android.server.hdmi.ActiveSourceAction(
                playbackDevice, ADDR_TV);
        playbackDevice.addAndStartAction(action);
        mTestLooper.dispatchAll();

        assertThat(playbackDevice.getActions(ActiveSourceAction.class)).hasSize(1);
        playbackDevice.handleActiveSource(activeSourceFromOtherDevice);
        mTestLooper.dispatchAll();

        // Action is removed
        assertThat(playbackDevice.getActions(ActiveSourceAction.class)).hasSize(0);
        assertThat(mNativeWrapper.getResultMessages()).doesNotContain(activeSourceFromDevice);
    }
}