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