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

Commit e57dead5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[CEC Configuration] Support hex values in the config XML"

parents b4377187 31be5dc8
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -282,6 +282,12 @@ public class HdmiCecConfig {
        }
    }

    private int getIntValue(@NonNull Value value) {
        return value.getHexValue() != null
               ? Integer.decode(value.getHexValue())
               : value.getIntValue();
    }

    /**
     * Returns a list of all settings based on the XML metadata.
     */
@@ -380,7 +386,7 @@ public class HdmiCecConfig {
        }
        List<Integer> allowedValues = new ArrayList<Integer>();
        for (Value allowedValue : setting.getAllowedValues().getValue()) {
            allowedValues.add(allowedValue.getIntValue());
            allowedValues.add(getIntValue(allowedValue));
        }
        return allowedValues;
    }
@@ -412,7 +418,7 @@ public class HdmiCecConfig {
            throw new IllegalArgumentException("Setting '" + name
                    + "' is not a string-type setting.");
        }
        return getSetting(name).getDefaultValue().getIntValue();
        return getIntValue(getSetting(name).getDefaultValue());
    }

    /**
@@ -444,7 +450,7 @@ public class HdmiCecConfig {
                    + "' is not a int-type setting.");
        }
        Slog.d(TAG, "Getting CEC setting value '" + name + "'.");
        String defaultValue = Integer.toString(setting.getDefaultValue().getIntValue());
        String defaultValue = Integer.toString(getIntValue(setting.getDefaultValue()));
        String value = retrieveValue(setting, defaultValue);
        return Integer.parseInt(value);
    }
+1 −0
Original line number Diff line number Diff line
@@ -25,5 +25,6 @@
  <xs:complexType name="value">
    <xs:attribute name="string-value" type="xs:string"/>
    <xs:attribute name="int-value" type="xs:int"/>
    <xs:attribute name="hex-value" type="xs:string"/>
  </xs:complexType>
</xs:schema>
+2 −0
Original line number Diff line number Diff line
@@ -22,8 +22,10 @@ package com.android.server.hdmi.cec.config {

  public class Value {
    ctor public Value();
    method public String getHexValue();
    method public int getIntValue();
    method public String getStringValue();
    method public void setHexValue(String);
    method public void setIntValue(int);
    method public void setStringValue(String);
  }
+91 −0
Original line number Diff line number Diff line
@@ -400,6 +400,28 @@ public final class HdmiCecConfigTest {
                                 HdmiControlManager.HDMI_CEC_CONTROL_ENABLED);
    }

    @Test
    public void getAllowedIntValues_HexValues() {
        HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
                mContext, mStorageAdapter,
                "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
                + "<cec-settings>"
                + "  <setting name=\"hdmi_cec_enabled\""
                + "           value-type=\"int\""
                + "           user-configurable=\"true\">"
                + "    <allowed-values>"
                + "      <value hex-value=\"0x00\" />"
                + "      <value hex-value=\"0x01\" />"
                + "    </allowed-values>"
                + "    <default-value hex-value=\"0x01\" />"
                + "  </setting>"
                + "</cec-settings>", null);
        assertThat(hdmiCecConfig.getAllowedIntValues(
                    HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED))
                .containsExactly(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED,
                                 HdmiControlManager.HDMI_CEC_CONTROL_ENABLED);
    }

    @Test
    public void getDefaultStringValue_NoMasterXml() {
        HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
@@ -524,6 +546,27 @@ public final class HdmiCecConfigTest {
                .isEqualTo(HdmiControlManager.HDMI_CEC_CONTROL_ENABLED);
    }

    @Test
    public void getDefaultIntValue_HexValue() {
        HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
                mContext, mStorageAdapter,
                "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
                + "<cec-settings>"
                + "  <setting name=\"hdmi_cec_enabled\""
                + "           value-type=\"int\""
                + "           user-configurable=\"true\">"
                + "    <allowed-values>"
                + "      <value hex-value=\"0x00\" />"
                + "      <value hex-value=\"0x01\" />"
                + "    </allowed-values>"
                + "    <default-value hex-value=\"0x01\" />"
                + "  </setting>"
                + "</cec-settings>", null);
        assertThat(hdmiCecConfig.getDefaultIntValue(
                    HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED))
                .isEqualTo(HdmiControlManager.HDMI_CEC_CONTROL_ENABLED);
    }

    @Test
    public void getStringValue_NoMasterXml() {
        HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
@@ -684,6 +727,31 @@ public final class HdmiCecConfigTest {
                .isEqualTo(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED);
    }

    @Test
    public void getIntValue_GlobalSetting_HexValue() {
        when(mStorageAdapter.retrieveGlobalSetting(mContext,
                  Global.HDMI_CONTROL_ENABLED,
                  Integer.toHexString(HdmiControlManager.HDMI_CEC_CONTROL_ENABLED)))
            .thenReturn(Integer.toString(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED));
        HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
                mContext, mStorageAdapter,
                "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
                + "<cec-settings>"
                + "  <setting name=\"hdmi_cec_enabled\""
                + "           value-type=\"int\""
                + "           user-configurable=\"true\">"
                + "    <allowed-values>"
                + "      <value hex-value=\"0x0\" />"
                + "      <value hex-value=\"0x1\" />"
                + "    </allowed-values>"
                + "    <default-value hex-value=\"0x1\" />"
                + "  </setting>"
                + "</cec-settings>", null);
        assertThat(hdmiCecConfig.getIntValue(
                    HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED))
                .isEqualTo(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED);
    }

    @Test
    public void getIntValue_SystemProperty_BasicSanity() {
        when(mStorageAdapter.retrieveSystemProperty(
@@ -910,6 +978,29 @@ public final class HdmiCecConfigTest {
                  Integer.toString(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED));
    }

    @Test
    public void setIntValue_GlobalSetting_HexValue() {
        HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
                mContext, mStorageAdapter,
                "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
                + "<cec-settings>"
                + "  <setting name=\"hdmi_cec_enabled\""
                + "           value-type=\"int\""
                + "           user-configurable=\"true\">"
                + "    <allowed-values>"
                + "      <value hex-value=\"0x0\" />"
                + "      <value hex-value=\"0x1\" />"
                + "    </allowed-values>"
                + "    <default-value hex-value=\"0x1\" />"
                + "  </setting>"
                + "</cec-settings>", null);
        hdmiCecConfig.setIntValue(HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
                                  HdmiControlManager.HDMI_CEC_CONTROL_DISABLED);
        verify(mStorageAdapter).storeGlobalSetting(mContext,
                  Global.HDMI_CONTROL_ENABLED,
                  Integer.toString(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED));
    }

    @Test
    public void setIntValue_SystemProperty_BasicSanity() {
        HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(