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 | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame^] | 19 | import android.content.ComponentName; |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 20 | import android.content.ContentUris; |
| 21 | import android.graphics.Bitmap; |
| 22 | import android.graphics.drawable.Drawable; |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 25 | import android.os.Handler; |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 26 | import android.provider.ContactsContract.Contacts; |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 27 | import android.telecomm.CallPropertyPresentation; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 28 | import android.telecomm.CallState; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 29 | import android.telecomm.ConnectionRequest; |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 30 | import android.telecomm.GatewayInfo; |
Ihab Awad | 98a5560 | 2014-06-30 21:27:28 -0700 | [diff] [blame] | 31 | import android.telecomm.PhoneAccount; |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 32 | import android.telecomm.Response; |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 33 | import android.telecomm.StatusHints; |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 34 | import android.telecomm.TelecommConstants; |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 35 | import android.telephony.DisconnectCause; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 36 | import android.telephony.PhoneNumberUtils; |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 37 | import android.text.TextUtils; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 38 | |
Nancy Chen | a65d41f | 2014-06-24 12:06:03 -0700 | [diff] [blame] | 39 | import com.android.internal.telecomm.ICallVideoProvider; |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 40 | import com.android.internal.telephony.CallerInfo; |
| 41 | import com.android.internal.telephony.CallerInfoAsyncQuery; |
| 42 | import com.android.internal.telephony.CallerInfoAsyncQuery.OnQueryCompleteListener; |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 43 | import com.android.internal.telephony.SmsApplication; |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 44 | import com.android.telecomm.ContactsAsyncHelper.OnImageLoadCompleteListener; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 45 | import com.google.common.base.Preconditions; |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 46 | import com.google.common.collect.Sets; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 47 | |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 48 | import java.util.Collections; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 49 | import java.util.LinkedList; |
| 50 | import java.util.List; |
Sailesh Nepal | 9199078 | 2014-03-08 17:45:52 -0800 | [diff] [blame] | 51 | import java.util.Locale; |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 52 | import java.util.Objects; |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 53 | import java.util.Set; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 54 | |
Ben Gilad | 2495d57 | 2014-01-09 17:26:19 -0800 | [diff] [blame] | 55 | /** |
| 56 | * Encapsulates all aspects of a given phone call throughout its lifecycle, starting |
| 57 | * from the time the call intent was received by Telecomm (vs. the time the call was |
| 58 | * connected etc). |
| 59 | */ |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 60 | final class Call implements OutgoingCallResponse { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 61 | /** |
| 62 | * Listener for events on the call. |
| 63 | */ |
| 64 | interface Listener { |
| 65 | void onSuccessfulOutgoingCall(Call call); |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 66 | void onFailedOutgoingCall(Call call, int errorCode, String errorMsg); |
| 67 | void onCancelledOutgoingCall(Call call); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 68 | void onSuccessfulIncomingCall(Call call); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 69 | void onFailedIncomingCall(Call call); |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 70 | void onRequestingRingback(Call call, boolean requestingRingback); |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 71 | void onPostDialWait(Call call, String remaining); |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 72 | void onCallCapabilitiesChanged(Call call); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 73 | void onExpiredConferenceCall(Call call); |
| 74 | void onConfirmedConferenceCall(Call call); |
| 75 | void onParentChanged(Call call); |
| 76 | void onChildrenChanged(Call call); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 77 | void onCannedSmsResponsesLoaded(Call call); |
Nancy Chen | a65d41f | 2014-06-24 12:06:03 -0700 | [diff] [blame] | 78 | void onCallVideoProviderChanged(Call call); |
Santos Cordon | 64c7e96 | 2014-07-02 15:15:27 -0700 | [diff] [blame] | 79 | void onCallerInfoChanged(Call call); |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 80 | void onAudioModeIsVoipChanged(Call call); |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 81 | void onStatusHintsChanged(Call call); |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 82 | void onHandleChanged(Call call); |
| 83 | void onCallerDisplayNameChanged(Call call); |
Santos Cordon | 64c7e96 | 2014-07-02 15:15:27 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | abstract static class ListenerBase implements Listener { |
| 87 | @Override |
| 88 | public void onSuccessfulOutgoingCall(Call call) {} |
| 89 | @Override |
| 90 | public void onFailedOutgoingCall(Call call, int errorCode, String errorMsg) {} |
| 91 | @Override |
| 92 | public void onCancelledOutgoingCall(Call call) {} |
| 93 | @Override |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 94 | public void onSuccessfulIncomingCall(Call call) {} |
Santos Cordon | 64c7e96 | 2014-07-02 15:15:27 -0700 | [diff] [blame] | 95 | @Override |
| 96 | public void onFailedIncomingCall(Call call) {} |
| 97 | @Override |
| 98 | public void onRequestingRingback(Call call, boolean requestingRingback) {} |
| 99 | @Override |
| 100 | public void onPostDialWait(Call call, String remaining) {} |
| 101 | @Override |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 102 | public void onCallCapabilitiesChanged(Call call) {} |
Santos Cordon | 64c7e96 | 2014-07-02 15:15:27 -0700 | [diff] [blame] | 103 | @Override |
| 104 | public void onExpiredConferenceCall(Call call) {} |
| 105 | @Override |
| 106 | public void onConfirmedConferenceCall(Call call) {} |
| 107 | @Override |
| 108 | public void onParentChanged(Call call) {} |
| 109 | @Override |
| 110 | public void onChildrenChanged(Call call) {} |
| 111 | @Override |
| 112 | public void onCannedSmsResponsesLoaded(Call call) {} |
| 113 | @Override |
| 114 | public void onCallVideoProviderChanged(Call call) {} |
| 115 | @Override |
Santos Cordon | 64c7e96 | 2014-07-02 15:15:27 -0700 | [diff] [blame] | 116 | public void onCallerInfoChanged(Call call) {} |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 117 | @Override |
| 118 | public void onAudioModeIsVoipChanged(Call call) {} |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 119 | @Override |
| 120 | public void onStatusHintsChanged(Call call) {} |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 121 | @Override |
| 122 | public void onHandleChanged(Call call) {} |
| 123 | @Override |
| 124 | public void onCallerDisplayNameChanged(Call call) {} |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 127 | private static final OnQueryCompleteListener sCallerInfoQueryListener = |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 128 | new OnQueryCompleteListener() { |
| 129 | /** ${inheritDoc} */ |
| 130 | @Override |
| 131 | public void onQueryComplete(int token, Object cookie, CallerInfo callerInfo) { |
| 132 | if (cookie != null) { |
| 133 | ((Call) cookie).setCallerInfo(callerInfo, token); |
| 134 | } |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 135 | } |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | private static final OnImageLoadCompleteListener sPhotoLoadListener = |
| 139 | new OnImageLoadCompleteListener() { |
| 140 | /** ${inheritDoc} */ |
| 141 | @Override |
| 142 | public void onImageLoadComplete( |
| 143 | int token, Drawable photo, Bitmap photoIcon, Object cookie) { |
| 144 | if (cookie != null) { |
| 145 | ((Call) cookie).setPhoto(photo, photoIcon, token); |
| 146 | } |
| 147 | } |
| 148 | }; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 149 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 150 | /** True if this is an incoming call. */ |
| 151 | private final boolean mIsIncoming; |
| 152 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 153 | /** |
| 154 | * The time this call was created, typically also the time this call was added to the set |
| 155 | * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard. |
| 156 | * Beyond logging and such, may also be used for bookkeeping and specifically for marking |
| 157 | * certain call attempts as failed attempts. |
| 158 | */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 159 | private final long mCreationTimeMillis = System.currentTimeMillis(); |
| 160 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 161 | /** The gateway information associated with this call. This stores the original call handle |
| 162 | * that the user is attempting to connect to via the gateway, the actual handle to dial in |
| 163 | * order to connect the call via the gateway, as well as the package name of the gateway |
| 164 | * service. */ |
| 165 | private final GatewayInfo mGatewayInfo; |
| 166 | |
Sailesh Nepal | b0ba087 | 2014-07-08 22:09:50 -0700 | [diff] [blame] | 167 | private PhoneAccount mPhoneAccount; |
Nancy Chen | 77d2d0e | 2014-06-24 12:06:03 -0700 | [diff] [blame] | 168 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 169 | private final Handler mHandler = new Handler(); |
| 170 | |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 171 | private long mConnectTimeMillis; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 172 | |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 173 | /** The state of the call. */ |
| 174 | private CallState mState; |
| 175 | |
| 176 | /** The handle with which to establish this call. */ |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 177 | private Uri mHandle; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 178 | |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 179 | /** The {@link CallPropertyPresentation} that controls how the handle is shown. */ |
| 180 | private int mHandlePresentation; |
| 181 | |
| 182 | /** The caller display name (CNAP) set by the connection service. */ |
| 183 | private String mCallerDisplayName; |
| 184 | |
| 185 | /** The {@link CallPropertyPresentation} that controls how the caller display name is shown. */ |
| 186 | private int mCallerDisplayNamePresentation; |
| 187 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 188 | /** |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 189 | * The connection service which is attempted or already connecting this call. |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 190 | */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 191 | private ConnectionServiceWrapper mConnectionService; |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 192 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 193 | private boolean mIsEmergencyCall; |
| 194 | |
Sai Cheemalapati | b7157e9 | 2014-06-11 17:51:55 -0700 | [diff] [blame] | 195 | private boolean mSpeakerphoneOn; |
| 196 | |
Tyler Gunn | c4abd91 | 2014-07-08 14:22:10 -0700 | [diff] [blame] | 197 | private int mVideoState; |
| 198 | |
Ben Gilad | 6192561 | 2014-03-11 19:06:36 -0700 | [diff] [blame] | 199 | /** |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 200 | * Disconnect cause for the call. Only valid if the state of the call is DISCONNECTED. |
| 201 | * See {@link android.telephony.DisconnectCause}. |
| 202 | */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 203 | private int mDisconnectCause = DisconnectCause.NOT_VALID; |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 204 | |
| 205 | /** |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 206 | * Additional disconnect information provided by the connection service. |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 207 | */ |
| 208 | private String mDisconnectMessage; |
| 209 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 210 | /** Info used by the connection services. */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 211 | private Bundle mExtras = Bundle.EMPTY; |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 212 | |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 213 | /** Set of listeners on this call. */ |
| 214 | private Set<Listener> mListeners = Sets.newHashSet(); |
| 215 | |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 216 | private OutgoingCallProcessor mOutgoingCallProcessor; |
| 217 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 218 | /** Caller information retrieved from the latest contact query. */ |
| 219 | private CallerInfo mCallerInfo; |
| 220 | |
| 221 | /** The latest token used with a contact info query. */ |
| 222 | private int mQueryToken = 0; |
| 223 | |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 224 | /** Whether this call is requesting that Telecomm play the ringback tone on its behalf. */ |
| 225 | private boolean mRequestingRingback = false; |
| 226 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 227 | /** Whether direct-to-voicemail query is pending. */ |
| 228 | private boolean mDirectToVoicemailQueryPending; |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 229 | |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 230 | private int mCallCapabilities; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 231 | |
| 232 | private boolean mIsConference = false; |
| 233 | |
| 234 | private Call mParentCall = null; |
| 235 | |
| 236 | private List<Call> mChildCalls = new LinkedList<>(); |
| 237 | |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 238 | /** Set of text message responses allowed for this call, if applicable. */ |
| 239 | private List<String> mCannedSmsResponses = Collections.EMPTY_LIST; |
| 240 | |
| 241 | /** Whether an attempt has been made to load the text message responses. */ |
| 242 | private boolean mCannedSmsResponsesLoadingStarted = false; |
| 243 | |
Nancy Chen | a65d41f | 2014-06-24 12:06:03 -0700 | [diff] [blame] | 244 | private ICallVideoProvider mCallVideoProvider; |
| 245 | |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 246 | private boolean mAudioModeIsVoip; |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 247 | private StatusHints mStatusHints; |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 248 | |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 249 | /** |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 250 | * Persists the specified parameters and initializes the new instance. |
| 251 | * |
| 252 | * @param handle The handle to dial. |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 253 | * @param gatewayInfo Gateway information to use for the call. |
Ihab Awad | 98a5560 | 2014-06-30 21:27:28 -0700 | [diff] [blame] | 254 | * @param account Account information to use for the call. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 255 | * @param isIncoming True if this is an incoming call. |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 256 | */ |
Ihab Awad | 98a5560 | 2014-06-30 21:27:28 -0700 | [diff] [blame] | 257 | Call(Uri handle, GatewayInfo gatewayInfo, PhoneAccount account, |
Nancy Chen | 77d2d0e | 2014-06-24 12:06:03 -0700 | [diff] [blame] | 258 | boolean isIncoming, boolean isConference) { |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 259 | mState = isConference ? CallState.ACTIVE : CallState.NEW; |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 260 | setHandle(handle, CallPropertyPresentation.ALLOWED); |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 261 | mGatewayInfo = gatewayInfo; |
Sailesh Nepal | b0ba087 | 2014-07-08 22:09:50 -0700 | [diff] [blame] | 262 | mPhoneAccount = account; |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 263 | mIsIncoming = isIncoming; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 264 | mIsConference = isConference; |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 265 | maybeLoadCannedSmsResponses(); |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 268 | void addListener(Listener listener) { |
| 269 | mListeners.add(listener); |
| 270 | } |
| 271 | |
| 272 | void removeListener(Listener listener) { |
| 273 | mListeners.remove(listener); |
| 274 | } |
| 275 | |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 276 | /** {@inheritDoc} */ |
| 277 | @Override public String toString() { |
Sailesh Nepal | 4538f01 | 2014-04-15 11:40:33 -0700 | [diff] [blame] | 278 | String component = null; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 279 | if (mConnectionService != null && mConnectionService.getComponentName() != null) { |
| 280 | component = mConnectionService.getComponentName().flattenToShortString(); |
Sailesh Nepal | 4538f01 | 2014-04-15 11:40:33 -0700 | [diff] [blame] | 281 | } |
| 282 | 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] | 283 | } |
| 284 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 285 | CallState getState() { |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 286 | if (mIsConference) { |
| 287 | if (!mChildCalls.isEmpty()) { |
| 288 | // If we have child calls, just return the child call. |
| 289 | return mChildCalls.get(0).getState(); |
| 290 | } |
| 291 | return CallState.ACTIVE; |
| 292 | } else { |
| 293 | return mState; |
| 294 | } |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Sets the call state. Although there exists the notion of appropriate state transitions |
| 299 | * (see {@link CallState}), in practice those expectations break down when cellular systems |
| 300 | * misbehave and they do this very often. The result is that we do not enforce state transitions |
| 301 | * and instead keep the code resilient to unexpected state changes. |
| 302 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 303 | void setState(CallState newState) { |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 304 | Preconditions.checkState(newState != CallState.DISCONNECTED || |
| 305 | mDisconnectCause != DisconnectCause.NOT_VALID); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 306 | if (mState != newState) { |
| 307 | Log.v(this, "setState %s -> %s", mState, newState); |
| 308 | mState = newState; |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 309 | maybeLoadCannedSmsResponses(); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 310 | } |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 313 | void setRequestingRingback(boolean requestingRingback) { |
| 314 | mRequestingRingback = requestingRingback; |
| 315 | for (Listener l : mListeners) { |
| 316 | l.onRequestingRingback(this, mRequestingRingback); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | boolean isRequestingRingback() { |
| 321 | return mRequestingRingback; |
| 322 | } |
| 323 | |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 324 | Uri getHandle() { |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 325 | return mHandle; |
| 326 | } |
| 327 | |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 328 | int getHandlePresentation() { |
| 329 | return mHandlePresentation; |
| 330 | } |
| 331 | |
| 332 | void setHandle(Uri handle, int presentation) { |
| 333 | if (!Objects.equals(handle, mHandle) || presentation != mHandlePresentation) { |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 334 | mHandle = handle; |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 335 | mHandlePresentation = presentation; |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 336 | mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber( |
Yorke Lee | 6625545 | 2014-06-05 08:09:24 -0700 | [diff] [blame] | 337 | TelecommApp.getInstance(), mHandle.getSchemeSpecificPart()); |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 338 | startCallerInfoLookup(); |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 339 | for (Listener l : mListeners) { |
| 340 | l.onHandleChanged(this); |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | String getCallerDisplayName() { |
| 346 | return mCallerDisplayName; |
| 347 | } |
| 348 | |
| 349 | int getCallerDisplayNamePresentation() { |
| 350 | return mCallerDisplayNamePresentation; |
| 351 | } |
| 352 | |
| 353 | void setCallerDisplayName(String callerDisplayName, int presentation) { |
| 354 | if (!TextUtils.equals(callerDisplayName, mCallerDisplayName) || |
| 355 | presentation != mCallerDisplayNamePresentation) { |
| 356 | mCallerDisplayName = callerDisplayName; |
| 357 | mCallerDisplayNamePresentation = presentation; |
| 358 | for (Listener l : mListeners) { |
| 359 | l.onCallerDisplayNameChanged(this); |
| 360 | } |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 361 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 364 | String getName() { |
| 365 | return mCallerInfo == null ? null : mCallerInfo.name; |
| 366 | } |
| 367 | |
| 368 | Bitmap getPhotoIcon() { |
| 369 | return mCallerInfo == null ? null : mCallerInfo.cachedPhotoIcon; |
| 370 | } |
| 371 | |
| 372 | Drawable getPhoto() { |
| 373 | return mCallerInfo == null ? null : mCallerInfo.cachedPhoto; |
| 374 | } |
| 375 | |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 376 | /** |
| 377 | * @param disconnectCause The reason for the disconnection, any of |
| 378 | * {@link android.telephony.DisconnectCause}. |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame^] | 379 | * @param disconnectMessage Optional message about the disconnect. |
Santos Cordon | 79ff2bc | 2014-03-27 15:31:27 -0700 | [diff] [blame] | 380 | */ |
| 381 | void setDisconnectCause(int disconnectCause, String disconnectMessage) { |
| 382 | // TODO: Consider combining this method with a setDisconnected() method that is totally |
| 383 | // separate from setState. |
| 384 | mDisconnectCause = disconnectCause; |
| 385 | mDisconnectMessage = disconnectMessage; |
| 386 | } |
| 387 | |
| 388 | int getDisconnectCause() { |
| 389 | return mDisconnectCause; |
| 390 | } |
| 391 | |
| 392 | String getDisconnectMessage() { |
| 393 | return mDisconnectMessage; |
| 394 | } |
| 395 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 396 | boolean isEmergencyCall() { |
| 397 | return mIsEmergencyCall; |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 400 | /** |
| 401 | * @return The original handle this call is associated with. In-call services should use this |
| 402 | * handle when indicating in their UI the handle that is being called. |
| 403 | */ |
| 404 | public Uri getOriginalHandle() { |
| 405 | if (mGatewayInfo != null && !mGatewayInfo.isEmpty()) { |
| 406 | return mGatewayInfo.getOriginalHandle(); |
| 407 | } |
| 408 | return getHandle(); |
| 409 | } |
| 410 | |
| 411 | GatewayInfo getGatewayInfo() { |
| 412 | return mGatewayInfo; |
| 413 | } |
| 414 | |
Sailesh Nepal | b0ba087 | 2014-07-08 22:09:50 -0700 | [diff] [blame] | 415 | PhoneAccount getPhoneAccount() { |
| 416 | return mPhoneAccount; |
Nancy Chen | 77d2d0e | 2014-06-24 12:06:03 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 419 | boolean isIncoming() { |
| 420 | return mIsIncoming; |
| 421 | } |
| 422 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 423 | /** |
| 424 | * @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] | 425 | * period since this call was added to the set pending outgoing calls, see |
| 426 | * mCreationTimeMillis. |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 427 | */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 428 | long getAgeMillis() { |
| 429 | return System.currentTimeMillis() - mCreationTimeMillis; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 430 | } |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 431 | |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 432 | /** |
| 433 | * @return The time when this call object was created and added to the set of pending outgoing |
| 434 | * calls. |
| 435 | */ |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 436 | long getCreationTimeMillis() { |
| 437 | return mCreationTimeMillis; |
| 438 | } |
| 439 | |
| 440 | long getConnectTimeMillis() { |
| 441 | return mConnectTimeMillis; |
| 442 | } |
| 443 | |
| 444 | void setConnectTimeMillis(long connectTimeMillis) { |
| 445 | mConnectTimeMillis = connectTimeMillis; |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 448 | int getCallCapabilities() { |
| 449 | return mCallCapabilities; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 452 | void setCallCapabilities(int callCapabilities) { |
| 453 | if (mCallCapabilities != callCapabilities) { |
| 454 | mCallCapabilities = callCapabilities; |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 455 | for (Listener l : mListeners) { |
Sailesh Nepal | e20bc97 | 2014-07-09 21:22:36 -0700 | [diff] [blame] | 456 | l.onCallCapabilitiesChanged(this); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | Call getParentCall() { |
| 462 | return mParentCall; |
| 463 | } |
| 464 | |
| 465 | List<Call> getChildCalls() { |
| 466 | return mChildCalls; |
| 467 | } |
| 468 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 469 | ConnectionServiceWrapper getConnectionService() { |
| 470 | return mConnectionService; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 473 | void setConnectionService(ConnectionServiceWrapper service) { |
| 474 | Preconditions.checkNotNull(service); |
| 475 | |
| 476 | clearConnectionService(); |
| 477 | |
| 478 | service.incrementAssociatedCallCount(); |
| 479 | mConnectionService = service; |
| 480 | mConnectionService.addCall(this); |
Sailesh Nepal | 0e5410a | 2014-04-04 01:20:58 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | /** |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 484 | * Clears the associated connection service. |
Sailesh Nepal | 0e5410a | 2014-04-04 01:20:58 -0700 | [diff] [blame] | 485 | */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 486 | void clearConnectionService() { |
| 487 | if (mConnectionService != null) { |
| 488 | ConnectionServiceWrapper serviceTemp = mConnectionService; |
| 489 | mConnectionService = null; |
| 490 | serviceTemp.removeCall(this); |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 491 | |
| 492 | // Decrementing the count can cause the service to unbind, which itself can trigger the |
| 493 | // service-death code. Since the service death code tries to clean up any associated |
| 494 | // calls, we need to make sure to remove that information (e.g., removeCall()) before |
| 495 | // we decrement. Technically, invoking removeCall() prior to decrementing is all that is |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 496 | // necessary, but cleaning up mConnectionService prior to triggering an unbind is good |
| 497 | // to do. |
| 498 | decrementAssociatedCallCount(serviceTemp); |
Yorke Lee | adee12d | 2014-03-13 12:08:30 -0700 | [diff] [blame] | 499 | } |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 502 | /** |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 503 | * Starts the incoming call flow through the switchboard. When switchboard completes, it will |
| 504 | * invoke handle[Un]SuccessfulIncomingCall. |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 505 | */ |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame^] | 506 | void startIncoming() { |
| 507 | Switchboard.getInstance().retrieveIncomingCall(this); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 510 | /** |
| 511 | * Takes a verified incoming call and uses the handle to lookup direct-to-voicemail property |
| 512 | * from the contacts provider. The call is not yet exposed to the user at this point and |
| 513 | * the result of the query will determine if the call is rejected or passed through to the |
| 514 | * in-call UI. |
| 515 | */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 516 | void handleVerifiedIncoming(ConnectionRequest request) { |
Sailesh Nepal | b0ba087 | 2014-07-08 22:09:50 -0700 | [diff] [blame] | 517 | mPhoneAccount = request.getAccount(); |
| 518 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 519 | // We do not handle incoming calls immediately when they are verified by the connection |
| 520 | // service. We allow the caller-info-query code to execute first so that we can read the |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 521 | // direct-to-voicemail property before deciding if we want to show the incoming call to the |
| 522 | // user or if we want to reject the call. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 523 | mDirectToVoicemailQueryPending = true; |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 524 | |
| 525 | // Setting the handle triggers the caller info lookup code. |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 526 | setHandle(request.getHandle(), CallPropertyPresentation.ALLOWED); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 527 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 528 | // Timeout the direct-to-voicemail lookup execution so that we dont wait too long before |
| 529 | // showing the user the incoming call screen. |
| 530 | mHandler.postDelayed(new Runnable() { |
| 531 | @Override |
| 532 | public void run() { |
| 533 | processDirectToVoicemail(); |
| 534 | } |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 535 | }, Timeouts.getDirectToVoicemailMillis()); |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 536 | } |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 537 | |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 538 | void processDirectToVoicemail() { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 539 | if (mDirectToVoicemailQueryPending) { |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 540 | if (mCallerInfo != null && mCallerInfo.shouldSendToVoicemail) { |
| 541 | Log.i(this, "Directing call to voicemail: %s.", this); |
| 542 | // TODO(santoscordon): Once we move State handling from CallsManager to Call, we |
| 543 | // will not need to set RINGING state prior to calling reject. |
| 544 | setState(CallState.RINGING); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 545 | reject(false, null); |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 546 | } else { |
| 547 | // TODO(santoscordon): Make this class (not CallsManager) responsible for changing |
| 548 | // the call state to RINGING. |
| 549 | |
| 550 | // TODO(santoscordon): Replace this with state transition to RINGING. |
| 551 | for (Listener l : mListeners) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 552 | l.onSuccessfulIncomingCall(this); |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 556 | mDirectToVoicemailQueryPending = false; |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
| 560 | void handleFailedIncoming() { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 561 | clearConnectionService(); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 562 | |
| 563 | // TODO: Needs more specific disconnect error for this case. |
| 564 | setDisconnectCause(DisconnectCause.ERROR_UNSPECIFIED, null); |
| 565 | setState(CallState.DISCONNECTED); |
| 566 | |
| 567 | // TODO(santoscordon): Replace this with state transitions related to "connecting". |
| 568 | for (Listener l : mListeners) { |
| 569 | l.onFailedIncomingCall(this); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | /** |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 574 | * Starts the outgoing call sequence. Upon completion, there should exist an active connection |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 575 | * through a connection service (or the call will have failed). |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 576 | */ |
| 577 | void startOutgoing() { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 578 | Preconditions.checkState(mOutgoingCallProcessor == null); |
| 579 | |
| 580 | mOutgoingCallProcessor = new OutgoingCallProcessor( |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame^] | 581 | this, Switchboard.getInstance().getConnectionServiceRepository(), this); |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 582 | mOutgoingCallProcessor.process(); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 585 | @Override |
| 586 | public void onOutgoingCallSuccess() { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 587 | // TODO(santoscordon): Replace this with state transitions related to "connecting". |
| 588 | for (Listener l : mListeners) { |
| 589 | l.onSuccessfulOutgoingCall(this); |
| 590 | } |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 591 | mOutgoingCallProcessor = null; |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 594 | @Override |
| 595 | public void onOutgoingCallFailure(int code, String msg) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 596 | // TODO(santoscordon): Replace this with state transitions related to "connecting". |
| 597 | for (Listener l : mListeners) { |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 598 | l.onFailedOutgoingCall(this, code, msg); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 599 | } |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 600 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 601 | clearConnectionService(); |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 602 | mOutgoingCallProcessor = null; |
| 603 | } |
| 604 | |
| 605 | @Override |
| 606 | public void onOutgoingCallCancel() { |
| 607 | // TODO(santoscordon): Replace this with state transitions related to "connecting". |
| 608 | for (Listener l : mListeners) { |
| 609 | l.onCancelledOutgoingCall(this); |
| 610 | } |
| 611 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 612 | clearConnectionService(); |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 613 | mOutgoingCallProcessor = null; |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /** |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 617 | * Plays the specified DTMF tone. |
| 618 | */ |
| 619 | void playDtmfTone(char digit) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 620 | if (mConnectionService == null) { |
| 621 | Log.w(this, "playDtmfTone() request on a call without a connection service."); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 622 | } else { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 623 | Log.i(this, "Send playDtmfTone to connection service for call %s", this); |
| 624 | mConnectionService.playDtmfTone(this, digit); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Stops playing any currently playing DTMF tone. |
| 630 | */ |
| 631 | void stopDtmfTone() { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 632 | if (mConnectionService == null) { |
| 633 | Log.w(this, "stopDtmfTone() request on a call without a connectino service."); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 634 | } else { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 635 | Log.i(this, "Send stopDtmfTone to connection service for call %s", this); |
| 636 | mConnectionService.stopDtmfTone(this); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
| 640 | /** |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 641 | * Attempts to disconnect the call through the connection service. |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 642 | */ |
| 643 | void disconnect() { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 644 | if (mState == CallState.NEW) { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 645 | Log.v(this, "Aborting call %s", this); |
| 646 | abort(); |
Santos Cordon | 74d420b | 2014-05-07 14:38:47 -0700 | [diff] [blame] | 647 | } else if (mState != CallState.ABORTED && mState != CallState.DISCONNECTED) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 648 | Preconditions.checkNotNull(mConnectionService); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 649 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 650 | Log.i(this, "Send disconnect to connection service for call: %s", this); |
| 651 | // The call isn't officially disconnected until the connection service confirms that the |
| 652 | // call was actually disconnected. Only then is the association between call and |
| 653 | // connection service severed, see {@link CallsManager#markCallAsDisconnected}. |
| 654 | mConnectionService.disconnect(this); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 658 | void abort() { |
| 659 | if (mOutgoingCallProcessor != null) { |
| 660 | mOutgoingCallProcessor.abort(); |
| 661 | } |
| 662 | } |
| 663 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 664 | /** |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 665 | * Answers the call if it is ringing. |
| 666 | */ |
| 667 | void answer() { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 668 | Preconditions.checkNotNull(mConnectionService); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 669 | |
| 670 | // Check to verify that the call is still in the ringing state. A call can change states |
| 671 | // between the time the user hits 'answer' and Telecomm receives the command. |
| 672 | if (isRinging("answer")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 673 | // At this point, we are asking the connection service to answer but we don't assume |
| 674 | // that it will work. Instead, we wait until confirmation from the connectino service |
| 675 | // that the call is in a non-RINGING state before changing the UI. See |
| 676 | // {@link ConnectionServiceAdapter#setActive} and other set* methods. |
| 677 | mConnectionService.answer(this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
| 681 | /** |
| 682 | * Rejects the call if it is ringing. |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 683 | * |
| 684 | * @param rejectWithMessage Whether to send a text message as part of the call rejection. |
| 685 | * @param textMessage An optional text message to send as part of the rejection. |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 686 | */ |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 687 | void reject(boolean rejectWithMessage, String textMessage) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 688 | Preconditions.checkNotNull(mConnectionService); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 689 | |
| 690 | // Check to verify that the call is still in the ringing state. A call can change states |
| 691 | // between the time the user hits 'reject' and Telecomm receives the command. |
| 692 | if (isRinging("reject")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 693 | mConnectionService.reject(this); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
| 697 | /** |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 698 | * Puts the call on hold if it is currently active. |
| 699 | */ |
| 700 | void hold() { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 701 | Preconditions.checkNotNull(mConnectionService); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 702 | |
| 703 | if (mState == CallState.ACTIVE) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 704 | mConnectionService.hold(this); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Releases the call from hold if it is currently active. |
| 710 | */ |
| 711 | void unhold() { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 712 | Preconditions.checkNotNull(mConnectionService); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 713 | |
| 714 | if (mState == CallState.ON_HOLD) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 715 | mConnectionService.unhold(this); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 719 | /** Checks if this is a live call or not. */ |
| 720 | boolean isAlive() { |
| 721 | switch (mState) { |
| 722 | case NEW: |
| 723 | case RINGING: |
| 724 | case DISCONNECTED: |
| 725 | case ABORTED: |
| 726 | return false; |
| 727 | default: |
| 728 | return true; |
| 729 | } |
| 730 | } |
| 731 | |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 732 | boolean isActive() { |
Ihab Awad | 84bfe47 | 2014-07-13 17:11:57 -0700 | [diff] [blame] | 733 | return mState == CallState.ACTIVE; |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 736 | Bundle getExtras() { |
| 737 | return mExtras; |
| 738 | } |
| 739 | |
| 740 | void setExtras(Bundle extras) { |
| 741 | mExtras = extras; |
| 742 | } |
| 743 | |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 744 | Uri getRingtone() { |
| 745 | return mCallerInfo == null ? null : mCallerInfo.contactRingtoneUri; |
| 746 | } |
| 747 | |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 748 | void onPostDialWait(String remaining) { |
| 749 | for (Listener l : mListeners) { |
| 750 | l.onPostDialWait(this, remaining); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | void postDialContinue(boolean proceed) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 755 | mConnectionService.onPostDialContinue(this, proceed); |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Sailesh Nepal | 77da19e | 2014-07-02 21:31:16 -0700 | [diff] [blame] | 758 | void phoneAccountClicked() { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 759 | mConnectionService.onPhoneAccountClicked(this); |
Sailesh Nepal | 77da19e | 2014-07-02 21:31:16 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 762 | void conferenceInto(Call conferenceCall) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 763 | if (mConnectionService == null) { |
| 764 | Log.w(this, "conference requested on a call without a connection service."); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 765 | } else { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 766 | mConnectionService.conference(conferenceCall, this); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | |
| 770 | void expireConference() { |
| 771 | // The conference call expired before we got a confirmation of the conference from the |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 772 | // connection service...so start shutting down. |
| 773 | clearConnectionService(); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 774 | for (Listener l : mListeners) { |
| 775 | l.onExpiredConferenceCall(this); |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | void confirmConference() { |
| 780 | Log.v(this, "confirming Conf call %s", mListeners); |
| 781 | for (Listener l : mListeners) { |
| 782 | l.onConfirmedConferenceCall(this); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | void splitFromConference() { |
| 787 | // TODO(santoscordon): todo |
| 788 | } |
| 789 | |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 790 | void swapWithBackgroundCall() { |
| 791 | mConnectionService.swapWithBackgroundCall(this); |
| 792 | } |
| 793 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 794 | void setParentCall(Call parentCall) { |
| 795 | if (parentCall == this) { |
| 796 | Log.e(this, new Exception(), "setting the parent to self"); |
| 797 | return; |
| 798 | } |
| 799 | Preconditions.checkState(parentCall == null || mParentCall == null); |
| 800 | |
| 801 | Call oldParent = mParentCall; |
| 802 | if (mParentCall != null) { |
| 803 | mParentCall.removeChildCall(this); |
| 804 | } |
| 805 | mParentCall = parentCall; |
| 806 | if (mParentCall != null) { |
| 807 | mParentCall.addChildCall(this); |
| 808 | } |
| 809 | |
| 810 | for (Listener l : mListeners) { |
| 811 | l.onParentChanged(this); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | private void addChildCall(Call call) { |
| 816 | if (!mChildCalls.contains(call)) { |
| 817 | mChildCalls.add(call); |
| 818 | |
| 819 | for (Listener l : mListeners) { |
| 820 | l.onChildrenChanged(this); |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | private void removeChildCall(Call call) { |
| 826 | if (mChildCalls.remove(call)) { |
| 827 | for (Listener l : mListeners) { |
| 828 | l.onChildrenChanged(this); |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 833 | /** |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 834 | * Return whether the user can respond to this {@code Call} via an SMS message. |
| 835 | * |
| 836 | * @return true if the "Respond via SMS" feature should be enabled |
| 837 | * for this incoming call. |
| 838 | * |
| 839 | * The general rule is that we *do* allow "Respond via SMS" except for |
| 840 | * the few (relatively rare) cases where we know for sure it won't |
| 841 | * work, namely: |
| 842 | * - a bogus or blank incoming number |
| 843 | * - a call from a SIP address |
| 844 | * - a "call presentation" that doesn't allow the number to be revealed |
| 845 | * |
| 846 | * In all other cases, we allow the user to respond via SMS. |
| 847 | * |
| 848 | * Note that this behavior isn't perfect; for example we have no way |
| 849 | * to detect whether the incoming call is from a landline (with most |
| 850 | * networks at least), so we still enable this feature even though |
| 851 | * SMSes to that number will silently fail. |
| 852 | */ |
| 853 | boolean isRespondViaSmsCapable() { |
| 854 | if (mState != CallState.RINGING) { |
| 855 | return false; |
| 856 | } |
| 857 | |
| 858 | if (getHandle() == null) { |
| 859 | // No incoming number known or call presentation is "PRESENTATION_RESTRICTED", in |
| 860 | // other words, the user should not be able to see the incoming phone number. |
| 861 | return false; |
| 862 | } |
| 863 | |
| 864 | if (PhoneNumberUtils.isUriNumber(getHandle().toString())) { |
| 865 | // The incoming number is actually a URI (i.e. a SIP address), |
| 866 | // not a regular PSTN phone number, and we can't send SMSes to |
| 867 | // SIP addresses. |
| 868 | // (TODO: That might still be possible eventually, though. Is |
| 869 | // there some SIP-specific equivalent to sending a text message?) |
| 870 | return false; |
| 871 | } |
| 872 | |
| 873 | // Is there a valid SMS application on the phone? |
| 874 | if (SmsApplication.getDefaultRespondViaMessageApplication(TelecommApp.getInstance(), |
| 875 | true /*updateIfNeeded*/) == null) { |
| 876 | return false; |
| 877 | } |
| 878 | |
| 879 | // TODO: with some carriers (in certain countries) you *can* actually |
| 880 | // tell whether a given number is a mobile phone or not. So in that |
| 881 | // case we could potentially return false here if the incoming call is |
| 882 | // from a land line. |
| 883 | |
| 884 | // If none of the above special cases apply, it's OK to enable the |
| 885 | // "Respond via SMS" feature. |
| 886 | return true; |
| 887 | } |
| 888 | |
| 889 | List<String> getCannedSmsResponses() { |
| 890 | return mCannedSmsResponses; |
| 891 | } |
| 892 | |
| 893 | /** |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 894 | * @return True if the call is ringing, else logs the action name. |
| 895 | */ |
| 896 | private boolean isRinging(String actionName) { |
| 897 | if (mState == CallState.RINGING) { |
| 898 | return true; |
| 899 | } |
| 900 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 901 | 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] | 902 | return false; |
| 903 | } |
| 904 | |
Ben Gilad | 8e55d1d | 2014-02-26 16:25:56 -0800 | [diff] [blame] | 905 | @SuppressWarnings("rawtypes") |
| 906 | private void decrementAssociatedCallCount(ServiceBinder binder) { |
| 907 | if (binder != null) { |
| 908 | binder.decrementAssociatedCallCount(); |
| 909 | } |
| 910 | } |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 911 | |
| 912 | /** |
| 913 | * Looks up contact information based on the current handle. |
| 914 | */ |
| 915 | private void startCallerInfoLookup() { |
| 916 | String number = mHandle == null ? null : mHandle.getSchemeSpecificPart(); |
| 917 | |
| 918 | mQueryToken++; // Updated so that previous queries can no longer set the information. |
| 919 | mCallerInfo = null; |
| 920 | if (!TextUtils.isEmpty(number)) { |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 921 | Log.v(this, "Looking up information for: %s.", Log.piiHandle(number)); |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 922 | CallerInfoAsyncQuery.startQuery( |
| 923 | mQueryToken, |
| 924 | TelecommApp.getInstance(), |
| 925 | number, |
| 926 | sCallerInfoQueryListener, |
| 927 | this); |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | /** |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 932 | * Saves the specified caller info if the specified token matches that of the last query |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 933 | * that was made. |
| 934 | * |
| 935 | * @param callerInfo The new caller information to set. |
| 936 | * @param token The token used with this query. |
| 937 | */ |
| 938 | private void setCallerInfo(CallerInfo callerInfo, int token) { |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 939 | Preconditions.checkNotNull(callerInfo); |
| 940 | |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 941 | if (mQueryToken == token) { |
| 942 | mCallerInfo = callerInfo; |
Santos Cordon | 5ba7f27 | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 943 | Log.i(this, "CallerInfo received for %s: %s", Log.piiHandle(mHandle), callerInfo); |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 944 | |
Makoto Onuki | a1662d0 | 2014-07-10 15:31:59 -0700 | [diff] [blame] | 945 | if (mCallerInfo.contactDisplayPhotoUri != null) { |
| 946 | Log.d(this, "Searching person uri %s for call %s", |
| 947 | mCallerInfo.contactDisplayPhotoUri, this); |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 948 | ContactsAsyncHelper.startObtainPhotoAsync( |
| 949 | token, |
| 950 | TelecommApp.getInstance(), |
Makoto Onuki | a1662d0 | 2014-07-10 15:31:59 -0700 | [diff] [blame] | 951 | mCallerInfo.contactDisplayPhotoUri, |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 952 | sPhotoLoadListener, |
| 953 | this); |
Makoto Onuki | a1662d0 | 2014-07-10 15:31:59 -0700 | [diff] [blame] | 954 | // Do not call onCallerInfoChanged yet in this case. We call it in setPhoto(). |
Santos Cordon | 64c7e96 | 2014-07-02 15:15:27 -0700 | [diff] [blame] | 955 | } else { |
| 956 | for (Listener l : mListeners) { |
| 957 | l.onCallerInfoChanged(this); |
| 958 | } |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 959 | } |
Santos Cordon | 2174fb5 | 2014-05-29 08:22:56 -0700 | [diff] [blame] | 960 | |
| 961 | processDirectToVoicemail(); |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | |
Yorke Lee | 6f3f7af | 2014-07-11 10:59:46 -0700 | [diff] [blame] | 965 | CallerInfo getCallerInfo() { |
| 966 | return mCallerInfo; |
| 967 | } |
| 968 | |
Santos Cordon | 99c8a6f | 2014-05-28 18:28:47 -0700 | [diff] [blame] | 969 | /** |
| 970 | * Saves the specified photo information if the specified token matches that of the last query. |
| 971 | * |
| 972 | * @param photo The photo as a drawable. |
| 973 | * @param photoIcon The photo as a small icon. |
| 974 | * @param token The token used with this query. |
| 975 | */ |
| 976 | private void setPhoto(Drawable photo, Bitmap photoIcon, int token) { |
| 977 | if (mQueryToken == token) { |
| 978 | mCallerInfo.cachedPhoto = photo; |
| 979 | mCallerInfo.cachedPhotoIcon = photoIcon; |
Santos Cordon | 64c7e96 | 2014-07-02 15:15:27 -0700 | [diff] [blame] | 980 | |
| 981 | for (Listener l : mListeners) { |
| 982 | l.onCallerInfoChanged(this); |
| 983 | } |
Santos Cordon | fd71f4a | 2014-05-28 13:59:49 -0700 | [diff] [blame] | 984 | } |
| 985 | } |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 986 | |
| 987 | private void maybeLoadCannedSmsResponses() { |
| 988 | if (mIsIncoming && isRespondViaSmsCapable() && !mCannedSmsResponsesLoadingStarted) { |
| 989 | Log.d(this, "maybeLoadCannedSmsResponses: starting task to load messages"); |
| 990 | mCannedSmsResponsesLoadingStarted = true; |
| 991 | RespondViaSmsManager.getInstance().loadCannedTextMessages( |
| 992 | new Response<Void, List<String>>() { |
| 993 | @Override |
| 994 | public void onResult(Void request, List<String>... result) { |
| 995 | if (result.length > 0) { |
| 996 | Log.d(this, "maybeLoadCannedSmsResponses: got %s", result[0]); |
| 997 | mCannedSmsResponses = result[0]; |
| 998 | for (Listener l : mListeners) { |
| 999 | l.onCannedSmsResponsesLoaded(Call.this); |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | @Override |
| 1005 | public void onError(Void request, int code, String msg) { |
| 1006 | Log.w(Call.this, "Error obtaining canned SMS responses: %d %s", code, |
| 1007 | msg); |
| 1008 | } |
| 1009 | } |
| 1010 | ); |
| 1011 | } else { |
| 1012 | Log.d(this, "maybeLoadCannedSmsResponses: doing nothing"); |
| 1013 | } |
| 1014 | } |
Sai Cheemalapati | b7157e9 | 2014-06-11 17:51:55 -0700 | [diff] [blame] | 1015 | |
| 1016 | /** |
| 1017 | * Sets speakerphone option on when call begins. |
| 1018 | */ |
| 1019 | public void setStartWithSpeakerphoneOn(boolean startWithSpeakerphone) { |
| 1020 | mSpeakerphoneOn = startWithSpeakerphone; |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * Returns speakerphone option. |
| 1025 | * |
| 1026 | * @return Whether or not speakerphone should be set automatically when call begins. |
| 1027 | */ |
| 1028 | public boolean getStartWithSpeakerphoneOn() { |
| 1029 | return mSpeakerphoneOn; |
| 1030 | } |
Andrew Lee | e9a7765 | 2014-06-26 13:07:57 -0700 | [diff] [blame] | 1031 | |
| 1032 | /** |
| 1033 | * Sets a call video provider for the call. |
| 1034 | */ |
Nancy Chen | a65d41f | 2014-06-24 12:06:03 -0700 | [diff] [blame] | 1035 | public void setCallVideoProvider(ICallVideoProvider callVideoProvider) { |
| 1036 | mCallVideoProvider = callVideoProvider; |
| 1037 | for (Listener l : mListeners) { |
| 1038 | l.onCallVideoProviderChanged(Call.this); |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * @return Return the call video Provider binder. |
| 1044 | */ |
| 1045 | public ICallVideoProvider getCallVideoProvider() { |
| 1046 | return mCallVideoProvider; |
Andrew Lee | e9a7765 | 2014-06-26 13:07:57 -0700 | [diff] [blame] | 1047 | } |
Tyler Gunn | e19cc00 | 2014-07-01 11:32:53 -0700 | [diff] [blame] | 1048 | |
| 1049 | /** |
Tyler Gunn | c4abd91 | 2014-07-08 14:22:10 -0700 | [diff] [blame] | 1050 | * The current video state for the call. |
| 1051 | * Valid values: {@link android.telecomm.VideoCallProfile#VIDEO_STATE_AUDIO_ONLY}, |
| 1052 | * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_BIDIRECTIONAL}, |
| 1053 | * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_TX_ENABLED}, |
| 1054 | * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_RX_ENABLED}. |
| 1055 | * |
| 1056 | * @return True if video is enabled. |
| 1057 | */ |
| 1058 | public int getVideoState() { |
| 1059 | return mVideoState; |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| 1063 | * At the start of the call, determines the desired video state for the call. |
| 1064 | * Valid values: {@link android.telecomm.VideoCallProfile#VIDEO_STATE_AUDIO_ONLY}, |
| 1065 | * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_BIDIRECTIONAL}, |
| 1066 | * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_TX_ENABLED}, |
| 1067 | * {@link android.telecomm.VideoCallProfile#VIDEO_STATE_RX_ENABLED}. |
| 1068 | * |
| 1069 | * @param videoState The desired video state for the call. |
| 1070 | */ |
| 1071 | public void setVideoState(int videoState) { |
| 1072 | mVideoState = videoState; |
| 1073 | } |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 1074 | |
| 1075 | public boolean getAudioModeIsVoip() { |
| 1076 | return mAudioModeIsVoip; |
| 1077 | } |
| 1078 | |
| 1079 | public void setAudioModeIsVoip(boolean audioModeIsVoip) { |
| 1080 | mAudioModeIsVoip = audioModeIsVoip; |
| 1081 | for (Listener l : mListeners) { |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 1082 | l.onAudioModeIsVoipChanged(this); |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | public StatusHints getStatusHints() { |
| 1087 | return mStatusHints; |
| 1088 | } |
| 1089 | |
| 1090 | public void setStatusHints(StatusHints statusHints) { |
| 1091 | mStatusHints = statusHints; |
| 1092 | for (Listener l : mListeners) { |
| 1093 | l.onStatusHintsChanged(this); |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 1094 | } |
| 1095 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 1096 | } |