Fix UiTranslationManager ErrorProne error.

"Must store Binder.clearCallingIdentity() token as final variable.."

Restoring identity isn't really needed here, but it's better to have to
be defensive -- in case we do add something later for which the calling
identity needs to be restored.

Bug: 177500482
Bug: 182896753
Test: mmma frameworks/base/ RUN_ERROR_PRONE=true
Change-Id: I72acc40f8776d46b3f875cde1759fe03a25e222b
This commit is contained in:
Ahaan Ugale
2021-03-17 00:52:09 -07:00
parent 93b9882eb8
commit 50f76874d9

View File

@@ -404,26 +404,27 @@ public final class UiTranslationManager {
@Override
public void sendResult(Bundle bundle) {
Binder.clearCallingIdentity();
mExecutor.execute(() -> {
int state = bundle.getInt(EXTRA_STATE);
switch (state) {
case STATE_UI_TRANSLATION_STARTED:
case STATE_UI_TRANSLATION_RESUMED:
mCallback.onStarted(
bundle.getString(EXTRA_SOURCE_LOCALE),
bundle.getString(EXTRA_TARGET_LOCALE));
break;
case STATE_UI_TRANSLATION_PAUSED:
mCallback.onPaused();
break;
case STATE_UI_TRANSLATION_FINISHED:
mCallback.onFinished();
break;
default:
Log.wtf(TAG, "Unexpected translation state:" + state);
}
});
Binder.withCleanCallingIdentity(() -> mExecutor.execute(() -> onStateChange(bundle)));
}
private void onStateChange(Bundle bundle) {
int state = bundle.getInt(EXTRA_STATE);
switch (state) {
case STATE_UI_TRANSLATION_STARTED:
case STATE_UI_TRANSLATION_RESUMED:
mCallback.onStarted(
bundle.getString(EXTRA_SOURCE_LOCALE),
bundle.getString(EXTRA_TARGET_LOCALE));
break;
case STATE_UI_TRANSLATION_PAUSED:
mCallback.onPaused();
break;
case STATE_UI_TRANSLATION_FINISHED:
mCallback.onFinished();
break;
default:
Log.wtf(TAG, "Unexpected translation state:" + state);
}
}
}
}