@@ -73,6 +73,36 @@ public class SQLiteDatabase extends SQLiteClosable {
73
73
private static final int EVENT_DB_OPERATION = 52000 ;
74
74
private static final int EVENT_DB_CORRUPT = 75004 ;
75
75
76
+ public static void upgradeDatabaseFormatFromVersion1To2 (File databaseToMigrate , String password ) throws Exception {
77
+
78
+ File newDatabasePath = null ;
79
+ boolean renameDatabase = false ;
80
+ SQLiteDatabaseHook hook = new SQLiteDatabaseHook (){
81
+ public void preKey (SQLiteDatabase database ){
82
+ database .execSQL ("PRAGMA cipher_default_use_hmac = off" );
83
+ }
84
+ public void postKey (SQLiteDatabase database ){
85
+ database .execSQL ("PRAGMA cipher_default_use_hmac = on" );
86
+ }
87
+ };
88
+
89
+ try {
90
+ newDatabasePath = File .createTempFile ("temp" , "db" , databaseToMigrate .getParentFile ());
91
+ SQLiteDatabase source = SQLiteDatabase .openOrCreateDatabase (databaseToMigrate , password , null , hook );
92
+ source .rawExecSQL (String .format ("ATTACH DATABASE '%s' as newdb" , newDatabasePath .getAbsolutePath ()));
93
+ source .rawExecSQL ("SELECT sqlcipher_export('newdb')" );
94
+ source .rawExecSQL ("DETACH DATABASE newdb" );
95
+ source .close ();
96
+ renameDatabase = true ;
97
+ } catch (Exception e ){
98
+ throw e ;
99
+ }
100
+ if (renameDatabase ){
101
+ databaseToMigrate .delete ();
102
+ newDatabasePath .renameTo (databaseToMigrate );
103
+ }
104
+ }
105
+
76
106
private static void loadICUData (Context context ) {
77
107
78
108
try {
@@ -81,8 +111,8 @@ private static void loadICUData(Context context) {
81
111
if (!icuDir .exists ()) icuDir .mkdirs ();
82
112
File icuDataFile = new File (icuDir , "icudt46l.dat" );
83
113
if (!icuDataFile .exists ()) {
84
- ZipInputStream in = new ZipInputStream (context .getAssets ().open ("icudt46l.zip" ));
85
- in .getNextEntry ();
114
+ ZipInputStream in = new ZipInputStream (context .getAssets ().open ("icudt46l.zip" ));
115
+ in .getNextEntry ();
86
116
87
117
OutputStream out = new FileOutputStream (icuDataFile );
88
118
byte [] buf = new byte [1024 ];
0 commit comments