* For #1039: Small cleanup * Closes #1039: Adds crash reporting * Add images * Adds build settings back * Fix nitsmaster
parent
202b195215
commit
5e96b2037e
|
@ -19,6 +19,7 @@ import androidx.navigation.ui.NavigationUI
|
|||
import mozilla.components.browser.session.Session
|
||||
import mozilla.components.concept.engine.EngineView
|
||||
import mozilla.components.feature.intent.IntentProcessor
|
||||
import mozilla.components.lib.crash.Crash
|
||||
import mozilla.components.support.base.feature.BackHandler
|
||||
import mozilla.components.support.ktx.kotlin.isUrl
|
||||
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
|
||||
|
@ -38,6 +39,10 @@ open class HomeActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private val navHost by lazy {
|
||||
supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
|
||||
}
|
||||
|
||||
lateinit var browsingModeManager: DefaultBrowsingModeManager
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -50,12 +55,10 @@ open class HomeActivity : AppCompatActivity() {
|
|||
|
||||
setContentView(R.layout.activity_home)
|
||||
|
||||
val host = supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
|
||||
val hostNavController = host.navController
|
||||
val appBarConfiguration = AppBarConfiguration.Builder(setOf(R.id.libraryFragment)).build()
|
||||
val navigationToolbar = findViewById<Toolbar>(R.id.navigationToolbar)
|
||||
setSupportActionBar(navigationToolbar)
|
||||
NavigationUI.setupWithNavController(navigationToolbar, hostNavController, appBarConfiguration)
|
||||
NavigationUI.setupWithNavController(navigationToolbar, navHost.navController, appBarConfiguration)
|
||||
|
||||
handleOpenedFromExternalSourceIfNecessary(intent)
|
||||
}
|
||||
|
@ -67,6 +70,7 @@ open class HomeActivity : AppCompatActivity() {
|
|||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
handleCrashIfNecessary(intent)
|
||||
handleOpenedFromExternalSourceIfNecessary(intent)
|
||||
}
|
||||
|
||||
|
@ -104,6 +108,18 @@ open class HomeActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleCrashIfNecessary(intent: Intent?) {
|
||||
if (intent == null) { return }
|
||||
if (!Crash.isCrashIntent(intent)) { return }
|
||||
|
||||
openToCrashReporter(intent)
|
||||
}
|
||||
|
||||
private fun openToCrashReporter(intent: Intent) {
|
||||
val directions = NavGraphDirections.actionGlobalCrashReporter(intent)
|
||||
navHost.navController.navigate(directions)
|
||||
}
|
||||
|
||||
private fun handleOpenedFromExternalSourceIfNecessary(intent: Intent?) {
|
||||
if (intent?.extras?.getBoolean(OPEN_TO_BROWSER) == true) {
|
||||
handleOpenedFromExternalSource()
|
||||
|
@ -121,8 +137,6 @@ open class HomeActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
fun openToBrowser(sessionId: String?, from: BrowserDirection) {
|
||||
val host = supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
|
||||
|
||||
val directions = when (from) {
|
||||
BrowserDirection.FromGlobal -> NavGraphDirections.actionGlobalBrowser(sessionId)
|
||||
BrowserDirection.FromHome -> HomeFragmentDirections.actionHomeFragmentToBrowserFragment(sessionId)
|
||||
|
@ -131,7 +145,7 @@ open class HomeActivity : AppCompatActivity() {
|
|||
SettingsFragmentDirections.actionSettingsFragmentToBrowserFragment(sessionId)
|
||||
}
|
||||
|
||||
host.navController.navigate(directions)
|
||||
navHost.navController.navigate(directions)
|
||||
}
|
||||
|
||||
private fun load(text: String, sessionId: String?) {
|
||||
|
|
|
@ -5,11 +5,14 @@
|
|||
package org.mozilla.fenix.components
|
||||
|
||||
import android.app.Application
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import mozilla.components.lib.crash.CrashReporter
|
||||
import mozilla.components.lib.crash.service.MozillaSocorroService
|
||||
import mozilla.components.lib.crash.service.SentryService
|
||||
import org.mozilla.fenix.BuildConfig
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.metrics.GleanMetricsService
|
||||
import org.mozilla.fenix.components.metrics.LeanplumMetricsService
|
||||
|
@ -34,6 +37,17 @@ class Analytics(
|
|||
|
||||
val socorroService = MozillaSocorroService(context, "Fenix")
|
||||
|
||||
val intent = Intent(context, HomeActivity::class.java).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||
}
|
||||
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
intent,
|
||||
0
|
||||
)
|
||||
|
||||
CrashReporter(
|
||||
services = listOf(sentryService, socorroService),
|
||||
shouldPrompt = CrashReporter.Prompt.ALWAYS,
|
||||
|
@ -41,7 +55,8 @@ class Analytics(
|
|||
appName = context.getString(R.string.app_name),
|
||||
organizationName = "Mozilla"
|
||||
),
|
||||
enabled = true
|
||||
enabled = true,
|
||||
nonFatalCrashIntent = pendingIntent
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/* 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 org.mozilla.fenix.crashes
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.Navigation
|
||||
import kotlinx.android.synthetic.main.fragment_crash_reporter.*
|
||||
import mozilla.components.lib.crash.Crash
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
|
||||
class CrashReporterFragment : Fragment() {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? = inflater.inflate(R.layout.fragment_crash_reporter, container, false)
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val crashIntent = CrashReporterFragmentArgs.fromBundle(arguments!!).crashIntent
|
||||
|
||||
val crash = Crash.fromIntent(CrashReporterFragmentArgs.fromBundle(arguments!!).crashIntent)
|
||||
// TODO TelemetryWrapper.crashReporterOpened()
|
||||
|
||||
closeTabButton.setOnClickListener {
|
||||
val wantsToSubmitCrashReport = sendCrashCheckbox.isChecked
|
||||
val selectedSession = requireComponents.core.sessionManager.selectedSession
|
||||
|
||||
selectedSession?.let { session -> requireComponents.useCases.tabsUseCases.removeTab.invoke(session) }
|
||||
// TODO TelemetryWrapper.crashReporterClosed(wantsSubmitCrashReport)
|
||||
|
||||
if (wantsToSubmitCrashReport) {
|
||||
requireComponents.analytics.crashReporter.submitReport(crash)
|
||||
}
|
||||
|
||||
navigateHome(view)
|
||||
}
|
||||
}
|
||||
|
||||
fun navigateHome(fromView: View) {
|
||||
val directions = CrashReporterFragmentDirections.actionCrashReporterFragmentToHomeFragment()
|
||||
Navigation.findNavController(fromView).navigate(directions)
|
||||
}
|
||||
|
||||
fun onBackPressed() {
|
||||
// TODO TelemetryWrapper.crashReporterClosed(false)
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
|
@ -11,6 +11,13 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context="browser.BrowserFragment">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/crash_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/photonRed50"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<mozilla.components.concept.engine.EngineView
|
||||
android:id="@+id/engineView"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/photonGrey10">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/crash_tab_image"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:src="@drawable/ic_error_session_crashed"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
app:layout_constraintWidth_percent="0.6"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:lineSpacingExtra="8sp"
|
||||
android:singleLine="false"
|
||||
android:text="@string/tab_crash_title"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/search_text"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/crash_tab_image" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:lineSpacingExtra="7sp"
|
||||
android:singleLine="false"
|
||||
android:text="@string/tab_crash_description"
|
||||
android:textColor="@color/search_text"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/sendCrashCheckbox"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginBottom="@dimen/crash_reporter_close_tab_button_bottom_margin"
|
||||
android:buttonTint="@color/crash_page_accent"
|
||||
android:checked="true"
|
||||
android:text="@string/tab_crash_send_report"
|
||||
android:textColor="@color/search_text"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toTopOf="@id/restoreTabButton"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintWidth_percent="0.8"
|
||||
tools:text="@string/tab_crash_send_report" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/restoreTabButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/crash_reporter_close_tab_button_horizontal_margin"
|
||||
android:layout_marginEnd="@dimen/crash_reporter_close_tab_button_horizontal_margin"
|
||||
android:layout_marginBottom="@dimen/crash_reporter_close_tab_button_bottom_margin"
|
||||
android:backgroundTint="@color/crash_page_accent"
|
||||
android:text="@string/tab_crash_restore"
|
||||
android:textColor="@color/off_white"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintWidth_percent="0.4" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/closeTabButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/crash_reporter_close_tab_button_horizontal_margin"
|
||||
android:layout_marginEnd="@dimen/crash_reporter_close_tab_button_horizontal_margin"
|
||||
android:layout_marginBottom="@dimen/crash_reporter_close_tab_button_bottom_margin"
|
||||
android:backgroundTint="@color/crash_page_off_accent"
|
||||
android:text="@string/tab_crash_close"
|
||||
android:textColor="@color/search_text"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintWidth_percent="0.4" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -11,6 +11,10 @@
|
|||
app:popUpTo="@id/nav_graph"
|
||||
app:popUpToInclusive="true" />
|
||||
|
||||
<action
|
||||
android:id="@+id/action_global_crash_reporter"
|
||||
app:destination="@id/crashReporterFragment" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/homeFragment"
|
||||
android:name="org.mozilla.fenix.home.HomeFragment"
|
||||
|
@ -119,4 +123,15 @@
|
|||
android:id="@+id/searchEngineFragment"
|
||||
android:name="org.mozilla.fenix.settings.SearchEngineFragment"
|
||||
android:label="SearchEngineFragment" />
|
||||
<fragment android:id="@+id/crashReporterFragment" android:name="org.mozilla.fenix.crashes.CrashReporterFragment"
|
||||
android:label="CrashReporterFragment">
|
||||
<action
|
||||
android:id="@+id/action_crashReporterFragment_to_browserFragment"
|
||||
app:destination="@id/browserFragment"
|
||||
app:popUpTo="@id/homeFragment">
|
||||
<argument android:name="session_id" app:argType="string" app:nullable="true"/>
|
||||
</action>
|
||||
<action android:id="@+id/action_crashReporterFragment_to_homeFragment" app:destination="@id/homeFragment"/>
|
||||
<argument android:name="crashIntent" app:argType="android.content.Intent"/>
|
||||
</fragment>
|
||||
</navigation>
|
|
@ -73,4 +73,7 @@
|
|||
<color name="history_header_private_theme">@color/photonGrey40</color>
|
||||
<color name="history_title_private_theme">@color/off_white</color>
|
||||
<color name="history_url_private_theme">@color/photonGrey40</color>
|
||||
|
||||
<color name="crash_page_accent">#45a1ff</color>
|
||||
<color name="crash_page_off_accent">@color/photonGrey30</color>
|
||||
</resources>
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
- 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/. -->
|
||||
<resources>
|
||||
<dimen name="crash_reporter_close_tab_button_horizontal_margin">26dp</dimen>
|
||||
<dimen name="crash_reporter_close_tab_button_bottom_margin">24dp</dimen>
|
||||
<dimen name="glyph_button_height">48dp</dimen>
|
||||
<dimen name="glyph_button_width">48dp</dimen>
|
||||
<dimen name="mozac_browser_menu_corner_radius">14dp</dimen>
|
||||
|
|
|
@ -219,4 +219,16 @@
|
|||
|
||||
<!-- Text displayed in a notification when the user enters full screen mode -->
|
||||
<string name="full_screen_notification">Entering full screen mode</string>
|
||||
|
||||
<!-- Crashes -->
|
||||
<!-- Title text displayed on the tab crash page -->
|
||||
<string name="tab_crash_title">Sorry. We\'re having a problem with this tab.</string>
|
||||
<!-- Description text displayed on the tab crash page -->
|
||||
<string name="tab_crash_description">You can attempt to restore or close this tab below.</string>
|
||||
<!-- Send crash report checkbox text on the tab crash page -->
|
||||
<string name="tab_crash_send_report">Send crash report to Mozilla</string>
|
||||
<!-- Close tab button text on the tab crash page -->
|
||||
<string name="tab_crash_close">Close tab</string>
|
||||
<!-- Restore tab button text on the tab crash page -->
|
||||
<string name="tab_crash_restore">Restore tab</string>
|
||||
</resources>
|
Loading…
Reference in New Issue