1 /*
2  * Copyright (C) 2011 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.dialer.calllog;
18 
19 import android.app.IntentService;
20 import android.content.Intent;
21 import android.net.Uri;
22 import android.util.Log;
23 
24 /**
25  * Provides operations for managing notifications.
26  * <p>
27  * It handles the following actions:
28  * <ul>
29  * <li>{@link #ACTION_MARK_NEW_VOICEMAILS_AS_OLD}: marks all the new voicemails in the call log as
30  * old; this is called when a notification is dismissed.</li>
31  * <li>{@link #ACTION_UPDATE_NOTIFICATIONS}: updates the content of the new items notification; it
32  * may include an optional extra {@link #EXTRA_NEW_VOICEMAIL_URI}, containing the URI of the new
33  * voicemail that has triggered this update (if any).</li>
34  * </ul>
35  */
36 public class CallLogNotificationsService extends IntentService {
37     private static final String TAG = "CallLogNotificationsService";
38 
39     /** Action to mark all the new voicemails as old. */
40     public static final String ACTION_MARK_NEW_VOICEMAILS_AS_OLD =
41             "com.android.dialer.calllog.ACTION_MARK_NEW_VOICEMAILS_AS_OLD";
42 
43     /**
44      * Action to update the notifications.
45      * <p>
46      * May include an optional extra {@link #EXTRA_NEW_VOICEMAIL_URI}.
47      */
48     public static final String ACTION_UPDATE_NOTIFICATIONS =
49             "com.android.dialer.calllog.UPDATE_NOTIFICATIONS";
50 
51     /**
52      * Extra to included with {@link #ACTION_UPDATE_NOTIFICATIONS} to identify the new voicemail
53      * that triggered an update.
54      * <p>
55      * It must be a {@link Uri}.
56      */
57     public static final String EXTRA_NEW_VOICEMAIL_URI = "NEW_VOICEMAIL_URI";
58 
59     private CallLogQueryHandler mCallLogQueryHandler;
60 
CallLogNotificationsService()61     public CallLogNotificationsService() {
62         super("CallLogNotificationsService");
63     }
64 
65     @Override
onCreate()66     public void onCreate() {
67         super.onCreate();
68         mCallLogQueryHandler = new CallLogQueryHandler(getContentResolver(), null /*listener*/);
69     }
70 
71     @Override
onHandleIntent(Intent intent)72     protected void onHandleIntent(Intent intent) {
73         if (intent == null) {
74             Log.d(TAG, "onHandleIntent: could not handle null intent");
75             return;
76         }
77         if (ACTION_MARK_NEW_VOICEMAILS_AS_OLD.equals(intent.getAction())) {
78             mCallLogQueryHandler.markNewVoicemailsAsOld();
79         } else if (ACTION_UPDATE_NOTIFICATIONS.equals(intent.getAction())) {
80             Uri voicemailUri = (Uri) intent.getParcelableExtra(EXTRA_NEW_VOICEMAIL_URI);
81             DefaultVoicemailNotifier.getInstance(this).updateNotification(voicemailUri);
82         } else {
83             Log.d(TAG, "onHandleIntent: could not handle: " + intent);
84         }
85     }
86 }
87