设置-显示-屏保,
打开关闭
设置代码在 ./packages/apps/Settings/src/com/android/settings/dream/DreamMainSwitchPreferenceController.java
,
@Override
public boolean isChecked() {
return mBackend.isEnabled();
}
@Override
public boolean setChecked(boolean isChecked) {
mBackend.setEnabled(isChecked);
return true;
}
追溯到 ./frameworks/base/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java
,
public boolean isEnabled() {
return getBoolean(Settings.Secure.SCREENSAVER_ENABLED, mDreamsEnabledByDefault);
}
public void setEnabled(boolean value) {
logd("setEnabled(%s)", value);
setBoolean(Settings.Secure.SCREENSAVER_ENABLED, value);
}
启用时机
可选 充电时、插入基座充电时,
设置代码在 ./packages/apps/Settings/src/com/android/settings/dream/WhenToDreamPicker.java
,
@Override
protected String getDefaultKey() {
return DreamSettings.getKeyFromSetting(mBackend.getWhenToDreamSetting());
}
@Override
protected boolean setDefaultKey(String key) {
mBackend.setWhenToDream(DreamSettings.getSettingFromPrefKey(key));
return true;
}
追溯到 ./frameworks/base/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java
,
@WhenToDream
public int getWhenToDreamSetting() {
return isActivatedOnDock() && isActivatedOnSleep() ? EITHER
: isActivatedOnDock() ? WHILE_DOCKED
: isActivatedOnSleep() ? WHILE_CHARGING
: NEVER;
}
public void setWhenToDream(@WhenToDream int whenToDream) {
setEnabled(whenToDream != NEVER);
switch (whenToDream) {
case WHILE_CHARGING:
setActivatedOnDock(false);
setActivatedOnSleep(true);
break;
case WHILE_DOCKED:
setActivatedOnDock(true);
setActivatedOnSleep(false);
break;
case EITHER:
setActivatedOnDock(true);
setActivatedOnSleep(true);
break;
case NEVER:
default:
break;
}
}
充电时
public boolean isActivatedOnSleep() {
return getBoolean(Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
mDreamsActivatedOnSleepByDefault);
}
public void setActivatedOnSleep(boolean value) {
logd("setActivatedOnSleep(%s)", value);
setBoolean(Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, value);
}
插入基座充电时
public boolean isActivatedOnDock() {
return getBoolean(Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
mDreamsActivatedOnDockByDefault);
}
public void setActivatedOnDock(boolean value) {
logd("setActivatedOnDock(%s)", value);
}
默认选项
默认值配置在 frameworks/base/core/res/res/values/config.xml
,
<!-- Specifies whether the dreams feature should be supported.
When true, the system will allow the user to configure dreams (screensavers)
to launch when a user activity timeout occurs or the system is told to nap.
When false, the dreams feature will be disabled (this does not affect dozing).
Consider setting this resource to false or disabling dreams by default when a
doze component is specified below since dreaming will supercede dozing and
will prevent the system from entering a low power state until the dream ends. -->
<bool name="config_dreamsSupported">true</bool>
<!-- If supported, are dreams enabled? (by default) -->
<bool name="config_dreamsEnabledByDefault">true</bool>
<!-- If supported and enabled, are dreams activated when docked? (by default) -->
<bool name="config_dreamsActivatedOnDockByDefault">true</bool>
<!-- If supported and enabled, are dreams activated when asleep and charging? (by default) -->
<bool name="config_dreamsActivatedOnSleepByDefault">false</bool>
<!-- ComponentName of the default dream (Settings.Secure.DEFAULT_SCREENSAVER_COMPONENT) -->
<string name="config_dreamsDefaultComponent" translatable="false">com.android.deskclock/com.android.deskclock.Screensaver</string>
key | value |
---|---|
config_dreamsSupported | 是否支持屏保 |
config_dreamsEnabledByDefault | 屏保是否默认打开 |
config_dreamsActivatedOnDockByDefault | 屏保默认选择 插入基座充电时 |
config_dreamsActivatedOnSleepByDefault | 屏保默认选择 充电时 |
config_dreamsDefaultComponent | 默认屏保组件 |
adb调试
查找屏保 screensaver 相关属性 ,
console:/ # settings list secure | grep screensaver
screensaver_activate_on_dock=0
screensaver_activate_on_sleep=1
screensaver_default_component=com.android.deskclock/com.android.deskclock.Screensaver
screensaver_enabled=1
打开/关闭 屏保
settings put secure screensaver_enabled 1/0