syncedFolders = RootSyncedFolderProvider.INSTANCE.getSyncedFolderRoots(getApplicationContext());
- CommonUtils.registerInitializationWorkers(syncedFolders, WorkManager.getInstance(getApplicationContext()) );
- }
-
- @Nullable
- @Override
- public IBinder onBind(@Nullable Intent intent) {
- return null;
- }
-}
\ 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 8b1d6747c01413d0dd5d87d276e4be22f200eb89..813b02b954fabea1519dcd631149e109057dab1e 100644
--- a/app/src/main/java/foundation/e/drive/services/ObserverService.java
+++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java
@@ -9,7 +9,7 @@
package foundation.e.drive.services;
-import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE;
+import static foundation.e.drive.utils.AppConstants.SETUP_COMPLETED;
import android.accounts.Account;
import android.accounts.AccountManager;
@@ -36,6 +36,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import foundation.e.drive.R;
import foundation.e.drive.contentScanner.LocalContentScanner;
import foundation.e.drive.contentScanner.LocalFileLister;
import foundation.e.drive.contentScanner.RemoteContentScanner;
@@ -112,7 +113,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene
final SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
final String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, "");
- final String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, "");
+ final String accountType = getApplicationContext().getString(R.string.eelo_account_type);
this.mAccount = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this));
forcedSync = intent != null && DebugCmdReceiver.ACTION_FORCE_SYNC.equals(intent.getAction());
@@ -150,10 +151,8 @@ public class ObserverService extends Service implements OnRemoteOperationListene
return false;
}
- if (!prefs.getBoolean(INITIALIZATION_HAS_BEEN_DONE, false)) {
- Timber.d("Initialization hasn't been done");
- Intent initializerIntent = new Intent(this, InitializerService.class);
- startService(initializerIntent);
+ if (!prefs.getBoolean(SETUP_COMPLETED, false)) {
+ Timber.d("setup hasn't been done");
return false;
}
diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java
index 11f6c7f0083f80b049ae7b5165c1987e89b0437b..08b7f76c44c8d2ed7ff878cddb12be19fd7da4ec 100644
--- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java
+++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
+import foundation.e.drive.R;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.database.FailedSyncPrefsManager;
import foundation.e.drive.models.SyncRequest;
@@ -78,7 +79,7 @@ public class SynchronizationService extends Service implements OnRemoteOperation
final SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
final String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, "");
- final String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, "");
+ final String accountType = getApplicationContext().getString(R.string.eelo_account_type);
account = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this));
if (account == null) {
diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.kt b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt
index fbf2dc62be05f4b615aeb72e19d59a7017970890..49d2b5d636b20375ac27eb63fd22fd116083d35c 100644
--- a/app/src/main/java/foundation/e/drive/utils/AppConstants.kt
+++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt
@@ -22,7 +22,7 @@ object AppConstants {
const val SETTINGS_SYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.SettingsSyncProvider"
const val METERED_NETWORK_ALLOWED_AUTHORITY =
"foundation.e.drive.providers.MeteredConnectionAllowedProvider"
- const val INITIALIZATION_HAS_BEEN_DONE = "initService_has_run"
+ const val SETUP_COMPLETED = "initService_has_run"
const val INITIAL_FOLDER_NUMBER = "initial_folder_number"
const val APPLICATIONS_LIST_FILE_NAME = "packages_list.csv"
const val SHARED_PREFERENCE_NAME = "preferences"
diff --git a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java
index b5eb5fe5524f1c641f7e308bdb33a41150a73788..1d6ec907f01c140beead7dce0c18e6a17865cbf0 100644
--- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java
+++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java
@@ -200,44 +200,6 @@ public abstract class CommonUtils {
return String.format(Locale.ENGLISH, "%.1f %cB", value / 1024.0, ci.current());
}
- /**
- * This method create a chain of WorkRequests to perform Initialization tasks:
- * Firstly, it creates WorkRequest to create remote root folders on ecloud
- * Then, once all folders are present on cloud, run the FirstStartWorker.
- *
- * in details:
- * - Create 9 remote folders on ecloud
- * - Run a first fullscan (ObserverService)
- * - start SynchronizationService
- * - Active FileObserver
- * - Schedule periodic fullscan.
- *
- * @param syncedFolders List of SyncedFolder for which we want to create a remote folder on ecloud
- * @param workManager WorkManager instance to register WorkRequest
- */
- public static void registerInitializationWorkers(@Nullable List syncedFolders, @NonNull WorkManager workManager) {
- if (syncedFolders == null || syncedFolders.isEmpty()) {
- Timber.d("registerInitializationWorkers: Can't create remote folders. List is empty");
- return;
- }
-
- final OneTimeWorkRequest getUserInfoRequest = WorkRequestFactory.getOneTimeWorkRequest(WorkRequestFactory.WorkType.ONE_TIME_USER_INFO, null);
-
- final List workRequests = new ArrayList<>();
- for (SyncedFolder folder : syncedFolders) {
- final OneTimeWorkRequest createRemoteFolderWorkRequest = WorkRequestFactory.getOneTimeWorkRequest(WorkRequestFactory.WorkType.CREATE_REMOTE_DIR, folder);
- workRequests.add(createRemoteFolderWorkRequest);
- }
-
- final OneTimeWorkRequest firstStartRequest = WorkRequestFactory.getOneTimeWorkRequest(WorkRequestFactory.WorkType.FIRST_START, null);
-
- workManager.beginWith(getUserInfoRequest)
- .then(workRequests)
- .then(firstStartRequest)
- .enqueue();
- }
-
-
public static void createNotificationChannel(@NonNull Context context) {
final CharSequence name = context.getString(R.string.notif_channel_name);
final String description = context.getString(R.string.notif_channel_description);
diff --git a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java
index 58e3669cf1468cd05a8159cca637076ae48471e2..aaf7f8e5ca345856b8fda4cb1c326c02a4d1afab 100644
--- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java
+++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java
@@ -49,7 +49,7 @@ public class FirstStartWorker extends Worker {
appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME,
Context.MODE_PRIVATE)
.edit()
- .putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, true)
+ .putBoolean(AppConstants.SETUP_COMPLETED, true)
.putInt(INITIAL_FOLDER_NUMBER, 9)
.apply();
diff --git a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java b/app/src/main/java/foundation/e/drive/work/RootFolderSetupWorker.java
similarity index 91%
rename from app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java
rename to app/src/main/java/foundation/e/drive/work/RootFolderSetupWorker.java
index d24339508794fdac4d5bf47fe3a672d49cbd2db4..8ff54f22354017e337a2c49519737a3b8c39f5a9 100644
--- a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java
+++ b/app/src/main/java/foundation/e/drive/work/RootFolderSetupWorker.java
@@ -25,6 +25,7 @@ import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
import java.io.File;
+import foundation.e.drive.R;
import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.utils.AppConstants;
@@ -33,11 +34,13 @@ import foundation.e.drive.utils.DavClientProvider;
import timber.log.Timber;
/**
- * /!\ Doesn't require NextcloudClient yet
* Create folder on ecloud for a given local folder
+ * Then register it in the database
+ *
+ * /i\ Doesn't require NextcloudClient yet
* @author Vincent Bourgmayer
*/
-public class CreateRemoteFolderWorker extends Worker {
+public class RootFolderSetupWorker extends Worker {
public static final String DATA_KEY_ID="id";
public static final String DATA_KEY_LIBELLE="libelle";
public static final String DATA_KEY_LOCAL_PATH="localPath";
@@ -49,9 +52,9 @@ public class CreateRemoteFolderWorker extends Worker {
public static final String DATA_KEY_ENABLE="enable";
public static final String DATA_KEY_MEDIATYPE="mediaType";
- public CreateRemoteFolderWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
+ public RootFolderSetupWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
- Timber.tag(CreateRemoteFolderWorker.class.getSimpleName());
+ Timber.tag(RootFolderSetupWorker.class.getSimpleName());
}
@NonNull
@@ -131,9 +134,9 @@ public class CreateRemoteFolderWorker extends Worker {
private Account getAccount() {
final SharedPreferences prefs = getApplicationContext().getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
final String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, "");
- final String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, "");
+ final String accountType = getApplicationContext().getString(R.string.eelo_account_type);
- if (accountName.isEmpty() && accountType.isEmpty()) return null;
+ if (accountName.isEmpty()) return null;
return CommonUtils.getAccount(accountName, accountType, AccountManager.get(getApplicationContext()));
}
}
diff --git a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java
index 58c87d75572934077c630a43fdcab32ba3681f54..0bef2fd5cd524958f5861cea2d7f6e8c5a4fed01 100644
--- a/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java
+++ b/app/src/main/java/foundation/e/drive/work/WorkRequestFactory.java
@@ -8,16 +8,16 @@
package foundation.e.drive.work;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_ENABLE;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_ID;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_LAST_ETAG;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_LAST_MODIFIED;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_LIBELLE;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_LOCAL_PATH;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_MEDIATYPE;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_REMOTE_PATH;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_SCAN_LOCAL;
-import static foundation.e.drive.work.CreateRemoteFolderWorker.DATA_KEY_SCAN_REMOTE;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_ENABLE;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_ID;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_LAST_ETAG;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_LAST_MODIFIED;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_LIBELLE;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_LOCAL_PATH;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_MEDIATYPE;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_REMOTE_PATH;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_SCAN_LOCAL;
+import static foundation.e.drive.work.RootFolderSetupWorker.DATA_KEY_SCAN_REMOTE;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -183,7 +183,7 @@ public class WorkRequestFactory {
final Constraints constraints = createUnmeteredNetworkAndHighBatteryConstraints();
return new OneTimeWorkRequest.Builder(
- CreateRemoteFolderWorker.class)
+ RootFolderSetupWorker.class)
.setBackoffCriteria(BackoffPolicy.LINEAR, 2, TimeUnit.MINUTES)
.setInputData(createDataFromSyncedFolder(syncedFolder))
.addTag(AppConstants.WORK_GENERIC_TAG)
diff --git a/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java b/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java
index c7b695cbaff9dd52c57e1de54b542e46877bb731..998157602efeb7a6b112107d884f02aedf119506 100644
--- a/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java
+++ b/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java
@@ -111,7 +111,7 @@ public abstract class AbstractServiceIT {
* So update the field before to call this to store specific value
*/
protected void registerSharedPref(){
- sharedPreferences.edit().putBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, init_done)
+ sharedPreferences.edit().putBoolean( AppConstants.SETUP_COMPLETED, init_done)
.putString(AccountManager.KEY_ACCOUNT_NAME, TEST_ACCOUNT_NAME)
.putString(AccountManager.KEY_ACCOUNT_TYPE, TEST_ACCOUNT_TYPE)
.putInt(AppConstants.INITIAL_FOLDER_NUMBER, initial_folder_number)
diff --git a/app/src/test/java/foundation/e/drive/services/InitializerServiceTest.java b/app/src/test/java/foundation/e/drive/services/InitializerServiceTest.java
deleted file mode 100644
index ca5febde32ca4d45688701e970af2035ffb5371b..0000000000000000000000000000000000000000
--- a/app/src/test/java/foundation/e/drive/services/InitializerServiceTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package foundation.e.drive.services;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import android.accounts.AccountManager;
-import android.app.job.JobScheduler;
-import android.content.Context;
-import android.net.ConnectivityManager;
-
-import androidx.test.core.app.ApplicationProvider;
-import org.junit.Test;
-import org.robolectric.Robolectric;
-
-import foundation.e.drive.TestUtils;
-import foundation.e.drive.database.DbHelper;
-import foundation.e.drive.utils.AppConstants;
-
-public class InitializerServiceTest extends AbstractServiceIT{
-
- public InitializerServiceTest(){
- mServiceController = Robolectric.buildService(InitializerService.class);
- mService = mServiceController.get();
- context = ApplicationProvider.getApplicationContext();
- accountManager = AccountManager.get(context);
- jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
- contentResolver = context.getContentResolver();
- sharedPreferences = context.getSharedPreferences( AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
- connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- dbHelper = new DbHelper(context);
- TestUtils.initializeWorkmanager(context);
- init_done = false;
- TestUtils.loadServerCredentials();
- TestUtils.prepareValidAccount(accountManager);
- }
-
- @Test
- public void checkStartConditions_noAccountInIntent_NorInPrefs_falseExpected() {
- registerSharedPref();
- final boolean canStart = mService.checkStartConditions(sharedPreferences, "", "");
- assertFalse("InitializerService.checkStartConditions without any available account info should return false but returned true", canStart);
- }
-
- @Test
- public void checkStartConditions_trueExpected() {
- registerSharedPref();
- final boolean canStart = mService.checkStartConditions(sharedPreferences, TestUtils.TEST_ACCOUNT_NAME, TestUtils.TEST_ACCOUNT_TYPE);
- assertTrue("InitializerService.checkStartConditions with invalid account should return false but returned true", canStart);
- }
-
- @Test
- public void checkStartConditions_withFakeAccountNameOrType_falseExpected() {
- registerSharedPref();
- final boolean canStart = mService.checkStartConditions(sharedPreferences, "any", "any");
- assertFalse("InitializerService.checkStartConditions with invalid account should return false but returned true", canStart);
- }
-
- @Test
- public void checkStartConditions_withInitDone_falseExpected() {
- registerSharedPref();
- sharedPreferences.edit().putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, true).apply();
- final boolean canStart = mService.checkStartConditions(sharedPreferences, TestUtils.TEST_ACCOUNT_NAME, TestUtils.TEST_ACCOUNT_TYPE);
- assertFalse("InitializerService.checkStartConditions with valid account but init already done should return false but returned true", canStart);
- }
-}
diff --git a/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java b/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java
index bb9ff1ad2c6988ca46ed7dd90a86752dc151e2b1..e9a9b7076c0f23c54de138250b055d9f61ca5144 100644
--- a/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java
+++ b/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java
@@ -3,7 +3,6 @@ package foundation.e.drive.services;
import android.accounts.AccountManager;
import android.app.job.JobScheduler;
import android.content.Context;
-import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -19,7 +18,6 @@ import org.robolectric.shadows.ShadowLog;
import org.robolectric.shadows.ShadowNetworkInfo;
import java.io.File;
-import android.net.Uri;
import java.util.List;
import foundation.e.drive.TestUtils;
@@ -32,7 +30,7 @@ import foundation.e.drive.utils.CommonUtils;
import static foundation.e.drive.TestUtils.TEST_LOCAL_ROOT_FOLDER_PATH;
import static foundation.e.drive.TestUtils.TEST_REMOTE_ROOT_FOLDER_PATH;
import static foundation.e.drive.TestUtils.getValidAccount;
-import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE;
+import static foundation.e.drive.utils.AppConstants.SETUP_COMPLETED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -187,8 +185,6 @@ public class ObserverServiceTest extends AbstractServiceIT {
//Start the service
mServiceController.create().startCommand(0, 0);
- //How to assert this... ?
-
List logs = ShadowLog.getLogs();
ShadowLog.LogItem lastLog = logs.get(logs.size()-1);
@@ -253,25 +249,18 @@ public class ObserverServiceTest extends AbstractServiceIT {
*/
@Ignore("Binding to synchronizationService make test fails")
@Test
- public void InitializationNotDone_shouldStop() {
+ public void setupNotDone_shouldStop() {
init_done = false; //This is the key settings for this test
-
setWifiNetworkStatus();
prepareValidAccount();
enableMediaAndSettingsSync(getValidAccount());
registerSharedPref();
-
- assertFalse("SharedPref doesn't contains the expected value for Initialization_has_been_done key", sharedPreferences.getBoolean(INITIALIZATION_HAS_BEEN_DONE, true));
+ assertFalse("SharedPref doesn't contains the expected value for Initialization_has_been_done key", sharedPreferences.getBoolean(SETUP_COMPLETED, true));
mServiceController.create().startCommand(0, 0);
//How to assert this... ?
- Intent expectedIntent = new Intent(mService, InitializerService.class);
- Intent actualIntent = shadowOf(RuntimeEnvironment.application).getNextStartedService();
-
- assertEquals("Checked intent not the expected one", expectedIntent.getComponent(), actualIntent.getComponent());
-
List logs = ShadowLog.getLogs();
ShadowLog.LogItem lastLog = logs.get(logs.size()-1);