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.phone;
18
19import android.app.IntentService;
20import android.content.ContentValues;
21import android.content.Intent;
22import android.provider.CallLog.Calls;
23
24/**
25 * Handles the intent to clear the missed calls that is triggered when a notification is dismissed.
26 */
27public class ClearMissedCallsService extends IntentService {
28    /** This action is used to clear missed calls. */
29    public static final String ACTION_CLEAR_MISSED_CALLS =
30            "com.android.phone.intent.CLEAR_MISSED_CALLS";
31
32    private PhoneGlobals mApp;
33
34    public ClearMissedCallsService() {
35        super(ClearMissedCallsService.class.getSimpleName());
36    }
37
38    @Override
39    public void onCreate() {
40        super.onCreate();
41        mApp = PhoneGlobals.getInstance();
42    }
43
44    @Override
45    protected void onHandleIntent(Intent intent) {
46        if (ACTION_CLEAR_MISSED_CALLS.equals(intent.getAction())) {
47            // Clear the list of new missed calls.
48            ContentValues values = new ContentValues();
49            values.put(Calls.NEW, 0);
50            values.put(Calls.IS_READ, 1);
51            StringBuilder where = new StringBuilder();
52            where.append(Calls.NEW);
53            where.append(" = 1 AND ");
54            where.append(Calls.TYPE);
55            where.append(" = ?");
56            getContentResolver().update(Calls.CONTENT_URI, values, where.toString(),
57                    new String[]{ Integer.toString(Calls.MISSED_TYPE) });
58            mApp.notificationMgr.cancelMissedCallNotification();
59        }
60    }
61}
62