Merge "[CEC Configuration] Return empty list of settings when no master XML present on a device"
This commit is contained in:
committed by
Android (Google) Code Review
commit
3217cc83cd
@@ -135,6 +135,12 @@ public class HdmiCecConfig {
|
|||||||
mStorageAdapter = storageAdapter;
|
mStorageAdapter = storageAdapter;
|
||||||
mProductConfig = productConfig;
|
mProductConfig = productConfig;
|
||||||
mVendorOverride = vendorOverride;
|
mVendorOverride = vendorOverride;
|
||||||
|
if (mProductConfig == null) {
|
||||||
|
Slog.i(TAG, "CEC master configuration XML missing.");
|
||||||
|
}
|
||||||
|
if (mVendorOverride == null) {
|
||||||
|
Slog.i(TAG, "CEC OEM configuration override XML missing.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HdmiCecConfig(@NonNull Context context) {
|
HdmiCecConfig(@NonNull Context context) {
|
||||||
@@ -164,6 +170,9 @@ public class HdmiCecConfig {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Setting getSetting(@NonNull String name) {
|
private Setting getSetting(@NonNull String name) {
|
||||||
|
if (mProductConfig == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (mVendorOverride != null) {
|
if (mVendorOverride != null) {
|
||||||
// First read from the vendor override.
|
// First read from the vendor override.
|
||||||
for (Setting setting : mVendorOverride.getSetting()) {
|
for (Setting setting : mVendorOverride.getSetting()) {
|
||||||
@@ -245,6 +254,9 @@ public class HdmiCecConfig {
|
|||||||
* Returns a list of all settings based on the XML metadata.
|
* Returns a list of all settings based on the XML metadata.
|
||||||
*/
|
*/
|
||||||
public @CecSettingName List<String> getAllSettings() {
|
public @CecSettingName List<String> getAllSettings() {
|
||||||
|
if (mProductConfig == null) {
|
||||||
|
return new ArrayList<String>();
|
||||||
|
}
|
||||||
List<String> allSettings = new ArrayList<String>();
|
List<String> allSettings = new ArrayList<String>();
|
||||||
for (Setting setting : mProductConfig.getSetting()) {
|
for (Setting setting : mProductConfig.getSetting()) {
|
||||||
allSettings.add(setting.getName());
|
allSettings.add(setting.getName());
|
||||||
@@ -256,6 +268,9 @@ public class HdmiCecConfig {
|
|||||||
* Returns a list of user-modifiable settings based on the XML metadata.
|
* Returns a list of user-modifiable settings based on the XML metadata.
|
||||||
*/
|
*/
|
||||||
public @CecSettingName List<String> getUserSettings() {
|
public @CecSettingName List<String> getUserSettings() {
|
||||||
|
if (mProductConfig == null) {
|
||||||
|
return new ArrayList<String>();
|
||||||
|
}
|
||||||
Set<String> userSettings = new HashSet<String>();
|
Set<String> userSettings = new HashSet<String>();
|
||||||
// First read from the product config.
|
// First read from the product config.
|
||||||
for (Setting setting : mProductConfig.getSetting()) {
|
for (Setting setting : mProductConfig.getSetting()) {
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ public final class HdmiCecConfigTest {
|
|||||||
mContext = InstrumentationRegistry.getTargetContext();
|
mContext = InstrumentationRegistry.getTargetContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllCecSettings_NoMasterXml() {
|
||||||
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(null, null);
|
||||||
|
assertThat(hdmiCecConfig.getAllSettings()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAllCecSettings_Empty() {
|
public void getAllCecSettings_Empty() {
|
||||||
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
||||||
@@ -100,6 +106,12 @@ public final class HdmiCecConfigTest {
|
|||||||
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP);
|
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getUserCecSettings_NoMasterXml() {
|
||||||
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(null, null);
|
||||||
|
assertThat(hdmiCecConfig.getUserSettings()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getUserCecSettings_Empty() {
|
public void getUserCecSettings_Empty() {
|
||||||
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
||||||
@@ -176,6 +188,13 @@ public final class HdmiCecConfigTest {
|
|||||||
.containsExactly(HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED);
|
.containsExactly(HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllowedValues_NoMasterXml() {
|
||||||
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(null, null);
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> hdmiCecConfig.getAllowedValues("foo"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAllowedValues_InvalidSetting() {
|
public void getAllowedValues_InvalidSetting() {
|
||||||
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
||||||
@@ -208,6 +227,13 @@ public final class HdmiCecConfigTest {
|
|||||||
HdmiControlManager.SEND_STANDBY_ON_SLEEP_NONE);
|
HdmiControlManager.SEND_STANDBY_ON_SLEEP_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDefaultValue_NoMasterXml() {
|
||||||
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(null, null);
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> hdmiCecConfig.getDefaultValue("foo"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDefaultValue_InvalidSetting() {
|
public void getDefaultValue_InvalidSetting() {
|
||||||
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
||||||
@@ -238,6 +264,13 @@ public final class HdmiCecConfigTest {
|
|||||||
.isEqualTo(HdmiControlManager.SEND_STANDBY_ON_SLEEP_TO_TV);
|
.isEqualTo(HdmiControlManager.SEND_STANDBY_ON_SLEEP_TO_TV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getValue_NoMasterXml() {
|
||||||
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(null, null);
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> hdmiCecConfig.getValue("foo"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getValue_InvalidSetting() {
|
public void getValue_InvalidSetting() {
|
||||||
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
||||||
@@ -298,6 +331,13 @@ public final class HdmiCecConfigTest {
|
|||||||
.STANDBY_NOW.name().toLowerCase());
|
.STANDBY_NOW.name().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setValue_NoMasterXml() {
|
||||||
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(null, null);
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> hdmiCecConfig.setValue("foo", "bar"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setValue_InvalidSetting() {
|
public void setValue_InvalidSetting() {
|
||||||
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
HdmiCecConfig hdmiCecConfig = createHdmiCecConfig(
|
||||||
@@ -400,7 +440,10 @@ public final class HdmiCecConfigTest {
|
|||||||
CecSettings productConfig = null;
|
CecSettings productConfig = null;
|
||||||
CecSettings vendorOverride = null;
|
CecSettings vendorOverride = null;
|
||||||
try {
|
try {
|
||||||
productConfig = XmlParser.read(new ByteArrayInputStream(productConfigXml.getBytes()));
|
if (productConfigXml != null) {
|
||||||
|
productConfig = XmlParser.read(
|
||||||
|
new ByteArrayInputStream(productConfigXml.getBytes()));
|
||||||
|
}
|
||||||
if (vendorOverrideXml != null) {
|
if (vendorOverrideXml != null) {
|
||||||
vendorOverride = XmlParser.read(
|
vendorOverride = XmlParser.read(
|
||||||
new ByteArrayInputStream(vendorOverrideXml.getBytes()));
|
new ByteArrayInputStream(vendorOverrideXml.getBytes()));
|
||||||
|
|||||||
Reference in New Issue
Block a user