Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Update to application-services v73.0.1.
Browse files Browse the repository at this point in the history
This release includes new auto-generated Kotlin bindings for the FxA Client
component, which come with a few breaking API changes. There should be
no changes in functionality though.
  • Loading branch information
rfk committed Mar 10, 2021
1 parent 5ab780f commit afa1a71
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 58 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object Versions {
const val disklrucache = "2.0.2"
const val leakcanary = "2.4"

const val mozilla_appservices = "72.1.0"
const val mozilla_appservices = "73.0.1"

const val mozilla_glean = "35.0.0"

Expand Down
2 changes: 1 addition & 1 deletion components/service/firefox-accounts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ val accountEventsObserver = object : AccountEventsObserver {
override fun onEvents(event: List<AccountEvent>) {
// device received some commands; for example, here's how you can process incoming Send Tab commands:
commands
.filter { it is AccountEvent.IncomingDeviceCommand }
.filter { it is AccountEvent.CommandReceived }
.map { it.command }
.filter { it is DeviceCommandIncoming.TabReceived }
.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ package mozilla.components.service.fxa
/**
* High-level exception class for the exceptions thrown in the Rust library.
*/
typealias FxaException = mozilla.appservices.fxaclient.FxaException
typealias FxaException = mozilla.appservices.fxaclient.FxaErrorException

/**
* Thrown on a network error.
*/
typealias FxaNetworkException = mozilla.appservices.fxaclient.FxaException.Network
typealias FxaNetworkException = mozilla.appservices.fxaclient.FxaErrorException.Network

/**
* Thrown when the Rust library hits an assertion or panic (this is always a bug).
*/
typealias FxaPanicException = mozilla.appservices.fxaclient.FxaException.Panic
typealias FxaPanicException = mozilla.appservices.fxaclient.FxaErrorException.Panic

/**
* Thrown when the operation requires additional authorization.
*/
typealias FxaUnauthorizedException = mozilla.appservices.fxaclient.FxaException.Unauthorized
typealias FxaUnauthorizedException = mozilla.appservices.fxaclient.FxaErrorException.Authentication

/**
* Thrown when the Rust library hits an unexpected error that isn't a panic.
* This may indicate library misuse, network errors, etc.
*/
typealias FxaUnspecifiedException = mozilla.appservices.fxaclient.FxaException.Unspecified
typealias FxaUnspecifiedException = mozilla.appservices.fxaclient.FxaErrorException.Other

/**
* @return 'true' if this exception should be re-thrown and eventually crash the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.plus
import mozilla.appservices.fxaclient.AuthorizationParams
import mozilla.appservices.fxaclient.AuthorizationParameters
import kotlinx.coroutines.withContext
import mozilla.appservices.fxaclient.FirefoxAccount as InternalFxAcct
import mozilla.appservices.fxaclient.PersistedFirefoxAccount as InternalFxAcct
import mozilla.components.concept.sync.AccessType
import mozilla.components.concept.sync.AuthFlowUrl
import mozilla.components.concept.sync.MigratingAccountInfo
Expand All @@ -21,7 +21,7 @@ import mozilla.components.concept.sync.StatePersistenceCallback
import mozilla.components.concept.base.crash.CrashReporting
import mozilla.components.support.base.log.logger.Logger

typealias PersistCallback = mozilla.appservices.fxaclient.FirefoxAccount.PersistCallback
typealias PersistCallback = mozilla.appservices.fxaclient.PersistedFirefoxAccount.PersistCallback

/**
* FirefoxAccount represents the authentication state of a client.
Expand Down Expand Up @@ -144,7 +144,7 @@ class FirefoxAccount internal constructor(
accessType: AccessType
) = withContext(scope.coroutineContext) {
handleFxaExceptions(logger, "authorizeOAuthCode", { null }) {
val params = AuthorizationParams(clientId, scopes, state, accessType.msg)
val params = AuthorizationParameters(clientId, scopes.toList(), state, accessType.msg, null, null, null)
inner.authorizeOAuthCode(params)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.withContext
import mozilla.appservices.fxaclient.FirefoxAccount
import mozilla.appservices.fxaclient.FxaException
import mozilla.appservices.fxaclient.PersistedFirefoxAccount as FirefoxAccount
import mozilla.appservices.fxaclient.FxaErrorException as FxaException
import mozilla.components.concept.sync.ConstellationState
import mozilla.components.concept.sync.Device
import mozilla.components.concept.sync.DeviceConstellation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ package mozilla.components.service.fxa
import mozilla.appservices.fxaclient.AccessTokenInfo
import mozilla.appservices.fxaclient.AccountEvent
import mozilla.appservices.fxaclient.Device
import mozilla.appservices.fxaclient.DeviceType as RustDeviceType
import mozilla.appservices.fxaclient.DeviceCapability as RustDeviceCapability
import mozilla.appservices.fxaclient.DevicePushSubscription as RustDevicePushSubscription
import mozilla.appservices.fxaclient.IncomingDeviceCommand
import mozilla.appservices.fxaclient.MigrationState
import mozilla.appservices.fxaclient.Profile
Expand Down Expand Up @@ -94,35 +97,39 @@ fun Profile.into(): mozilla.components.concept.sync.Profile {
return mozilla.components.concept.sync.Profile(
uid = this.uid,
email = this.email,
avatar = this.avatar?.let {
avatar = this.avatar.let {
Avatar(
url = it,
isDefault = this.avatarDefault
isDefault = this.isDefaultAvatar
)
},
displayName = this.displayName
)
}

internal fun Device.Type.into(): DeviceType {
internal fun RustDeviceType.into(): DeviceType {
return when (this) {
Device.Type.DESKTOP -> DeviceType.DESKTOP
Device.Type.MOBILE -> DeviceType.MOBILE
Device.Type.TABLET -> DeviceType.TABLET
Device.Type.TV -> DeviceType.TV
Device.Type.VR -> DeviceType.VR
Device.Type.UNKNOWN -> DeviceType.UNKNOWN
RustDeviceType.DESKTOP -> DeviceType.DESKTOP
RustDeviceType.MOBILE -> DeviceType.MOBILE
RustDeviceType.TABLET -> DeviceType.TABLET
RustDeviceType.TV -> DeviceType.TV
RustDeviceType.VR -> DeviceType.VR
RustDeviceType.UNKNOWN -> DeviceType.UNKNOWN
}
}

fun DeviceType.into(): Device.Type {
/**
* Convert between the native-code DeviceType data class
* and the one from the corresponding a-c concept.
*/
fun DeviceType.into(): RustDeviceType {
return when (this) {
DeviceType.DESKTOP -> Device.Type.DESKTOP
DeviceType.MOBILE -> Device.Type.MOBILE
DeviceType.TABLET -> Device.Type.TABLET
DeviceType.TV -> Device.Type.TV
DeviceType.VR -> Device.Type.VR
DeviceType.UNKNOWN -> Device.Type.UNKNOWN
DeviceType.DESKTOP -> RustDeviceType.DESKTOP
DeviceType.MOBILE -> RustDeviceType.MOBILE
DeviceType.TABLET -> RustDeviceType.TABLET
DeviceType.TV -> RustDeviceType.TV
DeviceType.VR -> RustDeviceType.VR
DeviceType.UNKNOWN -> RustDeviceType.UNKNOWN
}
}

Expand All @@ -141,27 +148,43 @@ fun DeviceType.intoSyncType(): mozilla.appservices.syncmanager.DeviceType {
}
}

fun DeviceCapability.into(): Device.Capability {
/**
* Convert between the native-code DeviceCapability data class
* and the one from the corresponding a-c concept.
*/
fun DeviceCapability.into(): RustDeviceCapability {
return when (this) {
DeviceCapability.SEND_TAB -> Device.Capability.SEND_TAB
DeviceCapability.SEND_TAB -> RustDeviceCapability.SEND_TAB
}
}

fun Device.Capability.into(): DeviceCapability {
/**
* Convert between the a-c concept DeviceCapability class and the corresponding
* native-code DeviceCapability data class.
*/
fun RustDeviceCapability.into(): DeviceCapability {
return when (this) {
Device.Capability.SEND_TAB -> DeviceCapability.SEND_TAB
RustDeviceCapability.SEND_TAB -> DeviceCapability.SEND_TAB
}
}

fun mozilla.components.concept.sync.DevicePushSubscription.into(): Device.PushSubscription {
return Device.PushSubscription(
/**
* Convert between the a-c concept DevicePushSubscription class and the corresponding
* native-code DevicePushSubscription data class.
*/
fun mozilla.components.concept.sync.DevicePushSubscription.into(): RustDevicePushSubscription {
return RustDevicePushSubscription(
endpoint = this.endpoint,
authKey = this.authKey,
publicKey = this.publicKey
)
}

fun Device.PushSubscription.into(): mozilla.components.concept.sync.DevicePushSubscription {
/**
* Convert between the native-code DevicePushSubscription data class
* and the one from the corresponding a-c concept.
*/
fun RustDevicePushSubscription.into(): mozilla.components.concept.sync.DevicePushSubscription {
return mozilla.components.concept.sync.DevicePushSubscription(
endpoint = this.endpoint,
authKey = this.authKey,
Expand Down Expand Up @@ -211,7 +234,7 @@ fun mozilla.components.concept.sync.TabData.into(): TabHistoryEntry {

fun AccountEvent.into(): mozilla.components.concept.sync.AccountEvent {
return when (this) {
is AccountEvent.IncomingDeviceCommand ->
is AccountEvent.CommandReceived ->
mozilla.components.concept.sync.AccountEvent.DeviceCommandIncoming(command = this.command.into())
is AccountEvent.ProfileUpdated ->
mozilla.components.concept.sync.AccountEvent.ProfileUpdated
Expand All @@ -235,8 +258,8 @@ fun IncomingDeviceCommand.into(): mozilla.components.concept.sync.DeviceCommandI

fun IncomingDeviceCommand.TabReceived.into(): mozilla.components.concept.sync.DeviceCommandIncoming.TabReceived {
return mozilla.components.concept.sync.DeviceCommandIncoming.TabReceived(
from = this.from?.into(),
entries = this.entries.map { it.into() }
from = this.sender?.into(),
entries = this.payload.entries.map { it.into() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.plus
import kotlinx.coroutines.runBlocking
import mozilla.appservices.fxaclient.FxaException
import mozilla.appservices.fxaclient.FxaErrorException as FxaException
import mozilla.appservices.fxaclient.IncomingDeviceCommand
import mozilla.appservices.fxaclient.TabHistoryEntry
import mozilla.appservices.fxaclient.SendTabPayload
import mozilla.appservices.syncmanager.DeviceSettings
import mozilla.components.concept.sync.AccountEvent
import mozilla.components.concept.sync.AccountEventsObserver
Expand Down Expand Up @@ -52,7 +53,9 @@ import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyZeroInteractions
import mozilla.appservices.fxaclient.AccountEvent as ASAccountEvent
import mozilla.appservices.fxaclient.Device as NativeDevice
import mozilla.appservices.fxaclient.FirefoxAccount as NativeFirefoxAccount
import mozilla.appservices.fxaclient.DeviceType as NativeDeviceType
import mozilla.appservices.fxaclient.DevicePushSubscription as NativeDevicePushSubscription
import mozilla.appservices.fxaclient.PersistedFirefoxAccount as NativeFirefoxAccount
import mozilla.appservices.syncmanager.DeviceType as RustDeviceType

@ExperimentalCoroutinesApi
Expand Down Expand Up @@ -99,10 +102,10 @@ class FxaDeviceConstellationTest {
constellation.finalizeDevice(it, config)
when (expectedFinalizeAction(it)) {
FxaDeviceConstellation.DeviceFinalizeAction.Initialize -> {
verify(account).initializeDevice("test name", NativeDevice.Type.TABLET, setOf(mozilla.appservices.fxaclient.Device.Capability.SEND_TAB))
verify(account).initializeDevice("test name", NativeDeviceType.TABLET, setOf(mozilla.appservices.fxaclient.DeviceCapability.SEND_TAB))
}
FxaDeviceConstellation.DeviceFinalizeAction.EnsureCapabilities -> {
verify(account).ensureCapabilities(setOf(mozilla.appservices.fxaclient.Device.Capability.SEND_TAB))
verify(account).ensureCapabilities(setOf(mozilla.appservices.fxaclient.DeviceCapability.SEND_TAB))
}
FxaDeviceConstellation.DeviceFinalizeAction.None -> {
verifyZeroInteractions(account)
Expand Down Expand Up @@ -187,8 +190,8 @@ class FxaDeviceConstellationTest {
val testDevice1 = testDevice("test1", false)
val testTab1 = TabHistoryEntry("Hello", "http://world.com/1")
`when`(account.handlePushMessage("raw events payload")).thenReturn(arrayOf(
ASAccountEvent.IncomingDeviceCommand(
command = IncomingDeviceCommand.TabReceived(testDevice1, arrayOf(testTab1))
ASAccountEvent.CommandReceived(
command = IncomingDeviceCommand.TabReceived(testDevice1, SendTabPayload(listOf(testTab1), "flowid", "streamid"))
)
))
assertTrue(constellation.processRawEvent("raw events payload"))
Expand All @@ -211,7 +214,7 @@ class FxaDeviceConstellationTest {

@Test
fun `send command to device will report exceptions`() = runBlocking(coroutinesTestRule.testDispatcher) {
val exception = FxaException.Unspecified("")
val exception = FxaException.Other("")
val exceptionCaptor = argumentCaptor<SendCommandException>()
doAnswer { throw exception }.`when`(account).sendSingleTab(any(), any(), any())

Expand Down Expand Up @@ -340,7 +343,7 @@ class FxaDeviceConstellationTest {

// Some commands.
`when`(account.pollDeviceCommands()).thenReturn(arrayOf(
IncomingDeviceCommand.TabReceived(null, emptyArray())
IncomingDeviceCommand.TabReceived(null, SendTabPayload(emptyList(), "", ""))
))
assertTrue(constellation.pollForCommands())

Expand All @@ -356,7 +359,7 @@ class FxaDeviceConstellationTest {

// Zero tabs from a single device.
`when`(account.pollDeviceCommands()).thenReturn(arrayOf(
IncomingDeviceCommand.TabReceived(testDevice1, emptyArray())
IncomingDeviceCommand.TabReceived(testDevice1, SendTabPayload(emptyList(), "", ""))
))
assertTrue(constellation.pollForCommands())

Expand All @@ -368,7 +371,7 @@ class FxaDeviceConstellationTest {

// Single tab from a single device.
`when`(account.pollDeviceCommands()).thenReturn(arrayOf(
IncomingDeviceCommand.TabReceived(testDevice2, arrayOf(testTab1))
IncomingDeviceCommand.TabReceived(testDevice2, SendTabPayload(listOf(testTab1), "", ""))
))
assertTrue(constellation.pollForCommands())

Expand All @@ -378,7 +381,7 @@ class FxaDeviceConstellationTest {

// Multiple tabs from a single device.
`when`(account.pollDeviceCommands()).thenReturn(arrayOf(
IncomingDeviceCommand.TabReceived(testDevice2, arrayOf(testTab1, testTab3))
IncomingDeviceCommand.TabReceived(testDevice2, SendTabPayload(listOf(testTab1, testTab3), "", ""))
))
assertTrue(constellation.pollForCommands())

Expand All @@ -388,8 +391,8 @@ class FxaDeviceConstellationTest {

// Multiple tabs received from multiple devices.
`when`(account.pollDeviceCommands()).thenReturn(arrayOf(
IncomingDeviceCommand.TabReceived(testDevice2, arrayOf(testTab1, testTab2)),
IncomingDeviceCommand.TabReceived(testDevice1, arrayOf(testTab3))
IncomingDeviceCommand.TabReceived(testDevice2, SendTabPayload(listOf(testTab1, testTab2), "", "")),
IncomingDeviceCommand.TabReceived(testDevice1, SendTabPayload(listOf(testTab3), "", ""))
))
assertTrue(constellation.pollForCommands())

Expand Down Expand Up @@ -445,12 +448,12 @@ class FxaDeviceConstellationTest {
return NativeDevice(
id = id,
displayName = "testName",
deviceType = NativeDevice.Type.MOBILE,
deviceType = NativeDeviceType.MOBILE,
isCurrentDevice = current,
lastAccessTime = 123L,
capabilities = listOf(),
pushEndpointExpired = expired,
pushSubscription = if (subscribed) NativeDevice.PushSubscription("http://endpoint.com", "pk", "auth key") else null
pushSubscription = if (subscribed) NativeDevicePushSubscription("http://endpoint.com", "pk", "auth key") else null
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.mozilla.experiments.nimbus.AvailableRandomizationUnits
import org.mozilla.experiments.nimbus.EnrolledExperiment
import org.mozilla.experiments.nimbus.EnrollmentChangeEvent
import org.mozilla.experiments.nimbus.EnrollmentChangeEventType
import org.mozilla.experiments.nimbus.ErrorException
import org.mozilla.experiments.nimbus.NimbusErrorException
import org.mozilla.experiments.nimbus.NimbusClient
import org.mozilla.experiments.nimbus.NimbusClientInterface
import org.mozilla.experiments.nimbus.RemoteSettingsConfig
Expand Down Expand Up @@ -298,9 +298,9 @@ class Nimbus(
try {
nimbus.fetchExperiments()
notifyObservers { onExperimentsFetched() }
} catch (e: ErrorException.RequestError) {
} catch (e: NimbusErrorException.RequestError) {
logger.info("Error fetching experiments from endpoint: $e")
} catch (e: ErrorException.ResponseError) {
} catch (e: NimbusErrorException.ResponseError) {
logger.info("Error fetching experiments from endpoint: $e")
}
}
Expand All @@ -318,7 +318,7 @@ class Nimbus(
nimbus.applyPendingExperiments().also(::recordExperimentTelemetryEvents)
// Get the experiments to record in telemetry
postEnrolmentCalculation()
} catch (e: ErrorException.InvalidExperimentFormat) {
} catch (e: NimbusErrorException.InvalidExperimentFormat) {
logger.info("Invalid experiment format: $e")
}
}
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ permalink: /changelog/
* **service-sync-autofill**
* Refactors `AutofillCreditCardsAddressesStorage` from **browser-storage-sync** into its own component. [#9801](https://github.com/mozilla-mobile/android-components/issues/9801)

* **service-firefox-accounts**,**browser-storage-sync**,**service-nimbus**,**service-sync-logins**
* Due to a temporary build issue in the Application Services project, it is not currently
possible to run some service-related unittests on a Windows host. [#9731](https://github.com/mozilla-mobile/android-components/pull/9731)
* Work on restoring this capability will be tracked in [application-services#3917](https://github.com/mozilla/application-services/issues/3917).

# 73.0.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v72.0.0...v73.0.0)
Expand Down

0 comments on commit afa1a71

Please sign in to comment.