summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java
blob: d6d8354ec63c20679da63abf8aacd17361866e41 (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
/*
 * 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.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.provider.CallLog.Calls;
import android.util.Log;

/** 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;

  public VoicemailQueryHandler(Context context, ContentResolver contentResolver) {
    super(contentResolver);
    mContext = context;
  }

  /** 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)});
  }

  @Override
  protected void onUpdateComplete(int token, Object cookie, int result) {
    if (token == UPDATE_MARK_VOICEMAILS_AS_OLD_TOKEN) {
      if (mContext != null) {
        Intent serviceIntent = new Intent(mContext, CallLogNotificationsService.class);
        serviceIntent.setAction(CallLogNotificationsService.ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS);
        mContext.startService(serviceIntent);
      } else {
        Log.w(TAG, "Unknown update completed: ignoring: " + token);
      }
    }
  }
}