summaryrefslogtreecommitdiffstats
path: root/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java
blob: 777f4c79f6721037a85019c3cfd0476957be526b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.dialer.app.calllog;

import android.app.NotificationManager;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.support.annotation.MainThread;
import android.support.annotation.Nullable;
import com.android.dialer.app.R;
import com.android.dialer.common.Assert;
import com.android.dialer.notification.GroupedNotificationUtil;

/** Handles asynchronous queries to the call log for voicemail. */
public class VoicemailQueryHandler extends AsyncQueryHandler {

  private static final String TAG = "VoicemailQueryHandler";

  /** The token for the query to mark all new voicemails as old. */
  private static final int UPDATE_MARK_VOICEMAILS_AS_OLD_TOKEN = 50;

  private Context mContext;

  @MainThread
  public VoicemailQueryHandler(Context context, ContentResolver contentResolver) {
    super(contentResolver);
    Assert.isMainThread();
    mContext = context;
  }

  /** Updates all new voicemails to mark them as old. */
  public void markNewVoicemailsAsOld(@Nullable Uri voicemailUri) {
    // 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(" = ?");

    if (voicemailUri != null) {
      where.append(" AND ").append(Calls.VOICEMAIL_URI).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(),
        voicemailUri == null
            ? new String[] {Integer.toString(Calls.VOICEMAIL_TYPE)}
            : new String[] {Integer.toString(Calls.VOICEMAIL_TYPE), voicemailUri.toString()});

    GroupedNotificationUtil.removeNotification(
        mContext.getSystemService(NotificationManager.class),
        voicemailUri != null ? voicemailUri.toString() : null,
        R.id.notification_visual_voicemail,
        DefaultVoicemailNotifier.VISUAL_VOICEMAIL_NOTIFICATION_TAG);
  }
}