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