Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 17 | package com.android.telecomm; |
| 18 | |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 19 | import android.content.ContentUris; |
| 20 | import android.graphics.Bitmap; |
| 21 | import android.graphics.drawable.Drawable; |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 25 | import android.provider.ContactsContract.Contacts; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 26 | import android.telecomm.CallInfo; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 27 | import android.telecomm.CallServiceDescriptor; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 28 | import android.telecomm.CallState; |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 29 | import android.telecomm.GatewayInfo; |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 30 | import android.telecomm.TelecommConstants; |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 31 | import android.telephony.DisconnectCause; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 32 | import android.telephony.PhoneNumberUtils; |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 33 | import android.text.TextUtils; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 34 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 35 | import com.android.internal.telephony.CallerInfo; |
| 36 | import com.android.internal.telephony.CallerInfoAsyncQuery; |
| 37 | import com.android.internal.telephony.CallerInfoAsyncQuery.OnQueryCompleteListener; |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 38 | |
| 39 | import com.android.telecomm.ContactsAsyncHelper.OnImageLoadCompleteListener; |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 40 | import com.google.android.collect.Sets; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 41 | import com.google.common.base.Preconditions; |
| 42 | |
Sailesh Nepal | 9199078 | 2014-03-08 17:45:52 -0800 | [diff] [blame] | 43 | import java.util.Locale; |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 44 | import java.util.Set; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 45 | |
Ben Gilad | 2495d57 | 2014-01-09 17:26:19 -0800 | [diff] [blame] | 46 | /** |
| 47 | * Encapsulates all aspects of a given phone call throughout its lifecycle, starting |
| 48 | * from the time the call intent was received by Telecomm (vs. the time the call was |
| 49 | * connected etc). |
| 50 | */ |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 51 | final class Call { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Listener for events on the call. |
| 55 | */ |
| 56 | interface Listener { |
| 57 | void onSuccessfulOutgoingCall(Call call); |
| 58 | void onFailedOutgoingCall(Call call, boolean isAborted); |
| 59 | void onSuccessfulIncomingCall(Call call, CallInfo callInfo); |
| 60 | void onFailedIncomingCall(Call call); |
Ihab Awad | 50a5713 | 2014-05-28 16:49:38 -0700 | [diff] [blame^] | 61 | void onRequestingRingback(Call call, boolean requestingRingback); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 64 | private static final OnQueryCompleteListener sCallerInfoQueryListener = |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 65 | new OnQueryCompleteListener() { |
| 66 | /** ${inheritDoc} */ |
| 67 | @Override |
| 68 | public void onQueryComplete(int token, Object cookie, CallerInfo callerInfo) { |
| 69 | if (cookie != null) { |
| 70 | ((Call) cookie).setCallerInfo(callerInfo, token); |
| 71 | } |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 72 | } |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | private static final OnImageLoadCompleteListener sPhotoLoadListener = |
| 76 | new OnImageLoadCompleteListener() { |
| 77 | /** ${inheritDoc} */ |
| 78 | @Override |
| 79 | public void onImageLoadComplete( |
| 80 | int token, Drawable photo, Bitmap photoIcon, Object cookie) { |
| 81 | if (cookie != null) { |
| 82 | ((Call) cookie).setPhoto(photo, photoIcon, token); |
| 83 | } |
| 84 | } |
| 85 | }; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 86 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 87 | /** True if this is an incoming call. */ |
| 88 | private final boolean mIsIncoming; |
| 89 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 90 | /** |
| 91 | * The time this call was created, typically also the time this call was added to the set |
| 92 | * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard. |
| 93 | * Beyond logging and such, may also be used for bookkeeping and specifically for marking |
| 94 | * certain call attempts as failed attempts. |
| 95 | */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 96 | private final long mCreationTimeMillis = System.currentTimeMillis(); |
| 97 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 98 | /** The gateway information associated with this call. This stores the original call handle |
| 99 | * that the user is attempting to connect to via the gateway, the actual handle to dial in |
| 100 | * order to connect the call via the gateway, as well as the package name of the gateway |
| 101 | * service. */ |
| 102 | private final GatewayInfo mGatewayInfo; |
| 103 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 104 | private final Handler mHandler = new Handler(); |
| 105 | |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 106 | private long mConnectTimeMillis; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 107 | |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 108 | /** The state of the call. */ |
| 109 | private CallState mState; |
| 110 | |
| 111 | /** The handle with which to establish this call. */ |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 112 | private Uri mHandle; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 113 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 114 | /** |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 115 | * The call service which is attempted or already connecting this call. |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 116 | */ |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 117 | private CallServiceWrapper mCallService; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 118 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 119 | /** |
| 120 | * The call-service selector for this call. |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 121 | */ |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 122 | private CallServiceSelectorWrapper mCallServiceSelector; |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 123 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 124 | /** |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 125 | * The set of call services that were attempted in the process of placing/switching this call |
| 126 | * but turned out unsuitable. Only used in the context of call switching. |
| 127 | */ |
| 128 | private Set<CallServiceWrapper> mIncompatibleCallServices; |
| 129 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 130 | private boolean mIsEmergencyCall; |
| 131 | |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 132 | /** |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 133 | * Disconnect cause for the call. Only valid if the state of the call is DISCONNECTED. |
| 134 | * See {@link android.telephony.DisconnectCause}. |
| 135 | */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 136 | private int mDisconnectCause = DisconnectCause.NOT_VALID; |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * Additional disconnect information provided by the call service. |
| 140 | */ |
| 141 | private String mDisconnectMessage; |
| 142 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 143 | /** Info used by the call services. */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 144 | private Bundle mExtras = Bundle.EMPTY; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 145 | |
| 146 | /** The Uri to dial to perform the handoff. If this is null then handoff is not supported. */ |
| 147 | private Uri mHandoffHandle; |
| 148 | |
| 149 | /** |
| 150 | * References the call that is being handed off. This value is non-null for untracked calls |
| 151 | * that are being used to perform a handoff. |
| 152 | */ |
| 153 | private Call mOriginalCall; |
| 154 | |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 155 | /** |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 156 | * The descriptor for the call service that this call is being switched to, null if handoff is |
| 157 | * not in progress. |
| 158 | */ |
| 159 | private CallServiceDescriptor mHandoffCallServiceDescriptor; |
| 160 | |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 161 | /** Set of listeners on this call. */ |
| 162 | private Set<Listener> mListeners = Sets.newHashSet(); |
| 163 | |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 164 | private OutgoingCallProcessor mOutgoingCallProcessor; |
| 165 | |
| 166 | // TODO(santoscordon): The repositories should be changed into singleton types. |
| 167 | private CallServiceRepository mCallServiceRepository; |
| 168 | private CallServiceSelectorRepository mSelectorRepository; |
| 169 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 170 | /** Caller information retrieved from the latest contact query. */ |
| 171 | private CallerInfo mCallerInfo; |
| 172 | |
| 173 | /** The latest token used with a contact info query. */ |
| 174 | private int mQueryToken = 0; |
| 175 | |
Ihab Awad | 50a5713 | 2014-05-28 16:49:38 -0700 | [diff] [blame^] | 176 | /** Whether this call is requesting that Telecomm play the ringback tone on its behalf. */ |
| 177 | private boolean mRequestingRingback = false; |
| 178 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 179 | /** Incoming call-info to use when direct-to-voicemail query finishes. */ |
| 180 | private CallInfo mPendingDirectToVoicemailCallInfo; |
| 181 | |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 182 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 183 | * Creates an empty call object. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 184 | * |
| 185 | * @param isIncoming True if this is an incoming call. |
Santos Cordon | 493e8f2 | 2014-02-19 03:15:12 -0800 | [diff] [blame] | 186 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 187 | Call(boolean isIncoming) { |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 188 | this(null, null, isIncoming); |
Santos Cordon | 493e8f2 | 2014-02-19 03:15:12 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /** |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 192 | * Persists the specified parameters and initializes the new instance. |
| 193 | * |
| 194 | * @param handle The handle to dial. |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 195 | * @param gatewayInfo Gateway information to use for the call. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 196 | * @param isIncoming True if this is an incoming call. |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 197 | */ |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 198 | Call(Uri handle, GatewayInfo gatewayInfo, boolean isIncoming) { |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 199 | mState = CallState.NEW; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 200 | setHandle(handle); |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 201 | mGatewayInfo = gatewayInfo; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 202 | mIsIncoming = isIncoming; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 205 | void addListener(Listener listener) { |
| 206 | mListeners.add(listener); |
| 207 | } |
| 208 | |
| 209 | void removeListener(Listener listener) { |
| 210 | mListeners.remove(listener); |
| 211 | } |
| 212 | |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 213 | /** {@inheritDoc} */ |
| 214 | @Override public String toString() { |
Sailesh Nepal | 4538f01 | 2014-04-15 11:40:33 -0700 | [diff] [blame] | 215 | String component = null; |
| 216 | if (mCallService != null && mCallService.getComponentName() != null) { |
| 217 | component = mCallService.getComponentName().flattenToShortString(); |
| 218 | } |
| 219 | return String.format(Locale.US, "[%s, %s, %s]", mState, component, Log.piiHandle(mHandle)); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 222 | CallState getState() { |
| 223 | return mState; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Sets the call state. Although there exists the notion of appropriate state transitions |
| 228 | * (see {@link CallState}), in practice those expectations break down when cellular systems |
| 229 | * misbehave and they do this very often. The result is that we do not enforce state transitions |
| 230 | * and instead keep the code resilient to unexpected state changes. |
| 231 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 232 | void setState(CallState newState) { |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 233 | Preconditions.checkState(newState != CallState.DISCONNECTED || |
| 234 | mDisconnectCause != DisconnectCause.NOT_VALID); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 235 | if (mState != newState) { |
| 236 | Log.v(this, "setState %s -> %s", mState, newState); |
| 237 | mState = newState; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 238 | } |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Ihab Awad | 50a5713 | 2014-05-28 16:49:38 -0700 | [diff] [blame^] | 241 | void setRequestingRingback(boolean requestingRingback) { |
| 242 | mRequestingRingback = requestingRingback; |
| 243 | for (Listener l : mListeners) { |
| 244 | l.onRequestingRingback(this, mRequestingRingback); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | boolean isRequestingRingback() { |
| 249 | return mRequestingRingback; |
| 250 | } |
| 251 | |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 252 | Uri getHandle() { |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 253 | return mHandle; |
| 254 | } |
| 255 | |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 256 | void setHandle(Uri handle) { |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 257 | if ((mHandle == null && handle != null) || (mHandle != null && !mHandle.equals(handle))) { |
| 258 | mHandle = handle; |
| 259 | mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber( |
| 260 | mHandle.getSchemeSpecificPart(), TelecommApp.getInstance()); |
| 261 | startCallerInfoLookup(); |
| 262 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 265 | String getName() { |
| 266 | return mCallerInfo == null ? null : mCallerInfo.name; |
| 267 | } |
| 268 | |
| 269 | Bitmap getPhotoIcon() { |
| 270 | return mCallerInfo == null ? null : mCallerInfo.cachedPhotoIcon; |
| 271 | } |
| 272 | |
| 273 | Drawable getPhoto() { |
| 274 | return mCallerInfo == null ? null : mCallerInfo.cachedPhoto; |
| 275 | } |
| 276 | |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 277 | /** |
| 278 | * @param disconnectCause The reason for the disconnection, any of |
| 279 | * {@link android.telephony.DisconnectCause}. |
| 280 | * @param disconnectMessage Optional call-service-provided message about the disconnect. |
| 281 | */ |
| 282 | void setDisconnectCause(int disconnectCause, String disconnectMessage) { |
| 283 | // TODO: Consider combining this method with a setDisconnected() method that is totally |
| 284 | // separate from setState. |
| 285 | mDisconnectCause = disconnectCause; |
| 286 | mDisconnectMessage = disconnectMessage; |
| 287 | } |
| 288 | |
| 289 | int getDisconnectCause() { |
| 290 | return mDisconnectCause; |
| 291 | } |
| 292 | |
| 293 | String getDisconnectMessage() { |
| 294 | return mDisconnectMessage; |
| 295 | } |
| 296 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 297 | boolean isEmergencyCall() { |
| 298 | return mIsEmergencyCall; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 301 | /** |
| 302 | * @return The original handle this call is associated with. In-call services should use this |
| 303 | * handle when indicating in their UI the handle that is being called. |
| 304 | */ |
| 305 | public Uri getOriginalHandle() { |
| 306 | if (mGatewayInfo != null && !mGatewayInfo.isEmpty()) { |
| 307 | return mGatewayInfo.getOriginalHandle(); |
| 308 | } |
| 309 | return getHandle(); |
| 310 | } |
| 311 | |
| 312 | GatewayInfo getGatewayInfo() { |
| 313 | return mGatewayInfo; |
| 314 | } |
| 315 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 316 | boolean isIncoming() { |
| 317 | return mIsIncoming; |
| 318 | } |
| 319 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 320 | /** |
| 321 | * @return The "age" of this call object in milliseconds, which typically also represents the |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 322 | * period since this call was added to the set pending outgoing calls, see |
| 323 | * mCreationTimeMillis. |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 324 | */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 325 | long getAgeMillis() { |
| 326 | return System.currentTimeMillis() - mCreationTimeMillis; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 327 | } |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 328 | |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 329 | /** |
| 330 | * @return The time when this call object was created and added to the set of pending outgoing |
| 331 | * calls. |
| 332 | */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 333 | long getCreationTimeMillis() { |
| 334 | return mCreationTimeMillis; |
| 335 | } |
| 336 | |
| 337 | long getConnectTimeMillis() { |
| 338 | return mConnectTimeMillis; |
| 339 | } |
| 340 | |
| 341 | void setConnectTimeMillis(long connectTimeMillis) { |
| 342 | mConnectTimeMillis = connectTimeMillis; |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 345 | CallServiceWrapper getCallService() { |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 346 | return mCallService; |
| 347 | } |
| 348 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 349 | void setCallService(CallServiceWrapper callService) { |
Sailesh Nepal | 0e5410a | 2014-04-04 01:20:58 -0700 | [diff] [blame] | 350 | setCallService(callService, null); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Changes the call service this call is associated with. If callToReplace is non-null then this |
| 355 | * call takes its place within the call service. |
| 356 | */ |
| 357 | void setCallService(CallServiceWrapper callService, Call callToReplace) { |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 358 | Preconditions.checkNotNull(callService); |
| 359 | |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 360 | clearCallService(); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 361 | |
| 362 | callService.incrementAssociatedCallCount(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 363 | mCallService = callService; |
Sailesh Nepal | 0e5410a | 2014-04-04 01:20:58 -0700 | [diff] [blame] | 364 | if (callToReplace == null) { |
| 365 | mCallService.addCall(this); |
| 366 | } else { |
| 367 | mCallService.replaceCall(this, callToReplace); |
| 368 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Clears the associated call service. |
| 373 | */ |
| 374 | void clearCallService() { |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 375 | if (mCallService != null) { |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 376 | CallServiceWrapper callServiceTemp = mCallService; |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 377 | mCallService = null; |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 378 | callServiceTemp.removeCall(this); |
| 379 | |
| 380 | // Decrementing the count can cause the service to unbind, which itself can trigger the |
| 381 | // service-death code. Since the service death code tries to clean up any associated |
| 382 | // calls, we need to make sure to remove that information (e.g., removeCall()) before |
| 383 | // we decrement. Technically, invoking removeCall() prior to decrementing is all that is |
| 384 | // necessary, but cleaning up mCallService prior to triggering an unbind is good to do. |
| 385 | // If you change this, make sure to update {@link clearCallServiceSelector} as well. |
| 386 | decrementAssociatedCallCount(callServiceTemp); |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 387 | } |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 390 | CallServiceSelectorWrapper getCallServiceSelector() { |
| 391 | return mCallServiceSelector; |
| 392 | } |
| 393 | |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 394 | void setCallServiceSelector(CallServiceSelectorWrapper selector) { |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 395 | Preconditions.checkNotNull(selector); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 396 | |
| 397 | clearCallServiceSelector(); |
| 398 | |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 399 | selector.incrementAssociatedCallCount(); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 400 | mCallServiceSelector = selector; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 401 | mCallServiceSelector.addCall(this); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void clearCallServiceSelector() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 405 | if (mCallServiceSelector != null) { |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 406 | CallServiceSelectorWrapper selectorTemp = mCallServiceSelector; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 407 | mCallServiceSelector = null; |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 408 | selectorTemp.removeCall(this); |
| 409 | |
| 410 | // See comment on {@link #clearCallService}. |
| 411 | decrementAssociatedCallCount(selectorTemp); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 412 | } |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /** |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 416 | * Starts the incoming call flow through the switchboard. When switchboard completes, it will |
| 417 | * invoke handle[Un]SuccessfulIncomingCall. |
| 418 | * |
| 419 | * @param descriptor The relevant call-service descriptor. |
| 420 | * @param extras The optional extras passed via |
| 421 | * {@link TelecommConstants#EXTRA_INCOMING_CALL_EXTRAS}. |
| 422 | */ |
| 423 | void startIncoming(CallServiceDescriptor descriptor, Bundle extras) { |
| 424 | Switchboard.getInstance().retrieveIncomingCall(this, descriptor, extras); |
| 425 | } |
| 426 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 427 | /** |
| 428 | * Takes a verified incoming call and uses the handle to lookup direct-to-voicemail property |
| 429 | * from the contacts provider. The call is not yet exposed to the user at this point and |
| 430 | * the result of the query will determine if the call is rejected or passed through to the |
| 431 | * in-call UI. |
| 432 | */ |
| 433 | void handleVerifiedIncoming(CallInfo callInfo) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 434 | Preconditions.checkState(callInfo.getState() == CallState.RINGING); |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 435 | |
| 436 | // We do not handle incoming calls immediately when they are verified by the call service. |
| 437 | // We allow the caller-info-query code to execute first so that we can read the |
| 438 | // direct-to-voicemail property before deciding if we want to show the incoming call to the |
| 439 | // user or if we want to reject the call. |
| 440 | mPendingDirectToVoicemailCallInfo = callInfo; |
| 441 | |
| 442 | // Setting the handle triggers the caller info lookup code. |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 443 | setHandle(callInfo.getHandle()); |
| 444 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 445 | // Timeout the direct-to-voicemail lookup execution so that we dont wait too long before |
| 446 | // showing the user the incoming call screen. |
| 447 | mHandler.postDelayed(new Runnable() { |
| 448 | @Override |
| 449 | public void run() { |
| 450 | processDirectToVoicemail(); |
| 451 | } |
| 452 | }, Timeouts.getDirectToVoicemail()); |
| 453 | } |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 454 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 455 | void processDirectToVoicemail() { |
| 456 | if (mPendingDirectToVoicemailCallInfo != null) { |
| 457 | if (mCallerInfo != null && mCallerInfo.shouldSendToVoicemail) { |
| 458 | Log.i(this, "Directing call to voicemail: %s.", this); |
| 459 | // TODO(santoscordon): Once we move State handling from CallsManager to Call, we |
| 460 | // will not need to set RINGING state prior to calling reject. |
| 461 | setState(CallState.RINGING); |
| 462 | reject(); |
| 463 | } else { |
| 464 | // TODO(santoscordon): Make this class (not CallsManager) responsible for changing |
| 465 | // the call state to RINGING. |
| 466 | |
| 467 | // TODO(santoscordon): Replace this with state transition to RINGING. |
| 468 | for (Listener l : mListeners) { |
| 469 | l.onSuccessfulIncomingCall(this, mPendingDirectToVoicemailCallInfo); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | mPendingDirectToVoicemailCallInfo = null; |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | void handleFailedIncoming() { |
| 478 | clearCallService(); |
| 479 | |
| 480 | // TODO: Needs more specific disconnect error for this case. |
| 481 | setDisconnectCause(DisconnectCause.ERROR_UNSPECIFIED, null); |
| 482 | setState(CallState.DISCONNECTED); |
| 483 | |
| 484 | // TODO(santoscordon): Replace this with state transitions related to "connecting". |
| 485 | for (Listener l : mListeners) { |
| 486 | l.onFailedIncomingCall(this); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /** |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 491 | * Starts the outgoing call sequence. Upon completion, there should exist an active connection |
| 492 | * through a call service (or the call will have failed). |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 493 | */ |
| 494 | void startOutgoing() { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 495 | Preconditions.checkState(mOutgoingCallProcessor == null); |
| 496 | |
| 497 | mOutgoingCallProcessor = new OutgoingCallProcessor( |
| 498 | this, |
| 499 | Switchboard.getInstance().getCallServiceRepository(), |
| 500 | Switchboard.getInstance().getSelectorRepository(), |
| 501 | new AsyncResultCallback<Boolean>() { |
| 502 | @Override |
| 503 | public void onResult(Boolean wasCallPlaced) { |
| 504 | if (wasCallPlaced) { |
| 505 | handleSuccessfulOutgoing(); |
| 506 | } else { |
| 507 | handleFailedOutgoing(mOutgoingCallProcessor.isAborted()); |
| 508 | } |
| 509 | mOutgoingCallProcessor = null; |
| 510 | } |
| 511 | }); |
| 512 | mOutgoingCallProcessor.process(); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | void handleSuccessfulOutgoing() { |
| 516 | // TODO(santoscordon): Replace this with state transitions related to "connecting". |
| 517 | for (Listener l : mListeners) { |
| 518 | l.onSuccessfulOutgoingCall(this); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | void handleFailedOutgoing(boolean isAborted) { |
| 523 | // TODO(santoscordon): Replace this with state transitions related to "connecting". |
| 524 | for (Listener l : mListeners) { |
| 525 | l.onFailedOutgoingCall(this, isAborted); |
| 526 | } |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 527 | |
| 528 | clearCallService(); |
| 529 | clearCallServiceSelector(); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /** |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 533 | * Adds the specified call service to the list of incompatible services. The set is used when |
| 534 | * attempting to switch a phone call between call services such that incompatible services can |
| 535 | * be avoided. |
| 536 | * |
| 537 | * @param callService The incompatible call service. |
| 538 | */ |
| 539 | void addIncompatibleCallService(CallServiceWrapper callService) { |
| 540 | if (mIncompatibleCallServices == null) { |
| 541 | mIncompatibleCallServices = Sets.newHashSet(); |
| 542 | } |
| 543 | mIncompatibleCallServices.add(callService); |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Checks whether or not the specified callService was identified as incompatible in the |
| 548 | * context of this call. |
| 549 | * |
| 550 | * @param callService The call service to evaluate. |
| 551 | * @return True upon incompatible call services and false otherwise. |
| 552 | */ |
| 553 | boolean isIncompatibleCallService(CallServiceWrapper callService) { |
| 554 | return mIncompatibleCallServices != null && |
| 555 | mIncompatibleCallServices.contains(callService); |
| 556 | } |
| 557 | |
| 558 | /** |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 559 | * Plays the specified DTMF tone. |
| 560 | */ |
| 561 | void playDtmfTone(char digit) { |
| 562 | if (mCallService == null) { |
| 563 | Log.w(this, "playDtmfTone() request on a call without a call service."); |
| 564 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 565 | Log.i(this, "Send playDtmfTone to call service for call %s", this); |
| 566 | mCallService.playDtmfTone(this, digit); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Stops playing any currently playing DTMF tone. |
| 572 | */ |
| 573 | void stopDtmfTone() { |
| 574 | if (mCallService == null) { |
| 575 | Log.w(this, "stopDtmfTone() request on a call without a call service."); |
| 576 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 577 | Log.i(this, "Send stopDtmfTone to call service for call %s", this); |
| 578 | mCallService.stopDtmfTone(this); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
| 582 | /** |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 583 | * Attempts to disconnect the call through the call service. |
| 584 | */ |
| 585 | void disconnect() { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 586 | if (mState == CallState.NEW) { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 587 | Log.v(this, "Aborting call %s", this); |
| 588 | abort(); |
Santos Cordon | 74d420b | 2014-05-07 14:38:47 -0700 | [diff] [blame] | 589 | } else if (mState != CallState.ABORTED && mState != CallState.DISCONNECTED) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 590 | Preconditions.checkNotNull(mCallService); |
| 591 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 592 | Log.i(this, "Send disconnect to call service for call: %s", this); |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 593 | // The call isn't officially disconnected until the call service confirms that the call |
| 594 | // was actually disconnected. Only then is the association between call and call service |
| 595 | // severed, see {@link CallsManager#markCallAsDisconnected}. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 596 | mCallService.disconnect(this); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 600 | void abort() { |
| 601 | if (mOutgoingCallProcessor != null) { |
| 602 | mOutgoingCallProcessor.abort(); |
| 603 | } |
| 604 | } |
| 605 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 606 | /** |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 607 | * Answers the call if it is ringing. |
| 608 | */ |
| 609 | void answer() { |
| 610 | Preconditions.checkNotNull(mCallService); |
| 611 | |
| 612 | // Check to verify that the call is still in the ringing state. A call can change states |
| 613 | // between the time the user hits 'answer' and Telecomm receives the command. |
| 614 | if (isRinging("answer")) { |
| 615 | // At this point, we are asking the call service to answer but we don't assume that |
| 616 | // it will work. Instead, we wait until confirmation from the call service that the |
| 617 | // call is in a non-RINGING state before changing the UI. See |
| 618 | // {@link CallServiceAdapter#setActive} and other set* methods. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 619 | mCallService.answer(this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Rejects the call if it is ringing. |
| 625 | */ |
| 626 | void reject() { |
| 627 | Preconditions.checkNotNull(mCallService); |
| 628 | |
| 629 | // Check to verify that the call is still in the ringing state. A call can change states |
| 630 | // between the time the user hits 'reject' and Telecomm receives the command. |
| 631 | if (isRinging("reject")) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 632 | mCallService.reject(this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
| 636 | /** |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 637 | * Puts the call on hold if it is currently active. |
| 638 | */ |
| 639 | void hold() { |
| 640 | Preconditions.checkNotNull(mCallService); |
| 641 | |
| 642 | if (mState == CallState.ACTIVE) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 643 | mCallService.hold(this); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Releases the call from hold if it is currently active. |
| 649 | */ |
| 650 | void unhold() { |
| 651 | Preconditions.checkNotNull(mCallService); |
| 652 | |
| 653 | if (mState == CallState.ON_HOLD) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 654 | mCallService.unhold(this); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
| 658 | /** |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 659 | * @return An object containing read-only information about this call. |
| 660 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 661 | CallInfo toCallInfo(String callId) { |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 662 | CallServiceDescriptor descriptor = null; |
| 663 | if (mCallService != null) { |
| 664 | descriptor = mCallService.getDescriptor(); |
| 665 | } else if (mOriginalCall != null && mOriginalCall.mCallService != null) { |
| 666 | descriptor = mOriginalCall.mCallService.getDescriptor(); |
| 667 | } |
| 668 | return new CallInfo(callId, mState, mHandle, mGatewayInfo, mExtras, descriptor); |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 671 | /** Checks if this is a live call or not. */ |
| 672 | boolean isAlive() { |
| 673 | switch (mState) { |
| 674 | case NEW: |
| 675 | case RINGING: |
| 676 | case DISCONNECTED: |
| 677 | case ABORTED: |
| 678 | return false; |
| 679 | default: |
| 680 | return true; |
| 681 | } |
| 682 | } |
| 683 | |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 684 | boolean isActive() { |
| 685 | switch (mState) { |
| 686 | case ACTIVE: |
| 687 | case POST_DIAL: |
| 688 | case POST_DIAL_WAIT: |
| 689 | return true; |
| 690 | default: |
| 691 | return false; |
| 692 | } |
| 693 | } |
| 694 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 695 | Bundle getExtras() { |
| 696 | return mExtras; |
| 697 | } |
| 698 | |
| 699 | void setExtras(Bundle extras) { |
| 700 | mExtras = extras; |
| 701 | } |
| 702 | |
| 703 | Uri getHandoffHandle() { |
| 704 | return mHandoffHandle; |
| 705 | } |
| 706 | |
| 707 | void setHandoffHandle(Uri handoffHandle) { |
| 708 | mHandoffHandle = handoffHandle; |
| 709 | } |
| 710 | |
| 711 | Call getOriginalCall() { |
| 712 | return mOriginalCall; |
| 713 | } |
| 714 | |
| 715 | void setOriginalCall(Call originalCall) { |
| 716 | mOriginalCall = originalCall; |
| 717 | } |
| 718 | |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 719 | CallServiceDescriptor getHandoffCallServiceDescriptor() { |
| 720 | return mHandoffCallServiceDescriptor; |
| 721 | } |
| 722 | |
| 723 | void setHandoffCallServiceDescriptor(CallServiceDescriptor descriptor) { |
| 724 | mHandoffCallServiceDescriptor = descriptor; |
| 725 | } |
| 726 | |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 727 | Uri getRingtone() { |
| 728 | return mCallerInfo == null ? null : mCallerInfo.contactRingtoneUri; |
| 729 | } |
| 730 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 731 | /** |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 732 | * @return True if the call is ringing, else logs the action name. |
| 733 | */ |
| 734 | private boolean isRinging(String actionName) { |
| 735 | if (mState == CallState.RINGING) { |
| 736 | return true; |
| 737 | } |
| 738 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 739 | Log.i(this, "Request to %s a non-ringing call %s", actionName, this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 740 | return false; |
| 741 | } |
| 742 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 743 | @SuppressWarnings("rawtypes") |
| 744 | private void decrementAssociatedCallCount(ServiceBinder binder) { |
| 745 | if (binder != null) { |
| 746 | binder.decrementAssociatedCallCount(); |
| 747 | } |
| 748 | } |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 749 | |
| 750 | /** |
| 751 | * Looks up contact information based on the current handle. |
| 752 | */ |
| 753 | private void startCallerInfoLookup() { |
| 754 | String number = mHandle == null ? null : mHandle.getSchemeSpecificPart(); |
| 755 | |
| 756 | mQueryToken++; // Updated so that previous queries can no longer set the information. |
| 757 | mCallerInfo = null; |
| 758 | if (!TextUtils.isEmpty(number)) { |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 759 | Log.v(this, "Looking up information for: %s.", Log.piiHandle(number)); |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 760 | CallerInfoAsyncQuery.startQuery( |
| 761 | mQueryToken, |
| 762 | TelecommApp.getInstance(), |
| 763 | number, |
| 764 | sCallerInfoQueryListener, |
| 765 | this); |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | /** |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 770 | * Saves the specified caller info if the specified token matches that of the last query |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 771 | * that was made. |
| 772 | * |
| 773 | * @param callerInfo The new caller information to set. |
| 774 | * @param token The token used with this query. |
| 775 | */ |
| 776 | private void setCallerInfo(CallerInfo callerInfo, int token) { |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 777 | Preconditions.checkNotNull(callerInfo); |
| 778 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 779 | if (mQueryToken == token) { |
| 780 | mCallerInfo = callerInfo; |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 781 | Log.i(this, "CallerInfo received for %s: %s", Log.piiHandle(mHandle), callerInfo); |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 782 | |
| 783 | if (mCallerInfo.person_id != 0) { |
| 784 | Uri personUri = |
| 785 | ContentUris.withAppendedId(Contacts.CONTENT_URI, mCallerInfo.person_id); |
| 786 | Log.d(this, "Searching person uri %s for call %s", personUri, this); |
| 787 | ContactsAsyncHelper.startObtainPhotoAsync( |
| 788 | token, |
| 789 | TelecommApp.getInstance(), |
| 790 | personUri, |
| 791 | sPhotoLoadListener, |
| 792 | this); |
| 793 | } |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 794 | |
| 795 | processDirectToVoicemail(); |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 796 | } |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * Saves the specified photo information if the specified token matches that of the last query. |
| 801 | * |
| 802 | * @param photo The photo as a drawable. |
| 803 | * @param photoIcon The photo as a small icon. |
| 804 | * @param token The token used with this query. |
| 805 | */ |
| 806 | private void setPhoto(Drawable photo, Bitmap photoIcon, int token) { |
| 807 | if (mQueryToken == token) { |
| 808 | mCallerInfo.cachedPhoto = photo; |
| 809 | mCallerInfo.cachedPhotoIcon = photoIcon; |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 810 | } |
| 811 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 812 | } |