// Dirty bit: mWakeLocks changed
private static final int DIRTY_WAKE_LOCKS = 1 << 0;
// Dirty bit: mWakefulness changed
private static final int DIRTY_WAKEFULNESS = 1 << 1;
// Dirty bit: user activity was poked or may have timed out
private static final int DIRTY_USER_ACTIVITY = 1 << 2;
// Dirty bit: actual display power state was updated asynchronously
private static final int DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED = 1 << 3;
// Dirty bit: mBootCompleted changed
private static final int DIRTY_BOOT_COMPLETED = 1 << 4;
// Dirty bit: settings changed
private static final int DIRTY_SETTINGS = 1 << 5;
// Dirty bit: mIsPowered changed
private static final int DIRTY_IS_POWERED = 1 << 6;
// Dirty bit: mStayOn changed
private static final int DIRTY_STAY_ON = 1 << 7;
// Dirty bit: battery state changed
private static final int DIRTY_BATTERY_STATE = 1 << 8;
// Dirty bit: proximity state changed
private static final int DIRTY_PROXIMITY_POSITIVE = 1 << 9;
// Dirty bit: dock state changed
private static final int DIRTY_DOCK_STATE = 1 << 10;
// Dirty bit: brightness boost changed
private static final int DIRTY_SCREEN_BRIGHTNESS_BOOST = 1 << 11;
WakeLock类中实现acquire()和release()方法实际上是调用了PowerManagerService的acquireWakeLock()和releaseWakeLock()方法。
updatePowerStateLocked为PowerManagerService的核心函数;
在执行完申请锁,释放锁,用户事件,强制唤醒/睡眠等操作都需要调用updatePowerStateLocked()来更新电源状态。
private void updatePowerStateLocked() {
//… …省略
// Phase 0: Basic state updates.
// 基本状态更新
updateIsPoweredLocked(mDirty);//BatteryManagerInternal–BatteryService 哪种充电方式 (ac交流、usb充电、无线)<integer name=”config_lowBatteryWarningLevel”>15</integer> 低电池的警告
updateStayOnLocked(mDirty); // 是否有开启”充电保持唤醒”功能
// Phase 1: Update wakefulness.
// Loop because the wake lock and user activity computations are influenced
// by changes in wakefulness.
final long now = SystemClock.uptimeMillis();
int dirtyPhase2 = 0;
for (;;) {
int dirtyPhase1 = mDirty;
dirtyPhase2 |= dirtyPhase1;
mDirty = 0;
//检查当前系统中所有激活的(没有释放)WakeLock
updateWakeLockSummaryLocked(dirtyPhase1);
//更新主动申请的系统状态如bright/dim
updateUserActivitySummaryLocked(now, dirtyPhase1);
// 如果经过前面的检查和更新后,没有新的状态变更则退出循环准备休眠
if (!updateWakefulnessLocked(dirtyPhase1)) {
break;
}
}
// Phase 2: Update dreams and display power state.
// 更新dream屏保状态
updateDreamLocked(dirtyPhase2);
// 更新显示状态,包含关闭/点亮屏幕
updateDisplayPowerStateLocked(dirtyPhase2);
// Phase 3: Send notifications, if needed.
// 休眠/唤醒是否准备完成
if (mDisplayReady) {
sendPendingNotificationsLocked();
}
// Phase 4: Update suspend blocker.
// Because we might release the last suspend blocker here, we need to make sure
// we finished everything else first!
// 休眠/唤醒前最后一步,之后会跳转到native层执行申请/释放锁的操作
updateSuspendBlockerLocked();
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/34928.html