blob: 975df5d40aa6ad28274c149569b590da23f7e9f5 [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;
Ihab Awad542e0ea2014-05-16 10:22:16 -070035
Sailesh Nepal61203862014-07-11 14:50:13 -070036 /**
Evan Charlton8c8a0622014-07-20 12:31:00 -070037 * @param accountHandle The accountHandle which should be used to place the call.
Sailesh Nepal61203862014-07-11 14:50:13 -070038 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Sailesh Nepal61203862014-07-11 14:50:13 -070039 * @param extras Application-specific extra data.
Tyler Gunnbe74de02014-08-29 14:51:48 -070040 */
41 public ConnectionRequest(
42 PhoneAccountHandle accountHandle,
43 Uri handle,
Tyler Gunnbe74de02014-08-29 14:51:48 -070044 Bundle extras) {
Nancy Chenea38cca2014-09-05 16:38:49 -070045 this(accountHandle, handle, extras, VideoProfile.VideoState.AUDIO_ONLY);
Tyler Gunnbe74de02014-08-29 14:51:48 -070046 }
47
48 /**
49 * @param accountHandle The accountHandle which should be used to place the call.
50 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect.
Tyler Gunnbe74de02014-08-29 14:51:48 -070051 * @param extras Application-specific extra data.
Sailesh Nepal61203862014-07-11 14:50:13 -070052 * @param videoState Determines the video state for the connection.
53 */
54 public ConnectionRequest(
Evan Charlton8c8a0622014-07-20 12:31:00 -070055 PhoneAccountHandle accountHandle,
Sailesh Nepal61203862014-07-11 14:50:13 -070056 Uri handle,
Sailesh Nepal61203862014-07-11 14:50:13 -070057 Bundle extras,
Tyler Gunn12013ad2014-07-08 14:04:58 -070058 int videoState) {
Evan Charlton8c8a0622014-07-20 12:31:00 -070059 mAccountHandle = accountHandle;
Nancy Chenea38cca2014-09-05 16:38:49 -070060 mAddress = handle;
Ihab Awadfbb092f2014-06-03 18:40:45 -070061 mExtras = extras;
Tyler Gunn12013ad2014-07-08 14:04:58 -070062 mVideoState = videoState;
Ihab Awadfbb092f2014-06-03 18:40:45 -070063 }
64
Sailesh Nepalc5b01572014-07-14 16:29:44 -070065 private ConnectionRequest(Parcel in) {
Evan Charlton8c8a0622014-07-20 12:31:00 -070066 mAccountHandle = in.readParcelable(getClass().getClassLoader());
Nancy Chenea38cca2014-09-05 16:38:49 -070067 mAddress = in.readParcelable(getClass().getClassLoader());
Sailesh Nepalc5b01572014-07-14 16:29:44 -070068 mExtras = in.readParcelable(getClass().getClassLoader());
69 mVideoState = in.readInt();
70 }
71
Ihab Awadfbb092f2014-06-03 18:40:45 -070072 /**
Ihab Awad9c3f1882014-06-30 21:17:13 -070073 * The account which should be used to place the call.
Santos Cordon52d8a152014-06-17 19:08:45 -070074 */
Evan Charlton8c8a0622014-07-20 12:31:00 -070075 public PhoneAccountHandle getAccountHandle() { return mAccountHandle; }
Santos Cordon52d8a152014-06-17 19:08:45 -070076
77 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -070078 * The handle (e.g., phone number) to which the {@link Connection} is to connect.
79 */
Nancy Chenea38cca2014-09-05 16:38:49 -070080 public Uri getAddress() { return mAddress; }
Sailesh Nepal61203862014-07-11 14:50:13 -070081
82 /**
Ihab Awad542e0ea2014-05-16 10:22:16 -070083 * Application-specific extra data. Used for passing back information from an incoming
84 * call {@code Intent}, and for any proprietary extensions arranged between a client
85 * and servant {@code ConnectionService} which agree on a vocabulary for such data.
86 */
87 public Bundle getExtras() { return mExtras; }
88
Tyler Gunn12013ad2014-07-08 14:04:58 -070089 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -070090 * Describes the video states supported by the client requesting the connection.
Yorke Lee32f24732015-05-12 16:18:03 -070091 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
92 * {@link VideoProfile#STATE_BIDIRECTIONAL},
93 * {@link VideoProfile#STATE_TX_ENABLED},
94 * {@link VideoProfile#STATE_RX_ENABLED}.
Tyler Gunn12013ad2014-07-08 14:04:58 -070095 *
96 * @return The video state for the connection.
97 */
98 public int getVideoState() {
99 return mVideoState;
100 }
101
Evan Charltonbf11f982014-07-20 22:06:28 -0700102 @Override
Ihab Awad542e0ea2014-05-16 10:22:16 -0700103 public String toString() {
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700104 return String.format("ConnectionRequest %s %s",
Nancy Chenea38cca2014-09-05 16:38:49 -0700105 mAddress == null
Ihab Awad542e0ea2014-05-16 10:22:16 -0700106 ? Uri.EMPTY
Nancy Chenea38cca2014-09-05 16:38:49 -0700107 : Connection.toLogSafePhoneNumber(mAddress.toString()),
Ihab Awad542e0ea2014-05-16 10:22:16 -0700108 mExtras == null ? "" : mExtras);
109 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700110
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700111 public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () {
112 @Override
113 public ConnectionRequest createFromParcel(Parcel source) {
114 return new ConnectionRequest(source);
115 }
Ihab Awadfbb092f2014-06-03 18:40:45 -0700116
Sailesh Nepalc5b01572014-07-14 16:29:44 -0700117 @Override
118 public ConnectionRequest[] newArray(int size) {
119 return new ConnectionRequest[size];
120 }
121 };
Ihab Awadfbb092f2014-06-03 18:40:45 -0700122
123 /**
124 * {@inheritDoc}
125 */
126 @Override
127 public int describeContents() {
128 return 0;
129 }
130
Ihab Awadfbb092f2014-06-03 18:40:45 -0700131 @Override
132 public void writeToParcel(Parcel destination, int flags) {
Evan Charlton8c8a0622014-07-20 12:31:00 -0700133 destination.writeParcelable(mAccountHandle, 0);
Nancy Chenea38cca2014-09-05 16:38:49 -0700134 destination.writeParcelable(mAddress, 0);
Ihab Awadfbb092f2014-06-03 18:40:45 -0700135 destination.writeParcelable(mExtras, 0);
Tyler Gunn12013ad2014-07-08 14:04:58 -0700136 destination.writeInt(mVideoState);
137 }
138}