aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-04-11 20:25:50 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-04-14 13:06:49 +0200
commit227155d484766a620a2f9467a248c844fca26382 (patch)
tree736238cd070ae89774dfdb9939095c37d60dd01a /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
parente02e9e6707612db592fdfb3ae834fef5cbb0def0 (diff)
downloadopen-keychain-227155d484766a620a2f9467a248c844fca26382.tar.gz
open-keychain-227155d484766a620a2f9467a248c844fca26382.tar.bz2
open-keychain-227155d484766a620a2f9467a248c844fca26382.zip
add debug backup/restore options to main menu
Closes #543
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java45
1 files changed, 44 insertions, 1 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
index b3165d347..80fa914b2 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java
@@ -36,6 +36,9 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UserIdsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.CertsColumns;
import org.sufficientlysecure.keychain.util.Log;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
public class KeychainDatabase extends SQLiteOpenHelper {
@@ -210,7 +213,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
}
}
- if(!hasApgDb)
+ if(!hasApgDb || true)
return;
Log.d(Constants.TAG, "apg.db exists! Importing...");
@@ -300,4 +303,44 @@ public class KeychainDatabase extends SQLiteOpenHelper {
Log.d(Constants.TAG, "All done, (not) deleting apg.db");
}
+
+ private static void copy(File in, File out) throws IOException {
+ FileInputStream ss = new FileInputStream(in);
+ FileOutputStream ds = new FileOutputStream(out);
+ byte[] buf = new byte[512];
+ while(ss.available() > 0) {
+ int count = ss.read(buf, 0, 512);
+ ds.write(buf, 0, count);
+ }
+ }
+
+ public static void debugRead(Context context) throws IOException {
+ if(!Constants.DEBUG) {
+ return;
+ }
+ File in = context.getDatabasePath("debug.db");
+ File out = context.getDatabasePath("openkeychain.db");
+ if(!in.canRead()) {
+ throw new IOException("Cannot read " + in.getName());
+ }
+ if(!out.canRead()) {
+ throw new IOException("Cannot write " + out.getName());
+ }
+ copy(in, out);
+ }
+
+ public static void debugWrite(Context context) throws IOException {
+ if(!Constants.DEBUG) {
+ return;
+ }
+ File in = context.getDatabasePath("openkeychain.db");
+ File out = context.getDatabasePath("debug.db");
+ if(!in.canRead()) {
+ throw new IOException("Cannot read " + in.getName());
+ }
+ if(!out.canRead()) {
+ throw new IOException("Cannot write " + out.getName());
+ }
+ copy(in, out);
+ }
}