From 768f2b7498ca548fa03b4bf7c70556ddaa1b3b3e Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Mon, 8 Mar 2021 23:15:49 -0500 Subject: [PATCH] Issue #9801: Refactor AutofillCreditCardsAddressesStorage into its own :service-sync-autofill component --- .buildconfig.yml | 4 + README.md | 2 + components/browser/storage-sync/build.gradle | 2 - .../components/browser/storage/sync/Types.kt | 87 +----------------- components/service/sync-autofill/README.md | 19 ++++ components/service/sync-autofill/build.gradle | 46 ++++++++++ .../service/sync-autofill/proguard-rules.pro | 21 +++++ .../src/main/AndroidManifest.xml | 5 ++ .../AutofillCreditCardsAddressesStorage.kt | 2 +- ...eckoCreditCardsAddressesStorageDelegate.kt | 2 +- .../components/service/sync/autofill/Types.kt | 89 +++++++++++++++++++ ...AutofillCreditCardsAddressesStorageTest.kt | 2 +- ...CreditCardsAddressesStorageDelegateTest.kt | 2 +- .../org.mockito.plugins.MockMaker | 1 + .../src/test/resources/robolectric.properties | 1 + docs/changelog.md | 3 + taskcluster/ci/config.yml | 1 + 17 files changed, 199 insertions(+), 90 deletions(-) create mode 100644 components/service/sync-autofill/README.md create mode 100644 components/service/sync-autofill/build.gradle create mode 100644 components/service/sync-autofill/proguard-rules.pro create mode 100644 components/service/sync-autofill/src/main/AndroidManifest.xml rename components/{browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync => service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill}/AutofillCreditCardsAddressesStorage.kt (98%) rename components/{browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync => service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill}/GeckoCreditCardsAddressesStorageDelegate.kt (96%) create mode 100644 components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/Types.kt rename components/{browser/storage-sync/src/test/java/mozilla/components/browser/storage/sync => service/sync-autofill/src/test/java/mozilla/components/service/sync/autofill}/AutofillCreditCardsAddressesStorageTest.kt (99%) rename components/{browser/storage-sync/src/test/java/mozilla/components/browser/storage/sync => service/sync-autofill/src/test/java/mozilla/components/service/sync/autofill}/GeckoCreditCardsAddressesStorageDelegateTest.kt (97%) create mode 100644 components/service/sync-autofill/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker create mode 100644 components/service/sync-autofill/src/test/resources/robolectric.properties diff --git a/.buildconfig.yml b/.buildconfig.yml index f49bca8a067..0ef57428e2b 100644 --- a/.buildconfig.yml +++ b/.buildconfig.yml @@ -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.' diff --git a/README.md b/README.md index 5a43bd8679e..5d63c477dea 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/components/browser/storage-sync/build.gradle b/components/browser/storage-sync/build.gradle index 4de85e228a9..8766b3eede6 100644 --- a/components/browser/storage-sync/build.gradle +++ b/components/browser/storage-sync/build.gradle @@ -32,7 +32,6 @@ dependencies { } api Dependencies.mozilla_remote_tabs - api Dependencies.mozilla_sync_autofill api project(':concept-storage') api project(':concept-sync') @@ -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 diff --git a/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/Types.kt b/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/Types.kt index d4a68d92282..8283745de4b 100644 --- a/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/Types.kt +++ b/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/Types.kt @@ -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 @@ -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. @@ -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 - ) -} diff --git a/components/service/sync-autofill/README.md b/components/service/sync-autofill/README.md new file mode 100644 index 00000000000..e537e84a99b --- /dev/null +++ b/components/service/sync-autofill/README.md @@ -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/ diff --git a/components/service/sync-autofill/build.gradle b/components/service/sync-autofill/build.gradle new file mode 100644 index 00000000000..1fa9ef908d5 --- /dev/null +++ b/components/service/sync-autofill/build.gradle @@ -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) diff --git a/components/service/sync-autofill/proguard-rules.pro b/components/service/sync-autofill/proguard-rules.pro new file mode 100644 index 00000000000..f1b424510da --- /dev/null +++ b/components/service/sync-autofill/proguard-rules.pro @@ -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 diff --git a/components/service/sync-autofill/src/main/AndroidManifest.xml b/components/service/sync-autofill/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..fae515622e8 --- /dev/null +++ b/components/service/sync-autofill/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + diff --git a/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/AutofillCreditCardsAddressesStorage.kt b/components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/AutofillCreditCardsAddressesStorage.kt similarity index 98% rename from components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/AutofillCreditCardsAddressesStorage.kt rename to components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/AutofillCreditCardsAddressesStorage.kt index 6ac88766ab8..64250a9d5b8 100644 --- a/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/AutofillCreditCardsAddressesStorage.kt +++ b/components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/AutofillCreditCardsAddressesStorage.kt @@ -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 diff --git a/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/GeckoCreditCardsAddressesStorageDelegate.kt b/components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/GeckoCreditCardsAddressesStorageDelegate.kt similarity index 96% rename from components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/GeckoCreditCardsAddressesStorageDelegate.kt rename to components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/GeckoCreditCardsAddressesStorageDelegate.kt index 23c9386e150..ec4db0da93b 100644 --- a/components/browser/storage-sync/src/main/java/mozilla/components/browser/storage/sync/GeckoCreditCardsAddressesStorageDelegate.kt +++ b/components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/GeckoCreditCardsAddressesStorageDelegate.kt @@ -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 diff --git a/components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/Types.kt b/components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/Types.kt new file mode 100644 index 00000000000..475382e4bac --- /dev/null +++ b/components/service/sync-autofill/src/main/java/mozilla/components/service/sync/autofill/Types.kt @@ -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 + ) +} diff --git a/components/browser/storage-sync/src/test/java/mozilla/components/browser/storage/sync/AutofillCreditCardsAddressesStorageTest.kt b/components/service/sync-autofill/src/test/java/mozilla/components/service/sync/autofill/AutofillCreditCardsAddressesStorageTest.kt similarity index 99% rename from components/browser/storage-sync/src/test/java/mozilla/components/browser/storage/sync/AutofillCreditCardsAddressesStorageTest.kt rename to components/service/sync-autofill/src/test/java/mozilla/components/service/sync/autofill/AutofillCreditCardsAddressesStorageTest.kt index 33cf0877ef5..ad094baa1ad 100644 --- a/components/browser/storage-sync/src/test/java/mozilla/components/browser/storage/sync/AutofillCreditCardsAddressesStorageTest.kt +++ b/components/service/sync-autofill/src/test/java/mozilla/components/service/sync/autofill/AutofillCreditCardsAddressesStorageTest.kt @@ -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 diff --git a/components/browser/storage-sync/src/test/java/mozilla/components/browser/storage/sync/GeckoCreditCardsAddressesStorageDelegateTest.kt b/components/service/sync-autofill/src/test/java/mozilla/components/service/sync/autofill/GeckoCreditCardsAddressesStorageDelegateTest.kt similarity index 97% rename from components/browser/storage-sync/src/test/java/mozilla/components/browser/storage/sync/GeckoCreditCardsAddressesStorageDelegateTest.kt rename to components/service/sync-autofill/src/test/java/mozilla/components/service/sync/autofill/GeckoCreditCardsAddressesStorageDelegateTest.kt index 3ed32277cd9..5c10396b39e 100644 --- a/components/browser/storage-sync/src/test/java/mozilla/components/browser/storage/sync/GeckoCreditCardsAddressesStorageDelegateTest.kt +++ b/components/service/sync-autofill/src/test/java/mozilla/components/service/sync/autofill/GeckoCreditCardsAddressesStorageDelegateTest.kt @@ -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 diff --git a/components/service/sync-autofill/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/components/service/sync-autofill/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 00000000000..ca6ee9cea8e --- /dev/null +++ b/components/service/sync-autofill/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file diff --git a/components/service/sync-autofill/src/test/resources/robolectric.properties b/components/service/sync-autofill/src/test/resources/robolectric.properties new file mode 100644 index 00000000000..89a6c8b4c2e --- /dev/null +++ b/components/service/sync-autofill/src/test/resources/robolectric.properties @@ -0,0 +1 @@ +sdk=28 \ No newline at end of file diff --git a/docs/changelog.md b/docs/changelog.md index 067c279a145..404ce71b3cf 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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) diff --git a/taskcluster/ci/config.yml b/taskcluster/ci/config.yml index 3c5f7b8c7c8..79182003413 100644 --- a/taskcluster/ci/config.yml +++ b/taskcluster/ci/config.yml @@ -97,6 +97,7 @@ treeherder: service-location: service-location service-nimbus: service-nimbus service-pocket: service-pocket + service-sync-autofill: service-sync-autofill service-sync-logins: service-sync-logins support-android-test: support-android-test support-base: support-base