• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.providers.calendar;
18 
19 import android.app.Activity;
20 import android.app.job.JobInfo;
21 import android.app.job.JobScheduler;
22 import android.app.job.JobWorkItem;
23 import android.content.BroadcastReceiver;
24 import android.content.ComponentName;
25 import android.content.Context;
26 import android.content.Intent;
27 import android.provider.CalendarContract;
28 import android.util.Log;
29 import android.util.Slog;
30 
31 public class CalendarProviderBroadcastReceiver extends BroadcastReceiver {
32     private static final String TAG = CalendarProvider2.TAG;
33 
34     @Override
onReceive(Context context, Intent intent)35     public void onReceive(Context context, Intent intent) {
36         String action = intent.getAction();
37         if (!CalendarAlarmManager.ACTION_CHECK_NEXT_ALARM.equals(action)
38                 && !CalendarContract.ACTION_EVENT_REMINDER.equals(action)) {
39             Log.e(TAG, "Received invalid intent: " + intent);
40             setResultCode(Activity.RESULT_CANCELED);
41             return;
42         }
43         if (Log.isLoggable(TAG, Log.DEBUG)) {
44             Log.d(TAG, "Received intent: " + intent);
45         }
46 
47         JobWorkItem jwi = new JobWorkItem(intent);
48         JobInfo alarmJob = new JobInfo.Builder(CalendarProviderJobService.JOB_ID,
49                 new ComponentName(context, CalendarProviderJobService.class))
50                 .setExpedited(true)
51                 .build();
52         JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
53         if (jobScheduler.enqueue(alarmJob, jwi) == JobScheduler.RESULT_SUCCESS) {
54             setResultCode(Activity.RESULT_OK);
55         } else {
56             Slog.wtf(TAG, "Failed to schedule expedited job");
57         }
58     }
59 }
60