Code example for PowerManager.WakeLock

Methods: isHeld, release

0
	private static final String TAG = "ManageWakeLocks";
	private static final String POWER_SERVICE = Context.POWER_SERVICE;
	private static WakeLock sWakeLock;
	private static boolean sScreenOn = true;
	static boolean hasLock() { 
		return (sWakeLock != null) && (sWakeLock.isHeld());
	} 
	static void acquire(Context context) {
		if (hasLock()) { 
			sWakeLock.release();
		} 
		if (!sScreenOn) {
			if (sWakeLock == null) {
				sWakeLock = ((PowerManager) context.getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
			} 
			sWakeLock.acquire();
		} 
	} 
	static void release() { 
		if (hasLock()) { 
			sWakeLock.release();
		} 
	} 
	static void setScreenState(boolean screenOn) {
		sScreenOn = screenOn;
		if (screenOn && hasLock()) {