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

Commit eb8b9152 authored by dev-12's avatar dev-12
Browse files

Merge branch '4252-enable-password-sync' into 'main'

enable password sync toggle by default for existing account

See merge request !198
parents cb7dfcb6 2bdd9ffb
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -820,6 +820,9 @@
        </intent>

        <provider android:authorities="foundation.e.mail.provider.AppContentProvider" />

        <!-- Murena Password app -->
        <package android:name="foundation.e.passwords"/>
    </queries>

</manifest>
+17 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import android.content.Context
import android.net.Uri
import android.os.StrictMode
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.edit
import androidx.core.graphics.drawable.toBitmap
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
@@ -57,6 +58,8 @@ class App: Application(), Thread.UncaughtExceptionHandler, Configuration.Provide
                .build()
        }

        private const val UPGRADE_PREFS = "upgrade_prefs"
        private const val PASSWORD_SYNC_ENABLED_ON_UPGRADE = "password_sync_enabled_on_upgrade"
    }

    @Inject lateinit var accountsUpdatedListener: AccountsUpdatedListener
@@ -113,6 +116,20 @@ class App: Application(), Thread.UncaughtExceptionHandler, Configuration.Provide
            TasksWatcher.watch(this)
            // check whether a tasks app is currently installed
            SyncUtils.updateTaskSync(this)

            // We shipped Password app as disabled in v3.7. Adding an account while it is disabled
            // leaves its sync toggle off, so retry enabling it on startup until it succeeds.
            val upgradePreferences = applicationContext.getSharedPreferences(
                UPGRADE_PREFS,
                MODE_PRIVATE
            )
            if (!upgradePreferences.getBoolean(PASSWORD_SYNC_ENABLED_ON_UPGRADE, false)) {
                val enabled = SyncUtils.enablePasswordAppSync(this)
                upgradePreferences.edit {
                    putBoolean(PASSWORD_SYNC_ENABLED_ON_UPGRADE, enabled)
                }
                Logger.log.log(Level.INFO, "sync for password app enabled : $enabled")
            }
        }
    }

+12 −0
Original line number Diff line number Diff line
@@ -115,6 +115,18 @@ object SyncUtils {
        return result
    }

    fun enablePasswordAppSync(context: Context): Boolean {
        val eeloAccountType = context.getString(R.string.eelo_account_type)
        val account = AccountManager.get(context)
            .getAccountsByType(eeloAccountType)
            .firstOrNull() ?: return false

        val authority = context.getString(R.string.password_authority)
        ContentResolver.setIsSyncable(account, authority, 1)
        ContentResolver.setSyncAutomatically(account, authority, true)
        return ContentResolver.getSyncAutomatically(account, authority)
    }

    // task sync utils

    @WorkerThread