blob: 221f8f129744f9a14582f8d8aca3a2d3d1b30059 [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
Hall Liub2306242019-11-15 17:13:05 -080019import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
22import android.annotation.TestApi;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023import android.net.Uri;
Sailesh Nepal61203862014-07-11 14:50:13 -070024import android.os.Bundle;
Ihab Awadfbb092f2014-06-03 18:40:45 -070025import android.os.Parcel;
Hall Liu95d55872017-01-25 17:12:49 -080026import android.os.ParcelFileDescriptor;
Ihab Awadfbb092f2014-06-03 18:40:45 -070027import android.os.Parcelable;
Ihab Awad542e0ea2014-05-16 10:22:16 -070028
29/**
30 * Simple data container encapsulating a request to some entity to
31 * create a new {@link Connection}.
32 */
Ihab Awadfbb092f2014-06-03 18:40:45 -070033public final class ConnectionRequest implements Parcelable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070034
Hall Liu95d55872017-01-25 17:12:49 -080035 /**
36 * Builder class for {@link ConnectionRequest}
37 * @hide
38 */
Hall Liub2306242019-11-15 17:13:05 -080039 @TestApi // For convenience in CTS tests
Hall Liu95d55872017-01-25 17:12:49 -080040 public static final class Builder {
41 private PhoneAccountHandle mAccountHandle;
42 private Uri mAddress;
43 private Bundle mExtras;
44 private int mVideoState = VideoProfile.STATE_AUDIO_ONLY;
45 private String mTelecomCallId;
46 private boolean mShouldShowIncomingCallUi = false;
47 private ParcelFileDescriptor mRttPipeToInCall;
48 private ParcelFileDescriptor mRttPipeFromInCall;
49
50 public Builder() { }
51
52 /**
53 * Sets the phone account handle for the resulting {@link ConnectionRequest}
54 * @param accountHandle The accountHandle which should be used to place the call.
55 */
Hall Liub2306242019-11-15 17:13:05 -080056 public @NonNull Builder setAccountHandle(@NonNull PhoneAccountHandle accountHandle) {
Hall Liu95d55872017-01-25 17:12:49 -080057 this.mAccountHandle = accountHandle;
58 return this;
59 }
60
61 /**
62 * Sets the address for the resulting {@link ConnectionRequest}
63 * @param address The address(e.g., phone number) to which the {@link Connection} is to
64 * connect.
65 */
Hall Liub2306242019-11-15 17:13:05 -080066 public @NonNull Builder setAddress(@NonNull Uri address) {
Hall Liu95d55872017-01-25 17:12:49 -080067 this.mAddress = address;
68 return this;
69 }
70
71 /**
72 * Sets the extras bundle for the resulting {@link ConnectionRequest}
73 * @param extras Application-specific extra data.
74 */
Hall Liub2306242019-11-15 17:13:05 -080075 public @NonNull Builder setExtras(@NonNull Bundle extras) {
Hall Liu95d55872017-01-25 17:12:49 -080076 this.mExtras = extras;
77 return this;
78 }
79
80 /**
81 * Sets the video state for the resulting {@link ConnectionRequest}
82 * @param videoState Determines the video state for the connection.
83 */
Hall Liub2306242019-11-15 17:13:05 -080084 public @NonNull Builder setVideoState(int videoState) {
Hall Liu95d55872017-01-25 17:12:49 -080085 this.mVideoState = videoState;
86 return this;
87 }
88
89 /**
90 * Sets the Telecom call ID for the resulting {@link ConnectionRequest}
91 * @param telecomCallId The telecom call ID.
92 */
Hall Liub2306242019-11-15 17:13:05 -080093 public @NonNull Builder setTelecomCallId(@NonNull String telecomCallId) {
Hall Liu95d55872017-01-25 17:12:49 -080094 this.mTelecomCallId = telecomCallId;
95 return this;
96 }
97
98 /**
99 * Sets shouldShowIncomingUi for the resulting {@link ConnectionRequest}
100 * @param shouldShowIncomingCallUi For a self-managed {@link ConnectionService}, will be
101 * {@code true} if the {@link ConnectionService} should show
102 * its own incoming call UI for an incoming call. When
103 * {@code false}, Telecom shows the incoming call UI.
104 */
Hall Liub2306242019-11-15 17:13:05 -0800105 public @NonNull Builder setShouldShowIncomingCallUi(boolean shouldShowIncomingCallUi) {
Hall Liu95d55872017-01-25 17:12:49 -0800106 this.mShouldShowIncomingCallUi = shouldShowIncomingCallUi;
107 return this;
108 }
109
110 /**
111 * Sets the RTT pipe for transferring text into the {@link ConnectionService} for the
112 * resulting {@link ConnectionRequest}
113 * @param rttPipeFromInCall The data pipe to read from.
114 */
Hall Liub2306242019-11-15 17:13:05 -0800115 public @NonNull Builder setRttPipeFromInCall(
116 @NonNull ParcelFileDescriptor rttPipeFromInCall) {
Hall Liu95d55872017-01-25 17:12:49 -0800117 this.mRttPipeFromInCall = rttPipeFromInCall;
118 return this;
119 }
120
121 /**
122 * Sets the RTT pipe for transferring text out of {@link ConnectionService} for the
123 * resulting {@link ConnectionRequest}
124 * @param rttPipeToInCall The data pipe to write to.
125 */
Hall Liub2306242019-11-15 17:13:05 -0800126 public @NonNull Builder setRttPipeToInCall(@NonNull ParcelFileDescriptor rttPipeToInCall) {
Hall Liu95d55872017-01-25 17:12:49 -0800127 this.mRttPipeToInCall = rttPipeToInCall;
128 return this;
129 }
130
Hall Liub2306242019-11-15 17:13:05 -0800131 /**
132 * Build the {@link ConnectionRequest}
133 * @return Result of the builder
134 */
135 public @NonNull ConnectionRequest build() {
Hall Liu95d55872017-01-25 17:12:49 -0800136 return new ConnectionRequest(
137 mAccountHandle,
138 mAddress,
139 mExtras,
140 mVideoState,
141 mTelecomCallId,
142 mShouldShowIncomingCallUi,
143 mRttPipeFromInCall,
144 mRttPipeToInCall);
145 }
146 }
147
Evan Charlton8c8a0622014-07-20 12:31:00 -0700148 private final PhoneAccountHandle mAccountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -0700149 private final Uri mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700150 private final Bundle mExtras;
Tyler Gunn12013ad2014-07-08 14:04:58 -0700151 private final int mVideoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700152 private final String mTelecomCallId;
Tyler Gunnf5035432017-01-09 09:43:12 -0800153 private final boolean mShouldShowIncomingCallUi;
Hall Liu95d55872017-01-25 17:12:49 -0800154 private final ParcelFileDescriptor mRttPipeToInCall;
155 private final ParcelFileDescriptor mRttPipeFromInCall;
Hall Liue9041242018-02-09 16:40:03 -0800156 // Cached return value of getRttTextStream -- we don't want to wrap it more than once.
157 private Connection.RttTextStream mRttTextStream;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700158
Sailesh Nepal61203862014-07-11 14:50:13 -0700159 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700160 * @param accountHandle The accountHandle which should be used to place the call.
Sailesh Nepal61203862014-07-11 14:50:13 -0700161 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Sailesh Nepal61203862014-07-11 14:50:13 -0700162 * @param extras Application-specific extra data.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700163 */
164 public ConnectionRequest(
165 PhoneAccountHandle accountHandle,
166 Uri handle,
Tyler Gunnbe74de02014-08-29 14:51:48 -0700167 Bundle extras) {
Hall Liu95d55872017-01-25 17:12:49 -0800168 this(accountHandle, handle, extras, VideoProfile.STATE_AUDIO_ONLY, null, false, null, null);
Tyler Gunnbe74de02014-08-29 14:51:48 -0700169 }
170
171 /**
172 * @param accountHandle The accountHandle which should be used to place the call.
173 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700174 * @param extras Application-specific extra data.
Sailesh Nepal61203862014-07-11 14:50:13 -0700175 * @param videoState Determines the video state for the connection.
176 */
177 public ConnectionRequest(
Evan Charlton8c8a0622014-07-20 12:31:00 -0700178 PhoneAccountHandle accountHandle,
Sailesh Nepal61203862014-07-11 14:50:13 -0700179 Uri handle,
Sailesh Nepal61203862014-07-11 14:50:13 -0700180 Bundle extras,
Tyler Gunn12013ad2014-07-08 14:04:58 -0700181 int videoState) {
Hall Liu95d55872017-01-25 17:12:49 -0800182 this(accountHandle, handle, extras, videoState, null, false, null, null);
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700183 }
184
185 /**
186 * @param accountHandle The accountHandle which should be used to place the call.
187 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
188 * @param extras Application-specific extra data.
189 * @param videoState Determines the video state for the connection.
190 * @param telecomCallId The telecom call ID.
Tyler Gunnf5035432017-01-09 09:43:12 -0800191 * @param shouldShowIncomingCallUi For a self-managed {@link ConnectionService}, will be
192 * {@code true} if the {@link ConnectionService} should show its
193 * own incoming call UI for an incoming call. When
194 * {@code false}, Telecom shows the incoming call UI.
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700195 * @hide
196 */
197 public ConnectionRequest(
198 PhoneAccountHandle accountHandle,
199 Uri handle,
200 Bundle extras,
201 int videoState,
Tyler Gunnf5035432017-01-09 09:43:12 -0800202 String telecomCallId,
203 boolean shouldShowIncomingCallUi) {
Hall Liu95d55872017-01-25 17:12:49 -0800204 this(accountHandle, handle, extras, videoState, telecomCallId,
205 shouldShowIncomingCallUi, null, null);
206 }
207
208 private ConnectionRequest(
209 PhoneAccountHandle accountHandle,
210 Uri handle,
211 Bundle extras,
212 int videoState,
213 String telecomCallId,
214 boolean shouldShowIncomingCallUi,
215 ParcelFileDescriptor rttPipeFromInCall,
216 ParcelFileDescriptor rttPipeToInCall) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700217 mAccountHandle = accountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -0700218 mAddress = handle;
Ihab Awadfbb092f2014-06-03 18:40:45 -0700219 mExtras = extras;
Tyler Gunn12013ad2014-07-08 14:04:58 -0700220 mVideoState = videoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700221 mTelecomCallId = telecomCallId;
Tyler Gunnf5035432017-01-09 09:43:12 -0800222 mShouldShowIncomingCallUi = shouldShowIncomingCallUi;
Hall Liu95d55872017-01-25 17:12:49 -0800223 mRttPipeFromInCall = rttPipeFromInCall;
224 mRttPipeToInCall = rttPipeToInCall;
Ihab Awadfbb092f2014-06-03 18:40:45 -0700225 }
226
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700227 private ConnectionRequest(Parcel in) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700228 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Nancy Chenea38cca2014-09-05 16:38:49 -0700229 mAddress = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700230 mExtras = in.readParcelable(getClass().getClassLoader());
231 mVideoState = in.readInt();
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700232 mTelecomCallId = in.readString();
Tyler Gunnf5035432017-01-09 09:43:12 -0800233 mShouldShowIncomingCallUi = in.readInt() == 1;
Hall Liu95d55872017-01-25 17:12:49 -0800234 mRttPipeFromInCall = in.readParcelable(getClass().getClassLoader());
235 mRttPipeToInCall = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700236 }
237
Ihab Awadfbb092f2014-06-03 18:40:45 -0700238 /**
Ihab Awad9c3f1882014-06-30 21:17:13 -0700239 * The account which should be used to place the call.
Santos Cordon52d8a152014-06-17 19:08:45 -0700240 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700241 public PhoneAccountHandle getAccountHandle() { return mAccountHandle; }
Santos Cordon52d8a152014-06-17 19:08:45 -0700242
243 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700244 * The handle (e.g., phone number) to which the {@link Connection} is to connect.
245 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700246 public Uri getAddress() { return mAddress; }
Sailesh Nepal61203862014-07-11 14:50:13 -0700247
248 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700249 * Application-specific extra data. Used for passing back information from an incoming
250 * call {@code Intent}, and for any proprietary extensions arranged between a client
251 * and servant {@code ConnectionService} which agree on a vocabulary for such data.
252 */
253 public Bundle getExtras() { return mExtras; }
254
Tyler Gunn12013ad2014-07-08 14:04:58 -0700255 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700256 * Describes the video states supported by the client requesting the connection.
Yorke Lee32f24732015-05-12 16:18:03 -0700257 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
258 * {@link VideoProfile#STATE_BIDIRECTIONAL},
259 * {@link VideoProfile#STATE_TX_ENABLED},
260 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunn12013ad2014-07-08 14:04:58 -0700261 *
262 * @return The video state for the connection.
263 */
264 public int getVideoState() {
265 return mVideoState;
266 }
267
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700268 /**
269 * Returns the internal Telecom ID associated with the connection request.
270 *
271 * @return The Telecom ID.
272 * @hide
273 */
Hall Liub2306242019-11-15 17:13:05 -0800274 @SystemApi
275 @TestApi
276 public @Nullable String getTelecomCallId() {
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700277 return mTelecomCallId;
278 }
279
Tyler Gunnf5035432017-01-09 09:43:12 -0800280 /**
281 * For a self-managed {@link ConnectionService}, indicates for an incoming call whether the
282 * {@link ConnectionService} should show its own incoming call UI for an incoming call.
283 *
284 * @return {@code true} if the {@link ConnectionService} should show its own incoming call UI.
285 * When {@code false}, Telecom shows the incoming call UI for the call.
286 * @hide
287 */
288 public boolean shouldShowIncomingCallUi() {
289 return mShouldShowIncomingCallUi;
290 }
291
Hall Liu95d55872017-01-25 17:12:49 -0800292 /**
293 * Gets the {@link ParcelFileDescriptor} that is used to send RTT text from the connection
294 * service to the in-call UI. In order to obtain an
295 * {@link java.io.InputStream} from this {@link ParcelFileDescriptor}, use
296 * {@link android.os.ParcelFileDescriptor.AutoCloseInputStream}.
297 * Only text data encoded using UTF-8 should be written into this {@link ParcelFileDescriptor}.
298 * @return The {@link ParcelFileDescriptor} that should be used for communication.
299 * Do not un-hide -- only for use by Telephony
300 * @hide
301 */
302 public ParcelFileDescriptor getRttPipeToInCall() {
303 return mRttPipeToInCall;
304 }
305
306 /**
307 * Gets the {@link ParcelFileDescriptor} that is used to send RTT text from the in-call UI to
308 * the connection service. In order to obtain an
309 * {@link java.io.OutputStream} from this {@link ParcelFileDescriptor}, use
310 * {@link android.os.ParcelFileDescriptor.AutoCloseOutputStream}.
311 * The contents of this {@link ParcelFileDescriptor} will consist solely of text encoded in
312 * UTF-8.
313 * @return The {@link ParcelFileDescriptor} that should be used for communication
314 * Do not un-hide -- only for use by Telephony
315 * @hide
316 */
317 public ParcelFileDescriptor getRttPipeFromInCall() {
318 return mRttPipeFromInCall;
319 }
320
321 /**
322 * Gets the {@link android.telecom.Connection.RttTextStream} object that should be used to
323 * send and receive RTT text to/from the in-call app.
324 * @return An instance of {@link android.telecom.Connection.RttTextStream}, or {@code null}
325 * if this connection request is not requesting an RTT session upon connection establishment.
Hall Liu95d55872017-01-25 17:12:49 -0800326 */
327 public Connection.RttTextStream getRttTextStream() {
328 if (isRequestingRtt()) {
Hall Liue9041242018-02-09 16:40:03 -0800329 if (mRttTextStream == null) {
330 mRttTextStream = new Connection.RttTextStream(mRttPipeToInCall, mRttPipeFromInCall);
331 }
332 return mRttTextStream;
Hall Liu95d55872017-01-25 17:12:49 -0800333 } else {
334 return null;
335 }
336 }
337
338 /**
339 * Convenience method for determining whether the ConnectionRequest is requesting an RTT session
340 * @return {@code true} if RTT is requested, {@code false} otherwise.
Hall Liu95d55872017-01-25 17:12:49 -0800341 */
342 public boolean isRequestingRtt() {
343 return mRttPipeFromInCall != null && mRttPipeToInCall != null;
344 }
345
Evan Charltonbf11f982014-07-20 22:06:28 -0700346 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700347 public String toString() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700348 return String.format("ConnectionRequest %s %s",
Nancy Chenea38cca2014-09-05 16:38:49 -0700349 mAddress == null
Ihab Awad542e0ea2014-05-16 10:22:16 -0700350 ? Uri.EMPTY
Nancy Chenea38cca2014-09-05 16:38:49 -0700351 : Connection.toLogSafePhoneNumber(mAddress.toString()),
Shi Yuanjieafea7de2018-07-19 20:30:10 +0900352 bundleToString(mExtras));
353 }
354
355 private static String bundleToString(Bundle extras){
356 if (extras == null) {
357 return "";
358 }
359 StringBuilder sb = new StringBuilder();
360 sb.append("Bundle[");
361 for (String key : extras.keySet()) {
362 sb.append(key);
363 sb.append("=");
364 switch (key) {
365 case TelecomManager.EXTRA_INCOMING_CALL_ADDRESS:
366 case TelecomManager.EXTRA_UNKNOWN_CALL_HANDLE:
367 sb.append(Log.pii(extras.get(key)));
368 break;
369 default:
370 sb.append(extras.get(key));
371 break;
372 }
373 sb.append(", ");
374 }
375 sb.append("]");
376 return sb.toString();
Ihab Awad542e0ea2014-05-16 10:22:16 -0700377 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700378
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700379 public static final @android.annotation.NonNull Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () {
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700380 @Override
381 public ConnectionRequest createFromParcel(Parcel source) {
382 return new ConnectionRequest(source);
383 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700384
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700385 @Override
386 public ConnectionRequest[] newArray(int size) {
387 return new ConnectionRequest[size];
388 }
389 };
Ihab Awadfbb092f2014-06-03 18:40:45 -0700390
391 /**
392 * {@inheritDoc}
393 */
394 @Override
395 public int describeContents() {
396 return 0;
397 }
398
Ihab Awadfbb092f2014-06-03 18:40:45 -0700399 @Override
400 public void writeToParcel(Parcel destination, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700401 destination.writeParcelable(mAccountHandle, 0);
Nancy Chenea38cca2014-09-05 16:38:49 -0700402 destination.writeParcelable(mAddress, 0);
Ihab Awadfbb092f2014-06-03 18:40:45 -0700403 destination.writeParcelable(mExtras, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700404 destination.writeInt(mVideoState);
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700405 destination.writeString(mTelecomCallId);
Tyler Gunnf5035432017-01-09 09:43:12 -0800406 destination.writeInt(mShouldShowIncomingCallUi ? 1 : 0);
Hall Liu95d55872017-01-25 17:12:49 -0800407 destination.writeParcelable(mRttPipeFromInCall, 0);
408 destination.writeParcelable(mRttPipeToInCall, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700409 }
410}