blob: d3972d31fa39c549af9c2451dfc08ef0bff06234 [file] [log] [blame]
Santos Cordon52d8a152014-06-17 19:08:45 -07001/*
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
17package android.telecomm;
18
Ihab Awadb19a0bc2014-08-07 19:46:01 -070019import com.android.internal.telecomm.IConnectionService;
20
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -070021import android.app.PendingIntent;
Santos Cordon52d8a152014-06-17 19:08:45 -070022import android.net.Uri;
Santos Cordon52d8a152014-06-17 19:08:45 -070023import android.os.RemoteException;
24import android.telephony.DisconnectCause;
25
Santos Cordon7c7bc7f2014-07-28 18:15:48 -070026import java.util.ArrayList;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070027import java.util.Collections;
Santos Cordon52d8a152014-06-17 19:08:45 -070028import java.util.HashSet;
Ihab Awad5d0410f2014-07-30 10:07:40 -070029import java.util.List;
Santos Cordon52d8a152014-06-17 19:08:45 -070030import java.util.Set;
Sailesh Nepalf4669df2014-08-14 17:43:13 -070031import java.util.concurrent.ConcurrentHashMap;
Santos Cordon52d8a152014-06-17 19:08:45 -070032
33/**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070034 * A connection provided to a {@link ConnectionService} by another {@code ConnectionService}
35 * running in a different process.
36 *
37 * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
38 * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
Santos Cordon52d8a152014-06-17 19:08:45 -070039 */
40public final class RemoteConnection {
Ihab Awad5d0410f2014-07-30 10:07:40 -070041
Evan Charltonbf11f982014-07-20 22:06:28 -070042 public static abstract class Listener {
Ihab Awad5d0410f2014-07-30 10:07:40 -070043 /**
44 * Invoked when the state of this {@code RemoteConnection} has changed. See
45 * {@link #getState()}.
46 *
47 * @param connection The {@code RemoteConnection} invoking this method.
48 * @param state The new state of the {@code RemoteConnection}.
49 */
Evan Charltonbf11f982014-07-20 22:06:28 -070050 public void onStateChanged(RemoteConnection connection, int state) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070051
52 /**
53 * Invoked when the parent of this {@code RemoteConnection} has changed. See
54 * {@link #getParent()}.
55 *
56 * @param connection The {@code RemoteConnection} invoking this method.
57 * @param parent The new parent of the {@code RemoteConnection}.
58 */
59 public void onParentChanged(RemoteConnection connection, RemoteConnection parent) {}
60
61 /**
62 * Invoked when the children of this {@code RemoteConnection} have changed. See
63 * {@link #getChildren()}.
64 *
65 * @param connection The {@code RemoteConnection} invoking this method.
66 * @param children The new children of the {@code RemoteConnection}.
67 */
68 public void onChildrenChanged(
69 RemoteConnection connection, List<RemoteConnection> children) {}
70
71 /**
72 * Invoked when this {@code RemoteConnection} is disconnected.
73 *
74 * @param connection The {@code RemoteConnection} invoking this method.
75 * @param disconnectCauseCode The failure code ({@see DisconnectCause}) associated with this
76 * failed connection.
77 * @param disconnectCauseMessage The reason for the connection failure. This will not be
78 * displayed to the user.
79 */
80 public void onDisconnected(
81 RemoteConnection connection,
82 int disconnectCauseCode,
83 String disconnectCauseMessage) {}
84
85 /**
86 * Invoked when this {@code RemoteConnection} is requesting ringback. See
87 * {@link #isRequestingRingback()}.
88 *
89 * @param connection The {@code RemoteConnection} invoking this method.
90 * @param ringback Whether the {@code RemoteConnection} is requesting ringback.
91 */
Evan Charltonbf11f982014-07-20 22:06:28 -070092 public void onRequestingRingback(RemoteConnection connection, boolean ringback) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -070093
94 /**
95 * Indicates that the call capabilities of this {@code RemoteConnection} have changed.
96 * See {@link #getCallCapabilities()}.
97 *
98 * @param connection The {@code RemoteConnection} invoking this method.
99 * @param callCapabilities The new call capabilities of the {@code RemoteConnection}.
100 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700101 public void onCallCapabilitiesChanged(RemoteConnection connection, int callCapabilities) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700102
103 /**
104 * Invoked when the post-dial sequence in the outgoing {@code Connection} has reached a
105 * pause character. This causes the post-dial signals to stop pending user confirmation. An
106 * implementation should present this choice to the user and invoke
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700107 * {@link RemoteConnection#postDialContinue(boolean)} when the user makes the choice.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700108 *
109 * @param connection The {@code RemoteConnection} invoking this method.
110 * @param remainingPostDialSequence The post-dial characters that remain to be sent.
111 */
112 public void onPostDialWait(RemoteConnection connection, String remainingPostDialSequence) {}
113
114 /**
115 * Indicates that the VOIP audio status of this {@code RemoteConnection} has changed.
116 * See {@link #getAudioModeIsVoip()}.
117 *
118 * @param connection The {@code RemoteConnection} invoking this method.
119 * @param isVoip Whether the new audio state of the {@code RemoteConnection} is VOIP.
120 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700121 public void onAudioModeIsVoipChanged(RemoteConnection connection, boolean isVoip) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700122
123 /**
124 * Indicates that the status hints of this {@code RemoteConnection} have changed. See
125 * {@link #getStatusHints()} ()}.
126 *
127 * @param connection The {@code RemoteConnection} invoking this method.
128 * @param statusHints The new status hints of the {@code RemoteConnection}.
129 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700130 public void onStatusHintsChanged(RemoteConnection connection, StatusHints statusHints) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700131
132 /**
133 * Indicates that the handle (e.g., phone number) of this {@code RemoteConnection} has
134 * changed. See {@link #getHandle()} and {@link #getHandlePresentation()}.
135 *
136 * @param connection The {@code RemoteConnection} invoking this method.
137 * @param handle The new handle of the {@code RemoteConnection}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700138 * @param presentation The {@link PropertyPresentation} which controls how the
Ihab Awad5d0410f2014-07-30 10:07:40 -0700139 * handle is shown.
140 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700141 public void onHandleChanged(RemoteConnection connection, Uri handle, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700142
143 /**
144 * Indicates that the caller display name of this {@code RemoteConnection} has changed.
145 * See {@link #getCallerDisplayName()} and {@link #getCallerDisplayNamePresentation()}.
146 *
147 * @param connection The {@code RemoteConnection} invoking this method.
148 * @param callerDisplayName The new caller display name of the {@code RemoteConnection}.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700149 * @param presentation The {@link PropertyPresentation} which controls how the
Ihab Awad5d0410f2014-07-30 10:07:40 -0700150 * caller display name is shown.
151 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700152 public void onCallerDisplayNameChanged(
153 RemoteConnection connection, String callerDisplayName, int presentation) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700154
155 /**
156 * Indicates that the video state of this {@code RemoteConnection} has changed.
157 * See {@link #getVideoState()}.
158 *
159 * @param connection The {@code RemoteConnection} invoking this method.
160 * @param videoState The new video state of the {@code RemoteConnection}.
161 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700162 public void onVideoStateChanged(RemoteConnection connection, int videoState) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700163
164 /**
165 * Indicates that this {@code RemoteConnection} is requesting that the in-call UI
166 * launch the specified activity.
167 *
168 * @param connection The {@code RemoteConnection} invoking this method.
169 * @param intent A {@link PendingIntent} that the {@code RemoteConnection} wishes to
170 * have launched on its behalf.
171 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700172 public void onStartActivityFromInCall(RemoteConnection connection, PendingIntent intent) {}
Ihab Awad5d0410f2014-07-30 10:07:40 -0700173
174 /**
175 * Indicates that this {@code RemoteConnection} has been destroyed. No further requests
176 * should be made to the {@code RemoteConnection}, and references to it should be cleared.
177 *
178 * @param connection The {@code RemoteConnection} invoking this method.
179 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700180 public void onDestroyed(RemoteConnection connection) {}
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700181 public void onConferenceableConnectionsChanged(
182 RemoteConnection connection, List<RemoteConnection> conferenceableConnections) {}
Santos Cordon52d8a152014-06-17 19:08:45 -0700183 }
184
Evan Charltonbf11f982014-07-20 22:06:28 -0700185 private IConnectionService mConnectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700186 private final String mConnectionId;
Sailesh Nepalf4669df2014-08-14 17:43:13 -0700187 private final Set<Listener> mListeners = Collections.newSetFromMap(
188 new ConcurrentHashMap<Listener, Boolean>(2));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700189 private final Set<RemoteConnection> mConferenceableConnections = new HashSet<>();
Santos Cordon52d8a152014-06-17 19:08:45 -0700190
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700191 private int mState = Connection.STATE_NEW;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700192 private int mDisconnectCauseCode = DisconnectCause.NOT_VALID;
193 private String mDisconnectCauseMessage;
Santos Cordon52d8a152014-06-17 19:08:45 -0700194 private boolean mRequestingRingback;
195 private boolean mConnected;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700196 private int mCallCapabilities;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700197 private int mVideoState;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700198 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700199 private StatusHints mStatusHints;
Sailesh Nepal61203862014-07-11 14:50:13 -0700200 private Uri mHandle;
201 private int mHandlePresentation;
202 private String mCallerDisplayName;
203 private int mCallerDisplayNamePresentation;
Evan Charltonbf11f982014-07-20 22:06:28 -0700204 private int mFailureCode;
205 private String mFailureMessage;
Santos Cordon52d8a152014-06-17 19:08:45 -0700206
207 /**
208 * @hide
209 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700210 RemoteConnection(
211 String id,
212 IConnectionService connectionService,
213 ConnectionRequest request) {
214 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700215 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700216 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700217 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700218 }
219
220 /**
221 * Create a RemoteConnection which is used for failed connections. Note that using it for any
222 * "real" purpose will almost certainly fail. Callers should note the failure and act
223 * accordingly (moving on to another RemoteConnection, for example)
224 *
225 * @param failureCode
226 * @param failureMessage
227 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700228 RemoteConnection(int failureCode, String failureMessage) {
229 this("NULL", null, null);
Evan Charltonbf11f982014-07-20 22:06:28 -0700230 mConnected = false;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700231 mState = Connection.STATE_FAILED;
Evan Charltonbf11f982014-07-20 22:06:28 -0700232 mFailureCode = failureCode;
233 mFailureMessage = failureMessage;
Santos Cordon52d8a152014-06-17 19:08:45 -0700234 }
235
Ihab Awad5d0410f2014-07-30 10:07:40 -0700236 /**
237 * Adds a listener to this {@code RemoteConnection}.
238 *
239 * @param listener A {@code Listener}.
240 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700241 public void addListener(Listener listener) {
242 mListeners.add(listener);
243 }
244
Ihab Awad5d0410f2014-07-30 10:07:40 -0700245 /**
246 * Removes a listener from this {@code RemoteConnection}.
247 *
248 * @param listener A {@code Listener}.
249 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700250 public void removeListener(Listener listener) {
251 mListeners.remove(listener);
252 }
253
Ihab Awad5d0410f2014-07-30 10:07:40 -0700254 /**
255 * Obtains the parent of this {@code RemoteConnection} in a conference, if any.
256 *
257 * @return The parent {@code RemoteConnection}, or {@code null} if this {@code RemoteConnection}
258 * is not a child of any conference {@code RemoteConnection}s.
259 */
260 public RemoteConnection getParent() { return null; }
261
262 /**
263 * Obtains the children of this conference {@code RemoteConnection}, if any.
264 *
265 * @return The children of this {@code RemoteConnection} if this {@code RemoteConnection} is
266 * a conference, or an empty {@code List} otherwise.
267 */
268 public List<RemoteConnection> getChildren() { return null; }
269
270 /**
271 * Obtains the state of this {@code RemoteConnection}.
272 *
273 * @return A state value, chosen from the {@code STATE_*} constants.
274 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700275 public int getState() {
276 return mState;
277 }
278
Ihab Awad5d0410f2014-07-30 10:07:40 -0700279 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700280 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5d0410f2014-07-30 10:07:40 -0700281 * disconnect cause expressed as a code chosen from among those declared in
282 * {@link DisconnectCause}.
283 */
284 public int getDisconnectCauseCode() {
285 return mDisconnectCauseCode;
Santos Cordon52d8a152014-06-17 19:08:45 -0700286 }
287
Ihab Awad5d0410f2014-07-30 10:07:40 -0700288 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700289 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, an optional
Ihab Awad5d0410f2014-07-30 10:07:40 -0700290 * reason for disconnection expressed as a free text message.
291 */
292 public String getDisconnectCauseMessage() {
293 return mDisconnectCauseMessage;
Santos Cordon52d8a152014-06-17 19:08:45 -0700294 }
295
Ihab Awad5d0410f2014-07-30 10:07:40 -0700296 /**
297 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700298 * {@link PhoneCapabilities}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700299 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700300 public int getCallCapabilities() {
301 return mCallCapabilities;
302 }
303
Ihab Awad5d0410f2014-07-30 10:07:40 -0700304 /**
305 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
306 */
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700307 public boolean getAudioModeIsVoip() {
308 return mAudioModeIsVoip;
309 }
310
Ihab Awad5d0410f2014-07-30 10:07:40 -0700311 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700312 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5d0410f2014-07-30 10:07:40 -0700313 * or {@code null} if none have been set.
314 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700315 public StatusHints getStatusHints() {
316 return mStatusHints;
317 }
318
Ihab Awad5d0410f2014-07-30 10:07:40 -0700319 /**
320 * @return The handle (e.g., phone number) to which the {@code RemoteConnection} is currently
321 * connected.
322 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700323 public Uri getHandle() {
324 return mHandle;
325 }
326
Ihab Awad5d0410f2014-07-30 10:07:40 -0700327 /**
328 * @return The presentation requirements for the handle. See
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700329 * {@link PropertyPresentation} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700330 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700331 public int getHandlePresentation() {
332 return mHandlePresentation;
333 }
334
Ihab Awad5d0410f2014-07-30 10:07:40 -0700335 /**
336 * @return The display name for the caller.
337 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700338 public String getCallerDisplayName() {
339 return mCallerDisplayName;
340 }
341
Ihab Awad5d0410f2014-07-30 10:07:40 -0700342 /**
343 * @return The presentation requirements for the caller display name. See
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700344 * {@link PropertyPresentation} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700345 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700346 public int getCallerDisplayNamePresentation() {
347 return mCallerDisplayNamePresentation;
348 }
349
Ihab Awad5d0410f2014-07-30 10:07:40 -0700350 /**
351 * @return The video state of the {@code RemoteConnection}. See
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700352 * {@link VideoProfile.VideoState}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700353 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700354 public int getVideoState() {
355 return mVideoState;
356 }
357
Ihab Awad5d0410f2014-07-30 10:07:40 -0700358 /**
359 * @return The failure code ({@see DisconnectCause}) associated with this failed
360 * {@code RemoteConnection}.
361 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700362 public int getFailureCode() {
363 return mFailureCode;
364 }
365
Ihab Awad5d0410f2014-07-30 10:07:40 -0700366 /**
367 * @return The reason for the connection failure. This will not be displayed to the user.
368 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700369 public String getFailureMessage() {
370 return mFailureMessage;
371 }
372
Ihab Awad5d0410f2014-07-30 10:07:40 -0700373 /**
374 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
375 * ringback tone on its behalf.
376 */
377 public boolean isRequestingRingback() {
378 return false;
379 }
380
381 /**
382 * Instructs this {@code RemoteConnection} to abort.
383 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700384 public void abort() {
385 try {
386 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700387 mConnectionService.abort(mConnectionId);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700388 }
389 } catch (RemoteException ignored) {
390 }
391 }
392
Ihab Awad5d0410f2014-07-30 10:07:40 -0700393 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700394 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700395 * @param videoState The video state in which to answer the call.
396 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700397 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700398 try {
399 if (mConnected) {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700400 mConnectionService.answer(mConnectionId, videoState);
Santos Cordon52d8a152014-06-17 19:08:45 -0700401 }
402 } catch (RemoteException ignored) {
403 }
404 }
405
Ihab Awad5d0410f2014-07-30 10:07:40 -0700406 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700407 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700408 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700409 public void reject() {
410 try {
411 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700412 mConnectionService.reject(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700413 }
414 } catch (RemoteException ignored) {
415 }
416 }
417
Ihab Awad5d0410f2014-07-30 10:07:40 -0700418 /**
419 * Instructs this {@code RemoteConnection} to go on hold.
420 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700421 public void hold() {
422 try {
423 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700424 mConnectionService.hold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700425 }
426 } catch (RemoteException ignored) {
427 }
428 }
429
Ihab Awad5d0410f2014-07-30 10:07:40 -0700430 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700431 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700432 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700433 public void unhold() {
434 try {
435 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700436 mConnectionService.unhold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700437 }
438 } catch (RemoteException ignored) {
439 }
440 }
441
Ihab Awad5d0410f2014-07-30 10:07:40 -0700442 /**
443 * Instructs this {@code RemoteConnection} to disconnect.
444 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700445 public void disconnect() {
446 try {
447 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700448 mConnectionService.disconnect(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700449 }
450 } catch (RemoteException ignored) {
451 }
452 }
453
Ihab Awad5d0410f2014-07-30 10:07:40 -0700454 /**
455 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
456 * (DTMF) tone.
457 *
458 * Any other currently playing DTMF tone in the specified call is immediately stopped.
459 *
460 * @param digit A character representing the DTMF digit for which to play the tone. This
461 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
462 */
463 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700464 try {
465 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700466 mConnectionService.playDtmfTone(mConnectionId, digit);
Santos Cordon52d8a152014-06-17 19:08:45 -0700467 }
468 } catch (RemoteException ignored) {
469 }
470 }
471
Ihab Awad5d0410f2014-07-30 10:07:40 -0700472 /**
473 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
474 * (DTMF) tone currently playing.
475 *
476 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
477 * currently playing, this method will do nothing.
478 */
479 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700480 try {
481 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700482 mConnectionService.stopDtmfTone(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700483 }
484 } catch (RemoteException ignored) {
485 }
486 }
487
Ihab Awad5d0410f2014-07-30 10:07:40 -0700488 /**
489 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
490 *
491 * A post-dial DTMF string is a string of digits following the first instance of either
492 * {@link TelecommManager#DTMF_CHARACTER_WAIT} or {@link TelecommManager#DTMF_CHARACTER_PAUSE}.
493 * These digits are immediately sent as DTMF tones to the recipient as soon as the
494 * connection is made.
495 *
496 * If the DTMF string contains a {@link TelecommManager#DTMF_CHARACTER_PAUSE} symbol, this
497 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
498 * of time.
499 *
500 * If the DTMF string contains a {@link TelecommManager#DTMF_CHARACTER_WAIT} symbol, this
501 * {@code RemoteConnection} will pause playing the tones and notify listeners via
502 * {@link Listener#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
503 * should display to the user an indication of this state and an affordance to continue
504 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
505 * app should invoke the {@link #postDialContinue(boolean)} method.
506 *
507 * @param proceed Whether or not to continue with the post-dial sequence.
508 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700509 public void postDialContinue(boolean proceed) {
510 try {
511 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700512 mConnectionService.onPostDialContinue(mConnectionId, proceed);
Santos Cordon52d8a152014-06-17 19:08:45 -0700513 }
514 } catch (RemoteException ignored) {
515 }
516 }
517
Ihab Awad5d0410f2014-07-30 10:07:40 -0700518 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700519 * Set the audio state of this {@code RemoteConnection}.
520 *
521 * @param state The audio state of this {@code RemoteConnection}.
522 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700523 public void setAudioState(AudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -0700524 try {
525 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700526 mConnectionService.onAudioStateChanged(mConnectionId, state);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700527 }
528 } catch (RemoteException ignored) {
529 }
530 }
531
Santos Cordon52d8a152014-06-17 19:08:45 -0700532 /**
533 * @hide
534 */
535 void setState(int state) {
536 if (mState != state) {
537 mState = state;
538 for (Listener l: mListeners) {
539 l.onStateChanged(this, state);
540 }
541 }
542 }
543
544 /**
545 * @hide
546 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700547 void setDisconnected(int cause, String message) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700548 if (mState != Connection.STATE_DISCONNECTED) {
549 mState = Connection.STATE_DISCONNECTED;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700550 mDisconnectCauseCode = cause;
551 mDisconnectCauseMessage = message;
Santos Cordon52d8a152014-06-17 19:08:45 -0700552
553 for (Listener l : mListeners) {
554 l.onDisconnected(this, cause, message);
555 }
556 }
557 }
558
559 /**
560 * @hide
561 */
562 void setRequestingRingback(boolean ringback) {
563 if (mRequestingRingback != ringback) {
564 mRequestingRingback = ringback;
565 for (Listener l : mListeners) {
566 l.onRequestingRingback(this, ringback);
567 }
568 }
569 }
570
571 /**
572 * @hide
573 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700574 void setCallCapabilities(int callCapabilities) {
575 mCallCapabilities = callCapabilities;
576 for (Listener l : mListeners) {
577 l.onCallCapabilitiesChanged(this, callCapabilities);
578 }
579 }
580
581 /**
582 * @hide
583 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700584 void setDestroyed() {
585 if (!mListeners.isEmpty()) {
586 // Make sure that the listeners are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700587 if (mState != Connection.STATE_DISCONNECTED) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700588 setDisconnected(DisconnectCause.ERROR_UNSPECIFIED, "Connection destroyed.");
589 }
590
591 Set<Listener> listeners = new HashSet<Listener>(mListeners);
592 mListeners.clear();
593 for (Listener l : listeners) {
594 l.onDestroyed(this);
595 }
596
597 mConnected = false;
598 }
599 }
600
601 /**
602 * @hide
603 */
604 void setPostDialWait(String remainingDigits) {
605 for (Listener l : mListeners) {
606 l.onPostDialWait(this, remainingDigits);
607 }
608 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700609
Tyler Gunnaa07df82014-07-17 07:50:22 -0700610 /**
611 * @hide
612 */
613 void setVideoState(int videoState) {
614 mVideoState = videoState;
615 for (Listener l : mListeners) {
616 l.onVideoStateChanged(this, videoState);
617 }
618 }
619
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700620 /** @hide */
621 void setAudioModeIsVoip(boolean isVoip) {
622 mAudioModeIsVoip = isVoip;
623 for (Listener l : mListeners) {
Sailesh Nepal61203862014-07-11 14:50:13 -0700624 l.onAudioModeIsVoipChanged(this, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700625 }
626 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700627
628 /** @hide */
629 void setStatusHints(StatusHints statusHints) {
630 mStatusHints = statusHints;
631 for (Listener l : mListeners) {
Sailesh Nepal61203862014-07-11 14:50:13 -0700632 l.onStatusHintsChanged(this, statusHints);
633 }
634 }
635
636 /** @hide */
637 void setHandle(Uri handle, int presentation) {
638 mHandle = handle;
639 mHandlePresentation = presentation;
640 for (Listener l : mListeners) {
641 l.onHandleChanged(this, handle, presentation);
642 }
643 }
644
645 /** @hide */
646 void setCallerDisplayName(String callerDisplayName, int presentation) {
647 mCallerDisplayName = callerDisplayName;
648 mCallerDisplayNamePresentation = presentation;
649 for (Listener l : mListeners) {
650 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700651 }
652 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700653
654 /** @hide */
655 void startActivityFromInCall(PendingIntent intent) {
656 for (Listener l : mListeners) {
657 l.onStartActivityFromInCall(this, intent);
658 }
659 }
Evan Charltonbf11f982014-07-20 22:06:28 -0700660
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700661 /** @hide */
662 void setConferenceableConnections(List<RemoteConnection> conferenceableConnections) {
663 mConferenceableConnections.clear();
664 mConferenceableConnections.addAll(conferenceableConnections);
665 for (Listener l : mListeners) {
666 l.onConferenceableConnectionsChanged(
667 this, new ArrayList<RemoteConnection>(mConferenceableConnections));
668 }
669 }
670
Evan Charltonbf11f982014-07-20 22:06:28 -0700671 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700672 * Create a RemoteConnection which is in the {@link Connection#STATE_FAILED} state. Attempting
Evan Charltonbf11f982014-07-20 22:06:28 -0700673 * to use it for anything will almost certainly result in bad things happening. Do not do this.
674 *
675 * @return a failed {@link RemoteConnection}
676 *
677 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700678 */
679 public static RemoteConnection failure(int failureCode, String failureMessage) {
680 return new RemoteConnection(failureCode, failureMessage);
681 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700682}