1 /* 2 * Copyright (C) 2016 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.server.telecom.callfiltering; 18 19 import android.net.Uri; 20 import android.telecom.Log; 21 22 import com.android.internal.telephony.CallerInfo; 23 import com.android.server.telecom.Call; 24 import com.android.server.telecom.CallerInfoLookupHelper; 25 import com.android.server.telecom.LogUtils; 26 27 import java.util.Objects; 28 29 public class DirectToVoicemailCallFilter implements IncomingCallFilter.CallFilter { 30 private final CallerInfoLookupHelper mCallerInfoLookupHelper; 31 32 public DirectToVoicemailCallFilter(CallerInfoLookupHelper callerInfoLookupHelper) { 33 mCallerInfoLookupHelper = callerInfoLookupHelper; 34 } 35 36 @Override 37 public void startFilterLookup(final Call call, CallFilterResultCallback callback) { 38 Log.addEvent(call, LogUtils.Events.DIRECT_TO_VM_INITIATED); 39 final Uri callHandle = call.getHandle(); 40 41 mCallerInfoLookupHelper.startLookup(callHandle, 42 new CallerInfoLookupHelper.OnQueryCompleteListener() { 43 @Override 44 public void onCallerInfoQueryComplete(Uri handle, CallerInfo info) { 45 CallFilteringResult result; 46 if ((handle != null) && Objects.equals(callHandle, handle)) { 47 if (info != null && info.shouldSendToVoicemail) { 48 result = new CallFilteringResult( 49 false, // shouldAllowCall 50 true, // shouldReject 51 true, // shouldAddToCallLog 52 true // shouldShowNotification 53 ); 54 } else { 55 result = new CallFilteringResult( 56 true, // shouldAllowCall 57 false, // shouldReject 58 true, // shouldAddToCallLog 59 true // shouldShowNotification 60 ); 61 } 62 Log.addEvent(call, LogUtils.Events.DIRECT_TO_VM_FINISHED, result); 63 callback.onCallFilteringComplete(call, result); 64 } else { 65 result = new CallFilteringResult( 66 true, // shouldAllowCall 67 false, // shouldReject 68 true, // shouldAddToCallLog 69 true // shouldShowNotification 70 ); 71 Log.addEvent(call, LogUtils.Events.DIRECT_TO_VM_FINISHED, result); 72 Log.w(this, "CallerInfo lookup returned with a different handle than " + 73 "what was passed in. Was %s, should be %s", handle, callHandle); 74 callback.onCallFilteringComplete(call, result); 75 } 76 } 77 78 @Override 79 public void onContactPhotoQueryComplete(Uri handle, CallerInfo info) { 80 // ignore 81 } 82 }); 83 } 84 } 85