2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/15430: Fix StrictMode death on opening app from widget voice search.

This commit is contained in:
mcarare 2020-10-27 17:09:50 +02:00 committed by Mihai Adrian Carare
parent c66ab231d5
commit e682cb55cc
2 changed files with 21 additions and 9 deletions

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.home.intent package org.mozilla.fenix.home.intent
import android.content.Intent import android.content.Intent
import android.os.StrictMode
import androidx.navigation.NavController import androidx.navigation.NavController
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
@ -26,13 +27,14 @@ class SpeechProcessingIntentProcessor(
override fun process(intent: Intent, navController: NavController, out: Intent): Boolean { override fun process(intent: Intent, navController: NavController, out: Intent): Boolean {
return if (intent.extras?.getBoolean(HomeActivity.OPEN_TO_BROWSER_AND_LOAD) == true) { return if (intent.extras?.getBoolean(HomeActivity.OPEN_TO_BROWSER_AND_LOAD) == true) {
out.putExtra(HomeActivity.OPEN_TO_BROWSER_AND_LOAD, false) out.putExtra(HomeActivity.OPEN_TO_BROWSER_AND_LOAD, false)
activity.components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
val searchEvent = MetricsUtils.createSearchEvent( val searchEvent = MetricsUtils.createSearchEvent(
activity.components.search.provider.getDefaultEngine(activity), activity.components.search.provider.getDefaultEngine(activity),
activity, activity,
Event.PerformedSearch.SearchAccessPoint.WIDGET Event.PerformedSearch.SearchAccessPoint.WIDGET
) )
searchEvent?.let { metrics.track(it) } searchEvent?.let { metrics.track(it) }
}
activity.openToBrowserAndLoad( activity.openToBrowserAndLoad(
searchTermOrURL = intent.getStringExtra(SPEECH_PROCESSING).orEmpty(), searchTermOrURL = intent.getStringExtra(SPEECH_PROCESSING).orEmpty(),

View File

@ -7,12 +7,14 @@ package org.mozilla.fenix.widget
import android.content.ComponentName import android.content.ComponentName
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.os.StrictMode
import android.speech.RecognizerIntent import android.speech.RecognizerIntent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import mozilla.components.support.locale.LocaleManager import mozilla.components.support.locale.LocaleManager
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.metrics
/** /**
@ -62,8 +64,16 @@ class VoiceSearchActivity : AppCompatActivity() {
*/ */
private fun displaySpeechRecognizer() { private fun displaySpeechRecognizer() {
val intentSpeech = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply { val intentSpeech = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) putExtra(
putExtra(RecognizerIntent.EXTRA_LANGUAGE, LocaleManager.getCurrentLocale(this@VoiceSearchActivity)) RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
)
putExtra(
RecognizerIntent.EXTRA_LANGUAGE,
components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) {
LocaleManager.getCurrentLocale(this@VoiceSearchActivity)
}
)
} }
metrics.track(Event.SearchWidgetVoiceSearchPressed) metrics.track(Event.SearchWidgetVoiceSearchPressed)