多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**PowerManagerService.java::BootCompletedReceiver** ~~~ private final class BootCompletedReceiver extendsBroadcastReceiver { publicvoid onReceive(Context context, Intent intent) { bootCompleted();//调用PMS的bootCompleted函数 } } ~~~ **PowerManagerService.java::bootCompleted函数** ~~~ void bootCompleted() { synchronized (mLocks) { mBootCompleted = true; //再次碰见userActivity,根据前面的描述,此时将重新计算屏幕超时时间 userActivity(SystemClock.uptimeMillis(), false, BUTTON_EVENT, true); updateWakeLockLocked();//此处先分析这个函数 mLocks.notifyAll(); } } ~~~ 在以上代码中,再一次遇见了userActivity,暂且对其置之不理。先分析updateWakeLockLocked函数,其代码如下: ~~~ private void updateWakeLockLocked() { /* mStayOnConditions用于控制当插上USB时,手机是否保持唤醒状态。 mBatteryService的isPowered用于判断当前是否处于USB充电状态。 如果满足下面的if条件满,则PMS需要使用wakeLock来确保系统不会掉电 */ if(mStayOnConditions != 0 &&mBatteryService.isPowered(mStayOnConditions)) { mStayOnWhilePluggedInScreenDimLock.acquire(); mStayOnWhilePluggedInPartialLock.acquire(); } else { //如果不满足if条件,则释放对应的wakeLock,这样系统就可以进入休眠状态 mStayOnWhilePluggedInScreenDimLock.release(); mStayOnWhilePluggedInPartialLock.release(); } } ~~~ mStayOnWhilePluggedInScreenDimLock和mStayOnWhilePluggedInPartialLock都为UnsynchronizedWakeLock类型,它们封装了WakeLock,可帮助PMS在使用它们时免遭线程同步之苦。