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) { |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 240 | Preconditions.checkNotNull(callService); |
| 241 | |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 242 | clearCallService(); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 243 | |
| 244 | callService.incrementAssociatedCallCount(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 245 | mCallService = callService; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 246 | mCallService.addCall(this); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Clears the associated call service. |
| 251 | */ |
| 252 | void clearCallService() { |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 253 | if (mCallService != null) { |
| 254 | decrementAssociatedCallCount(mCallService); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 255 | mCallService.removeCall(this); |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 256 | mCallService = null; |
| 257 | } |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 260 | CallServiceSelectorWrapper getCallServiceSelector() { |
| 261 | return mCallServiceSelector; |
| 262 | } |
| 263 | |
Sailesh Nepal | 18386a8 | 2014-03-19 10:22:40 -0700 | [diff] [blame] | 264 | void setCallServiceSelector(CallServiceSelectorWrapper selector) { |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 265 | Preconditions.checkNotNull(selector); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 266 | |
| 267 | clearCallServiceSelector(); |
| 268 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 269 | mCallServiceSelector = selector; |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 270 | mCallServiceSelector.addCall(this); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void clearCallServiceSelector() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 274 | if (mCallServiceSelector != null) { |
| 275 | // TODO(sail): Stop leaking selectors. |
| 276 | // decrementAssociatedCallCount(mCallServiceSelector); |
| 277 | mCallServiceSelector.removeCall(this); |
| 278 | mCallServiceSelector = null; |
| 279 | } |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /** |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 283 | * Adds the specified call service to the list of incompatible services. The set is used when |
| 284 | * attempting to switch a phone call between call services such that incompatible services can |
| 285 | * be avoided. |
| 286 | * |
| 287 | * @param callService The incompatible call service. |
| 288 | */ |
| 289 | void addIncompatibleCallService(CallServiceWrapper callService) { |
| 290 | if (mIncompatibleCallServices == null) { |
| 291 | mIncompatibleCallServices = Sets.newHashSet(); |
| 292 | } |
| 293 | mIncompatibleCallServices.add(callService); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Checks whether or not the specified callService was identified as incompatible in the |
| 298 | * context of this call. |
| 299 | * |
| 300 | * @param callService The call service to evaluate. |
| 301 | * @return True upon incompatible call services and false otherwise. |
| 302 | */ |
| 303 | boolean isIncompatibleCallService(CallServiceWrapper callService) { |
| 304 | return mIncompatibleCallServices != null && |
| 305 | mIncompatibleCallServices.contains(callService); |
| 306 | } |
| 307 | |
| 308 | /** |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 309 | * Aborts ongoing attempts to connect this call. Only applicable to {@link CallState#NEW} |
| 310 | * outgoing calls. See {@link #disconnect} for already-connected calls. |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 311 | */ |
| 312 | void abort() { |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 313 | if (mState == CallState.NEW) { |
| 314 | if (mCallService != null) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 315 | mCallService.abort(this); |
Ben Gilad | 28e8ad6 | 2014-03-06 17:01:54 -0800 | [diff] [blame] | 316 | } |
Ben Gilad | 9c23411 | 2014-03-04 16:07:33 -0800 | [diff] [blame] | 317 | clearCallService(); |
| 318 | clearCallServiceSelector(); |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 319 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 322 | /** |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 323 | * Plays the specified DTMF tone. |
| 324 | */ |
| 325 | void playDtmfTone(char digit) { |
| 326 | if (mCallService == null) { |
| 327 | Log.w(this, "playDtmfTone() request on a call without a call service."); |
| 328 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 329 | Log.i(this, "Send playDtmfTone to call service for call %s", this); |
| 330 | mCallService.playDtmfTone(this, digit); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Stops playing any currently playing DTMF tone. |
| 336 | */ |
| 337 | void stopDtmfTone() { |
| 338 | if (mCallService == null) { |
| 339 | Log.w(this, "stopDtmfTone() 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 stopDtmfTone to call service for call %s", this); |
| 342 | mCallService.stopDtmfTone(this); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
| 346 | /** |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 347 | * Attempts to disconnect the call through the call service. |
| 348 | */ |
| 349 | void disconnect() { |
| 350 | if (mCallService == null) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 351 | Log.w(this, "disconnect() request on a call without a call service."); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 352 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 353 | Log.i(this, "Send disconnect to call service for call: %s", this); |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 354 | // The call isn't officially disconnected until the call service confirms that the call |
| 355 | // was actually disconnected. Only then is the association between call and call service |
| 356 | // severed, see {@link CallsManager#markCallAsDisconnected}. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 357 | mCallService.disconnect(this); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 361 | /** |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 362 | * Answers the call if it is ringing. |
| 363 | */ |
| 364 | void answer() { |
| 365 | Preconditions.checkNotNull(mCallService); |
| 366 | |
| 367 | // Check to verify that the call is still in the ringing state. A call can change states |
| 368 | // between the time the user hits 'answer' and Telecomm receives the command. |
| 369 | if (isRinging("answer")) { |
| 370 | // At this point, we are asking the call service to answer but we don't assume that |
| 371 | // it will work. Instead, we wait until confirmation from the call service that the |
| 372 | // call is in a non-RINGING state before changing the UI. See |
| 373 | // {@link CallServiceAdapter#setActive} and other set* methods. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 374 | mCallService.answer(this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Rejects the call if it is ringing. |
| 380 | */ |
| 381 | void reject() { |
| 382 | Preconditions.checkNotNull(mCallService); |
| 383 | |
| 384 | // Check to verify that the call is still in the ringing state. A call can change states |
| 385 | // between the time the user hits 'reject' and Telecomm receives the command. |
| 386 | if (isRinging("reject")) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 387 | mCallService.reject(this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
| 391 | /** |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 392 | * Puts the call on hold if it is currently active. |
| 393 | */ |
| 394 | void hold() { |
| 395 | Preconditions.checkNotNull(mCallService); |
| 396 | |
| 397 | if (mState == CallState.ACTIVE) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 398 | mCallService.hold(this); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Releases the call from hold if it is currently active. |
| 404 | */ |
| 405 | void unhold() { |
| 406 | Preconditions.checkNotNull(mCallService); |
| 407 | |
| 408 | if (mState == CallState.ON_HOLD) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 409 | mCallService.unhold(this); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
| 413 | /** |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 414 | * @return An object containing read-only information about this call. |
| 415 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 416 | CallInfo toCallInfo(String callId) { |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 417 | CallServiceDescriptor descriptor = null; |
| 418 | if (mCallService != null) { |
| 419 | descriptor = mCallService.getDescriptor(); |
| 420 | } else if (mOriginalCall != null && mOriginalCall.mCallService != null) { |
| 421 | descriptor = mOriginalCall.mCallService.getDescriptor(); |
| 422 | } |
| 423 | return new CallInfo(callId, mState, mHandle, mGatewayInfo, mExtras, descriptor); |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 426 | /** Checks if this is a live call or not. */ |
| 427 | boolean isAlive() { |
| 428 | switch (mState) { |
| 429 | case NEW: |
| 430 | case RINGING: |
| 431 | case DISCONNECTED: |
| 432 | case ABORTED: |
| 433 | return false; |
| 434 | default: |
| 435 | return true; |
| 436 | } |
| 437 | } |
| 438 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 439 | Bundle getExtras() { |
| 440 | return mExtras; |
| 441 | } |
| 442 | |
| 443 | void setExtras(Bundle extras) { |
| 444 | mExtras = extras; |
| 445 | } |
| 446 | |
| 447 | Uri getHandoffHandle() { |
| 448 | return mHandoffHandle; |
| 449 | } |
| 450 | |
| 451 | void setHandoffHandle(Uri handoffHandle) { |
| 452 | mHandoffHandle = handoffHandle; |
| 453 | } |
| 454 | |
| 455 | Call getOriginalCall() { |
| 456 | return mOriginalCall; |
| 457 | } |
| 458 | |
| 459 | void setOriginalCall(Call originalCall) { |
| 460 | mOriginalCall = originalCall; |
| 461 | } |
| 462 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 463 | /** |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 464 | * @return True if the call is ringing, else logs the action name. |
| 465 | */ |
| 466 | private boolean isRinging(String actionName) { |
| 467 | if (mState == CallState.RINGING) { |
| 468 | return true; |
| 469 | } |
| 470 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 471 | 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] | 472 | return false; |
| 473 | } |
| 474 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 475 | @SuppressWarnings("rawtypes") |
| 476 | private void decrementAssociatedCallCount(ServiceBinder binder) { |
| 477 | if (binder != null) { |
| 478 | binder.decrementAssociatedCallCount(); |
| 479 | } |
| 480 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 481 | } |