page.title=Implementing Night Light @jd:body
Research suggests that blue light from screens can have a negative impact on sleep. Android 7.1.1 includes a feature called Night Light that reduces the amount of blue light emitted by the device display to better match the natural light of the user's time of day and location.
Night Light requires a
Hardware
Composer HAL 2.0 (HWC 2) implementation that can apply the matrix passed to
setColorTransform
to perform tinting without impacting power,
performance, and app compatibility.
Device manufacturers can enable the default implementation of the feature by
using the following flags defined in:
/android/frameworks/base/core/res/res/values/config.xml
<!-- Control whether Night display is available. This should only be enabled on devices with HWC 2 color transform support. --> <bool name="config_nightDisplayAvailable">false</bool> <!-- Default mode to control how Night display is automatically activated. One of the following values (see NightDisplayController.java): 0 - AUTO_MODE_DISABLED 1 - AUTO_MODE_CUSTOM 2 - AUTO_MODE_TWILIGHT --> <integer name="config_defaultNightDisplayAutoMode">0</integer> <!-- Default time when Night display is automatically activated. Represented as milliseconds from midnight (e.g. 79200000 == 10pm). --> <integer name="config_defaultNightDisplayCustomStartTime">79200000</integer> <!-- Default time when Night display is automatically deactivated. Represented as milliseconds from midnight (e.g. 21600000 == 6am). --> <integer name="config_defaultNightDisplayCustomEndTime">21600000</integer>
The code is divided between framework, system services, SystemUI, and Settings:
platform/frameworks/base/core ├ java/android/provider/Settings.java ├ java/com/android/internal/app/NightDisplayController.java └ res/res/values/config.xml platform/frameworks/base/proto/src/metrics_constants.proto platform/frameworks/base/services ├ core/java/com/android/server/display/DisplayManagerService.java ├ core/java/com/android/server/display/DisplayTransformManager.java ├ core/java/com/android/server/display/NightDisplayService.java └ java/com/android/server/SystemServer.java platform/frameworks/base/packages/SystemUI ├ res/drawable/ic_qs_night_display_off.xml ├ res/drawable/ic_qs_night_display_on.xml ├ res/values/strings.xml └ src/com/android/systemui/qs/tiles/NightDisplayTile.java platform/packages/apps/Settings ├ AndroidManifest.xml ├ res/drawable/ic_settings_night_display.xml ├ res/values/strings.xml ├ res/xml/display_settings.xml ├ res/xml/night_display_settings.xml ├ src/com/android/settings/Settings.java ├ src/com/android/settings/dashboard/conditional/NightDisplayCondition.java ├ src/com/android/settings/display/NightDisplayPreference.java └ src/com/android/settings/display/NightDisplaySettings.java
Because Night Light is a user-facing feature, users need to be able to control it. There is a full implementation of the settings in the Android Open Source Project (AOSP) packages/apps/Settings project that device manufacturers can reference for their Settings implementation.
The settings for Night Light are in Settings > Display > Night Light. From there, users can learn about Night Light, set its schedule, and turn it on or off.
Visible at the top of Settings when Night Light is on.
The Quick Settings tile behaves identically to the On / Off toggle in Settings > Display > Night Light.