diff --git a/components/feature/addons/src/main/java/mozilla/components/feature/addons/migration/SupportedAddonsChecker.kt b/components/feature/addons/src/main/java/mozilla/components/feature/addons/migration/SupportedAddonsChecker.kt index 61211851fbf..412a8474765 100644 --- a/components/feature/addons/src/main/java/mozilla/components/feature/addons/migration/SupportedAddonsChecker.kt +++ b/components/feature/addons/src/main/java/mozilla/components/feature/addons/migration/SupportedAddonsChecker.kt @@ -25,12 +25,12 @@ import kotlinx.coroutines.withContext import mozilla.components.concept.engine.webextension.EnableSource import mozilla.components.feature.addons.Addon import mozilla.components.feature.addons.R -import mozilla.components.feature.addons.migration.SupportedAddonsChecker.Frequency import mozilla.components.feature.addons.ui.translateName import mozilla.components.feature.addons.update.GlobalAddonDependencyProvider import mozilla.components.feature.addons.worker.shouldReport import mozilla.components.support.base.ids.SharedIdsHelper import mozilla.components.support.base.log.logger.Logger +import mozilla.components.support.base.worker.Frequency import mozilla.components.support.ktx.android.content.appName import mozilla.components.support.ktx.android.notification.ChannelData import mozilla.components.support.ktx.android.notification.ensureNotificationChannelExists @@ -50,13 +50,6 @@ interface SupportedAddonsChecker { * Unregisters for periodic checks for new available add-ons. */ fun unregisterForChecks() - - /** - * Indicates how often checks for newly supported add-ons should happen. - * @property repeatInterval Integer indicating how often the update should happen. - * @property repeatIntervalTimeUnit The time unit of the [repeatInterval]. - */ - data class Frequency(val repeatInterval: Long, val repeatIntervalTimeUnit: TimeUnit) } /** diff --git a/components/feature/addons/src/main/java/mozilla/components/feature/addons/update/AddonUpdater.kt b/components/feature/addons/src/main/java/mozilla/components/feature/addons/update/AddonUpdater.kt index b344f461bc3..bba6f800bed 100644 --- a/components/feature/addons/src/main/java/mozilla/components/feature/addons/update/AddonUpdater.kt +++ b/components/feature/addons/src/main/java/mozilla/components/feature/addons/update/AddonUpdater.kt @@ -35,12 +35,12 @@ import mozilla.components.concept.engine.webextension.WebExtensionException import mozilla.components.concept.engine.webextension.isUnsupported import mozilla.components.feature.addons.Addon import mozilla.components.feature.addons.R -import mozilla.components.feature.addons.update.AddonUpdater.Frequency import mozilla.components.feature.addons.update.db.UpdateAttemptsDatabase import mozilla.components.feature.addons.update.db.toEntity import mozilla.components.feature.addons.worker.shouldReport import mozilla.components.support.base.ids.SharedIdsHelper import mozilla.components.support.base.log.logger.Logger +import mozilla.components.support.base.worker.Frequency import mozilla.components.support.ktx.android.notification.ChannelData import mozilla.components.support.ktx.android.notification.ensureNotificationChannelExists import mozilla.components.support.utils.PendingIntentUtils @@ -134,13 +134,6 @@ interface AddonUpdater { data class Error(val message: String, val exception: Throwable) : Status() } - /** - * Indicates how often an extension should be updated. - * @property repeatInterval Integer indicating how often the update should happen. - * @property repeatIntervalTimeUnit The time unit of the [repeatInterval]. - */ - class Frequency(val repeatInterval: Long, val repeatIntervalTimeUnit: TimeUnit) - /** * Represents an attempt to update an add-on. */ diff --git a/components/feature/addons/src/test/java/mozilla/components/feature/addons/migration/DefaultSupportedAddonCheckerTest.kt b/components/feature/addons/src/test/java/mozilla/components/feature/addons/migration/DefaultSupportedAddonCheckerTest.kt index a6f9a240672..de88150ea61 100644 --- a/components/feature/addons/src/test/java/mozilla/components/feature/addons/migration/DefaultSupportedAddonCheckerTest.kt +++ b/components/feature/addons/src/test/java/mozilla/components/feature/addons/migration/DefaultSupportedAddonCheckerTest.kt @@ -20,7 +20,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker.Companion.CHECKER_UNIQUE_PERIODIC_WORK_NAME import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker.Companion.WORK_TAG_PERIODIC -import mozilla.components.feature.addons.migration.SupportedAddonsChecker.Frequency +import mozilla.components.support.base.worker.Frequency import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.rule.MainCoroutineRule diff --git a/components/feature/addons/src/test/java/mozilla/components/feature/addons/update/DefaultAddonUpdaterTest.kt b/components/feature/addons/src/test/java/mozilla/components/feature/addons/update/DefaultAddonUpdaterTest.kt index 0e87d0cc92a..1c17497e888 100644 --- a/components/feature/addons/src/test/java/mozilla/components/feature/addons/update/DefaultAddonUpdaterTest.kt +++ b/components/feature/addons/src/test/java/mozilla/components/feature/addons/update/DefaultAddonUpdaterTest.kt @@ -24,11 +24,11 @@ import kotlinx.coroutines.runBlocking import mozilla.components.concept.engine.webextension.DisabledFlags import mozilla.components.concept.engine.webextension.Metadata import mozilla.components.concept.engine.webextension.WebExtension -import mozilla.components.feature.addons.update.AddonUpdater.Frequency import mozilla.components.feature.addons.update.AddonUpdaterWorker.Companion.KEY_DATA_EXTENSIONS_ID import mozilla.components.feature.addons.update.DefaultAddonUpdater.Companion.WORK_TAG_IMMEDIATE import mozilla.components.feature.addons.update.DefaultAddonUpdater.Companion.WORK_TAG_PERIODIC import mozilla.components.feature.addons.update.DefaultAddonUpdater.NotificationHandlerService +import mozilla.components.support.base.worker.Frequency import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.rule.MainCoroutineRule diff --git a/components/service/contile/src/main/java/mozilla/components/service/contile/ContileTopSitesUpdater.kt b/components/service/contile/src/main/java/mozilla/components/service/contile/ContileTopSitesUpdater.kt index ec9f39f317f..c125f829b21 100644 --- a/components/service/contile/src/main/java/mozilla/components/service/contile/ContileTopSitesUpdater.kt +++ b/components/service/contile/src/main/java/mozilla/components/service/contile/ContileTopSitesUpdater.kt @@ -12,6 +12,7 @@ import androidx.work.NetworkType import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager import mozilla.components.support.base.log.logger.Logger +import mozilla.components.support.base.worker.Frequency import java.util.concurrent.TimeUnit /** @@ -78,14 +79,3 @@ class ContileTopSitesUpdater( internal const val PERIODIC_WORK_TAG = "mozilla.components.service.contile.periodicWork" } } - -/** - * Indicates how often Contile top sites should be updated. - * - * @property repeatInterval Long indicating how often the update should happen. - * @property repeatIntervalTimeUnit The time unit of the [repeatInterval]. - */ -data class Frequency( - val repeatInterval: Long, - val repeatIntervalTimeUnit: TimeUnit -) diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStoriesConfig.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStoriesConfig.kt index 41be9340d89..05db3eb329f 100644 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStoriesConfig.kt +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/PocketStoriesConfig.kt @@ -5,6 +5,7 @@ package mozilla.components.service.pocket import mozilla.components.concept.fetch.Client +import mozilla.components.support.base.worker.Frequency import java.util.concurrent.TimeUnit internal const val DEFAULT_REFRESH_INTERVAL = 4L @@ -24,11 +25,3 @@ class PocketStoriesConfig( DEFAULT_REFRESH_TIMEUNIT ) ) - -/** - * Indicates how often the pocket stories should be refreshed. - * - * @param repeatInterval Integer indicating how often the update should happen. - * @param repeatIntervalTimeUnit The time unit of the [repeatInterval]. - */ -class Frequency(val repeatInterval: Long, val repeatIntervalTimeUnit: TimeUnit) diff --git a/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/update/PocketStoriesRefreshScheduler.kt b/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/update/PocketStoriesRefreshScheduler.kt index 8a9d4b54331..b9eb2c5aa54 100644 --- a/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/update/PocketStoriesRefreshScheduler.kt +++ b/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/update/PocketStoriesRefreshScheduler.kt @@ -12,10 +12,10 @@ import androidx.work.NetworkType import androidx.work.PeriodicWorkRequest import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager -import mozilla.components.service.pocket.Frequency import mozilla.components.service.pocket.PocketStoriesConfig import mozilla.components.service.pocket.logger import mozilla.components.service.pocket.stories.update.RefreshPocketWorker.Companion.REFRESH_WORK_TAG +import mozilla.components.support.base.worker.Frequency /** * Class used to schedule Pocket recommended stories refresh. diff --git a/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoriesConfigTest.kt b/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoriesConfigTest.kt index 298ef681793..a130193562f 100644 --- a/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoriesConfigTest.kt +++ b/components/service/pocket/src/test/java/mozilla/components/service/pocket/PocketStoriesConfigTest.kt @@ -6,6 +6,7 @@ package mozilla.components.service.pocket import androidx.test.ext.junit.runners.AndroidJUnit4 import mozilla.components.service.pocket.helpers.assertClassVisibility +import mozilla.components.support.base.worker.Frequency import mozilla.components.support.test.mock import org.junit.Assert.assertEquals import org.junit.Test diff --git a/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/update/PocketStoriesRefreshSchedulerTest.kt b/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/update/PocketStoriesRefreshSchedulerTest.kt index 2cdb0db683f..c791a7370d6 100644 --- a/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/update/PocketStoriesRefreshSchedulerTest.kt +++ b/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/update/PocketStoriesRefreshSchedulerTest.kt @@ -10,10 +10,10 @@ import androidx.work.NetworkType import androidx.work.PeriodicWorkRequest import androidx.work.WorkManager import mozilla.components.lib.fetch.httpurlconnection.HttpURLConnectionClient -import mozilla.components.service.pocket.Frequency import mozilla.components.service.pocket.PocketStoriesConfig import mozilla.components.service.pocket.helpers.assertClassVisibility import mozilla.components.service.pocket.stories.update.RefreshPocketWorker.Companion.REFRESH_WORK_TAG +import mozilla.components.support.base.worker.Frequency import mozilla.components.support.test.any import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext diff --git a/components/support/base/src/main/java/mozilla/components/support/base/worker/Frequency.kt b/components/support/base/src/main/java/mozilla/components/support/base/worker/Frequency.kt new file mode 100644 index 00000000000..58ac36c8126 --- /dev/null +++ b/components/support/base/src/main/java/mozilla/components/support/base/worker/Frequency.kt @@ -0,0 +1,18 @@ +/* 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.support.base.worker + +import java.util.concurrent.TimeUnit + +/** + * Indicates how often the work request should be run. + * + * @property repeatInterval Long indicating how often the update should happen. + * @property repeatIntervalTimeUnit The time unit of [repeatInterval]. + */ +data class Frequency( + val repeatInterval: Long, + val repeatIntervalTimeUnit: TimeUnit +) diff --git a/docs/changelog.md b/docs/changelog.md index 5891c0e230f..f4391f040f1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,6 +13,10 @@ permalink: /changelog/ * **feature-top-sites** * ⚠️ **This is a breaking change**: This changes `fetchProvidedTopSites` in `TopSitesConfig` into a data class `TopSitesProviderConfig` that specifies whether or not to display the top sites from the provider. [#11654](https://github.com/mozilla-mobile/android-components/issues/11654) + +* **support-base** + * ⚠️ **This is a breaking change**: Refactor `Frequency` out of **feature-addons** and **service-pocket** [#11732](https://github.com/mozilla-mobile/android-components/pull/11732). + * **support-utils** * 🌟️️ **Added new Browsers constant for Fennec `Browsers.FIREFOX_FENNEC_NIGHTLY`. * ⚠️ **This is a breaking change**: `Browsers.FIREFOX_NIGHTLY` now points to `org.mozilla.fenix`, for fennec nightly use `Browsers.FIREFOX_FENNEC_NIGHTLY` [#11682](https://github.com/mozilla-mobile/android-components/pull/11682). diff --git a/samples/browser/build.gradle b/samples/browser/build.gradle index a5dc12a6647..a4b987c0899 100644 --- a/samples/browser/build.gradle +++ b/samples/browser/build.gradle @@ -127,6 +127,7 @@ dependencies { implementation project(':service-digitalassetlinks') implementation project(':service-sync-logins') + implementation project(':support-base') implementation project(':support-utils') implementation project(':support-ktx') implementation project(':support-webextensions') diff --git a/samples/browser/src/main/java/org/mozilla/samples/browser/DefaultComponents.kt b/samples/browser/src/main/java/org/mozilla/samples/browser/DefaultComponents.kt index ba5ada344de..c6686b795a2 100644 --- a/samples/browser/src/main/java/org/mozilla/samples/browser/DefaultComponents.kt +++ b/samples/browser/src/main/java/org/mozilla/samples/browser/DefaultComponents.kt @@ -37,8 +37,6 @@ import mozilla.components.concept.fetch.Client import mozilla.components.feature.addons.AddonManager import mozilla.components.feature.addons.amo.AddonCollectionProvider import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker -import mozilla.components.feature.addons.migration.SupportedAddonsChecker -import mozilla.components.feature.addons.update.AddonUpdater import mozilla.components.feature.addons.update.DefaultAddonUpdater import mozilla.components.feature.app.links.AppLinksInterceptor import mozilla.components.feature.app.links.AppLinksUseCases @@ -78,6 +76,7 @@ import mozilla.components.service.digitalassetlinks.local.StatementApi import mozilla.components.service.digitalassetlinks.local.StatementRelationChecker import mozilla.components.service.location.LocationService import mozilla.components.service.sync.logins.SyncableLoginsStorage +import mozilla.components.support.base.worker.Frequency import org.mozilla.samples.browser.addons.AddonsActivity import org.mozilla.samples.browser.autofill.AutofillConfirmActivity import org.mozilla.samples.browser.autofill.AutofillSearchActivity @@ -129,7 +128,7 @@ open class DefaultComponents(private val applicationContext: Context) { } val addonUpdater = - DefaultAddonUpdater(applicationContext, AddonUpdater.Frequency(1, TimeUnit.DAYS)) + DefaultAddonUpdater(applicationContext, Frequency(1, TimeUnit.DAYS)) // Engine open val engine: Engine by lazy { @@ -190,7 +189,7 @@ open class DefaultComponents(private val applicationContext: Context) { } val supportedAddonsChecker by lazy { - DefaultSupportedAddonsChecker(applicationContext, SupportedAddonsChecker.Frequency(1, TimeUnit.DAYS)) + DefaultSupportedAddonsChecker(applicationContext, Frequency(1, TimeUnit.DAYS)) } val searchUseCases by lazy {