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

Commit cce55e01 authored by Amy's avatar Amy Committed by shubang
Browse files

Adding system audio control muting logic.

cherry-pick ag/4823184

Test: atest com.android.server.hdmi
Change-Id: Ia6df1a4b3bce703e7d01956b539611732f2c5a86
parent 1b9f645e
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -273,6 +273,16 @@ final class Constants {
    // TODO(OEM): Set this to true to enable 'Set Menu Language' feature. False by default.
    // TODO(OEM): Set this to true to enable 'Set Menu Language' feature. False by default.
    static final String PROPERTY_SET_MENU_LANGUAGE = "ro.hdmi.set_menu_language";
    static final String PROPERTY_SET_MENU_LANGUAGE = "ro.hdmi.set_menu_language";


    /**
     * Property to disable muting logic in System Audio Control handling. Default is true.
     *
     * <p>True means enabling muting logic.
     * <p>False means never mute device.
     */
    // TODO(OEM): set to true to disable muting.
    static final String PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE =
            "ro.hdmi.property_system_audio_mode_muting_enable";

    // Set to false to allow playback device to go to suspend mode even
    // Set to false to allow playback device to go to suspend mode even
    // when it's an active source. True by default.
    // when it's an active source. True by default.
    static final String PROPERTY_KEEP_AWAKE = "persist.sys.hdmi.keep_awake";
    static final String PROPERTY_KEEP_AWAKE = "persist.sys.hdmi.keep_awake";
+19 −3
Original line number Original line Diff line number Diff line
@@ -77,6 +77,8 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDevice {
        // TODO(amyjojo) make System Audio Control controllable by users
        // TODO(amyjojo) make System Audio Control controllable by users
        /*mSystemAudioControlFeatureEnabled =
        /*mSystemAudioControlFeatureEnabled =
        mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, true);*/
        mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, true);*/
        // TODO(b/80297700): set read-only property in config instead of setting here
        SystemProperties.set(Constants.PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE, "false");
        mAutoDeviceOff = mService.readBooleanSetting(
        mAutoDeviceOff = mService.readBooleanSetting(
                Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED, true);
                Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED, true);
        mAutoTvOff = mService.readBooleanSetting(
        mAutoTvOff = mService.readBooleanSetting(
@@ -425,7 +427,21 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDevice {
        if (newSystemAudioMode && port >= 0) {
        if (newSystemAudioMode && port >= 0) {
            switchToAudioInput();
            switchToAudioInput();
        }
        }
        // TODO(b/80297700): Mute device when TV terminates the system audio control
        // Mute device when feature is turned off and unmute device when feature is turned on.
        // PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE is false when device never needs to be muted.
        boolean currentMuteStatus =
                mService.getAudioManager().isStreamMute(AudioManager.STREAM_MUSIC);
        if (SystemProperties.getBoolean(
                Constants.PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE, true)
                && currentMuteStatus == newSystemAudioMode) {
            mService.getAudioManager()
                    .adjustStreamVolume(
                            AudioManager.STREAM_MUSIC,
                            newSystemAudioMode
                                    ? AudioManager.ADJUST_UNMUTE
                                    : AudioManager.ADJUST_MUTE,
                                    0);
        }
        updateAudioManagerForSystemAudio(newSystemAudioMode);
        updateAudioManagerForSystemAudio(newSystemAudioMode);
        synchronized (mLock) {
        synchronized (mLock) {
            if (mSystemAudioActivated != newSystemAudioMode) {
            if (mSystemAudioActivated != newSystemAudioMode) {
+3 −5
Original line number Original line Diff line number Diff line
@@ -34,7 +34,6 @@ import androidx.test.filters.SmallTest;
import com.android.server.hdmi.HdmiCecLocalDevice.ActiveSource;
import com.android.server.hdmi.HdmiCecLocalDevice.ActiveSource;


import org.junit.Before;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.runners.JUnit4;
@@ -149,6 +148,7 @@ public class HdmiCecLocalDeviceAudioSystemTest {
        mAvrPhysicalAddress  = 0x2000;
        mAvrPhysicalAddress  = 0x2000;
        mNativeWrapper.setPhysicalAddress(mAvrPhysicalAddress);
        mNativeWrapper.setPhysicalAddress(mAvrPhysicalAddress);
        SystemProperties.set(Constants.PROPERTY_ARC_SUPPORT, "true");
        SystemProperties.set(Constants.PROPERTY_ARC_SUPPORT, "true");
        SystemProperties.set(Constants.PROPERTY_SYSTEM_AUDIO_MODE_MUTING_ENABLE, "true");
    }
    }


    @Test
    @Test
@@ -179,7 +179,6 @@ public class HdmiCecLocalDeviceAudioSystemTest {
        assertThat(mNativeWrapper.getOnlyResultMessage()).isEqualTo(expectedMessage);
        assertThat(mNativeWrapper.getOnlyResultMessage()).isEqualTo(expectedMessage);
    }
    }


    @Ignore("b/80297700")
    @Test
    @Test
    public void handleRequestShortAudioDescriptor_featureDisabled() throws Exception {
    public void handleRequestShortAudioDescriptor_featureDisabled() throws Exception {
        HdmiCecMessage expectedMessage =
        HdmiCecMessage expectedMessage =
@@ -261,7 +260,6 @@ public class HdmiCecLocalDeviceAudioSystemTest {
        assertThat(mMusicMute).isFalse();
        assertThat(mMusicMute).isFalse();
    }
    }


    @Ignore("b/80297700")
    @Test
    @Test
    public void handleSystemAudioModeRequest_turnOffByTv() throws Exception {
    public void handleSystemAudioModeRequest_turnOffByTv() throws Exception {
        assertThat(mMusicMute).isFalse();
        assertThat(mMusicMute).isFalse();
@@ -289,9 +287,10 @@ public class HdmiCecLocalDeviceAudioSystemTest {
        assertThat(mMusicMute).isTrue();
        assertThat(mMusicMute).isTrue();
    }
    }


    @Ignore("b/80297700")
    @Test
    @Test
    public void onStandbyAudioSystem_currentSystemAudioControlOn() throws Exception {
    public void onStandbyAudioSystem_currentSystemAudioControlOn() throws Exception {
        mHdmiCecLocalDeviceAudioSystem.setAutoDeviceOff(false);
        mHdmiCecLocalDeviceAudioSystem.setAutoTvOff(false);
        // Set system audio control on first
        // Set system audio control on first
        mHdmiCecLocalDeviceAudioSystem.setSystemAudioMode(true);
        mHdmiCecLocalDeviceAudioSystem.setSystemAudioMode(true);
        // Check if standby correctly turns off the feature
        // Check if standby correctly turns off the feature
@@ -372,7 +371,6 @@ public class HdmiCecLocalDeviceAudioSystemTest {
        assertThat(mNativeWrapper.getResultMessages()).isEmpty();
        assertThat(mNativeWrapper.getResultMessages()).isEmpty();
    }
    }


    @Ignore("b/80297700")
    @Test
    @Test
    public void terminateSystemAudioMode_systemAudioModeOn() throws Exception {
    public void terminateSystemAudioMode_systemAudioModeOn() throws Exception {
        mHdmiCecLocalDeviceAudioSystem.setSystemAudioMode(true);
        mHdmiCecLocalDeviceAudioSystem.setSystemAudioMode(true);