diff --git a/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java b/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java index c4b08a698482822f8243c684a1354ba81696746f..fc7293f74ab57c99652d53801fd0c6cb5a68a999 100644 --- a/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/AccountRemoveCallbackReceiver.java @@ -8,7 +8,7 @@ package foundation.e.drive.receivers; -import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; +import static foundation.e.drive.utils.AppConstants.INITIAL_FOLDER_NUMBER; import static foundation.e.drive.utils.AppConstants.INITIALIZATION_HAS_BEEN_DONE; import android.accounts.AccountManager; @@ -115,7 +115,7 @@ public class AccountRemoveCallbackReceiver extends BroadcastReceiver { prefs.edit().remove(AccountManager.KEY_ACCOUNT_NAME) .remove(AccountManager.KEY_ACCOUNT_TYPE) .remove(INITIALIZATION_HAS_BEEN_DONE) - .remove(INITIALFOLDERS_NUMBER) + .remove(INITIAL_FOLDER_NUMBER) .remove(AppConstants.KEY_LAST_SYNC_TIME) .apply(); } diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.java b/app/src/main/java/foundation/e/drive/utils/AppConstants.java deleted file mode 100644 index 1c9da75aee7f025396c2f1748e07479223997536..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/drive/utils/AppConstants.java +++ /dev/null @@ -1,63 +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.utils; - -import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR; - -import android.os.Build; -import android.os.Environment; - -import java.text.SimpleDateFormat; -import java.util.Locale; - -import foundation.e.drive.BuildConfig; - -/** - * @author Vincent Bourgmayer - * @author Abhishek Aggarwal - */ -public abstract class AppConstants { - - public static final String MEDIASYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.MediasSyncProvider"; - public static final String SETTINGSYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.SettingsSyncProvider"; - public static final String METERED_NETWORK_ALLOWED_AUTHORITY = "foundation.e.drive.providers.MeteredConnectionAllowedProvider"; - public static final String INITIALIZATION_HAS_BEEN_DONE = "initService_has_run"; - public static final String INITIALFOLDERS_NUMBER = "initial_folder_number"; - public static final String APPLICATIONS_LIST_FILE_NAME = "packages_list.csv"; - public static final String SHARED_PREFERENCE_NAME = "preferences"; - public static final String KEY_LAST_SYNC_TIME = "lastSyncTimestamp"; - - public static final String ACCOUNT_DATA_NAME = "display_name"; - public static final String ACCOUNT_DATA_USED_QUOTA_KEY = "used_quota"; - public static final String ACCOUNT_DATA_TOTAL_QUOTA_KEY = "total_quota"; - public static final String ACCOUNT_DATA_RELATIVE_QUOTA_KEY = "relative_quota"; - public static final String ACCOUNT_DATA_GROUPS = "group"; - public static final String ACCOUNT_DATA_ALIAS_KEY = "alias"; - public static final String ACCOUNT_DATA_EMAIL = "email"; - public static final String ACCOUNT_USER_ID_KEY = "USERID"; - public static final String[] MEDIA_SYNCABLE_CATEGORIES = new String[]{"Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts"}; - public static final String[] SETTINGS_SYNCABLE_CATEGORIES = new String[]{"Rom settings"}; - - public static final String notificationChannelID = "foundation.e.drive"; - public static final String WORK_GENERIC_TAG = "eDrive"; - public static final String WORK_INITIALIZATION_TAG = "eDrive-init"; - public static final String USER_AGENT = "eos(" + getBuildTime() + ")-eDrive(" + BuildConfig.VERSION_NAME + ")"; - - /** - * Get a readable OS's build date String - * - * @return Os'build date - */ - private static String getBuildTime() { - long ts = Build.TIME; - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd", Locale.getDefault()); - return sdf.format(ts); - } -} diff --git a/app/src/main/java/foundation/e/drive/utils/AppConstants.kt b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt new file mode 100644 index 0000000000000000000000000000000000000000..9822b5b814fdbdd4215b8e133bf7bd60e2857202 --- /dev/null +++ b/app/src/main/java/foundation/e/drive/utils/AppConstants.kt @@ -0,0 +1,55 @@ +/* + * Copyright © CLEUS SAS 2018-2019. + * Copyright © MURENA 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.utils + +import android.os.Build +import foundation.e.drive.BuildConfig +import java.text.SimpleDateFormat +import java.util.Locale + +/** + * @author Vincent Bourgmayer + * @author Abhishek Aggarwal + */ +object AppConstants { + const val MEDIA_SYNC_PROVIDER_AUTHORITY = "foundation.e.drive.providers.MediasSyncProvider" + 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 INITIAL_FOLDER_NUMBER = "initial_folder_number" + const val APPLICATIONS_LIST_FILE_NAME = "packages_list.csv" + const val SHARED_PREFERENCE_NAME = "preferences" + const val KEY_LAST_SYNC_TIME = "lastSyncTimestamp" + const val ACCOUNT_DATA_NAME = "display_name" + const val ACCOUNT_DATA_USED_QUOTA_KEY = "used_quota" + const val ACCOUNT_DATA_TOTAL_QUOTA_KEY = "total_quota" + const val ACCOUNT_DATA_RELATIVE_QUOTA_KEY = "relative_quota" + const val ACCOUNT_DATA_GROUPS = "group" + const val ACCOUNT_DATA_ALIAS_KEY = "alias" + const val ACCOUNT_DATA_EMAIL = "email" + const val ACCOUNT_USER_ID_KEY = "USERID" + const val notificationChannelID = "foundation.e.drive" + const val WORK_GENERIC_TAG = "eDrive" + const val WORK_INITIALIZATION_TAG = "eDrive-init" + @JvmField + val USER_AGENT = "eos(" + buildTime + ")-eDrive(" + BuildConfig.VERSION_NAME + ")" + + /** + * Get a readable OS's build date String + * + * @return Os'build date + */ + private val buildTime: String + get() { + val ts = Build.TIME + val sdf = SimpleDateFormat("yyyyMMdd", Locale.getDefault()) + return sdf.format(ts) + } +} \ 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 1ffb3a1ec3c21f81e9d30dd9377b22198e1cbc65..80dc0c7352c63bb5865664ea5eb6505c5259b56a 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -44,9 +44,9 @@ import foundation.e.drive.work.AccountUserInfoWorker; import foundation.e.drive.work.WorkRequestFactory; import timber.log.Timber; -import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; +import static foundation.e.drive.utils.AppConstants.MEDIA_SYNC_PROVIDER_AUTHORITY; import static foundation.e.drive.utils.AppConstants.METERED_NETWORK_ALLOWED_AUTHORITY; -import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; +import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNC_PROVIDER_AUTHORITY; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -137,7 +137,7 @@ public abstract class CommonUtils { * @return true if media sync enabled */ public static boolean isMediaSyncEnabled(@NonNull Account account) { - return ContentResolver.getSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY); + return ContentResolver.getSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY); } /** @@ -147,7 +147,7 @@ public abstract class CommonUtils { * @return true if enabled */ public static boolean isSettingsSyncEnabled(@NonNull Account account) { - return ContentResolver.getSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY); + return ContentResolver.getSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY); } /** 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 7cdbf4f15c6eb94fde151eec34e1b7d64a148d60..0f960a4f53c9c361676631438aa9d3ea760edb4d 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -8,7 +8,7 @@ package foundation.e.drive.work; -import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; +import static foundation.e.drive.utils.AppConstants.INITIAL_FOLDER_NUMBER; import static foundation.e.drive.work.WorkRequestFactory.WorkType.ONE_TIME_APP_LIST; import static foundation.e.drive.work.WorkRequestFactory.WorkType.PERIODIC_SCAN; @@ -49,7 +49,7 @@ public class FirstStartWorker extends Worker { Context.MODE_PRIVATE) .edit() .putBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, true) - .putInt(INITIALFOLDERS_NUMBER, 9) + .putInt(INITIAL_FOLDER_NUMBER, 9) .apply(); registerPeriodicWork(appContext); 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 6d82245a0670453fa0fc91a32656ab1f9f22b093..c7b695cbaff9dd52c57e1de54b542e46877bb731 100644 --- a/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java +++ b/app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java @@ -22,8 +22,8 @@ import foundation.e.drive.database.DbHelper; import foundation.e.drive.utils.AppConstants; import static foundation.e.drive.TestUtils.TEST_ACCOUNT_NAME; import static foundation.e.drive.TestUtils.TEST_ACCOUNT_TYPE; -import static foundation.e.drive.utils.AppConstants.MEDIASYNC_PROVIDER_AUTHORITY; -import static foundation.e.drive.utils.AppConstants.SETTINGSYNC_PROVIDER_AUTHORITY; +import static foundation.e.drive.utils.AppConstants.MEDIA_SYNC_PROVIDER_AUTHORITY; +import static foundation.e.drive.utils.AppConstants.SETTINGS_SYNC_PROVIDER_AUTHORITY; import com.nextcloud.common.NextcloudClient; @@ -70,32 +70,32 @@ public abstract class AbstractServiceIT { * enable Media & settings sync */ protected void enableMediaAndSettingsSync(Account account){ //replace this by robolectric the contentResolver - contentResolver.setSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY, true); - contentResolver.setSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY, true); + contentResolver.setSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY, true); + contentResolver.setSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY, true); } /** * disable Media & enable settings sync */ protected void disableMediaSync(Account account){ //replace this by robolectric the contentResolver - contentResolver.setSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY, false); - contentResolver.setSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY, true); + contentResolver.setSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY, false); + contentResolver.setSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY, true); } /** * enable Media and disable settings sync */ protected void disableSettingsSync(Account account){ //replace this by robolectric the contentResolver - contentResolver.setSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY, true); - contentResolver.setSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY, false); + contentResolver.setSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY, true); + contentResolver.setSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY, false); } /** * disable Media & settings sync */ protected void disableMediaAndSettingsSync(Account account){ //replace this by robolectric the contentResolver - contentResolver.setSyncAutomatically(account, MEDIASYNC_PROVIDER_AUTHORITY, false); - contentResolver.setSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY, false); + contentResolver.setSyncAutomatically(account, MEDIA_SYNC_PROVIDER_AUTHORITY, false); + contentResolver.setSyncAutomatically(account, SETTINGS_SYNC_PROVIDER_AUTHORITY, false); } /** @@ -114,7 +114,7 @@ public abstract class AbstractServiceIT { sharedPreferences.edit().putBoolean( AppConstants.INITIALIZATION_HAS_BEEN_DONE, init_done) .putString(AccountManager.KEY_ACCOUNT_NAME, TEST_ACCOUNT_NAME) .putString(AccountManager.KEY_ACCOUNT_TYPE, TEST_ACCOUNT_TYPE) - .putInt(AppConstants.INITIALFOLDERS_NUMBER, initial_folder_number) + .putInt(AppConstants.INITIAL_FOLDER_NUMBER, initial_folder_number) .putLong(AppConstants.KEY_LAST_SYNC_TIME, last_sync_time) .apply(); } 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 2a25755e1a07f0b0b5c2e9a8b4ae1c1c92218b6d..bb9ff1ad2c6988ca46ed7dd90a86752dc151e2b1 100644 --- a/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java +++ b/app/src/test/java/foundation/e/drive/services/ObserverServiceTest.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import com.nextcloud.common.NextcloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation; @@ -34,7 +33,6 @@ 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.MEDIA_SYNCABLE_CATEGORIES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -97,7 +95,7 @@ public class ObserverServiceTest extends AbstractServiceIT { }catch(SecurityException e){ fail(e.getMessage()); } - final SyncedFolder sFolder = new SyncedFolder(MEDIA_SYNCABLE_CATEGORIES[0], TEST_LOCAL_ROOT_FOLDER_PATH, TEST_REMOTE_ROOT_FOLDER_PATH, true); + final SyncedFolder sFolder = new SyncedFolder("Images", TEST_LOCAL_ROOT_FOLDER_PATH, TEST_REMOTE_ROOT_FOLDER_PATH, true); return sFolder; }