blob: e169e5f80741c3b55677512dc57027d98b6b748c [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 Liuffa4a812017-03-02 16:11:00 -080019import android.annotation.TestApi;
Ihab Awad542e0ea2014-05-16 10:22:16 -070020import android.net.Uri;
Sailesh Nepal61203862014-07-11 14:50:13 -070021import android.os.Bundle;
Ihab Awadfbb092f2014-06-03 18:40:45 -070022import android.os.Parcel;
Hall Liu95d55872017-01-25 17:12:49 -080023import android.os.ParcelFileDescriptor;
Ihab Awadfbb092f2014-06-03 18:40:45 -070024import android.os.Parcelable;
Ihab Awad542e0ea2014-05-16 10:22:16 -070025
26/**
27 * Simple data container encapsulating a request to some entity to
28 * create a new {@link Connection}.
29 */
Ihab Awadfbb092f2014-06-03 18:40:45 -070030public final class ConnectionRequest implements Parcelable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070031
Hall Liu95d55872017-01-25 17:12:49 -080032 /**
33 * Builder class for {@link ConnectionRequest}
34 * @hide
35 */
36 public static final class Builder {
37 private PhoneAccountHandle mAccountHandle;
38 private Uri mAddress;
39 private Bundle mExtras;
40 private int mVideoState = VideoProfile.STATE_AUDIO_ONLY;
41 private String mTelecomCallId;
42 private boolean mShouldShowIncomingCallUi = false;
43 private ParcelFileDescriptor mRttPipeToInCall;
44 private ParcelFileDescriptor mRttPipeFromInCall;
45
46 public Builder() { }
47
48 /**
49 * Sets the phone account handle for the resulting {@link ConnectionRequest}
50 * @param accountHandle The accountHandle which should be used to place the call.
51 */
52 public Builder setAccountHandle(PhoneAccountHandle accountHandle) {
53 this.mAccountHandle = accountHandle;
54 return this;
55 }
56
57 /**
58 * Sets the address for the resulting {@link ConnectionRequest}
59 * @param address The address(e.g., phone number) to which the {@link Connection} is to
60 * connect.
61 */
62 public Builder setAddress(Uri address) {
63 this.mAddress = address;
64 return this;
65 }
66
67 /**
68 * Sets the extras bundle for the resulting {@link ConnectionRequest}
69 * @param extras Application-specific extra data.
70 */
71 public Builder setExtras(Bundle extras) {
72 this.mExtras = extras;
73 return this;
74 }
75
76 /**
77 * Sets the video state for the resulting {@link ConnectionRequest}
78 * @param videoState Determines the video state for the connection.
79 */
80 public Builder setVideoState(int videoState) {
81 this.mVideoState = videoState;
82 return this;
83 }
84
85 /**
86 * Sets the Telecom call ID for the resulting {@link ConnectionRequest}
87 * @param telecomCallId The telecom call ID.
88 */
89 public Builder setTelecomCallId(String telecomCallId) {
90 this.mTelecomCallId = telecomCallId;
91 return this;
92 }
93
94 /**
95 * Sets shouldShowIncomingUi for the resulting {@link ConnectionRequest}
96 * @param shouldShowIncomingCallUi For a self-managed {@link ConnectionService}, will be
97 * {@code true} if the {@link ConnectionService} should show
98 * its own incoming call UI for an incoming call. When
99 * {@code false}, Telecom shows the incoming call UI.
100 */
101 public Builder setShouldShowIncomingCallUi(boolean shouldShowIncomingCallUi) {
102 this.mShouldShowIncomingCallUi = shouldShowIncomingCallUi;
103 return this;
104 }
105
106 /**
107 * Sets the RTT pipe for transferring text into the {@link ConnectionService} for the
108 * resulting {@link ConnectionRequest}
109 * @param rttPipeFromInCall The data pipe to read from.
110 */
111 public Builder setRttPipeFromInCall(ParcelFileDescriptor rttPipeFromInCall) {
112 this.mRttPipeFromInCall = rttPipeFromInCall;
113 return this;
114 }
115
116 /**
117 * Sets the RTT pipe for transferring text out of {@link ConnectionService} for the
118 * resulting {@link ConnectionRequest}
119 * @param rttPipeToInCall The data pipe to write to.
120 */
121 public Builder setRttPipeToInCall(ParcelFileDescriptor rttPipeToInCall) {
122 this.mRttPipeToInCall = rttPipeToInCall;
123 return this;
124 }
125
126 public ConnectionRequest build() {
127 return new ConnectionRequest(
128 mAccountHandle,
129 mAddress,
130 mExtras,
131 mVideoState,
132 mTelecomCallId,
133 mShouldShowIncomingCallUi,
134 mRttPipeFromInCall,
135 mRttPipeToInCall);
136 }
137 }
138
Evan Charlton8c8a0622014-07-20 12:31:00 -0700139 private final PhoneAccountHandle mAccountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -0700140 private final Uri mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700141 private final Bundle mExtras;
Tyler Gunn12013ad2014-07-08 14:04:58 -0700142 private final int mVideoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700143 private final String mTelecomCallId;
Tyler Gunnf5035432017-01-09 09:43:12 -0800144 private final boolean mShouldShowIncomingCallUi;
Hall Liu95d55872017-01-25 17:12:49 -0800145 private final ParcelFileDescriptor mRttPipeToInCall;
146 private final ParcelFileDescriptor mRttPipeFromInCall;
Ihab Awad542e0ea2014-05-16 10:22:16 -0700147
Sailesh Nepal61203862014-07-11 14:50:13 -0700148 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -0700149 * @param accountHandle The accountHandle which should be used to place the call.
Sailesh Nepal61203862014-07-11 14:50:13 -0700150 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Sailesh Nepal61203862014-07-11 14:50:13 -0700151 * @param extras Application-specific extra data.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700152 */
153 public ConnectionRequest(
154 PhoneAccountHandle accountHandle,
155 Uri handle,
Tyler Gunnbe74de02014-08-29 14:51:48 -0700156 Bundle extras) {
Hall Liu95d55872017-01-25 17:12:49 -0800157 this(accountHandle, handle, extras, VideoProfile.STATE_AUDIO_ONLY, null, false, null, null);
Tyler Gunnbe74de02014-08-29 14:51:48 -0700158 }
159
160 /**
161 * @param accountHandle The accountHandle which should be used to place the call.
162 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Tyler Gunnbe74de02014-08-29 14:51:48 -0700163 * @param extras Application-specific extra data.
Sailesh Nepal61203862014-07-11 14:50:13 -0700164 * @param videoState Determines the video state for the connection.
165 */
166 public ConnectionRequest(
Evan Charlton8c8a0622014-07-20 12:31:00 -0700167 PhoneAccountHandle accountHandle,
Sailesh Nepal61203862014-07-11 14:50:13 -0700168 Uri handle,
Sailesh Nepal61203862014-07-11 14:50:13 -0700169 Bundle extras,
Tyler Gunn12013ad2014-07-08 14:04:58 -0700170 int videoState) {
Hall Liu95d55872017-01-25 17:12:49 -0800171 this(accountHandle, handle, extras, videoState, null, false, null, null);
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700172 }
173
174 /**
175 * @param accountHandle The accountHandle which should be used to place the call.
176 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
177 * @param extras Application-specific extra data.
178 * @param videoState Determines the video state for the connection.
179 * @param telecomCallId The telecom call ID.
Tyler Gunnf5035432017-01-09 09:43:12 -0800180 * @param shouldShowIncomingCallUi For a self-managed {@link ConnectionService}, will be
181 * {@code true} if the {@link ConnectionService} should show its
182 * own incoming call UI for an incoming call. When
183 * {@code false}, Telecom shows the incoming call UI.
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700184 * @hide
185 */
186 public ConnectionRequest(
187 PhoneAccountHandle accountHandle,
188 Uri handle,
189 Bundle extras,
190 int videoState,
Tyler Gunnf5035432017-01-09 09:43:12 -0800191 String telecomCallId,
192 boolean shouldShowIncomingCallUi) {
Hall Liu95d55872017-01-25 17:12:49 -0800193 this(accountHandle, handle, extras, videoState, telecomCallId,
194 shouldShowIncomingCallUi, null, null);
195 }
196
197 private ConnectionRequest(
198 PhoneAccountHandle accountHandle,
199 Uri handle,
200 Bundle extras,
201 int videoState,
202 String telecomCallId,
203 boolean shouldShowIncomingCallUi,
204 ParcelFileDescriptor rttPipeFromInCall,
205 ParcelFileDescriptor rttPipeToInCall) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700206 mAccountHandle = accountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -0700207 mAddress = handle;
Ihab Awadfbb092f2014-06-03 18:40:45 -0700208 mExtras = extras;
Tyler Gunn12013ad2014-07-08 14:04:58 -0700209 mVideoState = videoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700210 mTelecomCallId = telecomCallId;
Tyler Gunnf5035432017-01-09 09:43:12 -0800211 mShouldShowIncomingCallUi = shouldShowIncomingCallUi;
Hall Liu95d55872017-01-25 17:12:49 -0800212 mRttPipeFromInCall = rttPipeFromInCall;
213 mRttPipeToInCall = rttPipeToInCall;
Ihab Awadfbb092f2014-06-03 18:40:45 -0700214 }
215
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700216 private ConnectionRequest(Parcel in) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700217 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Nancy Chenea38cca2014-09-05 16:38:49 -0700218 mAddress = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700219 mExtras = in.readParcelable(getClass().getClassLoader());
220 mVideoState = in.readInt();
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700221 mTelecomCallId = in.readString();
Tyler Gunnf5035432017-01-09 09:43:12 -0800222 mShouldShowIncomingCallUi = in.readInt() == 1;
Hall Liu95d55872017-01-25 17:12:49 -0800223 mRttPipeFromInCall = in.readParcelable(getClass().getClassLoader());
224 mRttPipeToInCall = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700225 }
226
Ihab Awadfbb092f2014-06-03 18:40:45 -0700227 /**
Ihab Awad9c3f1882014-06-30 21:17:13 -0700228 * The account which should be used to place the call.
Santos Cordon52d8a152014-06-17 19:08:45 -0700229 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700230 public PhoneAccountHandle getAccountHandle() { return mAccountHandle; }
Santos Cordon52d8a152014-06-17 19:08:45 -0700231
232 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700233 * The handle (e.g., phone number) to which the {@link Connection} is to connect.
234 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700235 public Uri getAddress() { return mAddress; }
Sailesh Nepal61203862014-07-11 14:50:13 -0700236
237 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700238 * Application-specific extra data. Used for passing back information from an incoming
239 * call {@code Intent}, and for any proprietary extensions arranged between a client
240 * and servant {@code ConnectionService} which agree on a vocabulary for such data.
241 */
242 public Bundle getExtras() { return mExtras; }
243
Tyler Gunn12013ad2014-07-08 14:04:58 -0700244 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700245 * Describes the video states supported by the client requesting the connection.
Yorke Lee32f24732015-05-12 16:18:03 -0700246 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
247 * {@link VideoProfile#STATE_BIDIRECTIONAL},
248 * {@link VideoProfile#STATE_TX_ENABLED},
249 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunn12013ad2014-07-08 14:04:58 -0700250 *
251 * @return The video state for the connection.
252 */
253 public int getVideoState() {
254 return mVideoState;
255 }
256
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700257 /**
258 * Returns the internal Telecom ID associated with the connection request.
259 *
260 * @return The Telecom ID.
261 * @hide
262 */
263 public String getTelecomCallId() {
264 return mTelecomCallId;
265 }
266
Tyler Gunnf5035432017-01-09 09:43:12 -0800267 /**
268 * For a self-managed {@link ConnectionService}, indicates for an incoming call whether the
269 * {@link ConnectionService} should show its own incoming call UI for an incoming call.
270 *
271 * @return {@code true} if the {@link ConnectionService} should show its own incoming call UI.
272 * When {@code false}, Telecom shows the incoming call UI for the call.
273 * @hide
274 */
275 public boolean shouldShowIncomingCallUi() {
276 return mShouldShowIncomingCallUi;
277 }
278
Hall Liu95d55872017-01-25 17:12:49 -0800279 /**
280 * Gets the {@link ParcelFileDescriptor} that is used to send RTT text from the connection
281 * service to the in-call UI. In order to obtain an
282 * {@link java.io.InputStream} from this {@link ParcelFileDescriptor}, use
283 * {@link android.os.ParcelFileDescriptor.AutoCloseInputStream}.
284 * Only text data encoded using UTF-8 should be written into this {@link ParcelFileDescriptor}.
285 * @return The {@link ParcelFileDescriptor} that should be used for communication.
286 * Do not un-hide -- only for use by Telephony
287 * @hide
288 */
289 public ParcelFileDescriptor getRttPipeToInCall() {
290 return mRttPipeToInCall;
291 }
292
293 /**
294 * Gets the {@link ParcelFileDescriptor} that is used to send RTT text from the in-call UI to
295 * the connection service. In order to obtain an
296 * {@link java.io.OutputStream} from this {@link ParcelFileDescriptor}, use
297 * {@link android.os.ParcelFileDescriptor.AutoCloseOutputStream}.
298 * The contents of this {@link ParcelFileDescriptor} will consist solely of text encoded in
299 * UTF-8.
300 * @return The {@link ParcelFileDescriptor} that should be used for communication
301 * Do not un-hide -- only for use by Telephony
302 * @hide
303 */
304 public ParcelFileDescriptor getRttPipeFromInCall() {
305 return mRttPipeFromInCall;
306 }
307
308 /**
309 * Gets the {@link android.telecom.Connection.RttTextStream} object that should be used to
310 * send and receive RTT text to/from the in-call app.
311 * @return An instance of {@link android.telecom.Connection.RttTextStream}, or {@code null}
312 * if this connection request is not requesting an RTT session upon connection establishment.
313 * @hide
314 */
Hall Liuffa4a812017-03-02 16:11:00 -0800315 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800316 public Connection.RttTextStream getRttTextStream() {
317 if (isRequestingRtt()) {
318 return new Connection.RttTextStream(mRttPipeToInCall, mRttPipeFromInCall);
319 } else {
320 return null;
321 }
322 }
323
324 /**
325 * Convenience method for determining whether the ConnectionRequest is requesting an RTT session
326 * @return {@code true} if RTT is requested, {@code false} otherwise.
327 * @hide
328 */
Hall Liuffa4a812017-03-02 16:11:00 -0800329 @TestApi
Hall Liu95d55872017-01-25 17:12:49 -0800330 public boolean isRequestingRtt() {
331 return mRttPipeFromInCall != null && mRttPipeToInCall != null;
332 }
333
Evan Charltonbf11f982014-07-20 22:06:28 -0700334 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700335 public String toString() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700336 return String.format("ConnectionRequest %s %s",
Nancy Chenea38cca2014-09-05 16:38:49 -0700337 mAddress == null
Ihab Awad542e0ea2014-05-16 10:22:16 -0700338 ? Uri.EMPTY
Nancy Chenea38cca2014-09-05 16:38:49 -0700339 : Connection.toLogSafePhoneNumber(mAddress.toString()),
Ihab Awad542e0ea2014-05-16 10:22:16 -0700340 mExtras == null ? "" : mExtras);
341 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700342
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700343 public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () {
344 @Override
345 public ConnectionRequest createFromParcel(Parcel source) {
346 return new ConnectionRequest(source);
347 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700348
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700349 @Override
350 public ConnectionRequest[] newArray(int size) {
351 return new ConnectionRequest[size];
352 }
353 };
Ihab Awadfbb092f2014-06-03 18:40:45 -0700354
355 /**
356 * {@inheritDoc}
357 */
358 @Override
359 public int describeContents() {
360 return 0;
361 }
362
Ihab Awadfbb092f2014-06-03 18:40:45 -0700363 @Override
364 public void writeToParcel(Parcel destination, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700365 destination.writeParcelable(mAccountHandle, 0);
Nancy Chenea38cca2014-09-05 16:38:49 -0700366 destination.writeParcelable(mAddress, 0);
Ihab Awadfbb092f2014-06-03 18:40:45 -0700367 destination.writeParcelable(mExtras, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700368 destination.writeInt(mVideoState);
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700369 destination.writeString(mTelecomCallId);
Tyler Gunnf5035432017-01-09 09:43:12 -0800370 destination.writeInt(mShouldShowIncomingCallUi ? 1 : 0);
Hall Liu95d55872017-01-25 17:12:49 -0800371 destination.writeParcelable(mRttPipeFromInCall, 0);
372 destination.writeParcelable(mRttPipeToInCall, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700373 }
374}