1 /* 2 * Copyright (C) 2018 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.internal.telephony.util; 18 19 import com.android.internal.telephony.GsmAlphabet.TextEncodingDetails; 20 import com.android.internal.telephony.ImsSmsDispatcher; 21 import com.android.internal.telephony.SmsHeader; 22 import com.android.internal.telephony.SmsMessageBase; 23 import com.android.internal.telephony.cdma.CdmaSMSDispatcher; 24 import com.android.internal.telephony.gsm.GsmSMSDispatcher; 25 26 /** 27 * Utilities used by {@link com.android.internal.telephony.SMSDispatcher}'s subclasses. 28 * 29 * These methods can not be moved to {@link CdmaSMSDispatcher} and {@link GsmSMSDispatcher} because 30 * they also need to be called from {@link ImsSmsDispatcher} and the utilities will invoke the cdma 31 * or gsm version of the method based on the format. 32 */ 33 public final class SMSDispatcherUtil { 34 // Prevent instantiation. SMSDispatcherUtil()35 private SMSDispatcherUtil() {} 36 37 /** 38 * Trigger the proper implementation for getting submit pdu for text sms based on format. 39 * 40 * @param isCdma true if cdma format should be used. 41 * @param scAddr is the service center address or null to use the current default SMSC 42 * @param destAddr the address to send the message to 43 * @param message the body of the message. 44 * @param statusReportRequested whether or not a status report is requested. 45 * @param smsHeader message header. 46 * @return the submit pdu. 47 */ getSubmitPdu(boolean isCdma, String scAddr, String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader)48 public static SmsMessageBase.SubmitPduBase getSubmitPdu(boolean isCdma, String scAddr, 49 String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader) { 50 if (isCdma) { 51 return getSubmitPduCdma(scAddr, destAddr, message, statusReportRequested, smsHeader); 52 } else { 53 return getSubmitPduGsm(scAddr, destAddr, message, statusReportRequested); 54 } 55 } 56 57 /** 58 * Trigger the proper implementation for getting submit pdu for text sms based on format. 59 * 60 * @param isCdma true if cdma format should be used. 61 * @param scAddr is the service center address or null to use the current default SMSC 62 * @param destAddr the address to send the message to 63 * @param message the body of the message. 64 * @param statusReportRequested whether or not a status report is requested. 65 * @param smsHeader message header. 66 * @param priority Priority level of the message 67 * Refer specification See 3GPP2 C.S0015-B, v2.0, table 4.5.9-1 68 * --------------------------------- 69 * PRIORITY | Level of Priority 70 * --------------------------------- 71 * '00' | Normal 72 * '01' | Interactive 73 * '10' | Urgent 74 * '11' | Emergency 75 * ---------------------------------- 76 * Any Other values included Negative considered as Invalid Priority Indicator of the message. 77 * @param validityPeriod Validity Period of the message in mins. 78 * Refer specification 3GPP TS 23.040 V6.8.1 section 9.2.3.12.1. 79 * Validity Period(Minimum) -> 5 mins 80 * Validity Period(Maximum) -> 635040 mins(i.e.63 weeks). 81 * Any Other values included Negative considered as Invalid Validity Period of the message. 82 * @return the submit pdu. 83 */ getSubmitPdu(boolean isCdma, String scAddr, String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader, int priority, int validityPeriod)84 public static SmsMessageBase.SubmitPduBase getSubmitPdu(boolean isCdma, String scAddr, 85 String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader, 86 int priority, int validityPeriod) { 87 if (isCdma) { 88 return getSubmitPduCdma(scAddr, destAddr, message, statusReportRequested, smsHeader, 89 priority); 90 } else { 91 return getSubmitPduGsm(scAddr, destAddr, message, statusReportRequested, 92 validityPeriod); 93 } 94 } 95 96 /** 97 * Trigger the proper implementation for getting submit pdu for text sms based on format. 98 * 99 * @param isCdma true if cdma format should be used. 100 * @param scAddr is the service center address or null to use the current default SMSC 101 * @param destAddr the address to send the message to 102 * @param message the body of the message. 103 * @param statusReportRequested whether or not a status report is requested. 104 * @param smsHeader message header. 105 * @param priority Priority level of the message 106 * Refer specification See 3GPP2 C.S0015-B, v2.0, table 4.5.9-1 107 * --------------------------------- 108 * PRIORITY | Level of Priority 109 * --------------------------------- 110 * '00' | Normal 111 * '01' | Interactive 112 * '10' | Urgent 113 * '11' | Emergency 114 * ---------------------------------- 115 * Any Other values included Negative considered as Invalid Priority Indicator of the message. 116 * @param validityPeriod Validity Period of the message in mins. 117 * Refer specification 3GPP TS 23.040 V6.8.1 section 9.2.3.12.1. 118 * Validity Period(Minimum) -> 5 mins 119 * Validity Period(Maximum) -> 635040 mins(i.e.63 weeks). 120 * Any Other values included Negative considered as Invalid Validity Period of the message. 121 * @param messageRef TP Message Reference number 122 * @return the submit pdu. 123 */ getSubmitPdu(boolean isCdma, String scAddr, String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader, int priority, int validityPeriod, int messageRef)124 public static SmsMessageBase.SubmitPduBase getSubmitPdu(boolean isCdma, String scAddr, 125 String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader, 126 int priority, int validityPeriod, int messageRef) { 127 if (isCdma) { 128 return getSubmitPduCdma(scAddr, destAddr, message, statusReportRequested, smsHeader, 129 priority); 130 } else { 131 return getSubmitPduGsm(scAddr, destAddr, message, statusReportRequested, 132 validityPeriod, messageRef); 133 } 134 } 135 136 /** 137 * Gsm implementation for 138 * {@link #getSubmitPdu(boolean, String, String, String, boolean)} 139 * 140 * @param scAddr is the service center address or null to use the current default SMSC 141 * @param destAddr the address to send the message to 142 * @param message the body of the message. 143 * @param statusReportRequested whether or not a status report is requested. 144 * @return the submit pdu. 145 */ getSubmitPduGsm(String scAddr, String destAddr, String message, boolean statusReportRequested)146 public static SmsMessageBase.SubmitPduBase getSubmitPduGsm(String scAddr, String destAddr, 147 String message, boolean statusReportRequested) { 148 return com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddr, destAddr, message, 149 statusReportRequested); 150 } 151 152 /** 153 * Gsm implementation for 154 * {@link #getSubmitPdu(boolean, String, String, String, boolean, int)} 155 * 156 * @param scAddr is the service center address or null to use the current default SMSC 157 * @param destAddr the address to send the message to 158 * @param message the body of the message. 159 * @param statusReportRequested whether or not a status report is requested. 160 * @param validityPeriod Validity Period of the message in mins. 161 * Refer specification 3GPP TS 23.040 V6.8.1 section 9.2.3.12.1. 162 * Validity Period(Minimum) -> 5 mins 163 * Validity Period(Maximum) -> 635040 mins(i.e.63 weeks). 164 * Any Other values included Negative considered as Invalid Validity Period of the message. 165 * @return the submit pdu. 166 */ getSubmitPduGsm(String scAddr, String destAddr, String message, boolean statusReportRequested, int validityPeriod)167 public static SmsMessageBase.SubmitPduBase getSubmitPduGsm(String scAddr, String destAddr, 168 String message, boolean statusReportRequested, int validityPeriod) { 169 return com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddr, destAddr, message, 170 statusReportRequested, validityPeriod); 171 } 172 173 /** 174 * Gsm implementation for 175 * {@link #getSubmitPdu(boolean, String, String, String, boolean, int)} 176 * 177 * @param scAddr is the service center address or null to use the current default SMSC 178 * @param destAddr the address to send the message to 179 * @param message the body of the message. 180 * @param statusReportRequested whether or not a status report is requested. 181 * @param validityPeriod Validity Period of the message in mins. 182 * Refer specification 3GPP TS 23.040 V6.8.1 section 9.2.3.12.1. 183 * Validity Period(Minimum) -> 5 mins 184 * Validity Period(Maximum) -> 635040 mins(i.e.63 weeks). 185 * Any Other values included Negative considered as Invalid Validity Period of the message. 186 * @param messageRef TP Message Reference number 187 * @return the submit pdu. 188 */ getSubmitPduGsm(String scAddr, String destAddr, String message, boolean statusReportRequested, int validityPeriod, int messageRef)189 public static SmsMessageBase.SubmitPduBase getSubmitPduGsm(String scAddr, String destAddr, 190 String message, boolean statusReportRequested, int validityPeriod, int messageRef) { 191 return com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddr, destAddr, message, 192 statusReportRequested, null, 0, 0, 0, validityPeriod, messageRef); 193 } 194 195 /** 196 * Cdma implementation for 197 * {@link #getSubmitPdu(boolean, String, String, String, boolean, SmsHeader)} 198 * 199 * @param scAddr is the service center address or null to use the current default SMSC 200 * @param destAddr the address to send the message to 201 * @param message the body of the message. 202 * @param statusReportRequested whether or not a status report is requested. 203 * @param smsHeader message header. 204 * @return the submit pdu. 205 */ getSubmitPduCdma(String scAddr, String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader)206 public static SmsMessageBase.SubmitPduBase getSubmitPduCdma(String scAddr, String destAddr, 207 String message, boolean statusReportRequested, SmsHeader smsHeader) { 208 return com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddr, destAddr, 209 message, statusReportRequested, smsHeader); 210 } 211 212 /** 213 * Cdma implementation for 214 * {@link #getSubmitPdu(boolean, String, String, String, boolean, SmsHeader)} 215 * 216 * @param scAddr is the service center address or null to use the current default SMSC 217 * @param destAddr the address to send the message to 218 * @param message the body of the message. 219 * @param statusReportRequested whether or not a status report is requested. 220 * @param smsHeader message header. 221 * @param priority Priority level of the message 222 * Refer specification See 3GPP2 C.S0015-B, v2.0, table 4.5.9-1 223 * --------------------------------- 224 * PRIORITY | Level of Priority 225 * --------------------------------- 226 * '00' | Normal 227 * '01' | Interactive 228 * '10' | Urgent 229 * '11' | Emergency 230 * ---------------------------------- 231 * Any Other values included Negative considered as Invalid Priority Indicator of the message. 232 * @return the submit pdu. 233 */ getSubmitPduCdma(String scAddr, String destAddr, String message, boolean statusReportRequested, SmsHeader smsHeader, int priority)234 public static SmsMessageBase.SubmitPduBase getSubmitPduCdma(String scAddr, String destAddr, 235 String message, boolean statusReportRequested, SmsHeader smsHeader, int priority) { 236 return com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddr, destAddr, 237 message, statusReportRequested, smsHeader, priority); 238 } 239 240 /** 241 * Trigger the proper implementation for getting submit pdu for data sms based on format. 242 * 243 * @param isCdma true if cdma format should be used. 244 * @param destAddr the address to send the message to 245 * @param scAddr is the service center address or null to use the current default SMSC 246 * @param destPort the port to deliver the message to 247 * @param message the body of the message to send 248 * @param statusReportRequested whether or not a status report is requested. 249 * @return the submit pdu. 250 */ getSubmitPdu(boolean isCdma, String scAddr, String destAddr, int destPort, byte[] message, boolean statusReportRequested)251 public static SmsMessageBase.SubmitPduBase getSubmitPdu(boolean isCdma, String scAddr, 252 String destAddr, int destPort, byte[] message, boolean statusReportRequested) { 253 if (isCdma) { 254 return getSubmitPduCdma(scAddr, destAddr, destPort, message, statusReportRequested); 255 } else { 256 return getSubmitPduGsm(scAddr, destAddr, destPort, message, statusReportRequested); 257 } 258 } 259 260 /** 261 * Trigger the proper implementation for getting submit pdu for data sms based on format. 262 * 263 * @param isCdma true if cdma format should be used. 264 * @param destAddr the address to send the message to 265 * @param scAddr is the service center address or null to use the current default SMSC 266 * @param destPort the port to deliver the message to 267 * @param message the body of the message to send 268 * @param statusReportRequested whether or not a status report is requested. 269 * @param messageRef TP Message Reference number 270 * @return the submit pdu. 271 */ getSubmitPdu(boolean isCdma, String scAddr, String destAddr, int destPort, byte[] message, boolean statusReportRequested, int messageRef)272 public static SmsMessageBase.SubmitPduBase getSubmitPdu(boolean isCdma, String scAddr, 273 String destAddr, int destPort, byte[] message, boolean statusReportRequested, 274 int messageRef) { 275 if (isCdma) { 276 return getSubmitPduCdma(scAddr, destAddr, destPort, message, statusReportRequested); 277 } else { 278 return getSubmitPduGsm(scAddr, destAddr, destPort, message, statusReportRequested, 279 messageRef); 280 } 281 } 282 283 /** 284 * Cdma implementation of {@link #getSubmitPdu(boolean, String, String, int, byte[], boolean)} 285 286 * @param destAddr the address to send the message to 287 * @param scAddr is the service center address or null to use the current default SMSC 288 * @param destPort the port to deliver the message to 289 * @param message the body of the message to send 290 * @param statusReportRequested whether or not a status report is requested. 291 * @return the submit pdu. 292 */ getSubmitPduCdma(String scAddr, String destAddr, int destPort, byte[] message, boolean statusReportRequested)293 public static SmsMessageBase.SubmitPduBase getSubmitPduCdma(String scAddr, String destAddr, 294 int destPort, byte[] message, boolean statusReportRequested) { 295 return com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddr, destAddr, 296 destPort, message, statusReportRequested); 297 } 298 299 /** 300 * Gsm implementation of {@link #getSubmitPdu(boolean, String, String, int, byte[], boolean)} 301 * 302 * @param destAddr the address to send the message to 303 * @param scAddr is the service center address or null to use the current default SMSC 304 * @param destPort the port to deliver the message to 305 * @param message the body of the message to send 306 * @param statusReportRequested whether or not a status report is requested. 307 * @return the submit pdu. 308 */ getSubmitPduGsm(String scAddr, String destAddr, int destPort, byte[] message, boolean statusReportRequested)309 public static SmsMessageBase.SubmitPduBase getSubmitPduGsm(String scAddr, String destAddr, 310 int destPort, byte[] message, boolean statusReportRequested) { 311 return com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddr, destAddr, 312 destPort, message, statusReportRequested); 313 314 } 315 316 /** 317 * Gsm implementation of {@link #getSubmitPdu(boolean, String, String, int, byte[], boolean)} 318 * 319 * @param destAddr the address to send the message to 320 * @param scAddr is the service center address or null to use the current default SMSC 321 * @param destPort the port to deliver the message to 322 * @param message the body of the message to send 323 * @param statusReportRequested whether or not a status report is requested. 324 * @return the submit pdu. 325 */ getSubmitPduGsm(String scAddr, String destAddr, int destPort, byte[] message, boolean statusReportRequested, int messageRef)326 public static SmsMessageBase.SubmitPduBase getSubmitPduGsm(String scAddr, String destAddr, 327 int destPort, byte[] message, boolean statusReportRequested, int messageRef) { 328 return com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddr, destAddr, 329 destPort, message, statusReportRequested, messageRef); 330 } 331 332 /** 333 * Calculate the number of septets needed to encode the message. This function should only be 334 * called for individual segments of multipart message. 335 * 336 * @param isCdma true if cdma format should be used. 337 * @param messageBody the message to encode 338 * @param use7bitOnly ignore (but still count) illegal characters if true 339 * @return TextEncodingDetails 340 */ calculateLength(boolean isCdma, CharSequence messageBody, boolean use7bitOnly)341 public static TextEncodingDetails calculateLength(boolean isCdma, CharSequence messageBody, 342 boolean use7bitOnly) { 343 if (isCdma) { 344 return calculateLengthCdma(messageBody, use7bitOnly); 345 } else { 346 return calculateLengthGsm(messageBody, use7bitOnly); 347 } 348 } 349 350 /** 351 * Gsm implementation for {@link #calculateLength(boolean, CharSequence, boolean)} 352 * 353 * @param messageBody the message to encode 354 * @param use7bitOnly ignore (but still count) illegal characters if true 355 * @return TextEncodingDetails 356 */ calculateLengthGsm(CharSequence messageBody, boolean use7bitOnly)357 public static TextEncodingDetails calculateLengthGsm(CharSequence messageBody, 358 boolean use7bitOnly) { 359 return com.android.internal.telephony.gsm.SmsMessage.calculateLength(messageBody, 360 use7bitOnly); 361 362 } 363 364 /** 365 * Cdma implementation for {@link #calculateLength(boolean, CharSequence, boolean)} 366 * 367 * @param messageBody the message to encode 368 * @param use7bitOnly ignore (but still count) illegal characters if true 369 * @return TextEncodingDetails 370 */ calculateLengthCdma(CharSequence messageBody, boolean use7bitOnly)371 public static TextEncodingDetails calculateLengthCdma(CharSequence messageBody, 372 boolean use7bitOnly) { 373 return com.android.internal.telephony.cdma.SmsMessage.calculateLength(messageBody, 374 use7bitOnly, false); 375 } 376 } 377