diff options
| author | 2020-11-05 12:39:24 +0100 | |
|---|---|---|
| committer | 2020-11-05 14:33:25 +0100 | |
| commit | 31be5dc8fc8d8162f7caed85fcf3663c0efee53d (patch) | |
| tree | 0f45d9ba6e184e601896710e0b02525bc3a70ac3 | |
| parent | d0fb8ca8aa475058e467ef21567a11fb9d74a76f (diff) | |
[CEC Configuration] Support hex values in the config XML
Bug: 166426337
Test: atest HdmiCecConfigTest
Change-Id: I9774e52ce988550b58514253bf14fccdcb562db1
4 files changed, 103 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecConfig.java b/services/core/java/com/android/server/hdmi/HdmiCecConfig.java index 90d31f2d7368..a4564a9e0bbe 100644 --- a/services/core/java/com/android/server/hdmi/HdmiCecConfig.java +++ b/services/core/java/com/android/server/hdmi/HdmiCecConfig.java @@ -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); } diff --git a/services/core/xsd/cec-config/cec-config.xsd b/services/core/xsd/cec-config/cec-config.xsd index ca02f70e9675..2129044bebcb 100644 --- a/services/core/xsd/cec-config/cec-config.xsd +++ b/services/core/xsd/cec-config/cec-config.xsd @@ -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> diff --git a/services/core/xsd/cec-config/schema/current.txt b/services/core/xsd/cec-config/schema/current.txt index 00dd15ba28f9..896ddfcdb40d 100644 --- a/services/core/xsd/cec-config/schema/current.txt +++ b/services/core/xsd/cec-config/schema/current.txt @@ -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); } diff --git a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecConfigTest.java b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecConfigTest.java index a92357f9150b..046bba3e0fc5 100644 --- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecConfigTest.java +++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecConfigTest.java @@ -401,6 +401,28 @@ public final class HdmiCecConfigTest { } @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( mContext, mStorageAdapter, null, null); @@ -525,6 +547,27 @@ public final class HdmiCecConfigTest { } @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( mContext, mStorageAdapter, null, null); @@ -685,6 +728,31 @@ public final class HdmiCecConfigTest { } @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( HdmiCecConfig.SYSPROP_SYSTEM_AUDIO_MODE_MUTING, @@ -911,6 +979,29 @@ public final class HdmiCecConfigTest { } @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( mContext, mStorageAdapter, |