Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Bug 1877278 - AC Translations Check for if the Engine is Supported #5544

Merged
merged 3 commits into from
Feb 14, 2024

Conversation

ohall-m
Copy link
Contributor

@ohall-m ohall-m commented Feb 9, 2024

This patch supports the workflow for checking if the device architecture supports translations.

This patch adds:

  • New TranslationsBrowserState to hold global translations engine state
  • New SetEngineSupportedAction to set the isEngineSupported value on TranslationsBrowserState
  • New EngineExceptionAction to set errors on TranslationsBrowserState

Pull Request checklist

  • Quality: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or does not need one
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features

After merge

  • Breaking Changes: If this is a breaking Android Components change, please push a draft PR on Reference Browser to address the breaking issues.

To download an APK when reviewing a PR (after all CI tasks finished running):

  1. Click on Checks at the top of the PR page.
  2. Click on the firefoxci-taskcluster group on the left to expand all tasks.
  3. Click on the build-apk-{fenix,focus,klar}-debug task you're interested in.
  4. Click on View task in Taskcluster in the new DETAILS section.
  5. The APK links should be on the right side of the screen, named for each CPU architecture.

GitHub Automation

https://bugzilla.mozilla.org/show_bug.cgi?id=1877278

@github-actions github-actions bot added the 🕵️‍♀️ needs review PRs that need to be reviewed label Feb 9, 2024
@ohall-m ohall-m added work in progress Not ready to land yet. Work in progress (WIP). and removed 🕵️‍♀️ needs review PRs that need to be reviewed labels Feb 9, 2024
@ohall-m ohall-m closed this Feb 9, 2024
@ohall-m ohall-m reopened this Feb 9, 2024
@github-actions github-actions bot added 🕵️‍♀️ needs review PRs that need to be reviewed and removed work in progress Not ready to land yet. Work in progress (WIP). labels Feb 9, 2024
@ohall-m ohall-m added work in progress Not ready to land yet. Work in progress (WIP). and removed 🕵️‍♀️ needs review PRs that need to be reviewed labels Feb 9, 2024
@github-actions github-actions bot added 🕵️‍♀️ needs review PRs that need to be reviewed and removed work in progress Not ready to land yet. Work in progress (WIP). labels Feb 9, 2024
@ohall-m ohall-m closed this Feb 9, 2024
@ohall-m ohall-m reopened this Feb 9, 2024
@@ -39,8 +41,52 @@ class TranslationsMiddleware(
) {
// Pre process actions
when (action) {
// Initially adding the tab
is TabListAction.AddTabAction -> {
Copy link
Contributor Author

@ohall-m ohall-m Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug is checking and adding to the store for if the engine is supported. (We won't show entryways into the feature if the engine isn't supported.)

Between AddTabAction (new tab), RestoreAction (reopening after a shutdown), and SelectTabAction (reopening after a shutdown and changing tabs), all the possibilities seem to be covered to ensure isEngineSupported is set on each tab.

We had a conversation about this style flow over here. Please let me know if you have suggestions or ideas!

1873672 will probably use these same actions to initialize the rest of the translations data needs. I'd like to get a stronger sense of how well it works for this case alone first, however we go about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @MatthewTighe and @gabrielluong, what do you think about this? Is there anything else I should consider or do you think it is good to start testing this option?

Copy link
Member

@gabrielluong gabrielluong Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the amount of research you did, I feel like this is good enough. I don't really have enough context on these actions to provide a better suggestion.

My understanding of what we are trying to achieve here is to make sure all the tabs have this engine supported property set. The only alternative I could see is calling this on-demand for the individual tab that is displayed instead of doing this for all the tabs. If I recall correctly, this alternative was what you first tried to do initially. Did we decide against this?

Do you have a sense of whether or not this operation is expensive? For instance, what happens if an user tries to add/restore 50, 100 or 1000 tabs? This might be worth testing with the debug tools.

Copy link
Member

@gabrielluong gabrielluong Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check if the engine is supported per tab?

I was re-reading the description for one of the properties below:

@Property isEngineSupported If the engine supports translations on this device.

and was wondering if we could just set this only once since this seem to indicate whether or not the engine supports translations on the device, which seems like a global state and not based on per tab, but on the user's device. Does the translation engine settings need to fetched per tab or do we only need to know if the engine is ready?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this question about whether the state is global. though it is useful on the one hand to have all the translation state encapsulated in TranslationState, any global state could definitely move to the top-level browser state or even a BrowserState.translationState. If you went the latter route, the current TranslationState may make more sense as SessionTranslationState

Copy link
Contributor Author

@ohall-m ohall-m Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look!

Do we need to check if the engine is supported per tab?

Not necessarily, this won't change once found.

Does the translation engine settings need to fetched per tab or do we only need to know if the engine is ready?

This isEngineSupported could be a global setting. 100% it is based on the users device and my understanding is it won't change, so once we know, we know. (Only exception might be something like a possible firmware update, but I think that would be an extreme example and generally not easily changed - more details.)

The engine automatically becoming ready is fully managed by Gecko AFAIK currently. They are also managing the new single process 1815339.

LMK how we normally handle something like this and I can refactor for sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you went the latter route, the current TranslationState may make more sense as SessionTranslationState

That could be interesting because supported languages are also not directly tied to the current tab. I'd say download state would probably make sense there too.

(I think there could also be an argument made for the never translate site and languages global settings to be on the global state, but they have a lot of coupling with the page settings, so they probably shouldn't be on a global state and stay tied to one for tabs/sessions.)

Do you have an example of something similar to this I could pattern off of?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking through BrowserState, there is global extension state and then tab-specific extension state in TabSessionState. I'm not really familiar with extensions, but I would be happy to chat through any implementation details if you'd like

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! I'll try following it and see where I end up. (Interestingly, I had to follow a lot of extensions patterns on the GeckoView side as well, so that makes sense too!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look! I followed how WebExtensions managed this as a general pattern to follow and it seems like a better pattern overall and reduces a lot of the weird tab actions. I'm still going to have to figure this out for initializing tabs, but I think the Init action is perfect for this case and have some new ideas to look into for the tab cases.

@github-actions github-actions bot added approved PR that has been approved and removed 🕵️‍♀️ needs review PRs that need to be reviewed labels Feb 12, 2024
@@ -39,8 +41,52 @@ class TranslationsMiddleware(
) {
// Pre process actions
when (action) {
// Initially adding the tab
is TabListAction.AddTabAction -> {
Copy link
Member

@gabrielluong gabrielluong Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the amount of research you did, I feel like this is good enough. I don't really have enough context on these actions to provide a better suggestion.

My understanding of what we are trying to achieve here is to make sure all the tabs have this engine supported property set. The only alternative I could see is calling this on-demand for the individual tab that is displayed instead of doing this for all the tabs. If I recall correctly, this alternative was what you first tried to do initially. Did we decide against this?

Do you have a sense of whether or not this operation is expensive? For instance, what happens if an user tries to add/restore 50, 100 or 1000 tabs? This might be worth testing with the debug tools.

@@ -39,8 +41,52 @@ class TranslationsMiddleware(
) {
// Pre process actions
when (action) {
// Initially adding the tab
is TabListAction.AddTabAction -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this question about whether the state is global. though it is useful on the one hand to have all the translation state encapsulated in TranslationState, any global state could definitely move to the top-level browser state or even a BrowserState.translationState. If you went the latter route, the current TranslationState may make more sense as SessionTranslationState

Comment on lines 84 to 88
TranslationOperation.FETCH_IS_ENGINE_SUPPORTED -> {
scope.launch {
requestEngineSupport(context, action.tabId)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only seeing that this operation is only really dispatched from this middleware, and only really used in this middleware outside of resetting the error state. I'm wondering if we need the additional operation/action dispatch, or if we can just call requestEngineSupport directly from things like AddTabAction.

If the isEngineSupported is global state as per the questions above, could we even maybe use BrowserAction.Init? I do seem to remember that you looked into that but can't recall the details

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated the pattern!

I can use BrowserAction.Init now with the tab independent state. The earlier issue was I needed a tabId to set on, if I set per tab. I still might have to figure out alternatives for tab initialization, but BrowserAction.Init seems much more stable for this patch.

@ohall-m ohall-m added work in progress Not ready to land yet. Work in progress (WIP). changes required PR that requires some changes before landing. and removed approved PR that has been approved labels Feb 12, 2024
@ohall-m ohall-m added 🕵️‍♀️ needs review PRs that need to be reviewed and removed approved PR that has been approved labels Feb 13, 2024
@github-actions github-actions bot added approved PR that has been approved and removed 🕵️‍♀️ needs review PRs that need to be reviewed labels Feb 13, 2024
Copy link
Contributor

mergify bot commented Feb 13, 2024

This pull request has conflicts when rebasing. Could you fix it @ohall-m? 🙏

@ohall-m ohall-m added 🕵️‍♀️ needs review PRs that need to be reviewed and removed approved PR that has been approved labels Feb 14, 2024
@@ -54,4 +55,5 @@ data class BrowserState(
val showExtensionsProcessDisabledPrompt: Boolean = false,
val extensionsProcessDisabled: Boolean = false,
val awesomeBarState: AwesomeBarState = AwesomeBarState(),
val translationEngine: TranslationsBrowserState = TranslationsBrowserState(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had trouble deciding with the naming here, please LMK if you have ideas!

* Indicates an app level translations error occurred and to set the error on
* [BrowserState.translationEngine].
*
* @property error The error that occurred.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @property error The error that occurred.
* @property error The [TranslationError] that occurred.

We could reference the class where possible if the naming and wording just makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good idea, updated!

@@ -35,6 +35,7 @@ import java.util.Locale
* on application startup e.g. as an indicator that tabs have been restored.
* @property locale The current locale of the app. Will be null when following the system default.
* @property awesomeBarState Holds state for interactions with the [AwesomeBar].
* @property translationEngine Holds state for translations that apply to the entire browser.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @property translationEngine Holds state for translations that apply to the entire browser.
* @property translationEngine Holds translation state that applies to the browser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty, updated

@@ -54,4 +55,5 @@ data class BrowserState(
val showExtensionsProcessDisabledPrompt: Boolean = false,
val extensionsProcessDisabled: Boolean = false,
val awesomeBarState: AwesomeBarState = AwesomeBarState(),
val translationEngine: TranslationsBrowserState = TranslationsBrowserState(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val translationEngine: TranslationsBrowserState = TranslationsBrowserState(),
val translationsEngineState: TranslationsEngineState = TranslationsEngineState(),

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, should have mentioned, the name of the class that the engine reports the tab state on is TranslationEngineState (singular).

Currently have:

For this one, I really struggled to find a new name:

TranslationsBrowserEngineState? TranslationsAppState? TranslationsEngineStatus? I keep struggling on this one to avoid a naming collision or something that makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe TranslationsState should become TabTanslationsState or TranslationsSessionState. Otherwise, TranslationsBrowState is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll leave TranslationsBrowserState for now, thanks for taking a look!

Agreed, I'll add a code health bug to refactor TranslationsState -> TranslationsSessionState. I think that'll help keep things more clear. Filed the session refactor naming to bug 1880352.

/**
* Value type that represents the state of the translations engine within a [BrowserState].
*
* @property isEngineSupported The translations engine supports the device architecture.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @property isEngineSupported The translations engine supports the device architecture.
* @property isEngineSupported Whether the translations engine supports the device architecture.

Just extra wording to indicate it is a boolean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty, nice wording

* Value type that represents the state of the translations engine within a [BrowserState].
*
* @property isEngineSupported The translations engine supports the device architecture.
* @property engineError If the translations engine has a global error state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @property engineError If the translations engine has a global error state.
* @property engineError Holds the error state of the translations engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, ty!

/**
* Could not determine if the translations engine works on the device architecture.
*
* @param cause The original throwable before it was converted into this error state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param cause The original throwable before it was converted into this error state.
* @param cause The original [Throwable] before it was converted into this error state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, ty!

@github-actions github-actions bot added approved PR that has been approved and removed 🕵️‍♀️ needs review PRs that need to be reviewed labels Feb 14, 2024
This patch supports the workflow for checking if the device architecture supports translations.

This patch adds:
* New `TranslationsBrowserState` to hold global translations engine state
* New `SetEngineSupportedAction` to set the isEngineSupported value on `TranslationsBrowserState`
* New `EngineExceptionAction` to set errors on `TranslationsBrowserState`
@ohall-m ohall-m added the 🛬 needs landing PRs that are ready to land label Feb 14, 2024
@ohall-m ohall-m closed this Feb 14, 2024
@ohall-m ohall-m reopened this Feb 14, 2024
@rvandermeulen
Copy link
Contributor

@Mergifyio refresh

Copy link
Contributor

mergify bot commented Feb 14, 2024

refresh

✅ Pull request refreshed

@mergify mergify bot merged commit b3aaa1e into mozilla-mobile:main Feb 14, 2024
111 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved PR that has been approved 🛬 needs landing PRs that are ready to land
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants