V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
standin000
V2EX  ›  问与答

安卓 app 不断被唤醒的原因求解

  •  
  •   standin000 · 2017-08-16 12:57:00 +08:00 · 3755 次点击
    这是一个创建于 2447 天前的主题,其中的信息可能已经有所发展或是发生改变。
    装了绿色守护,发现触宝电话不断被唤醒,绿色守护不停的休眠,已经关闭它所有权限,连抱团启动的 iShanghai 也关闭了。没有 root,一定要 root 才能关断他们吗?
    11 条回复    2017-08-21 10:59:41 +08:00
    honeycomb
        1
    honeycomb  
       2017-08-16 13:51:16 +08:00 via Android
    很残酷地,可能是的。
    如果系统是 android7.0 或更高版本,尝试用 appops 的 RUN_IN_BACKGROUND 项辅助一下
    lfk0000
        2
    lfk0000  
       2017-08-16 14:13:03 +08:00
    没 xposed 的绿色守护都已经够弱鸡的了。。。你这还没 root。。。
    试试黑域的 adb 模式吧
    miaomiao888
        3
    miaomiao888  
       2017-08-16 15:14:01 +08:00
    把那些国产都换成 PLAY 版试试?
    66beta
        4
    66beta  
       2017-08-16 15:16:00 +08:00
    卸载了黒域,每天到公司插上充电(下班保持 100%),再也没有这么多烦恼了~~
    standin000
        5
    standin000  
    OP
       2017-08-16 17:02:18 +08:00
    @lfk0000 绿色守护我也用了 adb,黑狱会比绿色守护好在哪里?
    honeycomb
        6
    honeycomb  
       2017-08-16 17:15:20 +08:00
    @standin000

    绿色守护的作者在 bugreport 列出了一些常见的保活措施:
    https://issuetracker.google.com/issues/62480012

    "
    1. Restart the service with a frequent periodic alarm (less than 5 minutes), causing the service being stopped and started again and again. (same applied to JobScheduler and SyncAdapter)
    2. Restart the service inside its Service.onDestroy(), reviving the service immediately upon stopping.
    3. Raise the background service to foreground service, when the screen is off to dodge from observation by user.
    4. Bind to each other within 2 services, to fool the activity manager to consider them as bound services.
    5. Restart service from JNI native library with "am start-service".
    "

    我觉得比较可能是通过另一个应用的 SDK 发出 expilcit Intent 启动,或者 Sync/Job 的方式,它们都能绕过 Force Close
    有 Android 7 的话,RUN_IN_BACKGROUND 应该能对付这里的所有情况
    然而如这个 bug report 所说,7~7.1 的这个实现有 bug(直到 Android 8 DP4 修复),只会杀进程的第一个 service
    honeycomb
        7
    honeycomb  
       2017-08-16 17:17:17 +08:00
    Sync/Job 的话仅仅是系统进入任何一级的 doze/应用被 app standby 就会被推迟到下一个维护窗口
    standin000
        8
    standin000  
    OP
       2017-08-17 10:53:04 +08:00
    @honeycomb 谢谢,我打开了唤醒追踪,发现它是被 KeepAliveJobService 启动,请问有办法屏蔽吗?
    honeycomb
        9
    honeycomb  
       2017-08-17 14:21:16 +08:00
    @standin000

    根据
    https://android.googlesource.com/platform/frameworks/base/+/bef28feba57be7fd6a4d14a85a8229154338b2ed%5E%21/

    有 Android 7+ 的话,AppOps 的 RUN_IN_BACKGROUND 确定能对付这个问题
    “ All jobs for the app are cancelled and no more can be scheduled.”

    使用 AppOps 无需 root,只要有 adb 就可以用

    这些软件把 adb 模式给包装好了:
    https://www.coolapk.com/apk/com.zzzmode.appopsx
    https://www.coolapk.com/apk/rikka.appops


    如果没有 Android7+,就要有 root 权限,可以使用这些方法:

    通过 pm disable 注销 KeepAliveJobService
    具体:
    https://www.coolapk.com/apk/cn.wq.myandroidtools

    通过增加一项 IFW 的规则阻止 KeepAliveJobService 被调用
    具体:
    绿色守护的处方特性

    强制把应用设置为 app standby
    具体:
    绿色守护改用 shallow hibernate 模式(这个可能没意义,你终究是希望把它的 service 杀掉,进程可以保留)


    如果没有 Android7,也没有 root,那就要用 brevent,它会混合使用 app standby+FC,效果至少比绿色守护好一些
    standin000
        10
    standin000  
    OP
       2017-08-21 10:45:29 +08:00
    @honeycomb 谢谢回答,我用的是 android 6,现在已经改装黑域了,开了 adb,但是我的权限禁止记录上仍然有触宝电话的读取本机识别码的记录,不过黑域里没有它出现的记录,不知道它是否在耗电。
    honeycomb
        11
    honeycomb  
       2017-08-21 10:59:41 +08:00   ❤️ 1
    @standin000 可以抓一下 bugreport,用 battery historian v2(需要 docker,docker 官方库里有提供其镜像,无需自行编译)检查应用到底消耗了多少 CPU 时间,wakelock 等

    源代码工程:
    https://github.com/google/battery-historian

    也可以用 wakelock detector (lite),手动给它 adb grant android.permission.DUMP 权限也可
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3801 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 10:26 · PVG 18:26 · LAX 03:26 · JFK 06:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.