blob: 23434624bf873af1b8826346ddc900bc39c661e3 [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;
Tyler Gunnf5035432017-01-09 09:43:12 -080036 private final boolean mShouldShowIncomingCallUi;
Ihab Awad542e0ea2014-05-16 10:22:16 -070037
Sailesh Nepal61203862014-07-11 14:50:13 -070038 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070039 * @param accountHandle The accountHandle which should be used to place the call.
Sailesh Nepal61203862014-07-11 14:50:13 -070040 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Sailesh Nepal61203862014-07-11 14:50:13 -070041 * @param extras Application-specific extra data.
Tyler Gunnbe74de02014-08-29 14:51:48 -070042 */
43 public ConnectionRequest(
44 PhoneAccountHandle accountHandle,
45 Uri handle,
Tyler Gunnbe74de02014-08-29 14:51:48 -070046 Bundle extras) {
Tyler Gunnf5035432017-01-09 09:43:12 -080047 this(accountHandle, handle, extras, VideoProfile.STATE_AUDIO_ONLY, null, false);
Tyler Gunnbe74de02014-08-29 14:51:48 -070048 }
49
50 /**
51 * @param accountHandle The accountHandle which should be used to place the call.
52 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Tyler Gunnbe74de02014-08-29 14:51:48 -070053 * @param extras Application-specific extra data.
Sailesh Nepal61203862014-07-11 14:50:13 -070054 * @param videoState Determines the video state for the connection.
55 */
56 public ConnectionRequest(
Evan Charlton8c8a0622014-07-20 12:31:00 -070057 PhoneAccountHandle accountHandle,
Sailesh Nepal61203862014-07-11 14:50:13 -070058 Uri handle,
Sailesh Nepal61203862014-07-11 14:50:13 -070059 Bundle extras,
Tyler Gunn12013ad2014-07-08 14:04:58 -070060 int videoState) {
Tyler Gunnf5035432017-01-09 09:43:12 -080061 this(accountHandle, handle, extras, videoState, null, false);
Tyler Gunnf0500bd2015-09-01 10:59:48 -070062 }
63
64 /**
65 * @param accountHandle The accountHandle which should be used to place the call.
66 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
67 * @param extras Application-specific extra data.
68 * @param videoState Determines the video state for the connection.
69 * @param telecomCallId The telecom call ID.
Tyler Gunnf5035432017-01-09 09:43:12 -080070 * @param shouldShowIncomingCallUi For a self-managed {@link ConnectionService}, will be
71 * {@code true} if the {@link ConnectionService} should show its
72 * own incoming call UI for an incoming call. When
73 * {@code false}, Telecom shows the incoming call UI.
Tyler Gunnf0500bd2015-09-01 10:59:48 -070074 * @hide
75 */
76 public ConnectionRequest(
77 PhoneAccountHandle accountHandle,
78 Uri handle,
79 Bundle extras,
80 int videoState,
Tyler Gunnf5035432017-01-09 09:43:12 -080081 String telecomCallId,
82 boolean shouldShowIncomingCallUi) {
Evan Charlton8c8a0622014-07-20 12:31:00 -070083 mAccountHandle = accountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -070084 mAddress = handle;
Ihab Awadfbb092f2014-06-03 18:40:45 -070085 mExtras = extras;
Tyler Gunn12013ad2014-07-08 14:04:58 -070086 mVideoState = videoState;
Tyler Gunnf0500bd2015-09-01 10:59:48 -070087 mTelecomCallId = telecomCallId;
Tyler Gunnf5035432017-01-09 09:43:12 -080088 mShouldShowIncomingCallUi = shouldShowIncomingCallUi;
Ihab Awadfbb092f2014-06-03 18:40:45 -070089 }
90
Sailesh Nepalc5b01572014-07-14 16:29:44 -070091 private ConnectionRequest(Parcel in) {
Evan Charlton8c8a0622014-07-20 12:31:00 -070092 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Nancy Chenea38cca2014-09-05 16:38:49 -070093 mAddress = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -070094 mExtras = in.readParcelable(getClass().getClassLoader());
95 mVideoState = in.readInt();
Tyler Gunnf0500bd2015-09-01 10:59:48 -070096 mTelecomCallId = in.readString();
Tyler Gunnf5035432017-01-09 09:43:12 -080097 mShouldShowIncomingCallUi = in.readInt() == 1;
Sailesh Nepalc5b01572014-07-14 16:29:44 -070098 }
99
Ihab Awadfbb092f2014-06-03 18:40:45 -0700100 /**
Ihab Awad9c3f1882014-06-30 21:17:13 -0700101 * The account which should be used to place the call.
Santos Cordon52d8a152014-06-17 19:08:45 -0700102 */
Evan Charlton8c8a0622014-07-20 12:31:00 -0700103 public PhoneAccountHandle getAccountHandle() { return mAccountHandle; }
Santos Cordon52d8a152014-06-17 19:08:45 -0700104
105 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700106 * The handle (e.g., phone number) to which the {@link Connection} is to connect.
107 */
Nancy Chenea38cca2014-09-05 16:38:49 -0700108 public Uri getAddress() { return mAddress; }
Sailesh Nepal61203862014-07-11 14:50:13 -0700109
110 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -0700111 * Application-specific extra data. Used for passing back information from an incoming
112 * call {@code Intent}, and for any proprietary extensions arranged between a client
113 * and servant {@code ConnectionService} which agree on a vocabulary for such data.
114 */
115 public Bundle getExtras() { return mExtras; }
116
Tyler Gunn12013ad2014-07-08 14:04:58 -0700117 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700118 * Describes the video states supported by the client requesting the connection.
Yorke Lee32f24732015-05-12 16:18:03 -0700119 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
120 * {@link VideoProfile#STATE_BIDIRECTIONAL},
121 * {@link VideoProfile#STATE_TX_ENABLED},
122 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunn12013ad2014-07-08 14:04:58 -0700123 *
124 * @return The video state for the connection.
125 */
126 public int getVideoState() {
127 return mVideoState;
128 }
129
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700130 /**
131 * Returns the internal Telecom ID associated with the connection request.
132 *
133 * @return The Telecom ID.
134 * @hide
135 */
136 public String getTelecomCallId() {
137 return mTelecomCallId;
138 }
139
Tyler Gunnf5035432017-01-09 09:43:12 -0800140 /**
141 * For a self-managed {@link ConnectionService}, indicates for an incoming call whether the
142 * {@link ConnectionService} should show its own incoming call UI for an incoming call.
143 *
144 * @return {@code true} if the {@link ConnectionService} should show its own incoming call UI.
145 * When {@code false}, Telecom shows the incoming call UI for the call.
146 * @hide
147 */
148 public boolean shouldShowIncomingCallUi() {
149 return mShouldShowIncomingCallUi;
150 }
151
Evan Charltonbf11f982014-07-20 22:06:28 -0700152 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700153 public String toString() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700154 return String.format("ConnectionRequest %s %s",
Nancy Chenea38cca2014-09-05 16:38:49 -0700155 mAddress == null
Ihab Awad542e0ea2014-05-16 10:22:16 -0700156 ? Uri.EMPTY
Nancy Chenea38cca2014-09-05 16:38:49 -0700157 : Connection.toLogSafePhoneNumber(mAddress.toString()),
Ihab Awad542e0ea2014-05-16 10:22:16 -0700158 mExtras == null ? "" : mExtras);
159 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700160
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700161 public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () {
162 @Override
163 public ConnectionRequest createFromParcel(Parcel source) {
164 return new ConnectionRequest(source);
165 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700166
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700167 @Override
168 public ConnectionRequest[] newArray(int size) {
169 return new ConnectionRequest[size];
170 }
171 };
Ihab Awadfbb092f2014-06-03 18:40:45 -0700172
173 /**
174 * {@inheritDoc}
175 */
176 @Override
177 public int describeContents() {
178 return 0;
179 }
180
Ihab Awadfbb092f2014-06-03 18:40:45 -0700181 @Override
182 public void writeToParcel(Parcel destination, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700183 destination.writeParcelable(mAccountHandle, 0);
Nancy Chenea38cca2014-09-05 16:38:49 -0700184 destination.writeParcelable(mAddress, 0);
Ihab Awadfbb092f2014-06-03 18:40:45 -0700185 destination.writeParcelable(mExtras, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700186 destination.writeInt(mVideoState);
Tyler Gunnf0500bd2015-09-01 10:59:48 -0700187 destination.writeString(mTelecomCallId);
Tyler Gunnf5035432017-01-09 09:43:12 -0800188 destination.writeInt(mShouldShowIncomingCallUi ? 1 : 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700189 }
190}