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

Commit 0ef6062e authored by Marvin Ramin's avatar Marvin Ramin
Browse files

Add Setting for HDMI CEC 2.0

Introduce Settings.Global.hdmi_cec_version. Stores an integer value
based on the CEC version constants defined in the HDMI-CEC
specification.

Defaults to v1.4b.

Bug: 166227067
Test: atest HdmiControlServiceTest
Change-Id: If3d85991230c00af4482076d90bf9a730ab385ae
parent 69bca6a5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -9896,6 +9896,13 @@ public final class Settings {
        public static final String HDMI_CEC_SWITCH_ENABLED =
                "hdmi_cec_switch_enabled";
        /**
         * HDMI CEC version to use. Defaults to v1.4b.
         * @hide
         */
        public static final String HDMI_CEC_VERSION =
                "hdmi_cec_version";
        /**
         * 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
@@ -293,6 +293,7 @@ public class SettingsBackupTest {
                    Settings.Global.GNSS_SATELLITE_BLACKLIST,
                    Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS,
                    Settings.Global.HDMI_CEC_SWITCH_ENABLED,
                    Settings.Global.HDMI_CEC_VERSION,
                    Settings.Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
                    Settings.Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED,
                    Settings.Global.HDMI_CONTROL_ENABLED,
+9 −0
Original line number Diff line number Diff line
@@ -492,6 +492,15 @@ final class Constants {
    static final int DISABLED = 0;
    static final int ENABLED = 1;

    @IntDef({
            VERSION_1_4,
            VERSION_2_0
    })
    @interface CecVersion {}
    static final int VERSION_1_3 = 0x04;
    static final int VERSION_1_4 = 0x05;
    static final int VERSION_2_0 = 0x06;

    private Constants() {
        /* cannot be instantiated */
    }
+20 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static com.android.server.hdmi.Constants.OPTION_MHL_ENABLE;
import static com.android.server.hdmi.Constants.OPTION_MHL_INPUT_SWITCHING;
import static com.android.server.hdmi.Constants.OPTION_MHL_POWER_CHARGE;
import static com.android.server.hdmi.Constants.OPTION_MHL_SERVICE_CONTROL;
import static com.android.server.hdmi.Constants.VERSION_1_4;
import static com.android.server.power.ShutdownThread.SHUTDOWN_ACTION_PROPERTY;

import android.annotation.Nullable;
@@ -79,6 +80,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.SystemService;
import com.android.server.hdmi.Constants.CecVersion;
import com.android.server.hdmi.HdmiAnnotations.ServiceThreadOnly;
import com.android.server.hdmi.HdmiCecController.AllocateAddressCallback;
import com.android.server.hdmi.HdmiCecLocalDevice.ActiveSource;
@@ -373,6 +375,9 @@ public class HdmiControlService extends SystemService {
    @Nullable
    private Looper mIoLooper;

    @CecVersion
    private int mCecVersion = Constants.VERSION_1_4;

    // Last input port before switching to the MHL port. Should switch back to this port
    // when the mobile device sends the request one touch play with off.
    // Gets invalidated if we go to other port/input.
@@ -660,6 +665,7 @@ public class HdmiControlService extends SystemService {
        String[] settings = new String[] {
                Global.HDMI_CONTROL_ENABLED,
                Global.HDMI_CONTROL_VOLUME_CONTROL_ENABLED,
                Global.HDMI_CEC_VERSION,
                Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED,
                Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
                Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED,
@@ -688,6 +694,9 @@ public class HdmiControlService extends SystemService {
                case Global.HDMI_CONTROL_ENABLED:
                    setControlEnabled(enabled);
                    break;
                case Global.HDMI_CEC_VERSION:
                    initializeCec(INITIATED_BY_ENABLE_CEC);
                    break;
                case Global.HDMI_CONTROL_VOLUME_CONTROL_ENABLED:
                    setHdmiCecVolumeControlEnabledInternal(enabled);
                    break;
@@ -753,6 +762,12 @@ public class HdmiControlService extends SystemService {
        return Global.getInt(cr, key, toInt(defVal)) == ENABLED;
    }

    @VisibleForTesting
    int readIntSetting(String key, int defVal) {
        ContentResolver cr = getContext().getContentResolver();
        return Global.getInt(cr, key, defVal);
    }

    void writeBooleanSetting(String key, boolean value) {
        ContentResolver cr = getContext().getContentResolver();
        Global.putInt(cr, key, toInt(value));
@@ -783,6 +798,8 @@ public class HdmiControlService extends SystemService {

    private void initializeCec(int initiatedBy) {
        mAddressAllocated = false;
        mCecVersion = readIntSetting(Global.HDMI_CEC_VERSION, VERSION_1_4);

        mCecController.setOption(OptionKey.SYSTEM_CEC_CONTROL, true);
        mCecController.setLanguage(mMenuLanguage);
        initializeLocalDevices(initiatedBy);
@@ -989,8 +1006,9 @@ public class HdmiControlService extends SystemService {
    /**
     * Returns version of CEC.
     */
    @CecVersion
    int getCecVersion() {
        return mCecController.getVersion();
        return mCecVersion;
    }

    /**
@@ -2204,6 +2222,7 @@ public class HdmiControlService extends SystemService {
            if (!DumpUtils.checkDumpPermission(getContext(), TAG, writer)) return;
            final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");

            pw.println("mCecVersion: " + mCecVersion);
            pw.println("mProhibitMode: " + mProhibitMode);
            pw.println("mPowerStatus: " + mPowerStatus);

+35 −0
Original line number Diff line number Diff line
@@ -383,6 +383,41 @@ public class HdmiControlServiceTest {
    }


    @Test
    public void getCecVersion_default() {
        assertThat(mHdmiControlService.getCecVersion()).isEqualTo(Constants.VERSION_1_4);
    }

    @Test
    public void getCecVersion_1_4() {
        Settings.Global.putInt(mContextSpy.getContentResolver(), Settings.Global.HDMI_CEC_VERSION,
                Constants.VERSION_1_4);
        mHdmiControlService.setControlEnabled(true);
        assertThat(mHdmiControlService.getCecVersion()).isEqualTo(Constants.VERSION_1_4);
    }

    @Test
    public void getCecVersion_2_0() {
        Settings.Global.putInt(mContextSpy.getContentResolver(), Settings.Global.HDMI_CEC_VERSION,
                Constants.VERSION_2_0);
        mHdmiControlService.setControlEnabled(true);
        assertThat(mHdmiControlService.getCecVersion()).isEqualTo(Constants.VERSION_2_0);
    }

    @Test
    public void getCecVersion_change() {
        Settings.Global.putInt(mContextSpy.getContentResolver(), Settings.Global.HDMI_CEC_VERSION,
                Constants.VERSION_1_4);
        mHdmiControlService.setControlEnabled(true);
        assertThat(mHdmiControlService.getCecVersion()).isEqualTo(Constants.VERSION_1_4);

        Settings.Global.putInt(mContextSpy.getContentResolver(), Settings.Global.HDMI_CEC_VERSION,
                Constants.VERSION_2_0);
        mHdmiControlService.setControlEnabled(true);
        assertThat(mHdmiControlService.getCecVersion()).isEqualTo(Constants.VERSION_2_0);
    }


    private static class VolumeControlFeatureCallback extends
            IHdmiCecVolumeControlFeatureListener.Stub {
        boolean mCallbackReceived = false;