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