1 <html devsite> 2 <head> 3 <title>Implementing Night Light</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 26 <p> 27 Research suggests that blue light from screens can have a negative impact on 28 sleep. Android 7.1.1 includes a feature called Night Light that reduces the 29 amount of blue light emitted by the device display to better match the natural 30 light of the user's time of day and location. 31 </p> 32 <p> 33 Night Light requires a 34 <a href="/devices/graphics/implement-hwc.html">Hardware 35 Composer HAL 2.0</a> (HWC 2) implementation that can apply the matrix passed to 36 <code>setColorTransform</code> to perform tinting without impacting power, 37 performance, and app compatibility. 38 </p> 39 <h2 id="implementation">Implementation</h2> 40 <p> 41 Device manufacturers can enable the default implementation of the feature by 42 using the following flags defined in: 43 <code><a href="https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml"> 44 /android/frameworks/base/core/res/res/values/config.xml</a></code> 45 46 <pre class="devsite-click-to-copy"> 47 <!-- Control whether Night display is available. This should only be enabled 48 on devices with HWC 2 color transform support. --> 49 <bool name="config_nightDisplayAvailable">false</bool> 50 <!-- Default mode to control how Night display is automatically activated. 51 One of the following values (see NightDisplayController.java): 52 0 - AUTO_MODE_DISABLED 53 1 - AUTO_MODE_CUSTOM 54 2 - AUTO_MODE_TWILIGHT 55 --> 56 <integer name="config_defaultNightDisplayAutoMode">0</integer> 57 <!-- Default time when Night display is automatically activated. 58 Represented as milliseconds from midnight (e.g. 79200000 == 10pm). --> 59 <integer name="config_defaultNightDisplayCustomStartTime">79200000</integer> 60 <!-- Default time when Night display is automatically deactivated. 61 Represented as milliseconds from midnight (e.g. 21600000 == 6am). --> 62 <integer name="config_defaultNightDisplayCustomEndTime">21600000</integer> 63 </pre> 64 <p> 65 The code is divided between framework, system services, SystemUI, and Settings: 66 </p> 67 <pre class="devsite-click-to-copy"> 68 platform/frameworks/base/core 69 java/android/provider/Settings.java 70 java/com/android/internal/app/NightDisplayController.java 71 res/res/values/config.xml 72 73 platform/frameworks/base/proto/src/metrics_constants.proto 74 75 platform/frameworks/base/services 76 core/java/com/android/server/display/DisplayManagerService.java 77 core/java/com/android/server/display/DisplayTransformManager.java 78 core/java/com/android/server/display/NightDisplayService.java 79 java/com/android/server/SystemServer.java 80 81 platform/frameworks/base/packages/SystemUI 82 res/drawable/ic_qs_night_display_off.xml 83 res/drawable/ic_qs_night_display_on.xml 84 res/values/strings.xml 85 src/com/android/systemui/qs/tiles/NightDisplayTile.java 86 87 platform/packages/apps/Settings 88 AndroidManifest.xml 89 res/drawable/ic_settings_night_display.xml 90 res/values/strings.xml 91 res/xml/display_settings.xml 92 res/xml/night_display_settings.xml 93 src/com/android/settings/Settings.java 94 src/com/android/settings/dashboard/conditional/NightDisplayCondition.java 95 src/com/android/settings/display/NightDisplayPreference.java 96 src/com/android/settings/display/NightDisplaySettings.java 97 </pre> 98 99 <h2 id="ui-features">UI features</h2> 100 <p> 101 Because Night Light is a user-facing feature, users need to be able to control 102 it. There is a full implementation of the settings in the Android Open Source 103 Project (AOSP) 104 <a href="https://android.googlesource.com/platform/packages/apps/Settings/">packages/apps/Settings</a> 105 project that device manufacturers can reference for their Settings 106 implementation. 107 </p> 108 <h3 id="settings">Settings</h3> 109 <p> 110 The settings for Night Light are in <em>Settings > Display > Night 111 Light</em>. From there, users can learn about Night Light, set its schedule, 112 and turn it on or off. 113 </p> 114 <ul> 115 <li><strong>Turn On Automatically</strong> 116 <ul> 117 <li><strong>Never</strong>: Night Light will never turn on automatically and 118 must be activated with the manual <strong>On / Off</strong> toggle.</li> 119 <li><strong>Custom schedule</strong>: Night Light turns on at a specified 120 <strong>Start time </strong>[default: 10:30 p.m.] and off at a specified 121 <strong>End time</strong> [default: 6:30 a.m.].</li> 122 <li><strong>Sunset to sunrise</strong>: Night Light turns on at sunset and off 123 at sunrise. The time for sunrise and sunset depends on the device location 124 and the time of year.</li> 125 </ul> 126 </li> 127 <li><strong>On / Off</strong>: Toggle that controls the current state of Night 128 Light. This state respects existing automatic rules. For example, if Night 129 Light is toggled on at 5:30 p.m. (before the automatic rule would turn it on 130 at 10:30 p.m.), Night Light will still turn off at 6:30 a.m. And if Night 131 Light is toggled off at 5:30 a.m. (before it turns off at 6:30 a.m.), it will 132 still turn on at 10:30 p.m.</li> 133 <li><strong>Informational text</strong>: Teaches the user what Night Light does 134 and why.</li> 135 </ul> 136 <h3 id="settings-conditional">Settings conditional</h3> 137 <p> 138 Visible at the top of Settings when Night Light is on. 139 </p> 140 <h3 id="quick-settings-tile">Quick Settings tile</h3> 141 <p> 142 The Quick Settings tile behaves identically to the <strong>On / Off</strong> 143 toggle in <em>Settings > Display > Night Light</em>. 144 </p> 145 146 </body> 147 </html> 148