设为首页 加入收藏

TOP

SettingsProvider 之 DatabaseHelper
2015-07-24 05:50:41 来源: 作者: 【 】 浏览:4
Tags:SettingsProvider DatabaseHelper

?

?

1、只为所有者创建global表。
// Only create the global table for the singleton 'owner' user
        //只为所有者创建global table。
        if (mUserHandle == UserHandle.USER_OWNER) {
            createGlobalTable(db);
        }

2、//如果我们正在 加密设备,只能运行核心应用程序。 onlyCore为true

?

?

        if (!onlyCore) {
            loadBookmarks(db);
        }

?

3、在Settings.db的upgradeVersion为26时,创建了Secure表。在upgradeVersion为27、52、55时,将部分配置项转移到secure中。
upgradeVersion = 70时,更新bookmarks

?

?

4、在Settings.db的upgradeVersion = 82时,创建了Global表。 // Move to per-user settings dbs
在Settings.java中创建moveToSystem或者moveToSecure,通过SettingsProvider,传到DatabaseHelper中。

upgradeVersion = 84、87,89、90、93时,从secure中移植到Global中。

upgradeVersion = 85、88、90、91、93时,从System中移植到Global中。
5、 100%

6、在SettingsProvider中定义变量,注意前缀和后缀都很重要,切记。

根据搜索中的前缀,将符合前缀规格的项移植到Secure中。
private void movePrefixedSettingsToNewTable(
            SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
        SQLiteStatement insertStmt = null;
        SQLiteStatement deleteStmt = null;

        db.beginTransaction();
        try {
            insertStmt = db.compileStatement(INSERT INTO  + destTable
                    +  (name,value) SELECT name,value FROM  + sourceTable
                    +  WHERE substr(name,0,?)=?);
            deleteStmt = db.compileStatement(
                    DELETE FROM  + sourceTable +  WHERE substr(name,0,?)=?);

            for (String prefix : prefixesToMove) {
                insertStmt.bindLong(1, prefix.length() + 1);
                insertStmt.bindString(2, prefix);
                insertStmt.execute();

                deleteStmt.bindLong(1, prefix.length() + 1);
                deleteStmt.bindString(2, prefix);
                deleteStmt.execute();
            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
            if (insertStmt != null) {
                insertStmt.close();
            }
            if (deleteStmt != null) {
                deleteStmt.close();
            }
        }
    }




?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇zoj3080 ChiBi --- floyd求连通块.. 下一篇PIG中的null问题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: