Home | History | Annotate | Download | only in phone
      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.phone;
     18 
     19 import android.app.IntentService;
     20 import android.content.ContentValues;
     21 import android.content.Intent;
     22 import android.provider.CallLog.Calls;
     23 
     24 /**
     25  * Handles the intent to clear the missed calls that is triggered when a notification is dismissed.
     26  */
     27 public 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 PhoneApp mApp;
     33 
     34     public ClearMissedCallsService() {
     35         super(ClearMissedCallsService.class.getSimpleName());
     36     }
     37 
     38     @Override
     39     public void onCreate() {
     40         super.onCreate();
     41         mApp = PhoneApp.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             StringBuilder where = new StringBuilder();
     51             where.append(Calls.NEW);
     52             where.append(" = 1 AND ");
     53             where.append(Calls.TYPE);
     54             where.append(" = ?");
     55             getContentResolver().update(Calls.CONTENT_URI, values, where.toString(),
     56                     new String[]{ Integer.toString(Calls.MISSED_TYPE) });
     57             mApp.notificationMgr.cancelMissedCallNotification();
     58         }
     59     }
     60 }
     61