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 17package com.android.dialer.app.calllog; 18 19import android.content.BroadcastReceiver; 20import android.content.Context; 21import android.content.Intent; 22import android.database.Cursor; 23import android.provider.VoicemailContract; 24import com.android.dialer.app.voicemail.error.VoicemailStatusCorruptionHandler; 25import com.android.dialer.app.voicemail.error.VoicemailStatusCorruptionHandler.Source; 26import com.android.dialer.common.LogUtil; 27import com.android.dialer.database.CallLogQueryHandler; 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 */ 35public class CallLogReceiver extends BroadcastReceiver { 36 37 @Override 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 DefaultVoicemailNotifier.updateVoicemailNotifications(context, pendingResult::finish); 43 } else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { 44 PendingResult pendingResult = goAsync(); 45 DefaultVoicemailNotifier.updateVoicemailNotifications(context, pendingResult::finish); 46 } else { 47 LogUtil.w("CallLogReceiver.onReceive", "could not handle: " + intent); 48 } 49 } 50 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