From bba7365aaf4e6a05be352ca787e8f9c862809005 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 16 Oct 2023 14:59:09 +0200 Subject: [PATCH 1/9] create new package: foundation.e.drive.account.receivers moved accountRemoveCallbackReceivers into the new package --- app/src/main/AndroidManifest.xml | 2 +- .../{ => account}/receivers/AccountRemoveCallbackReceiver.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/src/main/java/foundation/e/drive/{ => account}/receivers/AccountRemoveCallbackReceiver.java (99%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ec966a21..5a7e544b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -115,7 +115,7 @@ - diff --git a/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java similarity index 99% rename from app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java rename to app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java index fc7293f7..2826721f 100644 --- a/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java @@ -6,7 +6,7 @@ * http://www.gnu.org/licenses/gpl.html */ -package foundation.e.drive.receivers; +package foundation.e.drive.account.receivers; import static foundation.e.drive.utils.AppConstants.INITIAL_FOLDER_NUMBER; import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE; -- GitLab From e06ba3a67726afd54fd63d5d5e8fffb070122803 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 16 Oct 2023 15:15:01 +0200 Subject: [PATCH 2/9] implement AccountAddedReceiver Add signature & receiver declaration in AndroidManifest.xml Move method which register setup workers from commonUtils into new receiver --- app/src/main/AndroidManifest.xml | 12 ++ .../account/receivers/AccountAddedReceiver.kt | 134 ++++++++++++++++++ .../foundation/e/drive/utils/CommonUtils.java | 38 ----- 3 files changed, 146 insertions(+), 38 deletions(-) create mode 100644 app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5a7e544b..4c7ebc2d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,6 +28,9 @@ android:protectionLevel="signature" tools:ignore="ReservedSystemPermission" /> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt new file mode 100644 index 00000000..cfce3cd2 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt @@ -0,0 +1,134 @@ +/* + * Copyright © MURENA SAS 2023. + * 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.account.receivers + +import android.accounts.AccountManager +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import androidx.work.OneTimeWorkRequest +import androidx.work.WorkManager +import foundation.e.drive.R +import foundation.e.drive.models.SyncedFolder +import foundation.e.drive.utils.AppConstants +import foundation.e.drive.utils.CommonUtils +import foundation.e.drive.utils.DavClientProvider +import foundation.e.drive.utils.RootSyncedFolderProvider +import foundation.e.drive.work.WorkRequestFactory.* +import timber.log.Timber + +/** + * Entry point for eDrive + * Triggered by AccountManager + * @author Vincent Bourgmayer + */ +class AccountAddedReceiver() : BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + Timber.d("\"Account added\" intent received") + + if (context == null || intent == null || intent.extras == null) return + + val accountName = intent.extras!!.getString(AccountManager.KEY_ACCOUNT_NAME, "") + val accountType = intent.extras!!.getString(AccountManager.KEY_ACCOUNT_TYPE, "") + val prefs = context.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, + Context.MODE_PRIVATE) + + if (!canStart(accountName, accountType, prefs, context)) return + + if (registerSetupWorkers(context)) { + prefs.edit() + .putString(AccountManager.KEY_ACCOUNT_NAME, accountName) + .apply() + + DavClientProvider.getInstance().cleanUp() + + CommonUtils.registerPeriodicUserInfoChecking(WorkManager.getInstance(context)) + } +} + + + /** + * Check that conditions to start are met: + * - Setup has not already been done + * - AccountName is not empty + * - AccountType is /e/ account + * - the account is effectively available through accountManager + */ + private fun canStart( + accountName: String?, + accountType: String?, + prefs: SharedPreferences, + context: Context + ): Boolean { + if (isSetupAlreadyDone(prefs)) { + return false + } + + if (accountName.isNullOrEmpty()) { + return false + } + + if (isInvalidAccountType(accountType, context)) { + return false + } + + if (isExistingAccount(accountName, accountType!!, context)) { + Timber.w("No account exist for username: %s ", accountType, accountName) + return false + } + return true + } + + private fun isInvalidAccountType(accountType: String?, context: Context): Boolean { + val validAccountType = context.getString(R.string.eelo_account_type) + return accountType != validAccountType + } + + private fun isSetupAlreadyDone(prefs: SharedPreferences): Boolean { + return prefs.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false) + } + + private fun isExistingAccount(accountName: String, accountType: String, context: Context): Boolean { + val account = CommonUtils.getAccount(accountName, accountType, AccountManager.get(context)) + return account != null + } + + private fun registerSetupWorkers(context: Context): Boolean { + val rootFolderSetupWorkers = generateRootFolderSetupWorkers(context) ?: return false + val getUserInfoRequest = getOneTimeWorkRequest(WorkType.ONE_TIME_USER_INFO,null) + val firstStartRequest = getOneTimeWorkRequest(WorkType.FIRST_START, null) + + val workManager = WorkManager.getInstance(context) + + workManager.beginWith(getUserInfoRequest) + .then(rootFolderSetupWorkers) + .then(firstStartRequest) + .enqueue() + return true + } + + private fun generateRootFolderSetupWorkers(context: Context): MutableList? { + val rootSyncedFolderList: List = + RootSyncedFolderProvider.getSyncedFolderRoots(context) + + if(rootSyncedFolderList.isNullOrEmpty()) { + return null + } + + val workRequests: MutableList = ArrayList() + for (folder in rootSyncedFolderList) { + val createRemoteFolderWorkRequest = getOneTimeWorkRequest( + WorkType.CREATE_REMOTE_DIR, + folder + ) + workRequests.add(createRemoteFolderWorkRequest) + } + return workRequests + } +} \ No newline at end of file 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 b5eb5fe5..1d6ec907 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); -- GitLab From ae72ed206451ac9a5d73f971919df681ef6868cc Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 16 Oct 2023 17:53:10 +0200 Subject: [PATCH 3/9] remove InitializerService.java --- app/src/main/AndroidManifest.xml | 11 -- .../AccountRemoveCallbackReceiver.java | 5 - .../receivers/BootCompletedReceiver.java | 16 +-- .../e/drive/services/InitializerService.java | 123 ------------------ .../e/drive/services/ObserverService.java | 4 +- .../services/InitializerServiceTest.java | 65 --------- .../e/drive/services/ObserverServiceTest.java | 13 +- 7 files changed, 6 insertions(+), 231 deletions(-) delete mode 100644 app/src/main/java/foundation/e/drive/services/InitializerService.java delete mode 100644 app/src/test/java/foundation/e/drive/services/InitializerServiceTest.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4c7ebc2d..177f5488 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -83,17 +83,6 @@ android:exported="true" android:label="@string/account_setting_metered_network" tools:ignore="ExportedContentProvider" /> - - - - - - - diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java index 2826721f..38adbc61 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java @@ -26,7 +26,6 @@ import java.io.File; import foundation.e.drive.EdriveApplication; import foundation.e.drive.database.DbHelper; import foundation.e.drive.database.FailedSyncPrefsManager; -import foundation.e.drive.services.InitializerService; import foundation.e.drive.services.ObserverService; import foundation.e.drive.services.SynchronizationService; import foundation.e.drive.utils.AppConstants; @@ -100,10 +99,6 @@ public class AccountRemoveCallbackReceiver extends BroadcastReceiver { boolean observerServiceStopResult = applicationContext.stopService(observerServiceIntent); Timber.d("stop ObserverService: %s", observerServiceStopResult); - Intent initializerServiceIntent = new Intent(applicationContext, InitializerService.class); - boolean initServiceStopResult = applicationContext.stopService(initializerServiceIntent); - Timber.d("stop InitializerService: %s", initServiceStopResult); - Intent synchronizationServiceIntent = new Intent(applicationContext, SynchronizationService.class); boolean syncServiceStopResult = applicationContext.stopService(synchronizationServiceIntent); Timber.d("stop SynchronizationService: %s", syncServiceStopResult); diff --git a/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java b/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java index 12593bee..6f671bba 100644 --- a/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java @@ -18,7 +18,6 @@ import androidx.annotation.NonNull; import foundation.e.drive.BuildConfig; import foundation.e.drive.database.DbHelper; -import foundation.e.drive.services.InitializerService; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import timber.log.Timber; @@ -39,8 +38,8 @@ public class BootCompletedReceiver extends BroadcastReceiver { if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { final String currentDateProp = CommonUtils.getProp(DATE_SYSTEM_PROPERTY); - if (isOsUpdated(pref, currentDateProp)) { // App is persistent and system so do not have classical update - handleOsUpdate(pref, context, currentDateProp); + if (isOsUpdated(pref, currentDateProp)) { // App is persistent so can only be updated (by replacement) on OS update + handleOsUpdate(context ); } if (pref.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false) @@ -62,17 +61,10 @@ public class BootCompletedReceiver extends BroadcastReceiver { /** * Force reinitialization, upgrade of DB in case of OS update - * - * @param prefs SharedPreferences to extract last known build date + * todo remove when setPersistentFlag=true will be removed * @param context Context used to start InitializationService - * @param currentDateProp new build date */ - private void handleOsUpdate(@NonNull SharedPreferences prefs, @NonNull Context context, @NonNull String currentDateProp) { - prefs.edit().putString(DATE_SYSTEM_PROPERTY, currentDateProp) - .putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false) - .apply(); - - context.startService(new Intent(context, InitializerService.class)); + private void handleOsUpdate(@NonNull Context context) { forceDBUpdate(context); } diff --git a/app/src/main/java/foundation/e/drive/services/InitializerService.java b/app/src/main/java/foundation/e/drive/services/InitializerService.java deleted file mode 100644 index cafe34ff..00000000 --- a/app/src/main/java/foundation/e/drive/services/InitializerService.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright © CLEUS SAS 2018-2019. - * Copyright © ECORP SAS 2022-2023. - * 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.services; - -import android.accounts.Account; -import android.accounts.AccountManager; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.IBinder; - -import java.io.File; -import java.util.List; - -import foundation.e.drive.models.SyncedFolder; -import foundation.e.drive.utils.AppConstants; -import foundation.e.drive.utils.CommonUtils; -import foundation.e.drive.utils.DavClientProvider; -import foundation.e.drive.utils.RootSyncedFolderProvider; -import timber.log.Timber; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; -import androidx.work.WorkManager; - -/** - * @author Vincent Bourgmayer - * @author Jonathan Klee - * @author Abhishek Aggarwal - */ -public class InitializerService extends Service { - private Account account; - - @Override - public void onCreate() { - Timber.tag(InitializerService.class.getSimpleName()); - super.onCreate(); - } - - @Override - public int onStartCommand(@Nullable Intent intent, int flags, int startId) { - Timber.i("onStartCommand()"); - DavClientProvider.getInstance().cleanUp(); - CommonUtils.setServiceUnCaughtExceptionHandler(this); - - //Get account - final SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); - - String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); - String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, ""); - - if (accountName.isEmpty() && accountType.isEmpty() && intent != null && intent.getExtras() != null) { - - accountName = intent.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME, ""); - accountType = intent.getExtras().getString(AccountManager.KEY_ACCOUNT_TYPE, ""); - - prefs.edit().putString(AccountManager.KEY_ACCOUNT_NAME, accountName) - .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType) - .apply(); - } - - if (checkStartConditions(prefs, accountName, accountType)) { - start(); - } - return super.onStartCommand(intent, flags, startId); - } - - /** - * Check if condition are present to start - * - Initialization not already done - * - AccountName is not empty - * - Account available - * @return true if condition are met - */ - @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - public boolean checkStartConditions(@NonNull final SharedPreferences prefs, - @NonNull final String accountName, @NonNull final String accountType) { - if (prefs.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false)) { - Timber.w("Initialization has already been done"); - return false; - } - - if (accountName.isEmpty()) { - Timber.w("No account Name available"); - return false; - } - - account = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this)); - if (account == null) { - Timber.w("got Invalid %s account for username: %s ", accountType, accountName); - return false; - } - return true; - } - - /** - * Set up base component for eDrive: - * - Register basic worker - * - build root folders to sync - */ - private void start() { - Timber.d("start()"); - CommonUtils.registerPeriodicUserInfoChecking(WorkManager.getInstance(this)); - - final List 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 8b1d6747..64c69e12 100644 --- a/app/src/main/java/foundation/e/drive/services/ObserverService.java +++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java @@ -151,9 +151,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene } if (!prefs.getBoolean(INITIALIZATION_HAS_BEEN_DONE, false)) { - Timber.d("Initialization hasn't been done"); - Intent initializerIntent = new Intent(this, InitializerService.class); - startService(initializerIntent); + Timber.d("setup hasn't been done"); return false; } 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 ca5febde..00000000 --- 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 bb9ff1ad..68ff9f36 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; @@ -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)); 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); -- GitLab From f48cb782657ac41ed8c0573dee3bac107e3d993d Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 16 Oct 2023 18:01:44 +0200 Subject: [PATCH 4/9] rename CreateRemoteFolderWorker into RootFolderSetupWorker for better meanings --- ...Worker.java => RootFolderSetupWorker.java} | 10 +++++---- .../e/drive/work/WorkRequestFactory.java | 22 +++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) rename app/src/main/java/foundation/e/drive/work/{CreateRemoteFolderWorker.java => RootFolderSetupWorker.java} (94%) 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 94% 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 d2433950..8e4fdd1a 100644 --- a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java +++ b/app/src/main/java/foundation/e/drive/work/RootFolderSetupWorker.java @@ -33,11 +33,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 +51,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 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 58c87d75..0bef2fd5 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) -- GitLab From 275ef42359546a8e34889f4eb56d9b0b3ac8da82 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Mon, 16 Oct 2023 18:08:18 +0200 Subject: [PATCH 5/9] rename app constant INITIALIZATION_HAS_BEEN_DONE into SETUP_COMPLETED --- .../e/drive/account/receivers/AccountAddedReceiver.kt | 2 +- .../account/receivers/AccountRemoveCallbackReceiver.java | 4 ++-- .../foundation/e/drive/receivers/BootCompletedReceiver.java | 2 +- .../java/foundation/e/drive/services/ObserverService.java | 4 ++-- app/src/main/java/foundation/e/drive/utils/AppConstants.kt | 2 +- .../main/java/foundation/e/drive/work/FirstStartWorker.java | 2 +- .../java/foundation/e/drive/services/AbstractServiceIT.java | 2 +- .../java/foundation/e/drive/services/ObserverServiceTest.java | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt index cfce3cd2..6a4e6f80 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt @@ -91,7 +91,7 @@ class AccountAddedReceiver() : BroadcastReceiver() { } private fun isSetupAlreadyDone(prefs: SharedPreferences): Boolean { - return prefs.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false) + return prefs.getBoolean(AppConstants.SETUP_COMPLETED, false) } private fun isExistingAccount(accountName: String, accountType: String, context: Context): Boolean { diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java index 38adbc61..3363425b 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountRemoveCallbackReceiver.java @@ -9,7 +9,7 @@ package foundation.e.drive.account.receivers; import static foundation.e.drive.utils.AppConstants.INITIAL_FOLDER_NUMBER; -import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE; +import static foundation.e.drive.utils.AppConstants.SETUP_COMPLETED; import android.accounts.AccountManager; import android.annotation.SuppressLint; @@ -109,7 +109,7 @@ public class AccountRemoveCallbackReceiver extends BroadcastReceiver { //If removal failed, clear all data inside prefs.edit().remove(AccountManager.KEY_ACCOUNT_NAME) .remove(AccountManager.KEY_ACCOUNT_TYPE) - .remove(INITIALIZATION_HAS_BEEN_DONE) + .remove(SETUP_COMPLETED) .remove(INITIAL_FOLDER_NUMBER) .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); diff --git a/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java b/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java index 6f671bba..e27bd9f1 100644 --- a/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java @@ -42,7 +42,7 @@ public class BootCompletedReceiver extends BroadcastReceiver { handleOsUpdate(context ); } - if (pref.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false) + if (pref.getBoolean(AppConstants.SETUP_COMPLETED, false) && BuildConfig.VERSION_CODE > pref.getInt(PREF_VERSION_CODE, 1002000)) { pref.edit().putInt(PREF_VERSION_CODE, BuildConfig.VERSION_CODE).apply(); try { 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 64c69e12..cee1cab6 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; @@ -150,7 +150,7 @@ public class ObserverService extends Service implements OnRemoteOperationListene return false; } - if (!prefs.getBoolean(INITIALIZATION_HAS_BEEN_DONE, false)) { + 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/utils/AppConstants.kt b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt index fbf2dc62..49d2b5d6 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/work/FirstStartWorker.java b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java index 58e3669c..aaf7f8e5 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/test/java/foundation/e/drive/services/AbstractServiceIT.java b/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java index c7b695cb..99815760 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/ObserverServiceTest.java b/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java index 68ff9f36..e9a9b707 100644 --- a/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java +++ b/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java @@ -30,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; @@ -256,7 +256,7 @@ public class ObserverServiceTest extends AbstractServiceIT { 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... ? -- GitLab From 61acf1e75840abe721affd0b21b23a48082f6ca7 Mon Sep 17 00:00:00 2001 From: Vincent Bourgmayer Date: Tue, 17 Oct 2023 07:12:45 +0000 Subject: [PATCH 6/9] Apply 5 suggestion(s) to 2 file(s) --- .../e/drive/account/receivers/AccountAddedReceiver.kt | 10 +++++----- .../e/drive/receivers/BootCompletedReceiver.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt index 6a4e6f80..41fd5c46 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt @@ -34,8 +34,9 @@ class AccountAddedReceiver() : BroadcastReceiver() { if (context == null || intent == null || intent.extras == null) return - val accountName = intent.extras!!.getString(AccountManager.KEY_ACCOUNT_NAME, "") - val accountType = intent.extras!!.getString(AccountManager.KEY_ACCOUNT_TYPE, "") + val extras = intent.extras!! + val accountName = extras.getString(AccountManager.KEY_ACCOUNT_NAME, "") + val accountType = extras.getString(AccountManager.KEY_ACCOUNT_TYPE, "") val prefs = context.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE) @@ -52,7 +53,6 @@ class AccountAddedReceiver() : BroadcastReceiver() { } } - /** * Check that conditions to start are met: * - Setup has not already been done @@ -101,7 +101,7 @@ class AccountAddedReceiver() : BroadcastReceiver() { private fun registerSetupWorkers(context: Context): Boolean { val rootFolderSetupWorkers = generateRootFolderSetupWorkers(context) ?: return false - val getUserInfoRequest = getOneTimeWorkRequest(WorkType.ONE_TIME_USER_INFO,null) + val getUserInfoRequest = getOneTimeWorkRequest(WorkType.ONE_TIME_USER_INFO, null) val firstStartRequest = getOneTimeWorkRequest(WorkType.FIRST_START, null) val workManager = WorkManager.getInstance(context) @@ -117,7 +117,7 @@ class AccountAddedReceiver() : BroadcastReceiver() { val rootSyncedFolderList: List = RootSyncedFolderProvider.getSyncedFolderRoots(context) - if(rootSyncedFolderList.isNullOrEmpty()) { + if (rootSyncedFolderList.isNullOrEmpty()) { return null } diff --git a/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java b/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java index e27bd9f1..ce806ce1 100644 --- a/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/BootCompletedReceiver.java @@ -39,7 +39,7 @@ public class BootCompletedReceiver extends BroadcastReceiver { final String currentDateProp = CommonUtils.getProp(DATE_SYSTEM_PROPERTY); if (isOsUpdated(pref, currentDateProp)) { // App is persistent so can only be updated (by replacement) on OS update - handleOsUpdate(context ); + handleOsUpdate(context); } if (pref.getBoolean(AppConstants.SETUP_COMPLETED, false) -- GitLab From 8de72d8ccb2c3260e3fa9e0de7c0a3ec7eb1f33b Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 17 Oct 2023 09:29:16 +0200 Subject: [PATCH 7/9] apply jonathan's suggestion --- .../e/drive/account/receivers/AccountAddedReceiver.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt index 41fd5c46..ece24aef 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt @@ -61,8 +61,8 @@ class AccountAddedReceiver() : BroadcastReceiver() { * - the account is effectively available through accountManager */ private fun canStart( - accountName: String?, - accountType: String?, + accountName: String, + accountType: String, prefs: SharedPreferences, context: Context ): Boolean { @@ -70,7 +70,7 @@ class AccountAddedReceiver() : BroadcastReceiver() { return false } - if (accountName.isNullOrEmpty()) { + if (accountName.isEmpty()) { return false } @@ -78,14 +78,14 @@ class AccountAddedReceiver() : BroadcastReceiver() { return false } - if (isExistingAccount(accountName, accountType!!, context)) { + if (isExistingAccount(accountName, accountType, context)) { Timber.w("No account exist for username: %s ", accountType, accountName) return false } return true } - private fun isInvalidAccountType(accountType: String?, context: Context): Boolean { + private fun isInvalidAccountType(accountType: String, context: Context): Boolean { val validAccountType = context.getString(R.string.eelo_account_type) return accountType != validAccountType } -- GitLab From 3533ea8cb0ceeae96ac7440bae4cec52980d7ff1 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 17 Oct 2023 11:12:20 +0200 Subject: [PATCH 8/9] fix inversed if statement --- .../e/drive/account/receivers/AccountAddedReceiver.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt index ece24aef..96fef991 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt @@ -40,6 +40,8 @@ class AccountAddedReceiver() : BroadcastReceiver() { val prefs = context.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE) + Timber.d("AccountAddedReceiver.onReceive with name: %s and type: %s", accountName, accountType) + if (!canStart(accountName, accountType, prefs, context)) return if (registerSetupWorkers(context)) { @@ -78,7 +80,7 @@ class AccountAddedReceiver() : BroadcastReceiver() { return false } - if (isExistingAccount(accountName, accountType, context)) { + if (!isExistingAccount(accountName, accountType, context)) { Timber.w("No account exist for username: %s ", accountType, accountName) return false } -- GitLab From 68f88e074fc4241c63e3c065348455c8a482ccde Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 17 Oct 2023 11:44:45 +0200 Subject: [PATCH 9/9] reorder some instruction in accountAddedReceiver & fix way to get account in other component --- .../e/drive/account/receivers/AccountAddedReceiver.kt | 8 ++++---- .../java/foundation/e/drive/services/ObserverService.java | 3 ++- .../e/drive/services/SynchronizationService.java | 3 ++- .../foundation/e/drive/work/RootFolderSetupWorker.java | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt index 96fef991..f14a3e06 100644 --- a/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt +++ b/app/src/main/java/foundation/e/drive/account/receivers/AccountAddedReceiver.kt @@ -44,11 +44,11 @@ class AccountAddedReceiver() : BroadcastReceiver() { if (!canStart(accountName, accountType, prefs, context)) return - if (registerSetupWorkers(context)) { - prefs.edit() - .putString(AccountManager.KEY_ACCOUNT_NAME, accountName) - .apply() + prefs.edit() + .putString(AccountManager.KEY_ACCOUNT_NAME, accountName) + .apply() + if (registerSetupWorkers(context)) { DavClientProvider.getInstance().cleanUp() CommonUtils.registerPeriodicUserInfoChecking(WorkManager.getInstance(context)) 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 cee1cab6..813b02b9 100644 --- a/app/src/main/java/foundation/e/drive/services/ObserverService.java +++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java @@ -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()); 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 11f6c7f0..08b7f76c 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/work/RootFolderSetupWorker.java b/app/src/main/java/foundation/e/drive/work/RootFolderSetupWorker.java index 8e4fdd1a..8ff54f22 100644 --- a/app/src/main/java/foundation/e/drive/work/RootFolderSetupWorker.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; @@ -133,9 +134,9 @@ public class RootFolderSetupWorker 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())); } } -- GitLab