From 7e5e890993e4efd15a255d9bbb0ac400e59bb4f5 Mon Sep 17 00:00:00 2001 From: iorgamgabriel Date: Tue, 9 Aug 2022 12:47:04 +0300 Subject: [PATCH] For #7249 Create a search widget --- app/metrics.yaml | 54 +++++++++++++++++++ app/src/main/AndroidManifest.xml | 2 +- .../focus/activity/IntentReceiverActivity.kt | 10 +++- .../searchwidget}/SearchWidgetProvider.kt | 9 ++-- .../focus/searchwidget/VoiceSearchActivity.kt | 12 +++-- .../focus/telemetry/GleanMetricsService.kt | 7 ++- 6 files changed, 79 insertions(+), 15 deletions(-) rename app/src/main/java/org/mozilla/{gecko/search => focus/searchwidget}/SearchWidgetProvider.kt (84%) diff --git a/app/metrics.yaml b/app/metrics.yaml index 2ccba8ad4cc..d07ef8ac5ea 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -1900,3 +1900,57 @@ metrics: metadata: tags: - Performance + search_widget_installed: + type: boolean + lifetime: application + description: | + Whether or not the search widget is installed + send_in_pings: + - metrics + bugs: + - https://github.com/mozilla-mobile/fenix/issues/ + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/ + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 119 + metadata: + tags: + - Search + +search_widget: + new_tab_button: + type: event + description: | + A user pressed anywhere from the Focus logo until the start of the + microphone icon, opening a new tab search screen. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/ + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/ + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 119 + metadata: + tags: + - Search + voice_button: + type: event + description: | + A user pressed the microphone icon, opening a new voice search screen. + bugs: + - https://github.com/mozilla-mobile/fenix/issues/ + data_reviews: + - https://github.com/mozilla-mobile/fenix/pull/ + data_sensitivity: + - interaction + notification_emails: + - android-probes@mozilla.com + expires: 119 + metadata: + tags: + - Search diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2a214a71599..389816b35fa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -169,7 +169,7 @@ android:value="true" /> diff --git a/app/src/main/java/org/mozilla/focus/activity/IntentReceiverActivity.kt b/app/src/main/java/org/mozilla/focus/activity/IntentReceiverActivity.kt index a919bc93499..b8d1b483014 100644 --- a/app/src/main/java/org/mozilla/focus/activity/IntentReceiverActivity.kt +++ b/app/src/main/java/org/mozilla/focus/activity/IntentReceiverActivity.kt @@ -8,7 +8,9 @@ import android.app.Activity import android.content.Intent import android.os.Bundle import mozilla.components.feature.intent.ext.sanitize +import mozilla.components.service.glean.private.NoExtras import mozilla.components.support.utils.toSafeIntent +import org.mozilla.focus.GleanMetrics.SearchWidget import org.mozilla.focus.ext.components import org.mozilla.focus.session.IntentProcessor import org.mozilla.focus.utils.SupportUtils @@ -25,7 +27,9 @@ class IntentReceiverActivity : Activity() { super.onCreate(savedInstanceState) val intent = intent.sanitize().toSafeIntent() - + if (intent.getBooleanExtra(SEARCH_WIDGET, false)) { + SearchWidget.newTabButton.record(NoExtras()) + } if (intent.dataString.equals(SupportUtils.OPEN_WITH_DEFAULT_BROWSER_URL)) { dispatchNormalIntent() return @@ -61,4 +65,8 @@ class IntentReceiverActivity : Activity() { startActivity(intent) } + + companion object { + const val SEARCH_WIDGET = "search_widget" + } } diff --git a/app/src/main/java/org/mozilla/gecko/search/SearchWidgetProvider.kt b/app/src/main/java/org/mozilla/focus/searchwidget/SearchWidgetProvider.kt similarity index 84% rename from app/src/main/java/org/mozilla/gecko/search/SearchWidgetProvider.kt rename to app/src/main/java/org/mozilla/focus/searchwidget/SearchWidgetProvider.kt index 2a5efeb51e8..266c9bd1951 100644 --- a/app/src/main/java/org/mozilla/gecko/search/SearchWidgetProvider.kt +++ b/app/src/main/java/org/mozilla/focus/searchwidget/SearchWidgetProvider.kt @@ -2,7 +2,7 @@ * 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.gecko.search +package org.mozilla.focus.searchwidget import android.app.PendingIntent import android.content.Context @@ -17,10 +17,6 @@ import org.mozilla.focus.ext.components class SearchWidgetProvider : AppSearchWidgetProvider() { - // Implementation note: - // This class name (SearchWidgetProvider) and package name (org.mozilla.gecko.search) should - // not be changed because otherwise this widget will disappear from the home screen of the user. - // The existing name replicates the name and package we used in Fennec. override fun onEnabled(context: Context) { context.components.settings.addSearchWidgetInstalled(1) } @@ -42,6 +38,7 @@ class SearchWidgetProvider : AppSearchWidgetProvider() { val createTextSearchIntentFlags = PendingIntentUtils.defaultFlags or PendingIntent.FLAG_UPDATE_CURRENT intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + intent.putExtra(IntentReceiverActivity.SEARCH_WIDGET, true) PendingIntent.getActivity( context, REQUEST_CODE_NEW_TAB, intent, createTextSearchIntentFlags @@ -54,7 +51,7 @@ class SearchWidgetProvider : AppSearchWidgetProvider() { } override fun voiceSearchActivity(): Class { - return BaseVoiceSearchActivity::class.java + return VoiceSearchActivity::class.java } companion object { diff --git a/app/src/main/java/org/mozilla/focus/searchwidget/VoiceSearchActivity.kt b/app/src/main/java/org/mozilla/focus/searchwidget/VoiceSearchActivity.kt index e249d740508..9a2aaf9f5f3 100644 --- a/app/src/main/java/org/mozilla/focus/searchwidget/VoiceSearchActivity.kt +++ b/app/src/main/java/org/mozilla/focus/searchwidget/VoiceSearchActivity.kt @@ -8,6 +8,8 @@ import android.content.Intent import mozilla.components.feature.search.widget.BaseVoiceSearchActivity import mozilla.components.support.locale.LocaleManager import mozilla.components.support.locale.LocaleManager.getCurrentLocale +import mozilla.telemetry.glean.private.NoExtras +import org.mozilla.focus.GleanMetrics.SearchWidget import org.mozilla.focus.activity.IntentReceiverActivity import java.util.Locale @@ -18,15 +20,15 @@ class VoiceSearchActivity : BaseVoiceSearchActivity() { ?: LocaleManager.getSystemDefault() } - override fun recordVoiceButtonTelemetry() { - // TO DO add - } - - override fun startIntentAfterVoiceSearch(spokenText: String?) { + override fun onSpeechRecognitionEnded(spokenText: String) { val intent = Intent(this, IntentReceiverActivity::class.java) intent.action = Intent.ACTION_SEND intent.putExtra(SPEECH_PROCESSING, spokenText) intent.putExtra(Intent.EXTRA_TEXT, spokenText) startActivity(intent) } + + override fun onSpeechRecognitionStarted() { + SearchWidget.voiceButton.record(NoExtras()) + } } diff --git a/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt b/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt index 6167217c31c..4c109452ce0 100644 --- a/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt +++ b/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt @@ -24,6 +24,7 @@ import org.mozilla.focus.Components import org.mozilla.focus.GleanMetrics.Browser import org.mozilla.focus.GleanMetrics.GleanBuildInfo import org.mozilla.focus.GleanMetrics.LegacyIds +import org.mozilla.focus.GleanMetrics.Metrics import org.mozilla.focus.GleanMetrics.MozillaProducts import org.mozilla.focus.GleanMetrics.Pings import org.mozilla.focus.GleanMetrics.Preferences @@ -75,7 +76,7 @@ class GleanMetricsService(context: Context) : MetricsService { GlobalScope.launch(IO) { // Wait for preferences to be collected before we send the activation ping. - collectPrefMetrics(components, settings, context).await() + collectPrefMetricsAsync(components, settings, context).await() // Set the client ID in Glean as part of the deletion-request. LegacyIds.clientId.set(UUID.fromString(TelemetryWrapper.clientId)) @@ -90,7 +91,7 @@ class GleanMetricsService(context: Context) : MetricsService { } } - private fun collectPrefMetrics( + private fun collectPrefMetricsAsync( components: Components, settings: Settings, context: Context @@ -100,6 +101,8 @@ class GleanMetricsService(context: Context) : MetricsService { val isFenixDefaultBrowser = FenixProductDetector.isFenixDefaultBrowser(installedBrowsers.defaultBrowser) val isFocusDefaultBrowser = installedBrowsers.isDefaultBrowser + Metrics.searchWidgetInstalled.set(settings.searchWidgetInstalled) + Browser.isDefault.set(isFocusDefaultBrowser) Browser.localeOverride.set(components.store.state.locale?.displayName ?: "none") val shortcutsOnHomeNumber = components.topSitesStorage.getTopSites(