Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db8325da authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Add periodic file sync to the pictures and videos authority

parent ca974f3d
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ class App: Application(), Thread.UncaughtExceptionHandler, Configuration.Provide
            // check whether a tasks app is currently installed
            SyncUtils.updateTaskSync(this)

            AccountSettings.addPeriodicFileSyncIfMissing(this)

            // check/repair sync intervals
            AccountSettings.repairSyncIntervals(this)
        }
+31 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@ class AccountSettings(
        /** Stores the tasks sync interval (in seconds) so that it can be set again when the provider is switched */
        const val KEY_SYNC_INTERVAL_TASKS = "sync_interval_tasks"

        const val KEY_SYNC_INTERVAL_FILES = "sync_interval_files"

        const val KEY_USERNAME = "user_name"
        const val KEY_EMAIL_ADDRESS = "email_address"
        const val KEY_AUTH_STATE = "auth_state"
@@ -164,6 +166,20 @@ class AccountSettings(
            return bundle
        }

        fun addPeriodicFileSyncIfMissing(context: Context) {
            val accountManager = AccountManager.get(context)
            val mediaSyncAuthority = context.getString(R.string.media_authority)

            for (account in accountManager.getAccountsByType(context.getString(R.string.account_type))) {
                val settings = AccountSettings(context, account)

                if (settings.getSavedFilesSyncInterval() == null) {
                    ContentResolver.setIsSyncable(account, mediaSyncAuthority, 1)
                    settings.setSyncInterval(mediaSyncAuthority, Constants.DEFAULT_FILE_SYNC_INTERVAL)
                }
            }
        }

        fun repairSyncIntervals(context: Context) {
            val addressBooksAuthority = context.getString(R.string.address_books_authority)
            val taskAuthority = TaskUtils.currentProvider(context)?.authority
@@ -191,6 +207,16 @@ class AccountSettings(
                        }
                    }

                    // repair file sync
                    settings.getSavedFilesSyncInterval()?.let { shouldBe ->
                        val authority = context.getString(R.string.media_authority)
                        val current = settings.getSyncInterval(authority)
                        if (current != shouldBe) {
                            Logger.log.warning("${account.name}: $authority sync interval should be $shouldBe but is $current -> setting to $current")
                            settings.setSyncInterval(authority, shouldBe)
                        }
                    }

                    if (taskAuthority != null)
                    // repair calendar sync
                        settings.getSavedTasksSyncInterval()?.let { shouldBe ->
@@ -349,6 +375,9 @@ class AccountSettings(

            TaskProvider.ProviderName.values().any { it.authority == authority } ->
                accountManager.setUserData(account, KEY_SYNC_INTERVAL_TASKS, seconds.toString())

            authority == context.getString(R.string.media_authority) ->
                accountManager.setUserData(account, KEY_SYNC_INTERVAL_FILES, seconds.toString())
        }

        return true
@@ -358,6 +387,8 @@ class AccountSettings(
    fun getSavedCalendarsSyncInterval() = accountManager.getUserData(account, KEY_SYNC_INTERVAL_CALENDARS)?.toLong()
    fun getSavedTasksSyncInterval() = accountManager.getUserData(account, KEY_SYNC_INTERVAL_TASKS)?.toLong()

    fun getSavedFilesSyncInterval() = accountManager.getUserData(account, KEY_SYNC_INTERVAL_FILES)?.toLong()

    fun getSyncWifiOnly() =
            if (settings.containsKey(KEY_WIFI_ONLY))
                settings.getBoolean(KEY_WIFI_ONLY)
+6 −1
Original line number Diff line number Diff line
@@ -284,7 +284,6 @@ class AccountDetailsFragment : Fragment() {

                ContentResolver.setSyncAutomatically(account, context.getString(R.string.notes_authority), true)
                ContentResolver.setSyncAutomatically(account, context.getString(R.string.email_authority), true)
                ContentResolver.setSyncAutomatically(account, context.getString(R.string.media_authority), true)
                ContentResolver.setSyncAutomatically(account, context.getString(R.string.app_data_authority), true)
                ContentResolver.setSyncAutomatically(account, context.getString(R.string.metered_edrive_authority), true)

@@ -292,6 +291,12 @@ class AccountDetailsFragment : Fragment() {
                Logger.log.log(Level.INFO, "Writing account configuration to database", config)
                try {
                    val accountSettings = AccountSettings(context, account)

                    val mediaSyncAuthority = context.getString(R.string.media_authority)
                    ContentResolver.setIsSyncable(account, mediaSyncAuthority, 1)
                    accountSettings.setSyncInterval(mediaSyncAuthority, Constants.DEFAULT_FILE_SYNC_INTERVAL)


                    val defaultSyncInterval = Constants.DEFAULT_CALENDAR_SYNC_INTERVAL

                    val addrBookAuthority = context.getString(R.string.address_books_authority)