use of android.app.AlarmManager in project android_frameworks_base by DirtyUnicorns.
the class NetworkStatsService method create.
public static NetworkStatsService create(Context context, INetworkManagementService networkManager) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
NetworkStatsService service = new NetworkStatsService(context, networkManager, alarmManager, wakeLock, NtpTrustedTime.getInstance(context), TelephonyManager.getDefault(), new DefaultNetworkStatsSettings(context), new NetworkStatsObservers(), getDefaultSystemDir(), getDefaultBaseDir());
HandlerThread handlerThread = new HandlerThread(TAG);
Handler.Callback callback = new HandlerCallback(service);
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper(), callback);
service.setHandler(handler, callback);
return service;
}
use of android.app.AlarmManager in project android_frameworks_base by DirtyUnicorns.
the class CountdownConditionProvider method onSubscribe.
@Override
public void onSubscribe(Uri conditionId) {
if (DEBUG)
Slog.d(TAG, "onSubscribe " + conditionId);
mTime = ZenModeConfig.tryParseCountdownConditionId(conditionId);
final AlarmManager alarms = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
final Intent intent = new Intent(ACTION).putExtra(EXTRA_CONDITION_ID, conditionId).setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarms.cancel(pendingIntent);
if (mTime > 0) {
final long now = System.currentTimeMillis();
final CharSequence span = DateUtils.getRelativeTimeSpanString(mTime, now, DateUtils.MINUTE_IN_MILLIS);
if (mTime <= now) {
// in the past, already false
notifyCondition(newCondition(mTime, Condition.STATE_FALSE));
} else {
// in the future, set an alarm
alarms.setExact(AlarmManager.RTC_WAKEUP, mTime, pendingIntent);
}
if (DEBUG)
Slog.d(TAG, String.format("%s %s for %s, %s in the future (%s), now=%s", (mTime <= now ? "Not scheduling" : "Scheduling"), ACTION, ts(mTime), mTime - now, span, ts(now)));
}
}
use of android.app.AlarmManager in project android_frameworks_base by DirtyUnicorns.
the class EventConditionProvider method rescheduleAlarm.
private void rescheduleAlarm(long now, long time) {
mNextAlarmTime = time;
final AlarmManager alarms = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, REQUEST_CODE_EVALUATE, new Intent(ACTION_EVALUATE).addFlags(Intent.FLAG_RECEIVER_FOREGROUND).putExtra(EXTRA_TIME, time), PendingIntent.FLAG_UPDATE_CURRENT);
alarms.cancel(pendingIntent);
if (time == 0 || time < now) {
if (DEBUG)
Slog.d(TAG, "Not scheduling evaluate: " + (time == 0 ? "no time specified" : "specified time in the past"));
return;
}
if (DEBUG)
Slog.d(TAG, String.format("Scheduling evaluate for %s, in %s, now=%s", ts(time), formatDuration(time - now), ts(now)));
alarms.setExact(AlarmManager.RTC_WAKEUP, time, pendingIntent);
}
use of android.app.AlarmManager in project Etar-Calendar by Etar-Group.
the class CalendarAppWidgetProvider method onDisabled.
/**
* {@inheritDoc}
*/
@Override
public void onDisabled(Context context) {
// Unsubscribe from all AlarmManager updates
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingUpdate = getUpdateIntent(context);
am.cancel(pendingUpdate);
}
use of android.app.AlarmManager in project android_frameworks_base by DirtyUnicorns.
the class BluetoothDiscoverableTimeoutReceiver method cancelDiscoverableAlarm.
public static void cancelDiscoverableAlarm(Context context) {
Log.d(TAG, "cancelDiscoverableAlarm(): Enter");
Intent intent = new Intent(INTENT_DISCOVERABLE_TIMEOUT);
intent.setClass(context, BluetoothDiscoverableTimeoutReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_NO_CREATE);
if (pending != null) {
// Cancel any previous alarms that do the same thing.
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pending);
}
}
Aggregations