diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4b674380f3f5881c8de08b6fb4b42f9827ae901b..9bbbf1bb012f97f4d31b57f4935f8324152b07c9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -104,11 +104,12 @@ + diff --git a/app/src/main/java/foundation/e/drive/database/DbHelper.java b/app/src/main/java/foundation/e/drive/database/DbHelper.java index 0c84a7574a884f5b2ffd2acb59488839418a3e8b..ca30b84fdc8cf1a8addbbce814b704b785dcd79f 100644 --- a/app/src/main/java/foundation/e/drive/database/DbHelper.java +++ b/app/src/main/java/foundation/e/drive/database/DbHelper.java @@ -13,8 +13,17 @@ import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; + +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 java.util.ArrayList; import java.util.List; + +import foundation.e.drive.BuildConfig; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.models.SyncedFileState; @@ -287,4 +296,32 @@ public final class DbHelper extends SQLiteOpenHelper { dao.close(); return result; } + + + /** + * Copy database file into user accessible directory for debuging purpose + * @return path to the dump or null if failure + */ + public static void dumpDatabase(Context context) { + final File database = context.getDatabasePath(DbHelper.DATABASE_NAME); + final File dstDir = context.getExternalFilesDir("DataBaseDump"); + if (!dstDir.exists()) dstDir.mkdir(); + final File dbDump = new File(dstDir, "dump-" + BuildConfig.VERSION_NAME + "-" + System.currentTimeMillis() + ".db"); + + if (database.exists()) { + try (final InputStream src = new FileInputStream(database); + final OutputStream dst = new FileOutputStream(dbDump)) { + byte[] buffer = new byte[1024]; + int read; + while ((read = src.read(buffer)) != -1) { + dst.write(buffer, 0, read); + } + Log.i(TAG, "Database has been dump at "+ dbDump.getAbsolutePath()); + return; + } catch (IOException e) { + Log.e(TAG, "IOException", e); + } + } + Log.e(TAG,"Failed to dump Database"); + } } diff --git a/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java b/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..79809dd21e1df4ca65be5941dcf026a7c0796800 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java @@ -0,0 +1,43 @@ +/* + * Copyright © ECORP SAS 2021-2022. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + */ +package foundation.e.drive.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import foundation.e.drive.database.DbHelper; +import foundation.e.drive.services.ObserverService; + +/** + * @author Jonathan Klee + * @author Vincent Bourgmayer + */ +public class DebugCmdReceiver extends BroadcastReceiver { + + public static final String ACTION_FORCE_SYNC = "foundation.e.drive.action.FORCE_SYNC"; + public static final String ACTION_DUMP_DATABASE = "foundation.e.drive.action.DUMP_DATABASE"; + public static final String TAG = "DebugCmdReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + Log.d(TAG, "onReceive"); + switch (intent.getAction()) { + case ACTION_FORCE_SYNC: + Log.i(TAG, "Force Sync intent received"); + context.startService(new Intent(ACTION_FORCE_SYNC, null, context, ObserverService.class)); + break; + case ACTION_DUMP_DATABASE: + DbHelper.dumpDatabase(context); + break; + default: + break; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/receivers/ForceSyncReceiver.java b/app/src/main/java/foundation/e/drive/receivers/ForceSyncReceiver.java deleted file mode 100644 index a9656fec3b36c066e3bd0e8ff5850646d0d6c1e2..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/drive/receivers/ForceSyncReceiver.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © ECORP SAS 2021-2022. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html - */ -package foundation.e.drive.receivers; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -import foundation.e.drive.services.ObserverService; - -/** - * @author Jonathan Klee - */ -public class ForceSyncReceiver extends BroadcastReceiver { - - public static final String ACTION_FORCE_SYNC = "foundation.e.drive.action.FORCE_SYNC"; - public static final String TAG = "ForceSyncReceiver"; - - @Override - public void onReceive(Context context, Intent intent) { - if (ACTION_FORCE_SYNC.equals(intent.getAction())) { - Log.i(TAG, "Start ObserverService"); - context.startService(new Intent(ACTION_FORCE_SYNC, null, context, ObserverService.class)); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/services/ObserverService.java b/app/src/main/java/foundation/e/drive/services/ObserverService.java index 133abbabdfaa43fa523b7355579ba20410b01947..e57f135e1d21e537b17ac9ad9eb54073bf1e84f4 100644 --- a/app/src/main/java/foundation/e/drive/services/ObserverService.java +++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java @@ -43,7 +43,7 @@ import foundation.e.drive.models.SyncRequest; import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.models.SyncedFileState; import foundation.e.drive.operations.ListFileRemoteOperation; -import foundation.e.drive.receivers.ForceSyncReceiver; +import foundation.e.drive.receivers.DebugCmdReceiver; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.DavClientProvider; @@ -128,7 +128,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene long currentTime = System.currentTimeMillis(); boolean forceSync = false; if (intent != null) { - forceSync = ForceSyncReceiver.ACTION_FORCE_SYNC.equals(intent.getAction()); + forceSync = DebugCmdReceiver.ACTION_FORCE_SYNC.equals(intent.getAction()); } //if time diff between current sync and last sync is higher or equal to delay minimum between two sync