Fix UiTranslationStateCallback crash due to null locales.

The locales aren't available on a RESUMED event; now they're stored on a
STARTED event. The crash happens because the default Callback impl
converts the Locale to a string to support a deprecated method.

Fix: 186392998
Test: manual - install test apk which triggers the crash. no crash with
 this change.
Change-Id: Iaceca8d29f4c2b0d692c8f6780b0ab963e4e2243
This commit is contained in:
Ahaan Ugale
2021-05-03 19:45:02 -07:00
parent 19a0cc7574
commit e19085a0cd

View File

@@ -315,6 +315,8 @@ public final class UiTranslationManager {
private static class UiTranslationStateRemoteCallback extends IRemoteCallback.Stub {
private final Executor mExecutor;
private final UiTranslationStateCallback mCallback;
private ULocale mSourceLocale;
private ULocale mTargetLocale;
UiTranslationStateRemoteCallback(Executor executor,
UiTranslationStateCallback callback) {
@@ -331,10 +333,12 @@ public final class UiTranslationManager {
int state = bundle.getInt(EXTRA_STATE);
switch (state) {
case STATE_UI_TRANSLATION_STARTED:
mSourceLocale = (ULocale) bundle.getSerializable(EXTRA_SOURCE_LOCALE);
mTargetLocale = (ULocale) bundle.getSerializable(EXTRA_TARGET_LOCALE);
mCallback.onStarted(mSourceLocale, mTargetLocale);
break;
case STATE_UI_TRANSLATION_RESUMED:
mCallback.onStarted(
(ULocale) bundle.getSerializable(EXTRA_SOURCE_LOCALE),
(ULocale) bundle.getSerializable(EXTRA_TARGET_LOCALE));
mCallback.onStarted(mSourceLocale, mTargetLocale);
break;
case STATE_UI_TRANSLATION_PAUSED:
mCallback.onPaused();