Skip to content

Commit

Permalink
For mozilla-mobile#7249 Create a search widget
Browse files Browse the repository at this point in the history
  • Loading branch information
iorgamgabriel committed Aug 9, 2022
1 parent 0794dea commit 3126016
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 24 deletions.
54 changes: 54 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- [email protected]
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:
- [email protected]
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:
- [email protected]
expires: 119
metadata:
tags:
- Search
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
android:value="true" />

<receiver
android:name="org.mozilla.gecko.search.SearchWidgetProvider"
android:name=".searchwidget.SearchWidgetProvider"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -61,4 +65,8 @@ class IntentReceiverActivity : Activity() {

startActivity(intent)
}

companion object {
const val SEARCH_WIDGET = "search_widget"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -37,24 +33,26 @@ class SearchWidgetProvider : AppSearchWidgetProvider() {
)

override fun createTextSearchIntent(context: Context): PendingIntent {
return Intent(context, IntentReceiverActivity::class.java)
.let { intent ->
val createTextSearchIntentFlags = PendingIntentUtils.defaultFlags or
PendingIntent.FLAG_UPDATE_CURRENT
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
PendingIntent.getActivity(
context,
REQUEST_CODE_NEW_TAB, intent, createTextSearchIntentFlags
)
val textSearchIntent = Intent(context, IntentReceiverActivity::class.java)
.apply {
this.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
this.putExtra(IntentReceiverActivity.SEARCH_WIDGET, true)
}
return PendingIntent.getActivity(
context,
REQUEST_CODE_NEW_TAB,
textSearchIntent,
PendingIntentUtils.defaultFlags or
PendingIntent.FLAG_UPDATE_CURRENT
)
}

override fun shouldShowVoiceSearch(context: Context): Boolean {
return true
}

override fun voiceSearchActivity(): Class<out BaseVoiceSearchActivity> {
return BaseVoiceSearchActivity::class.java
return VoiceSearchActivity::class.java
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -90,7 +91,7 @@ class GleanMetricsService(context: Context) : MetricsService {
}
}

private fun collectPrefMetrics(
private fun collectPrefMetricsAsync(
components: Components,
settings: Settings,
context: Context
Expand All @@ -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(
Expand Down

0 comments on commit 3126016

Please sign in to comment.