Home | History | Annotate | Download | only in calendar
      1 /*
      2 ** Copyright 2006, 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 ** See the License for the specific language governing permissions and
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** limitations under the License.
     15 */
     16 
     17 package com.android.providers.calendar;
     18 
     19 import android.content.BroadcastReceiver;
     20 import android.content.ContentResolver;
     21 import android.content.Context;
     22 import android.content.Intent;
     23 
     24 /**
     25  * This IntentReceiver executes when the boot completes and ensures that
     26  * the Calendar provider has started and then initializes the alarm
     27  * scheduler for the Calendar provider.  This needs to be done after
     28  * the boot completes because the alarm manager may not have been started
     29  * yet.
     30  */
     31 public class CalendarReceiver extends BroadcastReceiver {
     32 
     33     static final String SCHEDULE = "com.android.providers.calendar.SCHEDULE_ALARM";
     34 
     35     @Override
     36     public void onReceive(Context context, Intent intent) {
     37         String action = intent.getAction();
     38         ContentResolver cr = context.getContentResolver();
     39         if (action.equals(SCHEDULE)) {
     40             cr.update(CalendarProvider2.SCHEDULE_ALARM_URI, null /* values */, null /* where */,
     41                     null /* selectionArgs */);
     42         } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
     43             // Remove alarms from the CalendarAlerts table that have been marked
     44             // as "scheduled" but not fired yet.  We do this because the
     45             // AlarmManagerService loses all information about alarms when the
     46             // power turns off but we store the information in a database table
     47             // that persists across reboots. See the documentation for
     48             // scheduleNextAlarmLocked() for more information.
     49             cr.update(CalendarProvider2.SCHEDULE_ALARM_REMOVE_URI,
     50                     null /* values */, null /* where */, null /* selectionArgs */);
     51         }
     52     }
     53 }
     54