• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015, Motorola Mobility LLC
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *     - Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     - Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     - Neither the name of Motorola Mobility nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MOTOROLA MOBILITY LLC BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26  * DAMAGE.
27  */
28 
29 package com.android.ims;
30 
31 import android.os.Bundle;
32 import android.os.Parcel;
33 import android.os.Parcelable;
34 import android.net.Uri;
35 
36 /**
37  * RcsPresenceInfo is the class for presence information.
38  * It is used to pass information to application for inent ACTION_PRESENCE_CHANGED
39  * need to get it by the following statement:
40  * ArrayList<RcsPresenceInfo> rcsPresenceInfoList = intent.getParcelableArrayListExtra(
41  *           RcsPresence.EXTRA_PRESENCE_INFO_LIST);
42  *
43  * @see RcsPresence#ACTION_PRESENCE_CHANGED
44  *
45  * @hide
46  */
47 public class RcsPresenceInfo implements Parcelable {
48     /**
49      * Key for save contact_number.
50      * It is passed by getCapabilityByContacts or getAvailability
51      *
52      * @see #getContactNumber
53      */
54      private static final String CONTACT_NUMBER = "contact_number";
55 
56     /**
57      * Key for the flag to indicate if the number is volte enabled.
58      *
59      * @see #getVolteStatus
60      */
61     public static final String VOLTE_STATUS = "volte_status";
62 
63     /**
64      * The Volte status:
65      * If the contact got the 404 for single contact fetch.
66      * or it got "rejected", "noresource" and "giveup", then it is
67      * VOLTE_DISABLED. Or it is VOLTE_ENBLED.
68      * If we didn't get a success polling yet then it is VOLTE_UNKNOWN.
69      */
70     public static class VolteStatus{
71         /**
72          * Didn't poll yet.
73          */
74         public static final int VOLTE_UNKNOWN = -1;
75 
76         /**
77          * Volte disabled for 404 response for single contact fetch
78          * or get "rejected", "noresource" and "giveup" notification.
79          */
80         public static final int VOLTE_DISABLED = 0;
81 
82         /**
83          * Volte enabled for get proper notification.
84          */
85         public static final int VOLTE_ENABLED = 1;
86     }
87 
88     /**
89      * For extension consideration we deinfed the sercice type here.
90      * Currently we only support the VoLte call and VT call.
91      *
92      * The service type for RCS
93      */
94     public static interface ServiceType {
95         /**
96          * For VoLte call.
97          */
98         public static final int VOLTE_CALL = 1;
99 
100         /**
101          * For VT call.
102          */
103         public static final int VT_CALL = 2;
104     }
105 
106     /**
107      * Service state
108      *
109      * @see #getServiceState
110      */
111     public static class ServiceState {
112         /**
113          * ONLINE means the servie is available.
114          */
115         public static final int ONLINE = 1;
116 
117         /**
118          * OFFLINE means the service is not available.
119          */
120         public static final int OFFLINE = 0;
121 
122        /**
123         * UNKNOWN means the presence service information didn't be got yet.
124         */
125         public static final int UNKNOWN = -1;
126     }
127 
128     /**
129      * The presence information is maintained by key and value pair.
130      * ServiceInfoKey defines the key of the current supported information.
131      */
132     public static class ServiceInfoKey {
133         /**
134          * Service type. It is defined by ServiceType.
135          *
136          * @see ServiceType
137          */
138         public static final String SERVICE_TYPE = "service_type"; // VOLTE_CALL,etc
139 
140         /**
141          * Service state. It is defined by ServiceState.
142          *
143          * @see ServiceState
144          * @see #getServiceState
145          */
146         public static final String STATE = "state"; // ONLINE, etc.
147 
148         /**
149          * The service contact. For example, the phone requests presence information for number
150          * "12345678", the service responses the presence with "987654321" as the service number
151          * of video call. Then the phone should start the video call with "987654321".
152          * The "987654321" is the service number.
153          *
154          * @see #getServiceContact
155          */
156         public static final String SERVICE_CONTACT = "service_contact";
157 
158         /**
159          * The timestamp which got from network.
160          *
161          * @see #getTimeStamp
162          */
163         public static final String TIMESTAMP = "timestamp";
164     }
165 
166     /**
167      * Return the contact number.
168      * It is passed by getCapabilityByContacts or getAvailability
169      *
170      * @return the contact number which has been passed in.
171      *
172      * @see #CONTACT_NUMBER
173      */
getContactNumber()174     public String getContactNumber() {
175         return mServiceInfo.getString(CONTACT_NUMBER);
176     }
177 
178     /**
179      * @Return the VolteStatus.
180      */
getVolteStatus()181     public int getVolteStatus(){
182         return mServiceInfo.getInt(VOLTE_STATUS);
183     }
184 
185     /**
186      * Return the ServiceState of the specific serviceType.
187      *
188      * @param serviceType it is defined by ServiceType.
189      *
190      * @return the service presence state which has been described in ServiceInfoKey.
191      *
192      * @see ServiceType
193      * @see ServiceState
194      * @see ServiceInfoKey#STATE
195      */
getServiceState(int serviceType)196     public int getServiceState(int serviceType) {
197         return getServiceInfo(serviceType, ServiceInfoKey.STATE, ServiceState.UNKNOWN);
198     }
199 
200     /**
201      * Return the service contact of the specific serviceType.
202      *
203      * @param serviceType It is defined by ServiceType.
204      *
205      * @return the service contact which is described in ServiceInfoKey.
206      *
207      * @see ServiceType
208      * @see ServiceInfoKey#SERVICE_CONTACT
209      */
getServiceContact(int serviceType)210     public String getServiceContact(int serviceType) {
211         return getServiceInfo(serviceType, ServiceInfoKey.SERVICE_CONTACT, "");
212     }
213 
214     /**
215      * Return the timestamp.
216      *
217      * @param serviceType It is defined by ServiceType.
218      *
219      * @return the timestamp which has been got from server.
220      *
221      * @see ServiceType
222      * @see ServiceInfoKey#TIMESTAMP
223      */
getTimeStamp(int serviceType)224     public long getTimeStamp(int serviceType) {
225         return getServiceInfo(serviceType, ServiceInfoKey.TIMESTAMP, 0L);
226     }
227 
228     /**
229      * @hide
230      */
RcsPresenceInfo()231     public RcsPresenceInfo() {
232     }
233 
234     /**
235      * @hide
236      */
RcsPresenceInfo(Parcel source)237     public RcsPresenceInfo(Parcel source) {
238         mServiceInfo.readFromParcel(source);
239     }
240 
241     /**
242      * @hide
243      */
getBundle()244     private Bundle getBundle() {
245         return mServiceInfo;
246     }
247 
248     /**
249      * @hide
250      */
RcsPresenceInfo(String contactNumber,int volteStatus, int ipVoiceCallState, String ipVoiceCallServiceNumber, long ipVoiceCallTimestamp, int ipVideoCallState, String ipVideoCallServiceNumber, long ipVideoCallTimestamp)251     public RcsPresenceInfo(String contactNumber,int volteStatus,
252             int ipVoiceCallState, String ipVoiceCallServiceNumber, long ipVoiceCallTimestamp,
253             int ipVideoCallState, String ipVideoCallServiceNumber, long ipVideoCallTimestamp) {
254         mServiceInfo.putString(CONTACT_NUMBER, contactNumber);
255         mServiceInfo.putInt(VOLTE_STATUS, volteStatus);
256 
257         set(ServiceType.VOLTE_CALL, ipVoiceCallState, ipVoiceCallServiceNumber,
258                 ipVoiceCallTimestamp);
259 
260         set(ServiceType.VT_CALL, ipVideoCallState, ipVideoCallServiceNumber,
261                 ipVideoCallTimestamp);
262     }
263 
set(int serviceType, int state, String serviceNumber, long timestamp)264     private void set(int serviceType, int state, String serviceNumber, long timestamp) {
265         Bundle capability = new Bundle();
266 
267         capability.putInt(ServiceInfoKey.SERVICE_TYPE, serviceType);
268         capability.putInt(ServiceInfoKey.STATE, state);
269         capability.putString(ServiceInfoKey.SERVICE_CONTACT, serviceNumber);
270         capability.putLong(ServiceInfoKey.TIMESTAMP, timestamp);
271 
272         mServiceInfo.putBundle(String.valueOf(serviceType), capability);
273     }
274 
275     /**
276      * Overload
277      * @hide
278      */
279     public static final Parcelable.Creator<RcsPresenceInfo> CREATOR = new
280             Parcelable.Creator<RcsPresenceInfo>() {
281         public RcsPresenceInfo createFromParcel(Parcel in) {
282             return new RcsPresenceInfo(in);
283         }
284 
285         public RcsPresenceInfo[] newArray(int size) {
286             return new RcsPresenceInfo[size];
287         }
288     };
289 
290     /**
291      * Overload
292      * @hide
293      */
writeToParcel(Parcel dest, int flags)294     public void writeToParcel(Parcel dest, int flags) {
295         mServiceInfo.writeToParcel(dest, flags);
296     }
297 
298     /**
299      * Overload
300      * @hide
301      */
describeContents()302     public int describeContents() {
303         return 0;
304     }
305 
306     private Bundle mServiceInfo = new Bundle();
307 
getServiceInfo(int serviceType, String infoKey, String defaultValue)308     private String getServiceInfo(int serviceType, String infoKey, String defaultValue) {
309         Bundle serviceInfo = mServiceInfo.getBundle(String.valueOf(serviceType));
310 
311         if (serviceInfo != null) {
312             return serviceInfo.getString(infoKey);
313         }
314         return defaultValue;
315     }
316 
getServiceInfo(int serviceType, String infoKey, long defaultValue)317     private long getServiceInfo(int serviceType, String infoKey, long defaultValue) {
318         Bundle serviceInfo = mServiceInfo.getBundle(String.valueOf(serviceType));
319         if (serviceInfo != null) {
320             return serviceInfo.getLong(infoKey);
321         }
322 
323         return defaultValue;
324     }
325 
getServiceInfo(int serviceType, String infoType, int defaultValue)326     private int getServiceInfo(int serviceType, String infoType, int defaultValue) {
327         Bundle serviceInfo = mServiceInfo.getBundle(String.valueOf(serviceType));
328         if (serviceInfo != null) {
329             return serviceInfo.getInt(infoType);
330         }
331         return defaultValue;
332     }
333 
getServiceInfo(int serviceType, String infoKey, Uri defaultValue)334     private Uri getServiceInfo(int serviceType, String infoKey, Uri defaultValue) {
335         Bundle serviceInfo = mServiceInfo.getBundle(String.valueOf(serviceType));
336         if (serviceInfo != null) {
337             return (Uri)serviceInfo.getParcelable(infoKey);
338         }
339 
340         return defaultValue;
341     }
342 
toString()343     public String toString() {
344         return" contactNumber=" + getContactNumber() +
345             " volteStatus=" + getVolteStatus() +
346             " ipVoiceCallSate=" + getServiceState(ServiceType.VOLTE_CALL) +
347             " ipVoiceCallServiceNumber=" + getServiceContact(ServiceType.VOLTE_CALL) +
348             " ipVoiceCallTimestamp=" + getTimeStamp(ServiceType.VOLTE_CALL) +
349             " ipVideoCallSate=" + getServiceState(ServiceType.VT_CALL) +
350             " ipVideoCallServiceNumber=" + getServiceContact(ServiceType.VT_CALL) +
351             " ipVideoCallTimestamp=" + getTimeStamp(ServiceType.VT_CALL);
352     }
353 }
354 
355