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
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:
<!-- 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.
- Turn On Automatically
- Never: Night Light will never turn on automatically and must be activated with the manual On / Off toggle.
- Custom schedule: Night Light turns on at a specified Start time [default: 10:30 p.m.] and off at a specified End time [default: 6:30 a.m.].
- Sunset to sunrise: Night Light turns on at sunset and off at sunrise. The time for sunrise and sunset depends on the device location and the time of year.
- On / Off: Toggle that controls the current state of Night Light. This state respects existing automatic rules. For example, if Night Light is toggled on at 5:30 p.m. (before the automatic rule would turn it on at 10:30 p.m.), Night Light will still turn off at 6:30 a.m. And if Night Light is toggled off at 5:30 a.m. (before it turns off at 6:30 a.m.), it will still turn on at 10:30 p.m.
- Informational text: Teaches the user what Night Light does and why.
Visible at the top of Settings when Night Light is on.
Quick Settings tile
The Quick Settings tile behaves identically to the On / Off toggle in Settings > Display > Night Light.