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 | |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 19 | import android.net.Uri; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 21 | import android.telecomm.CallInfo; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 22 | import android.telecomm.CallServiceDescriptor; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 23 | import android.telecomm.CallState; |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 24 | import android.telecomm.GatewayInfo; |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 25 | import android.telephony.DisconnectCause; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 26 | import android.telephony.PhoneNumberUtils; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 27 | |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 28 | import com.google.android.collect.Sets; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 29 | import com.google.common.base.Preconditions; |
| 30 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 31 | import java.util.Date; |
Sailesh Nepal | 9199078 | 2014-03-08 17:45:52 -0800 | [diff] [blame] | 32 | import java.util.Locale; |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 33 | import java.util.Set; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 34 | |
Ben Gilad | 2495d57 | 2014-01-09 17:26:19 -0800 | [diff] [blame] | 35 | /** |
| 36 | * Encapsulates all aspects of a given phone call throughout its lifecycle, starting |
| 37 | * from the time the call intent was received by Telecomm (vs. the time the call was |
| 38 | * connected etc). |
| 39 | */ |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 40 | final class Call { |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 41 | /** Additional contact information beyond handle above, optional. */ |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 42 | private final ContactInfo mContactInfo; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 43 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 44 | /** True if this is an incoming call. */ |
| 45 | private final boolean mIsIncoming; |
| 46 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 47 | /** |
| 48 | * The time this call was created, typically also the time this call was added to the set |
| 49 | * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard. |
| 50 | * Beyond logging and such, may also be used for bookkeeping and specifically for marking |
| 51 | * certain call attempts as failed attempts. |
| 52 | */ |
| 53 | private final Date mCreationTime; |
| 54 | |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 55 | /** The state of the call. */ |
| 56 | private CallState mState; |
| 57 | |
| 58 | /** The handle with which to establish this call. */ |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 59 | private Uri mHandle; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 60 | |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 61 | /** The gateway information associated with this call. This stores the original call handle |
| 62 | * that the user is attempting to connect to via the gateway, the actual handle to dial in |
| 63 | * order to connect the call via the gateway, as well as the package name of the gateway |
| 64 | * service. */ |
| 65 | private final GatewayInfo mGatewayInfo; |
| 66 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 67 | /** |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 68 | * The call service which is attempted or already connecting this call. |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 69 | */ |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 70 | private CallServiceWrapper mCallService; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 71 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 72 | /** |
| 73 | * The call-service selector for this call. |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 74 | */ |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 75 | private CallServiceSelectorWrapper mCallServiceSelector; |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 76 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 77 | /** |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 78 | * The set of call services that were attempted in the process of placing/switching this call |
| 79 | * but turned out unsuitable. Only used in the context of call switching. |
| 80 | */ |
| 81 | private Set<CallServiceWrapper> mIncompatibleCallServices; |
| 82 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 83 | private boolean mIsEmergencyCall; |
| 84 | |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 85 | /** |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 86 | * Disconnect cause for the call. Only valid if the state of the call is DISCONNECTED. |
| 87 | * See {@link android.telephony.DisconnectCause}. |
| 88 | */ |
| 89 | private int mDisconnectCause; |
| 90 | |
| 91 | /** |
| 92 | * Additional disconnect information provided by the call service. |
| 93 | */ |
| 94 | private String mDisconnectMessage; |
| 95 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 96 | /** Info used by the call services. */ |
| 97 | private Bundle mExtras; |
| 98 | |
| 99 | /** The Uri to dial to perform the handoff. If this is null then handoff is not supported. */ |
| 100 | private Uri mHandoffHandle; |
| 101 | |
| 102 | /** |
| 103 | * References the call that is being handed off. This value is non-null for untracked calls |
| 104 | * that are being used to perform a handoff. |
| 105 | */ |
| 106 | private Call mOriginalCall; |
| 107 | |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 108 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 109 | * Creates an empty call object. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 110 | * |
| 111 | * @param isIncoming True if this is an incoming call. |
Santos Cordon | 493e8f2 | 2014-02-19 03:15:12 -0800 | [diff] [blame] | 112 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 113 | Call(boolean isIncoming) { |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 114 | this(null, null, null, isIncoming); |
Santos Cordon | 493e8f2 | 2014-02-19 03:15:12 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /** |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 118 | * Persists the specified parameters and initializes the new instance. |
| 119 | * |
| 120 | * @param handle The handle to dial. |
| 121 | * @param contactInfo Information about the entity being called. |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 122 | * @param gatewayInfo Gateway information to use for the call. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 123 | * @param isIncoming True if this is an incoming call. |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 124 | */ |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 125 | Call(Uri handle, ContactInfo contactInfo, GatewayInfo gatewayInfo, boolean isIncoming) { |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 126 | mState = CallState.NEW; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 127 | setHandle(handle); |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 128 | mContactInfo = contactInfo; |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 129 | mGatewayInfo = gatewayInfo; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 130 | mIsIncoming = isIncoming; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 131 | mCreationTime = new Date(); |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 132 | mDisconnectCause = DisconnectCause.NOT_VALID; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 133 | mExtras = Bundle.EMPTY; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 136 | /** {@inheritDoc} */ |
| 137 | @Override public String toString() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 138 | return String.format(Locale.US, "[%s, %s, %s]", mState, |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 139 | mCallService == null ? "<null>" : mCallService.getComponentName(), |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 140 | Log.piiHandle(mHandle)); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 143 | CallState getState() { |
| 144 | return mState; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Sets the call state. Although there exists the notion of appropriate state transitions |
| 149 | * (see {@link CallState}), in practice those expectations break down when cellular systems |
| 150 | * misbehave and they do this very often. The result is that we do not enforce state transitions |
| 151 | * and instead keep the code resilient to unexpected state changes. |
| 152 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 153 | void setState(CallState newState) { |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 154 | Preconditions.checkState(newState != CallState.DISCONNECTED || |
| 155 | mDisconnectCause != DisconnectCause.NOT_VALID); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 156 | if (mState != newState) { |
| 157 | Log.v(this, "setState %s -> %s", mState, newState); |
| 158 | mState = newState; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 159 | } |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 162 | Uri getHandle() { |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 163 | return mHandle; |
| 164 | } |
| 165 | |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 166 | void setHandle(Uri handle) { |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 167 | mHandle = handle; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 168 | mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber( |
| 169 | mHandle.getSchemeSpecificPart(), TelecommApp.getInstance()); |
| 170 | } |
| 171 | |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 172 | /** |
| 173 | * @param disconnectCause The reason for the disconnection, any of |
| 174 | * {@link android.telephony.DisconnectCause}. |
| 175 | * @param disconnectMessage Optional call-service-provided message about the disconnect. |
| 176 | */ |
| 177 | void setDisconnectCause(int disconnectCause, String disconnectMessage) { |
| 178 | // TODO: Consider combining this method with a setDisconnected() method that is totally |
| 179 | // separate from setState. |
| 180 | mDisconnectCause = disconnectCause; |
| 181 | mDisconnectMessage = disconnectMessage; |
| 182 | } |
| 183 | |
| 184 | int getDisconnectCause() { |
| 185 | return mDisconnectCause; |
| 186 | } |
| 187 | |
| 188 | String getDisconnectMessage() { |
| 189 | return mDisconnectMessage; |
| 190 | } |
| 191 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 192 | boolean isEmergencyCall() { |
| 193 | return mIsEmergencyCall; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 196 | /** |
| 197 | * @return The original handle this call is associated with. In-call services should use this |
| 198 | * handle when indicating in their UI the handle that is being called. |
| 199 | */ |
| 200 | public Uri getOriginalHandle() { |
| 201 | if (mGatewayInfo != null && !mGatewayInfo.isEmpty()) { |
| 202 | return mGatewayInfo.getOriginalHandle(); |
| 203 | } |
| 204 | return getHandle(); |
| 205 | } |
| 206 | |
| 207 | GatewayInfo getGatewayInfo() { |
| 208 | return mGatewayInfo; |
| 209 | } |
| 210 | |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 211 | ContactInfo getContactInfo() { |
| 212 | return mContactInfo; |
| 213 | } |
| 214 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 215 | boolean isIncoming() { |
| 216 | return mIsIncoming; |
| 217 | } |
| 218 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 219 | /** |
| 220 | * @return The "age" of this call object in milliseconds, which typically also represents the |
| 221 | * period since this call was added to the set pending outgoing calls, see mCreationTime. |
| 222 | */ |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 223 | long getAgeMs() { |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 224 | return new Date().getTime() - mCreationTime.getTime(); |
| 225 | } |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 226 | |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 227 | /** |
| 228 | * @return The time when this call object was created and added to the set of pending outgoing |
| 229 | * calls. |
| 230 | */ |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 231 | long getCreationTimeMs() { |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 232 | return mCreationTime.getTime(); |
| 233 | } |
| 234 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 235 | CallServiceWrapper getCallService() { |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 236 | return mCallService; |
| 237 | } |
| 238 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 239 | void setCallService(CallServiceWrapper callService) { |
Sailesh Nepal | 0e5410a | 2014-04-04 01:20:58 -0700 | [diff] [blame^] | 240 | setCallService(callService, null); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Changes the call service this call is associated with. If callToReplace is non-null then this |
| 245 | * call takes its place within the call service. |
| 246 | */ |
| 247 | void setCallService(CallServiceWrapper callService, Call callToReplace) { |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 248 | Preconditions.checkNotNull(callService); |
| 249 | |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 250 | clearCallService(); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 251 | |
| 252 | callService.incrementAssociatedCallCount(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 253 | mCallService = callService; |
Sailesh Nepal | 0e5410a | 2014-04-04 01:20:58 -0700 | [diff] [blame^] | 254 | if (callToReplace == null) { |
| 255 | mCallService.addCall(this); |
| 256 | } else { |
| 257 | mCallService.replaceCall(this, callToReplace); |
| 258 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Clears the associated call service. |
| 263 | */ |
| 264 | void clearCallService() { |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 265 | if (mCallService != null) { |
| 266 | decrementAssociatedCallCount(mCallService); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 267 | mCallService.removeCall(this); |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 268 | mCallService = null; |
| 269 | } |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 272 | CallServiceSelectorWrapper getCallServiceSelector() { |
| 273 | return mCallServiceSelector; |
| 274 | } |
| 275 | |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 276 | void setCallServiceSelector(CallServiceSelectorWrapper selector) { |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 277 | Preconditions.checkNotNull(selector); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 278 | |
| 279 | clearCallServiceSelector(); |
| 280 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 281 | mCallServiceSelector = selector; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 282 | mCallServiceSelector.addCall(this); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void clearCallServiceSelector() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 286 | if (mCallServiceSelector != null) { |
| 287 | // TODO(sail): Stop leaking selectors. |
| 288 | // decrementAssociatedCallCount(mCallServiceSelector); |
| 289 | mCallServiceSelector.removeCall(this); |
| 290 | mCallServiceSelector = null; |
| 291 | } |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 295 | * Adds the specified call service to the list of incompatible services. The set is used when |
| 296 | * attempting to switch a phone call between call services such that incompatible services can |
| 297 | * be avoided. |
| 298 | * |
| 299 | * @param callService The incompatible call service. |
| 300 | */ |
| 301 | void addIncompatibleCallService(CallServiceWrapper callService) { |
| 302 | if (mIncompatibleCallServices == null) { |
| 303 | mIncompatibleCallServices = Sets.newHashSet(); |
| 304 | } |
| 305 | mIncompatibleCallServices.add(callService); |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Checks whether or not the specified callService was identified as incompatible in the |
| 310 | * context of this call. |
| 311 | * |
| 312 | * @param callService The call service to evaluate. |
| 313 | * @return True upon incompatible call services and false otherwise. |
| 314 | */ |
| 315 | boolean isIncompatibleCallService(CallServiceWrapper callService) { |
| 316 | return mIncompatibleCallServices != null && |
| 317 | mIncompatibleCallServices.contains(callService); |
| 318 | } |
| 319 | |
| 320 | /** |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 321 | * Aborts ongoing attempts to connect this call. Only applicable to {@link CallState#NEW} |
| 322 | * outgoing calls. See {@link #disconnect} for already-connected calls. |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 323 | */ |
| 324 | void abort() { |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 325 | if (mState == CallState.NEW) { |
| 326 | if (mCallService != null) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 327 | mCallService.abort(this); |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 328 | } |
Ben Gilad | 9c23411 | 2014-03-04 16:07:33 -0800 | [diff] [blame] | 329 | clearCallService(); |
| 330 | clearCallServiceSelector(); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 331 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 334 | /** |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 335 | * Plays the specified DTMF tone. |
| 336 | */ |
| 337 | void playDtmfTone(char digit) { |
| 338 | if (mCallService == null) { |
| 339 | Log.w(this, "playDtmfTone() request on a call without a call service."); |
| 340 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 341 | Log.i(this, "Send playDtmfTone to call service for call %s", this); |
| 342 | mCallService.playDtmfTone(this, digit); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Stops playing any currently playing DTMF tone. |
| 348 | */ |
| 349 | void stopDtmfTone() { |
| 350 | if (mCallService == null) { |
| 351 | Log.w(this, "stopDtmfTone() request on a call without a call service."); |
| 352 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 353 | Log.i(this, "Send stopDtmfTone to call service for call %s", this); |
| 354 | mCallService.stopDtmfTone(this); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
| 358 | /** |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 359 | * Attempts to disconnect the call through the call service. |
| 360 | */ |
| 361 | void disconnect() { |
| 362 | if (mCallService == null) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 363 | Log.w(this, "disconnect() request on a call without a call service."); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 364 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 365 | Log.i(this, "Send disconnect to call service for call: %s", this); |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 366 | // The call isn't officially disconnected until the call service confirms that the call |
| 367 | // was actually disconnected. Only then is the association between call and call service |
| 368 | // severed, see {@link CallsManager#markCallAsDisconnected}. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 369 | mCallService.disconnect(this); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 373 | /** |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 374 | * Answers the call if it is ringing. |
| 375 | */ |
| 376 | void answer() { |
| 377 | Preconditions.checkNotNull(mCallService); |
| 378 | |
| 379 | // Check to verify that the call is still in the ringing state. A call can change states |
| 380 | // between the time the user hits 'answer' and Telecomm receives the command. |
| 381 | if (isRinging("answer")) { |
| 382 | // At this point, we are asking the call service to answer but we don't assume that |
| 383 | // it will work. Instead, we wait until confirmation from the call service that the |
| 384 | // call is in a non-RINGING state before changing the UI. See |
| 385 | // {@link CallServiceAdapter#setActive} and other set* methods. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 386 | mCallService.answer(this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Rejects the call if it is ringing. |
| 392 | */ |
| 393 | void reject() { |
| 394 | Preconditions.checkNotNull(mCallService); |
| 395 | |
| 396 | // Check to verify that the call is still in the ringing state. A call can change states |
| 397 | // between the time the user hits 'reject' and Telecomm receives the command. |
| 398 | if (isRinging("reject")) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 399 | mCallService.reject(this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
| 403 | /** |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 404 | * Puts the call on hold if it is currently active. |
| 405 | */ |
| 406 | void hold() { |
| 407 | Preconditions.checkNotNull(mCallService); |
| 408 | |
| 409 | if (mState == CallState.ACTIVE) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 410 | mCallService.hold(this); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Releases the call from hold if it is currently active. |
| 416 | */ |
| 417 | void unhold() { |
| 418 | Preconditions.checkNotNull(mCallService); |
| 419 | |
| 420 | if (mState == CallState.ON_HOLD) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 421 | mCallService.unhold(this); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
| 425 | /** |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 426 | * @return An object containing read-only information about this call. |
| 427 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 428 | CallInfo toCallInfo(String callId) { |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 429 | CallServiceDescriptor descriptor = null; |
| 430 | if (mCallService != null) { |
| 431 | descriptor = mCallService.getDescriptor(); |
| 432 | } else if (mOriginalCall != null && mOriginalCall.mCallService != null) { |
| 433 | descriptor = mOriginalCall.mCallService.getDescriptor(); |
| 434 | } |
| 435 | return new CallInfo(callId, mState, mHandle, mGatewayInfo, mExtras, descriptor); |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 438 | /** Checks if this is a live call or not. */ |
| 439 | boolean isAlive() { |
| 440 | switch (mState) { |
| 441 | case NEW: |
| 442 | case RINGING: |
| 443 | case DISCONNECTED: |
| 444 | case ABORTED: |
| 445 | return false; |
| 446 | default: |
| 447 | return true; |
| 448 | } |
| 449 | } |
| 450 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 451 | Bundle getExtras() { |
| 452 | return mExtras; |
| 453 | } |
| 454 | |
| 455 | void setExtras(Bundle extras) { |
| 456 | mExtras = extras; |
| 457 | } |
| 458 | |
| 459 | Uri getHandoffHandle() { |
| 460 | return mHandoffHandle; |
| 461 | } |
| 462 | |
| 463 | void setHandoffHandle(Uri handoffHandle) { |
| 464 | mHandoffHandle = handoffHandle; |
| 465 | } |
| 466 | |
| 467 | Call getOriginalCall() { |
| 468 | return mOriginalCall; |
| 469 | } |
| 470 | |
| 471 | void setOriginalCall(Call originalCall) { |
| 472 | mOriginalCall = originalCall; |
| 473 | } |
| 474 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 475 | /** |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 476 | * @return True if the call is ringing, else logs the action name. |
| 477 | */ |
| 478 | private boolean isRinging(String actionName) { |
| 479 | if (mState == CallState.RINGING) { |
| 480 | return true; |
| 481 | } |
| 482 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 483 | 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] | 484 | return false; |
| 485 | } |
| 486 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 487 | @SuppressWarnings("rawtypes") |
| 488 | private void decrementAssociatedCallCount(ServiceBinder binder) { |
| 489 | if (binder != null) { |
| 490 | binder.decrementAssociatedCallCount(); |
| 491 | } |
| 492 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 493 | } |