2

在我们的 android 应用程序中使用 SQLCipher 4.2 后,我们看到性能急剧下降。即使我们不提供加密密钥并且只使用 SQLCipher 而不加密,我们的应用程序性能也会降低大约 300%,就像我们使用 FrameworkSQLite 数据库一样。是否有任何我们可以尝试更改以提高性能的连接参数?Android 附带的本机 sqlLite 引擎与 SqlCipher 使用的引擎有什么区别?

目标sdk是29

我们正在测试的设备是三星 T515 平板电脑,我们在分析器中没有看到太多 CPU 使用率

这就是我们定义 import sqlcipher android wrapper 的方式:

repositories {
    flatDir {
        dirs 'libs/aars'
    }
}
dependencies {
    ...
    implementation (name:'android-database-sqlcipher-4.2.0-release', ext:'aar')
    ...
} 

这是我们打开数据库的方式:

public SupportSQLiteOpenHelper getDatabase(final DatabaseIdentifier identifier, final DatabaseDefinition databaseDefinition) throws IOException, GeneralSecurityException {
    SupportSQLiteOpenHelper.Factory factory;
    final int sqliteEngine = databaseDefinition.getSqliteEngine();
    if (sqliteEngine == DatabaseDefinition.SQLITE_ENGINE_ANDROID_FRAMEWORK) {
        factory = new FrameworkSQLiteOpenHelperFactory();
    }
    else if (sqliteEngine == DatabaseDefinition.SQLITE_ENGINE_SQLCIPHER) {
        final SQLiteDatabaseHook sqlCipherHook = new SQLiteDatabaseHook() {
            @Override
            public void preKey(final net.sqlcipher.database.SQLiteDatabase sqLiteDatabase) {
            }
            @Override
            public void postKey(final net.sqlcipher.database.SQLiteDatabase sqLiteDatabase) {
                    sqLiteDatabase.rawExecSQL("PRAGMA cipher_memory_security = OFF;");
            }
        };
        if (databaseDefinition.isSqlCipherEncrypted()) {
            factory = new SupportFactory(databaseDefinition.getSqlCipherEncryptionKey(), sqlCipherHook);
        }
        else {
            factory = new SupportFactory(new byte[0], sqlCipherHook);
        }
    }
    else {
        throw new AssertionError();
    }
    final SupportSQLiteOpenHelper.Callback callback = new SupportSQLiteOpenHelper.Callback(1) {
        @Override
        public void onCreate(final SupportSQLiteDatabase db) {
        }
        @Override
        public void onUpgrade(final SupportSQLiteDatabase db, final int oldVersion, final int newVersion) {
        }
        @Override
        public void onOpen(final SupportSQLiteDatabase db) {
            super.onOpen(db);
            ....
        }
    };
    final SupportSQLiteOpenHelper.Configuration configuration = SupportSQLiteOpenHelper.Configuration
            .builder(mApplication)
            .name(databaseDefinition.getPath())
            .callback(callback)
            .build();
    return factory.create(configuration);
}``` 
4

0 回答 0