Commit b2779fd8 authored by Grisha Kruglov's avatar Grisha Kruglov Committed by Grisha Kruglov
Browse files

No issue: use 'FirefoxAccount@disconnect' instead of destroying current device

'disconnect' API was introduced recently which destroys the device record.
This means we can remove relevant code from a-c which used to do the same work.
parent 640110ec
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -26,15 +26,6 @@ interface DeviceConstellation : Observable<DeviceEventsObserver> {
        capabilities: Set<DeviceCapability>
    ): Deferred<Boolean>

    /**
     * Destroy current device record.
     * Use this when device record is no longer relevant, e.g. while logging out. On success, other
     * devices will no longer see the current device in their device lists.
     *
     * @return A [Deferred] that will be resolved with a success flag once operation is complete.
     */
    fun destroyCurrentDeviceAsync(): Deferred<Boolean>

    /**
     * Ensure that all passed in [capabilities] are configured.
     * This may involve backend service registration, or other work involving network/disc access.
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ interface OAuthAccount : AutoCloseable {
    fun registerPersistenceCallback(callback: StatePersistenceCallback)
    fun migrateFromSessionTokenAsync(sessionToken: String, kSync: String, kXCS: String): Deferred<Boolean>
    fun deviceConstellation(): DeviceConstellation
    fun disconnectAsync(): Deferred<Boolean>
    fun toJSONString(): String
}

+19 −0
Original line number Diff line number Diff line
@@ -238,6 +238,25 @@ class FirefoxAccount internal constructor(
        }
    }

    /**
     * Reset internal account state and destroy current device record.
     * Use this when device record is no longer relevant, e.g. while logging out. On success, other
     * devices will no longer see the current device in their device lists.
     *
     * @return A [Deferred] that will be resolved with a success flag once operation is complete.
     * Failure indicates that we may have failed to destroy current device record. Nothing to do for
     * the consumer; device record will be cleaned up eventually via TTL.
     */
    override fun disconnectAsync(): Deferred<Boolean> {
        return scope.async {
            // TODO can this ever throw FxaUnauthorizedException? would that even make sense? or is that a bug?
            handleFxaExceptions(logger, "disconnect", { false }) {
                inner.disconnect()
                true
            }
        }
    }

    override fun deviceConstellation(): DeviceConstellation {
        return deviceConstellation
    }
+0 −20
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
package mozilla.components.service.fxa

import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
@@ -67,25 +66,6 @@ class FxaDeviceConstellation(
        }
    }

    override fun destroyCurrentDeviceAsync(): Deferred<Boolean> {
        val state = state()
        state?.currentDevice?.let {
            return scope.async {
                handleFxaExceptions(logger, "destroying current device") {
                    account.disconnect() // Not sure if this is right!
                }
            }
        }

        if (state == null) {
            logger.warn("Asked to destroy device record, but constellation state is not available")
        } else {
            logger.warn("Asked to destroy device record, but current device record is not available")
        }

        return CompletableDeferred(false)
    }

    override fun ensureCapabilitiesAsync(capabilities: Set<DeviceCapability>): Deferred<Boolean> {
        return scope.async {
            handleFxaExceptions(logger, "ensuring capabilities") {
+6 −2
Original line number Diff line number Diff line
@@ -490,8 +490,12 @@ open class FxaAccountManager(
            AccountState.NotAuthenticated -> {
                when (via) {
                    Event.Logout -> {
                        // Destroy the current device record.
                        account.deviceConstellation().destroyCurrentDeviceAsync().await()
                        // Clean up internal account state and destroy the current FxA device record.
                        if (account.disconnectAsync().await()) {
                            logger.info("Disconnected FxA account")
                        } else {
                            logger.warn("Failed to fully disconnect the FxA account")
                        }
                        // Clean up resources.
                        profile = null
                        account.close()
Loading