Telephony.java revision dac6bb4a3b2046e1ac943c661563b6daebf49a8f
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.ComponentName;
22import android.content.ContentResolver;
23import android.content.ContentValues;
24import android.content.Context;
25import android.content.Intent;
26import android.database.Cursor;
27import android.database.sqlite.SqliteWrapper;
28import android.net.Uri;
29import android.telephony.SmsMessage;
30import android.telephony.SubscriptionManager;
31import android.text.TextUtils;
32import android.telephony.Rlog;
33import android.util.Patterns;
34
35import com.android.internal.telephony.PhoneConstants;
36import com.android.internal.telephony.SmsApplication;
37
38
39import java.util.HashSet;
40import java.util.Set;
41import java.util.regex.Matcher;
42import java.util.regex.Pattern;
43
44/**
45 * The Telephony provider contains data related to phone operation, specifically SMS and MMS
46 * messages and access to the APN list, including the MMSC to use.
47 *
48 * <p class="note"><strong>Note:</strong> These APIs are not available on all Android-powered
49 * devices. If your app depends on telephony features such as for managing SMS messages, include
50 * a <a href="{@docRoot}guide/topics/manifest/uses-feature-element.html">{@code &lt;uses-feature>}
51 * </a> element in your manifest that declares the {@code "android.hardware.telephony"} hardware
52 * feature. Alternatively, you can check for telephony availability at runtime using either
53 * {@link android.content.pm.PackageManager#hasSystemFeature
54 * hasSystemFeature(PackageManager.FEATURE_TELEPHONY)} or {@link
55 * android.telephony.TelephonyManager#getPhoneType}.</p>
56 *
57 * <h3>Creating an SMS app</h3>
58 *
59 * <p>Only the default SMS app (selected by the user in system settings) is able to write to the
60 * SMS Provider (the tables defined within the {@code Telephony} class) and only the default SMS
61 * app receives the {@link android.provider.Telephony.Sms.Intents#SMS_DELIVER_ACTION} broadcast
62 * when the user receives an SMS or the {@link
63 * android.provider.Telephony.Sms.Intents#WAP_PUSH_DELIVER_ACTION} broadcast when the user
64 * receives an MMS.</p>
65 *
66 * <p>Any app that wants to behave as the user's default SMS app must handle the following intents:
67 * <ul>
68 * <li>In a broadcast receiver, include an intent filter for {@link Sms.Intents#SMS_DELIVER_ACTION}
69 * (<code>"android.provider.Telephony.SMS_DELIVER"</code>). The broadcast receiver must also
70 * require the {@link android.Manifest.permission#BROADCAST_SMS} permission.
71 * <p>This allows your app to directly receive incoming SMS messages.</p></li>
72 * <li>In a broadcast receiver, include an intent filter for {@link
73 * Sms.Intents#WAP_PUSH_DELIVER_ACTION}} ({@code "android.provider.Telephony.WAP_PUSH_DELIVER"})
74 * with the MIME type <code>"application/vnd.wap.mms-message"</code>.
75 * The broadcast receiver must also require the {@link
76 * android.Manifest.permission#BROADCAST_WAP_PUSH} permission.
77 * <p>This allows your app to directly receive incoming MMS messages.</p></li>
78 * <li>In your activity that delivers new messages, include an intent filter for
79 * {@link android.content.Intent#ACTION_SENDTO} (<code>"android.intent.action.SENDTO"
80 * </code>) with schemas, <code>sms:</code>, <code>smsto:</code>, <code>mms:</code>, and
81 * <code>mmsto:</code>.
82 * <p>This allows your app to receive intents from other apps that want to deliver a
83 * message.</p></li>
84 * <li>In a service, include an intent filter for {@link
85 * android.telephony.TelephonyManager#ACTION_RESPOND_VIA_MESSAGE}
86 * (<code>"android.intent.action.RESPOND_VIA_MESSAGE"</code>) with schemas,
87 * <code>sms:</code>, <code>smsto:</code>, <code>mms:</code>, and <code>mmsto:</code>.
88 * This service must also require the {@link
89 * android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE} permission.
90 * <p>This allows users to respond to incoming phone calls with an immediate text message
91 * using your app.</p></li>
92 * </ul>
93 *
94 * <p>Other apps that are not selected as the default SMS app can only <em>read</em> the SMS
95 * Provider, but may also be notified when a new SMS arrives by listening for the {@link
96 * Sms.Intents#SMS_RECEIVED_ACTION}
97 * broadcast, which is a non-abortable broadcast that may be delivered to multiple apps. This
98 * broadcast is intended for apps that&mdash;while not selected as the default SMS app&mdash;need to
99 * read special incoming messages such as to perform phone number verification.</p>
100 *
101 * <p>For more information about building SMS apps, read the blog post, <a
102 * href="http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html"
103 * >Getting Your SMS Apps Ready for KitKat</a>.</p>
104 *
105 */
106public final class Telephony {
107    private static final String TAG = "Telephony";
108
109    /**
110     * Not instantiable.
111     * @hide
112     */
113    private Telephony() {
114    }
115
116    /**
117     * Base columns for tables that contain text-based SMSs.
118     */
119    public interface TextBasedSmsColumns {
120
121        /** Message type: all messages. */
122        public static final int MESSAGE_TYPE_ALL    = 0;
123
124        /** Message type: inbox. */
125        public static final int MESSAGE_TYPE_INBOX  = 1;
126
127        /** Message type: sent messages. */
128        public static final int MESSAGE_TYPE_SENT   = 2;
129
130        /** Message type: drafts. */
131        public static final int MESSAGE_TYPE_DRAFT  = 3;
132
133        /** Message type: outbox. */
134        public static final int MESSAGE_TYPE_OUTBOX = 4;
135
136        /** Message type: failed outgoing message. */
137        public static final int MESSAGE_TYPE_FAILED = 5;
138
139        /** Message type: queued to send later. */
140        public static final int MESSAGE_TYPE_QUEUED = 6;
141
142        /**
143         * The type of message.
144         * <P>Type: INTEGER</P>
145         */
146        public static final String TYPE = "type";
147
148        /**
149         * The thread ID of the message.
150         * <P>Type: INTEGER</P>
151         */
152        public static final String THREAD_ID = "thread_id";
153
154        /**
155         * The address of the other party.
156         * <P>Type: TEXT</P>
157         */
158        public static final String ADDRESS = "address";
159
160        /**
161         * The date the message was received.
162         * <P>Type: INTEGER (long)</P>
163         */
164        public static final String DATE = "date";
165
166        /**
167         * The date the message was sent.
168         * <P>Type: INTEGER (long)</P>
169         */
170        public static final String DATE_SENT = "date_sent";
171
172        /**
173         * Has the message been read?
174         * <P>Type: INTEGER (boolean)</P>
175         */
176        public static final String READ = "read";
177
178        /**
179         * Has the message been seen by the user? The "seen" flag determines
180         * whether we need to show a notification.
181         * <P>Type: INTEGER (boolean)</P>
182         */
183        public static final String SEEN = "seen";
184
185        /**
186         * {@code TP-Status} value for the message, or -1 if no status has been received.
187         * <P>Type: INTEGER</P>
188         */
189        public static final String STATUS = "status";
190
191        /** TP-Status: no status received. */
192        public static final int STATUS_NONE = -1;
193        /** TP-Status: complete. */
194        public static final int STATUS_COMPLETE = 0;
195        /** TP-Status: pending. */
196        public static final int STATUS_PENDING = 32;
197        /** TP-Status: failed. */
198        public static final int STATUS_FAILED = 64;
199
200        /**
201         * The subject of the message, if present.
202         * <P>Type: TEXT</P>
203         */
204        public static final String SUBJECT = "subject";
205
206        /**
207         * The body of the message.
208         * <P>Type: TEXT</P>
209         */
210        public static final String BODY = "body";
211
212        /**
213         * The ID of the sender of the conversation, if present.
214         * <P>Type: INTEGER (reference to item in {@code content://contacts/people})</P>
215         */
216        public static final String PERSON = "person";
217
218        /**
219         * The protocol identifier code.
220         * <P>Type: INTEGER</P>
221         */
222        public static final String PROTOCOL = "protocol";
223
224        /**
225         * Is the {@code TP-Reply-Path} flag set?
226         * <P>Type: BOOLEAN</P>
227         */
228        public static final String REPLY_PATH_PRESENT = "reply_path_present";
229
230        /**
231         * The service center (SC) through which to send the message, if present.
232         * <P>Type: TEXT</P>
233         */
234        public static final String SERVICE_CENTER = "service_center";
235
236        /**
237         * Is the message locked?
238         * <P>Type: INTEGER (boolean)</P>
239         */
240        public static final String LOCKED = "locked";
241
242        /**
243         * The sub_id to which the message belongs to
244         * <p>Type: INTEGER (long) </p>
245         * @hide
246         */
247        public static final String SUB_ID = "sub_id";
248
249        /**
250         * The MTU size of the mobile interface to which the APN connected
251         * @hide
252         */
253        public static final String MTU = "mtu";
254
255        /**
256         * Error code associated with sending or receiving this message
257         * <P>Type: INTEGER</P>
258         */
259        public static final String ERROR_CODE = "error_code";
260
261        /**
262         * The identity of the sender of a sent message. It is
263         * usually the package name of the app which sends the message.
264         * <p>Type: TEXT</p>
265         */
266        public static final String CREATOR = "creator";
267    }
268
269    /**
270     * Contains all text-based SMS messages.
271     */
272    public static final class Sms implements BaseColumns, TextBasedSmsColumns {
273
274        /**
275         * Not instantiable.
276         * @hide
277         */
278        private Sms() {
279        }
280
281        /**
282         * Used to determine the currently configured default SMS package.
283         * @param context context of the requesting application
284         * @return package name for the default SMS package or null
285         */
286        public static String getDefaultSmsPackage(Context context) {
287            ComponentName component = SmsApplication.getDefaultSmsApplication(context, false);
288            if (component != null) {
289                return component.getPackageName();
290            }
291            return null;
292        }
293
294        /**
295         * Return cursor for table query.
296         * @hide
297         */
298        public static Cursor query(ContentResolver cr, String[] projection) {
299            return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
300        }
301
302        /**
303         * Return cursor for table query.
304         * @hide
305         */
306        public static Cursor query(ContentResolver cr, String[] projection,
307                String where, String orderBy) {
308            return cr.query(CONTENT_URI, projection, where,
309                    null, orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
310        }
311
312        /**
313         * The {@code content://} style URL for this table.
314         */
315        public static final Uri CONTENT_URI = Uri.parse("content://sms");
316
317        /**
318         * The default sort order for this table.
319         */
320        public static final String DEFAULT_SORT_ORDER = "date DESC";
321
322        /**
323         * Add an SMS to the given URI.
324         *
325         * @param resolver the content resolver to use
326         * @param uri the URI to add the message to
327         * @param address the address of the sender
328         * @param body the body of the message
329         * @param subject the pseudo-subject of the message
330         * @param date the timestamp for the message
331         * @param read true if the message has been read, false if not
332         * @param deliveryReport true if a delivery report was requested, false if not
333         * @return the URI for the new message
334         * @hide
335         */
336        public static Uri addMessageToUri(ContentResolver resolver,
337                Uri uri, String address, String body, String subject,
338                Long date, boolean read, boolean deliveryReport) {
339            return addMessageToUri(SubscriptionManager.getPreferredSmsSubId(),
340                    resolver, uri, address, body, subject, date, read, deliveryReport, -1L);
341        }
342
343        /**
344         * Add an SMS to the given URI.
345         *
346         * @param resolver the content resolver to use
347         * @param uri the URI to add the message to
348         * @param address the address of the sender
349         * @param body the body of the message
350         * @param subject the psuedo-subject of the message
351         * @param date the timestamp for the message
352         * @param read true if the message has been read, false if not
353         * @param deliveryReport true if a delivery report was requested, false if not
354         * @param subId the sub_id which the message belongs to
355         * @return the URI for the new message
356         * @hide
357         */
358        public static Uri addMessageToUri(long subId, ContentResolver resolver,
359                Uri uri, String address, String body, String subject,
360                Long date, boolean read, boolean deliveryReport) {
361            return addMessageToUri(subId, resolver, uri, address, body, subject,
362                    date, read, deliveryReport, -1L);
363        }
364
365        /**
366         * Add an SMS to the given URI with the specified thread ID.
367         *
368         * @param resolver the content resolver to use
369         * @param uri the URI to add the message to
370         * @param address the address of the sender
371         * @param body the body of the message
372         * @param subject the pseudo-subject of the message
373         * @param date the timestamp for the message
374         * @param read true if the message has been read, false if not
375         * @param deliveryReport true if a delivery report was requested, false if not
376         * @param threadId the thread_id of the message
377         * @return the URI for the new message
378         * @hide
379         */
380        public static Uri addMessageToUri(ContentResolver resolver,
381                Uri uri, String address, String body, String subject,
382                Long date, boolean read, boolean deliveryReport, long threadId) {
383            return addMessageToUri(SubscriptionManager.getPreferredSmsSubId(),
384                    resolver, uri, address, body, subject,
385                    date, read, deliveryReport, threadId);
386        }
387
388        /**
389         * Add an SMS to the given URI with thread_id specified.
390         *
391         * @param resolver the content resolver to use
392         * @param uri the URI to add the message to
393         * @param address the address of the sender
394         * @param body the body of the message
395         * @param subject the psuedo-subject of the message
396         * @param date the timestamp for the message
397         * @param read true if the message has been read, false if not
398         * @param deliveryReport true if a delivery report was requested, false if not
399         * @param threadId the thread_id of the message
400         * @param subId the sub_id which the message belongs to
401         * @return the URI for the new message
402         * @hide
403         */
404        public static Uri addMessageToUri(long subId, ContentResolver resolver,
405                Uri uri, String address, String body, String subject,
406                Long date, boolean read, boolean deliveryReport, long threadId) {
407            ContentValues values = new ContentValues(8);
408            Rlog.v(TAG,"Telephony addMessageToUri sub id: " + subId);
409
410            values.put(SUB_ID, subId);
411            values.put(ADDRESS, address);
412            if (date != null) {
413                values.put(DATE, date);
414            }
415            values.put(READ, read ? Integer.valueOf(1) : Integer.valueOf(0));
416            values.put(SUBJECT, subject);
417            values.put(BODY, body);
418            if (deliveryReport) {
419                values.put(STATUS, STATUS_PENDING);
420            }
421            if (threadId != -1L) {
422                values.put(THREAD_ID, threadId);
423            }
424            return resolver.insert(uri, values);
425        }
426
427        /**
428         * Move a message to the given folder.
429         *
430         * @param context the context to use
431         * @param uri the message to move
432         * @param folder the folder to move to
433         * @return true if the operation succeeded
434         * @hide
435         */
436        public static boolean moveMessageToFolder(Context context,
437                Uri uri, int folder, int error) {
438            if (uri == null) {
439                return false;
440            }
441
442            boolean markAsUnread = false;
443            boolean markAsRead = false;
444            switch(folder) {
445            case MESSAGE_TYPE_INBOX:
446            case MESSAGE_TYPE_DRAFT:
447                break;
448            case MESSAGE_TYPE_OUTBOX:
449            case MESSAGE_TYPE_SENT:
450                markAsRead = true;
451                break;
452            case MESSAGE_TYPE_FAILED:
453            case MESSAGE_TYPE_QUEUED:
454                markAsUnread = true;
455                break;
456            default:
457                return false;
458            }
459
460            ContentValues values = new ContentValues(3);
461
462            values.put(TYPE, folder);
463            if (markAsUnread) {
464                values.put(READ, 0);
465            } else if (markAsRead) {
466                values.put(READ, 1);
467            }
468            values.put(ERROR_CODE, error);
469
470            return 1 == SqliteWrapper.update(context, context.getContentResolver(),
471                            uri, values, null, null);
472        }
473
474        /**
475         * Returns true iff the folder (message type) identifies an
476         * outgoing message.
477         * @hide
478         */
479        public static boolean isOutgoingFolder(int messageType) {
480            return  (messageType == MESSAGE_TYPE_FAILED)
481                    || (messageType == MESSAGE_TYPE_OUTBOX)
482                    || (messageType == MESSAGE_TYPE_SENT)
483                    || (messageType == MESSAGE_TYPE_QUEUED);
484        }
485
486        /**
487         * Contains all text-based SMS messages in the SMS app inbox.
488         */
489        public static final class Inbox implements BaseColumns, TextBasedSmsColumns {
490
491            /**
492             * Not instantiable.
493             * @hide
494             */
495            private Inbox() {
496            }
497
498            /**
499             * The {@code content://} style URL for this table.
500             */
501            public static final Uri CONTENT_URI = Uri.parse("content://sms/inbox");
502
503            /**
504             * The default sort order for this table.
505             */
506            public static final String DEFAULT_SORT_ORDER = "date DESC";
507
508            /**
509             * Add an SMS to the Draft box.
510             *
511             * @param resolver the content resolver to use
512             * @param address the address of the sender
513             * @param body the body of the message
514             * @param subject the pseudo-subject of the message
515             * @param date the timestamp for the message
516             * @param read true if the message has been read, false if not
517             * @return the URI for the new message
518             * @hide
519             */
520            public static Uri addMessage(ContentResolver resolver,
521                    String address, String body, String subject, Long date,
522                    boolean read) {
523                return addMessageToUri(SubscriptionManager.getPreferredSmsSubId(),
524                        resolver, CONTENT_URI, address, body, subject, date, read, false);
525            }
526
527            /**
528             * Add an SMS to the Draft box.
529             *
530             * @param resolver the content resolver to use
531             * @param address the address of the sender
532             * @param body the body of the message
533             * @param subject the psuedo-subject of the message
534             * @param date the timestamp for the message
535             * @param read true if the message has been read, false if not
536             * @param subId the sub_id which the message belongs to
537             * @return the URI for the new message
538             * @hide
539             */
540            public static Uri addMessage(long subId, ContentResolver resolver,
541                    String address, String body, String subject, Long date, boolean read) {
542                return addMessageToUri(subId, resolver, CONTENT_URI, address, body,
543                        subject, date, read, false);
544            }
545        }
546
547        /**
548         * Contains all sent text-based SMS messages in the SMS app.
549         */
550        public static final class Sent implements BaseColumns, TextBasedSmsColumns {
551
552            /**
553             * Not instantiable.
554             * @hide
555             */
556            private Sent() {
557            }
558
559            /**
560             * The {@code content://} style URL for this table.
561             */
562            public static final Uri CONTENT_URI = Uri.parse("content://sms/sent");
563
564            /**
565             * The default sort order for this table.
566             */
567            public static final String DEFAULT_SORT_ORDER = "date DESC";
568
569            /**
570             * Add an SMS to the Draft box.
571             *
572             * @param resolver the content resolver to use
573             * @param address the address of the sender
574             * @param body the body of the message
575             * @param subject the pseudo-subject of the message
576             * @param date the timestamp for the message
577             * @return the URI for the new message
578             * @hide
579             */
580            public static Uri addMessage(ContentResolver resolver,
581                    String address, String body, String subject, Long date) {
582                return addMessageToUri(SubscriptionManager.getPreferredSmsSubId(),
583                        resolver, CONTENT_URI, address, body, subject, date, true, false);
584            }
585
586            /**
587             * Add an SMS to the Draft box.
588             *
589             * @param resolver the content resolver to use
590             * @param address the address of the sender
591             * @param body the body of the message
592             * @param subject the psuedo-subject of the message
593             * @param date the timestamp for the message
594             * @param subId the sub_id which the message belongs to
595             * @return the URI for the new message
596             * @hide
597             */
598            public static Uri addMessage(long subId, ContentResolver resolver,
599                    String address, String body, String subject, Long date) {
600                return addMessageToUri(subId, resolver, CONTENT_URI, address, body,
601                        subject, date, true, false);
602            }
603        }
604
605        /**
606         * Contains all sent text-based SMS messages in the SMS app.
607         */
608        public static final class Draft implements BaseColumns, TextBasedSmsColumns {
609
610            /**
611             * Not instantiable.
612             * @hide
613             */
614            private Draft() {
615            }
616
617            /**
618             * The {@code content://} style URL for this table.
619             */
620            public static final Uri CONTENT_URI = Uri.parse("content://sms/draft");
621
622           /**
623            * @hide
624            */
625            public static Uri addMessage(ContentResolver resolver,
626                    String address, String body, String subject, Long date) {
627                return addMessageToUri(SubscriptionManager.getPreferredSmsSubId(),
628                        resolver, CONTENT_URI, address, body, subject, date, true, false);
629            }
630
631            /**
632             * Add an SMS to the Draft box.
633             *
634             * @param resolver the content resolver to use
635             * @param address the address of the sender
636             * @param body the body of the message
637             * @param subject the psuedo-subject of the message
638             * @param date the timestamp for the message
639             * @param subId the sub_id which the message belongs to
640             * @return the URI for the new message
641             * @hide
642             */
643            public static Uri addMessage(long subId, ContentResolver resolver,
644                    String address, String body, String subject, Long date) {
645                return addMessageToUri(subId, resolver, CONTENT_URI, address, body,
646                        subject, date, true, false);
647            }
648
649            /**
650             * The default sort order for this table.
651             */
652            public static final String DEFAULT_SORT_ORDER = "date DESC";
653        }
654
655        /**
656         * Contains all pending outgoing text-based SMS messages.
657         */
658        public static final class Outbox implements BaseColumns, TextBasedSmsColumns {
659
660            /**
661             * Not instantiable.
662             * @hide
663             */
664            private Outbox() {
665            }
666
667            /**
668             * The {@code content://} style URL for this table.
669             */
670            public static final Uri CONTENT_URI = Uri.parse("content://sms/outbox");
671
672            /**
673             * The default sort order for this table.
674             */
675            public static final String DEFAULT_SORT_ORDER = "date DESC";
676
677            /**
678             * Add an SMS to the outbox.
679             *
680             * @param resolver the content resolver to use
681             * @param address the address of the sender
682             * @param body the body of the message
683             * @param subject the pseudo-subject of the message
684             * @param date the timestamp for the message
685             * @param deliveryReport whether a delivery report was requested for the message
686             * @return the URI for the new message
687             * @hide
688             */
689            public static Uri addMessage(ContentResolver resolver,
690                    String address, String body, String subject, Long date,
691                    boolean deliveryReport, long threadId) {
692                return addMessageToUri(SubscriptionManager.getPreferredSmsSubId(),
693                        resolver, CONTENT_URI, address, body, subject, date,
694                        true, deliveryReport, threadId);
695            }
696
697            /**
698             * Add an SMS to the Out box.
699             *
700             * @param resolver the content resolver to use
701             * @param address the address of the sender
702             * @param body the body of the message
703             * @param subject the psuedo-subject of the message
704             * @param date the timestamp for the message
705             * @param deliveryReport whether a delivery report was requested for the message
706             * @param subId the sub_id which the message belongs to
707             * @return the URI for the new message
708             * @hide
709             */
710            public static Uri addMessage(long subId, ContentResolver resolver,
711                    String address, String body, String subject, Long date,
712                    boolean deliveryReport, long threadId) {
713                return addMessageToUri(subId, resolver, CONTENT_URI, address, body,
714                        subject, date, true, deliveryReport, threadId);
715            }
716        }
717
718        /**
719         * Contains all sent text-based SMS messages in the SMS app.
720         */
721        public static final class Conversations
722                implements BaseColumns, TextBasedSmsColumns {
723
724            /**
725             * Not instantiable.
726             * @hide
727             */
728            private Conversations() {
729            }
730
731            /**
732             * The {@code content://} style URL for this table.
733             */
734            public static final Uri CONTENT_URI = Uri.parse("content://sms/conversations");
735
736            /**
737             * The default sort order for this table.
738             */
739            public static final String DEFAULT_SORT_ORDER = "date DESC";
740
741            /**
742             * The first 45 characters of the body of the message.
743             * <P>Type: TEXT</P>
744             */
745            public static final String SNIPPET = "snippet";
746
747            /**
748             * The number of messages in the conversation.
749             * <P>Type: INTEGER</P>
750             */
751            public static final String MESSAGE_COUNT = "msg_count";
752        }
753
754        /**
755         * Contains constants for SMS related Intents that are broadcast.
756         */
757        public static final class Intents {
758
759            /**
760             * Not instantiable.
761             * @hide
762             */
763            private Intents() {
764            }
765
766            /**
767             * Set by BroadcastReceiver to indicate that the message was handled
768             * successfully.
769             */
770            public static final int RESULT_SMS_HANDLED = 1;
771
772            /**
773             * Set by BroadcastReceiver to indicate a generic error while
774             * processing the message.
775             */
776            public static final int RESULT_SMS_GENERIC_ERROR = 2;
777
778            /**
779             * Set by BroadcastReceiver to indicate insufficient memory to store
780             * the message.
781             */
782            public static final int RESULT_SMS_OUT_OF_MEMORY = 3;
783
784            /**
785             * Set by BroadcastReceiver to indicate that the message, while
786             * possibly valid, is of a format or encoding that is not
787             * supported.
788             */
789            public static final int RESULT_SMS_UNSUPPORTED = 4;
790
791            /**
792             * Set by BroadcastReceiver to indicate a duplicate incoming message.
793             */
794            public static final int RESULT_SMS_DUPLICATED = 5;
795
796            /**
797             * Activity action: Ask the user to change the default
798             * SMS application. This will show a dialog that asks the
799             * user whether they want to replace the current default
800             * SMS application with the one specified in
801             * {@link #EXTRA_PACKAGE_NAME}.
802             */
803            @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
804            public static final String ACTION_CHANGE_DEFAULT =
805                    "android.provider.Telephony.ACTION_CHANGE_DEFAULT";
806
807            /**
808             * The PackageName string passed in as an
809             * extra for {@link #ACTION_CHANGE_DEFAULT}
810             *
811             * @see #ACTION_CHANGE_DEFAULT
812             */
813            public static final String EXTRA_PACKAGE_NAME = "package";
814
815            /**
816             * Broadcast Action: A new text-based SMS message has been received
817             * by the device. This intent will only be delivered to the default
818             * sms app. That app is responsible for writing the message and notifying
819             * the user. The intent will have the following extra values:</p>
820             *
821             * <ul>
822             *   <li><em>"pdus"</em> - An Object[] of byte[]s containing the PDUs
823             *   that make up the message.</li>
824             * </ul>
825             *
826             * <p>The extra values can be extracted using
827             * {@link #getMessagesFromIntent(Intent)}.</p>
828             *
829             * <p>If a BroadcastReceiver encounters an error while processing
830             * this intent it should set the result code appropriately.</p>
831             *
832             * <p class="note"><strong>Note:</strong>
833             * The broadcast receiver that filters for this intent must declare
834             * {@link android.Manifest.permission#BROADCAST_SMS} as a required permission in
835             * the <a href="{@docRoot}guide/topics/manifest/receiver-element.html">{@code
836             * &lt;receiver>}</a> tag.
837             */
838            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
839            public static final String SMS_DELIVER_ACTION =
840                    "android.provider.Telephony.SMS_DELIVER";
841
842            /**
843             * Broadcast Action: A new text-based SMS message has been received
844             * by the device. This intent will only be delivered to a
845             * carrier app which is responsible for filtering the message.
846             * If the carrier app wants to drop a message, it should set the result
847             * code to {@link android.app.Activity#RESULT_CANCELED}. The carrier app can
848             * also modify the SMS PDU by setting the "pdus" value in result extras.</p>
849             *
850             * The intent will have the following extra values:</p>
851             *
852             * <ul>
853             *   <li><em>"pdus"</em> - An Object[] of byte[]s containing the PDUs
854             *   that make up the message.</li>
855             *   <li><em>"format"</em> - A String describing the format of the PDUs. It can
856             *   be either "3gpp" or "3gpp2".</li>
857             *   <li><em>"destport"</em> - An int describing the destination port of a data
858             *   SMS. It will be -1 for text SMS.</li>
859             * </ul>
860             *
861             * <p>The extra values can be extracted using
862             * {@link #getMessagesFromIntent(Intent)}.</p>
863             *
864             * <p class="note"><strong>Note:</strong>
865             * The broadcast receiver that filters for this intent must be a carrier privileged app.
866             * It must also declare {@link android.Manifest.permission#BROADCAST_SMS} as a required
867             * permission in the <a href="{@docRoot}guide/topics/manifest/receiver-element.html">
868             * {@code &lt;receiver>}</a> tag.
869             */
870            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
871            public static final String SMS_FILTER_ACTION =
872                    "android.provider.Telephony.SMS_FILTER";
873
874            /**
875             * Broadcast Action: A new text-based SMS message has been received
876             * by the device. This intent will be delivered to all registered
877             * receivers as a notification. These apps are not expected to write the
878             * message or notify the user. The intent will have the following extra
879             * values:</p>
880             *
881             * <ul>
882             *   <li><em>"pdus"</em> - An Object[] of byte[]s containing the PDUs
883             *   that make up the message.</li>
884             * </ul>
885             *
886             * <p>The extra values can be extracted using
887             * {@link #getMessagesFromIntent(Intent)}.</p>
888             *
889             * <p>If a BroadcastReceiver encounters an error while processing
890             * this intent it should set the result code appropriately.</p>
891             */
892            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
893            public static final String SMS_RECEIVED_ACTION =
894                    "android.provider.Telephony.SMS_RECEIVED";
895
896            /**
897             * Broadcast Action: A new data based SMS message has been received
898             * by the device. This intent will be delivered to all registered
899             * receivers as a notification. The intent will have the following extra
900             * values:</p>
901             *
902             * <ul>
903             *   <li><em>"pdus"</em> - An Object[] of byte[]s containing the PDUs
904             *   that make up the message.</li>
905             * </ul>
906             *
907             * <p>The extra values can be extracted using
908             * {@link #getMessagesFromIntent(Intent)}.</p>
909             *
910             * <p>If a BroadcastReceiver encounters an error while processing
911             * this intent it should set the result code appropriately.</p>
912             */
913            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
914            public static final String DATA_SMS_RECEIVED_ACTION =
915                    "android.intent.action.DATA_SMS_RECEIVED";
916
917            /**
918             * Broadcast Action: A new WAP PUSH message has been received by the
919             * device. This intent will only be delivered to the default
920             * sms app. That app is responsible for writing the message and notifying
921             * the user. The intent will have the following extra values:</p>
922             *
923             * <ul>
924             *   <li><em>"transactionId"</em> - (Integer) The WAP transaction ID</li>
925             *   <li><em>"pduType"</em> - (Integer) The WAP PDU type</li>
926             *   <li><em>"header"</em> - (byte[]) The header of the message</li>
927             *   <li><em>"data"</em> - (byte[]) The data payload of the message</li>
928             *   <li><em>"contentTypeParameters" </em>
929             *   -(HashMap&lt;String,String&gt;) Any parameters associated with the content type
930             *   (decoded from the WSP Content-Type header)</li>
931             * </ul>
932             *
933             * <p>If a BroadcastReceiver encounters an error while processing
934             * this intent it should set the result code appropriately.</p>
935             *
936             * <p>The contentTypeParameters extra value is map of content parameters keyed by
937             * their names.</p>
938             *
939             * <p>If any unassigned well-known parameters are encountered, the key of the map will
940             * be 'unassigned/0x...', where '...' is the hex value of the unassigned parameter.  If
941             * a parameter has No-Value the value in the map will be null.</p>
942             *
943             * <p class="note"><strong>Note:</strong>
944             * The broadcast receiver that filters for this intent must declare
945             * {@link android.Manifest.permission#BROADCAST_WAP_PUSH} as a required permission in
946             * the <a href="{@docRoot}guide/topics/manifest/receiver-element.html">{@code
947             * &lt;receiver>}</a> tag.
948             */
949            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
950            public static final String WAP_PUSH_DELIVER_ACTION =
951                    "android.provider.Telephony.WAP_PUSH_DELIVER";
952
953            /**
954             * Broadcast Action: A new WAP PUSH message has been received by the
955             * device. This intent will be delivered to all registered
956             * receivers as a notification. These apps are not expected to write the
957             * message or notify the user. The intent will have the following extra
958             * values:</p>
959             *
960             * <ul>
961             *   <li><em>"transactionId"</em> - (Integer) The WAP transaction ID</li>
962             *   <li><em>"pduType"</em> - (Integer) The WAP PDU type</li>
963             *   <li><em>"header"</em> - (byte[]) The header of the message</li>
964             *   <li><em>"data"</em> - (byte[]) The data payload of the message</li>
965             *   <li><em>"contentTypeParameters"</em>
966             *   - (HashMap&lt;String,String&gt;) Any parameters associated with the content type
967             *   (decoded from the WSP Content-Type header)</li>
968             * </ul>
969             *
970             * <p>If a BroadcastReceiver encounters an error while processing
971             * this intent it should set the result code appropriately.</p>
972             *
973             * <p>The contentTypeParameters extra value is map of content parameters keyed by
974             * their names.</p>
975             *
976             * <p>If any unassigned well-known parameters are encountered, the key of the map will
977             * be 'unassigned/0x...', where '...' is the hex value of the unassigned parameter.  If
978             * a parameter has No-Value the value in the map will be null.</p>
979             */
980            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
981            public static final String WAP_PUSH_RECEIVED_ACTION =
982                    "android.provider.Telephony.WAP_PUSH_RECEIVED";
983
984            /**
985             * Broadcast Action: A new Cell Broadcast message has been received
986             * by the device. The intent will have the following extra
987             * values:</p>
988             *
989             * <ul>
990             *   <li><em>"message"</em> - An SmsCbMessage object containing the broadcast message
991             *   data. This is not an emergency alert, so ETWS and CMAS data will be null.</li>
992             * </ul>
993             *
994             * <p>The extra values can be extracted using
995             * {@link #getMessagesFromIntent(Intent)}.</p>
996             *
997             * <p>If a BroadcastReceiver encounters an error while processing
998             * this intent it should set the result code appropriately.</p>
999             */
1000            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1001            public static final String SMS_CB_RECEIVED_ACTION =
1002                    "android.provider.Telephony.SMS_CB_RECEIVED";
1003
1004            /**
1005             * Broadcast Action: A new Emergency Broadcast message has been received
1006             * by the device. The intent will have the following extra
1007             * values:</p>
1008             *
1009             * <ul>
1010             *   <li><em>"message"</em> - An SmsCbMessage object containing the broadcast message
1011             *   data, including ETWS or CMAS warning notification info if present.</li>
1012             * </ul>
1013             *
1014             * <p>The extra values can be extracted using
1015             * {@link #getMessagesFromIntent(Intent)}.</p>
1016             *
1017             * <p>If a BroadcastReceiver encounters an error while processing
1018             * this intent it should set the result code appropriately.</p>
1019             */
1020            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1021            public static final String SMS_EMERGENCY_CB_RECEIVED_ACTION =
1022                    "android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED";
1023
1024            /**
1025             * Broadcast Action: A new CDMA SMS has been received containing Service Category
1026             * Program Data (updates the list of enabled broadcast channels). The intent will
1027             * have the following extra values:</p>
1028             *
1029             * <ul>
1030             *   <li><em>"operations"</em> - An array of CdmaSmsCbProgramData objects containing
1031             *   the service category operations (add/delete/clear) to perform.</li>
1032             * </ul>
1033             *
1034             * <p>The extra values can be extracted using
1035             * {@link #getMessagesFromIntent(Intent)}.</p>
1036             *
1037             * <p>If a BroadcastReceiver encounters an error while processing
1038             * this intent it should set the result code appropriately.</p>
1039             */
1040            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1041            public static final String SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED_ACTION =
1042                    "android.provider.Telephony.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED";
1043
1044            /**
1045             * Broadcast Action: The SIM storage for SMS messages is full.  If
1046             * space is not freed, messages targeted for the SIM (class 2) may
1047             * not be saved.
1048             */
1049            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1050            public static final String SIM_FULL_ACTION =
1051                    "android.provider.Telephony.SIM_FULL";
1052
1053            /**
1054             * Broadcast Action: An incoming SMS has been rejected by the
1055             * telephony framework.  This intent is sent in lieu of any
1056             * of the RECEIVED_ACTION intents.  The intent will have the
1057             * following extra value:</p>
1058             *
1059             * <ul>
1060             *   <li><em>"result"</em> - An int result code, e.g. {@link #RESULT_SMS_OUT_OF_MEMORY}
1061             *   indicating the error returned to the network.</li>
1062             * </ul>
1063             */
1064            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1065            public static final String SMS_REJECTED_ACTION =
1066                "android.provider.Telephony.SMS_REJECTED";
1067
1068            /**
1069             * Broadcast Action: A new SMS PDU needs to be sent from
1070             * the device. This intent will only be delivered to a
1071             * carrier app. That app is responsible for sending the PDU.
1072             * The intent will have the following extra values:</p>
1073             *
1074             * <ul>
1075             *   <li><em>"pdu"</em> - (byte[]) The PDU to send.</li>
1076             *   <li><em>"smsc"</em> - (byte[]) The service center address (for GSM PDU only).</li>
1077             *   <li><em>"format"</em> - (String) The format of the PDU. Either 3gpp or 3gpp2. </li>
1078             *   <li><em>"concat.refNumber"</em> - (int) If the SMS is part of a multi-part SMS, the
1079             *   ref number used in the SMS header.</li>
1080             *   <li><em>"concat.seqNumber"</em> - (int) If the SMS is part of a multi-part SMS, the
1081             *   sequence number of this SMS.</li>
1082             *   <li><em>"concat.msgCount"</em> - (int) If the SMS is part of a multi-part SMS, the
1083             *   total number of SMSes in the multi-part SMS.</li>
1084             * </ul>
1085             *
1086             * <p>If a BroadcastReceiver is trying to send the message,
1087             *  it should set the result code to {@link android.app.Activity#RESULT_OK} and set
1088             *  the following in the result extra values:</p>
1089             *
1090             * <ul>
1091             *   <li><em>"messageref"</em> - (int) The new message reference number which will be
1092             *   later used in the updateSmsSendStatus call.</li>
1093             * </ul>
1094             *
1095             * <p>If a BroadcastReceiver cannot send the message, it should not set the result
1096             *  code and the platform will send it via the normal pathway.
1097             * </p>
1098             *
1099             * <p class="note"><strong>Note:</strong>
1100             * The broadcast receiver that filters for this intent must be a carrier privileged app.
1101             * It must also declare {@link android.Manifest.permission#BROADCAST_SMS} as a required
1102             * permission in the <a href="{@docRoot}guide/topics/manifest/receiver-element.html">
1103             * {@code &lt;receiver>}</a> tag.
1104             */
1105            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
1106            public static final String SMS_SEND_ACTION =
1107                "android.provider.Telephony.SMS_SEND";
1108
1109            /**
1110             * Read the PDUs out of an {@link #SMS_RECEIVED_ACTION} or a
1111             * {@link #DATA_SMS_RECEIVED_ACTION} intent.
1112             *
1113             * @param intent the intent to read from
1114             * @return an array of SmsMessages for the PDUs
1115             */
1116            public static SmsMessage[] getMessagesFromIntent(Intent intent) {
1117                Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
1118                String format = intent.getStringExtra("format");
1119                long subId = intent.getLongExtra(PhoneConstants.SUBSCRIPTION_KEY, 0);
1120
1121                Rlog.v(TAG, " getMessagesFromIntent sub_id : " + subId);
1122
1123                int pduCount = messages.length;
1124                SmsMessage[] msgs = new SmsMessage[pduCount];
1125
1126                for (int i = 0; i < pduCount; i++) {
1127                    byte[] pdu = (byte[]) messages[i];
1128                    msgs[i] = SmsMessage.createFromPdu(pdu, format);
1129                    msgs[i].setSubId(subId);
1130                }
1131                return msgs;
1132            }
1133        }
1134    }
1135
1136    /**
1137     * Base columns for tables that contain MMSs.
1138     */
1139    public interface BaseMmsColumns extends BaseColumns {
1140
1141        /** Message box: all messages. */
1142        public static final int MESSAGE_BOX_ALL    = 0;
1143        /** Message box: inbox. */
1144        public static final int MESSAGE_BOX_INBOX  = 1;
1145        /** Message box: sent messages. */
1146        public static final int MESSAGE_BOX_SENT   = 2;
1147        /** Message box: drafts. */
1148        public static final int MESSAGE_BOX_DRAFTS = 3;
1149        /** Message box: outbox. */
1150        public static final int MESSAGE_BOX_OUTBOX = 4;
1151        /** Message box: failed. */
1152        public static final int MESSAGE_BOX_FAILED = 5;
1153
1154        /**
1155         * The thread ID of the message.
1156         * <P>Type: INTEGER (long)</P>
1157         */
1158        public static final String THREAD_ID = "thread_id";
1159
1160        /**
1161         * The date the message was received.
1162         * <P>Type: INTEGER (long)</P>
1163         */
1164        public static final String DATE = "date";
1165
1166        /**
1167         * The date the message was sent.
1168         * <P>Type: INTEGER (long)</P>
1169         */
1170        public static final String DATE_SENT = "date_sent";
1171
1172        /**
1173         * The box which the message belongs to, e.g. {@link #MESSAGE_BOX_INBOX}.
1174         * <P>Type: INTEGER</P>
1175         */
1176        public static final String MESSAGE_BOX = "msg_box";
1177
1178        /**
1179         * Has the message been read?
1180         * <P>Type: INTEGER (boolean)</P>
1181         */
1182        public static final String READ = "read";
1183
1184        /**
1185         * Has the message been seen by the user? The "seen" flag determines
1186         * whether we need to show a new message notification.
1187         * <P>Type: INTEGER (boolean)</P>
1188         */
1189        public static final String SEEN = "seen";
1190
1191        /**
1192         * Does the message have only a text part (can also have a subject) with
1193         * no picture, slideshow, sound, etc. parts?
1194         * <P>Type: INTEGER (boolean)</P>
1195         */
1196        public static final String TEXT_ONLY = "text_only";
1197
1198        /**
1199         * The {@code Message-ID} of the message.
1200         * <P>Type: TEXT</P>
1201         */
1202        public static final String MESSAGE_ID = "m_id";
1203
1204        /**
1205         * The subject of the message, if present.
1206         * <P>Type: TEXT</P>
1207         */
1208        public static final String SUBJECT = "sub";
1209
1210        /**
1211         * The character set of the subject, if present.
1212         * <P>Type: INTEGER</P>
1213         */
1214        public static final String SUBJECT_CHARSET = "sub_cs";
1215
1216        /**
1217         * The {@code Content-Type} of the message.
1218         * <P>Type: TEXT</P>
1219         */
1220        public static final String CONTENT_TYPE = "ct_t";
1221
1222        /**
1223         * The {@code Content-Location} of the message.
1224         * <P>Type: TEXT</P>
1225         */
1226        public static final String CONTENT_LOCATION = "ct_l";
1227
1228        /**
1229         * The expiry time of the message.
1230         * <P>Type: INTEGER (long)</P>
1231         */
1232        public static final String EXPIRY = "exp";
1233
1234        /**
1235         * The class of the message.
1236         * <P>Type: TEXT</P>
1237         */
1238        public static final String MESSAGE_CLASS = "m_cls";
1239
1240        /**
1241         * The type of the message defined by MMS spec.
1242         * <P>Type: INTEGER</P>
1243         */
1244        public static final String MESSAGE_TYPE = "m_type";
1245
1246        /**
1247         * The version of the specification that this message conforms to.
1248         * <P>Type: INTEGER</P>
1249         */
1250        public static final String MMS_VERSION = "v";
1251
1252        /**
1253         * The size of the message.
1254         * <P>Type: INTEGER</P>
1255         */
1256        public static final String MESSAGE_SIZE = "m_size";
1257
1258        /**
1259         * The priority of the message.
1260         * <P>Type: INTEGER</P>
1261         */
1262        public static final String PRIORITY = "pri";
1263
1264        /**
1265         * The {@code read-report} of the message.
1266         * <P>Type: INTEGER (boolean)</P>
1267         */
1268        public static final String READ_REPORT = "rr";
1269
1270        /**
1271         * Is read report allowed?
1272         * <P>Type: INTEGER (boolean)</P>
1273         */
1274        public static final String REPORT_ALLOWED = "rpt_a";
1275
1276        /**
1277         * The {@code response-status} of the message.
1278         * <P>Type: INTEGER</P>
1279         */
1280        public static final String RESPONSE_STATUS = "resp_st";
1281
1282        /**
1283         * The {@code status} of the message.
1284         * <P>Type: INTEGER</P>
1285         */
1286        public static final String STATUS = "st";
1287
1288        /**
1289         * The {@code transaction-id} of the message.
1290         * <P>Type: TEXT</P>
1291         */
1292        public static final String TRANSACTION_ID = "tr_id";
1293
1294        /**
1295         * The {@code retrieve-status} of the message.
1296         * <P>Type: INTEGER</P>
1297         */
1298        public static final String RETRIEVE_STATUS = "retr_st";
1299
1300        /**
1301         * The {@code retrieve-text} of the message.
1302         * <P>Type: TEXT</P>
1303         */
1304        public static final String RETRIEVE_TEXT = "retr_txt";
1305
1306        /**
1307         * The character set of the retrieve-text.
1308         * <P>Type: INTEGER</P>
1309         */
1310        public static final String RETRIEVE_TEXT_CHARSET = "retr_txt_cs";
1311
1312        /**
1313         * The {@code read-status} of the message.
1314         * <P>Type: INTEGER</P>
1315         */
1316        public static final String READ_STATUS = "read_status";
1317
1318        /**
1319         * The {@code content-class} of the message.
1320         * <P>Type: INTEGER</P>
1321         */
1322        public static final String CONTENT_CLASS = "ct_cls";
1323
1324        /**
1325         * The {@code delivery-report} of the message.
1326         * <P>Type: INTEGER</P>
1327         */
1328        public static final String DELIVERY_REPORT = "d_rpt";
1329
1330        /**
1331         * The {@code delivery-time-token} of the message.
1332         * <P>Type: INTEGER</P>
1333         * @deprecated this column is no longer supported.
1334         * @hide
1335         */
1336        @Deprecated
1337        public static final String DELIVERY_TIME_TOKEN = "d_tm_tok";
1338
1339        /**
1340         * The {@code delivery-time} of the message.
1341         * <P>Type: INTEGER</P>
1342         */
1343        public static final String DELIVERY_TIME = "d_tm";
1344
1345        /**
1346         * The {@code response-text} of the message.
1347         * <P>Type: TEXT</P>
1348         */
1349        public static final String RESPONSE_TEXT = "resp_txt";
1350
1351        /**
1352         * The {@code sender-visibility} of the message.
1353         * <P>Type: TEXT</P>
1354         * @deprecated this column is no longer supported.
1355         * @hide
1356         */
1357        @Deprecated
1358        public static final String SENDER_VISIBILITY = "s_vis";
1359
1360        /**
1361         * The {@code reply-charging} of the message.
1362         * <P>Type: INTEGER</P>
1363         * @deprecated this column is no longer supported.
1364         * @hide
1365         */
1366        @Deprecated
1367        public static final String REPLY_CHARGING = "r_chg";
1368
1369        /**
1370         * The {@code reply-charging-deadline-token} of the message.
1371         * <P>Type: INTEGER</P>
1372         * @deprecated this column is no longer supported.
1373         * @hide
1374         */
1375        @Deprecated
1376        public static final String REPLY_CHARGING_DEADLINE_TOKEN = "r_chg_dl_tok";
1377
1378        /**
1379         * The {@code reply-charging-deadline} of the message.
1380         * <P>Type: INTEGER</P>
1381         * @deprecated this column is no longer supported.
1382         * @hide
1383         */
1384        @Deprecated
1385        public static final String REPLY_CHARGING_DEADLINE = "r_chg_dl";
1386
1387        /**
1388         * The {@code reply-charging-id} of the message.
1389         * <P>Type: TEXT</P>
1390         * @deprecated this column is no longer supported.
1391         * @hide
1392         */
1393        @Deprecated
1394        public static final String REPLY_CHARGING_ID = "r_chg_id";
1395
1396        /**
1397         * The {@code reply-charging-size} of the message.
1398         * <P>Type: INTEGER</P>
1399         * @deprecated this column is no longer supported.
1400         * @hide
1401         */
1402        @Deprecated
1403        public static final String REPLY_CHARGING_SIZE = "r_chg_sz";
1404
1405        /**
1406         * The {@code previously-sent-by} of the message.
1407         * <P>Type: TEXT</P>
1408         * @deprecated this column is no longer supported.
1409         * @hide
1410         */
1411        @Deprecated
1412        public static final String PREVIOUSLY_SENT_BY = "p_s_by";
1413
1414        /**
1415         * The {@code previously-sent-date} of the message.
1416         * <P>Type: INTEGER</P>
1417         * @deprecated this column is no longer supported.
1418         * @hide
1419         */
1420        @Deprecated
1421        public static final String PREVIOUSLY_SENT_DATE = "p_s_d";
1422
1423        /**
1424         * The {@code store} of the message.
1425         * <P>Type: TEXT</P>
1426         * @deprecated this column is no longer supported.
1427         * @hide
1428         */
1429        @Deprecated
1430        public static final String STORE = "store";
1431
1432        /**
1433         * The {@code mm-state} of the message.
1434         * <P>Type: INTEGER</P>
1435         * @deprecated this column is no longer supported.
1436         * @hide
1437         */
1438        @Deprecated
1439        public static final String MM_STATE = "mm_st";
1440
1441        /**
1442         * The {@code mm-flags-token} of the message.
1443         * <P>Type: INTEGER</P>
1444         * @deprecated this column is no longer supported.
1445         * @hide
1446         */
1447        @Deprecated
1448        public static final String MM_FLAGS_TOKEN = "mm_flg_tok";
1449
1450        /**
1451         * The {@code mm-flags} of the message.
1452         * <P>Type: TEXT</P>
1453         * @deprecated this column is no longer supported.
1454         * @hide
1455         */
1456        @Deprecated
1457        public static final String MM_FLAGS = "mm_flg";
1458
1459        /**
1460         * The {@code store-status} of the message.
1461         * <P>Type: TEXT</P>
1462         * @deprecated this column is no longer supported.
1463         * @hide
1464         */
1465        @Deprecated
1466        public static final String STORE_STATUS = "store_st";
1467
1468        /**
1469         * The {@code store-status-text} of the message.
1470         * <P>Type: TEXT</P>
1471         * @deprecated this column is no longer supported.
1472         * @hide
1473         */
1474        @Deprecated
1475        public static final String STORE_STATUS_TEXT = "store_st_txt";
1476
1477        /**
1478         * The {@code stored} of the message.
1479         * <P>Type: TEXT</P>
1480         * @deprecated this column is no longer supported.
1481         * @hide
1482         */
1483        @Deprecated
1484        public static final String STORED = "stored";
1485
1486        /**
1487         * The {@code totals} of the message.
1488         * <P>Type: TEXT</P>
1489         * @deprecated this column is no longer supported.
1490         * @hide
1491         */
1492        @Deprecated
1493        public static final String TOTALS = "totals";
1494
1495        /**
1496         * The {@code mbox-totals} of the message.
1497         * <P>Type: TEXT</P>
1498         * @deprecated this column is no longer supported.
1499         * @hide
1500         */
1501        @Deprecated
1502        public static final String MBOX_TOTALS = "mb_t";
1503
1504        /**
1505         * The {@code mbox-totals-token} of the message.
1506         * <P>Type: INTEGER</P>
1507         * @deprecated this column is no longer supported.
1508         * @hide
1509         */
1510        @Deprecated
1511        public static final String MBOX_TOTALS_TOKEN = "mb_t_tok";
1512
1513        /**
1514         * The {@code quotas} of the message.
1515         * <P>Type: TEXT</P>
1516         * @deprecated this column is no longer supported.
1517         * @hide
1518         */
1519        @Deprecated
1520        public static final String QUOTAS = "qt";
1521
1522        /**
1523         * The {@code mbox-quotas} of the message.
1524         * <P>Type: TEXT</P>
1525         * @deprecated this column is no longer supported.
1526         * @hide
1527         */
1528        @Deprecated
1529        public static final String MBOX_QUOTAS = "mb_qt";
1530
1531        /**
1532         * The {@code mbox-quotas-token} of the message.
1533         * <P>Type: INTEGER</P>
1534         * @deprecated this column is no longer supported.
1535         * @hide
1536         */
1537        @Deprecated
1538        public static final String MBOX_QUOTAS_TOKEN = "mb_qt_tok";
1539
1540        /**
1541         * The {@code message-count} of the message.
1542         * <P>Type: INTEGER</P>
1543         * @deprecated this column is no longer supported.
1544         * @hide
1545         */
1546        @Deprecated
1547        public static final String MESSAGE_COUNT = "m_cnt";
1548
1549        /**
1550         * The {@code start} of the message.
1551         * <P>Type: INTEGER</P>
1552         * @deprecated this column is no longer supported.
1553         * @hide
1554         */
1555        @Deprecated
1556        public static final String START = "start";
1557
1558        /**
1559         * The {@code distribution-indicator} of the message.
1560         * <P>Type: TEXT</P>
1561         * @deprecated this column is no longer supported.
1562         * @hide
1563         */
1564        @Deprecated
1565        public static final String DISTRIBUTION_INDICATOR = "d_ind";
1566
1567        /**
1568         * The {@code element-descriptor} of the message.
1569         * <P>Type: TEXT</P>
1570         * @deprecated this column is no longer supported.
1571         * @hide
1572         */
1573        @Deprecated
1574        public static final String ELEMENT_DESCRIPTOR = "e_des";
1575
1576        /**
1577         * The {@code limit} of the message.
1578         * <P>Type: INTEGER</P>
1579         * @deprecated this column is no longer supported.
1580         * @hide
1581         */
1582        @Deprecated
1583        public static final String LIMIT = "limit";
1584
1585        /**
1586         * The {@code recommended-retrieval-mode} of the message.
1587         * <P>Type: INTEGER</P>
1588         * @deprecated this column is no longer supported.
1589         * @hide
1590         */
1591        @Deprecated
1592        public static final String RECOMMENDED_RETRIEVAL_MODE = "r_r_mod";
1593
1594        /**
1595         * The {@code recommended-retrieval-mode-text} of the message.
1596         * <P>Type: TEXT</P>
1597         * @deprecated this column is no longer supported.
1598         * @hide
1599         */
1600        @Deprecated
1601        public static final String RECOMMENDED_RETRIEVAL_MODE_TEXT = "r_r_mod_txt";
1602
1603        /**
1604         * The {@code status-text} of the message.
1605         * <P>Type: TEXT</P>
1606         * @deprecated this column is no longer supported.
1607         * @hide
1608         */
1609        @Deprecated
1610        public static final String STATUS_TEXT = "st_txt";
1611
1612        /**
1613         * The {@code applic-id} of the message.
1614         * <P>Type: TEXT</P>
1615         * @deprecated this column is no longer supported.
1616         * @hide
1617         */
1618        @Deprecated
1619        public static final String APPLIC_ID = "apl_id";
1620
1621        /**
1622         * The {@code reply-applic-id} of the message.
1623         * <P>Type: TEXT</P>
1624         * @deprecated this column is no longer supported.
1625         * @hide
1626         */
1627        @Deprecated
1628        public static final String REPLY_APPLIC_ID = "r_apl_id";
1629
1630        /**
1631         * The {@code aux-applic-id} of the message.
1632         * <P>Type: TEXT</P>
1633         * @deprecated this column is no longer supported.
1634         * @hide
1635         */
1636        @Deprecated
1637        public static final String AUX_APPLIC_ID = "aux_apl_id";
1638
1639        /**
1640         * The {@code drm-content} of the message.
1641         * <P>Type: TEXT</P>
1642         * @deprecated this column is no longer supported.
1643         * @hide
1644         */
1645        @Deprecated
1646        public static final String DRM_CONTENT = "drm_c";
1647
1648        /**
1649         * The {@code adaptation-allowed} of the message.
1650         * <P>Type: TEXT</P>
1651         * @deprecated this column is no longer supported.
1652         * @hide
1653         */
1654        @Deprecated
1655        public static final String ADAPTATION_ALLOWED = "adp_a";
1656
1657        /**
1658         * The {@code replace-id} of the message.
1659         * <P>Type: TEXT</P>
1660         * @deprecated this column is no longer supported.
1661         * @hide
1662         */
1663        @Deprecated
1664        public static final String REPLACE_ID = "repl_id";
1665
1666        /**
1667         * The {@code cancel-id} of the message.
1668         * <P>Type: TEXT</P>
1669         * @deprecated this column is no longer supported.
1670         * @hide
1671         */
1672        @Deprecated
1673        public static final String CANCEL_ID = "cl_id";
1674
1675        /**
1676         * The {@code cancel-status} of the message.
1677         * <P>Type: INTEGER</P>
1678         * @deprecated this column is no longer supported.
1679         * @hide
1680         */
1681        @Deprecated
1682        public static final String CANCEL_STATUS = "cl_st";
1683
1684        /**
1685         * Is the message locked?
1686         * <P>Type: INTEGER (boolean)</P>
1687         */
1688        public static final String LOCKED = "locked";
1689
1690        /**
1691         * The sub id to which message belongs to
1692         * <p>Type: INTEGER</p>
1693         * @hide
1694         */
1695        public static final String SUB_ID = "sub_id";
1696
1697        /**
1698         * The identity of the sender of a sent message. It is
1699         * usually the package name of the app which sends the message.
1700         * <p>Type: TEXT</p>
1701         */
1702        public static final String CREATOR = "creator";
1703    }
1704
1705    /**
1706     * Columns for the "canonical_addresses" table used by MMS and SMS.
1707     */
1708    public interface CanonicalAddressesColumns extends BaseColumns {
1709        /**
1710         * An address used in MMS or SMS.  Email addresses are
1711         * converted to lower case and are compared by string
1712         * equality.  Other addresses are compared using
1713         * PHONE_NUMBERS_EQUAL.
1714         * <P>Type: TEXT</P>
1715         */
1716        public static final String ADDRESS = "address";
1717    }
1718
1719    /**
1720     * Columns for the "threads" table used by MMS and SMS.
1721     */
1722    public interface ThreadsColumns extends BaseColumns {
1723
1724        /**
1725         * The date at which the thread was created.
1726         * <P>Type: INTEGER (long)</P>
1727         */
1728        public static final String DATE = "date";
1729
1730        /**
1731         * A string encoding of the recipient IDs of the recipients of
1732         * the message, in numerical order and separated by spaces.
1733         * <P>Type: TEXT</P>
1734         */
1735        public static final String RECIPIENT_IDS = "recipient_ids";
1736
1737        /**
1738         * The message count of the thread.
1739         * <P>Type: INTEGER</P>
1740         */
1741        public static final String MESSAGE_COUNT = "message_count";
1742
1743        /**
1744         * Indicates whether all messages of the thread have been read.
1745         * <P>Type: INTEGER</P>
1746         */
1747        public static final String READ = "read";
1748
1749        /**
1750         * The snippet of the latest message in the thread.
1751         * <P>Type: TEXT</P>
1752         */
1753        public static final String SNIPPET = "snippet";
1754
1755        /**
1756         * The charset of the snippet.
1757         * <P>Type: INTEGER</P>
1758         */
1759        public static final String SNIPPET_CHARSET = "snippet_cs";
1760
1761        /**
1762         * Type of the thread, either {@link Threads#COMMON_THREAD} or
1763         * {@link Threads#BROADCAST_THREAD}.
1764         * <P>Type: INTEGER</P>
1765         */
1766        public static final String TYPE = "type";
1767
1768        /**
1769         * Indicates whether there is a transmission error in the thread.
1770         * <P>Type: INTEGER</P>
1771         */
1772        public static final String ERROR = "error";
1773
1774        /**
1775         * Indicates whether this thread contains any attachments.
1776         * <P>Type: INTEGER</P>
1777         */
1778        public static final String HAS_ATTACHMENT = "has_attachment";
1779
1780        /**
1781         * If the thread is archived
1782         * <P>Type: INTEGER (boolean)</P>
1783         */
1784        public static final String ARCHIVED = "archived";
1785    }
1786
1787    /**
1788     * Helper functions for the "threads" table used by MMS and SMS.
1789     */
1790    public static final class Threads implements ThreadsColumns {
1791
1792        private static final String[] ID_PROJECTION = { BaseColumns._ID };
1793
1794        /**
1795         * Private {@code content://} style URL for this table. Used by
1796         * {@link #getOrCreateThreadId(android.content.Context, java.util.Set)}.
1797         */
1798        private static final Uri THREAD_ID_CONTENT_URI = Uri.parse(
1799                "content://mms-sms/threadID");
1800
1801        /**
1802         * The {@code content://} style URL for this table, by conversation.
1803         */
1804        public static final Uri CONTENT_URI = Uri.withAppendedPath(
1805                MmsSms.CONTENT_URI, "conversations");
1806
1807        /**
1808         * The {@code content://} style URL for this table, for obsolete threads.
1809         */
1810        public static final Uri OBSOLETE_THREADS_URI = Uri.withAppendedPath(
1811                CONTENT_URI, "obsolete");
1812
1813        /** Thread type: common thread. */
1814        public static final int COMMON_THREAD    = 0;
1815
1816        /** Thread type: broadcast thread. */
1817        public static final int BROADCAST_THREAD = 1;
1818
1819        /**
1820         * Not instantiable.
1821         * @hide
1822         */
1823        private Threads() {
1824        }
1825
1826        /**
1827         * This is a single-recipient version of {@code getOrCreateThreadId}.
1828         * It's convenient for use with SMS messages.
1829         * @param context the context object to use.
1830         * @param recipient the recipient to send to.
1831         * @hide
1832         */
1833        public static long getOrCreateThreadId(Context context, String recipient) {
1834            Set<String> recipients = new HashSet<String>();
1835
1836            recipients.add(recipient);
1837            return getOrCreateThreadId(context, recipients);
1838        }
1839
1840        /**
1841         * Given the recipients list and subject of an unsaved message,
1842         * return its thread ID.  If the message starts a new thread,
1843         * allocate a new thread ID.  Otherwise, use the appropriate
1844         * existing thread ID.
1845         *
1846         * <p>Find the thread ID of the same set of recipients (in any order,
1847         * without any additions). If one is found, return it. Otherwise,
1848         * return a unique thread ID.</p>
1849         * @hide
1850         */
1851        public static long getOrCreateThreadId(
1852                Context context, Set<String> recipients) {
1853            Uri.Builder uriBuilder = THREAD_ID_CONTENT_URI.buildUpon();
1854
1855            for (String recipient : recipients) {
1856                if (Mms.isEmailAddress(recipient)) {
1857                    recipient = Mms.extractAddrSpec(recipient);
1858                }
1859
1860                uriBuilder.appendQueryParameter("recipient", recipient);
1861            }
1862
1863            Uri uri = uriBuilder.build();
1864            //if (DEBUG) Rlog.v(TAG, "getOrCreateThreadId uri: " + uri);
1865
1866            Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(),
1867                    uri, ID_PROJECTION, null, null, null);
1868            if (cursor != null) {
1869                try {
1870                    if (cursor.moveToFirst()) {
1871                        return cursor.getLong(0);
1872                    } else {
1873                        Rlog.e(TAG, "getOrCreateThreadId returned no rows!");
1874                    }
1875                } finally {
1876                    cursor.close();
1877                }
1878            }
1879
1880            Rlog.e(TAG, "getOrCreateThreadId failed with uri " + uri.toString());
1881            throw new IllegalArgumentException("Unable to find or allocate a thread ID.");
1882        }
1883    }
1884
1885    /**
1886     * Contains all MMS messages.
1887     */
1888    public static final class Mms implements BaseMmsColumns {
1889
1890        /**
1891         * Not instantiable.
1892         * @hide
1893         */
1894        private Mms() {
1895        }
1896
1897        /**
1898         * The {@code content://} URI for this table.
1899         */
1900        public static final Uri CONTENT_URI = Uri.parse("content://mms");
1901
1902        /**
1903         * Content URI for getting MMS report requests.
1904         */
1905        public static final Uri REPORT_REQUEST_URI = Uri.withAppendedPath(
1906                                            CONTENT_URI, "report-request");
1907
1908        /**
1909         * Content URI for getting MMS report status.
1910         */
1911        public static final Uri REPORT_STATUS_URI = Uri.withAppendedPath(
1912                                            CONTENT_URI, "report-status");
1913
1914        /**
1915         * The default sort order for this table.
1916         */
1917        public static final String DEFAULT_SORT_ORDER = "date DESC";
1918
1919        /**
1920         * Regex pattern for names and email addresses.
1921         * <ul>
1922         *     <li><em>mailbox</em> = {@code name-addr}</li>
1923         *     <li><em>name-addr</em> = {@code [display-name] angle-addr}</li>
1924         *     <li><em>angle-addr</em> = {@code [CFWS] "<" addr-spec ">" [CFWS]}</li>
1925         * </ul>
1926         * @hide
1927         */
1928        public static final Pattern NAME_ADDR_EMAIL_PATTERN =
1929                Pattern.compile("\\s*(\"[^\"]*\"|[^<>\"]+)\\s*<([^<>]+)>\\s*");
1930
1931        /**
1932         * Helper method to query this table.
1933         * @hide
1934         */
1935        public static Cursor query(
1936                ContentResolver cr, String[] projection) {
1937            return cr.query(CONTENT_URI, projection, null, null, DEFAULT_SORT_ORDER);
1938        }
1939
1940        /**
1941         * Helper method to query this table.
1942         * @hide
1943         */
1944        public static Cursor query(
1945                ContentResolver cr, String[] projection,
1946                String where, String orderBy) {
1947            return cr.query(CONTENT_URI, projection,
1948                    where, null, orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
1949        }
1950
1951        /**
1952         * Helper method to extract email address from address string.
1953         * @hide
1954         */
1955        public static String extractAddrSpec(String address) {
1956            Matcher match = NAME_ADDR_EMAIL_PATTERN.matcher(address);
1957
1958            if (match.matches()) {
1959                return match.group(2);
1960            }
1961            return address;
1962        }
1963
1964        /**
1965         * Is the specified address an email address?
1966         *
1967         * @param address the input address to test
1968         * @return true if address is an email address; false otherwise.
1969         * @hide
1970         */
1971        public static boolean isEmailAddress(String address) {
1972            if (TextUtils.isEmpty(address)) {
1973                return false;
1974            }
1975
1976            String s = extractAddrSpec(address);
1977            Matcher match = Patterns.EMAIL_ADDRESS.matcher(s);
1978            return match.matches();
1979        }
1980
1981        /**
1982         * Is the specified number a phone number?
1983         *
1984         * @param number the input number to test
1985         * @return true if number is a phone number; false otherwise.
1986         * @hide
1987         */
1988        public static boolean isPhoneNumber(String number) {
1989            if (TextUtils.isEmpty(number)) {
1990                return false;
1991            }
1992
1993            Matcher match = Patterns.PHONE.matcher(number);
1994            return match.matches();
1995        }
1996
1997        /**
1998         * Contains all MMS messages in the MMS app inbox.
1999         */
2000        public static final class Inbox implements BaseMmsColumns {
2001
2002            /**
2003             * Not instantiable.
2004             * @hide
2005             */
2006            private Inbox() {
2007            }
2008
2009            /**
2010             * The {@code content://} style URL for this table.
2011             */
2012            public static final Uri
2013                    CONTENT_URI = Uri.parse("content://mms/inbox");
2014
2015            /**
2016             * The default sort order for this table.
2017             */
2018            public static final String DEFAULT_SORT_ORDER = "date DESC";
2019        }
2020
2021        /**
2022         * Contains all MMS messages in the MMS app sent folder.
2023         */
2024        public static final class Sent implements BaseMmsColumns {
2025
2026            /**
2027             * Not instantiable.
2028             * @hide
2029             */
2030            private Sent() {
2031            }
2032
2033            /**
2034             * The {@code content://} style URL for this table.
2035             */
2036            public static final Uri
2037                    CONTENT_URI = Uri.parse("content://mms/sent");
2038
2039            /**
2040             * The default sort order for this table.
2041             */
2042            public static final String DEFAULT_SORT_ORDER = "date DESC";
2043        }
2044
2045        /**
2046         * Contains all MMS messages in the MMS app drafts folder.
2047         */
2048        public static final class Draft implements BaseMmsColumns {
2049
2050            /**
2051             * Not instantiable.
2052             * @hide
2053             */
2054            private Draft() {
2055            }
2056
2057            /**
2058             * The {@code content://} style URL for this table.
2059             */
2060            public static final Uri
2061                    CONTENT_URI = Uri.parse("content://mms/drafts");
2062
2063            /**
2064             * The default sort order for this table.
2065             */
2066            public static final String DEFAULT_SORT_ORDER = "date DESC";
2067        }
2068
2069        /**
2070         * Contains all MMS messages in the MMS app outbox.
2071         */
2072        public static final class Outbox implements BaseMmsColumns {
2073
2074            /**
2075             * Not instantiable.
2076             * @hide
2077             */
2078            private Outbox() {
2079            }
2080
2081            /**
2082             * The {@code content://} style URL for this table.
2083             */
2084            public static final Uri
2085                    CONTENT_URI = Uri.parse("content://mms/outbox");
2086
2087            /**
2088             * The default sort order for this table.
2089             */
2090            public static final String DEFAULT_SORT_ORDER = "date DESC";
2091        }
2092
2093        /**
2094         * Contains address information for an MMS message.
2095         */
2096        public static final class Addr implements BaseColumns {
2097
2098            /**
2099             * Not instantiable.
2100             * @hide
2101             */
2102            private Addr() {
2103            }
2104
2105            /**
2106             * The ID of MM which this address entry belongs to.
2107             * <P>Type: INTEGER (long)</P>
2108             */
2109            public static final String MSG_ID = "msg_id";
2110
2111            /**
2112             * The ID of contact entry in Phone Book.
2113             * <P>Type: INTEGER (long)</P>
2114             */
2115            public static final String CONTACT_ID = "contact_id";
2116
2117            /**
2118             * The address text.
2119             * <P>Type: TEXT</P>
2120             */
2121            public static final String ADDRESS = "address";
2122
2123            /**
2124             * Type of address: must be one of {@code PduHeaders.BCC},
2125             * {@code PduHeaders.CC}, {@code PduHeaders.FROM}, {@code PduHeaders.TO}.
2126             * <P>Type: INTEGER</P>
2127             */
2128            public static final String TYPE = "type";
2129
2130            /**
2131             * Character set of this entry (MMS charset value).
2132             * <P>Type: INTEGER</P>
2133             */
2134            public static final String CHARSET = "charset";
2135        }
2136
2137        /**
2138         * Contains message parts.
2139         */
2140        public static final class Part implements BaseColumns {
2141
2142            /**
2143             * Not instantiable.
2144             * @hide
2145             */
2146            private Part() {
2147            }
2148
2149            /**
2150             * The identifier of the message which this part belongs to.
2151             * <P>Type: INTEGER</P>
2152             */
2153            public static final String MSG_ID = "mid";
2154
2155            /**
2156             * The order of the part.
2157             * <P>Type: INTEGER</P>
2158             */
2159            public static final String SEQ = "seq";
2160
2161            /**
2162             * The content type of the part.
2163             * <P>Type: TEXT</P>
2164             */
2165            public static final String CONTENT_TYPE = "ct";
2166
2167            /**
2168             * The name of the part.
2169             * <P>Type: TEXT</P>
2170             */
2171            public static final String NAME = "name";
2172
2173            /**
2174             * The charset of the part.
2175             * <P>Type: TEXT</P>
2176             */
2177            public static final String CHARSET = "chset";
2178
2179            /**
2180             * The file name of the part.
2181             * <P>Type: TEXT</P>
2182             */
2183            public static final String FILENAME = "fn";
2184
2185            /**
2186             * The content disposition of the part.
2187             * <P>Type: TEXT</P>
2188             */
2189            public static final String CONTENT_DISPOSITION = "cd";
2190
2191            /**
2192             * The content ID of the part.
2193             * <P>Type: INTEGER</P>
2194             */
2195            public static final String CONTENT_ID = "cid";
2196
2197            /**
2198             * The content location of the part.
2199             * <P>Type: INTEGER</P>
2200             */
2201            public static final String CONTENT_LOCATION = "cl";
2202
2203            /**
2204             * The start of content-type of the message.
2205             * <P>Type: INTEGER</P>
2206             */
2207            public static final String CT_START = "ctt_s";
2208
2209            /**
2210             * The type of content-type of the message.
2211             * <P>Type: TEXT</P>
2212             */
2213            public static final String CT_TYPE = "ctt_t";
2214
2215            /**
2216             * The location (on filesystem) of the binary data of the part.
2217             * <P>Type: INTEGER</P>
2218             */
2219            public static final String _DATA = "_data";
2220
2221            /**
2222             * The message text.
2223             * <P>Type: TEXT</P>
2224             */
2225            public static final String TEXT = "text";
2226        }
2227
2228        /**
2229         * Message send rate table.
2230         */
2231        public static final class Rate {
2232
2233            /**
2234             * Not instantiable.
2235             * @hide
2236             */
2237            private Rate() {
2238            }
2239
2240            /**
2241             * The {@code content://} style URL for this table.
2242             */
2243            public static final Uri CONTENT_URI = Uri.withAppendedPath(
2244                    Mms.CONTENT_URI, "rate");
2245
2246            /**
2247             * When a message was successfully sent.
2248             * <P>Type: INTEGER (long)</P>
2249             */
2250            public static final String SENT_TIME = "sent_time";
2251        }
2252
2253        /**
2254         * Intents class.
2255         */
2256        public static final class Intents {
2257
2258            /**
2259             * Not instantiable.
2260             * @hide
2261             */
2262            private Intents() {
2263            }
2264
2265            /**
2266             * Indicates that the contents of specified URIs were changed.
2267             * The application which is showing or caching these contents
2268             * should be updated.
2269             */
2270            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2271            public static final String CONTENT_CHANGED_ACTION
2272                    = "android.intent.action.CONTENT_CHANGED";
2273
2274            /**
2275             * Broadcast Action: A new MMS PDU needs to be sent from
2276             * the device. This intent will only be delivered to a
2277             * carrier app. That app is responsible for sending the PDU.
2278             * The intent will have the following extra values:</p>
2279             *
2280             * <ul>
2281             *   <li><em>"pdu"</em> - (byte[]) The PDU to send.</li>
2282             *   <li><em>"url"</em> - (String) The optional url to send this MMS PDU.
2283             *   If this is not specified, PDU should be sent to the default MMSC url.</li>
2284             * </ul>
2285             *
2286             * <p>If a BroadcastReceiver is trying to send the message,
2287             *  it should set the result code to {@link android.app.Activity#RESULT_OK} and set
2288             *  the following in the result extra values:</p>
2289             *
2290             * <ul>
2291             *   <li><em>"messageref"</em> - (int) The new message reference number which will be
2292             *   later used in the updateMmsSendStatus call.</li>
2293             * </ul>
2294             *
2295             * <p>If a BroadcastReceiver cannot send the message, it should not set the result
2296             *  code and the platform will send it via the normal pathway.
2297             * </p>
2298             *
2299             * <p class="note"><strong>Note:</strong>
2300             * The broadcast receiver that filters for this intent must be a carrier privileged app.
2301             * It must also declare {@link android.Manifest.permission#BROADCAST_WAP_PUSH} as a required
2302             * permission in the <a href="{@docRoot}guide/topics/manifest/receiver-element.html">
2303             * {@code &lt;receiver>}</a> tag.
2304             */
2305            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2306            public static final String MMS_SEND_ACTION =
2307                    "android.provider.Telephony.MMS_SEND";
2308
2309            /**
2310             * Broadcast Action: A new MMS needs to be downloaded.
2311             * This intent will only be delivered to a
2312             * carrier app. That app is responsible for downloading the message at the URL.
2313             * The intent will have the following extra values:</p>
2314             *
2315             * <ul>
2316             *   <li><em>"url"</em> - (String) The message URL to be downloaded.</li>
2317             * </ul>
2318             *
2319             * <p>If a BroadcastReceiver is trying to download the message,
2320             *  it should set the result code to {@link android.app.Activity#RESULT_OK} and set
2321             *  the following in the result extra values:</p>
2322             *
2323             * <ul>
2324             *   <li><em>"messageref"</em> - (int) The new message reference number which will be
2325             *   later used in the updateMmsDownloadStatus call.</li>
2326             * </ul>
2327             *
2328             * <p>If a BroadcastReceiver cannot download the message, it should not set the result
2329             *  code and the platform will download it via the normal pathway.
2330             * </p>
2331             *
2332             * <p class="note"><strong>Note:</strong>
2333             * The broadcast receiver that filters for this intent must be a carrier privileged app.
2334             * It must also declare {@link android.Manifest.permission#BROADCAST_WAP_PUSH} as a required
2335             * permission in the <a href="{@docRoot}guide/topics/manifest/receiver-element.html">
2336             * {@code &lt;receiver>}</a> tag.
2337             */
2338            @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
2339            public static final String MMS_DOWNLOAD_ACTION =
2340                    "android.provider.Telephony.MMS_DOWNLOAD";
2341
2342            /**
2343             * An extra field which stores the URI of deleted contents.
2344             */
2345            public static final String DELETED_CONTENTS = "deleted_contents";
2346        }
2347    }
2348
2349    /**
2350     * Contains all MMS and SMS messages.
2351     */
2352    public static final class MmsSms implements BaseColumns {
2353
2354        /**
2355         * Not instantiable.
2356         * @hide
2357         */
2358        private MmsSms() {
2359        }
2360
2361        /**
2362         * The column to distinguish SMS and MMS messages in query results.
2363         */
2364        public static final String TYPE_DISCRIMINATOR_COLUMN =
2365                "transport_type";
2366
2367        /**
2368         * The {@code content://} style URL for this table.
2369         */
2370        public static final Uri CONTENT_URI = Uri.parse("content://mms-sms/");
2371
2372        /**
2373         * The {@code content://} style URL for this table, by conversation.
2374         */
2375        public static final Uri CONTENT_CONVERSATIONS_URI = Uri.parse(
2376                "content://mms-sms/conversations");
2377
2378        /**
2379         * The {@code content://} style URL for this table, by phone number.
2380         */
2381        public static final Uri CONTENT_FILTER_BYPHONE_URI = Uri.parse(
2382                "content://mms-sms/messages/byphone");
2383
2384        /**
2385         * The {@code content://} style URL for undelivered messages in this table.
2386         */
2387        public static final Uri CONTENT_UNDELIVERED_URI = Uri.parse(
2388                "content://mms-sms/undelivered");
2389
2390        /**
2391         * The {@code content://} style URL for draft messages in this table.
2392         */
2393        public static final Uri CONTENT_DRAFT_URI = Uri.parse(
2394                "content://mms-sms/draft");
2395
2396        /**
2397         * The {@code content://} style URL for locked messages in this table.
2398         */
2399        public static final Uri CONTENT_LOCKED_URI = Uri.parse(
2400                "content://mms-sms/locked");
2401
2402        /**
2403         * Pass in a query parameter called "pattern" which is the text to search for.
2404         * The sort order is fixed to be: {@code thread_id ASC, date DESC}.
2405         */
2406        public static final Uri SEARCH_URI = Uri.parse(
2407                "content://mms-sms/search");
2408
2409        // Constants for message protocol types.
2410
2411        /** SMS protocol type. */
2412        public static final int SMS_PROTO = 0;
2413
2414        /** MMS protocol type. */
2415        public static final int MMS_PROTO = 1;
2416
2417        // Constants for error types of pending messages.
2418
2419        /** Error type: no error. */
2420        public static final int NO_ERROR                      = 0;
2421
2422        /** Error type: generic transient error. */
2423        public static final int ERR_TYPE_GENERIC              = 1;
2424
2425        /** Error type: SMS protocol transient error. */
2426        public static final int ERR_TYPE_SMS_PROTO_TRANSIENT  = 2;
2427
2428        /** Error type: MMS protocol transient error. */
2429        public static final int ERR_TYPE_MMS_PROTO_TRANSIENT  = 3;
2430
2431        /** Error type: transport failure. */
2432        public static final int ERR_TYPE_TRANSPORT_FAILURE    = 4;
2433
2434        /** Error type: permanent error (along with all higher error values). */
2435        public static final int ERR_TYPE_GENERIC_PERMANENT    = 10;
2436
2437        /** Error type: SMS protocol permanent error. */
2438        public static final int ERR_TYPE_SMS_PROTO_PERMANENT  = 11;
2439
2440        /** Error type: MMS protocol permanent error. */
2441        public static final int ERR_TYPE_MMS_PROTO_PERMANENT  = 12;
2442
2443        /**
2444         * Contains pending messages info.
2445         */
2446        public static final class PendingMessages implements BaseColumns {
2447
2448            /**
2449             * Not instantiable.
2450             * @hide
2451             */
2452            private PendingMessages() {
2453            }
2454
2455            public static final Uri CONTENT_URI = Uri.withAppendedPath(
2456                    MmsSms.CONTENT_URI, "pending");
2457
2458            /**
2459             * The type of transport protocol (MMS or SMS).
2460             * <P>Type: INTEGER</P>
2461             */
2462            public static final String PROTO_TYPE = "proto_type";
2463
2464            /**
2465             * The ID of the message to be sent or downloaded.
2466             * <P>Type: INTEGER (long)</P>
2467             */
2468            public static final String MSG_ID = "msg_id";
2469
2470            /**
2471             * The type of the message to be sent or downloaded.
2472             * This field is only valid for MM. For SM, its value is always set to 0.
2473             * <P>Type: INTEGER</P>
2474             */
2475            public static final String MSG_TYPE = "msg_type";
2476
2477            /**
2478             * The type of the error code.
2479             * <P>Type: INTEGER</P>
2480             */
2481            public static final String ERROR_TYPE = "err_type";
2482
2483            /**
2484             * The error code of sending/retrieving process.
2485             * <P>Type: INTEGER</P>
2486             */
2487            public static final String ERROR_CODE = "err_code";
2488
2489            /**
2490             * How many times we tried to send or download the message.
2491             * <P>Type: INTEGER</P>
2492             */
2493            public static final String RETRY_INDEX = "retry_index";
2494
2495            /**
2496             * The time to do next retry.
2497             * <P>Type: INTEGER (long)</P>
2498             */
2499            public static final String DUE_TIME = "due_time";
2500
2501            /**
2502             * The time we last tried to send or download the message.
2503             * <P>Type: INTEGER (long)</P>
2504             */
2505            public static final String LAST_TRY = "last_try";
2506
2507            /**
2508             * The sub_id to which the pending message belongs to
2509             * <p>Type: INTEGER (long) </p>
2510             * @hide
2511             */
2512            public static final String SUB_ID = "pending_sub_id";
2513        }
2514
2515        /**
2516         * Words table used by provider for full-text searches.
2517         * @hide
2518         */
2519        public static final class WordsTable {
2520
2521            /**
2522             * Not instantiable.
2523             * @hide
2524             */
2525            private WordsTable() {}
2526
2527            /**
2528             * Primary key.
2529             * <P>Type: INTEGER (long)</P>
2530             */
2531            public static final String ID = "_id";
2532
2533            /**
2534             * Source row ID.
2535             * <P>Type: INTEGER (long)</P>
2536             */
2537            public static final String SOURCE_ROW_ID = "source_id";
2538
2539            /**
2540             * Table ID (either 1 or 2).
2541             * <P>Type: INTEGER</P>
2542             */
2543            public static final String TABLE_ID = "table_to_use";
2544
2545            /**
2546             * The words to index.
2547             * <P>Type: TEXT</P>
2548             */
2549            public static final String INDEXED_TEXT = "index_text";
2550        }
2551    }
2552
2553    /**
2554     * Carriers class contains information about APNs, including MMSC information.
2555     */
2556    public static final class Carriers implements BaseColumns {
2557
2558        /**
2559         * Not instantiable.
2560         * @hide
2561         */
2562        private Carriers() {}
2563
2564        /**
2565         * The {@code content://} style URL for this table.
2566         */
2567        public static final Uri CONTENT_URI = Uri.parse("content://telephony/carriers");
2568
2569        /**
2570         * The default sort order for this table.
2571         */
2572        public static final String DEFAULT_SORT_ORDER = "name ASC";
2573
2574        /**
2575         * Entry name.
2576         * <P>Type: TEXT</P>
2577         */
2578        public static final String NAME = "name";
2579
2580        /**
2581         * APN name.
2582         * <P>Type: TEXT</P>
2583         */
2584        public static final String APN = "apn";
2585
2586        /**
2587         * Proxy address.
2588         * <P>Type: TEXT</P>
2589         */
2590        public static final String PROXY = "proxy";
2591
2592        /**
2593         * Proxy port.
2594         * <P>Type: TEXT</P>
2595         */
2596        public static final String PORT = "port";
2597
2598        /**
2599         * MMS proxy address.
2600         * <P>Type: TEXT</P>
2601         */
2602        public static final String MMSPROXY = "mmsproxy";
2603
2604        /**
2605         * MMS proxy port.
2606         * <P>Type: TEXT</P>
2607         */
2608        public static final String MMSPORT = "mmsport";
2609
2610        /**
2611         * Server address.
2612         * <P>Type: TEXT</P>
2613         */
2614        public static final String SERVER = "server";
2615
2616        /**
2617         * APN username.
2618         * <P>Type: TEXT</P>
2619         */
2620        public static final String USER = "user";
2621
2622        /**
2623         * APN password.
2624         * <P>Type: TEXT</P>
2625         */
2626        public static final String PASSWORD = "password";
2627
2628        /**
2629         * MMSC URL.
2630         * <P>Type: TEXT</P>
2631         */
2632        public static final String MMSC = "mmsc";
2633
2634        /**
2635         * Mobile Country Code (MCC).
2636         * <P>Type: TEXT</P>
2637         */
2638        public static final String MCC = "mcc";
2639
2640        /**
2641         * Mobile Network Code (MNC).
2642         * <P>Type: TEXT</P>
2643         */
2644        public static final String MNC = "mnc";
2645
2646        /**
2647         * Numeric operator ID (as String). Usually {@code MCC + MNC}.
2648         * <P>Type: TEXT</P>
2649         */
2650        public static final String NUMERIC = "numeric";
2651
2652        /**
2653         * Authentication type.
2654         * <P>Type:  INTEGER</P>
2655         */
2656        public static final String AUTH_TYPE = "authtype";
2657
2658        /**
2659         * Comma-delimited list of APN types.
2660         * <P>Type: TEXT</P>
2661         */
2662        public static final String TYPE = "type";
2663
2664        /**
2665         * The protocol to use to connect to this APN.
2666         *
2667         * One of the {@code PDP_type} values in TS 27.007 section 10.1.1.
2668         * For example: {@code IP}, {@code IPV6}, {@code IPV4V6}, or {@code PPP}.
2669         * <P>Type: TEXT</P>
2670         */
2671        public static final String PROTOCOL = "protocol";
2672
2673        /**
2674         * The protocol to use to connect to this APN when roaming.
2675         * The syntax is the same as protocol.
2676         * <P>Type: TEXT</P>
2677         */
2678        public static final String ROAMING_PROTOCOL = "roaming_protocol";
2679
2680        /**
2681         * Is this the current APN?
2682         * <P>Type: INTEGER (boolean)</P>
2683         */
2684        public static final String CURRENT = "current";
2685
2686        /**
2687         * Is this APN enabled?
2688         * <P>Type: INTEGER (boolean)</P>
2689         */
2690        public static final String CARRIER_ENABLED = "carrier_enabled";
2691
2692        /**
2693         * Radio Access Technology info.
2694         * To check what values are allowed, refer to {@link android.telephony.ServiceState}.
2695         * This should be spread to other technologies,
2696         * but is currently only used for LTE (14) and eHRPD (13).
2697         * <P>Type: INTEGER</P>
2698         */
2699        public static final String BEARER = "bearer";
2700
2701        /**
2702         * MVNO type:
2703         * {@code SPN (Service Provider Name), IMSI, GID (Group Identifier Level 1)}.
2704         * <P>Type: TEXT</P>
2705         */
2706        public static final String MVNO_TYPE = "mvno_type";
2707
2708        /**
2709         * MVNO data.
2710         * Use the following examples.
2711         * <ul>
2712         *     <li>SPN: A MOBILE, BEN NL, ...</li>
2713         *     <li>IMSI: 302720x94, 2060188, ...</li>
2714         *     <li>GID: 4E, 33, ...</li>
2715         * </ul>
2716         * <P>Type: TEXT</P>
2717         */
2718        public static final String MVNO_MATCH_DATA = "mvno_match_data";
2719
2720        /**
2721         * The sub_id to which the APN belongs to
2722         * <p>Type: INTEGER (long) </p>
2723         * @hide
2724         */
2725        public static final String SUB_ID = "sub_id";
2726
2727        /**
2728         * The profile_id to which the APN saved in modem
2729         * <p>Type: INTEGER</p>
2730         *@hide
2731         */
2732        public static final String PROFILE_ID = "profile_id";
2733
2734        /**
2735         * Is the apn setting to be set in modem
2736         * <P>Type: INTEGER (boolean)</P>
2737         *@hide
2738         */
2739        public static final String MODEM_COGNITIVE = "modem_cognitive";
2740
2741        /**
2742         * The max connections of this apn
2743         * <p>Type: INTEGER</p>
2744         *@hide
2745         */
2746        public static final String MAX_CONNS = "max_conns";
2747
2748        /**
2749         * The wait time for retry of the apn
2750         * <p>Type: INTEGER</p>
2751         *@hide
2752         */
2753        public static final String WAIT_TIME = "wait_time";
2754
2755        /**
2756         * The time to limit max connection for the apn
2757         * <p>Type: INTEGER</p>
2758         *@hide
2759         */
2760        public static final String MAX_CONNS_TIME = "max_conns_time";
2761
2762        /**
2763         * The MTU size of the mobile interface to  which the APN connected
2764         * <p>Type: INTEGER </p>
2765         * @hide
2766         */
2767        public static final String MTU = "mtu";
2768    }
2769
2770    /**
2771     * Contains received SMS cell broadcast messages.
2772     * @hide
2773     */
2774    public static final class CellBroadcasts implements BaseColumns {
2775
2776        /**
2777         * Not instantiable.
2778         * @hide
2779         */
2780        private CellBroadcasts() {}
2781
2782        /**
2783         * The {@code content://} URI for this table.
2784         */
2785        public static final Uri CONTENT_URI = Uri.parse("content://cellbroadcasts");
2786
2787        /**
2788         * Message geographical scope.
2789         * <P>Type: INTEGER</P>
2790         */
2791        public static final String GEOGRAPHICAL_SCOPE = "geo_scope";
2792
2793        /**
2794         * Message serial number.
2795         * <P>Type: INTEGER</P>
2796         */
2797        public static final String SERIAL_NUMBER = "serial_number";
2798
2799        /**
2800         * PLMN of broadcast sender. {@code SERIAL_NUMBER + PLMN + LAC + CID} uniquely identifies
2801         * a broadcast for duplicate detection purposes.
2802         * <P>Type: TEXT</P>
2803         */
2804        public static final String PLMN = "plmn";
2805
2806        /**
2807         * Location Area (GSM) or Service Area (UMTS) of broadcast sender. Unused for CDMA.
2808         * Only included if Geographical Scope of message is not PLMN wide (01).
2809         * <P>Type: INTEGER</P>
2810         */
2811        public static final String LAC = "lac";
2812
2813        /**
2814         * Cell ID of message sender (GSM/UMTS). Unused for CDMA. Only included when the
2815         * Geographical Scope of message is cell wide (00 or 11).
2816         * <P>Type: INTEGER</P>
2817         */
2818        public static final String CID = "cid";
2819
2820        /**
2821         * Message code. <em>OBSOLETE: merged into SERIAL_NUMBER.</em>
2822         * <P>Type: INTEGER</P>
2823         */
2824        public static final String V1_MESSAGE_CODE = "message_code";
2825
2826        /**
2827         * Message identifier. <em>OBSOLETE: renamed to SERVICE_CATEGORY.</em>
2828         * <P>Type: INTEGER</P>
2829         */
2830        public static final String V1_MESSAGE_IDENTIFIER = "message_id";
2831
2832        /**
2833         * Service category (GSM/UMTS: message identifier; CDMA: service category).
2834         * <P>Type: INTEGER</P>
2835         */
2836        public static final String SERVICE_CATEGORY = "service_category";
2837
2838        /**
2839         * Message language code.
2840         * <P>Type: TEXT</P>
2841         */
2842        public static final String LANGUAGE_CODE = "language";
2843
2844        /**
2845         * Message body.
2846         * <P>Type: TEXT</P>
2847         */
2848        public static final String MESSAGE_BODY = "body";
2849
2850        /**
2851         * Message delivery time.
2852         * <P>Type: INTEGER (long)</P>
2853         */
2854        public static final String DELIVERY_TIME = "date";
2855
2856        /**
2857         * Has the message been viewed?
2858         * <P>Type: INTEGER (boolean)</P>
2859         */
2860        public static final String MESSAGE_READ = "read";
2861
2862        /**
2863         * Message format (3GPP or 3GPP2).
2864         * <P>Type: INTEGER</P>
2865         */
2866        public static final String MESSAGE_FORMAT = "format";
2867
2868        /**
2869         * Message priority (including emergency).
2870         * <P>Type: INTEGER</P>
2871         */
2872        public static final String MESSAGE_PRIORITY = "priority";
2873
2874        /**
2875         * ETWS warning type (ETWS alerts only).
2876         * <P>Type: INTEGER</P>
2877         */
2878        public static final String ETWS_WARNING_TYPE = "etws_warning_type";
2879
2880        /**
2881         * CMAS message class (CMAS alerts only).
2882         * <P>Type: INTEGER</P>
2883         */
2884        public static final String CMAS_MESSAGE_CLASS = "cmas_message_class";
2885
2886        /**
2887         * CMAS category (CMAS alerts only).
2888         * <P>Type: INTEGER</P>
2889         */
2890        public static final String CMAS_CATEGORY = "cmas_category";
2891
2892        /**
2893         * CMAS response type (CMAS alerts only).
2894         * <P>Type: INTEGER</P>
2895         */
2896        public static final String CMAS_RESPONSE_TYPE = "cmas_response_type";
2897
2898        /**
2899         * CMAS severity (CMAS alerts only).
2900         * <P>Type: INTEGER</P>
2901         */
2902        public static final String CMAS_SEVERITY = "cmas_severity";
2903
2904        /**
2905         * CMAS urgency (CMAS alerts only).
2906         * <P>Type: INTEGER</P>
2907         */
2908        public static final String CMAS_URGENCY = "cmas_urgency";
2909
2910        /**
2911         * CMAS certainty (CMAS alerts only).
2912         * <P>Type: INTEGER</P>
2913         */
2914        public static final String CMAS_CERTAINTY = "cmas_certainty";
2915
2916        /** The default sort order for this table. */
2917        public static final String DEFAULT_SORT_ORDER = DELIVERY_TIME + " DESC";
2918
2919        /**
2920         * Query columns for instantiating {@link android.telephony.CellBroadcastMessage} objects.
2921         */
2922        public static final String[] QUERY_COLUMNS = {
2923                _ID,
2924                GEOGRAPHICAL_SCOPE,
2925                PLMN,
2926                LAC,
2927                CID,
2928                SERIAL_NUMBER,
2929                SERVICE_CATEGORY,
2930                LANGUAGE_CODE,
2931                MESSAGE_BODY,
2932                DELIVERY_TIME,
2933                MESSAGE_READ,
2934                MESSAGE_FORMAT,
2935                MESSAGE_PRIORITY,
2936                ETWS_WARNING_TYPE,
2937                CMAS_MESSAGE_CLASS,
2938                CMAS_CATEGORY,
2939                CMAS_RESPONSE_TYPE,
2940                CMAS_SEVERITY,
2941                CMAS_URGENCY,
2942                CMAS_CERTAINTY
2943        };
2944    }
2945}
2946