From 02fe90bb4202123bc21489e4f19fb3427b2f5745 Mon Sep 17 00:00:00 2001 From: Ahaan Ugale Date: Wed, 19 May 2021 22:21:10 -0700 Subject: [PATCH] Translate: Ignore duplicate translations. This can happen if UiTranslationManager#startTranslation is called more than once for the same view. If the same TranslationResponse is returned, it can simply be ignored. This is preferable to ignoring duplicate ViewTranslationRequests, since the Response is already cached. The TranslationService can cache translations, so duplicate requests isn't an issue. Ideally, the platform intelligence shouldn't issue multiple requests for the same view. Bug: 144292180 Test: atest CtsTranslationTestCases Change-Id: I0bba4a19284a61a9c7a5b79c71b4f42ddffe4e32 --- .../android/view/translation/UiTranslationController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/java/android/view/translation/UiTranslationController.java b/core/java/android/view/translation/UiTranslationController.java index 4b2c343655890..95b3f687c0584 100644 --- a/core/java/android/view/translation/UiTranslationController.java +++ b/core/java/android/view/translation/UiTranslationController.java @@ -389,6 +389,14 @@ public class UiTranslationController { continue; } mActivity.runOnUiThread(() -> { + if (view.getViewTranslationResponse() != null + && view.getViewTranslationResponse().equals(response)) { + if (DEBUG) { + Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId + + ". Ignoring."); + } + return; + } ViewTranslationCallback callback = view.getViewTranslationCallback(); if (callback == null) { if (view instanceof TextView) {