列出kernel层wake lock 信息
adb shell
cat /sys/power/wake_lock
cat /sys/power/wake_unlock 列出已经release的信息。
列出ap层的wake lock 信息
adb shell dumpsys power
并找到
Wake Locks: size=1
DOZE_WAKE_LOCK 'DreamManagerService' ACQ=-2m38s738ms (uid=1000 pid=1533)
APP申请wake lock
private static PowerManager.WakeLock mWakeLock = null;
private void createWakeLock() {
if (mWakeLock == null) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wakeLockDemo:WakeLockTag");
}
}
private void acquireWakeLock() {
createWakeLock();
if (mWakeLock != null && !mWakeLock.isHeld()) {
mWakeLock.acquire();
Log.d(TAG, "hold WakeLock");
}
}
private void releaseWakeLock() {
if (mWakeLock != null && mWakeLock.isHeld()) {
mWakeLock.release();
Log.d(TAG, "release WakeLock");
}
}