use of android.os.PowerManager.WakeLock in project Osmand by osmandapp.
the class NavigationService method onLocationChanged.
@Override
public void onLocationChanged(Location l) {
if (l != null && !settings.MAP_ACTIVITY_ENABLED.get()) {
net.osmand.Location location = OsmAndLocationProvider.convertLocation(l, (OsmandApplication) getApplication());
if (!isContinuous()) {
// unregister listener and wait next time
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try {
locationManager.removeUpdates(this);
} catch (SecurityException e) {
// $NON-NLS-1$
Log.d(PlatformUtil.TAG, "Location service permission not granted");
}
WakeLock lock = getLock(this);
if (lock.isHeld()) {
lock.release();
}
}
locationProvider.setLocationFromService(location, isContinuous());
}
}
use of android.os.PowerManager.WakeLock in project Osmand by osmandapp.
the class OnNavigationServiceAlarmReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
final WakeLock lock = NavigationService.getLock(context);
final NavigationService service = ((OsmandApplication) context.getApplicationContext()).getNavigationService();
// do not do nothing
if (lock.isHeld() || service == null) {
return;
}
//
lock.acquire();
// request location updates
final LocationManager locationManager = (LocationManager) service.getSystemService(Context.LOCATION_SERVICE);
try {
locationManager.requestLocationUpdates(service.getServiceOffProvider(), 0, 0, service);
if (service.getServiceOffInterval() > service.getServiceError()) {
service.getHandler().postDelayed(new Runnable() {
@Override
public void run() {
// if lock is not anymore held
if (lock.isHeld()) {
lock.release();
locationManager.removeUpdates(service);
}
}
}, service.getServiceError());
}
} catch (RuntimeException e) {
e.printStackTrace();
}
}
use of android.os.PowerManager.WakeLock in project ExoPlayer by google.
the class WakeLockManagerTest method stayAwakeTrue_wakeLockIsOnlyHeldWhenEnabled.
@Test
public void stayAwakeTrue_wakeLockIsOnlyHeldWhenEnabled() {
WakeLockManager wakeLockManager = new WakeLockManager(context);
wakeLockManager.setEnabled(true);
wakeLockManager.setStayAwake(true);
WakeLock wakeLock = ShadowPowerManager.getLatestWakeLock();
assertThat(wakeLock.isHeld()).isTrue();
wakeLockManager.setEnabled(false);
assertThat(wakeLock.isHeld()).isFalse();
}
use of android.os.PowerManager.WakeLock in project Signal-Android by WhisperSystems.
the class WakeLockUtil method runWithLock.
/**
* Run a runnable with a wake lock. Ensures that the lock is safely acquired and released.
*
* @param tag will be prefixed with "signal:" if it does not already start with it.
*/
public static void runWithLock(@NonNull Context context, int lockType, long timeout, @NonNull String tag, @NonNull Runnable task) {
WakeLock wakeLock = null;
try {
wakeLock = acquire(context, lockType, timeout, tag);
task.run();
} finally {
if (wakeLock != null) {
release(wakeLock, tag);
}
}
}
use of android.os.PowerManager.WakeLock in project androidannotations by androidannotations.
the class WakeLockActivityTest method testNoWakeLockUsedBefore.
@Test
public void testNoWakeLockUsedBefore() {
WakeLock wakeLock = ShadowPowerManager.getLatestWakeLock();
assertThat(wakeLock).isNull();
}
Aggregations