Skip to content

Commit

Permalink
Issue mozilla-mobile#9801: Refactor AutofillCreditCardsAddressesStora…
Browse files Browse the repository at this point in the history
…ge into its own component
  • Loading branch information
gabrielluong committed Mar 9, 2021
1 parent 2aa643b commit 32ef7ce
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 90 deletions.
4 changes: 4 additions & 0 deletions .buildconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ projects:
path: components/service/location
description: 'A library for providing location-based services.'
publish: true
service-sync-autofill:
path: components/service/sync-autofill
description: 'A library for autofilling addresses and credit cards.'
publish: true
service-sync-logins:
path: components/service/sync-logins
description: 'A library for integrating with Firefox Sync - Logins.'
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ _Components and libraries to interact with backend services._

* 🔵 [**Firefox Sync - Logins**](components/service/sync-logins/README.md) - A library for integrating with Firefox Sync - Logins.

* 🔴 [**Firefox Sync - Autofill**](components/service/sync-autofill/README.md) - A library for integrating with Firefox Sync - Autofill.

* 🔵 [**Glean**](components/service/glean/README.md) - A client-side telemetry SDK for collecting metrics and sending them to Mozilla's telemetry service (eventually replacing [service-telemetry](components/service/telemetry/README.md)).

* 🔵 [**Location**](components/service/location/README.md) - A library for accessing Mozilla's and other location services.
Expand Down
2 changes: 0 additions & 2 deletions components/browser/storage-sync/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ dependencies {
}

api Dependencies.mozilla_remote_tabs
api Dependencies.mozilla_sync_autofill
api project(':concept-storage')
api project(':concept-sync')

