简体   繁体   English

以编程方式更改打盹模式参数

[英]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:关于更改休眠模式转换参数的问题我有一个非 root 用户 Android 12 设备有许多参数可用于更改休眠模式下的转换时间:

  • inactive_to inactive_to
  • motion_inactive_to motion_inactive_to
  • light_after_inactive_to light_after_inactive_to

If you change these parameters through the PC using ADB, then the parameters are set.如果您使用 ADB 通过 PC 更改这些参数,则会设置这些参数。 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"” “cmd:找不到服务:“device_config””

And the second command gives an error:第二个命令给出了一个错误:

Permission Denial: getCurrentUser() from pid=28435, uid=10245 requires android.permission.INTERACT_ACROSS_USERS权限拒绝:来自 pid=28435 的 getCurrentUser(),uid=10245 需要 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.查了下INTERACT_ACROSS_USERS权限的资料,了解到是做应用系统需要的。 And for this I need to root the device.为此,我需要对设备进行 root 操作。

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.令人困惑的是,您可以在非根设备上使用 adb 运行命令,但不能直接在程序中运行。

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.不会。如果有的话,添加 Doze 模式将毫无意义,因为每个开发人员都会选择退出它。

It's confusing that you can run a command with adb on a non-rooted device, but you can't directly in the program.令人困惑的是,您可以在非根设备上使用 adb 运行命令,但不能直接在程序中运行。

Different users/processes having different privileges has been a common concept in operating systems for at least 30 years.具有不同权限的不同用户/进程至少 30 年来一直是操作系统中的一个普遍概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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