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