CalendarAlarmManager.java revision 656f9cb431c798c972260f31a4ebcd56047dff21
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.providers.calendar;
18
19import android.app.AlarmManager;
20import android.app.PendingIntent;
21import android.content.ContentResolver;
22import android.content.Context;
23import android.provider.Calendar;
24
25/**
26 * We are using the CalendarAlertManager to be able to mock the AlarmManager as the AlarmManager
27 * cannot be extended.
28 *
29 * CalendarAlertManager is delegating its calls to the real AlarmService.
30 */
31public class CalendarAlarmManager {
32
33    protected static final String TAG = "CalendarAlarmManager";
34
35    private Context mContext;
36    private AlarmManager mAlarmManager;
37
38    public CalendarAlarmManager(Context context) {
39        initializeWithContext(context);
40    }
41
42    protected void initializeWithContext(Context context) {
43        mContext = context;
44        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
45    }
46
47    public void set(int type, long triggerAtTime, PendingIntent operation) {
48        mAlarmManager.set(type, triggerAtTime, operation);
49    }
50
51    public void cancel(PendingIntent operation) {
52        mAlarmManager.cancel(operation);
53    }
54
55    public void scheduleAlarm(long alarmTime) {
56        Calendar.CalendarAlerts.scheduleAlarm(mContext, mAlarmManager, alarmTime);
57    }
58
59    public void rescheduleMissedAlarms(ContentResolver cr) {
60        Calendar.CalendarAlerts.rescheduleMissedAlarms(cr, mContext, mAlarmManager);
61    }
62}
63