如今去过厂家的SOC,尤其是国产芯片,在设计其Android AOSP系统的时候,基本都会遵循谷歌的架构和规范。本文基于全志H713 Android 11平台,介绍如何给谷歌标准版的TvSettings添加default.xml默认值。
给投影的HDMI CEC功能,配置几个默认值;
根据UI上的字符串,如“TV auto set language”,顺藤摸瓜,在代码中找到set value 的地方,之后进一步找到配置文件位置。
@Override
public boolean onPreferenceTreeClick(Preference preference) {
final String key = preference.getKey();
if (key == null) {
return super.onPreferenceTreeClick(preference);
}
switch (key) {
case KEY_HDMI_CONTROL:
writeCecOption(Settings.Global.HDMI_CONTROL_ENABLED, mHdmiControlPref.isChecked());
/// AW CODE: [feat] support hdmi cec with more switches
setPreferncesEnabled(mHdmiControlPref.isChecked());
/// AW:add end
return true;
case KEY_DEVICE_AUTO_OFF:
writeCecOption(Settings.Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
mDeviceAutoOffPref.isChecked());
return true;
case KEY_TV_AUTO_ON:
writeCecOption(Settings.Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED,
mTvAutoOnPref.isChecked());
return true;
/// AW CODE: [feat] support hdmi cec with more switches
case KEY_TV_AUTO_SET_LANGUAGE:
writeCecOption(Settings.Global.HDMI_CONTROL_AUTO_SET_LANGUAGE,
mTvAutoSetLanguage.isChecked());
return true;
case KEY_TV_AUTO_INPUT_PASSTHROUGH:
writeCecOption(Settings.Global.HDMI_CONTROL_AUTO_INPUT_PASSTHROUGH,
mTvAutoInputPassThrough.isChecked());
return true;
/// AW:add end
/// AW CODE: [feat] add item for AwLiveTv recovery
case KEY_INPUT_RECOVERY:
writeCecOption(Settings.Global.INPUT_RECOVERY,
mInputRecovery.isChecked());
return true;
/// AW:add end
}
return super.onPreferenceTreeClick(preference);
}
false
public static final String HDMI_CONTROL_AUTO_WAKEUP_ENABLED =
"hdmi_control_auto_wakeup_enabled";
/**
* Whether TV will also turn off other CEC devices when it goes to standby mode.
* (0 = false, 1 = true)
*
* @hide
*/
public static final String HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED =
"hdmi_control_auto_device_off_enabled";
/// AW CODE: [feat] HDMI-CEC: supprot device auto power on
/**
* Whether TV will also turn on other CEC devices when it goes to wakeup mode.
* (0 = false, 1 = true)
*
* @hide
*/
public static final String HDMI_CONTROL_AUTO_DEVICE_ON_ENABLED =
"hdmi_control_auto_device_on_enabled";
/// AW: add end.
if (currentVersion == 190) {
// Version 190: get HDMI auto device off from overlay
final SettingsState globalSettings = getGlobalSettingsLocked();
final Setting currentSetting = globalSettings.getSettingLocked(
Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED);
if (currentSetting.isNull()) {
globalSettings.insertSettingLocked(
Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
getContext().getResources().getBoolean(
R.bool.def_hdmiControlAutoDeviceOff) ? "1" : "0",
null, true, SettingsState.SYSTEM_PACKAGE_NAME);
}
currentVersion = 191;
}
// vXXX: Add new settings above this point.
h713-tuna_p3:/ # settings list global | grep hdmi
hdmi_control_auto_device_off_enabled=1
h713-tuna_p3:/ # pwd
h713-tuna_p3:/ # settings list global | grep hdmi
hdmi_control_auto_device_off_enabled=1
hdmi_control_auto_input_passthrough=1
hdmi_control_auto_set_language=1
hdmi_control_auto_wakeup_enabled=1
hdmi_control_enabled=1
h713-tuna_p3:/ # pwd
false
false
if (currentVersion == 191) {
//
final SettingsState globalSettings = getGlobalSettingsLocked();
final Setting currentSetting = globalSettings.getSettingLocked(
Global.HDMI_CONTROL_ENABLED);
if (currentSetting.isNull()) {
globalSettings.insertSettingLocked(
Global.HDMI_CONTROL_ENABLED,
getContext().getResources().getBoolean(
R.bool.def_hdmi_control_enabled) ? "1" : "0",
null, true, SettingsState.SYSTEM_PACKAGE_NAME);
}
currentVersion = 192;
}
if (currentVersion == 192) {
//
final SettingsState globalSettings = getGlobalSettingsLocked();
final Setting currentSetting = globalSettings.getSettingLocked(
Global.HDMI_CONTROL_AUTO_SET_LANGUAGE);
if (currentSetting.isNull()) {
globalSettings.insertSettingLocked(
Global.HDMI_CONTROL_AUTO_SET_LANGUAGE,
getContext().getResources().getBoolean(
R.bool.def_hdmi_control_auto_set_language) ? "1" : "0",
null, true, SettingsState.SYSTEM_PACKAGE_NAME);
}
currentVersion = 193;
}
// vXXX: Add new settings above this point.
C:\Users\szhou\Desktop>adb shell
h713-tuna_p3:/ # settings list global | grep hdmi
hdmi_control_auto_device_off_enabled=0
hdmi_control_auto_set_language=0
hdmi_control_enabled=0
h713-tuna_p3:/ #