防止后台服务因“检测到派生进程中的CPU过多"而被杀死. [英] Prevent background service from being killed due to "detect excessive cpu on forked process"
问题描述
我正在调试
I am debugging an issue of the Syncthing Android wrapper. The Android application wraps a native binary of the Syncthing project and provides some additional functionality like starting/stopping based on connecting WiFi, power, etc.
不幸的是,出现了服务无法通过WiFi更改自动启动的问题,尤其是在已升级到Android 6的手机上.由于我的个人手机最近已升级到6.0.1,因此我终于能够调试问题,今天我注意到以下内容:
Unfortunately, there have been issues about the service not auto-starting on WiFi change anymore, especially with handsets that have been upgraded to Android 6. Since my personal handset has been upgraded to 6.0.1 recently, I finally am able to debug into the issue and today I noticed the following:
07-06 20:52:26.562 1181 1363 I ActivityManager: [BgDetect]chkExcessCpu doKills: true uptime: 300309
07-06 20:52:26.960 1181 1363 I ActivityManager: [BgDetect]detect excessive cpu on forked process libsyncthing.so(pid : 2758) plan to stop it 371060 during 300309
07-06 20:52:26.960 1181 1363 I ActivityManager: [BgDetect]force stop com.nutomic.syncthingandroid.debug (uid 10132)
07-06 20:52:26.965 1181 1363 I ActivityManager: Force stopping com.nutomic.syncthingandroid.debug appid=10132 user=0: from pid 1181
07-06 20:52:26.966 1181 1363 I ActivityManager: Killing 1360:com.nutomic.syncthingandroid.debug/u0a132 (adj 15): stop com.nutomic.syncthingandroid.debug
07-06 20:52:26.968 1181 1363 W ActivityManager: Scheduling restart of crashed service com.nutomic.syncthingandroid.debug/com.nutomic.syncthingandroid.syncthing.SyncthingService in 1000ms
07-06 20:52:26.968 1181 1354 V ActivityManager: killProcessGroupAsync took 1 ms for PID 1360 on thread 14
07-06 20:52:26.971 1181 6410 I libprocessgroup: Killing pid 2758 in uid 10132 as part of process group 1360
07-06 20:52:26.973 1181 6410 I libprocessgroup: Killing pid 2758 in uid 10132 as part of process group 1360
07-06 20:52:26.974 1181 1363 I ActivityManager: Force stopping service ServiceRecord{47304c8 u0 com.nutomic.syncthingandroid.debug/com.nutomic.syncthingandroid.syncthing.SyncthingService}
在加密,哈希等方面,Syncthing协议在CPU方面非常繁琐.因此,由于派生的本机二进制文件对CPU的要求很高,因此该服务被迫停止.
The Syncthing protocol is quite heavy on the CPU side, regarding encryption, hashing, etc. So it seems that the service is force-stopped due to the high CPU demands of the forked native binary.
该应用程序已被标记为无电池优化",但仍然被杀死.有没有办法防止ActivityManager
由于派生进程的CPU需求而终止应用程序?
The application is already marked as "No battery optimization", but still it is being killed. Is there a way to prevent the ActivityManager
from killing the application due to the CPU demands of the forked process?
推荐答案
不幸的是,这是OnePlus/OxygenOS功能,它将基于谁知道什么规则终止任何后台进程,从而使电池寿命更长.
Unfortunately, this is a OnePlus / OxygenOS feature that will kill any background process based on who-knows what rules in order to give the appearance of a better battery life.
就目前而言,我在 GitHub问题中找到了一种非代码的解决方法似乎有帮助,但远非理想:在最近"屏幕上固定/锁定应用程序.
For now, I found a non-code workaround in a GitHub issue that seems to help, but is far from ideal: pin/lock the application on the recents screen.
这篇关于防止后台服务因“检测到派生进程中的CPU过多"而被杀死.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!