CalendarReceiver.java revision ca9b36fc9a01a2b8b3c1ad3c4e8fb22dc82b5869
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 17package com.android.providers.calendar; 18 19import android.content.ContentProvider; 20import android.content.ContentResolver; 21import android.content.Context; 22import android.content.IContentProvider; 23import android.content.Intent; 24import android.content.BroadcastReceiver; 25 26/** 27 * This IntentReceiver executes when the boot completes and ensures that 28 * the Calendar provider has started and then initializes the alarm 29 * scheduler for the Calendar provider. This needs to be done after 30 * the boot completes because the alarm manager may not have been started 31 * yet. 32 */ 33public class CalendarReceiver extends BroadcastReceiver { 34 35 static final String SCHEDULE = "com.android.providers.calendar.SCHEDULE_ALARM"; 36 37 @Override 38 public void onReceive(Context context, Intent intent) { 39 String action = intent.getAction(); 40 ContentResolver cr = context.getContentResolver(); 41 CalendarProvider provider; 42 IContentProvider icp = cr.acquireProvider("calendar"); 43 provider = (CalendarProvider) ContentProvider. 44 coerceToLocalContentProvider(icp); 45 if (action.equals(SCHEDULE)) { 46 provider.scheduleNextAlarm(); 47 } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { 48 provider.scheduleNextAlarm(); 49 } 50 cr.releaseProvider(icp); 51 } 52} 53