Skip to content

ICU dat file on SD card #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
developernotes opened this issue Mar 20, 2012 · 8 comments
Closed

ICU dat file on SD card #48

developernotes opened this issue Mar 20, 2012 · 8 comments
Labels
enhancement A software enhancement for SQLCipher for Android

Comments

@developernotes
Copy link
Member

Add the ability to specify the storage location of the unzipped ICU dat file. Specifically onto a SD card, this is a practical location for older devices that have limited onboard storage.

@jeffdcamp
Copy link
Contributor

Here is a very simple patch that will fix this issue and it is backwards compatible. I applied it and tested it against the v2 branch.


--- src/net/sqlcipher/database/SQLiteDatabase.java  (revision 2a7b24d6eecc6b8ff2ccffbe2a0d4d745ea5ace0)
+++ src/net/sqlcipher/database/SQLiteDatabase.java  (revision )
@@ -103,11 +103,10 @@
         }
     }
 
-    private static void loadICUData(Context context) {
+    private static void loadICUData(Context context, File workingDir) {
         
         try {
-            File applicationFilesDirectory = context.getFilesDir();
-            File icuDir = new File(applicationFilesDirectory, "icu");
+            File icuDir = new File(workingDir, "icu");
             if(!icuDir.exists()) icuDir.mkdirs();
             File icuDataFile = new File(icuDir, "icudt46l.dat");
             if(!icuDataFile.exists()) {
@@ -130,19 +129,23 @@
         }
     }
 
-    public static void loadLibs (Context context)
+    public static void loadLibs (Context context) {
+        loadLibs(context, context.getFilesDir());
+    }
+
+    public static void loadLibs (Context context, File workingDir)
     {
         System.loadLibrary("stlport_shared");
         System.loadLibrary("sqlcipher_android");
         System.loadLibrary("database_sqlcipher");
 
         boolean systemICUFileExists = new File("/system/usr/icu/icudt46l.dat").exists();
-        File applicationFilesDirectory = context.getFilesDir();
-        String icuRootPath = systemICUFileExists ? "/system/usr" : applicationFilesDirectory.getAbsolutePath();
+
+        String icuRootPath = systemICUFileExists ? "/system/usr" : workingDir.getAbsolutePath();
         setICURoot(icuRootPath);
         
         if(!systemICUFileExists){
-            loadICUData(context);
+            loadICUData(context, workingDir);
         }
     }

@developernotes
Copy link
Member Author

Hi jeffdcamp,

Thanks for taking a look at this. Would you mind sending a pull request for the change? Thanks!

@jeffdcamp
Copy link
Contributor

I just submitted 2 pull requests for the change.... one for master (version 1.1) and one for v2 (2.0)

@developernotes
Copy link
Member Author

Hi jeffdcamp,

Thanks for submitting that. I'll review it this afternoon and if everything runs smooth with our test suite I will merge it into the v2 branch. v2 will be merged back into master soon so no need for the extra pull request. Thanks again!

@jeffdcamp
Copy link
Contributor

I know this is not the place for this comment.... but is there a developer group that I can post comments/questions to? (I'm concerned about compatibility/migration from v1.1 to v2.0... my 1.1 database didn't seem to open when I compiled v2 branch and tried to open an existing 1.1 database using v2 code)

@developernotes
Copy link
Member Author

Hi jeffdcamp,

There is a difference between the database format in 2.0 vs. 1.1. I have added a upgrade method in v2 called SQLiteDatabase.upgradeDatabaseFormatFromVersion1To2 to perform the upgrade. If you need to maintain the 1.1 format but want to use the 2.0 library I have also added a SQLiteDatabaseHook interface that you can pass into the SQLDatabase.openOrCreateDatabase method which will allow you to open a 1.1 database without issues/upgrading with the 2.0 sqlcipher core. Note this is only available in the v2 branch. To do something like that it would look like:

SQLiteDatabaseHook hook = new SQLiteDatabaseHook(){
  public void preKey(SQLiteDatabase database){
    database.rawExecSQL("PRAGMA cipher_default_use_hmac = off");
  }
  public void postKey(SQLiteDatabase database){}
}

SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databasePath, 
                                                              password, null, hook);

@jeffdcamp
Copy link
Contributor

FYI... I've been using this feature ("ICU dat file on SD card") in 2.0RC5 for quite some time and on many devices using many different versions of Android and this has been working great.

Jeff

@developernotes
Copy link
Member Author

Jeff,

Glad to hear it's working well for you, thanks for reporting back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A software enhancement for SQLCipher for Android
Projects
None yet
Development

No branches or pull requests

2 participants