package xyz.monkeytong.hongbao.utils;

import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;

/**
 * Created by Zhongyi on 1/29/16.
 */
public class PowerUtil {
    private PowerManager.WakeLock wakeLock;
    private KeyguardManager.KeyguardLock keyguardLock;

    public PowerUtil(Context context) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                "HongbaoWakelock");
        KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        keyguardLock = km.newKeyguardLock("HongbaoKeyguardLock");

    }

    private void acquire() {
        wakeLock.acquire();
        keyguardLock.disableKeyguard();
    }

    private void release() {
        wakeLock.release();
        keyguardLock.reenableKeyguard();
    }

    public void handleWakeLock(boolean isWake) {
        if (isWake) {
            this.acquire();
        } else {
            this.release();
        }
    }
}

@@ -874,24 +874,61 @@
 release() %7B%0A
+        if (wakeLock.isHeld()) %7B%0A    
         wake
@@ -935,32 +935,36 @@
 Lock.release();%0A
+    
         keyguard
@@ -980,32 +980,42 @@
 ableKeyguard();%0A
+        %7D%0A
     %7D%0A%0A    publi

fix 首次开启服务时PowerManager状态导致崩溃问题