Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ package org.mozilla.reference.browser

import android.app.Application
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import mozilla.components.browser.state.action.SystemAction
import mozilla.components.concept.engine.webextension.isUnsupported
Expand All @@ -27,7 +30,20 @@ import org.mozilla.reference.browser.push.PushFxaIntegration
import org.mozilla.reference.browser.push.WebPushEngineIntegration

open class BrowserApplication : Application() {
val components by lazy { Components(this) }
/**
* Scope for long-running work that must outlive any individual activity. [SupervisorJob] keeps a failure in one
* child from cancelling the others.
*/
private val applicationScope: CoroutineScope =
CoroutineScope(
SupervisorJob() +
Dispatchers.Main +
CoroutineExceptionHandler { _, throwable ->
Logger.error("ApplicationScope: Unhandled error: ${throwable.message}", throwable)
}
)

val components by lazy { Components(this, applicationScope) }

override fun onCreate() {
super.onCreate()
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/org/mozilla/reference/browser/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.mozilla.reference.browser
import android.annotation.SuppressLint
import android.content.Context
import androidx.core.app.NotificationManagerCompat
import kotlinx.coroutines.CoroutineScope
import mozilla.components.feature.autofill.AutofillConfiguration
import mozilla.components.feature.downloads.DefaultFileSizeFormatter
import mozilla.components.feature.downloads.DownloadEstimator
Expand All @@ -26,8 +27,11 @@ import org.mozilla.reference.browser.components.UseCases
import org.mozilla.reference.browser.components.Utilities

/** Provides access to all components. */
class Components(private val context: Context) {
val core by lazy { Core(context, analytics.crashReporter) }
class Components(
private val context: Context,
val applicationScope: CoroutineScope,
) {
val core by lazy { Core(context, analytics.crashReporter, applicationScope) }
val useCases by lazy {
UseCases(
context,
Expand All @@ -45,6 +49,7 @@ class Components(private val context: Context) {
core.lazyHistoryStorage,
core.lazyRemoteTabsStorage,
core.lazyLoginsStorage,
applicationScope,
)
}
val analytics by lazy { Analytics(context) }
Expand All @@ -56,6 +61,7 @@ class Components(private val context: Context) {
useCases.searchUseCases,
useCases.tabsUseCases,
useCases.customTabsUseCases,
applicationScope,
)
}
val services by lazy { Services(context, backgroundServices.accountManager, useCases.tabsUseCases) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import org.mozilla.reference.browser.ext.components

class AutofillService : AbstractAutofillService() {
override val configuration: AutofillConfiguration by lazy { components.autofillConfiguration }
override val applicationScope by lazy { components.applicationScope }
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BackgroundServices(
placesHistoryStorage: Lazy<PlacesHistoryStorage>,
remoteTabsStorage: Lazy<RemoteTabsStorage>,
loginsStorage: Lazy<SyncableLoginsStorage>,
applicationScope: CoroutineScope,
) {
companion object {
const val CLIENT_ID = "3c49430b43dfba77"
Expand Down Expand Up @@ -91,7 +92,7 @@ class BackgroundServices(
NotificationManager.showReceivedTabs(context, device, tabs)
}

push.feature?.let { push -> FxaPushSupportFeature(context, accountManager, push) }
push.feature?.let { push -> FxaPushSupportFeature(context, accountManager, push, applicationScope) }

SyncedTabsIntegration(context, accountManager).launch()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.SharedPreferences
import android.os.Environment
import androidx.preference.PreferenceManager
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.CoroutineScope
import mozilla.components.browser.engine.gecko.permission.GeckoSitePermissionsStorage
import mozilla.components.browser.icons.BrowserIcons
import mozilla.components.browser.session.storage.SessionStorage
Expand Down Expand Up @@ -65,6 +66,7 @@ private const val DAY_IN_MINUTES = 24 * 60L
class Core(
private val context: Context,
crashReporter: CrashReporter,
private val applicationScope: CoroutineScope,
) {
/** The browser engine component initialized based on the build configuration (see build variants). */
val engine: Engine by lazy {
Expand Down Expand Up @@ -114,6 +116,7 @@ class Core(
RegionMiddleware(
context,
LocationService.default(),
applicationScope = applicationScope,
),
SearchMiddleware(context),
RecordingDevicesMiddleware(context, context.components.notificationsDelegate),
Expand Down Expand Up @@ -141,7 +144,7 @@ class Core(

/** The storage component for persisting browser tab sessions. */
val sessionStorage: SessionStorage by lazy {
SessionStorage(context, engine)
SessionStorage(context, engine, applicationScope = applicationScope)
}

/** The storage component to persist browsing history (with the exception of private sessions). */
Expand Down Expand Up @@ -203,7 +206,7 @@ class Core(
}

val fileUploadsDirCleaner: FileUploadsDirCleaner by lazy {
FileUploadsDirCleaner { context.cacheDir }
FileUploadsDirCleaner(scope = applicationScope) { context.cacheDir }
}

private fun provideDefaultAddonProvider(): AMOAddonsProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.mozilla.reference.browser.components

import android.content.Context
import kotlinx.coroutines.CoroutineScope
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.customtabs.CustomTabIntentProcessor
import mozilla.components.feature.intent.processing.TabIntentProcessor
Expand All @@ -17,13 +18,15 @@ import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.lib.publicsuffixlist.PublicSuffixList

/** Component group for miscellaneous components. */
@Suppress("LongParameterList")
class Utilities(
private val context: Context,
private val store: BrowserStore,
private val sessionUseCases: SessionUseCases,
private val searchUseCases: SearchUseCases,
private val tabsUseCases: TabsUseCases,
private val customTabsUseCases: CustomTabsUseCases,
private val applicationScope: CoroutineScope,
) {
/** Provides intent processing functionality for Progressive Web App and Custom Tab intents. */
val externalIntentProcessors by lazy {
Expand All @@ -46,7 +49,8 @@ class Utilities(
* processors.
*/
val intentProcessors by lazy {
externalIntentProcessors + TabIntentProcessor(tabsUseCases, searchUseCases.newTabSearch)
externalIntentProcessors +
TabIntentProcessor(tabsUseCases, searchUseCases.newTabSearch, applicationScope = applicationScope)
}

val publicSuffixList by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat() {
pref: Preference?,
failed: Boolean = false,
) {
@Suppress("DEPRECATION") // getLastSynced is deprecated see bug 2067060
val lastSyncTime = getLastSynced(context)

pref?.summary =
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
# Android Components
android-components = "157.0.20260831085937"
android-components = "157.0.20260901103215"

# AGP
android-gradle-plugin = "9.3.1"
Expand Down