More helper methods

This commit is contained in:
Jamorham 2018-01-26 10:29:56 +00:00
parent 69da0cf57a
commit 11fcfb88d4
No known key found for this signature in database
GPG key ID: 0BC5C3E0AAD64DF9

View file

@ -4,13 +4,13 @@ import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.os.PowerManager;
import android.util.Log;
import java.util.HashMap;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.PumpInsight.connector.Connector;
/**
* Created by jamorham on 24/01/2018.
@ -66,4 +66,18 @@ public class Helpers {
return new Handler(MainApp.instance().getMainLooper()).postDelayed(theRunnable, delay);
}
public static PowerManager.WakeLock getWakeLock(final String name, int millis) {
final PowerManager pm = (PowerManager) MainApp.instance().getSystemService(Context.POWER_SERVICE);
if (pm == null) return null;
final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
wl.acquire(millis);
return wl;
}
public static void releaseWakeLock(PowerManager.WakeLock wl) {
if (wl == null) return;
if (wl.isHeld()) wl.release();
}
}