• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.dialer.app.calllog;
18 
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.database.Cursor;
23 import android.provider.VoicemailContract;
24 import com.android.dialer.common.LogUtil;
25 import com.android.dialer.database.CallLogQueryHandler;
26 import com.android.dialer.voicemail.listui.error.VoicemailStatusCorruptionHandler;
27 import com.android.dialer.voicemail.listui.error.VoicemailStatusCorruptionHandler.Source;
28 
29 /**
30  * Receiver for call log events.
31  *
32  * <p>It is currently used to handle {@link VoicemailContract#ACTION_NEW_VOICEMAIL} and {@link
33  * Intent#ACTION_BOOT_COMPLETED}.
34  */
35 public class CallLogReceiver extends BroadcastReceiver {
36 
37   @Override
onReceive(Context context, Intent intent)38   public void onReceive(Context context, Intent intent) {
39     if (VoicemailContract.ACTION_NEW_VOICEMAIL.equals(intent.getAction())) {
40       checkVoicemailStatus(context);
41       PendingResult pendingResult = goAsync();
42       VisualVoicemailUpdateTask.scheduleTask(context, pendingResult::finish);
43     } else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
44       PendingResult pendingResult = goAsync();
45       VisualVoicemailUpdateTask.scheduleTask(context, pendingResult::finish);
46     } else {
47       LogUtil.w("CallLogReceiver.onReceive", "could not handle: " + intent);
48     }
49   }
50 
checkVoicemailStatus(Context context)51   private static void checkVoicemailStatus(Context context) {
52     new CallLogQueryHandler(
53             context,
54             context.getContentResolver(),
55             new CallLogQueryHandler.Listener() {
56               @Override
57               public void onVoicemailStatusFetched(Cursor statusCursor) {
58                 VoicemailStatusCorruptionHandler.maybeFixVoicemailStatus(
59                     context, statusCursor, Source.Notification);
60               }
61 
62               @Override
63               public void onVoicemailUnreadCountFetched(Cursor cursor) {
64                 // Do nothing
65               }
66 
67               @Override
68               public void onMissedCallsUnreadCountFetched(Cursor cursor) {
69                 // Do nothing
70               }
71 
72               @Override
73               public boolean onCallsFetched(Cursor combinedCursor) {
74                 return false;
75               }
76             })
77         .fetchVoicemailStatus();
78   }
79 }
80