当前位置:   article > 正文

Android 屏保开关

Android 屏保开关

设置-显示-屏保,
在这里插入图片描述

在这里插入图片描述

打开关闭

设置代码在 ./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;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

追溯到 ./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);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

启用时机

可选 充电时、插入基座充电时,

设置代码在 ./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;
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

追溯到 ./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;
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

充电时

    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);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

插入基座充电时

    public boolean isActivatedOnDock() {
        return getBoolean(Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
                mDreamsActivatedOnDockByDefault);
    }

    public void setActivatedOnDock(boolean value) {
        logd("setActivatedOnDock(%s)", value);
    }  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

默认选项

默认值配置在 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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
keyvalue
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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/618304
推荐阅读
相关标签
  

闽ICP备14008679号