Components.kt 4.4 KB
Newer Older
Jeff Boek's avatar
Jeff Boek committed
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2 3
 * 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/. */
Jeff Boek's avatar
Jeff Boek committed
4

5 6 7
package org.mozilla.fenix.components

import android.content.Context
8
import android.content.Intent
9
import androidx.core.content.getSystemService
10
import androidx.core.net.toUri
Gabriel Luong's avatar
Gabriel Luong committed
11 12
import mozilla.components.feature.addons.AddonManager
import mozilla.components.feature.addons.amo.AddonCollectionProvider
13 14
import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
import mozilla.components.feature.addons.migration.SupportedAddonsChecker
Gabriel Luong's avatar
Gabriel Luong committed
15 16
import mozilla.components.feature.addons.update.AddonUpdater
import mozilla.components.feature.addons.update.DefaultAddonUpdater
17
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
18
import mozilla.components.support.migration.state.MigrationStore
19
import org.mozilla.fenix.BuildConfig
20
import org.mozilla.fenix.HomeActivity
21
import org.mozilla.fenix.components.metrics.AppStartupTelemetry
22
import org.mozilla.fenix.utils.ClipboardHandler
23
import org.mozilla.fenix.utils.Mockable
24
import org.mozilla.fenix.utils.Settings
25
import org.mozilla.fenix.wifi.WifiConnectionMonitor
Gabriel Luong's avatar
Gabriel Luong committed
26 27 28
import java.util.concurrent.TimeUnit

private const val DAY_IN_MINUTES = 24 * 60L
29 30 31 32

/**
 * Provides access to all components.
 */
33
@Mockable
34
class Components(private val context: Context) {
35
    val backgroundServices by lazy {
36 37
        BackgroundServices(
            context,
38
            push,
39
            analytics.crashReporter,
40 41
            core.lazyHistoryStorage,
            core.lazyBookmarksStorage,
42 43
            core.lazyPasswordsStorage,
            core.lazyRemoteTabsStorage
44
        )
45
    }
Grisha Kruglov's avatar
Grisha Kruglov committed
46
    val services by lazy { Services(context, backgroundServices.accountManager) }
47
    val core by lazy { Core(context, analytics.crashReporter) }
48
    val search by lazy { Search(context) }
49
    val useCases by lazy {
50 51
        UseCases(
            context,
52
            core.engine,
53 54 55
            core.sessionManager,
            core.store,
            search.searchEngineManager,
56 57
            core.webAppShortcutManager,
            core.topSiteStorage
58
        )
59
    }
60
    val intentProcessors by lazy {
61 62 63 64 65
        IntentProcessors(
            context,
            core.sessionManager,
            useCases.sessionUseCases,
            useCases.searchUseCases,
Tiger Oakes's avatar
Tiger Oakes committed
66
            core.relationChecker,
67
            core.customTabsStore,
68 69
            migrationStore,
            core.webAppManifestStorage
70
        )
71
    }
Gabriel Luong's avatar
Gabriel Luong committed
72 73

    val addonCollectionProvider by lazy {
74 75 76 77 78 79 80 81 82 83
        if (!BuildConfig.AMO_COLLECTION.isNullOrEmpty()) {
            AddonCollectionProvider(
                context,
                core.client,
                collectionName = BuildConfig.AMO_COLLECTION,
                maxCacheAgeInMinutes = DAY_IN_MINUTES
            )
        } else {
            AddonCollectionProvider(context, core.client, maxCacheAgeInMinutes = DAY_IN_MINUTES)
        }
Gabriel Luong's avatar
Gabriel Luong committed
84 85
    }

86
    val appStartupTelemetry by lazy { AppStartupTelemetry(analytics.metrics) }
87

88
    @Suppress("MagicNumber")
Gabriel Luong's avatar
Gabriel Luong committed
89
    val addonUpdater by lazy {
90
        DefaultAddonUpdater(context, AddonUpdater.Frequency(12, TimeUnit.HOURS))
Gabriel Luong's avatar
Gabriel Luong committed
91 92
    }

93
    @Suppress("MagicNumber")
94
    val supportedAddonsChecker by lazy {
95
        DefaultSupportedAddonsChecker(context, SupportedAddonsChecker.Frequency(12, TimeUnit.HOURS),
96 97 98
            onNotificationClickIntent = Intent(context, HomeActivity::class.java).apply {
                action = Intent.ACTION_VIEW
                flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
99
                data = "${BuildConfig.DEEP_LINK_SCHEME}://settings_addon_manager".toUri()
100 101 102 103
            }
        )
    }

Gabriel Luong's avatar
Gabriel Luong committed
104 105 106 107
    val addonManager by lazy {
        AddonManager(core.store, core.engine, addonCollectionProvider, addonUpdater)
    }

108
    val analytics by lazy { Analytics(context) }
109
    val publicSuffixList by lazy { PublicSuffixList(context) }
110
    val clipboardHandler by lazy { ClipboardHandler(context) }
111
    val migrationStore by lazy { MigrationStore() }
112
    val performance by lazy { PerformanceComponent() }
113
    val push by lazy { Push(context, analytics.crashReporter) }
114
    val wifiConnectionMonitor by lazy { WifiConnectionMonitor(context.getSystemService()!!) }
115 116

    val settings by lazy { Settings(context) }
117 118 119 120 121 122 123

    val reviewPromptController by lazy {
        ReviewPromptController(
            context,
            FenixReviewSettings(settings)
        )
    }
124
}