/packages/providers/TelephonyProvider/src/com/android/providers/telephony/CdmaCallOptionProvider.java /packages/providers/TelephonyProvider/src/com/android/providers/telephony/MmsProvider.java /packages/providers/TelephonyProvider/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java /packages/providers/TelephonyProvider/src/com/android/providers/telephony/MmsSmsProvider.java /packages/providers/TelephonyProvider/src/com/android/providers/telephony/SmsProvider.java /packages/providers/TelephonyProvider/src/com/android/providers/telephony/TelephonyProvider.java
@Override public void onCreate(SQLiteDatabase db) { createMmsTables(db); createSmsTables(db); createCommonTables(db); createCommonTriggers(db); createMmsTriggers(db); createWordsTables(db); createIndices(db); }
private void createSmsTables(SQLiteDatabase db) {
// N.B.: Whenever the columns here are changed, the columns in
// {@ref MmsSmsProvider} must be changed to match.
db.execSQL("CREATE TABLE sms (" +
"_id INTEGER PRIMARY KEY," +
"thread_id INTEGER," +
"address TEXT," +
"person INTEGER," +
"date INTEGER," +
"protocol INTEGER," +
"read INTEGER DEFAULT 0," +
"status INTEGER DEFAULT -1," + // a TP-Status value // or -1 if it// status hasn't// been received
"type INTEGER," +
"reply_path_present INTEGER," +
"subject TEXT," +
"body TEXT," +
"service_center TEXT," +
"locked INTEGER DEFAULT 0," +
"sub_id INTEGER DEFAULT 0," + // sub_id : 0 for subscription 1// sub_id : 1 for subscription 2
"error_code INTEGER DEFAULT 0," +
"seen INTEGER DEFAULT 0" +
");");
/**
* This table is used by the SMS dispatcher to hold
* incomplete partial messages until all the parts arrive.
*/
db.execSQL("CREATE TABLE raw (" +
"_id INTEGER PRIMARY KEY," +
"date INTEGER," +
"reference_number INTEGER," + // one per full message
"count INTEGER," + // the number of parts
"sequence INTEGER," + // the part number of this message
"destination_port INTEGER," +
"address TEXT," +
"pdu TEXT);"); // the raw PDU for this part
db.execSQL("CREATE TABLE attachments (" +
"sms_id INTEGER," +
"content_url TEXT," +
"offset INTEGER);");
/**
* This table is used by the SMS dispatcher to hold pending
* delivery status report intents.
*/
db.execSQL("CREATE TABLE sr_pending (" +
"reference_number INTEGER," +
"action TEXT," +
"data TEXT);");
}
大家可以看到短信相关的4张表:sms、raw、attachments、sr_pending
列名 |
类型 |
说明 |
_id |
integer |
唯一标识,自增,从1开始 |
thread_id |
integer |
threads表的id |
address |
text |
接收者手机号码,对于一个会话,有可能含有多个接收者,每个人都将收到一条短信 |
person |
integer |
联系人(模块)列表里的序号,陌生人为null |
date |
integer |
时间,以豪秒来表示 |
protocol |
integer |
协议,分为:0-SMS_RPOTO,1-MMS_PROTO。成功发送后设置。 |
read |
integer |
是否阅读:0-未读,1-已读 |
status |
integer |
状态:-1默认值,0-complete,64-pending,128-failed |
type |
integer |
ALL=0;INBOX=1;SENT=2;DRAFT=3;OUTBOX=4;FAILED=5;QUEUED=6; |
reply_path_present |
integer |
TP-Reply-Path位的值 0/1 |
subject |
text |
短信的主题,默认为空 |
body |
text |
短信内容 |
service_center |
text |
短信服务中心号码编号 |
locked |
integer |
此条短信是否已由用户锁定,0-未锁定,1-已锁定 |
error_code |
integer |
错误代码,有哪些值暂时未知 |
seen |
integer |
用于指明该消息是否已被用户看到(非阅读,点开会话列表即可,不用打开会话),仅对收到的消息有用 |
private void createMmsTables(SQLiteDatabase db) { // N.B.: Whenever the columns here are changed, the columns in // {@ref MmsSmsProvider} must be changed to match. db.execSQL("CREATE TABLE " + MmsProvider.TABLE_PDU + " (" + Mms._ID + " INTEGER PRIMARY KEY," + Mms.THREAD_ID + " INTEGER," + Mms.DATE + " INTEGER," + Mms.MESSAGE_BOX + " INTEGER," + Mms.READ + " INTEGER DEFAULT 0," + Mms.MESSAGE_ID + " TEXT," + Mms.SUBJECT + " TEXT," + Mms.SUBJECT_CHARSET + " INTEGER," + Mms.CONTENT_TYPE + " TEXT," + Mms.CONTENT_LOCATION + " TEXT," + Mms.EXPIRY + " INTEGER," + Mms.MESSAGE_CLASS + " TEXT," + Mms.MESSAGE_TYPE + " INTEGER," + Mms.MMS_VERSION + " INTEGER," + Mms.MESSAGE_SIZE + " INTEGER," + Mms.PRIORITY + " INTEGER," + Mms.READ_REPORT + " INTEGER," + Mms.REPORT_ALLOWED + " INTEGER," + Mms.RESPONSE_STATUS + " INTEGER," + Mms.STATUS + " INTEGER," + Mms.TRANSACTION_ID + " TEXT," + Mms.RETRIEVE_STATUS + " INTEGER," + Mms.RETRIEVE_TEXT + " TEXT," + Mms.RETRIEVE_TEXT_CHARSET + " INTEGER," + Mms.READ_STATUS + " INTEGER," + Mms.CONTENT_CLASS + " INTEGER," + Mms.RESPONSE_TEXT + " TEXT," + Mms.DELIVERY_TIME + " INTEGER," + Mms.DELIVERY_REPORT + " INTEGER," + Mms.LOCKED + " INTEGER DEFAULT 0," + Mms.SEEN + " INTEGER DEFAULT 0," + Mms.SUB_ID + " INTEGER DEFAULT 0" + ");"); db.execSQL("CREATE TABLE " + MmsProvider.TABLE_ADDR + " (" + Addr._ID + " INTEGER PRIMARY KEY," + Addr.MSG_ID + " INTEGER," + Addr.CONTACT_ID + " INTEGER," + Addr.ADDRESS + " TEXT," + Addr.TYPE + " INTEGER," + Addr.CHARSET + " INTEGER);"); db.execSQL("CREATE TABLE " + MmsProvider.TABLE_PART + " (" + Part._ID + " INTEGER PRIMARY KEY," + Part.MSG_ID + " INTEGER," + Part.SEQ + " INTEGER DEFAULT 0," + Part.CONTENT_TYPE + " TEXT," + Part.NAME + " TEXT," + Part.CHARSET + " INTEGER," + Part.CONTENT_DISPOSITION + " TEXT," + Part.FILENAME + " TEXT," + Part.CONTENT_ID + " TEXT," + Part.CONTENT_LOCATION + " TEXT," + Part.CT_START + " INTEGER," + Part.CT_TYPE + " TEXT," + Part._DATA + " TEXT," + Part.TEXT + " TEXT);"); db.execSQL("CREATE TABLE " + MmsProvider.TABLE_RATE + " (" + Rate.SENT_TIME + " INTEGER);"); db.execSQL("CREATE TABLE " + MmsProvider.TABLE_DRM + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY," + "_data TEXT);"); }大家可以看出,彩信大致为以下5张表:pdu、addr、part、rate、drm
private void createCommonTables(SQLiteDatabase db) { db.execSQL("CREATE TABLE canonical_addresses (" + "_id INTEGER PRIMARY KEY," + "address TEXT);"); db.execSQL("CREATE TABLE threads (" + Threads._ID + " INTEGER PRIMARY KEY," + Threads.DATE + " INTEGER DEFAULT 0," + Threads.MESSAGE_COUNT + " INTEGER DEFAULT 0," + Threads.RECIPIENT_IDS + " TEXT," + Threads.SNIPPET + " TEXT," + Threads.SNIPPET_CHARSET + " INTEGER DEFAULT 0," + Threads.READ + " INTEGER DEFAULT 1," + Threads.TYPE + " INTEGER DEFAULT 0," + Threads.ERROR + " INTEGER DEFAULT 0," + Threads.HAS_ATTACHMENT + " INTEGER DEFAULT 0);"); db.execSQL("CREATE TABLE " + MmsSmsProvider.TABLE_PENDING_MSG +" (" + PendingMessages._ID + " INTEGER PRIMARY KEY," + PendingMessages.PROTO_TYPE + " INTEGER," + PendingMessages.MSG_ID + " INTEGER," + PendingMessages.MSG_TYPE + " INTEGER," + PendingMessages.ERROR_TYPE + " INTEGER," + PendingMessages.ERROR_CODE + " INTEGER," + PendingMessages.RETRY_INDEX + " INTEGER NOT NULL DEFAULT 0," + PendingMessages.DUE_TIME + " INTEGER," + PendingMessages.LAST_TRY + " INTEGER);"); }公共的表:canonical_addresses、threads、pending_msgs
private void createWordsTables(SQLiteDatabase db) { try { db.execSQL("CREATE VIRTUAL TABLE words USING FTS3 (_id INTEGER PRIMARY KEY, index_text TEXT, source_id INTEGER, table_to_use INTEGER);"); }words存储了 短彩信中的单词 ,用于搜索时使用