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