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

Commit 9abaedc2 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

AM: Allow changing account type

- In old account manager, our app supported multiple types
  (Google, WebDAV, Yahoo, Murena). Adding this flexibility
  now ensures we can add new account types in future commits.
parent fc52059a
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -127,19 +127,19 @@ class AccountRepositoryTest {
        val existing = Account("Existing Account", accountType)
        am.addAccountExplicitly(existing, null, null)

        accountRepository.rename(account.name, existing.name)
        accountRepository.rename(accountType, account.name, existing.name,)
    }

    @Test
    fun testRename_locksAccountsCleanup() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        verify { AccountsCleanupWorker.lockAccountsCleanup() }
    }

    @Test
    fun testRename_renamesAccountInAndroid() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val accountsAfter = am.getAccountsByType(accountType)
        assertTrue(accountsAfter.any { it.name == newName })
@@ -147,14 +147,14 @@ class AccountRepositoryTest {

    @Test
    fun testRename_cancelsRunningSynchronizationOfOldAccount() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        coVerify { syncWorkerManager.cancelAllWork(account) }
    }

    @Test
    fun testRename_disablesPeriodicSyncsForOldAccount() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        for (dataType in SyncDataType.entries)
            coVerify(exactly = 1) {
@@ -164,47 +164,47 @@ class AccountRepositoryTest {

    @Test
    fun testRename_updatesAccountNameReferencesInDatabase() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        coVerify { serviceRepository.renameAccount(account.name, newName) }
    }

    @Test
    fun testRename_updatesAddressBooks() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val newAccount = accountRepository.fromName(newName)
        coVerify { localAddressBookStore.updateAccount(account, newAccount) }
        val newAccount = accountRepository.fromName(newName, accountType)
        coVerify { localAddressBookStore.updateAccount(account, newAccount, accountType) }
    }

    @Test
    fun testRename_updatesCalendarEvents() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val newAccount = accountRepository.fromName(newName)
        coVerify { localCalendarStore.updateAccount(account, newAccount) }
        val newAccount = accountRepository.fromName(newName, accountType)
        coVerify { localCalendarStore.updateAccount(account, newAccount, accountType) }
    }

    @Test
    fun testRename_updatesAccountNameOfLocalTasks() = runTest {
        val mockDataStore = mockk<LocalDataStore<*>>(relaxed = true)
        every { tasksAppManager.getDataStore() } returns mockDataStore
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        coVerify { mockDataStore.updateAccount(account, accountRepository.fromName(newName)) }
        coVerify { mockDataStore.updateAccount(account, accountRepository.fromName(newName, accountType), accountType) }
    }

    @Test
    fun testRename_updatesAutomaticSync() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        val newAccount = accountRepository.fromName(newName)
        val newAccount = accountRepository.fromName(newName, accountType)
        coVerify { automaticSyncManager.updateAutomaticSync(newAccount) }
    }

    @Test
    fun testRename_releasesAccountsCleanupWorkerMutex() = runTest {
        accountRepository.rename(account.name, newName)
        accountRepository.rename(accountType, account.name, newName)

        verify { AccountsCleanupWorker.lockAccountsCleanup() }
        coVerify { serviceRepository.renameAccount(account.name, newName) }
+1 −1
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ class LocalAddressBookStoreTest {
        }

        mockkObject(localAddressBookStore)
        every { localAddressBookStore.createAddressBookAccount(any(), any(), any()) } returns null
        every { localAddressBookStore.createAddressBookAccount(any(), any(), any(), any()) } returns null

        assertEquals(null, localAddressBookStore.create(provider, collection))
    }
+1 −1
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ class SyncerTest {
            throw NotImplementedError()
        }

        override fun updateAccount(oldAccount: Account, newAccount: Account) {
        override fun updateAccount(oldAccount: Account, newAccount: Account, accountType: String) {
            throw NotImplementedError()
        }

+2 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import foundation.e.accountmanager.utils.AccountHelper
import java.io.Writer
import javax.inject.Singleton

@@ -104,7 +105,7 @@ abstract class AppDatabase: RoomDatabase() {

                    // remove all accounts because they're unfortunately useless without database
                    val am = AccountManager.get(context)
                    for (account in am.getAccountsByType(context.getString(R.string.account_type)))
                    for (account in AccountHelper.getAllAccounts(am))
                        am.removeAccountExplicitly(account)
                }
            })
+3 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import at.bitfire.davdroid.sync.SyncDataType
import at.bitfire.davdroid.sync.TasksAppManager
import at.bitfire.davdroid.sync.worker.SyncWorkerManager
import dagger.Lazy
import foundation.e.accountmanager.AccountTypes
import org.unifiedpush.android.connector.data.PushMessage
import org.xmlpull.v1.XmlPullParserException
import java.io.StringReader
@@ -70,7 +71,7 @@ class PushMessageHandler @Inject constructor(
                            syncDataTypes += SyncDataType.TASKS

                    // Schedule sync for all the types identified
                    val account = accountRepository.fromName(service.accountName)
                    val account = accountRepository.fromName(service.accountName, AccountTypes.getAccountTypeFromPrincipal(service.principal))
                    for (syncDataType in syncDataTypes)
                        syncWorkerManager.enqueueOneTime(account, syncDataType, fromPush = true)
                }
@@ -81,7 +82,7 @@ class PushMessageHandler @Inject constructor(
            val service = instance.toLongOrNull()?.let { serviceRepository.getBlocking(it) }
            if (service != null) {
                logger.warning("Got push message without topic and service, syncing all accounts")
                val account = accountRepository.fromName(service.accountName)
                val account = accountRepository.fromName(service.accountName, AccountTypes.getAccountTypeFromPrincipal(service.principal))
                syncWorkerManager.enqueueOneTimeAllAuthorities(account, fromPush = true)

            } else {
Loading