作者:左文欣936 | 来源:互联网 | 2023-09-02 13:19
在第一篇Android8.1Doze模式分析(一)我们知道,进入深度doze模式后调用PowerManagerService.java的setDeviceIdleMode()释放W
在第一篇Android 8.1 Doze模式分析(一)我们知道,进入深度doze模式后调用PowerManagerService.java的setDeviceIdleMode()释放WakeLock,现在我们就开始分析释放WakeLock的流程
PowerManagerService.java-->setDeviceIdleMode()
@Override
public boolean setDeviceIdleMode(boolean enabled) {
return setDeviceIdleModeInternal(enabled);
}
PowerManagerService.java-->setDeviceIdleModeInternal()
boolean setDeviceIdleModeInternal(boolean enabled) {
synchronized (mLock) {
if (mDeviceIdleMode == enabled) {
return false;
}
mDeviceIdleMode = enabled;
updateWakeLockDisabledStatesLocked();
}
if (enabled) {
EventLogTags.writeDeviceIdleOnPhase("power");
} else {
EventLogTags.writeDeviceIdleOffPhase("power");
}
return true;
}
PowerManagerService.java-->updateWakeLockDisabledStatesLocked()
private void updateWakeLockDisabledStatesLocked() {
boolean changed = false;
final int numWakeLocks = mWakeLocks.size();
for (int i = 0; i final WakeLock wakeLock = mWakeLocks.get(i);
if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
== PowerManager.PARTIAL_WAKE_LOCK) {
if (setWakeLockDisabledStateLocked(wakeLock)) {
changed = true;
if (wakeLock.mDisabled) {
// This wake lock is no longer being respected.
notifyWakeLockReleasedLocked(wakeLock);
} else {
notifyWakeLockAcquiredLocked(wakeLock);
}
}
}
}
if (changed) {
mDirty |= DIRTY_WAKE_LOCKS;
updatePowerStateLocked();
}
}
到这里是不是很熟悉,和我们在 Android Sprd省电管理(六)app 待机休眠优化讲到的就是一样了