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 import com.android.ims.internal.Logger; 37 38 /** 39 * RcsPresenceInfo is the class for presence information. 40 * It is used to pass information to application for inent ACTION_PRESENCE_CHANGED 41 * need to get it by the following statement: 42 * ArrayList<RcsPresenceInfo> rcsPresenceInfoList = intent.getParcelableArrayListExtra( 43 * RcsPresence.EXTRA_PRESENCE_INFO_LIST); 44 * 45 * @see RcsPresence#ACTION_PRESENCE_CHANGED 46 * 47 * @hide 48 */ 49 public class RcsPresenceInfo implements Parcelable { 50 /** 51 * Key for save contact_number. 52 * It is passed by getCapabilityByContacts or getAvailability 53 * 54 * @see #getContactNumber 55 */ 56 private static final String CONTACT_NUMBER = "contact_number"; 57 58 /** 59 * Key for the flag to indicate if the number is volte enabled. 60 * 61 * @see #getVolteStatus 62 */ 63 public static final String VOLTE_STATUS = "volte_status"; 64 65 /** 66 * The Volte status: 67 * If the contact got the 404 for single contact fetch. 68 * or it got "rejected", "noresource" and "giveup", then it is 69 * VOLTE_DISABLED. Or it is VOLTE_ENBLED. 70 * If we didn't get a success polling yet then it is VOLTE_UNKNOWN. 71 */ 72 public static class VolteStatus{ 73 /** 74 * Didn't poll yet. 75 */ 76 public static final int VOLTE_UNKNOWN = -1; 77 78 /** 79 * Volte disabled for 404 response for single contact fetch 80 * or get "rejected", "noresource" and "giveup" notification. 81 */ 82 public static final int VOLTE_DISABLED = 0; 83 84 /** 85 * Volte enabled for get proper notification. 86 */ 87 public static final int VOLTE_ENABLED = 1; 88 } 89 90 /** 91 * For extension consideration we deinfed the sercice type here. 92 * Currently we only support the VoLte call and VT call. 93 * 94 * The service type for RCS 95 */ 96 public static interface ServiceType { 97 /** 98 * For VoLte call. 99 */ 100 public static final int VOLTE_CALL = 1; 101 102 /** 103 * For VT call. 104 */ 105 public static final int VT_CALL = 2; 106 } 107 108 /** 109 * Service state 110 * 111 * @see #getServiceState 112 */ 113 public static class ServiceState { 114 /** 115 * ONLINE means the servie is available. 116 */ 117 public static final int ONLINE = 1; 118 119 /** 120 * OFFLINE means the service is not available. 121 */ 122 public static final int OFFLINE = 0; 123 124 /** 125 * UNKNOWN means the presence service information didn't be got yet. 126 */ 127 public static final int UNKNOWN = -1; 128 } 129 130 /** 131 * The presence information is maintained by key and value pair. 132 * ServiceInfoKey defines the key of the current supported information. 133 */ 134 public static class ServiceInfoKey { 135 /** 136 * Service type. It is defined by ServiceType. 137 * 138 * @see ServiceType 139 */ 140 public static final String SERVICE_TYPE = "service_type"; // VOLTE_CALL,etc 141 142 /** 143 * Service state. It is defined by ServiceState. 144 * 145 * @see ServiceState 146 * @see #getServiceState 147 */ 148 public static final String STATE = "state"; // ONLINE, etc. 149 150 /** 151 * The service contact. For example, the phone requests presence information for number 152 * "12345678", the service responses the presence with "987654321" as the service number 153 * of video call. Then the phone should start the video call with "987654321". 154 * The "987654321" is the service number. 155 * 156 * @see #getServiceContact 157 */ 158 public static final String SERVICE_CONTACT = "service_contact"; 159 160 /** 161 * The timestamp which got from network. 162 * 163 * @see #getTimeStamp 164 */ 165 public static final String TIMESTAMP = "timestamp"; 166 } 167 168 /** 169 * Return the contact number. 170 * It is passed by getCapabilityByContacts or getAvailability 171 * 172 * @return the contact number which has been passed in. 173 * 174 * @see #CONTACT_NUMBER 175 */ 176 public String getContactNumber() { 177 return mServiceInfo.getString(CONTACT_NUMBER); 178 } 179 180 /** 181 * @Return the VolteStatus. 182 */ 183 public int getVolteStatus(){ 184 return mServiceInfo.getInt(VOLTE_STATUS); 185 } 186 187 /** 188 * Return the ServiceState of the specific serviceType. 189 * 190 * @param serviceType it is defined by ServiceType. 191 * 192 * @return the service presence state which has been described in ServiceInfoKey. 193 * 194 * @see ServiceType 195 * @see ServiceState 196 * @see ServiceInfoKey#STATE 197 */ 198 public int getServiceState(int serviceType) { 199 return getServiceInfo(serviceType, ServiceInfoKey.STATE, ServiceState.UNKNOWN); 200 } 201 202 /** 203 * Return the service contact of the specific serviceType. 204 * 205 * @param serviceType It is defined by ServiceType. 206 * 207 * @return the service contact which is described in ServiceInfoKey. 208 * 209 * @see ServiceType 210 * @see ServiceInfoKey#SERVICE_CONTACT 211 */ 212 public String getServiceContact(int serviceType) { 213 return getServiceInfo(serviceType, ServiceInfoKey.SERVICE_CONTACT, ""); 214 } 215 216 /** 217 * Return the timestamp. 218 * 219 * @param serviceType It is defined by ServiceType. 220 * 221 * @return the timestamp which has been got from server. 222 * 223 * @see ServiceType 224 * @see ServiceInfoKey#TIMESTAMP 225 */ 226 public long getTimeStamp(int serviceType) { 227 return getServiceInfo(serviceType, ServiceInfoKey.TIMESTAMP, 0L); 228 } 229 230 /** 231 * @hide 232 */ 233 public RcsPresenceInfo() { 234 } 235 236 /** 237 * @hide 238 */ 239 public RcsPresenceInfo(Parcel source) { 240 mServiceInfo.readFromParcel(source); 241 } 242 243 /** 244 * @hide 245 */ 246 private Bundle getBundle() { 247 return mServiceInfo; 248 } 249 250 /** 251 * @hide 252 */ 253 public RcsPresenceInfo(String contactNumber,int volteStatus, 254 int ipVoiceCallState, String ipVoiceCallServiceNumber, long ipVoiceCallTimestamp, 255 int ipVideoCallState, String ipVideoCallServiceNumber, long ipVideoCallTimestamp) { 256 mServiceInfo.putString(CONTACT_NUMBER, contactNumber); 257 mServiceInfo.putInt(VOLTE_STATUS, volteStatus); 258 259 set(ServiceType.VOLTE_CALL, ipVoiceCallState, ipVoiceCallServiceNumber, 260 ipVoiceCallTimestamp); 261 262 set(ServiceType.VT_CALL, ipVideoCallState, ipVideoCallServiceNumber, 263 ipVideoCallTimestamp); 264 } 265 266 private void set(int serviceType, int state, String serviceNumber, long timestamp) { 267 Bundle capability = new Bundle(); 268 269 capability.putInt(ServiceInfoKey.SERVICE_TYPE, serviceType); 270 capability.putInt(ServiceInfoKey.STATE, state); 271 capability.putString(ServiceInfoKey.SERVICE_CONTACT, serviceNumber); 272 capability.putLong(ServiceInfoKey.TIMESTAMP, timestamp); 273 274 mServiceInfo.putBundle(String.valueOf(serviceType), capability); 275 } 276 277 /** 278 * Overload 279 * @hide 280 */ 281 public static final Parcelable.Creator<RcsPresenceInfo> CREATOR = new 282 Parcelable.Creator<RcsPresenceInfo>() { 283 public RcsPresenceInfo createFromParcel(Parcel in) { 284 return new RcsPresenceInfo(in); 285 } 286 287 public RcsPresenceInfo[] newArray(int size) { 288 return new RcsPresenceInfo[size]; 289 } 290 }; 291 292 /** 293 * Overload 294 * @hide 295 */ 296 public void writeToParcel(Parcel dest, int flags) { 297 mServiceInfo.writeToParcel(dest, flags); 298 } 299 300 /** 301 * Overload 302 * @hide 303 */ 304 public int describeContents() { 305 return 0; 306 } 307 308 private Bundle mServiceInfo = new Bundle(); 309 310 private String getServiceInfo(int serviceType, String infoKey, String defaultValue) { 311 Bundle serviceInfo = mServiceInfo.getBundle(String.valueOf(serviceType)); 312 313 if (serviceInfo != null) { 314 return serviceInfo.getString(infoKey); 315 } 316 return defaultValue; 317 } 318 319 private long getServiceInfo(int serviceType, String infoKey, long defaultValue) { 320 Bundle serviceInfo = mServiceInfo.getBundle(String.valueOf(serviceType)); 321 if (serviceInfo != null) { 322 return serviceInfo.getLong(infoKey); 323 } 324 325 return defaultValue; 326 } 327 328 private int getServiceInfo(int serviceType, String infoType, int defaultValue) { 329 Bundle serviceInfo = mServiceInfo.getBundle(String.valueOf(serviceType)); 330 if (serviceInfo != null) { 331 return serviceInfo.getInt(infoType); 332 } 333 return defaultValue; 334 } 335 336 private Uri getServiceInfo(int serviceType, String infoKey, Uri defaultValue) { 337 Bundle serviceInfo = mServiceInfo.getBundle(String.valueOf(serviceType)); 338 if (serviceInfo != null) { 339 return (Uri)serviceInfo.getParcelable(infoKey); 340 } 341 342 return defaultValue; 343 } 344 345 public String toString() { 346 return" contactNumber=" + Logger.hidePhoneNumberPii(getContactNumber()) + 347 " volteStatus=" + getVolteStatus() + 348 " ipVoiceCallSate=" + getServiceState(ServiceType.VOLTE_CALL) + 349 " ipVoiceCallServiceNumber=" + 350 Logger.hidePhoneNumberPii(getServiceContact(ServiceType.VOLTE_CALL)) + 351 " ipVoiceCallTimestamp=" + getTimeStamp(ServiceType.VOLTE_CALL) + 352 " ipVideoCallSate=" + getServiceState(ServiceType.VT_CALL) + 353 " ipVideoCallServiceNumber=" + 354 Logger.hidePhoneNumberPii(getServiceContact(ServiceType.VT_CALL)) + 355 " ipVideoCallTimestamp=" + getTimeStamp(ServiceType.VT_CALL); 356 } 357 } 358 359