3636 * A Short Message Service message.
3737 */
3838public class SmsMessage {
39- private static final boolean LOCAL_DEBUG = true ;
4039 private static final String LOG_TAG = "SMS" ;
4140
4241 /**
@@ -78,6 +77,18 @@ public enum MessageClass{
7877 */
7978 public static final int MAX_USER_DATA_SEPTETS_WITH_HEADER = 153 ;
8079
80+ /**
81+ * Indicates a 3GPP format SMS message.
82+ * @hide pending API council approval
83+ */
84+ public static final String FORMAT_3GPP = "3gpp" ;
85+
86+ /**
87+ * Indicates a 3GPP2 format SMS message.
88+ * @hide pending API council approval
89+ */
90+ public static final String FORMAT_3GPP2 = "3gpp2" ;
91+
8192 /** Contains actual SmsMessage. Only public for debugging and for framework layer.
8293 *
8394 * @hide
@@ -106,30 +117,47 @@ protected SubmitPdu(SubmitPduBase spb) {
106117
107118 }
108119
109- /**
110- * Constructor
111- *
112- * @hide
113- */
114- public SmsMessage () {
115- this (getSmsFacility ());
116- }
117-
118120 private SmsMessage (SmsMessageBase smb ) {
119121 mWrappedSmsMessage = smb ;
120122 }
121123
122124 /**
123125 * Create an SmsMessage from a raw PDU.
126+ *
127+ * <p><b>This method will soon be deprecated</b> and all applications which handle
128+ * incoming SMS messages by processing the {@code SMS_RECEIVED_ACTION} broadcast
129+ * intent <b>must</b> now pass the new {@code format} String extra from the intent
130+ * into the new method {@code createFromPdu(byte[], String)} which takes an
131+ * extra format parameter. This is required in order to correctly decode the PDU on
132+ * devices that require support for both 3GPP and 3GPP2 formats at the same time,
133+ * such as dual-mode GSM/CDMA and CDMA/LTE phones.
124134 */
125135 public static SmsMessage createFromPdu (byte [] pdu ) {
126- SmsMessageBase wrappedMessage ;
127136 int activePhone = TelephonyManager .getDefault ().getCurrentPhoneType ();
137+ String format = (PHONE_TYPE_CDMA == activePhone ) ? FORMAT_3GPP2 : FORMAT_3GPP ;
138+ return createFromPdu (pdu , format );
139+ }
128140
129- if (PHONE_TYPE_CDMA == activePhone ) {
141+ /**
142+ * Create an SmsMessage from a raw PDU with the specified message format. The
143+ * message format is passed in the {@code SMS_RECEIVED_ACTION} as the {@code format}
144+ * String extra, and will be either "3gpp" for GSM/UMTS/LTE messages in 3GPP format
145+ * or "3gpp2" for CDMA/LTE messages in 3GPP2 format.
146+ *
147+ * @param pdu the message PDU from the SMS_RECEIVED_ACTION intent
148+ * @param format the format extra from the SMS_RECEIVED_ACTION intent
149+ * @hide pending API council approval
150+ */
151+ public static SmsMessage createFromPdu (byte [] pdu , String format ) {
152+ SmsMessageBase wrappedMessage ;
153+
154+ if (FORMAT_3GPP2 .equals (format )) {
130155 wrappedMessage = com .android .internal .telephony .cdma .SmsMessage .createFromPdu (pdu );
131- } else {
156+ } else if ( FORMAT_3GPP . equals ( format )) {
132157 wrappedMessage = com .android .internal .telephony .gsm .SmsMessage .createFromPdu (pdu );
158+ } else {
159+ Log .e (LOG_TAG , "createFromPdu(): unsupported message format " + format );
160+ return null ;
133161 }
134162
135163 return new SmsMessage (wrappedMessage );
@@ -144,57 +172,19 @@ public static SmsMessage createFromPdu(byte[] pdu) {
144172 *
145173 * {@hide}
146174 */
147- public static SmsMessage newFromCMT (String [] lines ){
148- SmsMessageBase wrappedMessage ;
149- int activePhone = TelephonyManager .getDefault ().getCurrentPhoneType ();
150-
151- if (PHONE_TYPE_CDMA == activePhone ) {
152- wrappedMessage = com .android .internal .telephony .cdma .SmsMessage .newFromCMT (lines );
153- } else {
154- wrappedMessage = com .android .internal .telephony .gsm .SmsMessage .newFromCMT (lines );
155- }
156-
157- return new SmsMessage (wrappedMessage );
158- }
159-
160- /** @hide */
161- protected static SmsMessage newFromCMTI (String line ) {
162- SmsMessageBase wrappedMessage ;
163- int activePhone = TelephonyManager .getDefault ().getCurrentPhoneType ();
164-
165- if (PHONE_TYPE_CDMA == activePhone ) {
166- wrappedMessage = com .android .internal .telephony .cdma .SmsMessage .newFromCMTI (line );
167- } else {
168- wrappedMessage = com .android .internal .telephony .gsm .SmsMessage .newFromCMTI (line );
169- }
170-
171- return new SmsMessage (wrappedMessage );
172- }
173-
174- /** @hide */
175- public static SmsMessage newFromCDS (String line ) {
176- SmsMessageBase wrappedMessage ;
177- int activePhone = TelephonyManager .getDefault ().getCurrentPhoneType ();
178-
179- if (PHONE_TYPE_CDMA == activePhone ) {
180- wrappedMessage = com .android .internal .telephony .cdma .SmsMessage .newFromCDS (line );
181- } else {
182- wrappedMessage = com .android .internal .telephony .gsm .SmsMessage .newFromCDS (line );
183- }
175+ public static SmsMessage newFromCMT (String [] lines ) {
176+ // received SMS in 3GPP format
177+ SmsMessageBase wrappedMessage =
178+ com .android .internal .telephony .gsm .SmsMessage .newFromCMT (lines );
184179
185180 return new SmsMessage (wrappedMessage );
186181 }
187182
188183 /** @hide */
189184 public static SmsMessage newFromParcel (Parcel p ) {
190- SmsMessageBase wrappedMessage ;
191- int activePhone = TelephonyManager .getDefault ().getCurrentPhoneType ();
192-
193- if (PHONE_TYPE_CDMA == activePhone ) {
194- wrappedMessage = com .android .internal .telephony .cdma .SmsMessage .newFromParcel (p );
195- } else {
196- wrappedMessage = com .android .internal .telephony .gsm .SmsMessage .newFromParcel (p );
197- }
185+ // received SMS in 3GPP2 format
186+ SmsMessageBase wrappedMessage =
187+ com .android .internal .telephony .cdma .SmsMessage .newFromParcel (p );
198188
199189 return new SmsMessage (wrappedMessage );
200190 }
@@ -227,6 +217,9 @@ public static SmsMessage createFromEfRecord(int index, byte[] data) {
227217 /**
228218 * Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the
229219 * length in bytes (not hex chars) less the SMSC header
220+ *
221+ * FIXME: This method is only used by a CTS test case that isn't run on CDMA devices.
222+ * We should probably deprecate it and remove the obsolete test case.
230223 */
231224 public static int getTPLayerLengthForPDU (String pdu ) {
232225 int activePhone = TelephonyManager .getDefault ().getCurrentPhoneType ();
@@ -373,34 +366,6 @@ public static int[] calculateLength(String messageBody, boolean use7bitOnly) {
373366 * otherwise useful apps.
374367 */
375368
376- /**
377- * Get an SMS-SUBMIT PDU for a destination address and a message.
378- * This method will not attempt to use any GSM national language 7 bit encodings.
379- *
380- * @param scAddress Service Centre address. Null means use default.
381- * @return a <code>SubmitPdu</code> containing the encoded SC
382- * address, if applicable, and the encoded message.
383- * Returns null on encode error.
384- * @hide
385- */
386- public static SubmitPdu getSubmitPdu (String scAddress ,
387- String destinationAddress , String message ,
388- boolean statusReportRequested , byte [] header ) {
389- SubmitPduBase spb ;
390- int activePhone = TelephonyManager .getDefault ().getCurrentPhoneType ();
391-
392- if (PHONE_TYPE_CDMA == activePhone ) {
393- spb = com .android .internal .telephony .cdma .SmsMessage .getSubmitPdu (scAddress ,
394- destinationAddress , message , statusReportRequested ,
395- SmsHeader .fromByteArray (header ));
396- } else {
397- spb = com .android .internal .telephony .gsm .SmsMessage .getSubmitPdu (scAddress ,
398- destinationAddress , message , statusReportRequested , header );
399- }
400-
401- return new SubmitPdu (spb );
402- }
403-
404369 /**
405370 * Get an SMS-SUBMIT PDU for a destination address and a message.
406371 * This method will not attempt to use any GSM national language 7 bit encodings.
@@ -602,15 +567,6 @@ public byte[] getUserData() {
602567 return mWrappedSmsMessage .getUserData ();
603568 }
604569
605- /**
606- * Return the user data header (UDH).
607- *
608- * @hide
609- */
610- public SmsHeader getUserDataHeader () {
611- return mWrappedSmsMessage .getUserDataHeader ();
612- }
613-
614570 /**
615571 * Returns the raw PDU for the message.
616572 *
@@ -646,7 +602,6 @@ public byte[] getPdu() {
646602 * SmsManager.STATUS_ON_ICC_UNSENT
647603 */
648604 public int getStatusOnIcc () {
649-
650605 return mWrappedSmsMessage .getStatusOnIcc ();
651606 }
652607
@@ -666,7 +621,6 @@ public int getStatusOnIcc() {
666621 * SmsMessage was not created from a ICC SMS EF record.
667622 */
668623 public int getIndexOnIcc () {
669-
670624 return mWrappedSmsMessage .getIndexOnIcc ();
671625 }
672626
@@ -704,19 +658,4 @@ public boolean isStatusReportMessage() {
704658 public boolean isReplyPathPresent () {
705659 return mWrappedSmsMessage .isReplyPathPresent ();
706660 }
707-
708- /** This method returns the reference to a specific
709- * SmsMessage object, which is used for accessing its static methods.
710- * @return Specific SmsMessage.
711- *
712- * @hide
713- */
714- private static final SmsMessageBase getSmsFacility (){
715- int activePhone = TelephonyManager .getDefault ().getCurrentPhoneType ();
716- if (PHONE_TYPE_CDMA == activePhone ) {
717- return new com .android .internal .telephony .cdma .SmsMessage ();
718- } else {
719- return new com .android .internal .telephony .gsm .SmsMessage ();
720- }
721- }
722661}
0 commit comments