blob: aba38fe8a376e7521025f84ae3c255126152f022 [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;
22import android.os.Parcelable;
Ihab Awad542e0ea2014-05-16 10:22:16 -070023
24/**
25 * Simple data container encapsulating a request to some entity to
26 * create a new {@link Connection}.
27 */
Ihab Awadfbb092f2014-06-03 18:40:45 -070028public final class ConnectionRequest implements Parcelable {
Ihab Awad542e0ea2014-05-16 10:22:16 -070029
30 // TODO: Token to limit recursive invocations
Evan Charlton8c8a0622014-07-20 12:31:00 -070031 private final PhoneAccountHandle mAccountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -070032 private final Uri mAddress;
Ihab Awad542e0ea2014-05-16 10:22:16 -070033 private final Bundle mExtras;
Tyler Gunn12013ad2014-07-08 14:04:58 -070034 private final int mVideoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -070035 private final String mTelecomCallId;
Ihab Awad542e0ea2014-05-16 10:22:16 -070036
Sailesh Nepal61203862014-07-11 14:50:13 -070037 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070038 * @param accountHandle The accountHandle which should be used to place the call.
Sailesh Nepal61203862014-07-11 14:50:13 -070039 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Sailesh Nepal61203862014-07-11 14:50:13 -070040 * @param extras Application-specific extra data.
Tyler Gunnbe74de02014-08-29 14:51:48 -070041 */
42 public ConnectionRequest(
43 PhoneAccountHandle accountHandle,
44 Uri handle,
Tyler Gunnbe74de02014-08-29 14:51:48 -070045 Bundle extras) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -070046 this(accountHandle, handle, extras, VideoProfile.STATE_AUDIO_ONLY, null);
Tyler Gunnbe74de02014-08-29 14:51:48 -070047 }
48
49 /**
50 * @param accountHandle The accountHandle which should be used to place the call.
51 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Tyler Gunnbe74de02014-08-29 14:51:48 -070052 * @param extras Application-specific extra data.
Sailesh Nepal61203862014-07-11 14:50:13 -070053 * @param videoState Determines the video state for the connection.
54 */
55 public ConnectionRequest(
Evan Charlton8c8a0622014-07-20 12:31:00 -070056 PhoneAccountHandle accountHandle,
Sailesh Nepal61203862014-07-11 14:50:13 -070057 Uri handle,
Sailesh Nepal61203862014-07-11 14:50:13 -070058 Bundle extras,
Tyler Gunn12013ad2014-07-08 14:04:58 -070059 int videoState) {
Tyler Gunnf0500bd2015-09-01 10:59:48 -070060 this(accountHandle, handle, extras, videoState, null);
61 }
62
63 /**
64 * @param accountHandle The accountHandle which should be used to place the call.
65 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
66 * @param extras Application-specific extra data.
67 * @param videoState Determines the video state for the connection.
68 * @param telecomCallId The telecom call ID.
69 * @hide
70 */
71 public ConnectionRequest(
72 PhoneAccountHandle accountHandle,
73 Uri handle,
74 Bundle extras,
75 int videoState,
76 String telecomCallId) {
Evan Charlton8c8a0622014-07-20 12:31:00 -070077 mAccountHandle = accountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -070078 mAddress = handle;
Ihab Awadfbb092f2014-06-03 18:40:45 -070079 mExtras = extras;
Tyler Gunn12013ad2014-07-08 14:04:58 -070080 mVideoState = videoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -070081 mTelecomCallId = telecomCallId;
Ihab Awadfbb092f2014-06-03 18:40:45 -070082 }
83
Sailesh Nepalc5b01572014-07-14 16:29:44 -070084 private ConnectionRequest(Parcel in) {
Evan Charlton8c8a0622014-07-20 12:31:00 -070085 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Nancy Chenea38cca2014-09-05 16:38:49 -070086 mAddress = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -070087 mExtras = in.readParcelable(getClass().getClassLoader());
88 mVideoState = in.readInt();
Tyler Gunnf0500bd2015-09-01 10:59:48 -070089 mTelecomCallId = in.readString();
Sailesh Nepalc5b01572014-07-14 16:29:44 -070090 }
91
Ihab Awadfbb092f2014-06-03 18:40:45 -070092 /**
Ihab Awad9c3f1882014-06-30 21:17:13 -070093 * The account which should be used to place the call.
Santos Cordon52d8a152014-06-17 19:08:45 -070094 */
Evan Charlton8c8a0622014-07-20 12:31:00 -070095 public PhoneAccountHandle getAccountHandle() { return mAccountHandle; }
Santos Cordon52d8a152014-06-17 19:08:45 -070096
97 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -070098 * The handle (e.g., phone number) to which the {@link Connection} is to connect.
99 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700100 public Uri getAddress() { return mAddress; }
Sailesh Nepal61203862014-07-11 14:50:13 -0700101
102 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700103 * Application-specific extra data. Used for passing back information from an incoming
104 * call {@code Intent}, and for any proprietary extensions arranged between a client
105 * and servant {@code ConnectionService} which agree on a vocabulary for such data.
106 */
107 public Bundle getExtras() { return mExtras; }
108
Tyler Gunn12013ad2014-07-08 14:04:58 -0700109 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700110 * Describes the video states supported by the client requesting the connection.
Yorke Lee32f24732015-05-12 16:18:03 -0700111 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
112 * {@link VideoProfile#STATE_BIDIRECTIONAL},
113 * {@link VideoProfile#STATE_TX_ENABLED},
114 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunn12013ad2014-07-08 14:04:58 -0700115 *
116 * @return The video state for the connection.
117 */
118 public int getVideoState() {
119 return mVideoState;
120 }
121
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700122 /**
123 * Returns the internal Telecom ID associated with the connection request.
124 *
125 * @return The Telecom ID.
126 * @hide
127 */
128 public String getTelecomCallId() {
129 return mTelecomCallId;
130 }
131
Evan Charltonbf11f982014-07-20 22:06:28 -0700132 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700133 public String toString() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 return String.format("ConnectionRequest %s %s",
Nancy Chenea38cca2014-09-05 16:38:49 -0700135 mAddress == null
Ihab Awad542e0ea2014-05-16 10:22:16 -0700136 ? Uri.EMPTY
Nancy Chenea38cca2014-09-05 16:38:49 -0700137 : Connection.toLogSafePhoneNumber(mAddress.toString()),
Ihab Awad542e0ea2014-05-16 10:22:16 -0700138 mExtras == null ? "" : mExtras);
139 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700140
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700141 public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () {
142 @Override
143 public ConnectionRequest createFromParcel(Parcel source) {
144 return new ConnectionRequest(source);
145 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700146
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700147 @Override
148 public ConnectionRequest[] newArray(int size) {
149 return new ConnectionRequest[size];
150 }
151 };
Ihab Awadfbb092f2014-06-03 18:40:45 -0700152
153 /**
154 * {@inheritDoc}
155 */
156 @Override
157 public int describeContents() {
158 return 0;
159 }
160
Ihab Awadfbb092f2014-06-03 18:40:45 -0700161 @Override
162 public void writeToParcel(Parcel destination, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700163 destination.writeParcelable(mAccountHandle, 0);
Nancy Chenea38cca2014-09-05 16:38:49 -0700164 destination.writeParcelable(mAddress, 0);
Ihab Awadfbb092f2014-06-03 18:40:45 -0700165 destination.writeParcelable(mExtras, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700166 destination.writeInt(mVideoState);
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700167 destination.writeString(mTelecomCallId);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700168 }
169}