1/*
2 * Copyright (C) 2008 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
17package android.telephony.gsm;
18
19import android.telephony.TelephonyManager;
20
21import com.android.internal.telephony.GsmAlphabet;
22import com.android.internal.telephony.SmsHeader;
23import com.android.internal.telephony.SmsMessageBase;
24import com.android.internal.telephony.SmsMessageBase.SubmitPduBase;
25
26import java.util.Arrays;
27
28import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;
29
30
31/**
32 * A Short Message Service message.
33 * @deprecated Replaced by android.telephony.SmsMessage that supports both GSM and CDMA.
34 */
35@Deprecated
36public class SmsMessage {
37    /**
38     * SMS Class enumeration.
39     * See TS 23.038.
40     * @deprecated Use android.telephony.SmsMessage.
41     */
42    @Deprecated
43    public enum MessageClass{
44        UNKNOWN, CLASS_0, CLASS_1, CLASS_2, CLASS_3;
45    }
46
47    /** Unknown encoding scheme (see TS 23.038)
48     * @deprecated Use android.telephony.SmsMessage.
49     */
50    @Deprecated public static final int ENCODING_UNKNOWN = 0;
51
52    /** 7-bit encoding scheme (see TS 23.038)
53     * @deprecated Use android.telephony.SmsMessage.
54     */
55    @Deprecated public static final int ENCODING_7BIT = 1;
56
57    /** 8-bit encoding scheme (see TS 23.038)
58     * @deprecated Use android.telephony.SmsMessage.
59     */
60    @Deprecated public static final int ENCODING_8BIT = 2;
61
62    /** 16-bit encoding scheme (see TS 23.038)
63     * @deprecated Use android.telephony.SmsMessage.
64     */
65    @Deprecated public static final int ENCODING_16BIT = 3;
66
67    /** The maximum number of payload bytes per message
68     * @deprecated Use android.telephony.SmsMessage.
69     */
70    @Deprecated public static final int MAX_USER_DATA_BYTES = 140;
71
72    /**
73     * The maximum number of payload bytes per message if a user data header
74     * is present.  This assumes the header only contains the
75     * CONCATENATED_8_BIT_REFERENCE element.
76     *
77     * @deprecated Use android.telephony.SmsMessage.
78     * @hide pending API Council approval to extend the public API
79     */
80    @Deprecated public static final int MAX_USER_DATA_BYTES_WITH_HEADER = 134;
81
82    /** The maximum number of payload septets per message
83     * @deprecated Use android.telephony.SmsMessage.
84     */
85    @Deprecated public static final int MAX_USER_DATA_SEPTETS = 160;
86
87    /**
88     * The maximum number of payload septets per message if a user data header
89     * is present.  This assumes the header only contains the
90     * CONCATENATED_8_BIT_REFERENCE element.
91     * @deprecated Use android.telephony.SmsMessage.
92     */
93    @Deprecated public static final int MAX_USER_DATA_SEPTETS_WITH_HEADER = 153;
94
95    /** Contains actual SmsMessage. Only public for debugging and for framework layer.
96     * @deprecated Use android.telephony.SmsMessage.
97     * {@hide}
98     */
99    @Deprecated public SmsMessageBase mWrappedSmsMessage;
100
101    /** @deprecated Use android.telephony.SmsMessage. */
102    @Deprecated
103    public static class SubmitPdu {
104        /** @deprecated Use android.telephony.SmsMessage. */
105        @Deprecated public byte[] encodedScAddress; // Null if not applicable.
106        /** @deprecated Use android.telephony.SmsMessage. */
107        @Deprecated public byte[] encodedMessage;
108
109        //Constructor
110        /** @deprecated Use android.telephony.SmsMessage. */
111        @Deprecated
112        public SubmitPdu() {
113        }
114
115        /** @deprecated Use android.telephony.SmsMessage.
116         * {@hide}
117         */
118        @Deprecated
119        protected SubmitPdu(SubmitPduBase spb) {
120            this.encodedMessage = spb.encodedMessage;
121            this.encodedScAddress = spb.encodedScAddress;
122        }
123
124        /** @deprecated Use android.telephony.SmsMessage. */
125        @Override
126        @Deprecated
127        public String toString() {
128            return "SubmitPdu: encodedScAddress = "
129                    + Arrays.toString(encodedScAddress)
130                    + ", encodedMessage = "
131                    + Arrays.toString(encodedMessage);
132        }
133    }
134
135    // Constructor
136    /** @deprecated Use android.telephony.SmsMessage. */
137    @Deprecated
138    public SmsMessage() {
139        this(getSmsFacility());
140    }
141
142    private SmsMessage(SmsMessageBase smb) {
143        mWrappedSmsMessage = smb;
144    }
145
146    /**
147     * Create an SmsMessage from a raw PDU.
148     * @deprecated Use android.telephony.SmsMessage.
149     */
150    @Deprecated
151    public static SmsMessage createFromPdu(byte[] pdu) {
152        SmsMessageBase wrappedMessage;
153        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
154
155        if (PHONE_TYPE_CDMA == activePhone) {
156            wrappedMessage = com.android.internal.telephony.cdma.SmsMessage.createFromPdu(pdu);
157        } else {
158            wrappedMessage = com.android.internal.telephony.gsm.SmsMessage.createFromPdu(pdu);
159        }
160
161        return new SmsMessage(wrappedMessage);
162    }
163
164    /**
165     * Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the
166     * length in bytes (not hex chars) less the SMSC header
167     * @deprecated Use android.telephony.SmsMessage.
168     */
169    @Deprecated
170    public static int getTPLayerLengthForPDU(String pdu) {
171        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
172
173        if (PHONE_TYPE_CDMA == activePhone) {
174            return com.android.internal.telephony.cdma.SmsMessage.getTPLayerLengthForPDU(pdu);
175        } else {
176            return com.android.internal.telephony.gsm.SmsMessage.getTPLayerLengthForPDU(pdu);
177        }
178    }
179
180    /**
181     * Calculates the number of SMS's required to encode the message body and
182     * the number of characters remaining until the next message, given the
183     * current encoding.
184     *
185     * @param messageBody the message to encode
186     * @param use7bitOnly if true, characters that are not part of the GSM
187     *         alphabet are counted as a single space char.  If false, a
188     *         messageBody containing non-GSM alphabet characters is calculated
189     *         for 16-bit encoding.
190     * @return an int[4] with int[0] being the number of SMS's required, int[1]
191     *         the number of code units used, and int[2] is the number of code
192     *         units remaining until the next message. int[3] is the encoding
193     *         type that should be used for the message.
194     * @deprecated Use android.telephony.SmsMessage.
195     */
196    @Deprecated
197    public static int[] calculateLength(CharSequence messageBody, boolean use7bitOnly) {
198        GsmAlphabet.TextEncodingDetails ted =
199                com.android.internal.telephony.gsm.SmsMessage
200                        .calculateLength(messageBody, use7bitOnly);
201        int ret[] = new int[4];
202        ret[0] = ted.msgCount;
203        ret[1] = ted.codeUnitCount;
204        ret[2] = ted.codeUnitsRemaining;
205        ret[3] = ted.codeUnitSize;
206        return ret;
207    }
208
209    /**
210     * Calculates the number of SMS's required to encode the message body and
211     * the number of characters remaining until the next message, given the
212     * current encoding.
213     *
214     * @param messageBody the message to encode
215     * @param use7bitOnly if true, characters that are not part of the GSM
216     *         alphabet are counted as a single space char.  If false, a
217     *         messageBody containing non-GSM alphabet characters is calculated
218     *         for 16-bit encoding.
219     * @return an int[4] with int[0] being the number of SMS's required, int[1]
220     *         the number of code units used, and int[2] is the number of code
221     *         units remaining until the next message. int[3] is the encoding
222     *         type that should be used for the message.
223     * @deprecated Use android.telephony.SmsMessage.
224     */
225    @Deprecated
226    public static int[] calculateLength(String messageBody, boolean use7bitOnly) {
227        return calculateLength((CharSequence)messageBody, use7bitOnly);
228    }
229
230    /**
231     * Get an SMS-SUBMIT PDU for a destination address and a message
232     *
233     * @param scAddress Service Centre address.  Null means use default.
234     * @return a <code>SubmitPdu</code> containing the encoded SC
235     *         address, if applicable, and the encoded message.
236     *         Returns null on encode error.
237     * @deprecated Use android.telephony.SmsMessage.
238     * @hide
239     */
240    @Deprecated
241    public static SubmitPdu getSubmitPdu(String scAddress,
242            String destinationAddress, String message,
243            boolean statusReportRequested, byte[] header) {
244        SubmitPduBase spb;
245        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
246
247        if (PHONE_TYPE_CDMA == activePhone) {
248            spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress,
249                    destinationAddress, message, statusReportRequested,
250                    SmsHeader.fromByteArray(header));
251        } else {
252            spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
253                    destinationAddress, message, statusReportRequested, header);
254        }
255
256        return new SubmitPdu(spb);
257    }
258
259    /**
260     * Get an SMS-SUBMIT PDU for a destination address and a message
261     *
262     * @param scAddress Service Centre address.  Null means use default.
263     * @return a <code>SubmitPdu</code> containing the encoded SC
264     *         address, if applicable, and the encoded message.
265     *         Returns null on encode error.
266     * @deprecated Use android.telephony.SmsMessage.
267     */
268    @Deprecated
269    public static SubmitPdu getSubmitPdu(String scAddress,
270            String destinationAddress, String message, boolean statusReportRequested) {
271        SubmitPduBase spb;
272        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
273
274        if (PHONE_TYPE_CDMA == activePhone) {
275            spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress,
276                    destinationAddress, message, statusReportRequested, null);
277        } else {
278            spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
279                    destinationAddress, message, statusReportRequested);
280        }
281
282        return new SubmitPdu(spb);
283    }
284
285    /**
286     * Get an SMS-SUBMIT PDU for a data message to a destination address &amp; port
287     *
288     * @param scAddress Service Centre address. null == use default
289     * @param destinationAddress the address of the destination for the message
290     * @param destinationPort the port to deliver the message to at the
291     *        destination
292     * @param data the dat for the message
293     * @return a <code>SubmitPdu</code> containing the encoded SC
294     *         address, if applicable, and the encoded message.
295     *         Returns null on encode error.
296     * @deprecated Use android.telephony.SmsMessage.
297     */
298    @Deprecated
299    public static SubmitPdu getSubmitPdu(String scAddress,
300            String destinationAddress, short destinationPort, byte[] data,
301            boolean statusReportRequested) {
302        SubmitPduBase spb;
303        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
304
305        if (PHONE_TYPE_CDMA == activePhone) {
306            spb = com.android.internal.telephony.cdma.SmsMessage.getSubmitPdu(scAddress,
307                    destinationAddress, destinationPort, data, statusReportRequested);
308        } else {
309            spb = com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(scAddress,
310                    destinationAddress, destinationPort, data, statusReportRequested);
311        }
312
313        return new SubmitPdu(spb);
314    }
315
316    /**
317     * Returns the address of the SMS service center that relayed this message
318     * or null if there is none.
319     * @deprecated Use android.telephony.SmsMessage.
320     */
321    @Deprecated
322    public String getServiceCenterAddress() {
323        return mWrappedSmsMessage.getServiceCenterAddress();
324    }
325
326    /**
327     * Returns the originating address (sender) of this SMS message in String
328     * form or null if unavailable
329     * @deprecated Use android.telephony.SmsMessage.
330     */
331    @Deprecated
332    public String getOriginatingAddress() {
333        return mWrappedSmsMessage.getOriginatingAddress();
334    }
335
336    /**
337     * Returns the originating address, or email from address if this message
338     * was from an email gateway. Returns null if originating address
339     * unavailable.
340     * @deprecated Use android.telephony.SmsMessage.
341     */
342    @Deprecated
343    public String getDisplayOriginatingAddress() {
344        return mWrappedSmsMessage.getDisplayOriginatingAddress();
345    }
346
347    /**
348     * Returns the message body as a String, if it exists and is text based.
349     * @return message body is there is one, otherwise null
350     * @deprecated Use android.telephony.SmsMessage.
351     */
352    @Deprecated
353    public String getMessageBody() {
354        return mWrappedSmsMessage.getMessageBody();
355    }
356
357    /**
358     * Returns the class of this message.
359     * @deprecated Use android.telephony.SmsMessage.
360     */
361    @Deprecated
362    public MessageClass getMessageClass() {
363        int index = mWrappedSmsMessage.getMessageClass().ordinal();
364
365        return MessageClass.values()[index];
366    }
367
368    /**
369     * Returns the message body, or email message body if this message was from
370     * an email gateway. Returns null if message body unavailable.
371     * @deprecated Use android.telephony.SmsMessage.
372     */
373    @Deprecated
374    public String getDisplayMessageBody() {
375        return mWrappedSmsMessage.getDisplayMessageBody();
376    }
377
378    /**
379     * Unofficial convention of a subject line enclosed in parens empty string
380     * if not present
381     * @deprecated Use android.telephony.SmsMessage.
382     */
383    @Deprecated
384    public String getPseudoSubject() {
385        return mWrappedSmsMessage.getPseudoSubject();
386    }
387
388    /**
389     * Returns the service centre timestamp in currentTimeMillis() format
390     * @deprecated Use android.telephony.SmsMessage.
391     */
392    @Deprecated
393    public long getTimestampMillis() {
394        return mWrappedSmsMessage.getTimestampMillis();
395    }
396
397    /**
398     * Returns true if message is an email.
399     *
400     * @return true if this message came through an email gateway and email
401     *         sender / subject / parsed body are available
402     * @deprecated Use android.telephony.SmsMessage.
403     */
404    @Deprecated
405    public boolean isEmail() {
406        return mWrappedSmsMessage.isEmail();
407    }
408
409     /**
410     * @return if isEmail() is true, body of the email sent through the gateway.
411     *         null otherwise
412     * @deprecated Use android.telephony.SmsMessage.
413     */
414    @Deprecated
415    public String getEmailBody() {
416        return mWrappedSmsMessage.getEmailBody();
417    }
418
419    /**
420     * @return if isEmail() is true, email from address of email sent through
421     *         the gateway. null otherwise
422     * @deprecated Use android.telephony.SmsMessage.
423     */
424    @Deprecated
425    public String getEmailFrom() {
426        return mWrappedSmsMessage.getEmailFrom();
427    }
428
429    /**
430     * Get protocol identifier.
431     * @deprecated Use android.telephony.SmsMessage.
432     */
433    @Deprecated
434    public int getProtocolIdentifier() {
435        return mWrappedSmsMessage.getProtocolIdentifier();
436    }
437
438    /**
439     * See TS 23.040 9.2.3.9 returns true if this is a "replace short message" SMS
440     * @deprecated Use android.telephony.SmsMessage.
441     */
442    @Deprecated
443    public boolean isReplace() {
444        return mWrappedSmsMessage.isReplace();
445    }
446
447    /**
448     * Returns true for CPHS MWI toggle message.
449     *
450     * @return true if this is a CPHS MWI toggle message See CPHS 4.2 section B.4.2
451     * @deprecated Use android.telephony.SmsMessage.
452     */
453    @Deprecated
454    public boolean isCphsMwiMessage() {
455        return mWrappedSmsMessage.isCphsMwiMessage();
456    }
457
458    /**
459     * returns true if this message is a CPHS voicemail / message waiting
460     * indicator (MWI) clear message
461     * @deprecated Use android.telephony.SmsMessage.
462     */
463    @Deprecated
464    public boolean isMWIClearMessage() {
465        return mWrappedSmsMessage.isMWIClearMessage();
466    }
467
468    /**
469     * returns true if this message is a CPHS voicemail / message waiting
470     * indicator (MWI) set message
471     * @deprecated Use android.telephony.SmsMessage.
472     */
473    @Deprecated
474    public boolean isMWISetMessage() {
475        return mWrappedSmsMessage.isMWISetMessage();
476    }
477
478    /**
479     * returns true if this message is a "Message Waiting Indication Group:
480     * Discard Message" notification and should not be stored.
481     * @deprecated Use android.telephony.SmsMessage.
482     */
483    @Deprecated
484    public boolean isMwiDontStore() {
485        return mWrappedSmsMessage.isMwiDontStore();
486    }
487
488    /**
489     * returns the user data section minus the user data header if one was present.
490     * @deprecated Use android.telephony.SmsMessage.
491     */
492    @Deprecated
493    public byte[] getUserData() {
494        return mWrappedSmsMessage.getUserData();
495    }
496
497    /* Not part of the SDK interface and only needed by specific classes:
498       protected SmsHeader getUserDataHeader()
499    */
500
501    /**
502     * Returns the raw PDU for the message.
503     *
504     * @return the raw PDU for the message.
505     * @deprecated Use android.telephony.SmsMessage.
506     */
507    @Deprecated
508    public byte[] getPdu() {
509        return mWrappedSmsMessage.getPdu();
510    }
511
512    /**
513     * Returns the status of the message on the SIM (read, unread, sent, unsent).
514     *
515     * @return the status of the message on the SIM.  These are:
516     *         SmsManager.STATUS_ON_SIM_FREE
517     *         SmsManager.STATUS_ON_SIM_READ
518     *         SmsManager.STATUS_ON_SIM_UNREAD
519     *         SmsManager.STATUS_ON_SIM_SEND
520     *         SmsManager.STATUS_ON_SIM_UNSENT
521     * @deprecated Use android.telephony.SmsMessage and getStatusOnIcc instead.
522     */
523    @Deprecated
524    public int getStatusOnSim() {
525        return mWrappedSmsMessage.getStatusOnIcc();
526    }
527
528    /**
529     * Returns the status of the message on the ICC (read, unread, sent, unsent).
530     *
531     * @return the status of the message on the ICC.  These are:
532     *         SmsManager.STATUS_ON_ICC_FREE
533     *         SmsManager.STATUS_ON_ICC_READ
534     *         SmsManager.STATUS_ON_ICC_UNREAD
535     *         SmsManager.STATUS_ON_ICC_SEND
536     *         SmsManager.STATUS_ON_ICC_UNSENT
537     * @deprecated Use android.telephony.SmsMessage.
538     * @hide
539     */
540    @Deprecated
541    public int getStatusOnIcc() {
542
543        return mWrappedSmsMessage.getStatusOnIcc();
544    }
545
546    /**
547     * Returns the record index of the message on the SIM (1-based index).
548     * @return the record index of the message on the SIM, or -1 if this
549     *         SmsMessage was not created from a SIM SMS EF record.
550     * @deprecated Use android.telephony.SmsMessage and getIndexOnIcc instead.
551     */
552    @Deprecated
553    public int getIndexOnSim() {
554        return mWrappedSmsMessage.getIndexOnIcc();
555    }
556
557    /**
558     * Returns the record index of the message on the ICC (1-based index).
559     * @return the record index of the message on the ICC, or -1 if this
560     *         SmsMessage was not created from a ICC SMS EF record.
561     * @deprecated Use android.telephony.SmsMessage.
562     * @hide
563     */
564    @Deprecated
565    public int getIndexOnIcc() {
566
567        return mWrappedSmsMessage.getIndexOnIcc();
568    }
569
570    /**
571     * GSM:
572     * For an SMS-STATUS-REPORT message, this returns the status field from
573     * the status report.  This field indicates the status of a previously
574     * submitted SMS, if requested.  See TS 23.040, 9.2.3.15 TP-Status for a
575     * description of values.
576     * CDMA:
577     * For not interfering with status codes from GSM, the value is
578     * shifted to the bits 31-16.
579     * The value is composed of an error class (bits 25-24) and a status code (bits 23-16).
580     * Possible codes are described in C.S0015-B, v2.0, 4.5.21.
581     *
582     * @return 0 indicates the previously sent message was received.
583     *         See TS 23.040, 9.9.2.3.15 and C.S0015-B, v2.0, 4.5.21
584     *         for a description of other possible values.
585     * @deprecated Use android.telephony.SmsMessage.
586     */
587    @Deprecated
588    public int getStatus() {
589        return mWrappedSmsMessage.getStatus();
590    }
591
592    /**
593     * Return true iff the message is a SMS-STATUS-REPORT message.
594     * @deprecated Use android.telephony.SmsMessage.
595     */
596    @Deprecated
597    public boolean isStatusReportMessage() {
598        return mWrappedSmsMessage.isStatusReportMessage();
599    }
600
601    /**
602     * Returns true iff the <code>TP-Reply-Path</code> bit is set in
603     * this message.
604     * @deprecated Use android.telephony.SmsMessage.
605     */
606    @Deprecated
607    public boolean isReplyPathPresent() {
608        return mWrappedSmsMessage.isReplyPathPresent();
609    }
610
611    /** This method returns the reference to a specific
612     *  SmsMessage object, which is used for accessing its static methods.
613     * @return Specific SmsMessage.
614     * @deprecated Use android.telephony.SmsMessage.
615     */
616    @Deprecated
617    private static final SmsMessageBase getSmsFacility(){
618        int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
619        if (PHONE_TYPE_CDMA == activePhone) {
620            return new com.android.internal.telephony.cdma.SmsMessage();
621        } else {
622            return new com.android.internal.telephony.gsm.SmsMessage();
623        }
624    }
625}
626