diff --git a/README.md b/README.md index c7d430fa0f033ae1de1a4b494f92a45ed4cbf60f..b3b3b48d08b8a86aa11d7e73a9f84ed3bbafe525 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,21 @@ adb logcat --pid=$(adb shell pidof -s foundation.e.drive) You can also use the script `dev-tools.sh` to run those command. Use : `./dev-tools.sh -h` to display options + +**Disable File Observer** + + +```bash +adb shell am broadcast -a foundation.e.drive.action.ENABLE_FILE_OBSERVER --receiver-include-background --ez file_observer_enable false +``` + +**Enable File Observer** + + +```bash +adb shell am broadcast -a foundation.e.drive.action.ENABLE_FILE_OBSERVER --receiver-include-background --ez file_observer_enable true +``` + ### local NC for testing Use following documentation to set up a local NC instance diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b4bdbf181ae61d6c80d56f991db39da3b460e7e8..6d5f4569125dd2cb0576311c51a25645a32b206a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -105,6 +105,7 @@ + diff --git a/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java b/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java index d1c743c2da55a576745cd1946dfd9c01a1f822c3..2235d838b4c7b836afdacea9e75e729e30111f59 100644 --- a/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java @@ -21,7 +21,9 @@ import java.util.ArrayList; import java.util.List; import foundation.e.drive.EdriveApplication; +import foundation.e.drive.account.AccountUtils; import foundation.e.drive.database.DbHelper; +import foundation.e.drive.fileObservers.FileObserverManager; import foundation.e.drive.models.SyncRequest; import foundation.e.drive.models.SyncedFileState; import foundation.e.drive.models.SyncedFolder; @@ -41,7 +43,10 @@ public class DebugCmdReceiver extends BroadcastReceiver { public static final String ACTION_FORCE_SCAN = "foundation.e.drive.action.FORCE_SCAN"; public static final String ACTION_DUMP_DATABASE = "foundation.e.drive.action.DUMP_DATABASE"; public static final String ACTION_FULL_LOG_ON_PROD = "foundation.e.drive.action.FULL_LOG_ON_PROD"; + public static final String ACTION_ENABLE_FILE_OBSERVER = "foundation.e.drive.action.ENABLE_FILE_OBSERVER"; + private static final String FULL_LOG_ENABLE_KEY = "full_log_enable"; + private static final String FILE_OBSERVER_ENABLE_KEY = "file_observer_enable"; @Override public void onReceive(@NonNull Context context, @NonNull Intent intent) { @@ -62,6 +67,20 @@ public class DebugCmdReceiver extends BroadcastReceiver { ReleaseTree.allowDebugLogOnProd(allow_full_log); Timber.d("Allow full log on prod: %s", allow_full_log); break; + case ACTION_ENABLE_FILE_OBSERVER: + if (AccountUtils.getAccount(context) == null) { + Timber.d("Ignore intent: no account"); + } + + final EdriveApplication application = (EdriveApplication) context.getApplicationContext(); + final boolean enabled = intent.getBooleanExtra(FILE_OBSERVER_ENABLE_KEY, true); + Timber.i("Intent received: enable FileObserver: %s", enabled); + if (enabled) { + application.startRecursiveFileObserver(); + } else { + application.stopRecursiveFileObserver(); + } + break; case ACTION_TEST_SYNC: Timber.d("Test SyncWorker.kt started"); final SyncRequestCollector collector = (SyncRequestCollector) SyncProxy.INSTANCE; diff --git a/dev_tools.sh b/dev_tools.sh index 5f7d3e603783871bcd892b97fd7d4700b8a2fde7..442f5de7ede0d63f9e6e0d3ff3a425aba969cbab 100755 --- a/dev_tools.sh +++ b/dev_tools.sh @@ -15,6 +15,8 @@ function printHelp() { -h : print this help -L : (required value: true|false) : true: enable/ false: disable full log -l : (option: --clear) : --clear: clear logcat before. Otherwise just display logcat. Default: false + -n : Start nextcloud docker instance + -o : (required value: true|false) true: enable File Observer / false: disable File Observer -p : Pull database directory from device into current computer folder -s : test sync : Create 10 empty files in 'Document' folder and try to upload them "; @@ -79,7 +81,23 @@ function testSync() { adb shell am broadcast -a foundation.e.drive.action.TEST_SYNC --receiver-include-background } -while getopts acCdfhL:lps flag +function startNCDocker() { + docker run -d -p 8080:80 -e NEXTCLOUD_TRUSTED_DOMAINS=":8080" -e SQLITE_DATABASE=nc -e NEXTCLOUD_ADMIN_USER=admin -e NEXTCLOUD_ADMIN_PASSWORD=admin nextcloud:26 +} + +function enableFileObserver() { + if [ -z "$1" ]; then + echo "The parameter -L require a value (true|false)" + elif [ "$1" != "true" ] && [ "$1" != "false" ]; then + echo "Invalid parameter: $1. You need to provide: (true|false)" + else + echo "Sending broacast with $1 as parameter" + adb shell am broadcast -a foundation.e.drive.action.ENABLE_FILE_OBSERVER --receiver-include-background --ez file_observer_enable "$1" + fi +} + + +while getopts acCdfhL:lnops flag do case "${flag}" in a) registerAccount;; @@ -90,6 +108,8 @@ do h) printHelp;; l) displayLogcat;; L) setFullLog ${OPTARG};; + n) startNCDocker;; + o) enableFileObserver ${OPTARG};; p) pullDatabase;; s) testSync;; esac