简体   繁体   中英

Changing Doze mode parameters programmatically

Question about changing the parameters of the transition to doze mode I have a non-rooted Android 12 device There are a number of parameters for changing the transition time in doze mode:

  • inactive_to
  • motion_inactive_to
  • light_after_inactive_to

If you change these parameters through the PC using ADB, then the parameters are set. For instance:

adb shell device_config put device_idle inactive_to 2592000000

The problem is that after a reboot, the settings are reset. Tried to change them directly in the program

//            val command = arrayOf("/system/bin/device_config", "put", "device_idle", "motion_inactive_to", "2592000000")
val command = arrayOf("/system/bin/settings", "put", "global", "device_idle_constants", "light_after_inactive_to", "2592000000")
Log.d("ADB", "Start ${command.joinToString(separator = " ")}")
val process = Runtime.getRuntime().exec(command)
val bufReader = BufferedReader(InputStreamReader(process.errorStream))
val log = StringBuilder()
var line: String?
line = bufReader.readLine()
while (line != null) {
    log.append(line + "\n")
    line = bufReader.readLine()
}
Log.d("ADB", "Command: $log")

But the first command is answered:

“cmd: Can't find service: "device_config"”

And the second command gives an error:

Permission Denial: getCurrentUser() from pid=28435, uid=10245 requires android.permission.INTERACT_ACROSS_USERS

After searching for information about the INTERACT_ACROSS_USERS permission, I understand that it is necessary for it to make the application system. And for this I need to root the device.

Is there any other way to change the parameters of doze mode or disable it altogether? It's confusing that you can run a command with adb on a non-rooted device, but you can't directly in the program.

Is there any other way to change the parameters of doze mode or disable it altogether?

No. If there were, it would have been pointless to add Doze mode, as every developer would opt out of it.

It's confusing that you can run a command with adb on a non-rooted device, but you can't directly in the program.

Different users/processes having different privileges has been a common concept in operating systems for at least 30 years.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM