[CEC Configuration] Replace custom XML schema with RROs
Bug: 180316277
Test: atest HdmiCecConfigTest
Change-Id: I9593d0ecaf13eab162ea43b5ae19d31c4ab99354
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 7c66e64f..22f75c1 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -4740,4 +4740,97 @@
<!-- Whether to allow the caching of the SIM PIN for verification after unattended reboot -->
<bool name="config_allow_pin_storage_for_unattended_reboot">true</bool>
+
+ <!-- CEC Configuration -->
+ <bool name="config_cecHdmiCecEnabled_userConfigurable">true</bool>
+ <bool name="config_cecHdmiCecControlEnabled_allowed">true</bool>
+ <bool name="config_cecHdmiCecControlEnabled_default">true</bool>
+ <bool name="config_cecHdmiCecControlDisabled_allowed">true</bool>
+ <bool name="config_cecHdmiCecControlDisabled_default">false</bool>
+
+ <bool name="config_cecHdmiCecVersion_userConfigurable">true</bool>
+ <bool name="config_cecHdmiCecVersion14b_allowed">true</bool>
+ <bool name="config_cecHdmiCecVersion14b_default">true</bool>
+ <bool name="config_cecHdmiCecVersion20_allowed">true</bool>
+ <bool name="config_cecHdmiCecVersion20_default">false</bool>
+
+ <bool name="config_cecSendStandbyOnSleep_userConfigurable">true</bool>
+ <bool name="config_cecPowerControlModeTv_allowed">true</bool>
+ <bool name="config_cecPowerControlModeTv_default">true</bool>
+ <bool name="config_cecPowerControlModeBroadcast_allowed">true</bool>
+ <bool name="config_cecPowerControlModeBroadcast_default">false</bool>
+ <bool name="config_cecPowerControlModeNone_allowed">true</bool>
+ <bool name="config_cecPowerControlModeNone_default">false</bool>
+
+ <bool name="config_cecPowerStateChangeOnActiveSourceLost_userConfigurable">true</bool>
+ <bool name="config_cecPowerStateChangeOnActiveSourceLostNone_allowed">true</bool>
+ <bool name="config_cecPowerStateChangeOnActiveSourceLostNone_default">true</bool>
+ <bool name="config_cecPowerStateChangeOnActiveSourceLostStandbyNow_allowed">true</bool>
+ <bool name="config_cecPowerStateChangeOnActiveSourceLostStandbyNow_default">false</bool>
+
+ <bool name="config_cecSystemAudioModeMuting_userConfigurable">true</bool>
+ <bool name="config_cecSystemAudioModeMutingEnabled_allowed">true</bool>
+ <bool name="config_cecSystemAudioModeMutingEnabled_default">true</bool>
+ <bool name="config_cecSystemAudioModeMutingDisabled_allowed">true</bool>
+ <bool name="config_cecSystemAudioModeMutingDisabled_default">false</bool>
+
+ <bool name="config_cecVolumeControlMode_userConfigurable">true</bool>
+ <bool name="config_cecVolumeControlModeEnabled_allowed">true</bool>
+ <bool name="config_cecVolumeControlModeEnabled_default">true</bool>
+ <bool name="config_cecVolumeControlModeDisabled_allowed">true</bool>
+ <bool name="config_cecVolumeControlModeDisabled_default">false</bool>
+
+ <bool name="config_cecTvWakeOnOneTouchPlay_userConfigurable">true</bool>
+ <bool name="config_cecTvWakeOnOneTouchPlayEnabled_allowed">true</bool>
+ <bool name="config_cecTvWakeOnOneTouchPlayEnabled_default">true</bool>
+ <bool name="config_cecTvWakeOnOneTouchPlayDisabled_allowed">true</bool>
+ <bool name="config_cecTvWakeOnOneTouchPlayDisabled_default">false</bool>
+
+ <bool name="config_cecTvSendStandbyOnSleep_userConfigurable">true</bool>
+ <bool name="config_cecTvSendStandbyOnSleepEnabled_allowed">true</bool>
+ <bool name="config_cecTvSendStandbyOnSleepEnabled_default">true</bool>
+ <bool name="config_cecTvSendStandbyOnSleepDisabled_allowed">true</bool>
+ <bool name="config_cecTvSendStandbyOnSleepDisabled_default">false</bool>
+
+ <bool name="config_cecRcProfileTv_userConfigurable">true</bool>
+ <bool name="config_cecRcProfileTvNone_allowed">true</bool>
+ <bool name="config_cecRcProfileTvNone_default">true</bool>
+ <bool name="config_cecRcProfileTvOne_allowed">true</bool>
+ <bool name="config_cecRcProfileTvOne_default">false</bool>
+ <bool name="config_cecRcProfileTvTwo_allowed">true</bool>
+ <bool name="config_cecRcProfileTvTwo_default">false</bool>
+ <bool name="config_cecRcProfileTvThree_allowed">true</bool>
+ <bool name="config_cecRcProfileTvThree_default">false</bool>
+ <bool name="config_cecRcProfileTvFour_allowed">true</bool>
+ <bool name="config_cecRcProfileTvFour_default">false</bool>
+
+ <bool name="config_cecRcProfileSourceRootMenu_userConfigurable">true</bool>
+ <bool name="config_cecRcProfileSourceRootMenuHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceRootMenuHandled_default">true</bool>
+ <bool name="config_cecRcProfileSourceRootMenuNotHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceRootMenuNotHandled_default">false</bool>
+
+ <bool name="config_cecRcProfileSourceSetupMenu_userConfigurable">true</bool>
+ <bool name="config_cecRcProfileSourceSetupMenuHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceSetupMenuHandled_default">true</bool>
+ <bool name="config_cecRcProfileSourceSetupMenuNotHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceSetupMenuNotHandled_default">false</bool>
+
+ <bool name="config_cecRcProfileSourceContentsMenu_userConfigurable">true</bool>
+ <bool name="config_cecRcProfileSourceContentsMenuHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceContentsMenuHandled_default">false</bool>
+ <bool name="config_cecRcProfileSourceContentsMenuNotHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceContentsMenuNotHandled_default">true</bool>
+
+ <bool name="config_cecRcProfileSourceTopMenu_userConfigurable">true</bool>
+ <bool name="config_cecRcProfileSourceTopMenuHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceTopMenuHandled_default">false</bool>
+ <bool name="config_cecRcProfileSourceTopMenuNotHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceTopMenuNotHandled_default">true</bool>
+
+ <bool name="config_cecRcProfileSourceMediaContextSensitiveMenu_userConfigurable">true</bool>
+ <bool name="config_cecRcProfileSourceMediaContextSensitiveMenuHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceMediaContextSensitiveMenuHandled_default">false</bool>
+ <bool name="config_cecRcProfileSourceMediaContextSensitiveMenuNotHandled_allowed">true</bool>
+ <bool name="config_cecRcProfileSourceMediaContextSensitiveMenuNotHandled_default">true</bool>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index d904f7a..63774da 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -4224,4 +4224,97 @@
<java-symbol type="bool" name="config_voice_data_sms_auto_fallback" />
<java-symbol type="bool" name="config_enableOneHandedKeyguard" />
+
+ <!-- CEC Configuration -->
+ <java-symbol type="bool" name="config_cecHdmiCecEnabled_userConfigurable" />
+ <java-symbol type="bool" name="config_cecHdmiCecControlEnabled_allowed" />
+ <java-symbol type="bool" name="config_cecHdmiCecControlEnabled_default" />
+ <java-symbol type="bool" name="config_cecHdmiCecControlDisabled_allowed" />
+ <java-symbol type="bool" name="config_cecHdmiCecControlDisabled_default" />
+
+ <java-symbol type="bool" name="config_cecHdmiCecVersion_userConfigurable" />
+ <java-symbol type="bool" name="config_cecHdmiCecVersion14b_allowed" />
+ <java-symbol type="bool" name="config_cecHdmiCecVersion14b_default" />
+ <java-symbol type="bool" name="config_cecHdmiCecVersion20_allowed" />
+ <java-symbol type="bool" name="config_cecHdmiCecVersion20_default" />
+
+ <java-symbol type="bool" name="config_cecSendStandbyOnSleep_userConfigurable" />
+ <java-symbol type="bool" name="config_cecPowerControlModeTv_allowed" />
+ <java-symbol type="bool" name="config_cecPowerControlModeTv_default" />
+ <java-symbol type="bool" name="config_cecPowerControlModeBroadcast_allowed" />
+ <java-symbol type="bool" name="config_cecPowerControlModeBroadcast_default" />
+ <java-symbol type="bool" name="config_cecPowerControlModeNone_allowed" />
+ <java-symbol type="bool" name="config_cecPowerControlModeNone_default" />
+
+ <java-symbol type="bool" name="config_cecPowerStateChangeOnActiveSourceLost_userConfigurable" />
+ <java-symbol type="bool" name="config_cecPowerStateChangeOnActiveSourceLostNone_allowed" />
+ <java-symbol type="bool" name="config_cecPowerStateChangeOnActiveSourceLostNone_default" />
+ <java-symbol type="bool" name="config_cecPowerStateChangeOnActiveSourceLostStandbyNow_allowed" />
+ <java-symbol type="bool" name="config_cecPowerStateChangeOnActiveSourceLostStandbyNow_default" />
+
+ <java-symbol type="bool" name="config_cecSystemAudioModeMuting_userConfigurable" />
+ <java-symbol type="bool" name="config_cecSystemAudioModeMutingEnabled_allowed" />
+ <java-symbol type="bool" name="config_cecSystemAudioModeMutingEnabled_default" />
+ <java-symbol type="bool" name="config_cecSystemAudioModeMutingDisabled_allowed" />
+ <java-symbol type="bool" name="config_cecSystemAudioModeMutingDisabled_default" />
+
+ <java-symbol type="bool" name="config_cecVolumeControlMode_userConfigurable" />
+ <java-symbol type="bool" name="config_cecVolumeControlModeEnabled_allowed" />
+ <java-symbol type="bool" name="config_cecVolumeControlModeEnabled_default" />
+ <java-symbol type="bool" name="config_cecVolumeControlModeDisabled_allowed" />
+ <java-symbol type="bool" name="config_cecVolumeControlModeDisabled_default" />
+
+ <java-symbol type="bool" name="config_cecTvWakeOnOneTouchPlay_userConfigurable" />
+ <java-symbol type="bool" name="config_cecTvWakeOnOneTouchPlayEnabled_allowed" />
+ <java-symbol type="bool" name="config_cecTvWakeOnOneTouchPlayEnabled_default" />
+ <java-symbol type="bool" name="config_cecTvWakeOnOneTouchPlayDisabled_allowed" />
+ <java-symbol type="bool" name="config_cecTvWakeOnOneTouchPlayDisabled_default" />
+
+ <java-symbol type="bool" name="config_cecTvSendStandbyOnSleep_userConfigurable" />
+ <java-symbol type="bool" name="config_cecTvSendStandbyOnSleepEnabled_allowed" />
+ <java-symbol type="bool" name="config_cecTvSendStandbyOnSleepEnabled_default" />
+ <java-symbol type="bool" name="config_cecTvSendStandbyOnSleepDisabled_allowed" />
+ <java-symbol type="bool" name="config_cecTvSendStandbyOnSleepDisabled_default" />
+
+ <java-symbol type="bool" name="config_cecRcProfileTv_userConfigurable" />
+ <java-symbol type="bool" name="config_cecRcProfileTvNone_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileTvNone_default" />
+ <java-symbol type="bool" name="config_cecRcProfileTvOne_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileTvOne_default" />
+ <java-symbol type="bool" name="config_cecRcProfileTvTwo_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileTvTwo_default" />
+ <java-symbol type="bool" name="config_cecRcProfileTvThree_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileTvThree_default" />
+ <java-symbol type="bool" name="config_cecRcProfileTvFour_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileTvFour_default" />
+
+ <java-symbol type="bool" name="config_cecRcProfileSourceRootMenu_userConfigurable" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceRootMenuHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceRootMenuHandled_default" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceRootMenuNotHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceRootMenuNotHandled_default" />
+
+ <java-symbol type="bool" name="config_cecRcProfileSourceSetupMenu_userConfigurable" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceSetupMenuHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceSetupMenuHandled_default" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceSetupMenuNotHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceSetupMenuNotHandled_default" />
+
+ <java-symbol type="bool" name="config_cecRcProfileSourceContentsMenu_userConfigurable" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceContentsMenuHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceContentsMenuHandled_default" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceContentsMenuNotHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceContentsMenuNotHandled_default" />
+
+ <java-symbol type="bool" name="config_cecRcProfileSourceTopMenu_userConfigurable" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceTopMenuHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceTopMenuHandled_default" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceTopMenuNotHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceTopMenuNotHandled_default" />
+
+ <java-symbol type="bool" name="config_cecRcProfileSourceMediaContextSensitiveMenu_userConfigurable" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceMediaContextSensitiveMenuHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceMediaContextSensitiveMenuHandled_default" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceMediaContextSensitiveMenuNotHandled_allowed" />
+ <java-symbol type="bool" name="config_cecRcProfileSourceMediaContextSensitiveMenuNotHandled_default" />
</resources>
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecConfig.java b/services/core/java/com/android/server/hdmi/HdmiCecConfig.java
index 624af30..6fbb26c 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecConfig.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecConfig.java
@@ -35,33 +35,19 @@
import android.os.UserHandle;
import android.provider.Settings.Global;
import android.util.ArrayMap;
-import android.util.Slog;
+import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ConcurrentUtils;
-import com.android.server.hdmi.cec.config.CecSettings;
-import com.android.server.hdmi.cec.config.Setting;
-import com.android.server.hdmi.cec.config.Value;
-import com.android.server.hdmi.cec.config.XmlParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
-import java.util.Set;
import java.util.concurrent.Executor;
-import javax.xml.datatype.DatatypeConfigurationException;
-
/**
* The {@link HdmiCecConfig} class is used for getting information about
* available HDMI CEC settings.
@@ -74,6 +60,10 @@
private static final String SHARED_PREFS_DIR = "shared_prefs";
private static final String SHARED_PREFS_NAME = "cec_config.xml";
+ private static final int STORAGE_SYSPROPS = 0;
+ private static final int STORAGE_GLOBAL_SETTINGS = 1;
+ private static final int STORAGE_SHARED_PREFS = 2;
+
@IntDef({
STORAGE_SYSPROPS,
STORAGE_GLOBAL_SETTINGS,
@@ -81,10 +71,6 @@
})
private @interface Storage {}
- private static final int STORAGE_SYSPROPS = 0;
- private static final int STORAGE_GLOBAL_SETTINGS = 1;
- private static final int STORAGE_SHARED_PREFS = 2;
-
private static final String VALUE_TYPE_STRING = "string";
private static final String VALUE_TYPE_INT = "int";
@@ -96,8 +82,6 @@
@NonNull private final Context mContext;
@NonNull private final StorageAdapter mStorageAdapter;
- @Nullable private final CecSettings mSystemConfig;
- @Nullable private final CecSettings mVendorOverride;
private final Object mLock = new Object();
@@ -107,6 +91,18 @@
private SettingsObserver mSettingsObserver;
+ private LinkedHashMap<String, Setting> mSettings = new LinkedHashMap<>();
+
+ /**
+ * Exception thrown when the CEC Configuration setup verification fails.
+ * This usually means a settings lacks default value or storage/storage key.
+ */
+ public static class VerificationException extends RuntimeException {
+ public VerificationException(String message) {
+ super(message);
+ }
+ }
+
/**
* Listener used to get notifications when value of a setting changes.
*/
@@ -202,91 +198,297 @@
}
}
+ private class Value {
+ private final String mStringValue;
+ private final Integer mIntValue;
+
+ Value(@NonNull String value) {
+ mStringValue = value;
+ mIntValue = null;
+ }
+
+ Value(@NonNull Integer value) {
+ mStringValue = null;
+ mIntValue = value;
+ }
+
+ String getStringValue() {
+ return mStringValue;
+ }
+
+ Integer getIntValue() {
+ return mIntValue;
+ }
+ }
+
+ private class Setting {
+ @NonNull private final Context mContext;
+ @NonNull private final @CecSettingName String mName;
+ private final boolean mUserConfigurable;
+
+ private Value mDefaultValue = null;
+ private List<Value> mAllowedValues = new ArrayList<>();
+
+ Setting(@NonNull Context context,
+ @NonNull @CecSettingName String name,
+ int userConfResId) {
+ mContext = context;
+ mName = name;
+ mUserConfigurable = mContext.getResources().getBoolean(userConfResId);
+ }
+
+ public @CecSettingName String getName() {
+ return mName;
+ }
+
+ public @ValueType String getValueType() {
+ return getDefaultValue().getStringValue() != null
+ ? VALUE_TYPE_STRING
+ : VALUE_TYPE_INT;
+ }
+
+ public Value getDefaultValue() {
+ if (mDefaultValue == null) {
+ throw new VerificationException("Invalid CEC setup for '"
+ + this.getName() + "' setting. "
+ + "Setting has no default value.");
+ }
+ return mDefaultValue;
+ }
+
+ public boolean getUserConfigurable() {
+ return mUserConfigurable;
+ }
+
+ private void registerValue(@NonNull Value value,
+ int allowedResId, int defaultResId) {
+ if (mContext.getResources().getBoolean(allowedResId)) {
+ mAllowedValues.add(value);
+ if (mContext.getResources().getBoolean(defaultResId)) {
+ if (mDefaultValue != null) {
+ throw new VerificationException("Invalid CEC setup for '"
+ + this.getName() + "' setting. "
+ + "Setting already has a default value.");
+ }
+ mDefaultValue = value;
+ }
+ }
+ }
+
+ public void registerValue(@NonNull String value, int allowedResId,
+ int defaultResId) {
+ registerValue(new Value(value), allowedResId, defaultResId);
+ }
+
+ public void registerValue(int value, int allowedResId,
+ int defaultResId) {
+ registerValue(new Value(value), allowedResId, defaultResId);
+ }
+
+
+ public List<Value> getAllowedValues() {
+ return mAllowedValues;
+ }
+ }
+
@VisibleForTesting
HdmiCecConfig(@NonNull Context context,
- @NonNull StorageAdapter storageAdapter,
- @Nullable CecSettings systemConfig,
- @Nullable CecSettings vendorOverride) {
+ @NonNull StorageAdapter storageAdapter) {
mContext = context;
mStorageAdapter = storageAdapter;
- mSystemConfig = systemConfig;
- mVendorOverride = vendorOverride;
- if (mSystemConfig == null) {
- Slog.i(TAG, "CEC system configuration XML missing.");
- }
- if (mVendorOverride == null) {
- Slog.i(TAG, "CEC OEM configuration override XML missing.");
- }
+
+ Setting hdmiCecEnabled = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
+ R.bool.config_cecHdmiCecEnabled_userConfigurable);
+ hdmiCecEnabled.registerValue(HdmiControlManager.HDMI_CEC_CONTROL_ENABLED,
+ R.bool.config_cecHdmiCecControlEnabled_allowed,
+ R.bool.config_cecHdmiCecControlEnabled_default);
+ hdmiCecEnabled.registerValue(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED,
+ R.bool.config_cecHdmiCecControlDisabled_allowed,
+ R.bool.config_cecHdmiCecControlDisabled_default);
+
+ Setting hdmiCecVersion = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_VERSION,
+ R.bool.config_cecHdmiCecVersion_userConfigurable);
+ hdmiCecVersion.registerValue(HdmiControlManager.HDMI_CEC_VERSION_1_4_B,
+ R.bool.config_cecHdmiCecVersion14b_allowed,
+ R.bool.config_cecHdmiCecVersion14b_default);
+ hdmiCecVersion.registerValue(HdmiControlManager.HDMI_CEC_VERSION_2_0,
+ R.bool.config_cecHdmiCecVersion20_allowed,
+ R.bool.config_cecHdmiCecVersion20_default);
+
+ Setting powerControlMode = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE,
+ R.bool.config_cecSendStandbyOnSleep_userConfigurable);
+ powerControlMode.registerValue(HdmiControlManager.POWER_CONTROL_MODE_TV,
+ R.bool.config_cecPowerControlModeTv_allowed,
+ R.bool.config_cecPowerControlModeTv_default);
+ powerControlMode.registerValue(HdmiControlManager.POWER_CONTROL_MODE_BROADCAST,
+ R.bool.config_cecPowerControlModeBroadcast_allowed,
+ R.bool.config_cecPowerControlModeBroadcast_default);
+ powerControlMode.registerValue(HdmiControlManager.POWER_CONTROL_MODE_NONE,
+ R.bool.config_cecPowerControlModeNone_allowed,
+ R.bool.config_cecPowerControlModeNone_default);
+
+ Setting powerStateChangeOnActiveSourceLost = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
+ R.bool.config_cecPowerStateChangeOnActiveSourceLost_userConfigurable);
+ powerStateChangeOnActiveSourceLost.registerValue(
+ HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_NONE,
+ R.bool.config_cecPowerStateChangeOnActiveSourceLostNone_allowed,
+ R.bool.config_cecPowerStateChangeOnActiveSourceLostNone_default);
+ powerStateChangeOnActiveSourceLost.registerValue(
+ HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW,
+ R.bool.config_cecPowerStateChangeOnActiveSourceLostStandbyNow_allowed,
+ R.bool.config_cecPowerStateChangeOnActiveSourceLostStandbyNow_default);
+
+ Setting systemAudioModeMuting = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
+ R.bool.config_cecSystemAudioModeMuting_userConfigurable);
+ systemAudioModeMuting.registerValue(HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_ENABLED,
+ R.bool.config_cecSystemAudioModeMutingEnabled_allowed,
+ R.bool.config_cecSystemAudioModeMutingEnabled_default);
+ systemAudioModeMuting.registerValue(HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_DISABLED,
+ R.bool.config_cecSystemAudioModeMutingDisabled_allowed,
+ R.bool.config_cecSystemAudioModeMutingDisabled_default);
+
+ Setting volumeControlMode = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_VOLUME_CONTROL_MODE,
+ R.bool.config_cecVolumeControlMode_userConfigurable);
+ volumeControlMode.registerValue(HdmiControlManager.VOLUME_CONTROL_ENABLED,
+ R.bool.config_cecVolumeControlModeEnabled_allowed,
+ R.bool.config_cecVolumeControlModeEnabled_default);
+ volumeControlMode.registerValue(HdmiControlManager.VOLUME_CONTROL_DISABLED,
+ R.bool.config_cecVolumeControlModeDisabled_allowed,
+ R.bool.config_cecVolumeControlModeDisabled_default);
+
+ Setting tvWakeOnOneTouchPlay = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY,
+ R.bool.config_cecTvWakeOnOneTouchPlay_userConfigurable);
+ tvWakeOnOneTouchPlay.registerValue(HdmiControlManager.TV_WAKE_ON_ONE_TOUCH_PLAY_ENABLED,
+ R.bool.config_cecTvWakeOnOneTouchPlayEnabled_allowed,
+ R.bool.config_cecTvWakeOnOneTouchPlayEnabled_default);
+ tvWakeOnOneTouchPlay.registerValue(HdmiControlManager.TV_WAKE_ON_ONE_TOUCH_PLAY_DISABLED,
+ R.bool.config_cecTvWakeOnOneTouchPlayDisabled_allowed,
+ R.bool.config_cecTvWakeOnOneTouchPlayDisabled_default);
+
+ Setting tvSendStandbyOnSleep = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP,
+ R.bool.config_cecTvSendStandbyOnSleep_userConfigurable);
+ tvSendStandbyOnSleep.registerValue(HdmiControlManager.TV_SEND_STANDBY_ON_SLEEP_ENABLED,
+ R.bool.config_cecTvSendStandbyOnSleepEnabled_allowed,
+ R.bool.config_cecTvSendStandbyOnSleepEnabled_default);
+ tvSendStandbyOnSleep.registerValue(HdmiControlManager.TV_SEND_STANDBY_ON_SLEEP_DISABLED,
+ R.bool.config_cecTvSendStandbyOnSleepDisabled_allowed,
+ R.bool.config_cecTvSendStandbyOnSleepDisabled_default);
+
+ Setting rcProfileTv = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_TV,
+ R.bool.config_cecRcProfileTv_userConfigurable);
+ rcProfileTv.registerValue(HdmiControlManager.RC_PROFILE_TV_NONE,
+ R.bool.config_cecRcProfileTvNone_allowed,
+ R.bool.config_cecRcProfileTvNone_default);
+ rcProfileTv.registerValue(HdmiControlManager.RC_PROFILE_TV_ONE,
+ R.bool.config_cecRcProfileTvOne_allowed,
+ R.bool.config_cecRcProfileTvOne_default);
+ rcProfileTv.registerValue(HdmiControlManager.RC_PROFILE_TV_TWO,
+ R.bool.config_cecRcProfileTvTwo_allowed,
+ R.bool.config_cecRcProfileTvTwo_default);
+ rcProfileTv.registerValue(HdmiControlManager.RC_PROFILE_TV_THREE,
+ R.bool.config_cecRcProfileTvThree_allowed,
+ R.bool.config_cecRcProfileTvThree_default);
+ rcProfileTv.registerValue(HdmiControlManager.RC_PROFILE_TV_FOUR,
+ R.bool.config_cecRcProfileTvFour_allowed,
+ R.bool.config_cecRcProfileTvFour_default);
+
+ Setting rcProfileSourceRootMenu = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU,
+ R.bool.config_cecRcProfileSourceRootMenu_userConfigurable);
+ rcProfileSourceRootMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_ROOT_MENU_HANDLED,
+ R.bool.config_cecRcProfileSourceRootMenuHandled_allowed,
+ R.bool.config_cecRcProfileSourceRootMenuHandled_default);
+ rcProfileSourceRootMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_ROOT_MENU_NOT_HANDLED,
+ R.bool.config_cecRcProfileSourceRootMenuNotHandled_allowed,
+ R.bool.config_cecRcProfileSourceRootMenuNotHandled_default);
+
+ Setting rcProfileSourceSetupMenu = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU,
+ R.bool.config_cecRcProfileSourceSetupMenu_userConfigurable);
+ rcProfileSourceSetupMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_SETUP_MENU_HANDLED,
+ R.bool.config_cecRcProfileSourceSetupMenuHandled_allowed,
+ R.bool.config_cecRcProfileSourceSetupMenuHandled_default);
+ rcProfileSourceSetupMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_SETUP_MENU_NOT_HANDLED,
+ R.bool.config_cecRcProfileSourceSetupMenuNotHandled_allowed,
+ R.bool.config_cecRcProfileSourceSetupMenuNotHandled_default);
+
+ Setting rcProfileSourceContentsMenu = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU,
+ R.bool.config_cecRcProfileSourceContentsMenu_userConfigurable);
+ rcProfileSourceContentsMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_CONTENTS_MENU_HANDLED,
+ R.bool.config_cecRcProfileSourceContentsMenuHandled_allowed,
+ R.bool.config_cecRcProfileSourceContentsMenuHandled_default);
+ rcProfileSourceContentsMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_CONTENTS_MENU_NOT_HANDLED,
+ R.bool.config_cecRcProfileSourceContentsMenuNotHandled_allowed,
+ R.bool.config_cecRcProfileSourceContentsMenuNotHandled_default);
+
+ Setting rcProfileSourceTopMenu = registerSetting(
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU,
+ R.bool.config_cecRcProfileSourceTopMenu_userConfigurable);
+ rcProfileSourceTopMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_TOP_MENU_HANDLED,
+ R.bool.config_cecRcProfileSourceTopMenuHandled_allowed,
+ R.bool.config_cecRcProfileSourceTopMenuHandled_default);
+ rcProfileSourceTopMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_TOP_MENU_NOT_HANDLED,
+ R.bool.config_cecRcProfileSourceTopMenuNotHandled_allowed,
+ R.bool.config_cecRcProfileSourceTopMenuNotHandled_default);
+
+ Setting rcProfileSourceMediaContextSensitiveMenu = registerSetting(
+ HdmiControlManager
+ .CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU,
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenu_userConfigurable);
+ rcProfileSourceMediaContextSensitiveMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_MEDIA_CONTEXT_SENSITIVE_MENU_HANDLED,
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenuHandled_allowed,
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenuHandled_default);
+ rcProfileSourceMediaContextSensitiveMenu.registerValue(
+ HdmiControlManager.RC_PROFILE_SOURCE_MEDIA_CONTEXT_SENSITIVE_MENU_NOT_HANDLED,
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenuNotHandled_allowed,
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenuNotHandled_default);
+
+ verifySettings();
}
HdmiCecConfig(@NonNull Context context) {
- this(context, new StorageAdapter(context),
- readSettingsFromFile(Environment.buildPath(Environment.getRootDirectory(),
- ETC_DIR, CONFIG_FILE)),
- readSettingsFromFile(Environment.buildPath(Environment.getVendorDirectory(),
- ETC_DIR, CONFIG_FILE)));
+ this(context, new StorageAdapter(context));
}
- @Nullable
- private static CecSettings readSettingsFromFile(@NonNull File file) {
- if (!file.exists()) {
- return null;
- }
- if (!file.isFile()) {
- Slog.e(TAG, "CEC configuration is not a file: " + file + ", skipping.");
- return null;
- }
- try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
- return XmlParser.read(in);
- } catch (IOException | DatatypeConfigurationException | XmlPullParserException e) {
- Slog.e(TAG, "Encountered an error while reading/parsing CEC config file: " + file, e);
- }
- return null;
+ private Setting registerSetting(@NonNull @CecSettingName String name,
+ int userConfResId) {
+ Setting setting = new Setting(mContext, name, userConfResId);
+ mSettings.put(name, setting);
+ return setting;
}
- @NonNull
- @VisibleForTesting
- static HdmiCecConfig createFromStrings(@NonNull Context context,
- @NonNull StorageAdapter storageAdapter,
- @Nullable String productConfigXml,
- @Nullable String vendorOverrideXml) {
- CecSettings productConfig = null;
- CecSettings vendorOverride = null;
- try {
- if (productConfigXml != null) {
- productConfig = XmlParser.read(
- new ByteArrayInputStream(productConfigXml.getBytes()));
- }
- if (vendorOverrideXml != null) {
- vendorOverride = XmlParser.read(
- new ByteArrayInputStream(vendorOverrideXml.getBytes()));
- }
- } catch (IOException | DatatypeConfigurationException | XmlPullParserException e) {
- Slog.e(TAG, "Encountered an error while reading/parsing CEC config strings", e);
+ private void verifySettings() {
+ for (Setting setting: mSettings.values()) {
+ // This will throw an exception when a setting
+ // doesn't have a default value assigned.
+ setting.getDefaultValue();
+ getStorage(setting);
+ getStorageKey(setting);
}
- return new HdmiCecConfig(context, storageAdapter, productConfig, vendorOverride);
}
@Nullable
private Setting getSetting(@NonNull String name) {
- if (mSystemConfig == null) {
- return null;
- }
- if (mVendorOverride != null) {
- // First read from the vendor override.
- for (Setting setting : mVendorOverride.getSetting()) {
- if (setting.getName().equals(name)) {
- return setting;
- }
- }
- }
- // If not found, try the system config.
- for (Setting setting : mSystemConfig.getSetting()) {
- if (setting.getName().equals(name)) {
- return setting;
- }
- }
- return null;
+ return mSettings.containsKey(name) ? mSettings.get(name) : null;
}
@Storage
@@ -322,7 +524,7 @@
.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU:
return STORAGE_SHARED_PREFS;
default:
- throw new RuntimeException("Invalid CEC setting '" + setting.getName()
+ throw new VerificationException("Invalid CEC setting '" + setting.getName()
+ "' storage.");
}
}
@@ -359,7 +561,7 @@
.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU:
return setting.getName();
default:
- throw new RuntimeException("Invalid CEC setting '" + setting.getName()
+ throw new VerificationException("Invalid CEC setting '" + setting.getName()
+ "' storage key.");
}
}
@@ -396,10 +598,6 @@
}
}
- private int getIntValue(@NonNull Value value) {
- return Integer.decode(value.getIntValue());
- }
-
private void notifyGlobalSettingChanged(String setting) {
switch (setting) {
case Global.HDMI_CONTROL_ENABLED:
@@ -533,41 +731,20 @@
* Returns a list of all settings based on the XML metadata.
*/
public @CecSettingName List<String> getAllSettings() {
- if (mSystemConfig == null) {
- return new ArrayList<String>();
- }
- List<String> allSettings = new ArrayList<String>();
- for (Setting setting : mSystemConfig.getSetting()) {
- allSettings.add(setting.getName());
- }
- return allSettings;
+ return new ArrayList<>(mSettings.keySet());
}
/**
* Returns a list of user-modifiable settings based on the XML metadata.
*/
public @CecSettingName List<String> getUserSettings() {
- if (mSystemConfig == null) {
- return new ArrayList<String>();
- }
- Set<String> userSettings = new HashSet<String>();
- // First read from the system config.
- for (Setting setting : mSystemConfig.getSetting()) {
+ List<String> settings = new ArrayList<>();
+ for (Setting setting: mSettings.values()) {
if (setting.getUserConfigurable()) {
- userSettings.add(setting.getName());
+ settings.add(setting.getName());
}
}
- if (mVendorOverride != null) {
- // Next either add or remove based on the vendor override.
- for (Setting setting : mVendorOverride.getSetting()) {
- if (setting.getUserConfigurable()) {
- userSettings.add(setting.getName());
- } else {
- userSettings.remove(setting.getName());
- }
- }
- }
- return new ArrayList(userSettings);
+ return settings;
}
/**
@@ -607,7 +784,7 @@
+ "' is not a string-type setting.");
}
List<String> allowedValues = new ArrayList<String>();
- for (Value allowedValue : setting.getAllowedValues().getValue()) {
+ for (Value allowedValue : setting.getAllowedValues()) {
allowedValues.add(allowedValue.getStringValue());
}
return allowedValues;
@@ -626,8 +803,8 @@
+ "' is not a string-type setting.");
}
List<Integer> allowedValues = new ArrayList<Integer>();
- for (Value allowedValue : setting.getAllowedValues().getValue()) {
- allowedValues.add(getIntValue(allowedValue));
+ for (Value allowedValue : setting.getAllowedValues()) {
+ allowedValues.add(allowedValue.getIntValue());
}
return allowedValues;
}
@@ -659,7 +836,7 @@
throw new IllegalArgumentException("Setting '" + name
+ "' is not a string-type setting.");
}
- return getIntValue(getSetting(name).getDefaultValue());
+ return getSetting(name).getDefaultValue().getIntValue();
}
/**
@@ -691,7 +868,7 @@
+ "' is not a int-type setting.");
}
HdmiLogger.debug("Getting CEC setting value '" + name + "'.");
- String defaultValue = Integer.toString(getIntValue(setting.getDefaultValue()));
+ String defaultValue = Integer.toString(setting.getDefaultValue().getIntValue());
String value = retrieveValue(setting, defaultValue);
return Integer.parseInt(value);
}
diff --git a/services/tests/servicestests/src/com/android/server/hdmi/FakeHdmiCecConfig.java b/services/tests/servicestests/src/com/android/server/hdmi/FakeHdmiCecConfig.java
index 137bd88..375704e 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/FakeHdmiCecConfig.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/FakeHdmiCecConfig.java
@@ -16,183 +16,206 @@
package com.android.server.hdmi;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
import android.annotation.NonNull;
import android.content.Context;
-import android.util.Slog;
+import android.content.ContextWrapper;
+import android.content.res.Resources;
-import com.android.server.hdmi.cec.config.CecSettings;
-import com.android.server.hdmi.cec.config.XmlParser;
-
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-
-import javax.xml.datatype.DatatypeConfigurationException;
+import com.android.internal.R;
/**
- * Fake class which loads default system configuration with user-configurable
+ * Fake class which stubs default system configuration with user-configurable
* settings (useful for testing).
*/
final class FakeHdmiCecConfig extends HdmiCecConfig {
private static final String TAG = "FakeHdmiCecConfig";
- private static final String SYSTEM_CONFIG_XML =
- "<?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>"
- + " <setting name=\"power_state_change_on_active_source_lost\""
- + " value-type=\"string\""
- + " user-configurable=\"true\">"
- + " <allowed-values>"
- + " <value string-value=\"none\" />"
- + " <value string-value=\"standby_now\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"none\" />"
- + " </setting>"
- + " <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>"
- + " <setting name=\"hdmi_cec_version\""
- + " value-type=\"int\""
- + " user-configurable=\"true\">"
- + " <allowed-values>"
- + " <value int-value=\"0x05\" />"
- + " <value int-value=\"0x06\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0x05\" />"
- + " </setting>"
- + " <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>"
- + " <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>"
- + " <setting name=\"volume_control_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>"
- + " <setting name=\"tv_wake_on_one_touch_play\""
- + " value-type=\"int\""
- + " user-configurable=\"true\">"
- + " <allowed-values>"
- + " <value int-value=\"0\" />"
- + " <value int-value=\"1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"1\" />"
- + " </setting>"
- + " <setting name=\"tv_send_standby_on_sleep\""
- + " value-type=\"int\""
- + " user-configurable=\"true\">"
- + " <allowed-values>"
- + " <value int-value=\"0\" />"
- + " <value int-value=\"1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"1\" />"
- + " </setting>"
- + " <setting name=\"rc_profile_tv\""
- + " value-type=\"int\""
- + " user-configurable=\"false\">"
- + " <allowed-values>"
- + " <value int-value=\"0x0\" />"
- + " <value int-value=\"0x2\" />"
- + " <value int-value=\"0x6\" />"
- + " <value int-value=\"0xA\" />"
- + " <value int-value=\"0xE\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0x0\" />"
- + " </setting>"
- + " <setting name=\"rc_profile_source_handles_root_menu\""
- + " value-type=\"int\""
- + " user-configurable=\"false\">"
- + " <allowed-values>"
- + " <value int-value=\"0\" />"
- + " <value int-value=\"1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"1\" />"
- + " </setting>"
- + " <setting name=\"rc_profile_source_handles_setup_menu\""
- + " value-type=\"int\""
- + " user-configurable=\"false\">"
- + " <allowed-values>"
- + " <value int-value=\"0\" />"
- + " <value int-value=\"1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"1\" />"
- + " </setting>"
- + " <setting name=\"rc_profile_source_handles_contents_menu\""
- + " value-type=\"int\""
- + " user-configurable=\"false\">"
- + " <allowed-values>"
- + " <value int-value=\"0\" />"
- + " <value int-value=\"1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0\" />"
- + " </setting>"
- + " <setting name=\"rc_profile_source_handles_top_menu\""
- + " value-type=\"int\""
- + " user-configurable=\"false\">"
- + " <allowed-values>"
- + " <value int-value=\"0\" />"
- + " <value int-value=\"1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0\" />"
- + " </setting>"
- + " <setting name=\"rc_profile_source_handles_media_context_sensitive_menu\""
- + " value-type=\"int\""
- + " user-configurable=\"false\">"
- + " <allowed-values>"
- + " <value int-value=\"0\" />"
- + " <value int-value=\"1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0\" />"
- + " </setting>"
- + "</cec-settings>";
-
- FakeHdmiCecConfig(@NonNull Context context) {
- super(context, new StorageAdapter(context), parseFromString(SYSTEM_CONFIG_XML), null);
+ public static Context buildContext(Context context) {
+ Context contextSpy = spy(new ContextWrapper(context));
+ doReturn(buildResources(context)).when(contextSpy).getResources();
+ return contextSpy;
}
- private static CecSettings parseFromString(@NonNull String configXml) {
- CecSettings config = null;
- try {
- config = XmlParser.read(
- new ByteArrayInputStream(configXml.getBytes()));
- } catch (IOException | DatatypeConfigurationException | XmlPullParserException e) {
- Slog.e(TAG, "Encountered an error while reading/parsing CEC config strings", e);
- }
- return config;
+ private static Resources buildResources(Context context) {
+ Resources resources = spy(context.getResources());
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecEnabled_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecControlEnabled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecControlEnabled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecControlDisabled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecControlDisabled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecVersion_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecVersion14b_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecVersion14b_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecVersion20_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecHdmiCecVersion20_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecSendStandbyOnSleep_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecPowerControlModeTv_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecPowerControlModeTv_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecPowerControlModeBroadcast_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecPowerControlModeBroadcast_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecPowerControlModeNone_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecPowerControlModeNone_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecPowerStateChangeOnActiveSourceLost_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecPowerStateChangeOnActiveSourceLostNone_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecPowerStateChangeOnActiveSourceLostNone_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecPowerStateChangeOnActiveSourceLostStandbyNow_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecPowerStateChangeOnActiveSourceLostStandbyNow_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecSystemAudioModeMuting_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecSystemAudioModeMutingEnabled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecSystemAudioModeMutingEnabled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecSystemAudioModeMutingDisabled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecSystemAudioModeMutingDisabled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecVolumeControlMode_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecVolumeControlModeEnabled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecVolumeControlModeEnabled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecVolumeControlModeDisabled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecVolumeControlModeDisabled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecTvWakeOnOneTouchPlay_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecTvWakeOnOneTouchPlayEnabled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecTvWakeOnOneTouchPlayEnabled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecTvWakeOnOneTouchPlayDisabled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecTvWakeOnOneTouchPlayDisabled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecTvSendStandbyOnSleep_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecTvSendStandbyOnSleepEnabled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecTvSendStandbyOnSleepEnabled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecTvSendStandbyOnSleepDisabled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecTvSendStandbyOnSleepDisabled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTv_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvNone_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvNone_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvOne_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvOne_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvTwo_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvTwo_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvThree_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvThree_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvFour_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileTvFour_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceRootMenu_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceRootMenuHandled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceRootMenuHandled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceRootMenuNotHandled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceRootMenuNotHandled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceSetupMenu_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceSetupMenuHandled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceSetupMenuHandled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceSetupMenuNotHandled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceSetupMenuNotHandled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceContentsMenu_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceContentsMenuHandled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceContentsMenuHandled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceContentsMenuNotHandled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceContentsMenuNotHandled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceTopMenu_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceTopMenuHandled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceTopMenuHandled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceTopMenuNotHandled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceTopMenuNotHandled_default);
+
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenu_userConfigurable);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenuHandled_allowed);
+ doReturn(false).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenuHandled_default);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenuNotHandled_allowed);
+ doReturn(true).when(resources).getBoolean(
+ R.bool.config_cecRcProfileSourceMediaContextSensitiveMenuNotHandled_default);
+
+ return resources;
+ }
+
+ FakeHdmiCecConfig(@NonNull Context context) {
+ super(buildContext(context), new StorageAdapter(context));
}
}
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 798cf85..c834510 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecConfigTest.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecConfigTest.java
@@ -20,6 +20,7 @@
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -27,6 +28,7 @@
import android.annotation.NonNull;
import android.content.Context;
+import android.content.res.Resources;
import android.hardware.hdmi.HdmiControlManager;
import android.os.test.TestLooper;
import android.platform.test.annotations.Presubmit;
@@ -35,6 +37,8 @@
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
+import com.android.internal.R;
+
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -61,265 +65,118 @@
@Mock private HdmiCecConfig.StorageAdapter mStorageAdapter;
@Mock private HdmiCecConfig.SettingChangeListener mSettingChangeListener;
+ private void setBooleanResource(int resId, boolean value) {
+ Resources resources = mContext.getResources();
+ doReturn(value).when(resources).getBoolean(resId);
+ }
+
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mContext = InstrumentationRegistry.getTargetContext();
- }
-
- @Test
- public void getAllCecSettings_NoMasterXml() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter, null, null);
- assertThat(hdmiCecConfig.getAllSettings()).isEmpty();
- }
-
- @Test
- public void getAllCecSettings_Empty() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter,
- "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
- + "<cec-settings>"
- + "</cec-settings>", null);
- assertThat(hdmiCecConfig.getAllSettings()).isEmpty();
+ mContext = FakeHdmiCecConfig.buildContext(InstrumentationRegistry.getTargetContext());
}
@Test
public void getAllCecSettings_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>"
- + " <setting name=\"send_standby_on_sleep\""
- + " value-type=\"string\""
- + " user-configurable=\"false\">"
- + " <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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getAllSettings())
.containsExactly(HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
- HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE);
+ HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_VERSION,
+ HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE,
+ HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
+ HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
+ HdmiControlManager.CEC_SETTING_NAME_VOLUME_CONTROL_MODE,
+ HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY,
+ HdmiControlManager.CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_TV,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU,
+ HdmiControlManager
+ .CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU);
}
@Test
- public void getUserCecSettings_NoMasterXml() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter, null, null);
- assertThat(hdmiCecConfig.getUserSettings()).isEmpty();
- }
-
- @Test
- public void getUserCecSettings_Empty() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter,
- "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
- + "<cec-settings>"
- + "</cec-settings>", null);
- assertThat(hdmiCecConfig.getUserSettings()).isEmpty();
- }
-
- @Test
- public void getUserCecSettings_OnlyMasterXml() {
- 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>"
- + " <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);
+ public void getUserCecSettings_BasicSanity() {
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getUserSettings())
.containsExactly(HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
- HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE);
+ HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_VERSION,
+ HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE,
+ HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
+ HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
+ HdmiControlManager.CEC_SETTING_NAME_VOLUME_CONTROL_MODE,
+ HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY,
+ HdmiControlManager.CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_TV,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU,
+ HdmiControlManager
+ .CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU);
}
@Test
public void getUserCecSettings_WithOverride() {
- 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>"
- + " <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>",
- "<?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\" />"
- + " <value string-value=\"broadcast\" />"
- + " <value string-value=\"none\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"to_tv\" />"
- + " </setting>"
- + "</cec-settings>");
+ setBooleanResource(R.bool.config_cecHdmiCecEnabled_userConfigurable, false);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getUserSettings())
- .containsExactly(HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED);
- }
-
- @Test
- public void isStringValueType_NoMasterXml() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter, null, null);
- assertThrows(IllegalArgumentException.class,
- () -> hdmiCecConfig.isStringValueType("foo"));
+ .containsExactly(HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_VERSION,
+ HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE,
+ HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
+ HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
+ HdmiControlManager.CEC_SETTING_NAME_VOLUME_CONTROL_MODE,
+ HdmiControlManager.CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY,
+ HdmiControlManager.CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_TV,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU,
+ HdmiControlManager.CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU,
+ HdmiControlManager
+ .CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU);
}
@Test
public void isStringValueType_InvalidSetting() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter,
- "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
- + "<cec-settings>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.isStringValueType("foo"));
}
@Test
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\" />"
- + " <value string-value=\"broadcast\" />"
- + " <value string-value=\"none\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"to_tv\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertTrue(hdmiCecConfig.isStringValueType(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE));
}
@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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedStringValues(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED));
@@ -327,21 +184,7 @@
@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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getAllowedStringValues(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE))
.containsExactly(HdmiControlManager.POWER_CONTROL_MODE_TV,
@@ -350,41 +193,25 @@
}
@Test
- public void getAllowedIntValues_NoMasterXml() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter, null, null);
- assertThrows(IllegalArgumentException.class,
- () -> hdmiCecConfig.getAllowedIntValues("foo"));
+ public void getAllowedStringValues_WithOverride() {
+ setBooleanResource(R.bool.config_cecPowerControlModeNone_allowed, false);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
+ assertThat(hdmiCecConfig.getAllowedStringValues(
+ HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE))
+ .containsExactly(HdmiControlManager.POWER_CONTROL_MODE_TV,
+ HdmiControlManager.POWER_CONTROL_MODE_BROADCAST);
}
@Test
public void getAllowedIntValues_InvalidSetting() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter,
- "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
- + "<cec-settings>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedIntValues("foo"));
}
@Test
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\" />"
- + " <value string-value=\"broadcast\" />"
- + " <value string-value=\"none\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"to_tv\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getAllowedIntValues(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE));
@@ -392,20 +219,7 @@
@Test
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getAllowedIntValues(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED))
.containsExactly(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED,
@@ -413,62 +227,24 @@
}
@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 int-value=\"0x00\" />"
- + " <value int-value=\"0x01\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0x01\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ public void getAllowedIntValues_WithOverride() {
+ setBooleanResource(R.bool.config_cecHdmiCecControlDisabled_allowed, false);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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.getDefaultStringValue("foo"));
+ .containsExactly(HdmiControlManager.HDMI_CEC_CONTROL_ENABLED);
}
@Test
public void getDefaultStringValue_InvalidSetting() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter,
- "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
- + "<cec-settings>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultStringValue("foo"));
}
@Test
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultStringValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED));
@@ -476,62 +252,46 @@
@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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getDefaultStringValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE))
.isEqualTo(HdmiControlManager.POWER_CONTROL_MODE_TV);
}
@Test
- public void getDefaultIntValue_NoMasterXml() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter, null, null);
- assertThrows(IllegalArgumentException.class,
- () -> hdmiCecConfig.getDefaultIntValue("foo"));
+ public void getDefaultStringValue_WithOverride() {
+ setBooleanResource(R.bool.config_cecPowerControlModeTv_default, false);
+ setBooleanResource(R.bool.config_cecPowerControlModeBroadcast_default, true);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
+ assertThat(hdmiCecConfig.getDefaultStringValue(
+ HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE))
+ .isEqualTo(HdmiControlManager.POWER_CONTROL_MODE_BROADCAST);
+ }
+
+ @Test
+ public void getDefaultStringValue_MultipleDefaults() {
+ setBooleanResource(R.bool.config_cecPowerControlModeBroadcast_default, true);
+ assertThrows(RuntimeException.class,
+ () -> new HdmiCecConfig(mContext, mStorageAdapter));
+ }
+
+ @Test
+ public void getDefaultStringValue_NoDefault() {
+ setBooleanResource(R.bool.config_cecPowerControlModeTv_default, false);
+ assertThrows(RuntimeException.class,
+ () -> new HdmiCecConfig(mContext, mStorageAdapter));
}
@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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getDefaultIntValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE));
@@ -539,81 +299,32 @@
@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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getDefaultIntValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_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 int-value=\"0x00\" />"
- + " <value int-value=\"0x01\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0x01\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ public void getDefaultIntValue_WithOverride() {
+ setBooleanResource(R.bool.config_cecHdmiCecControlEnabled_default, false);
+ setBooleanResource(R.bool.config_cecHdmiCecControlDisabled_default, true);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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"));
+ .isEqualTo(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED);
}
@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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getStringValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED));
@@ -625,21 +336,7 @@
Global.HDMI_CONTROL_SEND_STANDBY_ON_SLEEP,
HdmiControlManager.POWER_CONTROL_MODE_TV))
.thenReturn(HdmiControlManager.POWER_CONTROL_MODE_BROADCAST);
- 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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getStringValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE))
.isEqualTo(HdmiControlManager.POWER_CONTROL_MODE_BROADCAST);
@@ -652,61 +349,22 @@
HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_NONE))
.thenReturn(
HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW);
- 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\" />"
- + " <value string-value=\"standby_now\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"none\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getStringValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST))
.isEqualTo(HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW);
}
@Test
- public void getIntValue_NoMasterXml() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter, null, null);
- assertThrows(IllegalArgumentException.class,
- () -> hdmiCecConfig.getIntValue("foo"));
- }
-
- @Test
public void getIntValue_InvalidSetting() {
- HdmiCecConfig hdmiCecConfig = HdmiCecConfig.createFromStrings(
- mContext, mStorageAdapter,
- "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
- + "<cec-settings>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getIntValue("foo"));
}
@Test
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.getIntValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE));
@@ -718,45 +376,7 @@
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_GlobalSetting_HexValue() {
- when(mStorageAdapter.retrieveGlobalSetting(
- 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 int-value=\"0x0\" />"
- + " <value int-value=\"0x1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0x1\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThat(hdmiCecConfig.getIntValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED))
.isEqualTo(HdmiControlManager.HDMI_CEC_CONTROL_DISABLED);
@@ -768,61 +388,23 @@
HdmiControlManager.CEC_SETTING_NAME_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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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\" />"
- + " <value string-value=\"broadcast\" />"
- + " <value string-value=\"none\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"to_tv\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ setBooleanResource(R.bool.config_cecSendStandbyOnSleep_userConfigurable, false);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setStringValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE,
@@ -831,21 +413,7 @@
@Test
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\" />"
- + " <value string-value=\"broadcast\" />"
- + " <value string-value=\"none\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"to_tv\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setStringValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE,
@@ -854,21 +422,7 @@
@Test
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\" />"
- + " <value string-value=\"broadcast\" />"
- + " <value string-value=\"none\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"to_tv\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
hdmiCecConfig.setStringValue(HdmiControlManager.CEC_SETTING_NAME_POWER_CONTROL_MODE,
HdmiControlManager.POWER_CONTROL_MODE_BROADCAST);
verify(mStorageAdapter).storeGlobalSetting(
@@ -878,20 +432,7 @@
@Test
public void setStringValue_SharedPref_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\" />"
- + " <value string-value=\"standby_now\" />"
- + " </allowed-values>"
- + " <default-value string-value=\"none\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
hdmiCecConfig.setStringValue(
HdmiControlManager.CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
HdmiControlManager.POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW);
@@ -901,40 +442,16 @@
}
@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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
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);
+ setBooleanResource(R.bool.config_cecHdmiCecEnabled_userConfigurable, false);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setIntValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
@@ -943,20 +460,7 @@
@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);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
assertThrows(IllegalArgumentException.class,
() -> hdmiCecConfig.setIntValue(
HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
@@ -965,43 +469,7 @@
@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(
- Global.HDMI_CONTROL_ENABLED,
- 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 int-value=\"0x0\" />"
- + " <value int-value=\"0x1\" />"
- + " </allowed-values>"
- + " <default-value int-value=\"0x1\" />"
- + " </setting>"
- + "</cec-settings>", null);
+ HdmiCecConfig hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
hdmiCecConfig.setIntValue(HdmiControlManager.CEC_SETTING_NAME_HDMI_CEC_ENABLED,
HdmiControlManager.HDMI_CEC_CONTROL_DISABLED);
verify(mStorageAdapter).storeGlobalSetting(
@@ -1011,20 +479,7 @@
@Test
public void setIntValue_SharedPref_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 hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
hdmiCecConfig.setIntValue(
HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
HdmiControlManager.SYSTEM_AUDIO_MODE_MUTING_DISABLED);
@@ -1035,20 +490,7 @@
@Test
public void registerChangeListener_SharedPref_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 hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
hdmiCecConfig.registerChangeListener(
HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
mSettingChangeListener);
@@ -1061,20 +503,7 @@
@Test
public void removeChangeListener_SharedPref_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 hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
hdmiCecConfig.registerChangeListener(
HdmiControlManager.CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
mSettingChangeListener);
@@ -1100,20 +529,7 @@
String originalValue = Global.getString(mContext.getContentResolver(),
Global.HDMI_CONTROL_ENABLED);
try {
- 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 hdmiCecConfig = new HdmiCecConfig(mContext, mStorageAdapter);
hdmiCecConfig.registerGlobalSettingsObserver(mTestLooper.getLooper());
HdmiCecConfig.SettingChangeListener latchUpdateListener =
new HdmiCecConfig.SettingChangeListener() {