android 获取CPU休眠锁
android 禁止CPU休眠
Java
private static PowerManager.WakeLock sCpuWakeLock;
public static PowerManager.WakeLock createPartialWakeLock(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
return pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
public static void acquireCpuWakeLock(Context context) {
if (sCpuWakeLock != null) {
return;
}
sCpuWakeLock = createPartialWakeLock(context);
sCpuWakeLock.acquire();
}
public static void releaseCpuLock() {
if (sCpuWakeLock != null) {
sCpuWakeLock.release();
sCpuWakeLock = null;
}
}
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论