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

Commit 0c2e29fa authored by Amy's avatar Amy Committed by shubang
Browse files

Adding HDMI_CEC_SWITCH_ENABLE Global property to enable/disable Routing

Control feature.

ag/5338671

Test: local tested
Bug: 118276878
Change-Id: I97f9716717129235116dd70afd8a7055511e4268
parent 420df88b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -9360,6 +9360,15 @@ public final class Settings {
        public static final String HDMI_SYSTEM_AUDIO_CONTROL_ENABLED =
                "hdmi_system_audio_control_enabled";
        /**
         * Whether HDMI Routing Control feature is enabled. If enabled, the switch device will
         * route to the correct input source on receiving Routing Control related messages. If
         * disabled, you can only switch the input via controls on this device.
         * @hide
         */
        public static final String HDMI_CEC_SWITCH_ENABLED =
                "hdmi_cec_switch_enabled";
        /**
         * Whether TV will automatically turn on upon reception of the CEC command
         * <Text View On> or <Image View On>. (0 = false, 1 = true)
+1 −0
Original line number Diff line number Diff line
@@ -270,6 +270,7 @@ public class SettingsBackupTest {
                    Settings.Global.GNSS_HAL_LOCATION_REQUEST_DURATION_MILLIS,
                    Settings.Global.GNSS_SATELLITE_BLACKLIST,
                    Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS,
                    Settings.Global.HDMI_CEC_SWITCH_ENABLED,
                    Settings.Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
                    Settings.Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED,
                    Settings.Global.HDMI_CONTROL_ENABLED,
+15 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.tv.TvContract;
import android.os.SystemProperties;
import android.provider.Settings.Global;
import android.util.Slog;
import android.util.SparseArray;

@@ -92,6 +93,8 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
        // TODO(amyjojo) make System Audio Control controllable by users
        /*mSystemAudioControlFeatureEnabled =
        mService.readBooleanSetting(Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED, true);*/
        mRoutingControlFeatureEnabled =
            mService.readBooleanSetting(Global.HDMI_CEC_SWITCH_ENABLED, true);
        // TODO(amyjojo): make the map ro property.
        mTvInputs.put(Constants.CEC_SWITCH_HDMI1,
                "com.droidlogic.tvinput/.services.Hdmi1InputService/HW5");
@@ -781,6 +784,14 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
        }
    }

    @ServiceThreadOnly
    void setRoutingControlFeatureEnables(boolean enabled) {
        assertRunOnServiceThread();
        synchronized (mLock) {
            mRoutingControlFeatureEnabled = enabled;
        }
    }

    @ServiceThreadOnly
    void doManualPortSwitching(int portId, IHdmiControlCallback callback) {
        assertRunOnServiceThread();
@@ -916,6 +927,10 @@ public class HdmiCecLocalDeviceAudioSystem extends HdmiCecLocalDeviceSource {
    }

    protected void routeToInputFromPortId(int portId) {
        if (!isRoutingControlFeatureEnabled()) {
            HdmiLogger.debug("Routing Control Feature is not enabled.");
            return;
        }
        if (mArcIntentUsed) {
            routeToTvInputFromPortId(portId);
        } else {
+21 −1
Original line number Diff line number Diff line
@@ -66,6 +66,10 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
    @LocalActivePort
    protected int mLocalActivePort = Constants.CEC_SWITCH_HOME;

    // Whether the Routing Coutrol feature is enabled or not. True by default.
    @GuardedBy("mLock")
    protected boolean mRoutingControlFeatureEnabled;

    protected HdmiCecLocalDeviceSource(HdmiControlService service, int deviceType) {
        super(service, deviceType);
    }
@@ -123,7 +127,9 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
        }
        setIsActiveSource(physicalAddress == mService.getPhysicalAddress());
        updateDevicePowerStatus(logicalAddress, HdmiControlManager.POWER_STATUS_ON);
        if (isRoutingControlFeatureEnabled()) {
            switchInputOnReceivingNewActivePath(physicalAddress);
        }
        return true;
    }

@@ -153,6 +159,10 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
    @ServiceThreadOnly
    protected boolean handleRoutingChange(HdmiCecMessage message) {
        assertRunOnServiceThread();
        if (!isRoutingControlFeatureEnabled()) {
            mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED);
            return true;
        }
        int newPath = HdmiUtils.twoBytesToInt(message.getParams(), 2);
        // if the current device is a pure playback device
        if (!mIsSwitchDevice
@@ -168,6 +178,10 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
    @ServiceThreadOnly
    protected boolean handleRoutingInformation(HdmiCecMessage message) {
        assertRunOnServiceThread();
        if (!isRoutingControlFeatureEnabled()) {
            mService.maySendFeatureAbortCommand(message, Constants.ABORT_REFUSED);
            return true;
        }
        int physicalAddress = HdmiUtils.twoBytesToInt(message.getParams());
        // if the current device is a pure playback device
        if (!mIsSwitchDevice
@@ -279,6 +293,12 @@ abstract class HdmiCecLocalDeviceSource extends HdmiCecLocalDevice {
        }
    }

    boolean isRoutingControlFeatureEnabled() {
        synchronized (mLock) {
            return mRoutingControlFeatureEnabled;
        }
    }

    // Check if the device is trying to switch to the same input that is active right now.
    // This can help avoid redundant port switching.
    protected boolean isSwitchingToTheSameInput(@LocalActivePort int activePort) {
+7 −1
Original line number Diff line number Diff line
@@ -568,7 +568,8 @@ public class HdmiControlService extends SystemService {
                Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
                Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED,
                Global.MHL_INPUT_SWITCHING_ENABLED,
                Global.MHL_POWER_CHARGE_ENABLED
                Global.MHL_POWER_CHARGE_ENABLED,
                Global.HDMI_CEC_SWITCH_ENABLED
        };
        for (String s : settings) {
            resolver.registerContentObserver(Global.getUriFor(s), false, mSettingsObserver,
@@ -610,6 +611,11 @@ public class HdmiControlService extends SystemService {
                        tv().setSystemAudioControlFeatureEnabled(enabled);
                    }
                    break;
                case Global.HDMI_CEC_SWITCH_ENABLED:
                    if (isAudioSystemDevice()) {
                        audioSystem().setRoutingControlFeatureEnables(enabled);
                    }
                    break;
                case Global.MHL_INPUT_SWITCHING_ENABLED:
                    setMhlInputChangeEnabled(enabled);
                    break;