Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.telecom; |
| 18 | |
| 19 | import android.net.Uri; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
Youming Ye | d6de26e | 2019-01-30 11:20:35 -0800 | [diff] [blame] | 22 | import android.text.TextUtils; |
| 23 | |
| 24 | import com.android.internal.annotations.VisibleForTesting; |
| 25 | import com.android.internal.telephony.PhoneConstants; |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Parcelable representation of a participant's state in a conference call. |
| 29 | * @hide |
| 30 | */ |
| 31 | public class ConferenceParticipant implements Parcelable { |
| 32 | |
| 33 | /** |
Youming Ye | d6de26e | 2019-01-30 11:20:35 -0800 | [diff] [blame] | 34 | * 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 Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 39 | * 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 Ye | d6de26e | 2019-01-30 11:20:35 -0800 | [diff] [blame] | 62 | * 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 Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 72 | * 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 Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 89 | public static final @android.annotation.NonNull Parcelable.Creator<ConferenceParticipant> CREATOR = |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 90 | 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 Ye | d6de26e | 2019-01-30 11:20:35 -0800 | [diff] [blame] | 114 | * 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 Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 162 | * 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 Gunn | 5de6886 | 2016-07-12 08:28:54 -0700 | [diff] [blame] | 184 | sb.append(Log.pii(mHandle)); |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 185 | sb.append(" DisplayName: "); |
Tyler Gunn | 5de6886 | 2016-07-12 08:28:54 -0700 | [diff] [blame] | 186 | sb.append(Log.pii(mDisplayName)); |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 187 | sb.append(" Endpoint: "); |
Tyler Gunn | 5de6886 | 2016-07-12 08:28:54 -0700 | [diff] [blame] | 188 | sb.append(Log.pii(mEndpoint)); |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 189 | sb.append(" State: "); |
Tyler Gunn | 5de6886 | 2016-07-12 08:28:54 -0700 | [diff] [blame] | 190 | sb.append(Connection.stateToString(mState)); |
Youming Ye | d6de26e | 2019-01-30 11:20:35 -0800 | [diff] [blame] | 191 | sb.append(" ConnectTime: "); |
| 192 | sb.append(getConnectTime()); |
| 193 | sb.append(" ConnectElapsedTime: "); |
| 194 | sb.append(getConnectElapsedTime()); |
Tyler Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 195 | 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 Ye | d6de26e | 2019-01-30 11:20:35 -0800 | [diff] [blame] | 229 | |
| 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 Gunn | 3bffcf7 | 2014-10-28 13:51:27 -0700 | [diff] [blame] | 251 | } |