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

This commit is contained in:
TreeHugger Robot
2020-11-05 17:21:49 +00:00
committed by Android (Google) Code Review
4 changed files with 103 additions and 3 deletions

View File

@@ -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. * Returns a list of all settings based on the XML metadata.
*/ */
@@ -380,7 +386,7 @@ public class HdmiCecConfig {
} }
List<Integer> allowedValues = new ArrayList<Integer>(); List<Integer> allowedValues = new ArrayList<Integer>();
for (Value allowedValue : setting.getAllowedValues().getValue()) { for (Value allowedValue : setting.getAllowedValues().getValue()) {
allowedValues.add(allowedValue.getIntValue()); allowedValues.add(getIntValue(allowedValue));
} }
return allowedValues; return allowedValues;
} }
@@ -412,7 +418,7 @@ public class HdmiCecConfig {
throw new IllegalArgumentException("Setting '" + name throw new IllegalArgumentException("Setting '" + name
+ "' is not a string-type setting."); + "' 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."); + "' is not a int-type setting.");
} }
Slog.d(TAG, "Getting CEC setting value '" + name + "'."); 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); String value = retrieveValue(setting, defaultValue);
return Integer.parseInt(value); return Integer.parseInt(value);
} }

View File

@@ -25,5 +25,6 @@
<xs:complexType name="value"> <xs:complexType name="value">
<xs:attribute name="string-value" type="xs:string"/> <xs:attribute name="string-value" type="xs:string"/>
<xs:attribute name="int-value" type="xs:int"/> <xs:attribute name="int-value" type="xs:int"/>
<xs:attribute name="hex-value" type="xs:string"/>
</xs:complexType> </xs:complexType>
</xs:schema> </xs:schema>

View File

@@ -22,8 +22,10 @@ package com.android.server.hdmi.cec.config {
public class Value { public class Value {
ctor public Value(); ctor public Value();
method public String getHexValue();
method public int getIntValue(); method public int getIntValue();
method public String getStringValue(); method public String getStringValue();
method public void setHexValue(String);
method public void setIntValue(int); method public void setIntValue(int);
method public void setStringValue(String); method public void setStringValue(String);
} }

View File

@@ -400,6 +400,28 @@ public final class HdmiCecConfigTest {
HdmiControlManager.HDMI_CEC_CONTROL_ENABLED); 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 @Test
public void getDefaultStringValue_NoMasterXml() { public void getDefaultStringValue_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings( HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
@@ -524,6 +546,27 @@ public final class HdmiCecConfigTest {
.isEqualTo(HdmiControlManager.HDMI_CEC_CONTROL_ENABLED); .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 @Test
public void getStringValue_NoMasterXml() { public void getStringValue_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings( HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
@@ -684,6 +727,31 @@ public final class HdmiCecConfigTest {
.isEqualTo(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED); .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 @Test
public void getIntValue_SystemProperty_BasicSanity() { public void getIntValue_SystemProperty_BasicSanity() {
when(mStorageAdapter.retrieveSystemProperty( when(mStorageAdapter.retrieveSystemProperty(
@@ -910,6 +978,29 @@ public final class HdmiCecConfigTest {
Integer.toString(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED)); 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 @Test
public void setIntValue_SystemProperty_BasicSanity() { public void setIntValue_SystemProperty_BasicSanity() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings( HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(