summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-02-01 19:00:52 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-03-31 14:36:30 +0000
commitea6e76015cc95529f98fa4a0afb4606c134228e8 (patch)
treeaa79463da960c1d73e9bf2fab7ef8490f2d5c9eb /android/src/main
parent618939bfc6aaab742782b672f7088feca582a845 (diff)
downloadmullvadvpn-ea6e76015cc95529f98fa4a0afb4606c134228e8.tar.xz
mullvadvpn-ea6e76015cc95529f98fa4a0afb4606c134228e8.zip
Refactor service side `AccountCache` exposed API
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt34
1 files changed, 11 insertions, 23 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
index 158fb15d5e..74cdc3f11f 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/AccountCache.kt
@@ -104,19 +104,19 @@ class AccountCache(private val endpoint: ServiceEndpoint) {
}
}
- fun createNewAccount() {
- commandChannel.sendBlocking(Command.CreateAccount)
- }
+ fun onDestroy() {
+ endpoint.settingsListener.accountNumberNotifier.unsubscribe(this)
+ jobTracker.cancelAllJobs()
- fun login(account: String) {
- commandChannel.sendBlocking(Command.Login(account))
- }
+ onAccountNumberChange.unsubscribeAll()
+ onAccountExpiryChange.unsubscribeAll()
+ onAccountHistoryChange.unsubscribeAll()
+ onLoginStatusChange.unsubscribeAll()
- fun logout() {
- commandChannel.sendBlocking(Command.Logout)
+ commandChannel.close()
}
- fun fetchAccountExpiry() {
+ private fun fetchAccountExpiry() {
synchronized(this) {
accountNumber?.let { account ->
jobTracker.newBackgroundJob("fetch") {
@@ -145,7 +145,7 @@ class AccountCache(private val endpoint: ServiceEndpoint) {
}
}
- fun invalidateAccountExpiry(accountExpiryToInvalidate: DateTime) {
+ private fun invalidateAccountExpiry(accountExpiryToInvalidate: DateTime) {
synchronized(this) {
if (accountExpiry == accountExpiryToInvalidate) {
oldAccountExpiry = accountExpiryToInvalidate
@@ -154,25 +154,13 @@ class AccountCache(private val endpoint: ServiceEndpoint) {
}
}
- fun removeAccountFromHistory(accountToken: String) {
+ private fun removeAccountFromHistory(accountToken: String) {
jobTracker.newBackgroundJob("removeAccountFromHistory $accountToken") {
daemon.await().removeAccountFromHistory(accountToken)
fetchAccountHistory()
}
}
- fun onDestroy() {
- endpoint.settingsListener.accountNumberNotifier.unsubscribe(this)
- jobTracker.cancelAllJobs()
-
- onAccountNumberChange.unsubscribeAll()
- onAccountExpiryChange.unsubscribeAll()
- onAccountHistoryChange.unsubscribeAll()
- onLoginStatusChange.unsubscribeAll()
-
- commandChannel.close()
- }
-
private fun spawnActor() = GlobalScope.actor<Command>(Dispatchers.Default, Channel.UNLIMITED) {
try {
val command = channel.receive()