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

Commit 25e23385 authored by Amy's avatar Amy Committed by shubang
Browse files

Add setSystemAudioMode handler to update isSystemAudioModeActivated.

Test: atest com.android.server.hdmi
Bug: 123369653
Change-Id: I03349499236d32e4bf14ec89fe4a79046e8056fb
parent 489454ff
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -274,6 +274,23 @@ public class HdmiCecLocalDevicePlayback extends HdmiCecLocalDeviceSource {
        }
        }
    }
    }


    @Override
    protected boolean handleSetSystemAudioMode(HdmiCecMessage message) {
        // System Audio Mode only turns on/off when Audio System broadcasts on/off message.
        // For device with type 4 and 5, it can set system audio mode on/off
        // when there is another audio system device connected into the system first.
        if (message.getDestination() != Constants.ADDR_BROADCAST
                || message.getSource() != Constants.ADDR_AUDIO_SYSTEM
                || mService.audioSystem() != null) {
            return true;
        }
        boolean setSystemAudioModeOn = HdmiUtils.parseCommandParamSystemAudioStatus(message);
        if (mService.isSystemAudioActivated() != setSystemAudioModeOn) {
            mService.setSystemAudioActivated(setSystemAudioModeOn);
        }
        return true;
    }

    @Override
    @Override
    protected int findKeyReceiverAddress() {
    protected int findKeyReceiverAddress() {
        return Constants.ADDR_TV;
        return Constants.ADDR_TV;
+28 −0
Original line number Original line Diff line number Diff line
@@ -60,6 +60,11 @@ public class HdmiCecLocalDevicePlaybackTest {
                boolean isControlEnabled() {
                boolean isControlEnabled() {
                    return true;
                    return true;
                }
                }

                @Override
                void writeStringSystemProperty(String key, String value) {
                    // do nothing
                }
            };
            };


        mMyLooper = mTestLooper.getLooper();
        mMyLooper = mTestLooper.getLooper();
@@ -92,4 +97,27 @@ public class HdmiCecLocalDevicePlaybackTest {
        // TODO(amyjojo): Move set and get LocalActivePath to Control Service.
        // TODO(amyjojo): Move set and get LocalActivePath to Control Service.
        assertThat(mHdmiCecLocalDevicePlayback.getLocalActivePath()).isEqualTo(1);
        assertThat(mHdmiCecLocalDevicePlayback.getLocalActivePath()).isEqualTo(1);
    }
    }

    @Test
    public void handleSetSystemAudioModeOn_audioSystemBroadcast() {
        assertThat(mHdmiCecLocalDevicePlayback.mService.isSystemAudioActivated()).isFalse();
        HdmiCecMessage message =
                HdmiCecMessageBuilder.buildSetSystemAudioMode(
                        Constants.ADDR_AUDIO_SYSTEM, Constants.ADDR_BROADCAST, true);
        assertThat(mHdmiCecLocalDevicePlayback.handleSetSystemAudioMode(message)).isTrue();
        assertThat(mHdmiCecLocalDevicePlayback.mService.isSystemAudioActivated()).isTrue();
    }

    @Test
    public void handleSetSystemAudioModeOff_audioSystemToPlayback() {
        mHdmiCecLocalDevicePlayback.mService.setSystemAudioActivated(true);
        assertThat(mHdmiCecLocalDevicePlayback.mService.isSystemAudioActivated()).isTrue();
        // This direct message to Playback device is invalid.
        // Test should ignore it and still keep the system audio mode on.
        HdmiCecMessage message =
                HdmiCecMessageBuilder.buildSetSystemAudioMode(
                        Constants.ADDR_AUDIO_SYSTEM, mHdmiCecLocalDevicePlayback.mAddress, false);
        assertThat(mHdmiCecLocalDevicePlayback.handleSetSystemAudioMode(message)).isTrue();
        assertThat(mHdmiCecLocalDevicePlayback.mService.isSystemAudioActivated()).isTrue();
    }
}
}