SMS/MMS provider - MmsSmsDatabaseHelper

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        待发送列表



http://blog.csdn.net/hailushijie/article/details/8734167

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值