blob: 0afde88b8918db141eb58e8d82e7475eadb5236e [file] [log] [blame]
Wink Savillef8458ff2014-06-25 16:08:02 -07001/*
2 * Copyright (c) 2013 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 com.android.ims;
18
19import java.util.HashMap;
20import java.util.Iterator;
21import java.util.Map.Entry;
22import java.util.Set;
23
24import android.os.Bundle;
25import android.os.Parcel;
26import android.os.Parcelable;
Tyler Gunn3bffcf72014-10-28 13:51:27 -070027import android.telecom.Call;
28import android.telecom.Connection;
Wink Savillef8458ff2014-06-25 16:08:02 -070029
30/**
31 * Provides the conference information (defined in RFC 4575) for IMS conference call.
32 *
33 * @hide
34 */
35public class ImsConferenceState implements Parcelable {
36 /**
37 * conference-info : user
38 */
39 // user (String) : Tel or SIP URI
40 public static final String USER = "user";
41 // user > display text (String)
42 public static final String DISPLAY_TEXT = "display-text";
43 // user > endpoint (String) : URI or GRUU or Phone number
44 public static final String ENDPOINT = "endpoint";
45 // user > endpoint > status
46 public static final String STATUS = "status";
47
48 /**
49 * status-type (String) :
50 * "pending" : Endpoint is not yet in the session, but it is anticipated that he/she will
51 * join in the near future.
52 * "dialing-out" : Focus has dialed out to connect the endpoint to the conference,
53 * but the endpoint is not yet in the roster (probably being authenticated).
54 * "dialing-in" : Endpoint is dialing into the conference, not yet in the roster
55 * (probably being authenticated).
56 * "alerting" : PSTN alerting or SIP 180 Ringing was returned for the outbound call;
57 * endpoint is being alerted.
58 * "on-hold" : Active signaling dialog exists between an endpoint and a focus,
59 * but endpoint is "on-hold" for this conference, i.e., he/she is neither "hearing"
60 * the conference mix nor is his/her media being mixed in the conference.
61 * "connected" : Endpoint is a participant in the conference. Depending on the media policies,
62 * he/she can send and receive media to and from other participants.
63 * "disconnecting" : Focus is in the process of disconnecting the endpoint
64 * (e.g. in SIP a DISCONNECT or BYE was sent to the endpoint).
65 * "disconnected" : Endpoint is not a participant in the conference, and no active dialog
66 * exists between the endpoint and the focus.
67 * "muted-via-focus" : Active signaling dialog exists beween an endpoint and a focus and
68 * the endpoint can "listen" to the conference, but the endpoint's media is not being
69 * mixed into the conference.
70 * "connect-fail" : Endpoint fails to join the conference by rejecting the conference call.
71 */
72 public static final String STATUS_PENDING = "pending";
73 public static final String STATUS_DIALING_OUT = "dialing-out";
74 public static final String STATUS_DIALING_IN = "dialing-in";
75 public static final String STATUS_ALERTING = "alerting";
76 public static final String STATUS_ON_HOLD = "on-hold";
77 public static final String STATUS_CONNECTED = "connected";
78 public static final String STATUS_DISCONNECTING = "disconnecting";
79 public static final String STATUS_DISCONNECTED = "disconnected";
80 public static final String STATUS_MUTED_VIA_FOCUS = "muted-via-focus";
81 public static final String STATUS_CONNECT_FAIL = "connect-fail";
Tyler Gunnb229dda2017-08-25 15:01:00 -070082 public static final String STATUS_SEND_ONLY = "sendonly";
83 public static final String STATUS_SEND_RECV = "sendrecv";
Wink Savillef8458ff2014-06-25 16:08:02 -070084
85 /**
86 * conference-info : SIP status code (integer)
87 */
88 public static final String SIP_STATUS_CODE = "sipstatuscode";
89
90 public HashMap<String, Bundle> mParticipants = new HashMap<String, Bundle>();
91
92 public ImsConferenceState() {
93 }
94
95 public ImsConferenceState(Parcel in) {
96 readFromParcel(in);
97 }
98
99 @Override
100 public int describeContents() {
101 return 0;
102 }
103
104 @Override
105 public void writeToParcel(Parcel out, int flags) {
106 out.writeInt(mParticipants.size());
107
108 if (mParticipants.size() > 0) {
109 Set<Entry<String, Bundle>> entries = mParticipants.entrySet();
110
111 if (entries != null) {
112 Iterator<Entry<String, Bundle>> iterator = entries.iterator();
113
114 while (iterator.hasNext()) {
115 Entry<String, Bundle> entry = iterator.next();
116
117 out.writeString(entry.getKey());
118 out.writeParcelable(entry.getValue(), 0);
119 }
120 }
121 }
122 }
123
124 private void readFromParcel(Parcel in) {
125 int size = in.readInt();
126
127 for (int i = 0; i < size; ++i) {
128 String user = in.readString();
129 Bundle state = in.readParcelable(null);
130 mParticipants.put(user, state);
131 }
132 }
133
134 public static final Creator<ImsConferenceState> CREATOR =
135 new Creator<ImsConferenceState>() {
136 @Override
137 public ImsConferenceState createFromParcel(Parcel in) {
138 return new ImsConferenceState(in);
139 }
140
141 @Override
142 public ImsConferenceState[] newArray(int size) {
143 return new ImsConferenceState[size];
144 }
145 };
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700146
147 /**
148 * Translates an {@code ImsConferenceState} status type to a telecom connection state.
149 *
150 * @param status The status type.
151 * @return The corresponding {@link android.telecom.Connection} state.
152 */
153 public static int getConnectionStateForStatus(String status) {
154 if (status.equals(STATUS_PENDING)) {
155 return Connection.STATE_INITIALIZING;
156 } else if (status.equals(STATUS_DIALING_IN)) {
157 return Connection.STATE_RINGING;
158 } else if (status.equals(STATUS_ALERTING) ||
159 status.equals(STATUS_DIALING_OUT)) {
160 return Connection.STATE_DIALING;
Tyler Gunnb229dda2017-08-25 15:01:00 -0700161 } else if (status.equals(STATUS_ON_HOLD) ||
162 status.equals(STATUS_SEND_ONLY)) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700163 return Connection.STATE_HOLDING;
164 } else if (status.equals(STATUS_CONNECTED) ||
165 status.equals(STATUS_MUTED_VIA_FOCUS) ||
Tyler Gunnb229dda2017-08-25 15:01:00 -0700166 status.equals(STATUS_DISCONNECTING) ||
167 status.equals(STATUS_SEND_RECV)) {
Tyler Gunn3bffcf72014-10-28 13:51:27 -0700168 return Connection.STATE_ACTIVE;
169 } else if (status.equals(STATUS_DISCONNECTED)) {
170 return Connection.STATE_DISCONNECTED;
171 }
172 return Call.STATE_ACTIVE;
173 }
Tyler Gunnb229dda2017-08-25 15:01:00 -0700174
175 @Override
176 public String toString() {
177 StringBuilder sb = new StringBuilder();
178 sb.append("[");
179 sb.append(ImsConferenceState.class.getSimpleName());
180 sb.append(" ");
181 if (mParticipants.size() > 0) {
182 Set<Entry<String, Bundle>> entries = mParticipants.entrySet();
183
184 if (entries != null) {
185 Iterator<Entry<String, Bundle>> iterator = entries.iterator();
186 sb.append("<");
187 while (iterator.hasNext()) {
188 Entry<String, Bundle> entry = iterator.next();
189 sb.append(entry.getKey());
190 sb.append(": ");
191 Bundle participantData = entry.getValue();
192
193 for (String key : participantData.keySet()) {
194 sb.append(key);
195 sb.append("=");
196 if (ENDPOINT.equals(key) || USER.equals(key)) {
197 sb.append(android.telecom.Log.pii(participantData.get(key)));
198 } else {
199 sb.append(participantData.get(key));
200 }
201 sb.append(", ");
202 }
203 }
204 sb.append(">");
205 }
206 }
207 sb.append("]");
208 return sb.toString();
209 }
Wink Savillef8458ff2014-06-25 16:08:02 -0700210}