SMS/MMS数据都保存在数据库:
/data/data/com.android.providers.telephony/databases/mmssms.db
数据库处理代码在:
packages/providers/TelephonyProvider/MmsSmsDatabaseHelper.java
@Override public void onCreate(SQLiteDatabase db) { createMmsTables(db); // create mms table createSmsTables(db); // create sms table createCommonTables(db); //create common table, for example, thread createCommonTriggers(db); //create common triggers createMmsTriggers(db); // create mms related triggers createWordsTables(db); // create words related triggers, will be used in search function createIndices(db); //create index typeThreadIdIndex about (type, thread_id) for sms tabble }
Function: CreateWordsTables
1.create words table;
2.create trigger for sms update/delete, mms update/delete;
3.init words table
PS: why don't create trigger for sms insert?
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);");
// monitor the sms table
// NOTE don't handle inserts using a trigger because it has an unwanted
// side effect: the value returned for the last row ends up being the
// id of one of the trigger insert not the original row insert.
// Handle inserts manually in the provider.
db.execSQL("CREATE TRIGGER sms_words_update AFTER UPDATE ON sms BEGIN UPDATE words " +
" SET index_text = NEW.body WHERE (source_id=NEW._id AND table_to_use=1); " +
" END;");
db.execSQL("CREATE TRIGGER sms_words_delete AFTER DELETE ON sms BEGIN DELETE FROM " +
" words WHERE source_id = OLD._id AND table_to_use = 1; END;");
// monitor the mms table
db.execSQL("CREATE TRIGGER mms_words_update AFTER UPDATE ON part BEGIN UPDATE words " +
" SET index_text = NEW.text WHERE (source_id=NEW._id AND table_to_use=2); " +
" END;");
db.execSQL("CREATE TRIGGER mms_words_delete AFTER DELETE ON part BEGIN DELETE FROM " +
" words WHERE source_id = OLD._id AND table_to_use = 2; END;");
populateWordsTable(db);
} catch (Exception ex) {
Log.e(TAG, "got exception creating words table: " + ex.toString());
}
}
其他定义:
public class MmsProvider extends ContentProvider {
static final String TABLE_PDU = "pdu";static final String TABLE_ADDR = "addr";
static final String TABLE_PART = "part";
static final String TABLE_RATE = "rate";
static final String TABLE_DRM = "drm";
static final String TABLE_WORDS = "words";
...
}
public class MmsSmsProvider extends ContentProvider {
/**
* the name of the table that is used to store the queue of
* messages(both MMS and SMS) to be sent/downloaded.
*/
public static final String TABLE_PENDING_MSG = "pending_msgs";
/**
* the name of the table that is used to store the canonical addresses for both SMS and MMS.
*/
private static final String TABLE_CANONICAL_ADDRESSES = "canonical_addresses";
private static final String TABLE_THREADS = "threads";
...
}
public class SmsProvider extends ContentProvider {
static final String TABLE_SMS = "sms";
private static final String TABLE_RAW = "raw";
private static final String TABLE_SR_PENDING = "sr_pending";
..
}
content://sms/inbox 收件箱
content://sms/sent 已发送
content://sms/draft 草稿
content://sms/outbox 发件箱
content://sms/failed 发送失败
content://sms/queued 待发送列表