Enable screen timeout in Android 11

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Enable screen timeout in Android 11

1,418 Views
abhiroopnray
Contributor III

Hi,

I am using Android 11.2.6 in a CUSTOM IMX8MPlus board. I want to implement screen timeout after 10 seconds and again screen turn on on double tap.

 

If I write in Settings.System for the value SCREEN_OFF_TIMEOUT nothing is happening.

But if I change in 

<integer name="config_attentiveTimeout">10000</integer>, after 10 seconds the screen is going black.

Is this the correct approach?

But then on double tap the screen is not getting enabled on double-tap.

 

Please let me know the correct way to implement Scree-off timeout in Android.

 

Thanks,

Abhiroop Nandi Ray

0 Kudos
3 Replies

1,322 Views
abhiroopnray
Contributor III

Hi @Dhruvit ,

From my application I want to disable and enable the screen_time_off. If enabled, time off will be in 20 seconds.

But by default it should be disabled.

Changes I have made is shown below.

diff --git a/frameworks/base/core/res/res/values/config.xml b/frameworks/base/core/res/res/values/config.xml
index 5f02eb6a6a..ea6d533c39 100644
--- a/frameworks/base/core/res/res/values/config.xml
+++ b/frameworks/base/core/res/res/values/config.xml
@@ -1291,8 +1291,8 @@
<!-- Screen brightness used to dim the screen when the user activity
timeout expires. May be less than the minimum allowed brightness setting
that can be set by the user. -->
- <integer name="config_screenBrightnessDim">10</integer>
- <item name="config_screenBrightnessDimFloat" format="float" type="dimen">0.05</item>
+ <integer name="config_screenBrightnessDim">0</integer>
+ <item name="config_screenBrightnessDimFloat" format="float" type="dimen">0.0</item>

<!-- Minimum allowable screen brightness to use in a very dark room.
This value sets the floor for the darkest possible auto-brightness
@@ -2196,7 +2196,7 @@
This value must be greater than zero, otherwise the device will immediately
fall asleep again as soon as it is awoken.
-->
- <integer name="config_minimumScreenOffTimeout">10000</integer>
+ <integer name="config_minimumScreenOffTimeout">300000</integer>

<!-- User activity timeout: Maximum screen dim duration in milliseconds.

@@ -2212,7 +2212,7 @@
This value may be zero in which case the screen will not dim before the
device goes to sleep.
-->
- <integer name="config_maximumScreenDimDuration">7000</integer>
+ <integer name="config_maximumScreenDimDuration">0</integer>

<!-- User activity timeout: Maximum screen dim duration as a percentage of screen off timeout.

@@ -3096,7 +3096,7 @@
<bool name="config_allowAnimationsInLowPowerMode">false</bool>

<!-- Whether device supports double tap to wake -->
- <bool name="config_supportDoubleTapWake">false</bool>
+ <bool name="config_supportDoubleTapWake">true</bool>

<!-- The RadioAccessFamilies supported by the device.
Empty is viewed as "all". Only used on devices which

diff --git a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
index 2ffad473e1..e1b0d91207 100644
--- a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
+++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml
@@ -18,7 +18,7 @@
-->
<resources>
<bool name="def_dim_screen">true</bool>
- <integer name="def_screen_off_timeout">60000</integer>
+ <integer name="def_screen_off_timeout">-1</integer>
<integer name="def_sleep_timeout">-1</integer>
<bool name="def_airplane_mode_on">false</bool>
<bool name="def_theater_mode_on">false</bool>
diff --git a/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java b/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
index dee604a3a5..f187b64cee 100644
--- a/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
@@ -189,7 +189,7 @@ public final class PowerManagerService extends SystemService

// Default timeout in milliseconds. This is only used until the settings
// provider populates the actual default value (R.integer.def_screen_off_timeout).
- private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000;
+ private static final int DEFAULT_SCREEN_OFF_TIMEOUT = -1;
private static final int DEFAULT_SLEEP_TIMEOUT = -1;

// Screen brightness boost timeout.

Query 1: By default the screen time off is not getting disabled. How to disable it?

Query 2: When I am executing the code :

fun setAutoDim(timeOut: Int): Boolean {
return try {
Settings.System.putString(
context.contentResolver,
Settings.System.SCREEN_OFF_TIMEOUT,
timeOut.toString()
)
} catch (e: SecurityException) {
pdsLogger.e(TAG, e.message!!)
return false
}
}


I am getting the following exception:
04-25 19:59:10.400 1783 1986 D GlobalExceptionHandler: insert: java.lang.IllegalArgumentException: Invalid value: -1 for setting: screen_off_timeout.

I have WRITE_SECURE_SETTING permission and using it as a System applcation.
I have tried with putInt, putLong and putString.



Let me know how I can enable screen time off for particular period of time.

 

Thanks,

Abhiroop Nandi Ray

 

 

 

 

0 Kudos

1,299 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @abhiroopnray,

I hope you are doing well.

->If one wants to keep the display on all the time or disable the screen time off please kindly refer to the link.
https://community.nxp.com/t5/i-MX-Processors/Android-LL-disable-screen-lock-and-suspend/m-p/447561

->One can use the below-given links to enable the screen time off for reference.
https://stackoverflow.com/questions/1114270/android-screen-timeout
https://stackoverflow.com/questions/10748861/how-to-change-screen-timeout-programmatically

public static final String SCREEN_OFF_TIMEOUT
->The amount of time in milliseconds before the device goes to sleep or begins to dream after a period of inactivity. This value is also known as the user activity timeout period since the screen isn't necessarily turned off when it expires.
->This value is bounded by the maximum timeout set by DevicePolicyManager.setMaximumTimeToLock(ComponentName, long).

I hope this information helps you!

Thanks & Regards,
Dhruvit Vasavada

0 Kudos

1,390 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @abhiroopnray,

I hope you are doing well.

To adjust the screen timeout please use the given below command.
adb shell settings put system screen_off_timeout <time_in_ms>

After setting the value please check via the below-given command.
adb shell settings get system screen_off_timeout

Thanks & Regards,
Dhruvit Vasavada

0 Kudos