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