• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.calllogutils;
18 
19 import android.content.Context;
20 import android.provider.CallLog.Calls;
21 import android.support.annotation.IntDef;
22 import android.text.TextUtils;
23 import com.android.dialer.duo.DuoComponent;
24 import java.lang.annotation.Retention;
25 import java.lang.annotation.RetentionPolicy;
26 
27 /** Helper class to determine the callback action associated with a call in the call log. */
28 public class CallbackActionHelper {
29 
30   /** Specifies the action a user can take to make a callback. */
31   @Retention(RetentionPolicy.SOURCE)
32   @IntDef({CallbackAction.NONE, CallbackAction.IMS_VIDEO, CallbackAction.DUO, CallbackAction.VOICE})
33   public @interface CallbackAction {
34     int NONE = 0;
35     int IMS_VIDEO = 1;
36     int DUO = 2;
37     int VOICE = 3;
38   }
39 
40   /**
41    * Returns the {@link CallbackAction} that can be associated with a call.
42    *
43    * @param number The phone number in column {@link android.provider.CallLog.Calls#NUMBER}.
44    * @param features Value of features in column {@link android.provider.CallLog.Calls#FEATURES}.
45    * @param phoneAccountComponentName Account name in column {@link
46    *     android.provider.CallLog.Calls#PHONE_ACCOUNT_COMPONENT_NAME}.
47    * @return One of the values in {@link CallbackAction}
48    */
getCallbackAction( Context context, String number, int features, String phoneAccountComponentName)49   public static @CallbackAction int getCallbackAction(
50       Context context, String number, int features, String phoneAccountComponentName) {
51     return getCallbackAction(number, features, isDuoCall(context, phoneAccountComponentName));
52   }
53 
54   /**
55    * Returns the {@link CallbackAction} that can be associated with a call.
56    *
57    * @param number The phone number in column {@link android.provider.CallLog.Calls#NUMBER}.
58    * @param features Value of features in column {@link android.provider.CallLog.Calls#FEATURES}.
59    * @param isDuoCall Whether the call is a Duo call.
60    * @return One of the values in {@link CallbackAction}
61    */
getCallbackAction( String number, int features, boolean isDuoCall)62   public static @CallbackAction int getCallbackAction(
63       String number, int features, boolean isDuoCall) {
64     if (TextUtils.isEmpty(number)) {
65       return CallbackAction.NONE;
66     }
67     if (isDuoCall) {
68       return CallbackAction.DUO;
69     }
70 
71     boolean isVideoCall = (features & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO;
72     if (isVideoCall) {
73       return CallbackAction.IMS_VIDEO;
74     }
75 
76     return CallbackAction.VOICE;
77   }
78 
isDuoCall(Context context, String phoneAccountComponentName)79   private static boolean isDuoCall(Context context, String phoneAccountComponentName) {
80     return DuoComponent.get(context).getDuo().isDuoAccount(phoneAccountComponentName);
81   }
82 }
83