aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-05-31 19:21:39 +0200
committerChristian Schneppe <christian@pix-art.de>2016-05-31 19:21:39 +0200
commit5b451b2703621747391f8915bfdb33a58a3f76c1 (patch)
tree125b477ca8a0d727d0c2ab6d97502e05ec00c38a /src/main/java/eu/siacs/conversations
parent2cdc31a6887f242dfe4faca91af63ffd4e74ef67 (diff)
parent848878b2a84efe884908ae56032b35e6e2fcd0a4 (diff)
Merge branch 'refs/heads/old_version' into new_version
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java44
2 files changed, 45 insertions, 1 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index f1155b07d..5a7ca7a56 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -51,7 +51,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null;
- private static final String DATABASE_NAME = "history";
+ public static final String DATABASE_NAME = "history";
private static final int DATABASE_VERSION = 27;
private static String CREATE_CONTATCS_STATEMENT = "create table "
diff --git a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java
index a9adfb174..b47b0c1dd 100644
--- a/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/UpdaterActivity.java
@@ -27,9 +27,15 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
+import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.services.UpdaterWebService;
public class UpdaterActivity extends Activity {
@@ -94,6 +100,37 @@ public class UpdaterActivity extends Activity {
}
}
+ private void ExportDatabase() throws IOException {
+
+ // Get hold of the db:
+ InputStream myInput = new
+ FileInputStream(this.getDatabasePath(DatabaseBackend.DATABASE_NAME));
+
+ // Set the output folder on the SDcard
+ File directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Pix-Art Messenger/.Database/");
+
+ // Create the folder if it doesn't exist:
+ if (!directory.exists()) {
+ directory.mkdirs();
+ }
+
+ // Set the output file stream up:
+ OutputStream myOutput = new FileOutputStream(directory.getPath() + "/Database.bak");
+
+ // Transfer bytes from the input file to the output file
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = myInput.read(buffer)) > 0) {
+ myOutput.write(buffer, 0, length);
+ }
+
+ // Close and clear the streams
+ myOutput.flush();
+ myOutput.close();
+ myInput.close();
+ }
+
+
@Override
public void onDestroy() {
//unregister your receivers
@@ -201,6 +238,13 @@ public class UpdaterActivity extends Activity {
reponseObj = new JSONObject(responseMessage);
boolean success = reponseObj.getBoolean("success");
if (success) {
+ //start backing up database
+ try {
+ ExportDatabase();
+ Log.d(Config.LOGTAG,"AppUpdater: Database successfully exported");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
//Overall information about the contents of a package
//This corresponds to all of the information collected from AndroidManifest.xml.
PackageInfo pInfo = null;