Android Open Source - RS-Text-Forwarder-Android-Client Wake Locker






From Project

Back to project page RS-Text-Forwarder-Android-Client.

License

The source code is released under:

GNU General Public License

If you think the Android project RS-Text-Forwarder-Android-Client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.rolisoft.textforwarder;
/*from w  w  w .  ja  v  a2 s.co  m*/
import android.content.Context;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;

public class WakeLocker {

    private static final String TAG = WakeLocker.class.getName();

    private static WakeLock _wl;
    private static int _ctr = 0;

    public static void acquire(Context context)
    {
        release();
        PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
        _wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WakeLock");
        _wl.acquire();

        Log.i(TAG, "Acquired partial wakelock.");
    }

    public static void acquire(Context context, long timeout)
    {
        release();
        PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
        _wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WakeLock");
        _wl.acquire(timeout);

        Log.i(TAG, "Acquired partial wakelock with " + (timeout / 1000) + " sec timeout.");
    }

    public static void release()
    {
        if (_wl != null) {
            _wl.release();
            _wl = null;
            Log.i(TAG, "Released wakelock.");
        }
    }

    public static void push(Context context)
    {
        if (_ctr <= 0 && (_wl == null || !_wl.isHeld())) {
            acquire(context);
            _ctr = 1;
            Log.i(TAG, "Wakelock counter is " + _ctr);
        } else {
            _ctr++;
            Log.i(TAG, "Increased wakelock counter to " + _ctr);
        }
    }

    public static void pushd(Context context)
    {
        push(context);
        push(context);
    }

    public static void pop()
    {
        if (_ctr <= 1 && _wl != null && _wl.isHeld()) {
            _ctr = 0;
            Log.i(TAG, "Wakelock counter is " + _ctr);
            release();
        } else {
            _ctr--;
            Log.i(TAG, "Decreased wakelock counter to " + _ctr);
        }
    }

    public static void popd()
    {
        pop();
        pop();
    }

}




Java Source Code List

eu.chainfire.libsuperuser.Application.java
eu.chainfire.libsuperuser.Debug.java
eu.chainfire.libsuperuser.ShellNotClosedException.java
eu.chainfire.libsuperuser.ShellOnMainThreadException.java
eu.chainfire.libsuperuser.Shell.java
eu.chainfire.libsuperuser.StreamGobbler.java
net.rolisoft.textforwarder.BackgroundIntentService.java
net.rolisoft.textforwarder.CallReceiver.java
net.rolisoft.textforwarder.ContactTools.java
net.rolisoft.textforwarder.Contact.java
net.rolisoft.textforwarder.MainActivity.java
net.rolisoft.textforwarder.MmsReceiver.java
net.rolisoft.textforwarder.PrngFix.java
net.rolisoft.textforwarder.PushReceiver.java
net.rolisoft.textforwarder.ServerError.java
net.rolisoft.textforwarder.SmsReceiver.java
net.rolisoft.textforwarder.TextMessage.java
net.rolisoft.textforwarder.Tuple.java
net.rolisoft.textforwarder.WakeLocker.java