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