1 /* 2 * Copyright (C) 2021 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 com.android.ims.rcs.uce.presence.publish; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.telephony.ims.RcsContactPresenceTuple; 22 import android.text.TextUtils; 23 24 import java.util.Objects; 25 26 /** 27 * Represents the "service-description" element in the PIDF XML for SIP PUBLISH of RCS capabilities. 28 */ 29 public class ServiceDescription { 30 31 public static final ServiceDescription SERVICE_DESCRIPTION_CHAT_IM = new ServiceDescription( 32 RcsContactPresenceTuple.SERVICE_ID_CHAT_V1, 33 "1.0" /*version*/, 34 null /*description*/ 35 ); 36 37 public static final ServiceDescription SERVICE_DESCRIPTION_CHAT_SESSION = 38 new ServiceDescription( 39 RcsContactPresenceTuple.SERVICE_ID_CHAT_V2, 40 "2.0" /*version*/, 41 null /*description*/ 42 ); 43 44 public static final ServiceDescription SERVICE_DESCRIPTION_FT = new ServiceDescription( 45 RcsContactPresenceTuple.SERVICE_ID_FT, 46 "1.0" /*version*/, 47 null /*description*/ 48 ); 49 50 public static final ServiceDescription SERVICE_DESCRIPTION_FT_SMS = new ServiceDescription( 51 RcsContactPresenceTuple.SERVICE_ID_FT_OVER_SMS, 52 "1.0" /*version*/, 53 null /*description*/ 54 ); 55 56 public static final ServiceDescription SERVICE_DESCRIPTION_PRESENCE = new ServiceDescription( 57 RcsContactPresenceTuple.SERVICE_ID_PRESENCE, 58 "1.0" /*version*/, 59 "Capabilities Discovery Service" /*description*/ 60 ); 61 62 public static final ServiceDescription SERVICE_DESCRIPTION_MMTEL_VOICE = new ServiceDescription( 63 RcsContactPresenceTuple.SERVICE_ID_MMTEL, 64 "1.0" /*version*/, 65 "Voice Service" /*description*/ 66 ); 67 68 // No change except for description (service capabilities generated elsewhere). 69 public static final ServiceDescription SERVICE_DESCRIPTION_MMTEL_VOICE_VIDEO = 70 new ServiceDescription( 71 RcsContactPresenceTuple.SERVICE_ID_MMTEL, 72 "1.0" /*version*/, 73 "Voice and Video Service" /*description*/ 74 ); 75 76 public static final ServiceDescription SERVICE_DESCRIPTION_GEOPUSH = new ServiceDescription( 77 RcsContactPresenceTuple.SERVICE_ID_GEO_PUSH, 78 "1.0" /*version*/, 79 null /*description*/ 80 ); 81 82 public static final ServiceDescription SERVICE_DESCRIPTION_GEOPUSH_SMS = new ServiceDescription( 83 RcsContactPresenceTuple.SERVICE_ID_GEO_PUSH_VIA_SMS, 84 "1.0" /*version*/, 85 null /*description*/ 86 ); 87 88 public static final ServiceDescription SERVICE_DESCRIPTION_CALL_COMPOSER = 89 new ServiceDescription( 90 RcsContactPresenceTuple.SERVICE_ID_CALL_COMPOSER, 91 "1.0" /*version*/, 92 null /*description*/ 93 ); 94 95 public static final ServiceDescription SERVICE_DESCRIPTION_CALL_COMPOSER_MMTEL = 96 new ServiceDescription( 97 RcsContactPresenceTuple.SERVICE_ID_CALL_COMPOSER, 98 "2.0" /*version*/, 99 null /*description*/ 100 ); 101 102 public static final ServiceDescription SERVICE_DESCRIPTION_POST_CALL = new ServiceDescription( 103 RcsContactPresenceTuple.SERVICE_ID_POST_CALL, 104 "1.0" /*version*/, 105 null /*description*/ 106 ); 107 108 public static final ServiceDescription SERVICE_DESCRIPTION_SHARED_MAP = new ServiceDescription( 109 RcsContactPresenceTuple.SERVICE_ID_SHARED_MAP, 110 "1.0" /*version*/, 111 null /*description*/ 112 ); 113 114 public static final ServiceDescription SERVICE_DESCRIPTION_SHARED_SKETCH = 115 new ServiceDescription( 116 RcsContactPresenceTuple.SERVICE_ID_SHARED_SKETCH, 117 "1.0" /*version*/, 118 null /*description*/ 119 ); 120 // this is the same as below but redefined so that it can be a separate key entry 121 // in DEFAULT_SERVICE_DESCRIPTION_MAP 122 public static final ServiceDescription SERVICE_DESCRIPTION_CHATBOT_SESSION = 123 new ServiceDescription( 124 RcsContactPresenceTuple.SERVICE_ID_CHATBOT, 125 "1.0" /*version*/, 126 null /*description*/ 127 ); 128 129 public static final ServiceDescription SERVICE_DESCRIPTION_CHATBOT_SESSION_V1 = 130 new ServiceDescription( 131 RcsContactPresenceTuple.SERVICE_ID_CHATBOT, 132 "1.0" /*version*/, 133 "Chatbot Session" /*description*/ 134 ); 135 136 public static final ServiceDescription SERVICE_DESCRIPTION_CHATBOT_SESSION_V2 = 137 new ServiceDescription( 138 RcsContactPresenceTuple.SERVICE_ID_CHATBOT, 139 "2.0" /*version*/, 140 "Chatbot Session" /*description*/ 141 ); 142 // this is the same as below but redefined so that it can be a separate key entry 143 // in DEFAULT_SERVICE_DESCRIPTION_MAP 144 public static final ServiceDescription SERVICE_DESCRIPTION_CHATBOT_SA_SESSION = 145 new ServiceDescription( 146 RcsContactPresenceTuple.SERVICE_ID_CHATBOT_STANDALONE.trim(), 147 "1.0" /*version*/, 148 null /*description*/ 149 ); 150 151 public static final ServiceDescription SERVICE_DESCRIPTION_CHATBOT_SA_SESSION_V1 = 152 new ServiceDescription( 153 RcsContactPresenceTuple.SERVICE_ID_CHATBOT_STANDALONE.trim(), 154 "1.0" /*version*/, 155 "Chatbot Standalone" /*description*/ 156 ); 157 158 public static final ServiceDescription SERVICE_DESCRIPTION_CHATBOT_SA_SESSION_V2 = 159 new ServiceDescription( 160 RcsContactPresenceTuple.SERVICE_ID_CHATBOT_STANDALONE.trim(), 161 "2.0" /*version*/, 162 "Chatbot Standalone" /*description*/ 163 ); 164 165 public static final ServiceDescription SERVICE_DESCRIPTION_CHATBOT_ROLE = 166 new ServiceDescription( 167 RcsContactPresenceTuple.SERVICE_ID_CHATBOT_ROLE, 168 "1.0" /*version*/, 169 null /*description*/ 170 ); 171 172 public static final ServiceDescription SERVICE_DESCRIPTION_SLM = 173 new ServiceDescription( 174 RcsContactPresenceTuple.SERVICE_ID_SLM, 175 "2.0" /*version*/, 176 null /*description*/ 177 ); 178 179 public static final ServiceDescription SERVICE_DESCRIPTION_SLM_PAGER_LARGE = 180 new ServiceDescription( 181 RcsContactPresenceTuple.SERVICE_ID_SLM, 182 "2.0" /*version*/, 183 "Standalone Messaging" /*description*/ 184 ); 185 186 /** Mandatory "service-id" element */ 187 public final @NonNull String serviceId; 188 /** Mandatory "version" element */ 189 public final @NonNull String version; 190 /** Optional "description" element */ 191 public final @Nullable String description; 192 ServiceDescription(String serviceId, String version, String description)193 public ServiceDescription(String serviceId, String version, String description) { 194 this.serviceId = serviceId; 195 this.version = version; 196 this.description = description; 197 } 198 getTupleBuilder()199 public RcsContactPresenceTuple.Builder getTupleBuilder() { 200 RcsContactPresenceTuple.Builder b = new RcsContactPresenceTuple.Builder( 201 RcsContactPresenceTuple.TUPLE_BASIC_STATUS_OPEN, serviceId, version); 202 if (!TextUtils.isEmpty(description)) { 203 b.setServiceDescription(description); 204 } 205 return b; 206 } 207 208 @Override equals(Object o)209 public boolean equals(Object o) { 210 if (this == o) return true; 211 if (o == null || getClass() != o.getClass()) return false; 212 ServiceDescription that = (ServiceDescription) o; 213 return serviceId.equals(that.serviceId) 214 && version.equals(that.version) 215 && Objects.equals(description, that.description); 216 } 217 218 @Override hashCode()219 public int hashCode() { 220 return Objects.hash(serviceId, version, description); 221 } 222 223 @Override toString()224 public String toString() { 225 return "(id=" + serviceId + ", v=" + version + ", d=" + description + ')'; 226 } 227 } 228