CallLogNotificationsService.java revision 60c1f788e39577cad5b74414e65d9bab7ca17574
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
17package com.android.contacts.calllog;
18
19import android.app.IntentService;
20import android.content.Intent;
21import android.net.Uri;
22import 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_CALLS_AS_OLD}: marks all the new items in the call log as old; this
30 * 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 */
36public class CallLogNotificationsService extends IntentService {
37    private static final String TAG = "CallLogNotificationsService";
38
39    /**
40     * Action to mark all the new calls as old.
41     */
42    public static final String ACTION_MARK_NEW_CALLS_AS_OLD =
43            "com.android.contacts.calllog.MARK_NEW_CALLS_AS_OLD";
44
45    /**
46     * Action to update the notifications.
47     * <p>
48     * May include an optional extra {@link #EXTRA_NEW_VOICEMAIL_URI}.
49     */
50    public static final String ACTION_UPDATE_NOTIFICATIONS =
51            "com.android.contacts.calllog.UPDATE_NOTIFICATIONS";
52
53    /**
54     * Extra to included with {@link #ACTION_UPDATE_NOTIFICATIONS} to identify the new voicemail
55     * that triggered an update.
56     * <p>
57     * It must be a {@link Uri}.
58     */
59    public static final String EXTRA_NEW_VOICEMAIL_URI = "NEW_VOICEMAIL_URI";
60
61    private CallLogQueryHandler mCallLogQueryHandler;
62
63    public CallLogNotificationsService() {
64        super("CallLogNotificationsService");
65    }
66
67    @Override
68    public void onCreate() {
69        super.onCreate();
70        mCallLogQueryHandler = new CallLogQueryHandler(getContentResolver(), null /*listener*/);
71    }
72
73    @Override
74    protected void onHandleIntent(Intent intent) {
75        if (ACTION_MARK_NEW_CALLS_AS_OLD.equals(intent.getAction())) {
76            mCallLogQueryHandler.markNewCallsAsOld();
77        } else if (ACTION_UPDATE_NOTIFICATIONS.equals(intent.getAction())) {
78            Uri voicemailUri = (Uri) intent.getParcelableExtra(EXTRA_NEW_VOICEMAIL_URI);
79            DefaultVoicemailNotifier.getInstance(this).updateNotification(voicemailUri);
80        } else {
81            Log.d(TAG, "onHandleIntent: could not handle: " + intent);
82        }
83    }
84}
85