Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
For #12565 Implement the common part of search widget in Android Comp…
Browse files Browse the repository at this point in the history
…onents
  • Loading branch information
iorgamgabriel committed Aug 10, 2022
2 parents a982c83 + 2cdbf4b commit ae86961
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@ class SessionStorage(
return true
}

val stateToPersist = if (state.selectedTabId != null && state.selectedTab == null) {
// "about:crashparent" is meant for testing purposes only. If saved/restored then it will
// continue to crash the app until data is cleared. Therefore, we are filtering it out.
val updatedTabList = state.tabs.filterNot { it.content.url == "about:crashparent" }
val updatedState = state.copy(tabs = updatedTabList)

val stateToPersist = if (updatedState.selectedTabId != null && updatedState.selectedTab == null) {
// Needs investigation to figure out and prevent cause:
// https://github.com/mozilla-mobile/android-components/issues/8417
logger.error("Selected tab ID set, but tab with matching ID not found. Clearing selection.")
state.copy(selectedTabId = null)
updatedState.copy(selectedTabId = null)
} else {
state
updatedState
}

return synchronized(sessionFileLock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,34 @@ class SessionStorageTest {
// the first one if all tabs have the same last access value.
assertEquals("mozilla", browsingSession.selectedTabId)
}

@Test
fun `WHEN saving state with crash parent tab THEN don't save tab`() {
val state = BrowserState(
tabs = listOf(
createTab(url = "about:crashparent", id = "crash"),
createTab(url = "https://getpocket.com", id = "pocket")
),
selectedTabId = "crash"
)

val engine = FakeEngine()

val storage = SessionStorage(testContext, engine)
val persisted = storage.save(state)
assertTrue(persisted)

// Read it back
val browsingSession = storage.restore()
assertNotNull(browsingSession!!)

assertEquals(1, browsingSession.tabs.size)
assertEquals("https://getpocket.com", browsingSession.tabs[0].state.url)

// Selected tab doesn't exist so we take to most recently accessed one, or
// the first one if all tabs have the same last access value.
assertEquals("pocket", browsingSession.selectedTabId)
}
}

internal fun TabSessionState.assertSameAs(tab: RecoverableTab) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import mozilla.components.feature.search.widget.BaseVoiceSearchActivity.Companio
import mozilla.components.support.utils.PendingIntentUtils

/**
* It contains all the Gui and behaviour for AppWidgetProvider.
* Needs to be extended in client app.
* An abstract [AppWidgetProvider] that implements core behaviour needed to support a Search Widget
* on the launcher.
*/
abstract class AppSearchWidgetProvider : AppWidgetProvider() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ abstract class BaseVoiceSearchActivity : AppCompatActivity() {
*/
private var previousIntent: Intent? = null

@VisibleForTesting
private var activityResultLauncher: ActivityResultLauncher<Intent>? = null
private var activityResultLauncher: ActivityResultLauncher<Intent> = getActivityResultLauncher()

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
Expand All @@ -36,7 +35,6 @@ abstract class BaseVoiceSearchActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityResultLauncher = getActivityResultLauncher()
if (Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).resolveActivity(packageManager) == null) {
finish()
return
Expand Down Expand Up @@ -111,7 +109,7 @@ abstract class BaseVoiceSearchActivity : AppCompatActivity() {
)
}
onSpeechRecognitionStarted()
activityResultLauncher?.launch(intentSpeech)
activityResultLauncher.launch(intentSpeech)
}

/**
Expand Down
3 changes: 3 additions & 0 deletions components/lib/crash/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<!-- Label of notification showing that the crash report service is running. %1$s will be replaced with the name of the organization (e.g. Mozilla). -->
<string name="mozac_lib_send_crash_report_in_progress">Envoi du rapport de plantage à %1$s</string>

<!-- Label of notification showing that the crash handling service is gathering the crash data. -->
<string name="mozac_lib_gathering_crash_data_in_progress">Collecte des données de plantage</string>

<!-- Label of notification showing that the telemetry service is gathering the crash data. -->
<string name="mozac_lib_gathering_crash_telemetry_in_progress">Collecte des données de télémétrie du plantage</string>

Expand Down
3 changes: 3 additions & 0 deletions components/lib/crash/src/main/res/values-sl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<!-- Label of notification showing that the crash report service is running. %1$s will be replaced with the name of the organization (e.g. Mozilla). -->
<string name="mozac_lib_send_crash_report_in_progress">Pošiljanje poročila o sesutju organizaciji %1$s</string>

<!-- Label of notification showing that the crash handling service is gathering the crash data. -->
<string name="mozac_lib_gathering_crash_data_in_progress">Zbiranje podatkov o sesutju</string>

<!-- Label of notification showing that the telemetry service is gathering the crash data. -->
<string name="mozac_lib_gathering_crash_telemetry_in_progress">Zbiranje telemetričnih podatkov o sesutju</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class NimbusPlugin implements Plugin<Project> {
// a) this plugin is going to live in the AS repo (eventually)
// See https://github.com/mozilla-mobile/android-components/issues/11422 for tying this
// to a version that is specified in buildSrc/src/main/java/Dependencies.kt
return "93.5.0"
return "93.6.0"
}

// Try one or more hosts to download the given file.
Expand Down

0 comments on commit ae86961

Please sign in to comment.