blob: 2f1505cd9e4e0db0cd8c55601b68d2821b2bfed2 [file] [log] [blame]
Tyler Gunn3bffcf72014-10-28 13:51:27 -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
17package android.telecom;
18
19import android.net.Uri;
20import android.os.Parcel;
21import android.os.Parcelable;
Youming Yed6de26e2019-01-30 11:20:35 -080022import android.text.TextUtils;
23
24import com.android.internal.annotations.VisibleForTesting;
25import com.android.internal.telephony.PhoneConstants;
Tyler Gunn3bffcf72014-10-28 13:51:27 -070026
27/**
28 * Parcelable representation of a participant's state in a conference call.
29 * @hide
30 */
31public class ConferenceParticipant implements Parcelable {
32
33 /**
Youming Yed6de26e2019-01-30 11:20:35 -080034 * RFC5767 states that a SIP URI with an unknown number should use an address of
35 * {@code anonymous@anonymous.invalid}. E.g. the host name is anonymous.invalid.
36 */
37 private static final String ANONYMOUS_INVALID_HOST = "anonymous.invalid";
38 /**
Tyler Gunn3bffcf72014-10-28 13:51:27 -070039 * The conference participant's handle (e.g., phone number).
40 */
41 private final Uri mHandle;
42
43 /**
44 * The display name for the participant.
45 */
46 private final String mDisplayName;
47
48 /**
49 * The endpoint Uri which uniquely identifies this conference participant. E.g. for an IMS
50 * conference call, this is the endpoint URI for the participant on the IMS conference server.
51 */
52 private final Uri mEndpoint;
53
54 /**
55 * The state of the participant in the conference.
56 *
57 * @see android.telecom.Connection
58 */
59 private final int mState;
60
61 /**
Youming Yed6de26e2019-01-30 11:20:35 -080062 * The connect time of the participant.
63 */
64 private long mConnectTime;
65
66 /**
67 * The connect elapsed time of the participant.
68 */
69 private long mConnectElapsedTime;
70
71 /**
Tyler Gunn3bffcf72014-10-28 13:51:27 -070072 * Creates an instance of {@code ConferenceParticipant}.
73 *
74 * @param handle The conference participant's handle (e.g., phone number).
75 * @param displayName The display name for the participant.
76 * @param endpoint The enpoint Uri which uniquely identifies this conference participant.
77 * @param state The state of the participant in the conference.
78 */
79 public ConferenceParticipant(Uri handle, String displayName, Uri endpoint, int state) {
80 mHandle = handle;
81 mDisplayName = displayName;
82 mEndpoint = endpoint;
83 mState = state;
84 }
85
86 /**
87 * Responsible for creating {@code ConferenceParticipant} objects for deserialized Parcels.
88 */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070089 public static final @android.annotation.NonNull Parcelable.Creator<ConferenceParticipant> CREATOR =
Tyler Gunn3bffcf72014-10-28 13:51:27 -070090 new Parcelable.Creator<ConferenceParticipant>() {
91
92 @Override
93 public ConferenceParticipant createFromParcel(Parcel source) {
94 ClassLoader classLoader = ParcelableCall.class.getClassLoader();
95 Uri handle = source.readParcelable(classLoader);
96 String displayName = source.readString();
97 Uri endpoint = source.readParcelable(classLoader);
98 int state = source.readInt();
99 return new ConferenceParticipant(handle, displayName, endpoint, state);
100 }
101
102 @Override
103 public ConferenceParticipant[] newArray(int size) {
104 return new ConferenceParticipant[size];
105 }
106 };
107
108 @Override
109 public int describeContents() {
110 return 0;
111 }
112
113 /**
Youming Yed6de26e2019-01-30 11:20:35 -0800114 * Determines the number presentation for a conference participant. Per RFC5767, if the host
115 * name contains {@code anonymous.invalid} we can assume that there is no valid caller ID
116 * information for the caller, otherwise we'll assume that the URI can be shown.
117 *
118 * @return The number presentation.
119 */
120 @VisibleForTesting
121 public int getParticipantPresentation() {
122 Uri address = getHandle();
123 if (address == null) {
124 return PhoneConstants.PRESENTATION_RESTRICTED;
125 }
126
127 String number = address.getSchemeSpecificPart();
128 // If no number, bail early and set restricted presentation.
129 if (TextUtils.isEmpty(number)) {
130 return PhoneConstants.PRESENTATION_RESTRICTED;
131 }
132 // Per RFC3261, the host name portion can also potentially include extra information:
133 // E.g. sip:anonymous1@anonymous.invalid;legid=1
134 // In this case, hostName will be anonymous.invalid and there is an extra parameter for
135 // legid=1.
136 // Parameters are optional, and the address (e.g. test@test.com) will always be the first
137 // part, with any parameters coming afterwards.
138 String [] hostParts = number.split("[;]");
139 String addressPart = hostParts[0];
140
141 // Get the number portion from the address part.
142 // This will typically be formatted similar to: 6505551212@test.com
143 String [] numberParts = addressPart.split("[@]");
144
145 // If we can't parse the host name out of the URI, then there is probably other data
146 // present, and is likely a valid SIP URI.
147 if (numberParts.length != 2) {
148 return PhoneConstants.PRESENTATION_ALLOWED;
149 }
150 String hostName = numberParts[1];
151
152 // If the hostname portion of the SIP URI is the invalid host string, presentation is
153 // restricted.
154 if (hostName.equals(ANONYMOUS_INVALID_HOST)) {
155 return PhoneConstants.PRESENTATION_RESTRICTED;
156 }
157
158 return PhoneConstants.PRESENTATION_ALLOWED;
159 }
160
161 /**
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700162 * Writes the {@code ConferenceParticipant} to a parcel.
163 *
164 * @param dest The Parcel in which the object should be written.
165 * @param flags Additional flags about how the object should be written.
166 */
167 @Override
168 public void writeToParcel(Parcel dest, int flags) {
169 dest.writeParcelable(mHandle, 0);
170 dest.writeString(mDisplayName);
171 dest.writeParcelable(mEndpoint, 0);
172 dest.writeInt(mState);
173 }
174
175 /**
176 * Builds a string representation of this instance.
177 *
178 * @return String representing the conference participant.
179 */
180 @Override
181 public String toString() {
182 StringBuilder sb = new StringBuilder();
183 sb.append("[ConferenceParticipant Handle: ");
Tyler Gunn5de68862016-07-12 08:28:54 -0700184 sb.append(Log.pii(mHandle));
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700185 sb.append(" DisplayName: ");
Tyler Gunn5de68862016-07-12 08:28:54 -0700186 sb.append(Log.pii(mDisplayName));
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700187 sb.append(" Endpoint: ");
Tyler Gunn5de68862016-07-12 08:28:54 -0700188 sb.append(Log.pii(mEndpoint));
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700189 sb.append(" State: ");
Tyler Gunn5de68862016-07-12 08:28:54 -0700190 sb.append(Connection.stateToString(mState));
Youming Yed6de26e2019-01-30 11:20:35 -0800191 sb.append(" ConnectTime: ");
192 sb.append(getConnectTime());
193 sb.append(" ConnectElapsedTime: ");
194 sb.append(getConnectElapsedTime());
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700195 sb.append("]");
196 return sb.toString();
197 }
198
199 /**
200 * The conference participant's handle (e.g., phone number).
201 */
202 public Uri getHandle() {
203 return mHandle;
204 }
205
206 /**
207 * The display name for the participant.
208 */
209 public String getDisplayName() {
210 return mDisplayName;
211 }
212
213 /**
214 * The enpoint Uri which uniquely identifies this conference participant. E.g. for an IMS
215 * conference call, this is the endpoint URI for the participant on the IMS conference server.
216 */
217 public Uri getEndpoint() {
218 return mEndpoint;
219 }
220
221 /**
222 * The state of the participant in the conference.
223 *
224 * @see android.telecom.Connection
225 */
226 public int getState() {
227 return mState;
228 }
Youming Yed6de26e2019-01-30 11:20:35 -0800229
230 /**
231 * The connect time of the participant to the conference.
232 */
233 public long getConnectTime() {
234 return mConnectTime;
235 }
236
237 public void setConnectTime(long connectTime) {
238 this.mConnectTime = connectTime;
239 }
240
241 /**
242 * The connect elpased time of the participant to the conference.
243 */
244 public long getConnectElapsedTime() {
245 return mConnectElapsedTime;
246 }
247
248 public void setConnectElapsedTime(long connectElapsedTime) {
249 mConnectElapsedTime = connectElapsedTime;
250 }
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700251}