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>&lt;!-- Control whether Night display is available. This should only be enabled
44      on devices with HWC 2 color transform  support. --&gt;
45 &lt;bool name="config_nightDisplayAvailable">false&lt;/bool&gt;
46 &lt;!-- 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 --&gt;
52 &lt;integer name="config_defaultNightDisplayAutoMode">0&lt;/integer&gt;
53 &lt;!-- Default time when Night display is automatically activated.
54      Represented as milliseconds from midnight (e.g. 79200000 == 10pm). --&gt;
55 &lt;integer name="config_defaultNightDisplayCustomStartTime">79200000&lt;/integer&gt;
56 &lt;!-- Default time when Night display is automatically deactivated.
57      Represented as milliseconds from midnight (e.g. 21600000 == 6am). --&gt;
58 &lt;integer name="config_defaultNightDisplayCustomEndTime">21600000&lt;/integer&gt;
59</pre>
60<p>
61The code is divided between framework, system services, SystemUI, and Settings:
62</p>
63<pre>platform/frameworks/base/core
64java/android/provider/Settings.java
65java/com/android/internal/app/NightDisplayController.java
66res/res/values/config.xml
67
68platform/frameworks/base/proto/src/metrics_constants.proto
69
70platform/frameworks/base/services
71core/java/com/android/server/display/DisplayManagerService.java
72core/java/com/android/server/display/DisplayTransformManager.java
73core/java/com/android/server/display/NightDisplayService.java
74java/com/android/server/SystemServer.java
75
76platform/frameworks/base/packages/SystemUI
77res/drawable/ic_qs_night_display_off.xml
78res/drawable/ic_qs_night_display_on.xml
79res/values/strings.xml
80src/com/android/systemui/qs/tiles/NightDisplayTile.java
81
82platform/packages/apps/Settings
83AndroidManifest.xml
84res/drawable/ic_settings_night_display.xml
85res/values/strings.xml
86res/xml/display_settings.xml
87res/xml/night_display_settings.xml
88src/com/android/settings/Settings.java
89src/com/android/settings/dashboard/conditional/NightDisplayCondition.java
90src/com/android/settings/display/NightDisplayPreference.java
91src/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 &gt; Display &gt; 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 &gt; Display &gt; Night Light</em>.
139</p>
140