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

Commit 654d48ef 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 bb41b1d0
Loading
Loading
Loading
Loading
Loading
+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

@@ -97,7 +98,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 {
+3 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import at.bitfire.davdroid.repository.DavServiceRepository
import at.bitfire.davdroid.sync.account.InvalidAccountException
import dagger.Lazy
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.accountmanager.AccountTypes
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.runInterruptible
@@ -179,7 +180,7 @@ class PushRegistrationManager @Inject constructor(
        if (subscribeTo.isEmpty())
            return

        val account = accountRepository.get().fromName(service.accountName)
        val account = accountRepository.get().fromName(service.accountName, AccountTypes.getAccountTypeFromPrincipal(service.principal))
        httpClientBuilder.get()
            .fromAccountAsync(account)
            .build()
@@ -293,7 +294,7 @@ class PushRegistrationManager @Inject constructor(
        if (from.isEmpty())
            return

        val account = accountRepository.get().fromName(service.accountName)
        val account = accountRepository.get().fromName(service.accountName, AccountTypes.getAccountTypeFromPrincipal(service.principal))
        httpClientBuilder.get()
            .fromAccountAsync(account)
            .build()
Loading