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

Commit e9849423 authored by Sherry Huang's avatar Sherry Huang
Browse files

HDMI-CEC: Do not request active source if it is already cached

Check if HdmiControlService's buffer contains <Active Source> before
send <Request Active Source>. Added a new function in HdmiControlService
to getCecMessageWithOpcode.

Test: atest HdmiCecLocalDeviceTvTest
Bug: b/383941201
Flag: EXEMPT bugfix only
Change-Id: I929b470e0ae7a7715f67550afbc6f040c33812c8
parent 0c0cfa27
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -219,7 +219,9 @@ public class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
                && reason != HdmiControlService.INITIATED_BY_BOOT_UP;
                && reason != HdmiControlService.INITIATED_BY_BOOT_UP;
        List<HdmiCecMessage> bufferedActiveSource = mDelayedMessageBuffer
        List<HdmiCecMessage> bufferedActiveSource = mDelayedMessageBuffer
                .getBufferedMessagesWithOpcode(Constants.MESSAGE_ACTIVE_SOURCE);
                .getBufferedMessagesWithOpcode(Constants.MESSAGE_ACTIVE_SOURCE);
        if (bufferedActiveSource.isEmpty()) {
        List<HdmiCecMessage> bufferedActiveSourceFromService = mService.getCecMessageWithOpcode(
                Constants.MESSAGE_ACTIVE_SOURCE);
        if (bufferedActiveSource.isEmpty() && bufferedActiveSourceFromService.isEmpty()) {
            addAndStartAction(new RequestActiveSourceAction(this, new IHdmiControlCallback.Stub() {
            addAndStartAction(new RequestActiveSourceAction(this, new IHdmiControlCallback.Stub() {
                @Override
                @Override
                public void onComplete(int result) {
                public void onComplete(int result) {
+11 −0
Original line number Original line Diff line number Diff line
@@ -1593,6 +1593,17 @@ public class HdmiControlService extends SystemService {
        this.mCecMessageBuffer = cecMessageBuffer;
        this.mCecMessageBuffer = cecMessageBuffer;
    }
    }


    List<HdmiCecMessage> getCecMessageWithOpcode(int opcode) {
        List<HdmiCecMessage> cecMessagesWithOpcode = new ArrayList<>();
        List<HdmiCecMessage> cecMessages = mCecMessageBuffer.getBuffer();
        for (HdmiCecMessage message: cecMessages) {
            if (message.getOpcode() == opcode) {
                cecMessagesWithOpcode.add(message);
            }
        }
        return cecMessagesWithOpcode;
    }

    /**
    /**
     * Returns {@link Looper} of main thread. Use this {@link Looper} instance
     * Returns {@link Looper} of main thread. Use this {@link Looper} instance
     * for tasks that are running on main service thread.
     * for tasks that are running on main service thread.
+32 −0
Original line number Original line Diff line number Diff line
@@ -2295,6 +2295,38 @@ public class HdmiCecLocalDeviceTvTest {
                .hasSize(1);
                .hasSize(1);
    }
    }


    @Test
    public void onOneTouchPlay_wakeUp_exist_device() {
        HdmiCecMessage requestActiveSource =
                HdmiCecMessageBuilder.buildRequestActiveSource(ADDR_TV);

        // Go to standby to trigger RequestActiveSourceAction for playback_1
        mHdmiControlService.onStandby(STANDBY_SCREEN_OFF);
        mTestLooper.dispatchAll();

        mNativeWrapper.setPollAddressResponse(ADDR_PLAYBACK_1, SendMessageResult.SUCCESS);
        mHdmiControlService.onWakeUp(WAKE_UP_SCREEN_ON);
        mTestLooper.dispatchAll();

        // Skip the LauncherX API timeout.
        mTestLooper.moveTimeForward(TIMEOUT_WAIT_FOR_TV_ASSERT_ACTIVE_SOURCE_MS);
        mTestLooper.dispatchAll();

        assertThat(mNativeWrapper.getResultMessages()).contains(requestActiveSource);
        mNativeWrapper.clearResultMessages();

        // turn off TV and wake up with one touch play
        mHdmiControlService.onStandby(STANDBY_SCREEN_OFF);
        mTestLooper.dispatchAll();

        // FakePowerManagerWrapper#wakeUp() doesn't broadcast Intent.ACTION_SCREEN_ON
        // manually trigger onWakeUp to mock OTP
        mHdmiControlService.onWakeUp(WAKE_UP_SCREEN_ON);
        mTestLooper.dispatchAll();

        assertThat(mNativeWrapper.getResultMessages()).doesNotContain(requestActiveSource);
    }



    @Test
    @Test
    public void handleReportAudioStatus_SamOnAvrStandby_startSystemAudioActionFromTv() {
    public void handleReportAudioStatus_SamOnAvrStandby_startSystemAudioActionFromTv() {