Merge "[CEC Configuration] Introduce 'int' type to the API"

This commit is contained in:
TreeHugger Robot
2020-11-04 18:27:36 +00:00
committed by Android (Google) Code Review
9 changed files with 835 additions and 104 deletions

View File

@@ -42,9 +42,11 @@ import com.android.internal.util.ConcurrentUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
/**
* The {@link HdmiControlManager} class is used to send HDMI control messages
@@ -325,17 +327,17 @@ public final class HdmiControlManager {
*
* @hide
*/
public static final String HDMI_CEC_CONTROL_ENABLED = "1";
public static final int HDMI_CEC_CONTROL_ENABLED = 1;
/**
* HDMI CEC disabled.
*
* @hide
*/
public static final String HDMI_CEC_CONTROL_DISABLED = "0";
public static final int HDMI_CEC_CONTROL_DISABLED = 0;
/**
* @hide
*/
@StringDef({
@IntDef({
HDMI_CEC_CONTROL_ENABLED,
HDMI_CEC_CONTROL_DISABLED
})
@@ -401,17 +403,17 @@ public final class HdmiControlManager {
*
* @hide
*/
public static final String SYSTEM_AUDIO_MODE_MUTING_ENABLED = "1";
public static final int SYSTEM_AUDIO_MODE_MUTING_ENABLED = 1;
/**
* System Audio Mode muting disabled.
*
* @hide
*/
public static final String SYSTEM_AUDIO_MODE_MUTING_DISABLED = "0";
public static final int SYSTEM_AUDIO_MODE_MUTING_DISABLED = 0;
/**
* @hide
*/
@StringDef({
@IntDef({
SYSTEM_AUDIO_MODE_MUTING_ENABLED,
SYSTEM_AUDIO_MODE_MUTING_DISABLED
})
@@ -1317,24 +1319,51 @@ public final class HdmiControlManager {
}
/**
* Get a set of allowed values for a settings.
* Get a set of allowed values for a setting (string value-type).
*
* @param name name of the setting
* @return a set of allowed values for a settings. {@code null} on failure.
* @throws IllegalArgumentException when setting {@code name} does not exist.
* @throws IllegalArgumentException when setting {@code name} value type is invalid.
* @throws RuntimeException when the HdmiControlService is not available.
*
* @hide
*/
@NonNull
@RequiresPermission(android.Manifest.permission.HDMI_CEC)
public List<String> getAllowedCecSettingValues(@NonNull @CecSettingName String name) {
public List<String> getAllowedCecSettingStringValues(@NonNull @CecSettingName String name) {
if (mService == null) {
Log.e(TAG, "HdmiControlService is not available");
throw new RuntimeException("HdmiControlService is not available");
}
try {
return mService.getAllowedCecSettingValues(name);
return mService.getAllowedCecSettingStringValues(name);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Get a set of allowed values for a setting (int value-type).
*
* @param name name of the setting
* @return a set of allowed values for a settings. {@code null} on failure.
* @throws IllegalArgumentException when setting {@code name} does not exist.
* @throws IllegalArgumentException when setting {@code name} value type is invalid.
* @throws RuntimeException when the HdmiControlService is not available.
*
* @hide
*/
@NonNull
@RequiresPermission(android.Manifest.permission.HDMI_CEC)
public List<Integer> getAllowedCecSettingIntValues(@NonNull @CecSettingName String name) {
if (mService == null) {
Log.e(TAG, "HdmiControlService is not available");
throw new RuntimeException("HdmiControlService is not available");
}
try {
int[] allowedValues = mService.getAllowedCecSettingIntValues(name);
return Arrays.stream(allowedValues).boxed().collect(Collectors.toList());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1350,13 +1379,13 @@ public final class HdmiControlManager {
* @hide
*/
@RequiresPermission(android.Manifest.permission.HDMI_CEC)
public void setHdmiCecEnabled(@NonNull @HdmiCecControl String value) {
public void setHdmiCecEnabled(@NonNull @HdmiCecControl int value) {
if (mService == null) {
Log.e(TAG, "HdmiControlService is not available");
throw new RuntimeException("HdmiControlService is not available");
}
try {
mService.setCecSettingValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED, value);
mService.setCecSettingIntValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED, value);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1373,13 +1402,13 @@ public final class HdmiControlManager {
@NonNull
@HdmiCecControl
@RequiresPermission(android.Manifest.permission.HDMI_CEC)
public String getHdmiCecEnabled() {
public int getHdmiCecEnabled() {
if (mService == null) {
Log.e(TAG, "HdmiControlService is not available");
throw new RuntimeException("HdmiControlService is not available");
}
try {
return mService.getCecSettingValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED);
return mService.getCecSettingIntValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1401,7 +1430,7 @@ public final class HdmiControlManager {
throw new RuntimeException("HdmiControlService is not available");
}
try {
mService.setCecSettingValue(CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP, value);
mService.setCecSettingStringValue(CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP, value);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1424,7 +1453,7 @@ public final class HdmiControlManager {
throw new RuntimeException("HdmiControlService is not available");
}
try {
return mService.getCecSettingValue(CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP);
return mService.getCecSettingStringValue(CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1447,7 +1476,7 @@ public final class HdmiControlManager {
throw new RuntimeException("HdmiControlService is not available");
}
try {
mService.setCecSettingValue(
mService.setCecSettingStringValue(
CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST, value);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -1471,7 +1500,7 @@ public final class HdmiControlManager {
throw new RuntimeException("HdmiControlService is not available");
}
try {
return mService.getCecSettingValue(
return mService.getCecSettingStringValue(
CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
@@ -1488,13 +1517,13 @@ public final class HdmiControlManager {
* @hide
*/
@RequiresPermission(android.Manifest.permission.HDMI_CEC)
public void setSystemAudioModeMuting(@NonNull @SystemAudioModeMuting String value) {
public void setSystemAudioModeMuting(@NonNull @SystemAudioModeMuting int value) {
if (mService == null) {
Log.e(TAG, "HdmiControlService is not available");
throw new RuntimeException("HdmiControlService is not available");
}
try {
mService.setCecSettingValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING, value);
mService.setCecSettingIntValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING, value);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -1511,13 +1540,13 @@ public final class HdmiControlManager {
@NonNull
@SystemAudioModeMuting
@RequiresPermission(android.Manifest.permission.HDMI_CEC)
public String getSystemAudioModeMuting() {
public int getSystemAudioModeMuting() {
if (mService == null) {
Log.e(TAG, "HdmiControlService is not available");
throw new RuntimeException("HdmiControlService is not available");
}
try {
return mService.getCecSettingValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING);
return mService.getCecSettingIntValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}

View File

@@ -301,18 +301,33 @@ public final class HdmiControlServiceWrapper {
}
@Override
public List<String> getAllowedCecSettingValues(String name) {
return HdmiControlServiceWrapper.this.getAllowedCecSettingValues(name);
public List<String> getAllowedCecSettingStringValues(String name) {
return HdmiControlServiceWrapper.this.getAllowedCecSettingStringValues(name);
}
@Override
public String getCecSettingValue(String name) {
return HdmiControlServiceWrapper.this.getCecSettingValue(name);
public int[] getAllowedCecSettingIntValues(String name) {
return HdmiControlServiceWrapper.this.getAllowedCecSettingIntValues(name);
}
@Override
public void setCecSettingValue(String name, String value) {
HdmiControlServiceWrapper.this.setCecSettingValue(name, value);
public String getCecSettingStringValue(String name) {
return HdmiControlServiceWrapper.this.getCecSettingStringValue(name);
}
@Override
public void setCecSettingStringValue(String name, String value) {
HdmiControlServiceWrapper.this.setCecSettingStringValue(name, value);
}
@Override
public int getCecSettingIntValue(String name) {
return HdmiControlServiceWrapper.this.getCecSettingIntValue(name);
}
@Override
public void setCecSettingIntValue(String name, int value) {
HdmiControlServiceWrapper.this.setCecSettingIntValue(name, value);
}
};
@@ -494,15 +509,30 @@ public final class HdmiControlServiceWrapper {
}
/** @hide */
public List<String> getAllowedCecSettingValues(String name) {
public List<String> getAllowedCecSettingStringValues(String name) {
return new ArrayList<>();
}
/** @hide */
public String getCecSettingValue(String name) {
public int[] getAllowedCecSettingIntValues(String name) {
return new int[0];
}
/** @hide */
public String getCecSettingStringValue(String name) {
return "";
}
/** @hide */
public void setCecSettingValue(String name, String value) {}
public void setCecSettingStringValue(String name, String value) {
}
/** @hide */
public int getCecSettingIntValue(String name) {
return 0;
}
/** @hide */
public void setCecSettingIntValue(String name, int value) {
}
}

View File

@@ -88,7 +88,10 @@ interface IHdmiControlService {
void reportAudioStatus(int deviceType, int volume, int maxVolume, boolean isMute);
void setSystemAudioModeOnForAudioOnlySource();
List<String> getUserCecSettings();
List<String> getAllowedCecSettingValues(String name);
String getCecSettingValue(String name);
void setCecSettingValue(String name, String value);
List<String> getAllowedCecSettingStringValues(String name);
int[] getAllowedCecSettingIntValues(String name);
String getCecSettingStringValue(String name);
void setCecSettingStringValue(String name, String value);
int getCecSettingIntValue(String name);
void setCecSettingIntValue(String name, int value);
}

View File

@@ -381,17 +381,31 @@ public class HdmiAudioSystemClientTest {
}
@Override
public List<String> getAllowedCecSettingValues(String name) {
public List<String> getAllowedCecSettingStringValues(String name) {
return new ArrayList<>();
}
@Override
public String getCecSettingValue(String name) {
public int[] getAllowedCecSettingIntValues(String name) {
return new int[0];
}
@Override
public String getCecSettingStringValue(String name) {
return "";
}
@Override
public void setCecSettingValue(String name, String value) {
public void setCecSettingStringValue(String name, String value) {
}
@Override
public int getCecSettingIntValue(String name) {
return 0;
}
@Override
public void setCecSettingIntValue(String name, int value) {
}
}

View File

@@ -21,6 +21,7 @@ import static android.hardware.hdmi.HdmiControlManager.CecSettingName;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.content.Context;
import android.hardware.hdmi.HdmiControlManager;
import android.os.Environment;
@@ -68,6 +69,15 @@ public class HdmiCecConfig {
private static final int STORAGE_SYSPROPS = 0;
private static final int STORAGE_GLOBAL_SETTINGS = 1;
private static final String VALUE_TYPE_STRING = "string";
private static final String VALUE_TYPE_INT = "int";
@StringDef({
VALUE_TYPE_STRING,
VALUE_TYPE_INT,
})
private @interface ValueType {}
/**
* System property key for Power State Change on Active Source Lost.
*/
@@ -247,17 +257,15 @@ public class HdmiCecConfig {
}
}
private String retrieveValue(@NonNull Setting setting) {
private String retrieveValue(@NonNull Setting setting, @NonNull String defaultValue) {
@Storage int storage = getStorage(setting);
String storageKey = getStorageKey(setting);
if (storage == STORAGE_SYSPROPS) {
Slog.d(TAG, "Reading '" + storageKey + "' sysprop.");
return mStorageAdapter.retrieveSystemProperty(storageKey,
setting.getDefaultValue().getStringValue());
return mStorageAdapter.retrieveSystemProperty(storageKey, defaultValue);
} else if (storage == STORAGE_GLOBAL_SETTINGS) {
Slog.d(TAG, "Reading '" + storageKey + "' global setting.");
return mStorageAdapter.retrieveGlobalSetting(mContext, storageKey,
setting.getDefaultValue().getStringValue());
return mStorageAdapter.retrieveGlobalSetting(mContext, storageKey, defaultValue);
}
return null;
}
@@ -316,13 +324,41 @@ public class HdmiCecConfig {
}
/**
* For a given setting name returns values that are allowed for that setting.
* For a given setting name returns true if and only if the value type of that
* setting is a string.
*/
public List<String> getAllowedValues(@NonNull @CecSettingName String name) {
public boolean isStringValueType(@NonNull @CecSettingName String name) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
return getSetting(name).getValueType().equals(VALUE_TYPE_STRING);
}
/**
* For a given setting name returns true if and only if the value type of that
* setting is an int.
*/
public boolean isIntValueType(@NonNull @CecSettingName String name) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
return getSetting(name).getValueType().equals(VALUE_TYPE_INT);
}
/**
* For a given setting name returns values that are allowed for that setting (string).
*/
public List<String> getAllowedStringValues(@NonNull @CecSettingName String name) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
if (!setting.getValueType().equals(VALUE_TYPE_STRING)) {
throw new IllegalArgumentException("Setting '" + name
+ "' is not a string-type setting.");
}
List<String> allowedValues = new ArrayList<String>();
for (Value allowedValue : setting.getAllowedValues().getValue()) {
allowedValues.add(allowedValue.getStringValue());
@@ -331,32 +367,92 @@ public class HdmiCecConfig {
}
/**
* For a given setting name returns the default value for that setting.
* For a given setting name returns values that are allowed for that setting (string).
*/
public String getDefaultValue(@NonNull @CecSettingName String name) {
public List<Integer> getAllowedIntValues(@NonNull @CecSettingName String name) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
if (!setting.getValueType().equals(VALUE_TYPE_INT)) {
throw new IllegalArgumentException("Setting '" + name
+ "' is not a string-type setting.");
}
List<Integer> allowedValues = new ArrayList<Integer>();
for (Value allowedValue : setting.getAllowedValues().getValue()) {
allowedValues.add(allowedValue.getIntValue());
}
return allowedValues;
}
/**
* For a given setting name returns the default value for that setting (string).
*/
public String getDefaultStringValue(@NonNull @CecSettingName String name) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
if (!setting.getValueType().equals(VALUE_TYPE_STRING)) {
throw new IllegalArgumentException("Setting '" + name
+ "' is not a string-type setting.");
}
return getSetting(name).getDefaultValue().getStringValue();
}
/**
* For a given setting name returns the current value of that setting.
* For a given setting name returns the default value for that setting (int).
*/
public String getValue(@NonNull @CecSettingName String name) {
public int getDefaultIntValue(@NonNull @CecSettingName String name) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
Slog.d(TAG, "Getting CEC setting value '" + name + "'.");
return retrieveValue(setting);
if (!setting.getValueType().equals(VALUE_TYPE_INT)) {
throw new IllegalArgumentException("Setting '" + name
+ "' is not a string-type setting.");
}
return getSetting(name).getDefaultValue().getIntValue();
}
/**
* For a given setting name and value sets the current value of that setting.
* For a given setting name returns the current value of that setting (string).
*/
public void setValue(@NonNull @CecSettingName String name, @NonNull String value) {
public String getStringValue(@NonNull @CecSettingName String name) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
if (!setting.getValueType().equals(VALUE_TYPE_STRING)) {
throw new IllegalArgumentException("Setting '" + name
+ "' is not a string-type setting.");
}
Slog.d(TAG, "Getting CEC setting value '" + name + "'.");
return retrieveValue(setting, setting.getDefaultValue().getStringValue());
}
/**
* For a given setting name returns the current value of that setting (int).
*/
public int getIntValue(@NonNull @CecSettingName String name) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
if (!setting.getValueType().equals(VALUE_TYPE_INT)) {
throw new IllegalArgumentException("Setting '" + name
+ "' is not a int-type setting.");
}
Slog.d(TAG, "Getting CEC setting value '" + name + "'.");
String defaultValue = Integer.toString(setting.getDefaultValue().getIntValue());
String value = retrieveValue(setting, defaultValue);
return Integer.parseInt(value);
}
/**
* For a given setting name and value sets the current value of that setting (string).
*/
public void setStringValue(@NonNull @CecSettingName String name, @NonNull String value) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
@@ -364,11 +460,38 @@ public class HdmiCecConfig {
if (!setting.getUserConfigurable()) {
throw new IllegalArgumentException("Updating CEC setting '" + name + "' prohibited.");
}
if (!getAllowedValues(name).contains(value)) {
if (!setting.getValueType().equals(VALUE_TYPE_STRING)) {
throw new IllegalArgumentException("Setting '" + name
+ "' is not a string-type setting.");
}
if (!getAllowedStringValues(name).contains(value)) {
throw new IllegalArgumentException("Invalid CEC setting '" + name
+ "' value: '" + value + "'.");
}
Slog.d(TAG, "Updating CEC setting '" + name + "' to '" + value + "'.");
storeValue(setting, value);
}
/**
* For a given setting name and value sets the current value of that setting (int).
*/
public void setIntValue(@NonNull @CecSettingName String name, int value) {
Setting setting = getSetting(name);
if (setting == null) {
throw new IllegalArgumentException("Setting '" + name + "' does not exist.");
}
if (!setting.getUserConfigurable()) {
throw new IllegalArgumentException("Updating CEC setting '" + name + "' prohibited.");
}
if (!setting.getValueType().equals(VALUE_TYPE_INT)) {
throw new IllegalArgumentException("Setting '" + name
+ "' is not a int-type setting.");
}
if (!getAllowedIntValues(name).contains(value)) {
throw new IllegalArgumentException("Invalid CEC setting '" + name
+ "' value: '" + value + "'.");
}
Slog.d(TAG, "Updating CEC setting '" + name + "' to '" + value + "'.");
storeValue(setting, Integer.toString(value));
}
}

View File

@@ -2242,9 +2242,15 @@ public class HdmiControlService extends SystemService {
List<String> allSettings = hdmiCecConfig.getAllSettings();
Set<String> userSettings = new HashSet<>(hdmiCecConfig.getUserSettings());
for (String setting : allSettings) {
pw.println(setting + ": " + hdmiCecConfig.getValue(setting)
+ " (default: " + hdmiCecConfig.getDefaultValue(setting) + ")"
+ (userSettings.contains(setting) ? " [modifiable]" : ""));
if (hdmiCecConfig.isStringValueType(setting)) {
pw.println(setting + " (string): " + hdmiCecConfig.getStringValue(setting)
+ " (default: " + hdmiCecConfig.getDefaultStringValue(setting) + ")"
+ (userSettings.contains(setting) ? " [modifiable]" : ""));
} else if (hdmiCecConfig.isIntValueType(setting)) {
pw.println(setting + " (int): " + hdmiCecConfig.getIntValue(setting)
+ " (default: " + hdmiCecConfig.getDefaultIntValue(setting) + ")"
+ (userSettings.contains(setting) ? " [modifiable]" : ""));
}
}
pw.decreaseIndent();
@@ -2273,33 +2279,68 @@ public class HdmiControlService extends SystemService {
}
@Override
public List<String> getAllowedCecSettingValues(String name) {
public List<String> getAllowedCecSettingStringValues(String name) {
enforceAccessPermission();
long token = Binder.clearCallingIdentity();
try {
return HdmiControlService.this.getHdmiCecConfig().getAllowedValues(name);
return HdmiControlService.this.getHdmiCecConfig().getAllowedStringValues(name);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
public String getCecSettingValue(String name) {
public int[] getAllowedCecSettingIntValues(String name) {
enforceAccessPermission();
long token = Binder.clearCallingIdentity();
try {
return HdmiControlService.this.getHdmiCecConfig().getValue(name);
List<Integer> allowedValues =
HdmiControlService.this.getHdmiCecConfig().getAllowedIntValues(name);
return allowedValues.stream().mapToInt(i->i).toArray();
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
public void setCecSettingValue(String name, String value) {
public String getCecSettingStringValue(String name) {
enforceAccessPermission();
long token = Binder.clearCallingIdentity();
try {
HdmiControlService.this.getHdmiCecConfig().setValue(name, value);
return HdmiControlService.this.getHdmiCecConfig().getStringValue(name);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
public void setCecSettingStringValue(String name, String value) {
enforceAccessPermission();
long token = Binder.clearCallingIdentity();
try {
HdmiControlService.this.getHdmiCecConfig().setStringValue(name, value);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
public int getCecSettingIntValue(String name) {
enforceAccessPermission();
long token = Binder.clearCallingIdentity();
try {
return HdmiControlService.this.getHdmiCecConfig().getIntValue(name);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
public void setCecSettingIntValue(String name, int value) {
enforceAccessPermission();
long token = Binder.clearCallingIdentity();
try {
HdmiControlService.this.getHdmiCecConfig().setIntValue(name, value);
} finally {
Binder.restoreCallingIdentity(token);
}

View File

@@ -12,6 +12,7 @@
</xs:element>
<xs:complexType name="setting">
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="value-type" type="xs:string"/>
<xs:attribute name="user-configurable" type="xs:boolean"/>
<xs:element name="allowed-values" type="value-list" minOccurs="1" maxOccurs="1"/>
<xs:element name="default-value" type="value" minOccurs="1" maxOccurs="1"/>
@@ -23,5 +24,6 @@
</xs:complexType>
<xs:complexType name="value">
<xs:attribute name="string-value" type="xs:string"/>
<xs:attribute name="int-value" type="xs:int"/>
</xs:complexType>
</xs:schema>

View File

@@ -12,15 +12,19 @@ package com.android.server.hdmi.cec.config {
method public com.android.server.hdmi.cec.config.Value getDefaultValue();
method public String getName();
method public boolean getUserConfigurable();
method public String getValueType();
method public void setAllowedValues(com.android.server.hdmi.cec.config.ValueList);
method public void setDefaultValue(com.android.server.hdmi.cec.config.Value);
method public void setName(String);
method public void setUserConfigurable(boolean);
method public void setValueType(String);
}
public class Value {
ctor public Value();
method public int getIntValue();
method public String getStringValue();
method public void setIntValue(int);
method public void setStringValue(String);
}

View File

@@ -17,6 +17,8 @@ package com.android.server.hdmi;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertThrows;
@@ -77,14 +79,16 @@ public final class HdmiCecConfigTest {
"<?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 string-value=\"0\" />"
+ " <value string-value=\"1\" />"
+ " <value int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value string-value=\"1\" />"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"false\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -123,14 +127,16 @@ public final class HdmiCecConfigTest {
"<?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 string-value=\"0\" />"
+ " <value string-value=\"1\" />"
+ " <value int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value string-value=\"1\" />"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -152,14 +158,16 @@ public final class HdmiCecConfigTest {
"<?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 string-value=\"0\" />"
+ " <value string-value=\"1\" />"
+ " <value int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value string-value=\"1\" />"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -172,6 +180,7 @@ public final class HdmiCecConfigTest {
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"false\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -186,31 +195,32 @@ public final class HdmiCecConfigTest {
}
@Test
public void getAllowedValues_NoMasterXml() {
public void isStringValueType_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter, null, null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedValues("foo"));
() -> hdmiCecConfig.isStringValueType("foo"));
}
@Test
public void getAllowedValues_InvalidSetting() {
public void isStringValueType_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedValues("foo"));
() -> hdmiCecConfig.isStringValueType("foo"));
}
@Test
public void getAllowedValues_BasicSanity() {
public void isStringValueType_BasicSanity() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -220,7 +230,107 @@ public final class HdmiCecConfigTest {
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThat(hdmiCecConfig.getAllowedValues(
assertTrue(hdmiCecConfig.isStringValueType(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP));
}
@Test
public void isIntValueType_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter, null, null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.isIntValueType("foo"));
}
@Test
public void isIntValueType_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.isIntValueType("foo"));
}
@Test
public void isIntValueType_BasicSanity() {
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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertTrue(hdmiCecConfig.isIntValueType(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED));
}
@Test
public void getAllowedStringValues_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter, null, null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedStringValues("foo"));
}
@Test
public void getAllowedStringValues_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedStringValues("foo"));
}
@Test
public void getAllowedStringValues_InvalidValueType() {
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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedStringValues(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED));
}
@Test
public void getAllowedStringValues_BasicSanity() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
+ " <value string-value=\"broadcast\" />"
+ " <value string-value=\"none\" />"
+ " </allowed-values>"
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThat(hdmiCecConfig.getAllowedStringValues(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP))
.containsExactly(HdmiControlManager.SEND_STANDBY_ON_SLEEP_TO_TV,
HdmiControlManager.SEND_STANDBY_ON_SLEEP_BROADCAST,
@@ -228,31 +338,32 @@ public final class HdmiCecConfigTest {
}
@Test
public void getDefaultValue_NoMasterXml() {
public void getAllowedIntValues_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter, null, null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultValue("foo"));
() -> hdmiCecConfig.getAllowedIntValues("foo"));
}
@Test
public void getDefaultValue_InvalidSetting() {
public void getAllowedIntValues_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultValue("foo"));
() -> hdmiCecConfig.getAllowedIntValues("foo"));
}
@Test
public void getDefaultValue_BasicSanity() {
public void getAllowedIntValues_InvalidValueType() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -262,32 +373,199 @@ public final class HdmiCecConfigTest {
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThat(hdmiCecConfig.getDefaultValue(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP))
.isEqualTo(HdmiControlManager.SEND_STANDBY_ON_SLEEP_TO_TV);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedIntValues(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP));
}
@Test
public void getValue_NoMasterXml() {
public void getAllowedIntValues_BasicSanity() {
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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </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);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getValue("foo"));
() -> hdmiCecConfig.getDefaultStringValue("foo"));
}
@Test
public void getValue_InvalidSetting() {
public void getDefaultStringValue_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getValue("foo"));
() -> hdmiCecConfig.getDefaultStringValue("foo"));
}
@Test
public void getValue_GlobalSetting_BasicSanity() {
public void getDefaultStringValue_InvalidValueType() {
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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultStringValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED));
}
@Test
public void getDefaultStringValue_BasicSanity() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
+ " <value string-value=\"broadcast\" />"
+ " <value string-value=\"none\" />"
+ " </allowed-values>"
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThat(hdmiCecConfig.getDefaultStringValue(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP))
.isEqualTo(HdmiControlManager.SEND_STANDBY_ON_SLEEP_TO_TV);
}
@Test
public void getDefaultIntValue_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter, null, null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultIntValue("foo"));
}
@Test
public void getDefaultIntValue_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultIntValue("foo"));
}
@Test
public void getDefaultIntValue_InvalidValueType() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
+ " <value string-value=\"broadcast\" />"
+ " <value string-value=\"none\" />"
+ " </allowed-values>"
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultIntValue(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP));
}
@Test
public void getDefaultIntValue_BasicSanity() {
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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </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);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getStringValue("foo"));
}
@Test
public void getStringValue_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getStringValue("foo"));
}
@Test
public void getStringValue_InvalidType() {
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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getStringValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED));
}
@Test
public void getStringValue_GlobalSetting_BasicSanity() {
when(mStorageAdapter.retrieveGlobalSetting(mContext,
Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP,
HdmiControlManager.SEND_STANDBY_ON_SLEEP_TO_TV))
@@ -297,6 +575,7 @@ public final class HdmiCecConfigTest {
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -306,13 +585,13 @@ public final class HdmiCecConfigTest {
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThat(hdmiCecConfig.getValue(
assertThat(hdmiCecConfig.getStringValue(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP))
.isEqualTo(HdmiControlManager.SEND_STANDBY_ON_SLEEP_BROADCAST);
}
@Test
public void getValue_SystemProperty_BasicSanity() {
public void getStringValue_SystemProperty_BasicSanity() {
when(mStorageAdapter.retrieveSystemProperty(
HdmiCecConfig.SYSPROP_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
HdmiProperties.power_state_change_on_active_source_lost_values
@@ -324,6 +603,7 @@ public final class HdmiCecConfigTest {
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"power_state_change_on_active_source_lost\""
+ " value-type=\"string\""
+ " user-configurable=\"false\">"
+ " <allowed-values>"
+ " <value string-value=\"none\" />"
@@ -332,38 +612,130 @@ public final class HdmiCecConfigTest {
+ " <default-value string-value=\"none\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThat(hdmiCecConfig.getValue(
assertThat(hdmiCecConfig.getStringValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST))
.isEqualTo(HdmiProperties.power_state_change_on_active_source_lost_values
.STANDBY_NOW.name().toLowerCase());
}
@Test
public void setValue_NoMasterXml() {
public void getIntValue_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter, null, null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setValue("foo", "bar"));
() -> hdmiCecConfig.getIntValue("foo"));
}
@Test
public void setValue_InvalidSetting() {
public void getIntValue_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setValue("foo", "bar"));
() -> hdmiCecConfig.getIntValue("foo"));
}
@Test
public void setValue_NotConfigurable() {
public void getIntValue_InvalidType() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
+ " <value string-value=\"broadcast\" />"
+ " <value string-value=\"none\" />"
+ " </allowed-values>"
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getIntValue(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP));
}
@Test
public void getIntValue_GlobalSetting_BasicSanity() {
when(mStorageAdapter.retrieveGlobalSetting(mContext,
Global.HDMI_CONTROL_ENABLED,
Integer.toString(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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </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,
Integer.toString(HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_ENABLED)))
.thenReturn(Integer.toString(HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_DISABLED));
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"system_audio_mode_muting\""
+ " value-type=\"int\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThat(hdmiCecConfig.getIntValue(
HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING))
.isEqualTo(HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_DISABLED);
}
@Test
public void setStringValue_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter, null, null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setStringValue("foo", "bar"));
}
@Test
public void setStringValue_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setStringValue("foo", "bar"));
}
@Test
public void setStringValue_NotConfigurable() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"false\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -374,18 +746,19 @@ public final class HdmiCecConfigTest {
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setValue(
() -> hdmiCecConfig.setStringValue(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP,
HdmiControlManager.SEND_STANDBY_ON_SLEEP_BROADCAST));
}
@Test
public void setValue_InvalidValue() {
public void setStringValue_InvalidValue() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -396,18 +769,19 @@ public final class HdmiCecConfigTest {
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setValue(
() -> hdmiCecConfig.setStringValue(
HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP,
"bar"));
}
@Test
public void setValue_GlobalSetting_BasicSanity() {
public void setStringValue_GlobalSetting_BasicSanity() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"send_standby_on_sleep\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"to_tv\" />"
@@ -417,7 +791,7 @@ public final class HdmiCecConfigTest {
+ " <default-value string-value=\"to_tv\" />"
+ " </setting>"
+ "</cec-settings>", null);
hdmiCecConfig.setValue(HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP,
hdmiCecConfig.setStringValue(HdmiControlManager.CEC_SETTING_NAME_SEND_STANDBY_ON_SLEEP,
HdmiControlManager.SEND_STANDBY_ON_SLEEP_BROADCAST);
verify(mStorageAdapter).storeGlobalSetting(mContext,
Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP,
@@ -425,12 +799,13 @@ public final class HdmiCecConfigTest {
}
@Test
public void setValue_SystemProperty_BasicSanity() {
public void setStringValue_SystemProperty_BasicSanity() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"power_state_change_on_active_source_lost\""
+ " value-type=\"string\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value string-value=\"none\" />"
@@ -439,7 +814,7 @@ public final class HdmiCecConfigTest {
+ " <default-value string-value=\"none\" />"
+ " </setting>"
+ "</cec-settings>", null);
hdmiCecConfig.setValue(
hdmiCecConfig.setStringValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
HdmiProperties.power_state_change_on_active_source_lost_values
.STANDBY_NOW.name().toLowerCase());
@@ -448,4 +823,114 @@ public final class HdmiCecConfigTest {
HdmiProperties.power_state_change_on_active_source_lost_values
.STANDBY_NOW.name().toLowerCase());
}
@Test
public void setIntValue_NoMasterXml() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter, null, null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setIntValue("foo", 0));
}
@Test
public void setIntValue_InvalidSetting() {
HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
mContext, mStorageAdapter,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setIntValue("foo", 0));
}
@Test
public void setIntValue_NotConfigurable() {
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=\"false\">"
+ " <allowed-values>"
+ " <value int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setIntValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
HdmiControlManager.HDMI_CEC_CONTROL_DISABLED));
}
@Test
public void setIntValue_InvalidValue() {
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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ "</cec-settings>", null);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setIntValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
123));
}
@Test
public void setIntValue_GlobalSetting_BasicSanity() {
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 int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </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,
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
+ "<cec-settings>"
+ " <setting name=\"system_audio_mode_muting\""
+ " value-type=\"int\""
+ " user-configurable=\"true\">"
+ " <allowed-values>"
+ " <value int-value=\"0\" />"
+ " <value int-value=\"1\" />"
+ " </allowed-values>"
+ " <default-value int-value=\"1\" />"
+ " </setting>"
+ "</cec-settings>", null);
hdmiCecConfig.setIntValue(
HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_DISABLED);
verify(mStorageAdapter).storeSystemProperty(
HdmiCecConfig.SYSPROP_SYSTEM_AUDIO_MODE_MUTING,
Integer.toString(HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_DISABLED));
}
}