blob: 30cfdde8ea809f0289d27a8e986b7bb1830c464f [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;
Jay Shrauner229e3822014-08-15 09:23:07 -0700187 /**
188 * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
189 * load factor before resizing, 1 means we only expect a single thread to
190 * access the map so make only a single shard
191 */
Sailesh Nepalf4669df2014-08-14 17:43:13 -0700192 private final Set<Listener> mListeners = Collections.newSetFromMap(
Jay Shrauner229e3822014-08-15 09:23:07 -0700193 new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700194 private final Set<RemoteConnection> mConferenceableConnections = new HashSet<>();
Santos Cordon52d8a152014-06-17 19:08:45 -0700195
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700196 private int mState = Connection.STATE_NEW;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700197 private int mDisconnectCauseCode = DisconnectCause.NOT_VALID;
198 private String mDisconnectCauseMessage;
Santos Cordon52d8a152014-06-17 19:08:45 -0700199 private boolean mRequestingRingback;
200 private boolean mConnected;
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700201 private int mCallCapabilities;
Tyler Gunnaa07df82014-07-17 07:50:22 -0700202 private int mVideoState;
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700203 private boolean mAudioModeIsVoip;
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700204 private StatusHints mStatusHints;
Sailesh Nepal61203862014-07-11 14:50:13 -0700205 private Uri mHandle;
206 private int mHandlePresentation;
207 private String mCallerDisplayName;
208 private int mCallerDisplayNamePresentation;
Evan Charltonbf11f982014-07-20 22:06:28 -0700209 private int mFailureCode;
210 private String mFailureMessage;
Santos Cordon52d8a152014-06-17 19:08:45 -0700211
212 /**
213 * @hide
214 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700215 RemoteConnection(
216 String id,
217 IConnectionService connectionService,
218 ConnectionRequest request) {
219 mConnectionId = id;
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700220 mConnectionService = connectionService;
Santos Cordon52d8a152014-06-17 19:08:45 -0700221 mConnected = true;
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700222 mState = Connection.STATE_INITIALIZING;
Evan Charltonbf11f982014-07-20 22:06:28 -0700223 }
224
225 /**
226 * Create a RemoteConnection which is used for failed connections. Note that using it for any
227 * "real" purpose will almost certainly fail. Callers should note the failure and act
228 * accordingly (moving on to another RemoteConnection, for example)
229 *
230 * @param failureCode
231 * @param failureMessage
232 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700233 RemoteConnection(int failureCode, String failureMessage) {
234 this("NULL", null, null);
Evan Charltonbf11f982014-07-20 22:06:28 -0700235 mConnected = false;
Ihab Awad6107bab2014-08-18 09:23:25 -0700236 mState = Connection.STATE_DISCONNECTED;
237 mFailureCode = DisconnectCause.OUTGOING_FAILURE;
238 mFailureMessage = failureMessage + " original code = " + failureCode;
Santos Cordon52d8a152014-06-17 19:08:45 -0700239 }
240
Ihab Awad5d0410f2014-07-30 10:07:40 -0700241 /**
242 * Adds a listener to this {@code RemoteConnection}.
243 *
244 * @param listener A {@code Listener}.
245 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700246 public void addListener(Listener listener) {
247 mListeners.add(listener);
248 }
249
Ihab Awad5d0410f2014-07-30 10:07:40 -0700250 /**
251 * Removes a listener from this {@code RemoteConnection}.
252 *
253 * @param listener A {@code Listener}.
254 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700255 public void removeListener(Listener listener) {
Jay Shrauner229e3822014-08-15 09:23:07 -0700256 if (listener != null) {
257 mListeners.remove(listener);
258 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700259 }
260
Ihab Awad5d0410f2014-07-30 10:07:40 -0700261 /**
262 * Obtains the parent of this {@code RemoteConnection} in a conference, if any.
263 *
264 * @return The parent {@code RemoteConnection}, or {@code null} if this {@code RemoteConnection}
265 * is not a child of any conference {@code RemoteConnection}s.
266 */
267 public RemoteConnection getParent() { return null; }
268
269 /**
270 * Obtains the children of this conference {@code RemoteConnection}, if any.
271 *
272 * @return The children of this {@code RemoteConnection} if this {@code RemoteConnection} is
273 * a conference, or an empty {@code List} otherwise.
274 */
275 public List<RemoteConnection> getChildren() { return null; }
276
277 /**
278 * Obtains the state of this {@code RemoteConnection}.
279 *
280 * @return A state value, chosen from the {@code STATE_*} constants.
281 */
Sailesh Nepalade3f252014-07-01 17:25:37 -0700282 public int getState() {
283 return mState;
284 }
285
Ihab Awad5d0410f2014-07-30 10:07:40 -0700286 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700287 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, the
Ihab Awad5d0410f2014-07-30 10:07:40 -0700288 * disconnect cause expressed as a code chosen from among those declared in
289 * {@link DisconnectCause}.
290 */
291 public int getDisconnectCauseCode() {
292 return mDisconnectCauseCode;
Santos Cordon52d8a152014-06-17 19:08:45 -0700293 }
294
Ihab Awad5d0410f2014-07-30 10:07:40 -0700295 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700296 * @return For a {@link Connection#STATE_DISCONNECTED} {@code RemoteConnection}, an optional
Ihab Awad5d0410f2014-07-30 10:07:40 -0700297 * reason for disconnection expressed as a free text message.
298 */
299 public String getDisconnectCauseMessage() {
300 return mDisconnectCauseMessage;
Santos Cordon52d8a152014-06-17 19:08:45 -0700301 }
302
Ihab Awad5d0410f2014-07-30 10:07:40 -0700303 /**
304 * @return A bitmask of the capabilities of the {@code RemoteConnection}, as defined in
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700305 * {@link PhoneCapabilities}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700306 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700307 public int getCallCapabilities() {
308 return mCallCapabilities;
309 }
310
Ihab Awad5d0410f2014-07-30 10:07:40 -0700311 /**
312 * @return {@code true} if the {@code RemoteConnection}'s current audio mode is VOIP.
313 */
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700314 public boolean getAudioModeIsVoip() {
315 return mAudioModeIsVoip;
316 }
317
Ihab Awad5d0410f2014-07-30 10:07:40 -0700318 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700319 * @return The current {@link StatusHints} of this {@code RemoteConnection},
Ihab Awad5d0410f2014-07-30 10:07:40 -0700320 * or {@code null} if none have been set.
321 */
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700322 public StatusHints getStatusHints() {
323 return mStatusHints;
324 }
325
Ihab Awad5d0410f2014-07-30 10:07:40 -0700326 /**
327 * @return The handle (e.g., phone number) to which the {@code RemoteConnection} is currently
328 * connected.
329 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700330 public Uri getHandle() {
331 return mHandle;
332 }
333
Ihab Awad5d0410f2014-07-30 10:07:40 -0700334 /**
335 * @return The presentation requirements for the handle. See
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700336 * {@link PropertyPresentation} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700337 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700338 public int getHandlePresentation() {
339 return mHandlePresentation;
340 }
341
Ihab Awad5d0410f2014-07-30 10:07:40 -0700342 /**
343 * @return The display name for the caller.
344 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700345 public String getCallerDisplayName() {
346 return mCallerDisplayName;
347 }
348
Ihab Awad5d0410f2014-07-30 10:07:40 -0700349 /**
350 * @return The presentation requirements for the caller display name. See
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700351 * {@link PropertyPresentation} for valid values.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700352 */
Sailesh Nepal61203862014-07-11 14:50:13 -0700353 public int getCallerDisplayNamePresentation() {
354 return mCallerDisplayNamePresentation;
355 }
356
Ihab Awad5d0410f2014-07-30 10:07:40 -0700357 /**
358 * @return The video state of the {@code RemoteConnection}. See
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700359 * {@link VideoProfile.VideoState}.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700360 */
Tyler Gunnaa07df82014-07-17 07:50:22 -0700361 public int getVideoState() {
362 return mVideoState;
363 }
364
Ihab Awad5d0410f2014-07-30 10:07:40 -0700365 /**
366 * @return The failure code ({@see DisconnectCause}) associated with this failed
367 * {@code RemoteConnection}.
368 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700369 public int getFailureCode() {
370 return mFailureCode;
371 }
372
Ihab Awad5d0410f2014-07-30 10:07:40 -0700373 /**
374 * @return The reason for the connection failure. This will not be displayed to the user.
375 */
Evan Charltonbf11f982014-07-20 22:06:28 -0700376 public String getFailureMessage() {
377 return mFailureMessage;
378 }
379
Ihab Awad5d0410f2014-07-30 10:07:40 -0700380 /**
381 * @return Whether the {@code RemoteConnection} is requesting that the framework play a
382 * ringback tone on its behalf.
383 */
384 public boolean isRequestingRingback() {
385 return false;
386 }
387
388 /**
389 * Instructs this {@code RemoteConnection} to abort.
390 */
Sailesh Nepal091768c2014-06-30 15:15:23 -0700391 public void abort() {
392 try {
393 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700394 mConnectionService.abort(mConnectionId);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700395 }
396 } catch (RemoteException ignored) {
397 }
398 }
399
Ihab Awad5d0410f2014-07-30 10:07:40 -0700400 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700401 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to answer.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700402 * @param videoState The video state in which to answer the call.
403 */
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700404 public void answer(int videoState) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700405 try {
406 if (mConnected) {
Andrew Lee8da4c3c2014-07-16 10:11:42 -0700407 mConnectionService.answer(mConnectionId, videoState);
Santos Cordon52d8a152014-06-17 19:08:45 -0700408 }
409 } catch (RemoteException ignored) {
410 }
411 }
412
Ihab Awad5d0410f2014-07-30 10:07:40 -0700413 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700414 * Instructs this {@link Connection#STATE_RINGING} {@code RemoteConnection} to reject.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700415 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700416 public void reject() {
417 try {
418 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700419 mConnectionService.reject(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700420 }
421 } catch (RemoteException ignored) {
422 }
423 }
424
Ihab Awad5d0410f2014-07-30 10:07:40 -0700425 /**
426 * Instructs this {@code RemoteConnection} to go on hold.
427 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700428 public void hold() {
429 try {
430 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700431 mConnectionService.hold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700432 }
433 } catch (RemoteException ignored) {
434 }
435 }
436
Ihab Awad5d0410f2014-07-30 10:07:40 -0700437 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700438 * Instructs this {@link Connection#STATE_HOLDING} call to release from hold.
Ihab Awad5d0410f2014-07-30 10:07:40 -0700439 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700440 public void unhold() {
441 try {
442 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700443 mConnectionService.unhold(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700444 }
445 } catch (RemoteException ignored) {
446 }
447 }
448
Ihab Awad5d0410f2014-07-30 10:07:40 -0700449 /**
450 * Instructs this {@code RemoteConnection} to disconnect.
451 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700452 public void disconnect() {
453 try {
454 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700455 mConnectionService.disconnect(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700456 }
457 } catch (RemoteException ignored) {
458 }
459 }
460
Ihab Awad5d0410f2014-07-30 10:07:40 -0700461 /**
462 * Instructs this {@code RemoteConnection} to play a dual-tone multi-frequency signaling
463 * (DTMF) tone.
464 *
465 * Any other currently playing DTMF tone in the specified call is immediately stopped.
466 *
467 * @param digit A character representing the DTMF digit for which to play the tone. This
468 * value must be one of {@code '0'} through {@code '9'}, {@code '*'} or {@code '#'}.
469 */
470 public void playDtmfTone(char digit) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700471 try {
472 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700473 mConnectionService.playDtmfTone(mConnectionId, digit);
Santos Cordon52d8a152014-06-17 19:08:45 -0700474 }
475 } catch (RemoteException ignored) {
476 }
477 }
478
Ihab Awad5d0410f2014-07-30 10:07:40 -0700479 /**
480 * Instructs this {@code RemoteConnection} to stop any dual-tone multi-frequency signaling
481 * (DTMF) tone currently playing.
482 *
483 * DTMF tones are played by calling {@link #playDtmfTone(char)}. If no DTMF tone is
484 * currently playing, this method will do nothing.
485 */
486 public void stopDtmfTone() {
Santos Cordon52d8a152014-06-17 19:08:45 -0700487 try {
488 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700489 mConnectionService.stopDtmfTone(mConnectionId);
Santos Cordon52d8a152014-06-17 19:08:45 -0700490 }
491 } catch (RemoteException ignored) {
492 }
493 }
494
Ihab Awad5d0410f2014-07-30 10:07:40 -0700495 /**
496 * Instructs this {@code RemoteConnection} to continue playing a post-dial DTMF string.
497 *
498 * A post-dial DTMF string is a string of digits following the first instance of either
499 * {@link TelecommManager#DTMF_CHARACTER_WAIT} or {@link TelecommManager#DTMF_CHARACTER_PAUSE}.
500 * These digits are immediately sent as DTMF tones to the recipient as soon as the
501 * connection is made.
502 *
503 * If the DTMF string contains a {@link TelecommManager#DTMF_CHARACTER_PAUSE} symbol, this
504 * {@code RemoteConnection} will temporarily pause playing the tones for a pre-defined period
505 * of time.
506 *
507 * If the DTMF string contains a {@link TelecommManager#DTMF_CHARACTER_WAIT} symbol, this
508 * {@code RemoteConnection} will pause playing the tones and notify listeners via
509 * {@link Listener#onPostDialWait(RemoteConnection, String)}. At this point, the in-call app
510 * should display to the user an indication of this state and an affordance to continue
511 * the postdial sequence. When the user decides to continue the postdial sequence, the in-call
512 * app should invoke the {@link #postDialContinue(boolean)} method.
513 *
514 * @param proceed Whether or not to continue with the post-dial sequence.
515 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700516 public void postDialContinue(boolean proceed) {
517 try {
518 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700519 mConnectionService.onPostDialContinue(mConnectionId, proceed);
Santos Cordon52d8a152014-06-17 19:08:45 -0700520 }
521 } catch (RemoteException ignored) {
522 }
523 }
524
Ihab Awad5d0410f2014-07-30 10:07:40 -0700525 /**
Ihab Awad5d0410f2014-07-30 10:07:40 -0700526 * Set the audio state of this {@code RemoteConnection}.
527 *
528 * @param state The audio state of this {@code RemoteConnection}.
529 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700530 public void setAudioState(AudioState state) {
Sailesh Nepal091768c2014-06-30 15:15:23 -0700531 try {
532 if (mConnected) {
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700533 mConnectionService.onAudioStateChanged(mConnectionId, state);
Sailesh Nepal091768c2014-06-30 15:15:23 -0700534 }
535 } catch (RemoteException ignored) {
536 }
537 }
538
Santos Cordon52d8a152014-06-17 19:08:45 -0700539 /**
540 * @hide
541 */
542 void setState(int state) {
543 if (mState != state) {
544 mState = state;
545 for (Listener l: mListeners) {
546 l.onStateChanged(this, state);
547 }
548 }
549 }
550
551 /**
552 * @hide
553 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700554 void setDisconnected(int cause, String message) {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700555 if (mState != Connection.STATE_DISCONNECTED) {
556 mState = Connection.STATE_DISCONNECTED;
Ihab Awad5d0410f2014-07-30 10:07:40 -0700557 mDisconnectCauseCode = cause;
558 mDisconnectCauseMessage = message;
Santos Cordon52d8a152014-06-17 19:08:45 -0700559
560 for (Listener l : mListeners) {
561 l.onDisconnected(this, cause, message);
562 }
563 }
564 }
565
566 /**
567 * @hide
568 */
569 void setRequestingRingback(boolean ringback) {
570 if (mRequestingRingback != ringback) {
571 mRequestingRingback = ringback;
572 for (Listener l : mListeners) {
573 l.onRequestingRingback(this, ringback);
574 }
575 }
576 }
577
578 /**
579 * @hide
580 */
Sailesh Nepal1a7061b2014-07-09 21:03:20 -0700581 void setCallCapabilities(int callCapabilities) {
582 mCallCapabilities = callCapabilities;
583 for (Listener l : mListeners) {
584 l.onCallCapabilitiesChanged(this, callCapabilities);
585 }
586 }
587
588 /**
589 * @hide
590 */
Santos Cordon52d8a152014-06-17 19:08:45 -0700591 void setDestroyed() {
592 if (!mListeners.isEmpty()) {
593 // Make sure that the listeners are notified that the call is destroyed first.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700594 if (mState != Connection.STATE_DISCONNECTED) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700595 setDisconnected(DisconnectCause.ERROR_UNSPECIFIED, "Connection destroyed.");
596 }
597
Jay Shrauner229e3822014-08-15 09:23:07 -0700598 for (Listener l : mListeners) {
Santos Cordon52d8a152014-06-17 19:08:45 -0700599 l.onDestroyed(this);
600 }
Jay Shrauner229e3822014-08-15 09:23:07 -0700601 mListeners.clear();
Santos Cordon52d8a152014-06-17 19:08:45 -0700602
603 mConnected = false;
604 }
605 }
606
607 /**
608 * @hide
609 */
610 void setPostDialWait(String remainingDigits) {
611 for (Listener l : mListeners) {
612 l.onPostDialWait(this, remainingDigits);
613 }
614 }
Sailesh Nepal2a46b902014-07-04 17:21:07 -0700615
Tyler Gunnaa07df82014-07-17 07:50:22 -0700616 /**
617 * @hide
618 */
619 void setVideoState(int videoState) {
620 mVideoState = videoState;
621 for (Listener l : mListeners) {
622 l.onVideoStateChanged(this, videoState);
623 }
624 }
625
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700626 /** @hide */
627 void setAudioModeIsVoip(boolean isVoip) {
628 mAudioModeIsVoip = isVoip;
629 for (Listener l : mListeners) {
Sailesh Nepal61203862014-07-11 14:50:13 -0700630 l.onAudioModeIsVoipChanged(this, isVoip);
Sailesh Nepal33aaae42014-07-07 22:49:44 -0700631 }
632 }
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700633
634 /** @hide */
635 void setStatusHints(StatusHints statusHints) {
636 mStatusHints = statusHints;
637 for (Listener l : mListeners) {
Sailesh Nepal61203862014-07-11 14:50:13 -0700638 l.onStatusHintsChanged(this, statusHints);
639 }
640 }
641
642 /** @hide */
643 void setHandle(Uri handle, int presentation) {
644 mHandle = handle;
645 mHandlePresentation = presentation;
646 for (Listener l : mListeners) {
647 l.onHandleChanged(this, handle, presentation);
648 }
649 }
650
651 /** @hide */
652 void setCallerDisplayName(String callerDisplayName, int presentation) {
653 mCallerDisplayName = callerDisplayName;
654 mCallerDisplayNamePresentation = presentation;
655 for (Listener l : mListeners) {
656 l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
Sailesh Nepale7ef59a2014-07-08 21:48:22 -0700657 }
658 }
Sailesh Nepal2ab88cc2014-07-18 14:49:18 -0700659
660 /** @hide */
661 void startActivityFromInCall(PendingIntent intent) {
662 for (Listener l : mListeners) {
663 l.onStartActivityFromInCall(this, intent);
664 }
665 }
Evan Charltonbf11f982014-07-20 22:06:28 -0700666
Santos Cordon7c7bc7f2014-07-28 18:15:48 -0700667 /** @hide */
668 void setConferenceableConnections(List<RemoteConnection> conferenceableConnections) {
669 mConferenceableConnections.clear();
670 mConferenceableConnections.addAll(conferenceableConnections);
671 for (Listener l : mListeners) {
672 l.onConferenceableConnectionsChanged(
673 this, new ArrayList<RemoteConnection>(mConferenceableConnections));
674 }
675 }
676
Evan Charltonbf11f982014-07-20 22:06:28 -0700677 /**
Ihab Awad6107bab2014-08-18 09:23:25 -0700678 * Create a RemoteConnection represents a failure, and which will be in
679 * {@link Connection#STATE_DISCONNECTED}. Attempting to use it for anything will almost
680 * certainly result in bad things happening. Do not do this.
Evan Charltonbf11f982014-07-20 22:06:28 -0700681 *
682 * @return a failed {@link RemoteConnection}
683 *
684 * @hide
Evan Charltonbf11f982014-07-20 22:06:28 -0700685 */
686 public static RemoteConnection failure(int failureCode, String failureMessage) {
687 return new RemoteConnection(failureCode, failureMessage);
688 }
Santos Cordon52d8a152014-06-17 19:08:45 -0700689}