Merge "Fix clearing of voicemail notifications."
diff --git a/src/com/android/contacts/calllog/CallLogNotificationsService.java b/src/com/android/contacts/calllog/CallLogNotificationsService.java
index 6dd24aa..be540ad 100644
--- a/src/com/android/contacts/calllog/CallLogNotificationsService.java
+++ b/src/com/android/contacts/calllog/CallLogNotificationsService.java
@@ -26,8 +26,8 @@
  * <p>
  * It handles the following actions:
  * <ul>
- * <li>{@link #ACTION_MARK_NEW_CALLS_AS_OLD}: marks all the new items in the call log as old; this
- * is called when a notification is dismissed.</li>
+ * <li>{@link #ACTION_MARK_NEW_VOICEMAILS_AS_OLD}: marks all the new voicemails in the call log as
+ * old; this is called when a notification is dismissed.</li>
  * <li>{@link #ACTION_UPDATE_NOTIFICATIONS}: updates the content of the new items notification; it
  * may include an optional extra {@link #EXTRA_NEW_VOICEMAIL_URI}, containing the URI of the new
  * voicemail that has triggered this update (if any).</li>
@@ -36,11 +36,9 @@
 public class CallLogNotificationsService extends IntentService {
     private static final String TAG = "CallLogNotificationsService";
 
-    /**
-     * Action to mark all the new calls as old.
-     */
-    public static final String ACTION_MARK_NEW_CALLS_AS_OLD =
-            "com.android.contacts.calllog.MARK_NEW_CALLS_AS_OLD";
+    /** Action to mark all the new voicemails as old. */
+    public static final String ACTION_MARK_NEW_VOICEMAILS_AS_OLD =
+            "com.android.contacts.calllog.ACTION_MARK_NEW_VOICEMAILS_AS_OLD";
 
     /**
      * Action to update the notifications.
@@ -72,8 +70,8 @@
 
     @Override
     protected void onHandleIntent(Intent intent) {
-        if (ACTION_MARK_NEW_CALLS_AS_OLD.equals(intent.getAction())) {
-            mCallLogQueryHandler.markNewCallsAsOld();
+        if (ACTION_MARK_NEW_VOICEMAILS_AS_OLD.equals(intent.getAction())) {
+            mCallLogQueryHandler.markNewVoicemailsAsOld();
         } else if (ACTION_UPDATE_NOTIFICATIONS.equals(intent.getAction())) {
             Uri voicemailUri = (Uri) intent.getParcelableExtra(EXTRA_NEW_VOICEMAIL_URI);
             DefaultVoicemailNotifier.getInstance(this).updateNotification(voicemailUri);
diff --git a/src/com/android/contacts/calllog/CallLogQueryHandler.java b/src/com/android/contacts/calllog/CallLogQueryHandler.java
index b4e4248..979db4b 100644
--- a/src/com/android/contacts/calllog/CallLogQueryHandler.java
+++ b/src/com/android/contacts/calllog/CallLogQueryHandler.java
@@ -51,12 +51,13 @@
     private static final int QUERY_OLD_CALLS_TOKEN = 54;
     /** The token for the query to mark all missed calls as old after seeing the call log. */
     private static final int UPDATE_MARK_AS_OLD_TOKEN = 55;
+    /** The token for the query to mark all new voicemails as old. */
+    private static final int UPDATE_MARK_VOICEMAILS_AS_OLD_TOKEN = 56;
     /** The token for the query to mark all missed calls as read after seeing the call log. */
-    private static final int UPDATE_MARK_MISSED_CALL_AS_READ_TOKEN = 56;
+    private static final int UPDATE_MARK_MISSED_CALL_AS_READ_TOKEN = 57;
 
     /** The token for the query to fetch voicemail status messages. */
-    private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 57;
-
+    private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 58;
 
     private final WeakReference<Listener> mListener;
 
@@ -192,6 +193,22 @@
                 values, where.toString(), null);
     }
 
+    /** Updates all new voicemails to mark them as old. */
+    public void markNewVoicemailsAsOld() {
+        // Mark all "new" voicemails as not new anymore.
+        StringBuilder where = new StringBuilder();
+        where.append(Calls.NEW);
+        where.append(" = 1 AND ");
+        where.append(Calls.TYPE);
+        where.append(" = ?");
+
+        ContentValues values = new ContentValues(1);
+        values.put(Calls.NEW, "0");
+
+        startUpdate(UPDATE_MARK_VOICEMAILS_AS_OLD_TOKEN, null, Calls.CONTENT_URI_WITH_VOICEMAIL,
+                values, where.toString(), new String[]{ Integer.toString(Calls.VOICEMAIL_TYPE) });
+    }
+
     /** Updates all missed calls to mark them as read. */
     public void markMissedCallsAsRead() {
         // Mark all "new" calls as not new anymore.
diff --git a/src/com/android/contacts/calllog/DefaultVoicemailNotifier.java b/src/com/android/contacts/calllog/DefaultVoicemailNotifier.java
index 1cf67c1..f795a9c 100644
--- a/src/com/android/contacts/calllog/DefaultVoicemailNotifier.java
+++ b/src/com/android/contacts/calllog/DefaultVoicemailNotifier.java
@@ -153,7 +153,7 @@
                 .setContentTitle(title)
                 .setContentText(callers)
                 .setDefaults(callToNotify != null ? Notification.DEFAULT_ALL : 0)
-                .setDeleteIntent(createMarkNewCallsAsOld())
+                .setDeleteIntent(createMarkNewVoicemailsAsOldIntent())
                 .setAutoCancel(true)
                 .getNotification();
 
@@ -182,10 +182,10 @@
         mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, notification);
     }
 
-    /** Creates a pending intent that marks all new calls as old. */
-    private PendingIntent createMarkNewCallsAsOld() {
+    /** Creates a pending intent that marks all new voicemails as old. */
+    private PendingIntent createMarkNewVoicemailsAsOldIntent() {
         Intent intent = new Intent(mContext, CallLogNotificationsService.class);
-        intent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_CALLS_AS_OLD);
+        intent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_VOICEMAILS_AS_OLD);
         return PendingIntent.getService(mContext, 0, intent, 0);
     }