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