1b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda/* 2b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * Copyright (C) 2011 The Android Open Source Project 3b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * 4b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * Licensed under the Apache License, Version 2.0 (the "License"); 5b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * you may not use this file except in compliance with the License. 6b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * You may obtain a copy of the License at 7b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * 8b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * http://www.apache.org/licenses/LICENSE-2.0 9b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * 10b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * Unless required by applicable law or agreed to in writing, software 11b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * distributed under the License is distributed on an "AS IS" BASIS, 12b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * See the License for the specific language governing permissions and 14b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * limitations under the License. 15b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda */ 16b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda 17b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerdapackage com.android.contacts.calllog; 18b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda 19b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerdaimport android.app.IntentService; 20b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerdaimport android.content.Intent; 2160c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerdaimport android.net.Uri; 22b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerdaimport android.util.Log; 23b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda 24b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda/** 25b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * Provides operations for managing notifications. 26b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda * <p> 2760c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * It handles the following actions: 2860c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * <ul> 290331d14de21c78cd6969ef177e399a4b99290f7dFlavio Lerda * <li>{@link #ACTION_MARK_NEW_VOICEMAILS_AS_OLD}: marks all the new voicemails in the call log as 300331d14de21c78cd6969ef177e399a4b99290f7dFlavio Lerda * old; this is called when a notification is dismissed.</li> 3160c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * <li>{@link #ACTION_UPDATE_NOTIFICATIONS}: updates the content of the new items notification; it 3260c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * may include an optional extra {@link #EXTRA_NEW_VOICEMAIL_URI}, containing the URI of the new 3360c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * voicemail that has triggered this update (if any).</li> 3460c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * </ul> 35b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda */ 36b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerdapublic class CallLogNotificationsService extends IntentService { 37b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda private static final String TAG = "CallLogNotificationsService"; 38b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda 390331d14de21c78cd6969ef177e399a4b99290f7dFlavio Lerda /** Action to mark all the new voicemails as old. */ 400331d14de21c78cd6969ef177e399a4b99290f7dFlavio Lerda public static final String ACTION_MARK_NEW_VOICEMAILS_AS_OLD = 410331d14de21c78cd6969ef177e399a4b99290f7dFlavio Lerda "com.android.contacts.calllog.ACTION_MARK_NEW_VOICEMAILS_AS_OLD"; 4260c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda 4360c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda /** 4460c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * Action to update the notifications. 4560c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * <p> 4660c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * May include an optional extra {@link #EXTRA_NEW_VOICEMAIL_URI}. 4760c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda */ 4860c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda public static final String ACTION_UPDATE_NOTIFICATIONS = 4960c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda "com.android.contacts.calllog.UPDATE_NOTIFICATIONS"; 5060c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda 5160c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda /** 5260c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * Extra to included with {@link #ACTION_UPDATE_NOTIFICATIONS} to identify the new voicemail 5360c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * that triggered an update. 5460c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * <p> 5560c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda * It must be a {@link Uri}. 5660c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda */ 5760c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda public static final String EXTRA_NEW_VOICEMAIL_URI = "NEW_VOICEMAIL_URI"; 58b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda 59b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda private CallLogQueryHandler mCallLogQueryHandler; 60b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda 61b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda public CallLogNotificationsService() { 62b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda super("CallLogNotificationsService"); 6360c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda } 6460c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda 6560c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda @Override 6660c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda public void onCreate() { 6760c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda super.onCreate(); 68b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda mCallLogQueryHandler = new CallLogQueryHandler(getContentResolver(), null /*listener*/); 69b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda } 70b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda 71b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda @Override 72b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda protected void onHandleIntent(Intent intent) { 730331d14de21c78cd6969ef177e399a4b99290f7dFlavio Lerda if (ACTION_MARK_NEW_VOICEMAILS_AS_OLD.equals(intent.getAction())) { 740331d14de21c78cd6969ef177e399a4b99290f7dFlavio Lerda mCallLogQueryHandler.markNewVoicemailsAsOld(); 7560c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda } else if (ACTION_UPDATE_NOTIFICATIONS.equals(intent.getAction())) { 7660c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda Uri voicemailUri = (Uri) intent.getParcelableExtra(EXTRA_NEW_VOICEMAIL_URI); 7760c1f788e39577cad5b74414e65d9bab7ca17574Flavio Lerda DefaultVoicemailNotifier.getInstance(this).updateNotification(voicemailUri); 78b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda } else { 79b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda Log.d(TAG, "onHandleIntent: could not handle: " + intent); 80b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda } 81b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda } 82b78b7096618cd9c3c8db8e4a8e0ed684fe8b1b11Flavio Lerda} 83