blob: 054de4c561382ee12a9fd7265cf3d01b69fa0e7a [file] [log] [blame]
Ihab Awad542e0ea2014-05-16 10:22:16 -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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Ihab Awad542e0ea2014-05-16 10:22:16 -070018
Ihab Awad542e0ea2014-05-16 10:22:16 -070019import android.net.Uri;
Sailesh Nepal61203862014-07-11 14:50:13 -070020import android.os.Bundle;
Ihab Awadfbb092f2014-06-03 18:40:45 -070021import android.os.Parcel;
Hall Liu95d55872017-01-25 17:12:49 -080022import android.os.ParcelFileDescriptor;
Ihab Awadfbb092f2014-06-03 18:40:45 -070023import android.os.Parcelable;
Ihab Awad542e0ea2014-05-16 10:22:16 -070024
25/**
26 * Simple data container encapsulating a request to some entity to
27 * create a new {@link Connection}.
28 */
Ihab Awadfbb092f2014-06-03 18:40:45 -070029public final class ConnectionRequest implements Parcelable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070030
Hall Liu95d55872017-01-25 17:12:49 -080031 /**
32 * Builder class for {@link ConnectionRequest}
33 * @hide
34 */
35 public static final class Builder {
36 private PhoneAccountHandle mAccountHandle;
37 private Uri mAddress;
38 private Bundle mExtras;
39 private int mVideoState = VideoProfile.STATE_AUDIO_ONLY;
40 private String mTelecomCallId;
41 private boolean mShouldShowIncomingCallUi = false;
42 private ParcelFileDescriptor mRttPipeToInCall;
43 private ParcelFileDescriptor mRttPipeFromInCall;
44
45 public Builder() { }
46
47 /**
48 * Sets the phone account handle for the resulting {@link ConnectionRequest}
49 * @param accountHandle The accountHandle which should be used to place the call.
50 */
51 public Builder setAccountHandle(PhoneAccountHandle accountHandle) {
52 this.mAccountHandle = accountHandle;
53 return this;
54 }
55
56 /**
57 * Sets the address for the resulting {@link ConnectionRequest}
58 * @param address The address(e.g., phone number) to which the {@link Connection} is to
59 * connect.
60 */
61 public Builder setAddress(Uri address) {
62 this.mAddress = address;
63 return this;
64 }
65
66 /**
67 * Sets the extras bundle for the resulting {@link ConnectionRequest}
68 * @param extras Application-specific extra data.
69 */
70 public Builder setExtras(Bundle extras) {
71 this.mExtras = extras;
72 return this;
73 }
74
75 /**
76 * Sets the video state for the resulting {@link ConnectionRequest}
77 * @param videoState Determines the video state for the connection.
78 */
79 public Builder setVideoState(int videoState) {
80 this.mVideoState = videoState;
81 return this;
82 }
83
84 /**
85 * Sets the Telecom call ID for the resulting {@link ConnectionRequest}
86 * @param telecomCallId The telecom call ID.
87 */
88 public Builder setTelecomCallId(String telecomCallId) {
89 this.mTelecomCallId = telecomCallId;
90 return this;
91 }
92
93 /**
94 * Sets shouldShowIncomingUi for the resulting {@link ConnectionRequest}
95 * @param shouldShowIncomingCallUi For a self-managed {@link ConnectionService}, will be
96 * {@code true} if the {@link ConnectionService} should show
97 * its own incoming call UI for an incoming call. When
98 * {@code false}, Telecom shows the incoming call UI.
99 */
100 public Builder setShouldShowIncomingCallUi(boolean shouldShowIncomingCallUi) {
101 this.mShouldShowIncomingCallUi = shouldShowIncomingCallUi;
102 return this;
103 }
104
105 /**
106 * Sets the RTT pipe for transferring text into the {@link ConnectionService} for the
107 * resulting {@link ConnectionRequest}
108 * @param rttPipeFromInCall The data pipe to read from.
109 */
110 public Builder setRttPipeFromInCall(ParcelFileDescriptor rttPipeFromInCall) {
111 this.mRttPipeFromInCall = rttPipeFromInCall;
112 return this;
113 }
114
115 /**
116 * Sets the RTT pipe for transferring text out of {@link ConnectionService} for the
117 * resulting {@link ConnectionRequest}
118 * @param rttPipeToInCall The data pipe to write to.
119 */
120 public Builder setRttPipeToInCall(ParcelFileDescriptor rttPipeToInCall) {
121 this.mRttPipeToInCall = rttPipeToInCall;
122 return this;
123 }
124
125 public ConnectionRequest build() {
126 return new ConnectionRequest(
127 mAccountHandle,
128 mAddress,
129 mExtras,
130 mVideoState,
131 mTelecomCallId,
132 mShouldShowIncomingCallUi,
133 mRttPipeFromInCall,
134 mRttPipeToInCall);
135 }
136 }
137
Evan Charlton8c8a0622014-07-20 12:31:00 -0700138 private final PhoneAccountHandle mAccountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -0700139 private final Uri mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700140 private final Bundle mExtras;
Tyler Gunn12013ad2014-07-08 14:04:58 -0700141 private final int mVideoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700142 private final String mTelecomCallId;
Tyler Gunnf5035432017-01-09 09:43:12 -0800143 private final boolean mShouldShowIncomingCallUi;
Hall Liu95d55872017-01-25 17:12:49 -0800144 private final ParcelFileDescriptor mRttPipeToInCall;
145 private final ParcelFileDescriptor mRttPipeFromInCall;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700146
Sailesh Nepal61203862014-07-11 14:50:13 -0700147 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700148 * @param accountHandle The accountHandle which should be used to place the call.
Sailesh Nepal61203862014-07-11 14:50:13 -0700149 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Sailesh Nepal61203862014-07-11 14:50:13 -0700150 * @param extras Application-specific extra data.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700151 */
152 public ConnectionRequest(
153 PhoneAccountHandle accountHandle,
154 Uri handle,
Tyler Gunnbe74de02014-08-29 14:51:48 -0700155 Bundle extras) {
Hall Liu95d55872017-01-25 17:12:49 -0800156 this(accountHandle, handle, extras, VideoProfile.STATE_AUDIO_ONLY, null, false, null, null);
Tyler Gunnbe74de02014-08-29 14:51:48 -0700157 }
158
159 /**
160 * @param accountHandle The accountHandle which should be used to place the call.
161 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700162 * @param extras Application-specific extra data.
Sailesh Nepal61203862014-07-11 14:50:13 -0700163 * @param videoState Determines the video state for the connection.
164 */
165 public ConnectionRequest(
Evan Charlton8c8a0622014-07-20 12:31:00 -0700166 PhoneAccountHandle accountHandle,
Sailesh Nepal61203862014-07-11 14:50:13 -0700167 Uri handle,
Sailesh Nepal61203862014-07-11 14:50:13 -0700168 Bundle extras,
Tyler Gunn12013ad2014-07-08 14:04:58 -0700169 int videoState) {
Hall Liu95d55872017-01-25 17:12:49 -0800170 this(accountHandle, handle, extras, videoState, null, false, null, null);
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700171 }
172
173 /**
174 * @param accountHandle The accountHandle which should be used to place the call.
175 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
176 * @param extras Application-specific extra data.
177 * @param videoState Determines the video state for the connection.
178 * @param telecomCallId The telecom call ID.
Tyler Gunnf5035432017-01-09 09:43:12 -0800179 * @param shouldShowIncomingCallUi For a self-managed {@link ConnectionService}, will be
180 * {@code true} if the {@link ConnectionService} should show its
181 * own incoming call UI for an incoming call. When
182 * {@code false}, Telecom shows the incoming call UI.
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700183 * @hide
184 */
185 public ConnectionRequest(
186 PhoneAccountHandle accountHandle,
187 Uri handle,
188 Bundle extras,
189 int videoState,
Tyler Gunnf5035432017-01-09 09:43:12 -0800190 String telecomCallId,
191 boolean shouldShowIncomingCallUi) {
Hall Liu95d55872017-01-25 17:12:49 -0800192 this(accountHandle, handle, extras, videoState, telecomCallId,
193 shouldShowIncomingCallUi, null, null);
194 }
195
196 private ConnectionRequest(
197 PhoneAccountHandle accountHandle,
198 Uri handle,
199 Bundle extras,
200 int videoState,
201 String telecomCallId,
202 boolean shouldShowIncomingCallUi,
203 ParcelFileDescriptor rttPipeFromInCall,
204 ParcelFileDescriptor rttPipeToInCall) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700205 mAccountHandle = accountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -0700206 mAddress = handle;
Ihab Awadfbb092f2014-06-03 18:40:45 -0700207 mExtras = extras;
Tyler Gunn12013ad2014-07-08 14:04:58 -0700208 mVideoState = videoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700209 mTelecomCallId = telecomCallId;
Tyler Gunnf5035432017-01-09 09:43:12 -0800210 mShouldShowIncomingCallUi = shouldShowIncomingCallUi;
Hall Liu95d55872017-01-25 17:12:49 -0800211 mRttPipeFromInCall = rttPipeFromInCall;
212 mRttPipeToInCall = rttPipeToInCall;
Ihab Awadfbb092f2014-06-03 18:40:45 -0700213 }
214
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700215 private ConnectionRequest(Parcel in) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700216 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Nancy Chenea38cca2014-09-05 16:38:49 -0700217 mAddress = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700218 mExtras = in.readParcelable(getClass().getClassLoader());
219 mVideoState = in.readInt();
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700220 mTelecomCallId = in.readString();
Tyler Gunnf5035432017-01-09 09:43:12 -0800221 mShouldShowIncomingCallUi = in.readInt() == 1;
Hall Liu95d55872017-01-25 17:12:49 -0800222 mRttPipeFromInCall = in.readParcelable(getClass().getClassLoader());
223 mRttPipeToInCall = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700224 }
225
Ihab Awadfbb092f2014-06-03 18:40:45 -0700226 /**
Ihab Awad9c3f1882014-06-30 21:17:13 -0700227 * The account which should be used to place the call.
Santos Cordon52d8a152014-06-17 19:08:45 -0700228 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700229 public PhoneAccountHandle getAccountHandle() { return mAccountHandle; }
Santos Cordon52d8a152014-06-17 19:08:45 -0700230
231 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700232 * The handle (e.g., phone number) to which the {@link Connection} is to connect.
233 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700234 public Uri getAddress() { return mAddress; }
Sailesh Nepal61203862014-07-11 14:50:13 -0700235
236 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700237 * Application-specific extra data. Used for passing back information from an incoming
238 * call {@code Intent}, and for any proprietary extensions arranged between a client
239 * and servant {@code ConnectionService} which agree on a vocabulary for such data.
240 */
241 public Bundle getExtras() { return mExtras; }
242
Tyler Gunn12013ad2014-07-08 14:04:58 -0700243 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700244 * Describes the video states supported by the client requesting the connection.
Yorke Lee32f24732015-05-12 16:18:03 -0700245 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
246 * {@link VideoProfile#STATE_BIDIRECTIONAL},
247 * {@link VideoProfile#STATE_TX_ENABLED},
248 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunn12013ad2014-07-08 14:04:58 -0700249 *
250 * @return The video state for the connection.
251 */
252 public int getVideoState() {
253 return mVideoState;
254 }
255
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700256 /**
257 * Returns the internal Telecom ID associated with the connection request.
258 *
259 * @return The Telecom ID.
260 * @hide
261 */
262 public String getTelecomCallId() {
263 return mTelecomCallId;
264 }
265
Tyler Gunnf5035432017-01-09 09:43:12 -0800266 /**
267 * For a self-managed {@link ConnectionService}, indicates for an incoming call whether the
268 * {@link ConnectionService} should show its own incoming call UI for an incoming call.
269 *
270 * @return {@code true} if the {@link ConnectionService} should show its own incoming call UI.
271 * When {@code false}, Telecom shows the incoming call UI for the call.
272 * @hide
273 */
274 public boolean shouldShowIncomingCallUi() {
275 return mShouldShowIncomingCallUi;
276 }
277
Hall Liu95d55872017-01-25 17:12:49 -0800278 /**
279 * Gets the {@link ParcelFileDescriptor} that is used to send RTT text from the connection
280 * service to the in-call UI. In order to obtain an
281 * {@link java.io.InputStream} from this {@link ParcelFileDescriptor}, use
282 * {@link android.os.ParcelFileDescriptor.AutoCloseInputStream}.
283 * Only text data encoded using UTF-8 should be written into this {@link ParcelFileDescriptor}.
284 * @return The {@link ParcelFileDescriptor} that should be used for communication.
285 * Do not un-hide -- only for use by Telephony
286 * @hide
287 */
288 public ParcelFileDescriptor getRttPipeToInCall() {
289 return mRttPipeToInCall;
290 }
291
292 /**
293 * Gets the {@link ParcelFileDescriptor} that is used to send RTT text from the in-call UI to
294 * the connection service. In order to obtain an
295 * {@link java.io.OutputStream} from this {@link ParcelFileDescriptor}, use
296 * {@link android.os.ParcelFileDescriptor.AutoCloseOutputStream}.
297 * The contents of this {@link ParcelFileDescriptor} will consist solely of text encoded in
298 * UTF-8.
299 * @return The {@link ParcelFileDescriptor} that should be used for communication
300 * Do not un-hide -- only for use by Telephony
301 * @hide
302 */
303 public ParcelFileDescriptor getRttPipeFromInCall() {
304 return mRttPipeFromInCall;
305 }
306
307 /**
308 * Gets the {@link android.telecom.Connection.RttTextStream} object that should be used to
309 * send and receive RTT text to/from the in-call app.
310 * @return An instance of {@link android.telecom.Connection.RttTextStream}, or {@code null}
311 * if this connection request is not requesting an RTT session upon connection establishment.
312 * @hide
313 */
314 public Connection.RttTextStream getRttTextStream() {
315 if (isRequestingRtt()) {
316 return new Connection.RttTextStream(mRttPipeToInCall, mRttPipeFromInCall);
317 } else {
318 return null;
319 }
320 }
321
322 /**
323 * Convenience method for determining whether the ConnectionRequest is requesting an RTT session
324 * @return {@code true} if RTT is requested, {@code false} otherwise.
325 * @hide
326 */
327 public boolean isRequestingRtt() {
328 return mRttPipeFromInCall != null && mRttPipeToInCall != null;
329 }
330
Evan Charltonbf11f982014-07-20 22:06:28 -0700331 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700332 public String toString() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700333 return String.format("ConnectionRequest %s %s",
Nancy Chenea38cca2014-09-05 16:38:49 -0700334 mAddress == null
Ihab Awad542e0ea2014-05-16 10:22:16 -0700335 ? Uri.EMPTY
Nancy Chenea38cca2014-09-05 16:38:49 -0700336 : Connection.toLogSafePhoneNumber(mAddress.toString()),
Ihab Awad542e0ea2014-05-16 10:22:16 -0700337 mExtras == null ? "" : mExtras);
338 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700339
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700340 public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () {
341 @Override
342 public ConnectionRequest createFromParcel(Parcel source) {
343 return new ConnectionRequest(source);
344 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700345
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700346 @Override
347 public ConnectionRequest[] newArray(int size) {
348 return new ConnectionRequest[size];
349 }
350 };
Ihab Awadfbb092f2014-06-03 18:40:45 -0700351
352 /**
353 * {@inheritDoc}
354 */
355 @Override
356 public int describeContents() {
357 return 0;
358 }
359
Ihab Awadfbb092f2014-06-03 18:40:45 -0700360 @Override
361 public void writeToParcel(Parcel destination, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700362 destination.writeParcelable(mAccountHandle, 0);
Nancy Chenea38cca2014-09-05 16:38:49 -0700363 destination.writeParcelable(mAddress, 0);
Ihab Awadfbb092f2014-06-03 18:40:45 -0700364 destination.writeParcelable(mExtras, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700365 destination.writeInt(mVideoState);
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700366 destination.writeString(mTelecomCallId);
Tyler Gunnf5035432017-01-09 09:43:12 -0800367 destination.writeInt(mShouldShowIncomingCallUi ? 1 : 0);
Hall Liu95d55872017-01-25 17:12:49 -0800368 destination.writeParcelable(mRttPipeFromInCall, 0);
369 destination.writeParcelable(mRttPipeToInCall, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700370 }
371}