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