Search in sources :

Example 26 with AlarmManager

use of android.app.AlarmManager in project android_frameworks_base by ResurrectionRemix.

the class DevicePolicyManagerService method setExpirationAlarmCheckLocked.

/**
     * Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration
     * reminders.  Clears alarm if no expirations are configured.
     */
private void setExpirationAlarmCheckLocked(Context context, int userHandle, boolean parent) {
    final long expiration = getPasswordExpirationLocked(null, userHandle, parent);
    final long now = System.currentTimeMillis();
    final long timeToExpire = expiration - now;
    final long alarmTime;
    if (expiration == 0) {
        // No expirations are currently configured:  Cancel alarm.
        alarmTime = 0;
    } else if (timeToExpire <= 0) {
        // The password has already expired:  Repeat every 24 hours.
        alarmTime = now + MS_PER_DAY;
    } else {
        // Selecting the next alarm time:  Roll forward to the next 24 hour multiple before
        // the expiration time.
        long alarmInterval = timeToExpire % MS_PER_DAY;
        if (alarmInterval == 0) {
            alarmInterval = MS_PER_DAY;
        }
        alarmTime = now + alarmInterval;
    }
    long token = mInjector.binderClearCallingIdentity();
    try {
        int affectedUserHandle = parent ? getProfileParentId(userHandle) : userHandle;
        AlarmManager am = mInjector.getAlarmManager();
        PendingIntent pi = PendingIntent.getBroadcastAsUser(context, REQUEST_EXPIRE_PASSWORD, new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION), PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT, UserHandle.of(affectedUserHandle));
        am.cancel(pi);
        if (alarmTime != 0) {
            am.set(AlarmManager.RTC, alarmTime, pi);
        }
    } finally {
        mInjector.binderRestoreCallingIdentity(token);
    }
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 27 with AlarmManager

use of android.app.AlarmManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TetherService method cancelAlarmIfNecessary.

private void cancelAlarmIfNecessary() {
    if (mCurrentTethers.size() != 0) {
        if (DEBUG)
            Log.d(TAG, "Tethering still active, not cancelling alarm");
        return;
    }
    Intent intent = new Intent(this, TetherService.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);
    if (DEBUG)
        Log.d(TAG, "Tethering no longer active, canceling recheck");
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 28 with AlarmManager

use of android.app.AlarmManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class TetherService method scheduleAlarm.

private void scheduleAlarm() {
    Intent intent = new Intent(this, TetherService.class);
    intent.putExtra(ConnectivityManager.EXTRA_RUN_PROVISION, true);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    int period = getResources().getInteger(com.android.internal.R.integer.config_mobile_hotspot_provision_check_period);
    long periodMs = period * MS_PER_HOUR;
    long firstTime = SystemClock.elapsedRealtime() + periodMs;
    if (DEBUG)
        Log.d(TAG, "Scheduling alarm at interval " + periodMs);
    alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, firstTime, periodMs, pendingIntent);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 29 with AlarmManager

use of android.app.AlarmManager in project cw-omnibus by commonsguy.

the class PollReceiver method scheduleAlarms.

static void scheduleAlarms(Context ctxt) {
    AlarmManager mgr = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(ctxt, PollReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(ctxt, 0, i, 0);
    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + INITIAL_DELAY, PERIOD, pi);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 30 with AlarmManager

use of android.app.AlarmManager in project HomeMirror by HannahMitt.

the class AlarmReceiver method stopMirrorUpdates.

public static void stopMirrorUpdates(Context context) {
    AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, 0);
    alarmMgr.cancel(alarmIntent);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

AlarmManager (android.app.AlarmManager)471 PendingIntent (android.app.PendingIntent)349 Intent (android.content.Intent)323 Calendar (java.util.Calendar)75 SuppressLint (android.annotation.SuppressLint)24 Date (java.util.Date)24 Context (android.content.Context)22 SharedPreferences (android.content.SharedPreferences)20 SimpleDateFormat (java.text.SimpleDateFormat)18 Test (org.junit.Test)17 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)13 Config (org.robolectric.annotation.Config)13 Handler (android.os.Handler)11 HashMap (java.util.HashMap)11 PowerManager (android.os.PowerManager)10 File (java.io.File)10 Map (java.util.Map)10 Activity (android.app.Activity)9 ShadowAlarmManager (org.robolectric.shadows.ShadowAlarmManager)9 TargetApi (android.annotation.TargetApi)8