jellybean的suspend策略变动

最近查看代码,发现android的suspend策略有变动了


在ICS上,当暗屏/亮屏时,会调用powerManagerService的setPowerState,最终会调到 hardware/libhardware_legacy/power/power.c下的set_screen_state,在这个函数中,通过向/sys/power/state中写入 “mem”或"on",让系统进入early suspend。进入early suspend后,若没人持有wakelock,则系统即进入suspend状态了。


再看下Jellybean的代码,之前的power.c这个hal,已经不存在了。搜索源码,发现相关功能的实现,已经挪到 system/core/libsuspend下,而且实现方式也有所改变(PowerManagerService的调用方式还是一样):

将功能模块命名的更合理了:以前叫screen_state, 现在叫auto suspend

方法调用过程也更易读易懂了:以前是通过 set_screen_state(1)和set_screen_state(0)来进入和退出suspend状态,现在改成了autosuspend_enable()和autosuspend_disable()

suspend策略更多了,发现共有三种策略:autosuspend_earlysuspend; autosuspend_autosleep和 autosuspend_wakeup_count。


现在每次调用autosuspend功能时,都尝试着选择三种策略的一种来使用:

static int autosuspend_init(void)
{
    if (autosuspend_inited) {
        return 0;
    }

    autosuspend_inited = true;

    autosuspend_ops = autosuspend_earlysuspend_init();
    if (autosuspend_ops) {
        goto out;
    }

    autosuspend_ops = autosuspend_autosleep_init();
    if (autosuspend_ops) {
        goto out;
    }

    autosuspend_ops = autosuspend_wakeup_count_init();
    if (autosuspend_ops) {
        goto out;
    }

    if (!autosuspend_ops) {
        ALOGE("failed to initialize autosuspend\n");
        return -1;
    }

out:
    ALOGV("autosuspend initialized\n");
    return 0;
}
这里的autosuspend_earlysuspend,和ICS上的suspend,也就是power HAL上的实现是一致的,即early suspend。

从这个初始化代码,也可以看到,三种策略的选择是 earlysuspend > autosleep > wakeup_count, 目前我们还没用到后两种。后两种的机制的原理和工作方法,还要抽空了解下~


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值