Skip to content

Commit 74d9dd2

Browse files
Bug 1912288 - Add an about:glean page to fenix r=android-reviewers,007
Differential Revision: https://phabricator.services.mozilla.com/D225081
1 parent 29e732f commit 74d9dd2

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/BrowserDirection.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ enum class BrowserDirection(@IdRes val fragmentId: Int) {
4242
FromDownloadLanguagesPreferenceFragment(R.id.downloadLanguagesPreferenceFragment),
4343
FromMenuDialogFragment(R.id.menuDialogFragment),
4444
FromWebCompatReporterFragment(R.id.webCompatReporterFragment),
45+
FromGleanDebugToolsFragment(R.id.gleanDebugToolsFragment),
4546
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package org.mozilla.fenix.debugsettings.gleandebugtools
6+
7+
import android.annotation.SuppressLint
8+
import android.content.Intent
9+
import android.net.Uri
10+
import android.widget.Toast
11+
import androidx.compose.material.Icon
12+
import androidx.compose.material.IconButton
13+
import androidx.compose.material.Scaffold
14+
import androidx.compose.material.Text
15+
import androidx.compose.material.TopAppBar
16+
import androidx.compose.runtime.Composable
17+
import androidx.compose.ui.res.painterResource
18+
import androidx.compose.ui.res.stringResource
19+
import androidx.navigation.fragment.findNavController
20+
import mozilla.telemetry.glean.Glean
21+
import org.mozilla.fenix.R
22+
import org.mozilla.fenix.components.lazyStore
23+
import org.mozilla.fenix.compose.ComposeFragment
24+
import org.mozilla.fenix.debugsettings.gleandebugtools.ui.GleanDebugToolsScreen
25+
import org.mozilla.fenix.ext.requireComponents
26+
import org.mozilla.fenix.theme.FirefoxTheme
27+
28+
/**
29+
* [ComposeFragment] for displaying the Glean Debug Tools in the about:glean page.
30+
*/
31+
class GleanDebugToolsFragment : ComposeFragment() {
32+
33+
private val store by lazyStore {
34+
GleanDebugToolsStore(
35+
initialState = GleanDebugToolsState(
36+
logPingsToConsoleEnabled = Glean.getLogPings(),
37+
debugViewTag = Glean.getDebugViewTag() ?: "",
38+
),
39+
middlewares = listOf(
40+
GleanDebugToolsMiddleware(
41+
gleanDebugToolsStorage = DefaultGleanDebugToolsStorage(),
42+
clipboardHandler = requireComponents.clipboardHandler,
43+
openDebugView = { debugViewLink ->
44+
val intent = Intent(Intent.ACTION_VIEW)
45+
intent.data = Uri.parse(debugViewLink)
46+
requireContext().startActivity(intent)
47+
},
48+
showToast = { pingType ->
49+
val toast = Toast.makeText(
50+
requireContext(),
51+
requireContext().getString(
52+
R.string.glean_debug_tools_send_ping_toast_message,
53+
pingType,
54+
),
55+
Toast.LENGTH_LONG,
56+
)
57+
toast.show()
58+
},
59+
),
60+
),
61+
)
62+
}
63+
64+
@Composable
65+
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
66+
override fun UI() {
67+
FirefoxTheme {
68+
Scaffold(
69+
topBar = {
70+
TopAppBar(
71+
title = {
72+
Text(
73+
text = stringResource(R.string.glean_debug_tools_title),
74+
color = FirefoxTheme.colors.textPrimary,
75+
style = FirefoxTheme.typography.headline6,
76+
)
77+
},
78+
navigationIcon = {
79+
val directions = GleanDebugToolsFragmentDirections.actionGlobalBrowser()
80+
IconButton(onClick = { findNavController().navigate(directions) }) {
81+
Icon(
82+
painter = painterResource(R.drawable.mozac_ic_back_24),
83+
contentDescription = stringResource(
84+
R.string.bookmark_navigate_back_button_content_description,
85+
),
86+
tint = FirefoxTheme.colors.iconPrimary,
87+
)
88+
}
89+
},
90+
backgroundColor = FirefoxTheme.colors.layer1,
91+
)
92+
},
93+
backgroundColor = FirefoxTheme.colors.layer1,
94+
) {
95+
GleanDebugToolsScreen(
96+
gleanDebugToolsStore = store,
97+
)
98+
}
99+
}
100+
}
101+
}

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/ext/Activity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import org.mozilla.fenix.addons.AddonsManagementFragmentDirections
3434
import org.mozilla.fenix.components.menu.MenuDialogFragmentDirections
3535
import org.mozilla.fenix.customtabs.EXTRA_IS_SANDBOX_CUSTOM_TAB
3636
import org.mozilla.fenix.customtabs.ExternalAppBrowserActivity
37+
import org.mozilla.fenix.debugsettings.gleandebugtools.GleanDebugToolsFragmentDirections
3738
import org.mozilla.fenix.exceptions.trackingprotection.TrackingProtectionExceptionsFragmentDirections
3839
import org.mozilla.fenix.home.HomeFragmentDirections
3940
import org.mozilla.fenix.library.bookmarks.BookmarkFragmentDirections
@@ -285,6 +286,8 @@ private fun getHomeNavDirections(
285286

286287
BrowserDirection.FromHistory -> HistoryFragmentDirections.actionGlobalBrowser()
287288

289+
BrowserDirection.FromGleanDebugToolsFragment -> GleanDebugToolsFragmentDirections.actionGlobalBrowser()
290+
288291
BrowserDirection.FromHistoryMetadataGroup -> HistoryMetadataGroupFragmentDirections.actionGlobalBrowser()
289292

290293
BrowserDirection.FromTrackingProtectionExceptions ->

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/search/SearchDialogController.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class SearchDialogController(
9393
navController.navigateSafe(R.id.searchDialogFragment, directions)
9494
store.dispatch(AwesomeBarAction.EngagementFinished(abandoned = false))
9595
}
96+
"about:glean" -> {
97+
val directions = SearchDialogFragmentDirections.actionGleanDebugToolsFragment()
98+
navController.navigate(directions)
99+
}
96100
"moz://a" -> openSearchOrUrl(
97101
SupportUtils.getMozillaPageUrl(SupportUtils.MozillaPage.MANIFESTO),
98102
)

mobile/android/fenix/app/src/main/res/navigation/nav_graph.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@
288288
android:defaultValue="@null"
289289
app:argType="string"
290290
app:nullable="true" />
291+
<action
292+
android:id="@+id/action_gleanDebugToolsFragment"
293+
app:destination="@id/gleanDebugToolsFragment" />
291294
</dialog>
292295

293296
<fragment
@@ -1160,6 +1163,10 @@
11601163
app:argType="mozilla.components.feature.addons.Addon" />
11611164
</fragment>
11621165

1166+
<fragment
1167+
android:id="@+id/gleanDebugToolsFragment"
1168+
android:name="org.mozilla.fenix.debugsettings.gleandebugtools.GleanDebugToolsFragment" />
1169+
11631170
<navigation
11641171
android:id="@+id/site_permissions_exceptions_graph"
11651172
app:startDestination="@id/sitePermissionsExceptionsFragment">

mobile/android/fenix/app/src/test/java/org/mozilla/fenix/search/SearchDialogControllerTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import org.mozilla.fenix.components.metrics.MetricsUtils
5050
import org.mozilla.fenix.ext.components
5151
import org.mozilla.fenix.helpers.FenixGleanTestRule
5252
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
53+
import org.mozilla.fenix.search.SearchDialogFragmentDirections.Companion.actionGleanDebugToolsFragment
5354
import org.mozilla.fenix.search.SearchDialogFragmentDirections.Companion.actionGlobalAddonsManagementFragment
5455
import org.mozilla.fenix.search.SearchDialogFragmentDirections.Companion.actionGlobalSearchEngineFragment
5556
import org.mozilla.fenix.search.toolbar.SearchSelectorMenu
@@ -329,6 +330,18 @@ class SearchDialogControllerTest {
329330
}
330331
}
331332

333+
@Test
334+
fun handleGleanUrlCommitted() {
335+
val url = "about:glean"
336+
val directions = actionGleanDebugToolsFragment()
337+
338+
createController().handleUrlCommitted(url)
339+
340+
browserStore.waitUntilIdle()
341+
342+
verify { navController.navigate(directions) }
343+
}
344+
332345
@Test
333346
fun handleMozillaUrlCommitted() {
334347
val url = "moz://a"

0 commit comments

Comments
 (0)