-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathCipherMigrateTest.java
45 lines (39 loc) · 1.58 KB
/
CipherMigrateTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package net.zetetic.tests;
import android.util.Log;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteDatabaseHook;
import net.zetetic.QueryHelper;
import net.zetetic.ZeteticApplication;
import java.io.File;
public class CipherMigrateTest extends SQLCipherTest {
File olderFormatDatabase = ZeteticApplication.getInstance().getDatabasePath("2x.db");
@Override
public boolean execute(SQLiteDatabase database) {
database.close();
final boolean[] status = {false};
try {
ZeteticApplication.getInstance().extractAssetToDatabaseDirectory("2x.db");
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
public void preKey(SQLiteDatabase database) {}
public void postKey(SQLiteDatabase database) {
String value = QueryHelper.singleValueFromQuery(database, "PRAGMA cipher_migrate");
setMessage(String.format("cipher_migrate result:%s", value));
status[0] = Integer.valueOf(value) == 0;
}
};
database = SQLiteDatabase.openDatabase(olderFormatDatabase.getPath(),
ZeteticApplication.DATABASE_PASSWORD, null,
SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.CREATE_IF_NECESSARY, hook);
if(database != null){
database.close();
}
} catch (Exception e) {
Log.i(TAG, "error", e);
}
return status[0];
}
@Override
public String getName() {
return "Cipher Migrate Test";
}
}