Expand All @@ -47,7 +46,6 @@ dependencies {
testImplementation Dependencies.androidx_test_junit
testImplementation Dependencies.testing_robolectric
testImplementation Dependencies.testing_mockito
testImplementation Dependencies.testing_coroutines

testImplementation Dependencies.mozilla_places
testImplementation Dependencies.mozilla_remote_tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@file:Suppress("MatchingDeclarationName", "TooManyFunctions")
@file:Suppress("MatchingDeclarationName")

package mozilla.components.browser.storage.sync

Expand All @@ -11,20 +11,15 @@ import mozilla.appservices.places.BookmarkItem
import mozilla.appservices.places.BookmarkSeparator
import mozilla.appservices.places.BookmarkTreeNode
import mozilla.appservices.places.SyncAuthInfo
import mozilla.components.concept.storage.Address
import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
import mozilla.components.concept.storage.CreditCard
import mozilla.components.concept.storage.FrecencyThresholdOption
import mozilla.components.concept.storage.TopFrecentSiteInfo
import mozilla.components.concept.storage.VisitInfo
import mozilla.components.concept.storage.VisitType
import mozilla.appservices.autofill.UpdatableAddressFields
import mozilla.appservices.autofill.UpdatableCreditCardFields

// We have type definitions at the concept level, and "external" types defined within
// Autofill and Places. In practice these two types are largely the same, and this file
// is the conversion point.
// We have type definitions at the concept level, and "external" types defined within Places.
// In practice these two types are largely the same, and this file is the conversion point.

/**
* Conversion from our SyncAuthInfo into its "native" version used at the interface boundary.
Expand Down Expand Up @@ -106,79 +101,3 @@ internal fun BookmarkTreeNode.asBookmarkNode(): BookmarkNode {
}
}
}

/**
* Conversion from a generic [UpdatableAddressFields] into its richer comrade within the 'autofill' lib.
*/
internal fun mozilla.components.concept.storage.UpdatableAddressFields.into(): UpdatableAddressFields {
return UpdatableAddressFields(
givenName = this.givenName,
additionalName = this.additionalName,
familyName = this.familyName,
organization = this.organization,
streetAddress = this.streetAddress,
addressLevel3 = this.addressLevel3,
addressLevel2 = this.addressLevel2,
addressLevel1 = this.addressLevel1,
postalCode = this.postalCode,
country = this.country,
tel = this.tel,
email = this.email
)
}

/**
* Conversion from a generic [UpdatableCreditCardFields] into its richer comrade within the 'autofill' lib.
*/
internal fun mozilla.components.concept.storage.UpdatableCreditCardFields.into(): UpdatableCreditCardFields {
return UpdatableCreditCardFields(
ccName = this.billingName,
ccNumber = this.cardNumber,
ccExpMonth = this.expiryMonth,
ccExpYear = this.expiryYear,
ccType = this.cardType
)
}

/**
* Conversion from a "native" autofill [Address] into its generic comrade.
*/
internal fun mozilla.appservices.autofill.Address.into(): Address {
return Address(
guid = this.guid,
givenName = this.givenName,
additionalName = this.additionalName,
familyName = this.familyName,
organization = this.organization,
streetAddress = this.streetAddress,
addressLevel3 = this.addressLevel3,
addressLevel2 = this.addressLevel2,
addressLevel1 = this.addressLevel1,
postalCode = this.postalCode,
country = this.country,
tel = this.tel,
email = this.email,
timeCreated = this.timeCreated,
timeLastUsed = this.timeLastUsed,
timeLastModified = this.timeLastModified,
timesUsed = this.timesUsed
)
}

/**
* Conversion from a "native" autofill [CreditCard] into its generic comrade.
*/
internal fun mozilla.appservices.autofill.CreditCard.into(): CreditCard {
return CreditCard(
guid = this.guid,
billingName = this.ccName,
cardNumber = this.ccNumber,
expiryMonth = this.ccExpMonth,
expiryYear = this.ccExpYear,
cardType = this.ccType,
timeCreated = this.timeCreated,
timeLastUsed = this.timeLastUsed,
timeLastModified = this.timeLastModified,
timesUsed = this.timesUsed
)
}
19 changes: 19 additions & 0 deletions components/service/sync-autofill/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# [Android Components](../../../README.md) > Service > Firefox Sync - Autofill

A library for autofilling addresses and credit cards based on `concept-storage` backed by [application-services' Autofill lib](https://github.com/mozilla/application-services).

## Usage

### Setting up the dependency

Use Gradle to download the library from [maven.mozilla.org](https://maven.mozilla.org/) ([Setup repository](../../../README.md#maven-repository)):

```Groovy
implementation "org.mozilla.components:service-sync-autofill:{latest-version}"
```

## License

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/
46 changes: 46 additions & 0 deletions components/service/sync-autofill/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion config.compileSdkVersion

defaultConfig {
minSdkVersion config.minSdkVersion
targetSdkVersion config.targetSdkVersion

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
api Dependencies.mozilla_sync_autofill

api project(':concept-storage')

implementation project(':support-utils')

implementation Dependencies.kotlin_stdlib

testImplementation project(':support-test')

testImplementation Dependencies.androidx_test_core
testImplementation Dependencies.androidx_test_junit
testImplementation Dependencies.testing_robolectric
testImplementation Dependencies.testing_mockito
testImplementation Dependencies.testing_coroutines
testImplementation Dependencies.mozilla_full_megazord_forUnitTests
}

apply from: '../../../publish.gradle'
ext.configurePublish(config.componentsGroupId, archivesBaseName, project.ext.description)
21 changes: 21 additions & 0 deletions components/service/sync-autofill/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
5 changes: 5 additions & 0 deletions components/service/sync-autofill/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mozilla.components.browser.storage.sync.autofill" />
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.browser.storage.sync
package mozilla.components.service.sync.autofill

import android.content.Context
import androidx.annotation.GuardedBy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.browser.storage.sync
package mozilla.components.service.sync.autofill

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.service.sync.autofill

import mozilla.components.concept.storage.Address
import mozilla.components.concept.storage.CreditCard
import mozilla.appservices.autofill.UpdatableAddressFields
import mozilla.appservices.autofill.UpdatableCreditCardFields

// We have type definitions at the concept level, and "external" types defined within Autofill.
// In practice these two types are largely the same, and this file is the conversion point.

/**
* Conversion from a generic [UpdatableAddressFields] into its richer comrade within the 'autofill' lib.
*/
internal fun mozilla.components.concept.storage.UpdatableAddressFields.into(): UpdatableAddressFields {
return UpdatableAddressFields(
givenName = this.givenName,
additionalName = this.additionalName,
familyName = this.familyName,
organization = this.organization,
streetAddress = this.streetAddress,
addressLevel3 = this.addressLevel3,
addressLevel2 = this.addressLevel2,
addressLevel1 = this.addressLevel1,
postalCode = this.postalCode,
country = this.country,
tel = this.tel,
email = this.email
)
}

/**
* Conversion from a generic [UpdatableCreditCardFields] into its richer comrade within the 'autofill' lib.
*/
internal fun mozilla.components.concept.storage.UpdatableCreditCardFields.into(): UpdatableCreditCardFields {
return UpdatableCreditCardFields(
ccName = this.billingName,
ccNumber = this.cardNumber,
ccExpMonth = this.expiryMonth,
ccExpYear = this.expiryYear,
ccType = this.cardType
)
}

/**
* Conversion from a "native" autofill [Address] into its generic comrade.
*/
internal fun mozilla.appservices.autofill.Address.into(): Address {
return Address(
guid = this.guid,
givenName = this.givenName,
additionalName = this.additionalName,
familyName = this.familyName,
organization = this.organization,
streetAddress = this.streetAddress,
addressLevel3 = this.addressLevel3,
addressLevel2 = this.addressLevel2,
addressLevel1 = this.addressLevel1,
postalCode = this.postalCode,
country = this.country,
tel = this.tel,
email = this.email,
timeCreated = this.timeCreated,
timeLastUsed = this.timeLastUsed,
timeLastModified = this.timeLastModified,
timesUsed = this.timesUsed
)
}

/**
* Conversion from a "native" autofill [CreditCard] into its generic comrade.
*/
internal fun mozilla.appservices.autofill.CreditCard.into(): CreditCard {
return CreditCard(
guid = this.guid,
billingName = this.ccName,
cardNumber = this.ccNumber,
expiryMonth = this.ccExpMonth,
expiryYear = this.ccExpYear,
cardType = this.ccType,
timeCreated = this.timeCreated,
timeLastUsed = this.timeLastUsed,
timeLastModified = this.timeLastModified,
timesUsed = this.timesUsed
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.browser.storage.sync
package mozilla.components.service.sync.autofill

import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.runBlocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.browser.storage.sync
package mozilla.components.service.sync.autofill

import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdk=28
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ permalink: /changelog/
* **feature-top-sites**
* ⚠️ **This is a breaking change**: Replace `TopSitesUseCases.renameTopSites` with `TopSitesUseCases.updateTopSites` which allows for updating the title and the url of a top site. [#9599](https://github.com/mozilla-mobile/android-components/issues/9599)

* **service-sync-autofill**
* Refactors `AutofillCreditCardsAddressesStorage` from **browser-storage-sync** into its own component. [#9801](https://github.com/mozilla-mobile/android-components/issues/9801)

# 73.0.0

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

0 comments on commit 32ef7ce

Please sign in to comment.