<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Android screen-off timer set as 2 seconds in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Android-screen-off-timer-set-as-2-seconds/m-p/198205#M10700</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;H3 id="toc-hId-1427990438"&gt;1. I tried to reproduce this issue by blow actions:&lt;/H3&gt;&lt;P&gt;a. Power up Android, input Screen-off timer to 2 seconds in console.&lt;/P&gt;&lt;DIV class="panel code"&gt;&lt;DIV class="panelContent codeContent"&gt;&lt;PRE class="code-java"&gt;$ sqlite3 /data/data/com.android.providers.settings/databases/settings.db sqlite&amp;gt; update system set value=&lt;SPAN class="code-quote"&gt;"2000"&lt;/SPAN&gt; where name=&lt;SPAN class="code-quote"&gt;"screen_off_timeout"&lt;/SPAN&gt;; sqlite&amp;gt; .quit &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;b. Unlock the screen and wait for suspend message, about 6 seconds, I can see suspend message output from console. It shows what I see is exactly same as customer’s.&lt;/P&gt;&lt;H3 id="toc-hId--1124166523"&gt;&lt;A name="Androidscreen-offtimersetas2seconds-2.%09Locatethereason." target="_blank"&gt;&lt;/A&gt;2. Locate the reason.&lt;/H3&gt;&lt;P&gt;In “frameworks/base/services/java/com/android/server/PowerManagerService.java”, function private void setTimeoutLocked(long now, final long originalTimeoutOverride, int nextState), we can see below code. For nextState = SCREEN_BRIGHT, it will wait for mKeylightDelay and then enter next state.&lt;/P&gt;&lt;DIV class="panel code"&gt;&lt;DIV class="panelContent codeContent"&gt;&lt;PRE class="code-java"&gt;&lt;SPAN class="code-keyword"&gt;switch&lt;/SPAN&gt; (nextState) {     &lt;SPAN class="code-keyword"&gt;case&lt;/SPAN&gt; SCREEN_BRIGHT:         when = now + mKeylightDelay;         &lt;SPAN class="code-keyword"&gt;break&lt;/SPAN&gt;;     &lt;SPAN class="code-keyword"&gt;case&lt;/SPAN&gt; SCREEN_DIM:         &lt;SPAN class="code-keyword"&gt;if&lt;/SPAN&gt; (mDimDelay &amp;gt;= 0) {             when = now + mDimDelay;             &lt;SPAN class="code-keyword"&gt;break&lt;/SPAN&gt;;         } &lt;SPAN class="code-keyword"&gt;else&lt;/SPAN&gt; {             Slog.w(TAG, &lt;SPAN class="code-quote"&gt;"mDimDelay="&lt;/SPAN&gt; + mDimDelay + &lt;SPAN class="code-quote"&gt;" &lt;SPAN class="code-keyword"&gt;while&lt;/SPAN&gt; trying to dim"&lt;/SPAN&gt;);         }     &lt;SPAN class="code-keyword"&gt;case&lt;/SPAN&gt; SCREEN_OFF:         &lt;SPAN class="code-keyword"&gt;synchronized&lt;/SPAN&gt; (mLocks) {             when = now + mScreenOffDelay;         }         &lt;SPAN class="code-keyword"&gt;break&lt;/SPAN&gt;;     &lt;SPAN class="code-keyword"&gt;default&lt;/SPAN&gt;:         when = now;         &lt;SPAN class="code-keyword"&gt;break&lt;/SPAN&gt;;     } &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;I checked code, mKeylightDelay get its value “LONG_KEYLIGHT_DELAY” in function private void setScreenOffTimeoutsLocked(). And we can see macro definition in this file.&lt;/P&gt;&lt;DIV class="panel code"&gt;&lt;DIV class="panelContent codeContent"&gt;&lt;PRE class="code-java"&gt;    &lt;SPAN class="code-comment"&gt;// time since last state: time since last event: &lt;/SPAN&gt;    &lt;SPAN class="code-comment"&gt;// The &lt;SPAN class="code-object"&gt;short&lt;/SPAN&gt; keylight delay comes from secure settings; &lt;SPAN class="code-keyword"&gt;this&lt;/SPAN&gt; is the &lt;SPAN class="code-keyword"&gt;default&lt;/SPAN&gt;. &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; SHORT_KEYLIGHT_DELAY_DEFAULT = 6000; &lt;SPAN class="code-comment"&gt;// t+6 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; MEDIUM_KEYLIGHT_DELAY = 15000;       &lt;SPAN class="code-comment"&gt;// t+15 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; LONG_KEYLIGHT_DELAY = 6000;        &lt;SPAN class="code-comment"&gt;// t+6 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; LONG_DIM_TIME = 7000;              &lt;SPAN class="code-comment"&gt;// t+N-5 sec&lt;/SPAN&gt; &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;From above definition, we can see that is Android default design method, and we know why we will wait 6 seconds to enter suspend mode even we set screen-off timer as 2 seconds.&lt;/P&gt;&lt;H3 id="toc-hId-618643812"&gt;&lt;A name="Androidscreen-offtimersetas2seconds-3.%09Solution." target="_blank"&gt;&lt;/A&gt;3. Solution.&lt;/H3&gt;&lt;P&gt;a. We should keep minimum screen-off timer as 6 seconds, just following Android default design method.&lt;BR /&gt;b. I tried to modify the macro definition like below, and have a test, it can enter into suspend mode within 2 seconds. However, user experience is not good. Because 2 seconds is too short, e-reader panel response is slow, it is very easy to enter suspend mode, we have to wakeup it frequency.&lt;/P&gt;&lt;DIV class="panel code"&gt;&lt;DIV class="panelContent codeContent"&gt;&lt;PRE class="code-java"&gt;    &lt;SPAN class="code-comment"&gt;// time since last state: time since last event: &lt;/SPAN&gt;    &lt;SPAN class="code-comment"&gt;// The &lt;SPAN class="code-object"&gt;short&lt;/SPAN&gt; keylight delay comes from secure settings; &lt;SPAN class="code-keyword"&gt;this&lt;/SPAN&gt; is the &lt;SPAN class="code-keyword"&gt;default&lt;/SPAN&gt;. &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; SHORT_KEYLIGHT_DELAY_DEFAULT = 1000; &lt;SPAN class="code-comment"&gt;// t+6 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; MEDIUM_KEYLIGHT_DELAY = 9000;       &lt;SPAN class="code-comment"&gt;// t+15 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; LONG_KEYLIGHT_DELAY = 1000;        &lt;SPAN class="code-comment"&gt;// t+6 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; LONG_DIM_TIME = 2000;              &lt;SPAN class="code-comment"&gt;// t+N-5 sec&lt;/SPAN&gt; &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Please tradeoff it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Dec 2011 05:35:35 GMT</pubDate>
    <dc:creator>MarkDing</dc:creator>
    <dc:date>2011-12-29T05:35:35Z</dc:date>
    <item>
      <title>Android screen-off timer set as 2 seconds</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Android-screen-off-timer-set-as-2-seconds/m-p/198205#M10700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;H3 id="toc-hId-1427990438"&gt;1. I tried to reproduce this issue by blow actions:&lt;/H3&gt;&lt;P&gt;a. Power up Android, input Screen-off timer to 2 seconds in console.&lt;/P&gt;&lt;DIV class="panel code"&gt;&lt;DIV class="panelContent codeContent"&gt;&lt;PRE class="code-java"&gt;$ sqlite3 /data/data/com.android.providers.settings/databases/settings.db sqlite&amp;gt; update system set value=&lt;SPAN class="code-quote"&gt;"2000"&lt;/SPAN&gt; where name=&lt;SPAN class="code-quote"&gt;"screen_off_timeout"&lt;/SPAN&gt;; sqlite&amp;gt; .quit &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;b. Unlock the screen and wait for suspend message, about 6 seconds, I can see suspend message output from console. It shows what I see is exactly same as customer’s.&lt;/P&gt;&lt;H3 id="toc-hId--1124166523"&gt;&lt;A name="Androidscreen-offtimersetas2seconds-2.%09Locatethereason." target="_blank"&gt;&lt;/A&gt;2. Locate the reason.&lt;/H3&gt;&lt;P&gt;In “frameworks/base/services/java/com/android/server/PowerManagerService.java”, function private void setTimeoutLocked(long now, final long originalTimeoutOverride, int nextState), we can see below code. For nextState = SCREEN_BRIGHT, it will wait for mKeylightDelay and then enter next state.&lt;/P&gt;&lt;DIV class="panel code"&gt;&lt;DIV class="panelContent codeContent"&gt;&lt;PRE class="code-java"&gt;&lt;SPAN class="code-keyword"&gt;switch&lt;/SPAN&gt; (nextState) {     &lt;SPAN class="code-keyword"&gt;case&lt;/SPAN&gt; SCREEN_BRIGHT:         when = now + mKeylightDelay;         &lt;SPAN class="code-keyword"&gt;break&lt;/SPAN&gt;;     &lt;SPAN class="code-keyword"&gt;case&lt;/SPAN&gt; SCREEN_DIM:         &lt;SPAN class="code-keyword"&gt;if&lt;/SPAN&gt; (mDimDelay &amp;gt;= 0) {             when = now + mDimDelay;             &lt;SPAN class="code-keyword"&gt;break&lt;/SPAN&gt;;         } &lt;SPAN class="code-keyword"&gt;else&lt;/SPAN&gt; {             Slog.w(TAG, &lt;SPAN class="code-quote"&gt;"mDimDelay="&lt;/SPAN&gt; + mDimDelay + &lt;SPAN class="code-quote"&gt;" &lt;SPAN class="code-keyword"&gt;while&lt;/SPAN&gt; trying to dim"&lt;/SPAN&gt;);         }     &lt;SPAN class="code-keyword"&gt;case&lt;/SPAN&gt; SCREEN_OFF:         &lt;SPAN class="code-keyword"&gt;synchronized&lt;/SPAN&gt; (mLocks) {             when = now + mScreenOffDelay;         }         &lt;SPAN class="code-keyword"&gt;break&lt;/SPAN&gt;;     &lt;SPAN class="code-keyword"&gt;default&lt;/SPAN&gt;:         when = now;         &lt;SPAN class="code-keyword"&gt;break&lt;/SPAN&gt;;     } &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;I checked code, mKeylightDelay get its value “LONG_KEYLIGHT_DELAY” in function private void setScreenOffTimeoutsLocked(). And we can see macro definition in this file.&lt;/P&gt;&lt;DIV class="panel code"&gt;&lt;DIV class="panelContent codeContent"&gt;&lt;PRE class="code-java"&gt;    &lt;SPAN class="code-comment"&gt;// time since last state: time since last event: &lt;/SPAN&gt;    &lt;SPAN class="code-comment"&gt;// The &lt;SPAN class="code-object"&gt;short&lt;/SPAN&gt; keylight delay comes from secure settings; &lt;SPAN class="code-keyword"&gt;this&lt;/SPAN&gt; is the &lt;SPAN class="code-keyword"&gt;default&lt;/SPAN&gt;. &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; SHORT_KEYLIGHT_DELAY_DEFAULT = 6000; &lt;SPAN class="code-comment"&gt;// t+6 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; MEDIUM_KEYLIGHT_DELAY = 15000;       &lt;SPAN class="code-comment"&gt;// t+15 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; LONG_KEYLIGHT_DELAY = 6000;        &lt;SPAN class="code-comment"&gt;// t+6 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; LONG_DIM_TIME = 7000;              &lt;SPAN class="code-comment"&gt;// t+N-5 sec&lt;/SPAN&gt; &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;From above definition, we can see that is Android default design method, and we know why we will wait 6 seconds to enter suspend mode even we set screen-off timer as 2 seconds.&lt;/P&gt;&lt;H3 id="toc-hId-618643812"&gt;&lt;A name="Androidscreen-offtimersetas2seconds-3.%09Solution." target="_blank"&gt;&lt;/A&gt;3. Solution.&lt;/H3&gt;&lt;P&gt;a. We should keep minimum screen-off timer as 6 seconds, just following Android default design method.&lt;BR /&gt;b. I tried to modify the macro definition like below, and have a test, it can enter into suspend mode within 2 seconds. However, user experience is not good. Because 2 seconds is too short, e-reader panel response is slow, it is very easy to enter suspend mode, we have to wakeup it frequency.&lt;/P&gt;&lt;DIV class="panel code"&gt;&lt;DIV class="panelContent codeContent"&gt;&lt;PRE class="code-java"&gt;    &lt;SPAN class="code-comment"&gt;// time since last state: time since last event: &lt;/SPAN&gt;    &lt;SPAN class="code-comment"&gt;// The &lt;SPAN class="code-object"&gt;short&lt;/SPAN&gt; keylight delay comes from secure settings; &lt;SPAN class="code-keyword"&gt;this&lt;/SPAN&gt; is the &lt;SPAN class="code-keyword"&gt;default&lt;/SPAN&gt;. &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; SHORT_KEYLIGHT_DELAY_DEFAULT = 1000; &lt;SPAN class="code-comment"&gt;// t+6 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; MEDIUM_KEYLIGHT_DELAY = 9000;       &lt;SPAN class="code-comment"&gt;// t+15 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; LONG_KEYLIGHT_DELAY = 1000;        &lt;SPAN class="code-comment"&gt;// t+6 sec &lt;/SPAN&gt;    &lt;SPAN class="code-keyword"&gt;private&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="code-keyword"&gt;final&lt;/SPAN&gt; &lt;SPAN class="code-object"&gt;int&lt;/SPAN&gt; LONG_DIM_TIME = 2000;              &lt;SPAN class="code-comment"&gt;// t+N-5 sec&lt;/SPAN&gt; &lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Please tradeoff it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Dec 2011 05:35:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Android-screen-off-timer-set-as-2-seconds/m-p/198205#M10700</guid>
      <dc:creator>MarkDing</dc:creator>
      <dc:date>2011-12-29T05:35:35Z</dc:date>
    </item>
  </channel>
</rss>

