1/*
2 * Copyright (C) 2006 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.provider;
18
19import android.annotation.SdkConstant;
20import android.annotation.SdkConstant.SdkConstantType;
21import android.content.ContentResolver;
22import android.content.ContentValues;
23import android.content.Context;
24import android.content.Intent;
25import android.database.Cursor;
26import android.database.sqlite.SqliteWrapper;
27import android.net.Uri;
28import android.os.Environment;
29import android.telephony.SmsMessage;
30import android.text.TextUtils;
31import android.util.Log;
32import android.util.Patterns;
33
34
35import java.util.HashSet;
36import java.util.Set;
37import java.util.regex.Matcher;
38import java.util.regex.Pattern;
39
40/**
41 * The Telephony provider contains data related to phone operation.
42 *
43 * @hide
44 */
45public final class Telephony {
46    private static final String TAG = "Telephony";
47    private static final boolean DEBUG = true;
48    private static final boolean LOCAL_LOGV = false;
49
50    // Constructor
51    public Telephony() {
52    }
53
54    /**
55     * Base columns for tables that contain text based SMSs.
56     */
57    public interface TextBasedSmsColumns {
58        /**
59         * The type of the message
60         * <P>Type: INTEGER</P>
61         */
62        public static final String TYPE = "type";
63
64        public static final int MESSAGE_TYPE_ALL    = 0;
65        public static final int MESSAGE_TYPE_INBOX  = 1;
66        public static final int MESSAGE_TYPE_SENT   = 2;
67        public static final int MESSAGE_TYPE_DRAFT  = 3;
68        public static final int MESSAGE_TYPE_OUTBOX = 4;
69        public static final int MESSAGE_TYPE_FAILED = 5; // for failed outgoing messages
70        public static final int MESSAGE_TYPE_QUEUED = 6; // for messages to send later
71
72
73        /**
74         * The thread ID of the message
75         * <P>Type: INTEGER</P>
76         */
77        public static final String THREAD_ID = "thread_id";
78
79        /**
80         * The address of the other party
81         * <P>Type: TEXT</P>
82         */
83        public static final String ADDRESS = "address";
84
85        /**
86         * The person ID of the sender
87         * <P>Type: INTEGER (long)</P>
88         */
89        public static final String PERSON_ID = "person";
90
91        /**
92         * The date the message was received
93         * <P>Type: INTEGER (long)</P>
94         */
95        public static final String DATE = "date";
96
97        /**
98         * The date the message was sent
99         * <P>Type: INTEGER (long)</P>
100         */
101        public static final String DATE_SENT = "date_sent";
102
103        /**
104         * Has the message been read
105         * <P>Type: INTEGER (boolean)</P>
106         */
107        public static final String READ = "read";
108
109        /**
110         * Indicates whether this message has been seen by the user. The "seen" flag will be
111         * used to figure out whether we need to throw up a statusbar notification or not.
112         */
113        public static final String SEEN = "seen";
114
115        /**
116         * The TP-Status value for the message, or -1 if no status has
117         * been received
118         */
119        public static final String STATUS = "status";
120
121        public static final int STATUS_NONE = -1;
122        public static final int STATUS_COMPLETE = 0;
123        public static final int STATUS_PENDING = 32;
124        public static final int STATUS_FAILED = 64;
125
126        /**
127         * The subject of the message, if present
128         * <P>Type: TEXT</P>
129         */
130        public static final String SUBJECT = "subject";
131
132        /**
133         * The body of the message
134         * <P>Type: TEXT</P>
135         */
136        public static final String BODY = "body";
137
138        /**
139         * The id of the sender of the conversation, if present
140         * <P>Type: INTEGER (reference to item in content://contacts/people)</P>
141         */
142        public static final String PERSON = "person";
143
144        /**
145         * The protocol identifier code
146         * <P>Type: INTEGER</P>
147         */
148        public static final String PROTOCOL = "protocol";
149
150        /**
151         * Whether the <code>TP-Reply-Path</code> bit was set on this message
152         * <P>Type: BOOLEAN</P>
153         */
154        public static final String REPLY_PATH_PRESENT = "reply_path_present";
155
156        /**
157         * The service center (SC) through which to send the message, if present
158         * <P>Type: TEXT</P>
159         */
160        public static final String SERVICE_CENTER = "service_center";
161
162        /**
163         * Has the message been locked?
164         * <P>Type: INTEGER (boolean)</P>
165         */
166        public static final String LOCKED = "locked";
167
168        /**
169         * Error code associated with sending or receiving this message
170         * <P>Type: INTEGER</P>
171         */
172        public static final String ERROR_CODE = "error_code";
173
174        /**
175         * Meta data used externally.
176         * <P>Type: TEXT</P>
177         */
178        public static final String META_DATA = "meta_data";
179    }
180
181    /**
182     * Contains all text based SMS messages.
183     */
184    public static final class Sms implements BaseColumns, TextBasedSmsColumns {
185        public static final Cursor query(ContentResolver cr, String[] projection) {
186            return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
187        }
188
189        public static final Cursor query(ContentResolver cr, String[] projection,
190                String where, String orderBy) {
191            return cr.query(CONTENT_URI, projection, where,
192                                         null, orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
193        }
194
195        /**
196         * The content:// style URL for this table
197         */
198        public static final Uri CONTENT_URI =
199            Uri.parse("content://sms");
200
201        /**
202         * The default sort order for this table
203         */
204        public static final String DEFAULT_SORT_ORDER = "date DESC";
205
206        /**
207         * Add an SMS to the given URI.
208         *
209         * @param resolver the content resolver to use
210         * @param uri the URI to add the message to
211         * @param address the address of the sender
212         * @param body the body of the message
213         * @param subject the psuedo-subject of the message
214         * @param date the timestamp for the message
215         * @param read true if the message has been read, false if not
216         * @param deliveryReport true if a delivery report was requested, false if not
217         * @return the URI for the new message
218         */
219        public static Uri addMessageToUri(ContentResolver resolver,
220                Uri uri, String address, String body, String subject,
221                Long date, boolean read, boolean deliveryReport) {
222            return addMessageToUri(resolver, uri, address, body, subject,
223                    date, read, deliveryReport, -1L);
224        }
225
226        /**
227         * Add an SMS to the given URI with thread_id specified.
228         *
229         * @param resolver the content resolver to use
230         * @param uri the URI to add the message to
231         * @param address the address of the sender
232         * @param body the body of the message
233         * @param subject the psuedo-subject of the message
234         * @param date the timestamp for the message
235         * @param read true if the message has been read, false if not
236         * @param deliveryReport true if a delivery report was requested, false if not
237         * @param threadId the thread_id of the message
238         * @return the URI for the new message
239         */
240        public static Uri addMessageToUri(ContentResolver resolver,
241                Uri uri, String address, String body, String subject,
242                Long date, boolean read, boolean deliveryReport, long threadId) {
243            ContentValues values = new ContentValues(7);
244
245            values.put(ADDRESS, address);
246            if (date != null) {
247                values.put(DATE, date);
248            }
249            values.put(READ, read ? Integer.valueOf(1) : Integer.valueOf(0));
250            values.put(SUBJECT, subject);
251            values.put(BODY, body);
252            if (deliveryReport) {
253                values.put(STATUS, STATUS_PENDING);
254            }
255            if (threadId != -1L) {
256                values.put(THREAD_ID, threadId);
257            }
258            return resolver.insert(uri, values);
259        }
260
261        /**
262         * Move a message to the given folder.
263         *
264         * @param context the context to use
265         * @param uri the message to move
266         * @param folder the folder to move to
267         * @return true if the operation succeeded
268         */
269        public static boolean moveMessageToFolder(Context context,
270                Uri uri, int folder, int error) {
271            if (uri == null) {
272                return false;
273            }
274
275            boolean markAsUnread = false;
276            boolean markAsRead = false;
277            switch(folder) {
278            case MESSAGE_TYPE_INBOX:
279            case MESSAGE_TYPE_DRAFT:
280                break;
281            case MESSAGE_TYPE_OUTBOX:
282            case MESSAGE_TYPE_SENT:
283                markAsRead = true;
284                break;
285            case MESSAGE_TYPE_FAILED:
286            case MESSAGE_TYPE_QUEUED:
287                markAsUnread = true;
288                break;
289            default:
290                return false;
291            }
292
293            ContentValues values = new ContentValues(3);
294
295            values.put(TYPE, folder);
296            if (markAsUnread) {
297                values.put(READ, Integer.valueOf(0));
298            } else if (markAsRead) {
299                values.put(READ, Integer.valueOf(1));
300            }
301            values.put(ERROR_CODE, error);
302
303            return 1 == SqliteWrapper.update(context, context.getContentResolver(),
304                            uri, values, null, null);
305        }
306
307        /**
308         * Returns true iff the folder (message type) identifies an
309         * outgoing message.
310         */
311        public static boolean isOutgoingFolder(int messageType) {
312            return  (messageType == MESSAGE_TYPE_FAILED)
313                    || (messageType == MESSAGE_TYPE_OUTBOX)
314                    || (messageType == MESSAGE_TYPE_SENT)
315                    || (messageType == MESSAGE_TYPE_QUEUED);
316        }
317
318        /**
319         * Contains all text based SMS messages in the SMS app's inbox.
320         */
321        public static final class Inbox implements BaseColumns, TextBasedSmsColumns {
322            /**
323             * The content:// style URL for this table
324             */
325            public static final Uri CONTENT_URI =
326                Uri.parse("content://sms/inbox");
327
328            /**
329             * The default sort order for this table
330             */
331            public static final String DEFAULT_SORT_ORDER = "date DESC";
332
333            /**
334             * Add an SMS to the Draft box.
335             *
336             * @param resolver the content resolver to use
337             * @param address the address of the sender
338             * @param body the body of the message
339             * @param subject the psuedo-subject of the message
340             * @param date the timestamp for the message
341             * @param read true if the message has been read, false if not
342             * @return the URI for the new message
343             */
344            public static Uri addMessage(ContentResolver resolver,
345                    String address, String body, String subject, Long date,
346                    boolean read) {
347                return addMessageToUri(resolver, CONTENT_URI, address, body,
348                        subject, date, read, false);
349            }
350        }
351
352        /**
353         * Contains all sent text based SMS messages in the SMS app's.
354         */
355        public static final class Sent implements BaseColumns, TextBasedSmsColumns {
356            /**
357             * The content:// style URL for this table
358             */
359            public static final Uri CONTENT_URI =
360                    Uri.parse("content://sms/sent");
361
362            /**
363             * The default sort order for this table
364             */
365            public static final String DEFAULT_SORT_ORDER = "date DESC";
366
367            /**
368             * Add an SMS to the Draft box.
369             *
370             * @param resolver the content resolver to use
371             * @param address the address of the sender
372             * @param body the body of the message
373             * @param subject the psuedo-subject of the message
374             * @param date the timestamp for the message
375             * @return the URI for the new message
376             */
377            public static Uri addMessage(ContentResolver resolver,
378                    String address, String body, String subject, Long date) {
379                return addMessageToUri(resolver, CONTENT_URI, address, body,
380                        subject, date, true, false);
381            }
382        }
383
384        /**
385         * Contains all sent text based SMS messages in the SMS app's.
386         */
387        public static final class Draft implements BaseColumns, TextBasedSmsColumns {
388            /**
389             * The content:// style URL for this table
390             */
391            public static final Uri CONTENT_URI =
392                    Uri.parse("content://sms/draft");
393
394            /**
395             * The default sort order for this table
396             */
397            public static final String DEFAULT_SORT_ORDER = "date DESC";
398
399            /**
400             * Add an SMS to the Draft box.
401             *
402             * @param resolver the content resolver to use
403             * @param address the address of the sender
404             * @param body the body of the message
405             * @param subject the psuedo-subject of the message
406             * @param date the timestamp for the message
407             * @return the URI for the new message
408             */
409            public static Uri addMessage(ContentResolver resolver,
410                    String address, String body, String subject, Long date) {
411                return addMessageToUri(resolver, CONTENT_URI, address, body,
412                        subject, date, true, false);
413            }
414
415            /**
416             * Save over an existing draft message.
417             *
418             * @param resolver the content resolver to use
419             * @param uri of existing message
420             * @param body the new body for the draft message
421             * @return true is successful, false otherwise
422             */
423            public static boolean saveMessage(ContentResolver resolver,
424                    Uri uri, String body) {
425                ContentValues values = new ContentValues(2);
426                values.put(BODY, body);
427                values.put(DATE, System.currentTimeMillis());
428                return resolver.update(uri, values, null, null) == 1;
429            }
430        }
431
432        /**
433         * Contains all pending outgoing text based SMS messages.
434         */
435        public static final class Outbox implements BaseColumns, TextBasedSmsColumns {
436            /**
437             * The content:// style URL for this table
438             */
439            public static final Uri CONTENT_URI =
440                Uri.parse("content://sms/outbox");
441
442            /**
443             * The default sort order for this table
444             */
445            public static final String DEFAULT_SORT_ORDER = "date DESC";
446
447            /**
448             * Add an SMS to the Out box.
449             *
450             * @param resolver the content resolver to use
451             * @param address the address of the sender
452             * @param body the body of the message
453             * @param subject the psuedo-subject of the message
454             * @param date the timestamp for the message
455             * @param deliveryReport whether a delivery report was requested for the message
456             * @return the URI for the new message
457             */
458            public static Uri addMessage(ContentResolver resolver,
459                    String address, String body, String subject, Long date,
460                    boolean deliveryReport, long threadId) {
461                return addMessageToUri(resolver, CONTENT_URI, address, body,
462                        subject, date, true, deliveryReport, threadId);
463            }
464        }
465
466        /**
467         * Contains all sent text-based SMS messages in the SMS app's.
468         */
469        public static final class Conversations
470                implements BaseColumns, TextBasedSmsColumns {
471            /**
472             * The content:// style URL for this table
473             */
474            public static final Uri CONTENT_URI =
475                Uri.parse("content://sms/conversations");
476
477            /**
478             * The default sort order for this table
479             */
480            public static final String DEFAULT_SORT_ORDER = "date DESC";
481
482            /**
483             * The first 45 characters of the body of the message
484             * <P>Type: TEXT</P>
485             */
486            public static final String SNIPPET = "snippet";
487
488            /**
489             * The number of messages in the conversation
490             * <P>Type: INTEGER</P>
491             */
492            public static final String MESSAGE_COUNT = "msg_count";
493        }
494
495        /**
496         * Contains info about SMS related Intents that are broadcast.
497         */
498        public static final class Intents {
499            /**
500             * Set by BroadcastReceiver. Indicates the message was handled
501             * successfully.
502             */
503            public static final int RESULT_SMS_HANDLED = 1;
504
505            /**
506             * Set by BroadcastReceiver. Indicates a generic error while
507             * processing the message.
508             */
509            public static final int RESULT_SMS_GENERIC_ERROR = 2;
510
511            /**
512             * Set by BroadcastReceiver. Indicates insufficient memory to store
513             * the message.
514             */
515            public static final int RESULT_SMS_OUT_OF_MEMORY = 3;
516
517            /**
518             * Set by BroadcastReceiver. Indicates the message, while
519             * possibly valid, is of a format or encoding that is not
520             * supported.
521             */
522            public static final int RESULT_SMS_UNSUPPORTED = 4;
523
524            /**
525             * Broadcast Action: A new text based SMS message has been received
526             * by the device. The intent will have the following extra
527             * values:</p>
528             *
529             * <ul>
530             *   <li><em>pdus</em> - An Object[] od byte[]s containing the PDUs
531             *   that make up the message.</li>
532             * </ul>
533             *
534             * <p>The extra values can be extracted using
535             * {@link #getMessagesFromIntent(Intent)}.</p>
536             *
537             * <p>If a BroadcastReceiver encounters an error while processing
538             * this intent it should set the result code appropriately.</p>
539             */
540            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
541            public static final String SMS_RECEIVED_ACTION =
542                    "android.provider.Telephony.SMS_RECEIVED";
543
544            /**
545             * Broadcast Action: A new data based SMS message has been received
546             * by the device. The intent will have the following extra
547             * values:</p>
548             *
549             * <ul>
550             *   <li><em>pdus</em> - An Object[] of byte[]s containing the PDUs
551             *   that make up the message.</li>
552             * </ul>
553             *
554             * <p>The extra values can be extracted using
555             * {@link #getMessagesFromIntent(Intent)}.</p>
556             *
557             * <p>If a BroadcastReceiver encounters an error while processing
558             * this intent it should set the result code appropriately.</p>
559             */
560            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
561            public static final String DATA_SMS_RECEIVED_ACTION =
562                    "android.intent.action.DATA_SMS_RECEIVED";
563
564            /**
565             * Broadcast Action: A new WAP PUSH message has been received by the
566             * device. The intent will have the following extra
567             * values:</p>
568             *
569             * <ul>
570             *   <li><em>transactionId (Integer)</em> - The WAP transaction ID</li>
571             *   <li><em>pduType (Integer)</em> - The WAP PDU type</li>
572             *   <li><em>header (byte[])</em> - The header of the message</li>
573             *   <li><em>data (byte[])</em> - The data payload of the message</li>
574             *   <li><em>contentTypeParameters (HashMap&lt;String,String&gt;)</em>
575             *   - Any parameters associated with the content type
576             *   (decoded from the WSP Content-Type header)</li>
577             * </ul>
578             *
579             * <p>If a BroadcastReceiver encounters an error while processing
580             * this intent it should set the result code appropriately.</p>
581             *
582             * <p>The contentTypeParameters extra value is map of content parameters keyed by
583             * their names.</p>
584             *
585             * <p>If any unassigned well-known parameters are encountered, the key of the map will
586             * be 'unassigned/0x...', where '...' is the hex value of the unassigned parameter.  If
587             * a parameter has No-Value the value in the map will be null.</p>
588             */
589            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
590            public static final String WAP_PUSH_RECEIVED_ACTION =
591                    "android.provider.Telephony.WAP_PUSH_RECEIVED";
592
593            /**
594             * Broadcast Action: A new Cell Broadcast message has been received
595             * by the device. The intent will have the following extra
596             * values:</p>
597             *
598             * <ul>
599             *   <li><em>message</em> - An SmsCbMessage object containing the broadcast message
600             *   data. This is not an emergency alert, so ETWS and CMAS data will be null.</li>
601             * </ul>
602             *
603             * <p>The extra values can be extracted using
604             * {@link #getMessagesFromIntent(Intent)}.</p>
605             *
606             * <p>If a BroadcastReceiver encounters an error while processing
607             * this intent it should set the result code appropriately.</p>
608             */
609            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
610            public static final String SMS_CB_RECEIVED_ACTION =
611                    "android.provider.Telephony.SMS_CB_RECEIVED";
612
613            /**
614             * Broadcast Action: A new Emergency Broadcast message has been received
615             * by the device. The intent will have the following extra
616             * values:</p>
617             *
618             * <ul>
619             *   <li><em>message</em> - An SmsCbMessage object containing the broadcast message
620             *   data, including ETWS or CMAS warning notification info if present.</li>
621             * </ul>
622             *
623             * <p>The extra values can be extracted using
624             * {@link #getMessagesFromIntent(Intent)}.</p>
625             *
626             * <p>If a BroadcastReceiver encounters an error while processing
627             * this intent it should set the result code appropriately.</p>
628             */
629            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
630            public static final String SMS_EMERGENCY_CB_RECEIVED_ACTION =
631                    "android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED";
632
633            /**
634             * Broadcast Action: A new CDMA SMS has been received containing Service Category
635             * Program Data (updates the list of enabled broadcast channels). The intent will
636             * have the following extra values:</p>
637             *
638             * <ul>
639             *   <li><em>operations</em> - An array of CdmaSmsCbProgramData objects containing
640             *   the service category operations (add/delete/clear) to perform.</li>
641             * </ul>
642             *
643             * <p>The extra values can be extracted using
644             * {@link #getMessagesFromIntent(Intent)}.</p>
645             *
646             * <p>If a BroadcastReceiver encounters an error while processing
647             * this intent it should set the result code appropriately.</p>
648             */
649            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
650            public static final String SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED_ACTION =
651                    "android.provider.Telephony.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED";
652
653            /**
654             * Broadcast Action: The SIM storage for SMS messages is full.  If
655             * space is not freed, messages targeted for the SIM (class 2) may
656             * not be saved.
657             */
658            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
659            public static final String SIM_FULL_ACTION =
660                    "android.provider.Telephony.SIM_FULL";
661
662            /**
663             * Broadcast Action: An incoming SMS has been rejected by the
664             * telephony framework.  This intent is sent in lieu of any
665             * of the RECEIVED_ACTION intents.  The intent will have the
666             * following extra value:</p>
667             *
668             * <ul>
669             *   <li><em>result</em> - An int result code, eg,
670             *   <code>{@link #RESULT_SMS_OUT_OF_MEMORY}</code>,
671             *   indicating the error returned to the network.</li>
672             * </ul>
673
674             */
675            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
676            public static final String SMS_REJECTED_ACTION =
677                "android.provider.Telephony.SMS_REJECTED";
678
679            /**
680             * Read the PDUs out of an {@link #SMS_RECEIVED_ACTION} or a
681             * {@link #DATA_SMS_RECEIVED_ACTION} intent.
682             *
683             * @param intent the intent to read from
684             * @return an array of SmsMessages for the PDUs
685             */
686            public static SmsMessage[] getMessagesFromIntent(
687                    Intent intent) {
688                Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
689                String format = intent.getStringExtra("format");
690                byte[][] pduObjs = new byte[messages.length][];
691
692                for (int i = 0; i < messages.length; i++) {
693                    pduObjs[i] = (byte[]) messages[i];
694                }
695                byte[][] pdus = new byte[pduObjs.length][];
696                int pduCount = pdus.length;
697                SmsMessage[] msgs = new SmsMessage[pduCount];
698                for (int i = 0; i < pduCount; i++) {
699                    pdus[i] = pduObjs[i];
700                    msgs[i] = SmsMessage.createFromPdu(pdus[i], format);
701                }
702                return msgs;
703            }
704        }
705    }
706
707    /**
708     * Base columns for tables that contain MMSs.
709     */
710    public interface BaseMmsColumns extends BaseColumns {
711
712        public static final int MESSAGE_BOX_ALL    = 0;
713        public static final int MESSAGE_BOX_INBOX  = 1;
714        public static final int MESSAGE_BOX_SENT   = 2;
715        public static final int MESSAGE_BOX_DRAFTS = 3;
716        public static final int MESSAGE_BOX_OUTBOX = 4;
717
718        /**
719         * The date the message was received.
720         * <P>Type: INTEGER (long)</P>
721         */
722        public static final String DATE = "date";
723
724        /**
725         * The date the message was sent.
726         * <P>Type: INTEGER (long)</P>
727         */
728        public static final String DATE_SENT = "date_sent";
729
730        /**
731         * The box which the message belong to, for example, MESSAGE_BOX_INBOX.
732         * <P>Type: INTEGER</P>
733         */
734        public static final String MESSAGE_BOX = "msg_box";
735
736        /**
737         * Has the message been read.
738         * <P>Type: INTEGER (boolean)</P>
739         */
740        public static final String READ = "read";
741
742        /**
743         * Indicates whether this message has been seen by the user. The "seen" flag will be
744         * used to figure out whether we need to throw up a statusbar notification or not.
745         */
746        public static final String SEEN = "seen";
747
748        /**
749         * Indicates whether this message has only a text part (can also have a subject) and
750         * no picture, slideshow, or sound, etc., parts. The value is a boolean, 1 or 0.
751         */
752        public static final String TEXT_ONLY = "text_only";
753
754        /**
755         * The Message-ID of the message.
756         * <P>Type: TEXT</P>
757         */
758        public static final String MESSAGE_ID = "m_id";
759
760        /**
761         * The subject of the message, if present.
762         * <P>Type: TEXT</P>
763         */
764        public static final String SUBJECT = "sub";
765
766        /**
767         * The character set of the subject, if present.
768         * <P>Type: INTEGER</P>
769         */
770        public static final String SUBJECT_CHARSET = "sub_cs";
771
772        /**
773         * The Content-Type of the message.
774         * <P>Type: TEXT</P>
775         */
776        public static final String CONTENT_TYPE = "ct_t";
777
778        /**
779         * The Content-Location of the message.
780         * <P>Type: TEXT</P>
781         */
782        public static final String CONTENT_LOCATION = "ct_l";
783
784        /**
785         * The address of the sender.
786         * <P>Type: TEXT</P>
787         */
788        public static final String FROM = "from";
789
790        /**
791         * The address of the recipients.
792         * <P>Type: TEXT</P>
793         */
794        public static final String TO = "to";
795
796        /**
797         * The address of the cc. recipients.
798         * <P>Type: TEXT</P>
799         */
800        public static final String CC = "cc";
801
802        /**
803         * The address of the bcc. recipients.
804         * <P>Type: TEXT</P>
805         */
806        public static final String BCC = "bcc";
807
808        /**
809         * The expiry time of the message.
810         * <P>Type: INTEGER</P>
811         */
812        public static final String EXPIRY = "exp";
813
814        /**
815         * The class of the message.
816         * <P>Type: TEXT</P>
817         */
818        public static final String MESSAGE_CLASS = "m_cls";
819
820        /**
821         * The type of the message defined by MMS spec.
822         * <P>Type: INTEGER</P>
823         */
824        public static final String MESSAGE_TYPE = "m_type";
825
826        /**
827         * The version of specification that this message conform.
828         * <P>Type: INTEGER</P>
829         */
830        public static final String MMS_VERSION = "v";
831
832        /**
833         * The size of the message.
834         * <P>Type: INTEGER</P>
835         */
836        public static final String MESSAGE_SIZE = "m_size";
837
838        /**
839         * The priority of the message.
840         * <P>Type: TEXT</P>
841         */
842        public static final String PRIORITY = "pri";
843
844        /**
845         * The read-report of the message.
846         * <P>Type: TEXT</P>
847         */
848        public static final String READ_REPORT = "rr";
849
850        /**
851         * Whether the report is allowed.
852         * <P>Type: TEXT</P>
853         */
854        public static final String REPORT_ALLOWED = "rpt_a";
855
856        /**
857         * The response-status of the message.
858         * <P>Type: INTEGER</P>
859         */
860        public static final String RESPONSE_STATUS = "resp_st";
861
862        /**
863         * The status of the message.
864         * <P>Type: INTEGER</P>
865         */
866        public static final String STATUS = "st";
867
868        /**
869         * The transaction-id of the message.
870         * <P>Type: TEXT</P>
871         */
872        public static final String TRANSACTION_ID = "tr_id";
873
874        /**
875         * The retrieve-status of the message.
876         * <P>Type: INTEGER</P>
877         */
878        public static final String RETRIEVE_STATUS = "retr_st";
879
880        /**
881         * The retrieve-text of the message.
882         * <P>Type: TEXT</P>
883         */
884        public static final String RETRIEVE_TEXT = "retr_txt";
885
886        /**
887         * The character set of the retrieve-text.
888         * <P>Type: TEXT</P>
889         */
890        public static final String RETRIEVE_TEXT_CHARSET = "retr_txt_cs";
891
892        /**
893         * The read-status of the message.
894         * <P>Type: INTEGER</P>
895         */
896        public static final String READ_STATUS = "read_status";
897
898        /**
899         * The content-class of the message.
900         * <P>Type: INTEGER</P>
901         */
902        public static final String CONTENT_CLASS = "ct_cls";
903
904        /**
905         * The delivery-report of the message.
906         * <P>Type: INTEGER</P>
907         */
908        public static final String DELIVERY_REPORT = "d_rpt";
909
910        /**
911         * The delivery-time-token of the message.
912         * <P>Type: INTEGER</P>
913         */
914        public static final String DELIVERY_TIME_TOKEN = "d_tm_tok";
915
916        /**
917         * The delivery-time of the message.
918         * <P>Type: INTEGER</P>
919         */
920        public static final String DELIVERY_TIME = "d_tm";
921
922        /**
923         * The response-text of the message.
924         * <P>Type: TEXT</P>
925         */
926        public static final String RESPONSE_TEXT = "resp_txt";
927
928        /**
929         * The sender-visibility of the message.
930         * <P>Type: TEXT</P>
931         */
932        public static final String SENDER_VISIBILITY = "s_vis";
933
934        /**
935         * The reply-charging of the message.
936         * <P>Type: INTEGER</P>
937         */
938        public static final String REPLY_CHARGING = "r_chg";
939
940        /**
941         * The reply-charging-deadline-token of the message.
942         * <P>Type: INTEGER</P>
943         */
944        public static final String REPLY_CHARGING_DEADLINE_TOKEN = "r_chg_dl_tok";
945
946        /**
947         * The reply-charging-deadline of the message.
948         * <P>Type: INTEGER</P>
949         */
950        public static final String REPLY_CHARGING_DEADLINE = "r_chg_dl";
951
952        /**
953         * The reply-charging-id of the message.
954         * <P>Type: TEXT</P>
955         */
956        public static final String REPLY_CHARGING_ID = "r_chg_id";
957
958        /**
959         * The reply-charging-size of the message.
960         * <P>Type: INTEGER</P>
961         */
962        public static final String REPLY_CHARGING_SIZE = "r_chg_sz";
963
964        /**
965         * The previously-sent-by of the message.
966         * <P>Type: TEXT</P>
967         */
968        public static final String PREVIOUSLY_SENT_BY = "p_s_by";
969
970        /**
971         * The previously-sent-date of the message.
972         * <P>Type: INTEGER</P>
973         */
974        public static final String PREVIOUSLY_SENT_DATE = "p_s_d";
975
976        /**
977         * The store of the message.
978         * <P>Type: TEXT</P>
979         */
980        public static final String STORE = "store";
981
982        /**
983         * The mm-state of the message.
984         * <P>Type: INTEGER</P>
985         */
986        public static final String MM_STATE = "mm_st";
987
988        /**
989         * The mm-flags-token of the message.
990         * <P>Type: INTEGER</P>
991         */
992        public static final String MM_FLAGS_TOKEN = "mm_flg_tok";
993
994        /**
995         * The mm-flags of the message.
996         * <P>Type: TEXT</P>
997         */
998        public static final String MM_FLAGS = "mm_flg";
999
1000        /**
1001         * The store-status of the message.
1002         * <P>Type: TEXT</P>
1003         */
1004        public static final String STORE_STATUS = "store_st";
1005
1006        /**
1007         * The store-status-text of the message.
1008         * <P>Type: TEXT</P>
1009         */
1010        public static final String STORE_STATUS_TEXT = "store_st_txt";
1011
1012        /**
1013         * The stored of the message.
1014         * <P>Type: TEXT</P>
1015         */
1016        public static final String STORED = "stored";
1017
1018        /**
1019         * The totals of the message.
1020         * <P>Type: TEXT</P>
1021         */
1022        public static final String TOTALS = "totals";
1023
1024        /**
1025         * The mbox-totals of the message.
1026         * <P>Type: TEXT</P>
1027         */
1028        public static final String MBOX_TOTALS = "mb_t";
1029
1030        /**
1031         * The mbox-totals-token of the message.
1032         * <P>Type: INTEGER</P>
1033         */
1034        public static final String MBOX_TOTALS_TOKEN = "mb_t_tok";
1035
1036        /**
1037         * The quotas of the message.
1038         * <P>Type: TEXT</P>
1039         */
1040        public static final String QUOTAS = "qt";
1041
1042        /**
1043         * The mbox-quotas of the message.
1044         * <P>Type: TEXT</P>
1045         */
1046        public static final String MBOX_QUOTAS = "mb_qt";
1047
1048        /**
1049         * The mbox-quotas-token of the message.
1050         * <P>Type: INTEGER</P>
1051         */
1052        public static final String MBOX_QUOTAS_TOKEN = "mb_qt_tok";
1053
1054        /**
1055         * The message-count of the message.
1056         * <P>Type: INTEGER</P>
1057         */
1058        public static final String MESSAGE_COUNT = "m_cnt";
1059
1060        /**
1061         * The start of the message.
1062         * <P>Type: INTEGER</P>
1063         */
1064        public static final String START = "start";
1065
1066        /**
1067         * The distribution-indicator of the message.
1068         * <P>Type: TEXT</P>
1069         */
1070        public static final String DISTRIBUTION_INDICATOR = "d_ind";
1071
1072        /**
1073         * The element-descriptor of the message.
1074         * <P>Type: TEXT</P>
1075         */
1076        public static final String ELEMENT_DESCRIPTOR = "e_des";
1077
1078        /**
1079         * The limit of the message.
1080         * <P>Type: INTEGER</P>
1081         */
1082        public static final String LIMIT = "limit";
1083
1084        /**
1085         * The recommended-retrieval-mode of the message.
1086         * <P>Type: INTEGER</P>
1087         */
1088        public static final String RECOMMENDED_RETRIEVAL_MODE = "r_r_mod";
1089
1090        /**
1091         * The recommended-retrieval-mode-text of the message.
1092         * <P>Type: TEXT</P>
1093         */
1094        public static final String RECOMMENDED_RETRIEVAL_MODE_TEXT = "r_r_mod_txt";
1095
1096        /**
1097         * The status-text of the message.
1098         * <P>Type: TEXT</P>
1099         */
1100        public static final String STATUS_TEXT = "st_txt";
1101
1102        /**
1103         * The applic-id of the message.
1104         * <P>Type: TEXT</P>
1105         */
1106        public static final String APPLIC_ID = "apl_id";
1107
1108        /**
1109         * The reply-applic-id of the message.
1110         * <P>Type: TEXT</P>
1111         */
1112        public static final String REPLY_APPLIC_ID = "r_apl_id";
1113
1114        /**
1115         * The aux-applic-id of the message.
1116         * <P>Type: TEXT</P>
1117         */
1118        public static final String AUX_APPLIC_ID = "aux_apl_id";
1119
1120        /**
1121         * The drm-content of the message.
1122         * <P>Type: TEXT</P>
1123         */
1124        public static final String DRM_CONTENT = "drm_c";
1125
1126        /**
1127         * The adaptation-allowed of the message.
1128         * <P>Type: TEXT</P>
1129         */
1130        public static final String ADAPTATION_ALLOWED = "adp_a";
1131
1132        /**
1133         * The replace-id of the message.
1134         * <P>Type: TEXT</P>
1135         */
1136        public static final String REPLACE_ID = "repl_id";
1137
1138        /**
1139         * The cancel-id of the message.
1140         * <P>Type: TEXT</P>
1141         */
1142        public static final String CANCEL_ID = "cl_id";
1143
1144        /**
1145         * The cancel-status of the message.
1146         * <P>Type: INTEGER</P>
1147         */
1148        public static final String CANCEL_STATUS = "cl_st";
1149
1150        /**
1151         * The thread ID of the message
1152         * <P>Type: INTEGER</P>
1153         */
1154        public static final String THREAD_ID = "thread_id";
1155
1156        /**
1157         * Has the message been locked?
1158         * <P>Type: INTEGER (boolean)</P>
1159         */
1160        public static final String LOCKED = "locked";
1161
1162        /**
1163         * Meta data used externally.
1164         * <P>Type: TEXT</P>
1165         */
1166        public static final String META_DATA = "meta_data";
1167    }
1168
1169    /**
1170     * Columns for the "canonical_addresses" table used by MMS and
1171     * SMS."
1172     */
1173    public interface CanonicalAddressesColumns extends BaseColumns {
1174        /**
1175         * An address used in MMS or SMS.  Email addresses are
1176         * converted to lower case and are compared by string
1177         * equality.  Other addresses are compared using
1178         * PHONE_NUMBERS_EQUAL.
1179         * <P>Type: TEXT</P>
1180         */
1181        public static final String ADDRESS = "address";
1182    }
1183
1184    /**
1185     * Columns for the "threads" table used by MMS and SMS.
1186     */
1187    public interface ThreadsColumns extends BaseColumns {
1188        /**
1189         * The date at which the thread was created.
1190         *
1191         * <P>Type: INTEGER (long)</P>
1192         */
1193        public static final String DATE = "date";
1194
1195        /**
1196         * A string encoding of the recipient IDs of the recipients of
1197         * the message, in numerical order and separated by spaces.
1198         * <P>Type: TEXT</P>
1199         */
1200        public static final String RECIPIENT_IDS = "recipient_ids";
1201
1202        /**
1203         * The message count of the thread.
1204         * <P>Type: INTEGER</P>
1205         */
1206        public static final String MESSAGE_COUNT = "message_count";
1207        /**
1208         * Indicates whether all messages of the thread have been read.
1209         * <P>Type: INTEGER</P>
1210         */
1211        public static final String READ = "read";
1212
1213        /**
1214         * The snippet of the latest message in the thread.
1215         * <P>Type: TEXT</P>
1216         */
1217        public static final String SNIPPET = "snippet";
1218        /**
1219         * The charset of the snippet.
1220         * <P>Type: INTEGER</P>
1221         */
1222        public static final String SNIPPET_CHARSET = "snippet_cs";
1223        /**
1224         * Type of the thread, either Threads.COMMON_THREAD or
1225         * Threads.BROADCAST_THREAD.
1226         * <P>Type: INTEGER</P>
1227         */
1228        public static final String TYPE = "type";
1229        /**
1230         * Indicates whether there is a transmission error in the thread.
1231         * <P>Type: INTEGER</P>
1232         */
1233        public static final String ERROR = "error";
1234        /**
1235         * Indicates whether this thread contains any attachments.
1236         * <P>Type: INTEGER</P>
1237         */
1238        public static final String HAS_ATTACHMENT = "has_attachment";
1239    }
1240
1241    /**
1242     * Helper functions for the "threads" table used by MMS and SMS.
1243     */
1244    public static final class Threads implements ThreadsColumns {
1245        private static final String[] ID_PROJECTION = { BaseColumns._ID };
1246        private static final String STANDARD_ENCODING = "UTF-8";
1247        private static final Uri THREAD_ID_CONTENT_URI = Uri.parse(
1248                "content://mms-sms/threadID");
1249        public static final Uri CONTENT_URI = Uri.withAppendedPath(
1250                MmsSms.CONTENT_URI, "conversations");
1251        public static final Uri OBSOLETE_THREADS_URI = Uri.withAppendedPath(
1252                CONTENT_URI, "obsolete");
1253
1254        public static final int COMMON_THREAD    = 0;
1255        public static final int BROADCAST_THREAD = 1;
1256
1257        // No one should construct an instance of this class.
1258        private Threads() {
1259        }
1260
1261        /**
1262         * This is a single-recipient version of
1263         * getOrCreateThreadId.  It's convenient for use with SMS
1264         * messages.
1265         */
1266        public static long getOrCreateThreadId(Context context, String recipient) {
1267            Set<String> recipients = new HashSet<String>();
1268
1269            recipients.add(recipient);
1270            return getOrCreateThreadId(context, recipients);
1271        }
1272
1273        /**
1274         * Given the recipients list and subject of an unsaved message,
1275         * return its thread ID.  If the message starts a new thread,
1276         * allocate a new thread ID.  Otherwise, use the appropriate
1277         * existing thread ID.
1278         *
1279         * Find the thread ID of the same set of recipients (in
1280         * any order, without any additions). If one
1281         * is found, return it.  Otherwise, return a unique thread ID.
1282         */
1283        public static long getOrCreateThreadId(
1284                Context context, Set<String> recipients) {
1285            Uri.Builder uriBuilder = THREAD_ID_CONTENT_URI.buildUpon();
1286
1287            for (String recipient : recipients) {
1288                if (Mms.isEmailAddress(recipient)) {
1289                    recipient = Mms.extractAddrSpec(recipient);
1290                }
1291
1292                uriBuilder.appendQueryParameter("recipient", recipient);
1293            }
1294
1295            Uri uri = uriBuilder.build();
1296            //if (DEBUG) Log.v(TAG, "getOrCreateThreadId uri: " + uri);
1297
1298            Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(),
1299                    uri, ID_PROJECTION, null, null, null);
1300            if (cursor != null) {
1301                try {
1302                    if (cursor.moveToFirst()) {
1303                        return cursor.getLong(0);
1304                    } else {
1305                        Log.e(TAG, "getOrCreateThreadId returned no rows!");
1306                    }
1307                } finally {
1308                    cursor.close();
1309                }
1310            }
1311
1312            Log.e(TAG, "getOrCreateThreadId failed with uri " + uri.toString());
1313            throw new IllegalArgumentException("Unable to find or allocate a thread ID.");
1314        }
1315    }
1316
1317    /**
1318     * Contains all MMS messages.
1319     */
1320    public static final class Mms implements BaseMmsColumns {
1321        /**
1322         * The content:// style URL for this table
1323         */
1324        public static final Uri CONTENT_URI = Uri.parse("content://mms");
1325
1326        public static final Uri REPORT_REQUEST_URI = Uri.withAppendedPath(
1327                                            CONTENT_URI, "report-request");
1328
1329        public static final Uri REPORT_STATUS_URI = Uri.withAppendedPath(
1330                                            CONTENT_URI, "report-status");
1331
1332        /**
1333         * The default sort order for this table
1334         */
1335        public static final String DEFAULT_SORT_ORDER = "date DESC";
1336
1337        /**
1338         * mailbox         =       name-addr
1339         * name-addr       =       [display-name] angle-addr
1340         * angle-addr      =       [CFWS] "<" addr-spec ">" [CFWS]
1341         */
1342        public static final Pattern NAME_ADDR_EMAIL_PATTERN =
1343                Pattern.compile("\\s*(\"[^\"]*\"|[^<>\"]+)\\s*<([^<>]+)>\\s*");
1344
1345        /**
1346         * quoted-string   =       [CFWS]
1347         *                         DQUOTE *([FWS] qcontent) [FWS] DQUOTE
1348         *                         [CFWS]
1349         */
1350        public static final Pattern QUOTED_STRING_PATTERN =
1351                Pattern.compile("\\s*\"([^\"]*)\"\\s*");
1352
1353        public static final Cursor query(
1354                ContentResolver cr, String[] projection) {
1355            return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
1356        }
1357
1358        public static final Cursor query(
1359                ContentResolver cr, String[] projection,
1360                String where, String orderBy) {
1361            return cr.query(CONTENT_URI, projection,
1362                    where, null, orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
1363        }
1364
1365        public static final String getMessageBoxName(int msgBox) {
1366            switch (msgBox) {
1367                case MESSAGE_BOX_ALL:
1368                    return "all";
1369                case MESSAGE_BOX_INBOX:
1370                    return "inbox";
1371                case MESSAGE_BOX_SENT:
1372                    return "sent";
1373                case MESSAGE_BOX_DRAFTS:
1374                    return "drafts";
1375                case MESSAGE_BOX_OUTBOX:
1376                    return "outbox";
1377                default:
1378                    throw new IllegalArgumentException("Invalid message box: " + msgBox);
1379            }
1380        }
1381
1382        public static String extractAddrSpec(String address) {
1383            Matcher match = NAME_ADDR_EMAIL_PATTERN.matcher(address);
1384
1385            if (match.matches()) {
1386                return match.group(2);
1387            }
1388            return address;
1389        }
1390
1391        /**
1392         * Returns true if the address is an email address
1393         *
1394         * @param address the input address to be tested
1395         * @return true if address is an email address
1396         */
1397        public static boolean isEmailAddress(String address) {
1398            if (TextUtils.isEmpty(address)) {
1399                return false;
1400            }
1401
1402            String s = extractAddrSpec(address);
1403            Matcher match = Patterns.EMAIL_ADDRESS.matcher(s);
1404            return match.matches();
1405        }
1406
1407        /**
1408         * Returns true if the number is a Phone number
1409         *
1410         * @param number the input number to be tested
1411         * @return true if number is a Phone number
1412         */
1413        public static boolean isPhoneNumber(String number) {
1414            if (TextUtils.isEmpty(number)) {
1415                return false;
1416            }
1417
1418            Matcher match = Patterns.PHONE.matcher(number);
1419            return match.matches();
1420        }
1421
1422        /**
1423         * Contains all MMS messages in the MMS app's inbox.
1424         */
1425        public static final class Inbox implements BaseMmsColumns {
1426            /**
1427             * The content:// style URL for this table
1428             */
1429            public static final Uri
1430                    CONTENT_URI = Uri.parse("content://mms/inbox");
1431
1432            /**
1433             * The default sort order for this table
1434             */
1435            public static final String DEFAULT_SORT_ORDER = "date DESC";
1436        }
1437
1438        /**
1439         * Contains all MMS messages in the MMS app's sent box.
1440         */
1441        public static final class Sent implements BaseMmsColumns {
1442            /**
1443             * The content:// style URL for this table
1444             */
1445            public static final Uri
1446                    CONTENT_URI = Uri.parse("content://mms/sent");
1447
1448            /**
1449             * The default sort order for this table
1450             */
1451            public static final String DEFAULT_SORT_ORDER = "date DESC";
1452        }
1453
1454        /**
1455         * Contains all MMS messages in the MMS app's drafts box.
1456         */
1457        public static final class Draft implements BaseMmsColumns {
1458            /**
1459             * The content:// style URL for this table
1460             */
1461            public static final Uri
1462                    CONTENT_URI = Uri.parse("content://mms/drafts");
1463
1464            /**
1465             * The default sort order for this table
1466             */
1467            public static final String DEFAULT_SORT_ORDER = "date DESC";
1468        }
1469
1470        /**
1471         * Contains all MMS messages in the MMS app's outbox.
1472         */
1473        public static final class Outbox implements BaseMmsColumns {
1474            /**
1475             * The content:// style URL for this table
1476             */
1477            public static final Uri
1478                    CONTENT_URI = Uri.parse("content://mms/outbox");
1479
1480            /**
1481             * The default sort order for this table
1482             */
1483            public static final String DEFAULT_SORT_ORDER = "date DESC";
1484        }
1485
1486        public static final class Addr implements BaseColumns {
1487            /**
1488             * The ID of MM which this address entry belongs to.
1489             */
1490            public static final String MSG_ID = "msg_id";
1491
1492            /**
1493             * The ID of contact entry in Phone Book.
1494             */
1495            public static final String CONTACT_ID = "contact_id";
1496
1497            /**
1498             * The address text.
1499             */
1500            public static final String ADDRESS = "address";
1501
1502            /**
1503             * Type of address, must be one of PduHeaders.BCC,
1504             * PduHeaders.CC, PduHeaders.FROM, PduHeaders.TO.
1505             */
1506            public static final String TYPE = "type";
1507
1508            /**
1509             * Character set of this entry.
1510             */
1511            public static final String CHARSET = "charset";
1512        }
1513
1514        public static final class Part implements BaseColumns {
1515            /**
1516             * The identifier of the message which this part belongs to.
1517             * <P>Type: INTEGER</P>
1518             */
1519            public static final String MSG_ID = "mid";
1520
1521            /**
1522             * The order of the part.
1523             * <P>Type: INTEGER</P>
1524             */
1525            public static final String SEQ = "seq";
1526
1527            /**
1528             * The content type of the part.
1529             * <P>Type: TEXT</P>
1530             */
1531            public static final String CONTENT_TYPE = "ct";
1532
1533            /**
1534             * The name of the part.
1535             * <P>Type: TEXT</P>
1536             */
1537            public static final String NAME = "name";
1538
1539            /**
1540             * The charset of the part.
1541             * <P>Type: TEXT</P>
1542             */
1543            public static final String CHARSET = "chset";
1544
1545            /**
1546             * The file name of the part.
1547             * <P>Type: TEXT</P>
1548             */
1549            public static final String FILENAME = "fn";
1550
1551            /**
1552             * The content disposition of the part.
1553             * <P>Type: TEXT</P>
1554             */
1555            public static final String CONTENT_DISPOSITION = "cd";
1556
1557            /**
1558             * The content ID of the part.
1559             * <P>Type: INTEGER</P>
1560             */
1561            public static final String CONTENT_ID = "cid";
1562
1563            /**
1564             * The content location of the part.
1565             * <P>Type: INTEGER</P>
1566             */
1567            public static final String CONTENT_LOCATION = "cl";
1568
1569            /**
1570             * The start of content-type of the message.
1571             * <P>Type: INTEGER</P>
1572             */
1573            public static final String CT_START = "ctt_s";
1574
1575            /**
1576             * The type of content-type of the message.
1577             * <P>Type: TEXT</P>
1578             */
1579            public static final String CT_TYPE = "ctt_t";
1580
1581            /**
1582             * The location(on filesystem) of the binary data of the part.
1583             * <P>Type: INTEGER</P>
1584             */
1585            public static final String _DATA = "_data";
1586
1587            public static final String TEXT = "text";
1588
1589        }
1590
1591        public static final class Rate {
1592            public static final Uri CONTENT_URI = Uri.withAppendedPath(
1593                    Mms.CONTENT_URI, "rate");
1594            /**
1595             * When a message was successfully sent.
1596             * <P>Type: INTEGER</P>
1597             */
1598            public static final String SENT_TIME = "sent_time";
1599        }
1600
1601        public static final class Intents {
1602            private Intents() {
1603                // Non-instantiatable.
1604            }
1605
1606            /**
1607             * The extra field to store the contents of the Intent,
1608             * which should be an array of Uri.
1609             */
1610            public static final String EXTRA_CONTENTS = "contents";
1611            /**
1612             * The extra field to store the type of the contents,
1613             * which should be an array of String.
1614             */
1615            public static final String EXTRA_TYPES    = "types";
1616            /**
1617             * The extra field to store the 'Cc' addresses.
1618             */
1619            public static final String EXTRA_CC       = "cc";
1620            /**
1621             * The extra field to store the 'Bcc' addresses;
1622             */
1623            public static final String EXTRA_BCC      = "bcc";
1624            /**
1625             * The extra field to store the 'Subject'.
1626             */
1627            public static final String EXTRA_SUBJECT  = "subject";
1628            /**
1629             * Indicates that the contents of specified URIs were changed.
1630             * The application which is showing or caching these contents
1631             * should be updated.
1632             */
1633            public static final String
1634            CONTENT_CHANGED_ACTION = "android.intent.action.CONTENT_CHANGED";
1635            /**
1636             * An extra field which stores the URI of deleted contents.
1637             */
1638            public static final String DELETED_CONTENTS = "deleted_contents";
1639        }
1640    }
1641
1642    /**
1643     * Contains all MMS and SMS messages.
1644     */
1645    public static final class MmsSms implements BaseColumns {
1646        /**
1647         * The column to distinguish SMS &amp; MMS messages in query results.
1648         */
1649        public static final String TYPE_DISCRIMINATOR_COLUMN =
1650                "transport_type";
1651
1652        public static final Uri CONTENT_URI = Uri.parse("content://mms-sms/");
1653
1654        public static final Uri CONTENT_CONVERSATIONS_URI = Uri.parse(
1655                "content://mms-sms/conversations");
1656
1657        public static final Uri CONTENT_FILTER_BYPHONE_URI = Uri.parse(
1658                "content://mms-sms/messages/byphone");
1659
1660        public static final Uri CONTENT_UNDELIVERED_URI = Uri.parse(
1661                "content://mms-sms/undelivered");
1662
1663        public static final Uri CONTENT_DRAFT_URI = Uri.parse(
1664                "content://mms-sms/draft");
1665
1666        public static final Uri CONTENT_LOCKED_URI = Uri.parse(
1667                "content://mms-sms/locked");
1668
1669        /***
1670         * Pass in a query parameter called "pattern" which is the text
1671         * to search for.
1672         * The sort order is fixed to be thread_id ASC,date DESC.
1673         */
1674        public static final Uri SEARCH_URI = Uri.parse(
1675                "content://mms-sms/search");
1676
1677        // Constants for message protocol types.
1678        public static final int SMS_PROTO = 0;
1679        public static final int MMS_PROTO = 1;
1680
1681        // Constants for error types of pending messages.
1682        public static final int NO_ERROR                      = 0;
1683        public static final int ERR_TYPE_GENERIC              = 1;
1684        public static final int ERR_TYPE_SMS_PROTO_TRANSIENT  = 2;
1685        public static final int ERR_TYPE_MMS_PROTO_TRANSIENT  = 3;
1686        public static final int ERR_TYPE_TRANSPORT_FAILURE    = 4;
1687        public static final int ERR_TYPE_GENERIC_PERMANENT    = 10;
1688        public static final int ERR_TYPE_SMS_PROTO_PERMANENT  = 11;
1689        public static final int ERR_TYPE_MMS_PROTO_PERMANENT  = 12;
1690
1691        public static final class PendingMessages implements BaseColumns {
1692            public static final Uri CONTENT_URI = Uri.withAppendedPath(
1693                    MmsSms.CONTENT_URI, "pending");
1694            /**
1695             * The type of transport protocol(MMS or SMS).
1696             * <P>Type: INTEGER</P>
1697             */
1698            public static final String PROTO_TYPE = "proto_type";
1699            /**
1700             * The ID of the message to be sent or downloaded.
1701             * <P>Type: INTEGER</P>
1702             */
1703            public static final String MSG_ID = "msg_id";
1704            /**
1705             * The type of the message to be sent or downloaded.
1706             * This field is only valid for MM. For SM, its value is always
1707             * set to 0.
1708             */
1709            public static final String MSG_TYPE = "msg_type";
1710            /**
1711             * The type of the error code.
1712             * <P>Type: INTEGER</P>
1713             */
1714            public static final String ERROR_TYPE = "err_type";
1715            /**
1716             * The error code of sending/retrieving process.
1717             * <P>Type:  INTEGER</P>
1718             */
1719            public static final String ERROR_CODE = "err_code";
1720            /**
1721             * How many times we tried to send or download the message.
1722             * <P>Type:  INTEGER</P>
1723             */
1724            public static final String RETRY_INDEX = "retry_index";
1725            /**
1726             * The time to do next retry.
1727             */
1728            public static final String DUE_TIME = "due_time";
1729            /**
1730             * The time we last tried to send or download the message.
1731             */
1732            public static final String LAST_TRY = "last_try";
1733        }
1734
1735        public static final class WordsTable {
1736            public static final String ID = "_id";
1737            public static final String SOURCE_ROW_ID = "source_id";
1738            public static final String TABLE_ID = "table_to_use";
1739            public static final String INDEXED_TEXT = "index_text";
1740        }
1741    }
1742
1743    public static final class Carriers implements BaseColumns {
1744        /**
1745         * The content:// style URL for this table
1746         */
1747        public static final Uri CONTENT_URI =
1748            Uri.parse("content://telephony/carriers");
1749
1750        /**
1751         * The default sort order for this table
1752         */
1753        public static final String DEFAULT_SORT_ORDER = "name ASC";
1754
1755        public static final String NAME = "name";
1756
1757        public static final String APN = "apn";
1758
1759        public static final String PROXY = "proxy";
1760
1761        public static final String PORT = "port";
1762
1763        public static final String MMSPROXY = "mmsproxy";
1764
1765        public static final String MMSPORT = "mmsport";
1766
1767        public static final String SERVER = "server";
1768
1769        public static final String USER = "user";
1770
1771        public static final String PASSWORD = "password";
1772
1773        public static final String MMSC = "mmsc";
1774
1775        public static final String MCC = "mcc";
1776
1777        public static final String MNC = "mnc";
1778
1779        public static final String NUMERIC = "numeric";
1780
1781        public static final String AUTH_TYPE = "authtype";
1782
1783        public static final String TYPE = "type";
1784
1785        public static final String INACTIVE_TIMER = "inactivetimer";
1786
1787        // Only if enabled try Data Connection.
1788        public static final String ENABLED = "enabled";
1789
1790        // Rules apply based on class.
1791        public static final String CLASS = "class";
1792
1793        /**
1794         * The protocol to be used to connect to this APN.
1795         *
1796         * One of the PDP_type values in TS 27.007 section 10.1.1.
1797         * For example, "IP", "IPV6", "IPV4V6", or "PPP".
1798         */
1799        public static final String PROTOCOL = "protocol";
1800
1801        /**
1802          * The protocol to be used to connect to this APN when roaming.
1803          *
1804          * The syntax is the same as protocol.
1805          */
1806        public static final String ROAMING_PROTOCOL = "roaming_protocol";
1807
1808        public static final String CURRENT = "current";
1809
1810        /**
1811          * Current status of APN
1812          * true : enabled APN, false : disabled APN.
1813          */
1814        public static final String CARRIER_ENABLED = "carrier_enabled";
1815
1816        /**
1817          * Radio Access Technology info
1818          * To check what values can hold, refer to ServiceState.java.
1819          * This should be spread to other technologies,
1820          * but currently only used for LTE(14) and EHRPD(13).
1821          */
1822        public static final String BEARER = "bearer";
1823    }
1824
1825    /**
1826     * Contains received SMS cell broadcast messages.
1827     */
1828    public static final class CellBroadcasts implements BaseColumns {
1829
1830        /** Not instantiable. */
1831        private CellBroadcasts() {}
1832
1833        /**
1834         * The content:// style URL for this table
1835         */
1836        public static final Uri CONTENT_URI =
1837            Uri.parse("content://cellbroadcasts");
1838
1839        /**
1840         * Message geographical scope.
1841         * <P>Type: INTEGER</P>
1842         */
1843        public static final String GEOGRAPHICAL_SCOPE = "geo_scope";
1844
1845        /**
1846         * Message serial number.
1847         * <P>Type: INTEGER</P>
1848         */
1849        public static final String SERIAL_NUMBER = "serial_number";
1850
1851        /**
1852         * PLMN of broadcast sender. (SERIAL_NUMBER + PLMN + LAC + CID) uniquely identifies a
1853         * broadcast for duplicate detection purposes.
1854         * <P>Type: TEXT</P>
1855         */
1856        public static final String PLMN = "plmn";
1857
1858        /**
1859         * Location Area (GSM) or Service Area (UMTS) of broadcast sender. Unused for CDMA.
1860         * Only included if Geographical Scope of message is not PLMN wide (01).
1861         * <P>Type: INTEGER</P>
1862         */
1863        public static final String LAC = "lac";
1864
1865        /**
1866         * Cell ID of message sender (GSM/UMTS). Unused for CDMA. Only included when the
1867         * Geographical Scope of message is cell wide (00 or 11).
1868         * <P>Type: INTEGER</P>
1869         */
1870        public static final String CID = "cid";
1871
1872        /**
1873         * Message code (OBSOLETE: merged into SERIAL_NUMBER).
1874         * <P>Type: INTEGER</P>
1875         */
1876        public static final String V1_MESSAGE_CODE = "message_code";
1877
1878        /**
1879         * Message identifier (OBSOLETE: renamed to SERVICE_CATEGORY).
1880         * <P>Type: INTEGER</P>
1881         */
1882        public static final String V1_MESSAGE_IDENTIFIER = "message_id";
1883
1884        /**
1885         * Service category (GSM/UMTS message identifier, CDMA service category).
1886         * <P>Type: INTEGER</P>
1887         */
1888        public static final String SERVICE_CATEGORY = "service_category";
1889
1890        /**
1891         * Message language code.
1892         * <P>Type: TEXT</P>
1893         */
1894        public static final String LANGUAGE_CODE = "language";
1895
1896        /**
1897         * Message body.
1898         * <P>Type: TEXT</P>
1899         */
1900        public static final String MESSAGE_BODY = "body";
1901
1902        /**
1903         * Message delivery time.
1904         * <P>Type: INTEGER (long)</P>
1905         */
1906        public static final String DELIVERY_TIME = "date";
1907
1908        /**
1909         * Has the message been viewed?
1910         * <P>Type: INTEGER (boolean)</P>
1911         */
1912        public static final String MESSAGE_READ = "read";
1913
1914        /**
1915         * Message format (3GPP or 3GPP2).
1916         * <P>Type: INTEGER</P>
1917         */
1918        public static final String MESSAGE_FORMAT = "format";
1919
1920        /**
1921         * Message priority (including emergency).
1922         * <P>Type: INTEGER</P>
1923         */
1924        public static final String MESSAGE_PRIORITY = "priority";
1925
1926        /**
1927         * ETWS warning type (ETWS alerts only).
1928         * <P>Type: INTEGER</P>
1929         */
1930        public static final String ETWS_WARNING_TYPE = "etws_warning_type";
1931
1932        /**
1933         * CMAS message class (CMAS alerts only).
1934         * <P>Type: INTEGER</P>
1935         */
1936        public static final String CMAS_MESSAGE_CLASS = "cmas_message_class";
1937
1938        /**
1939         * CMAS category (CMAS alerts only).
1940         * <P>Type: INTEGER</P>
1941         */
1942        public static final String CMAS_CATEGORY = "cmas_category";
1943
1944        /**
1945         * CMAS response type (CMAS alerts only).
1946         * <P>Type: INTEGER</P>
1947         */
1948        public static final String CMAS_RESPONSE_TYPE = "cmas_response_type";
1949
1950        /**
1951         * CMAS severity (CMAS alerts only).
1952         * <P>Type: INTEGER</P>
1953         */
1954        public static final String CMAS_SEVERITY = "cmas_severity";
1955
1956        /**
1957         * CMAS urgency (CMAS alerts only).
1958         * <P>Type: INTEGER</P>
1959         */
1960        public static final String CMAS_URGENCY = "cmas_urgency";
1961
1962        /**
1963         * CMAS certainty (CMAS alerts only).
1964         * <P>Type: INTEGER</P>
1965         */
1966        public static final String CMAS_CERTAINTY = "cmas_certainty";
1967
1968        /**
1969         * The default sort order for this table
1970         */
1971        public static final String DEFAULT_SORT_ORDER = DELIVERY_TIME + " DESC";
1972
1973        /**
1974         * Query columns for instantiating {@link android.telephony.CellBroadcastMessage} objects.
1975         */
1976        public static final String[] QUERY_COLUMNS = {
1977                _ID,
1978                GEOGRAPHICAL_SCOPE,
1979                PLMN,
1980                LAC,
1981                CID,
1982                SERIAL_NUMBER,
1983                SERVICE_CATEGORY,
1984                LANGUAGE_CODE,
1985                MESSAGE_BODY,
1986                DELIVERY_TIME,
1987                MESSAGE_READ,
1988                MESSAGE_FORMAT,
1989                MESSAGE_PRIORITY,
1990                ETWS_WARNING_TYPE,
1991                CMAS_MESSAGE_CLASS,
1992                CMAS_CATEGORY,
1993                CMAS_RESPONSE_TYPE,
1994                CMAS_SEVERITY,
1995                CMAS_URGENCY,
1996                CMAS_CERTAINTY
1997        };
1998    }
1999}
2000