Skip to content

Commit 1c1d316

Browse files
jonalmeidamergify[bot]
authored andcommitted
Fix breaking APIs from CrashReporter and adds AppServices init
1 parent e6f42e9 commit 1c1d316

File tree

7 files changed

+47
-47
lines changed

7 files changed

+47
-47
lines changed

app/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,9 @@ dependencies {
330330
implementation libs.mozilla.service.location
331331
implementation libs.mozilla.service.sync.logins
332332

333+
implementation libs.mozilla.support.appservices
333334
implementation libs.mozilla.support.base
334335
implementation libs.mozilla.support.ktx
335-
implementation libs.mozilla.support.rusthttp
336-
implementation libs.mozilla.support.rustlog
337336
implementation libs.mozilla.support.utils
338337
implementation libs.mozilla.support.webextensions
339338

app/src/main/java/org/mozilla/reference/browser/BrowserActivity.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import org.mozilla.reference.browser.addons.WebExtensionActionPopupActivity
2626
import org.mozilla.reference.browser.browser.BrowserFragment
2727
import org.mozilla.reference.browser.browser.CrashIntegration
2828
import org.mozilla.reference.browser.ext.components
29-
import org.mozilla.reference.browser.ext.isCrashReportActive
3029

3130
/**
3231
* Activity that holds the [BrowserFragment].
@@ -59,12 +58,10 @@ open class BrowserActivity : AppCompatActivity() {
5958
}
6059
}
6160

62-
if (isCrashReportActive) {
63-
crashIntegration = CrashIntegration(this, components.analytics.crashReporter) { crash ->
64-
onNonFatalCrash(crash)
65-
}
66-
lifecycle.addObserver(crashIntegration)
61+
crashIntegration = CrashIntegration(this, components.analytics.crashReporter) { crash ->
62+
onNonFatalCrash(crash)
6763
}
64+
lifecycle.addObserver(crashIntegration)
6865

6966
NotificationManager.checkAndNotifyPolicy(this)
7067
lifecycle.addObserver(webExtensionPopupObserver)

app/src/main/java/org/mozilla/reference/browser/BrowserApplication.kt

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ import mozilla.components.browser.state.action.SystemAction
1313
import mozilla.components.concept.engine.webextension.isUnsupported
1414
import mozilla.components.concept.push.PushProcessor
1515
import mozilla.components.feature.addons.update.GlobalAddonDependencyProvider
16+
import mozilla.components.support.AppServicesInitializer
1617
import mozilla.components.support.base.log.Log
1718
import mozilla.components.support.base.log.logger.Logger
1819
import mozilla.components.support.base.log.sink.AndroidLogSink
1920
import mozilla.components.support.ktx.android.content.isMainProcess
2021
import mozilla.components.support.ktx.android.content.runOnlyInMainProcess
2122
import mozilla.components.support.rusthttp.RustHttpConfig
22-
import mozilla.components.support.rustlog.RustLog
2323
import mozilla.components.support.webextensions.WebExtensionSupport
24-
import org.mozilla.reference.browser.ext.isCrashReportActive
2524
import org.mozilla.reference.browser.push.PushFxaIntegration
2625
import org.mozilla.reference.browser.push.WebPushEngineIntegration
2726
import java.util.concurrent.TimeUnit
@@ -34,8 +33,10 @@ open class BrowserApplication : Application() {
3433

3534
setupCrashReporting(this)
3635

36+
AppServicesInitializer.init(components.analytics.crashReporter)
3737
RustHttpConfig.setClient(lazy { components.core.client })
38-
setupLogging()
38+
39+
Log.addSink(AndroidLogSink())
3940

4041
if (!isMainProcess()) {
4142
// If this is not the main process then do not continue with the initialization here. Everything that
@@ -136,18 +137,10 @@ open class BrowserApplication : Application() {
136137
}
137138
}
138139

139-
private fun setupLogging() {
140-
// We want the log messages of all builds to go to Android logcat
141-
Log.addSink(AndroidLogSink())
142-
RustLog.enable()
143-
}
144-
145140
private fun setupCrashReporting(application: BrowserApplication) {
146-
if (isCrashReportActive) {
147-
application
148-
.components
149-
.analytics
150-
.crashReporter
151-
.install(application)
152-
}
141+
application
142+
.components
143+
.analytics
144+
.crashReporter
145+
.install(application)
153146
}

app/src/main/java/org/mozilla/reference/browser/CrashListActivity.kt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,40 @@
55
package org.mozilla.reference.browser
66

77
import android.content.Intent
8+
import android.os.Bundle
9+
import androidx.appcompat.app.AppCompatActivity
810
import androidx.core.net.toUri
911
import mozilla.components.lib.crash.CrashReporter
10-
import mozilla.components.lib.crash.ui.AbstractCrashListActivity
11-
import org.mozilla.reference.browser.ext.components
12+
import mozilla.components.lib.crash.ui.AbstractCrashListFragment
13+
import org.mozilla.reference.browser.ext.requireComponents
1214

13-
class CrashListActivity : AbstractCrashListActivity() {
14-
override val crashReporter: CrashReporter by lazy { components.analytics.crashReporter }
15+
/**
16+
* A simple activity whose only purpose is to load the [CrashListFragment].
17+
*/
18+
class CrashListActivity : AppCompatActivity() {
19+
override fun onCreate(savedInstanceState: Bundle?) {
20+
super.onCreate(savedInstanceState)
21+
22+
packageName
23+
supportFragmentManager
24+
.beginTransaction()
25+
.add(android.R.id.content, CrashListFragment())
26+
.commit()
27+
}
28+
}
29+
30+
/**
31+
* An [AbstractCrashListFragment] implementor that uses the application [CrashReporter].
32+
*/
33+
class CrashListFragment : AbstractCrashListFragment() {
34+
override val reporter: CrashReporter by lazy { requireComponents.analytics.crashReporter }
1535

1636
override fun onCrashServiceSelected(url: String) {
1737
val intent = Intent(Intent.ACTION_VIEW).apply {
1838
data = url.toUri()
19-
`package` = packageName
39+
`package` = context?.packageName
2040
}
2141
startActivity(intent)
22-
finish()
42+
activity?.finish()
2343
}
2444
}

app/src/main/java/org/mozilla/reference/browser/EngineProvider.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import mozilla.components.feature.webcompat.WebCompatFeature
1414
import mozilla.components.lib.crash.handler.CrashHandlerService
1515
import org.mozilla.geckoview.GeckoRuntime
1616
import org.mozilla.geckoview.GeckoRuntimeSettings
17-
import org.mozilla.reference.browser.ext.isCrashReportActive
1817

1918
object EngineProvider {
2019
private var runtime: GeckoRuntime? = null
@@ -24,9 +23,7 @@ object EngineProvider {
2423
if (runtime == null) {
2524
val builder = GeckoRuntimeSettings.Builder()
2625

27-
if (isCrashReportActive) {
28-
builder.crashHandler(CrashHandlerService::class.java)
29-
}
26+
builder.crashHandler(CrashHandlerService::class.java)
3027

3128
// About config it's no longer enabled by default
3229
builder.aboutConfigEnabled(true)

app/src/main/java/org/mozilla/reference/browser/browser/CrashIntegration.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import mozilla.components.lib.crash.Crash
1818
import mozilla.components.lib.crash.CrashReporter
1919
import mozilla.components.support.utils.ext.registerReceiverCompat
2020
import org.mozilla.reference.browser.BrowserApplication.Companion.NON_FATAL_CRASH_BROADCAST
21-
import org.mozilla.reference.browser.ext.isCrashReportActive
2221

2322
class CrashIntegration(
2423
private val context: Context,
@@ -41,20 +40,16 @@ class CrashIntegration(
4140

4241
override fun onStart(owner: LifecycleOwner) {
4342
super.onStart(owner)
44-
if (isCrashReportActive) {
45-
context.registerReceiverCompat(
46-
receiver,
47-
IntentFilter(NON_FATAL_CRASH_BROADCAST),
48-
ContextCompat.RECEIVER_NOT_EXPORTED,
49-
)
50-
}
43+
context.registerReceiverCompat(
44+
receiver,
45+
IntentFilter(NON_FATAL_CRASH_BROADCAST),
46+
ContextCompat.RECEIVER_NOT_EXPORTED,
47+
)
5148
}
5249

5350
override fun onStop(owner: LifecycleOwner) {
5451
super.onStop(owner)
55-
if (isCrashReportActive) {
56-
context.unregisterReceiver(receiver)
57-
}
52+
context.unregisterReceiver(receiver)
5853
}
5954

6055
@OptIn(DelicateCoroutinesApi::class)

gradle/libs.versions.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ mozilla-service-firefox-accounts = { group = "org.mozilla.components", name = "s
173173
mozilla-service-location = { group = "org.mozilla.components", name = "service-location", version.ref = "android-components" }
174174
mozilla-service-sync-logins = { group = "org.mozilla.components", name = "service-sync-logins", version.ref = "android-components" }
175175

176+
mozilla-support-appservices = { group = "org.mozilla.components", name = "support-appservices", version.ref = "android-components" }
176177
mozilla-support-base = { group = "org.mozilla.components", name = "support-base", version.ref = "android-components" }
177178
mozilla-support-ktx = { group = "org.mozilla.components", name = "support-ktx", version.ref = "android-components" }
178-
mozilla-support-rusthttp = { group = "org.mozilla.components", name = "support-rusthttp", version.ref = "android-components" }
179-
mozilla-support-rustlog = { group = "org.mozilla.components", name = "support-rustlog", version.ref = "android-components" }
180179
mozilla-support-utils = { group = "org.mozilla.components", name = "support-utils", version.ref = "android-components" }
181180
mozilla-support-webextensions = { group = "org.mozilla.components", name = "support-webextensions", version.ref = "android-components" }
182181

0 commit comments

Comments
 (0)