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