Components.kt 4.78 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
package org.mozilla.fenix.components

7
import android.app.Application
8
import android.content.Context
9
10
import android.content.Intent
import androidx.core.net.toUri
Gabriel Luong's avatar
Gabriel Luong committed
11
import mozilla.components.feature.addons.AddonManager
12
13
import mozilla.components.feature.addons.migration.DefaultSupportedAddonsChecker
import mozilla.components.feature.addons.migration.SupportedAddonsChecker
Gabriel Luong's avatar
Gabriel Luong committed
14
15
import mozilla.components.feature.addons.update.AddonUpdater
import mozilla.components.feature.addons.update.DefaultAddonUpdater
16
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
17
import mozilla.components.support.migration.state.MigrationStore
18
import org.mozilla.fenix.BuildConfig
19
import org.mozilla.fenix.Config
20
import org.mozilla.fenix.HomeActivity
21
import org.mozilla.fenix.perf.StrictModeManager
22
import org.mozilla.fenix.components.metrics.AppStartupTelemetry
23
import org.mozilla.fenix.ext.settings
24
import org.mozilla.fenix.perf.lazyMonitored
Matthew Finkel's avatar
Matthew Finkel committed
25
import org.mozilla.fenix.tor.TorController
26
import org.mozilla.fenix.utils.ClipboardHandler
27
import org.mozilla.fenix.utils.Mockable
28
import org.mozilla.fenix.utils.Settings
29
import org.mozilla.fenix.wifi.WifiConnectionMonitor
Gabriel Luong's avatar
Gabriel Luong committed
30
31
32
import java.util.concurrent.TimeUnit

private const val DAY_IN_MINUTES = 24 * 60L
33
34

/**
35
36
37
38
39
 * Provides access to all components. This class is an implementation of the Service Locator
 * pattern, which helps us manage the dependencies in our app.
 *
 * Note: these aren't just "components" from "android-components": they're any "component" that
 * can be considered a building block of our app.
40
 */
41
@Mockable
42
class Components(private val context: Context) {
43
    val backgroundServices by lazyMonitored {
44
45
        BackgroundServices(
            context,
46
            push,
47
            analytics.crashReporter,
48
49
            core.lazyHistoryStorage,
            core.lazyBookmarksStorage,
50
            core.lazyPasswordsStorage,
51
52
            core.lazyRemoteTabsStorage,
            strictMode
53
        )
54
    }
55
56
57
58
    val services by lazyMonitored { Services(context, backgroundServices.accountManager) }
    val core by lazyMonitored { Core(context, analytics.crashReporter, strictMode) }
    val search by lazyMonitored { Search(context) }
    val useCases by lazyMonitored {
59
60
        UseCases(
            context,
61
            core.engine,
62
63
64
            core.sessionManager,
            core.store,
            search.searchEngineManager,
65
            core.webAppShortcutManager,
66
            core.topSitesStorage
67
        )
68
    }
69
    val intentProcessors by lazyMonitored {
70
71
72
73
74
        IntentProcessors(
            context,
            core.sessionManager,
            useCases.sessionUseCases,
            useCases.searchUseCases,
Tiger Oakes's avatar
Tiger Oakes committed
75
            core.relationChecker,
76
            core.customTabsStore,
77
78
            migrationStore,
            core.webAppManifestStorage
79
        )
80
    }
Gabriel Luong's avatar
Gabriel Luong committed
81

82
    val addonCollectionProvider by lazyMonitored {
Alex Catarineu's avatar
Alex Catarineu committed
83
        TorAddonCollectionProvider(context, core.client)
Gabriel Luong's avatar
Gabriel Luong committed
84
85
    }

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

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

93
    @Suppress("MagicNumber")
94
    val supportedAddonsChecker by lazyMonitored {
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
Matthew Finkel's avatar
Matthew Finkel committed
99
                data = "${BuildConfig.DEEP_LINK_SCHEME}://settings_addon_manager".toUri()
100
101
102
103
            }
        )
    }

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

108
109
110
111
112
113
114
115
    val analytics by lazyMonitored { Analytics(context) }
    val publicSuffixList by lazyMonitored { PublicSuffixList(context) }
    val clipboardHandler by lazyMonitored { ClipboardHandler(context) }
    val migrationStore by lazyMonitored { MigrationStore() }
    val performance by lazyMonitored { PerformanceComponent() }
    val push by lazyMonitored { Push(context, analytics.crashReporter) }
    val wifiConnectionMonitor by lazyMonitored { WifiConnectionMonitor(context as Application) }
    val strictMode by lazyMonitored { StrictModeManager(Config, this) }
116

117
    val settings by lazyMonitored { Settings(context) }
118

119
    val reviewPromptController by lazyMonitored {
120
121
122
123
124
        ReviewPromptController(
            context,
            FenixReviewSettings(settings)
        )
    }
Matthew Finkel's avatar
Matthew Finkel committed
125
126

    val torController by lazyMonitored { TorController(context) }
127
}