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