1
0
mirror of https://github.com/etesync/android synced 2025-04-01 15:25:47 +00:00

Add support for associate accounts.

This commit is contained in:
Tom Hacohen 2019-01-11 15:40:06 +00:00
parent 3ab441b9d4
commit 5dbca6e00f
4 changed files with 21 additions and 9 deletions

View File

@ -29,8 +29,12 @@ abstract class BaseManager {
when (response.code()) {
HttpURLConnection.HTTP_UNAVAILABLE -> throw Exceptions.ServiceUnavailableException(response, "Service unavailable")
HttpURLConnection.HTTP_UNAUTHORIZED -> throw Exceptions.UnauthorizedException(response, "Unauthorized auth token")
HttpURLConnection.HTTP_FORBIDDEN -> if (apiError.code == "service_inactive") {
throw Exceptions.UserInactiveException(response, apiError.detail)
HttpURLConnection.HTTP_FORBIDDEN -> {
if (apiError.code == "service_inactive") {
throw Exceptions.UserInactiveException(response, apiError.detail)
} else if (apiError.code == "associate_not_allowed") {
throw Exceptions.AssociateNotAllowedException(response, apiError.detail)
}
}
}// Fall through. We want to always throw when unsuccessful.

View File

@ -8,6 +8,8 @@ import java.io.Serializable
import java.security.GeneralSecurityException
class Exceptions {
class AssociateNotAllowedException(response: Response, message: String?) : HttpException(response, message)
class UnauthorizedException(response: Response, message: String?) : HttpException(response, message)
class UserInactiveException(response: Response, message: String?) : HttpException(response, message)

View File

@ -134,13 +134,17 @@ abstract class SyncAdapterService : Service() {
}
if (journals.isEmpty()) {
val info = CollectionInfo.defaultForServiceType(serviceType)
val uid = JournalManager.Journal.genUid()
info.uid = uid
val crypto = Crypto.CryptoManager(info.version, settings.password(), uid)
val journal = JournalManager.Journal(crypto, info.toJson(), uid)
journalsManager.create(journal)
journals.add(Pair(journal, info))
try {
val info = CollectionInfo.defaultForServiceType(serviceType)
val uid = JournalManager.Journal.genUid()
info.uid = uid
val crypto = Crypto.CryptoManager(info.version, settings.password(), uid)
val journal = JournalManager.Journal(crypto, info.toJson(), uid)
journalsManager.create(journal)
journals.add(Pair(journal, info))
} catch (e: Exceptions.AssociateNotAllowedException) {
// Skip for now
}
}
saveCollections(journals)

View File

@ -131,6 +131,8 @@ class CreateCollectionFragment : DialogFragment(), LoaderManager.LoaderCallbacks
return e
} catch (e: Exceptions.GenericCryptoException) {
return e
} catch (e: Exceptions.AssociateNotAllowedException) {
return e
}
return null