Search in sources :

Example 1 with WakeLock

use of android.os.PowerManager.WakeLock in project android_frameworks_base by ResurrectionRemix.

the class WakeUpCall method screenOn.

private void screenOn(Context context) {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    @SuppressWarnings("deprecation") WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOG_TAG);
    wl.acquire(500);
}
Also used : PowerManager(android.os.PowerManager) WakeLock(android.os.PowerManager.WakeLock)

Example 2 with WakeLock

use of android.os.PowerManager.WakeLock in project android_packages_apps_OmniClock by omnirom.

the class AlarmInitReceiver method onReceive.

/**
 * Sets alarm on ACTION_BOOT_COMPLETED.  Resets alarm on
 * TIME_SET, TIMEZONE_CHANGED
 */
@Override
public void onReceive(final Context context, Intent intent) {
    final String action = intent.getAction();
    LogUtils.v("AlarmInitReceiver " + action);
    final PendingResult result = goAsync();
    final WakeLock wl = AlarmAlertWakeLock.createPartialWakeLock(context);
    wl.acquire();
    // We need to increment the global id out of the async task to prevent
    // race conditions
    AlarmStateManager.updateGlobalIntentId(context);
    AsyncHandler.post(new Runnable() {

        @Override
        public void run() {
            // Remove the snooze alarm after a boot.
            if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
                // Clear stopwatch and timers data
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
                LogUtils.v("AlarmInitReceiver - Reset timers and clear stopwatch data");
                TimerObj.resetTimersInSharedPrefs(prefs);
                Utils.clearSwSharedPref(prefs);
                if (!prefs.getBoolean(PREF_VOLUME_DEF_DONE, false)) {
                    // Fix the default
                    LogUtils.v("AlarmInitReceiver - resetting volume button default");
                    switchVolumeButtonDefault(prefs);
                }
            }
            if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
            }
            // Update all the alarm instances on time change event
            AlarmStateManager.fixAlarmInstances(context);
            result.finish();
            LogUtils.v("AlarmInitReceiver finished");
            wl.release();
        }
    });
}
Also used : WakeLock(android.os.PowerManager.WakeLock) SharedPreferences(android.content.SharedPreferences)

Example 3 with WakeLock

use of android.os.PowerManager.WakeLock in project Osmand by osmandapp.

the class NavigationService method onDestroy.

@Override
public void onDestroy() {
    super.onDestroy();
    final OsmandApplication app = (OsmandApplication) getApplication();
    app.setNavigationService(null);
    usedBy = 0;
    // remove updates
    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");
    }
    if (!isContinuous()) {
        WakeLock lock = getLock(this);
        if (lock.isHeld()) {
            lock.release();
        }
    }
    if (pendingIntent != null) {
        // remove alarm
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarmManager.cancel(pendingIntent);
    }
    // remove notification
    stopForeground(Boolean.TRUE);
    app.getNotificationHelper().updateTopNotification();
    app.runInUIThread(new Runnable() {

        @Override
        public void run() {
            app.getNotificationHelper().refreshNotifications();
        }
    }, 500);
}
Also used : LocationManager(android.location.LocationManager) WakeLock(android.os.PowerManager.WakeLock) AlarmManager(android.app.AlarmManager)

Example 4 with WakeLock

use of android.os.PowerManager.WakeLock in project ExoPlayer by google.

the class WakeLockManagerTest method stayAwakeFalse_wakeLockIsNeverHeld.

@Test
public void stayAwakeFalse_wakeLockIsNeverHeld() {
    WakeLockManager wakeLockManager = new WakeLockManager(context);
    wakeLockManager.setEnabled(true);
    wakeLockManager.setStayAwake(false);
    WakeLock wakeLock = ShadowPowerManager.getLatestWakeLock();
    assertThat(wakeLock.isHeld()).isFalse();
    wakeLockManager.setEnabled(false);
    assertThat(wakeLock.isHeld()).isFalse();
}
Also used : WakeLock(android.os.PowerManager.WakeLock) Test(org.junit.Test)

Example 5 with WakeLock

use of android.os.PowerManager.WakeLock in project Signal-Android by WhisperSystems.

the class WakeLockUtil method acquire.

/**
 * @param tag will be prefixed with "signal:" if it does not already start with it.
 */
public static WakeLock acquire(@NonNull Context context, int lockType, long timeout, @NonNull String tag) {
    tag = prefixTag(tag);
    try {
        PowerManager powerManager = ServiceUtil.getPowerManager(context);
        WakeLock wakeLock = powerManager.newWakeLock(lockType, tag);
        wakeLock.acquire(timeout);
        return wakeLock;
    } catch (Exception e) {
        Log.w(TAG, "Failed to acquire wakelock with tag: " + tag, e);
        return null;
    }
}
Also used : PowerManager(android.os.PowerManager) WakeLock(android.os.PowerManager.WakeLock)

Aggregations

WakeLock (android.os.PowerManager.WakeLock)14 PowerManager (android.os.PowerManager)5 Test (org.junit.Test)4 LocationManager (android.location.LocationManager)3 AlarmManager (android.app.AlarmManager)1 SharedPreferences (android.content.SharedPreferences)1