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