Bug Fix: fix NullPointerException while scrolling message apps
The issue will occur when the view is removed from the hierarchy by the time the translation response returns. Do a null check to make sure the view still exists. Bug: 196933332 Test: atest CtsTranslationTestCases Tese: manual. not see the crash when scrolling the apps. Change-Id: Ifee933a802385750d431800ef50f6f2c306ccc0f
This commit is contained in:
@@ -356,7 +356,11 @@ public class UiTranslationController {
|
||||
}
|
||||
for (int i = 0; i < translatedResult.size(); i++) {
|
||||
final AutofillId autofillId = new AutofillId(translatedResult.keyAt(i));
|
||||
final View view = mViews.get(autofillId).get();
|
||||
final WeakReference<View> viewRef = mViews.get(autofillId);
|
||||
if (viewRef == null) {
|
||||
continue;
|
||||
}
|
||||
final View view = viewRef.get();
|
||||
if (view == null) {
|
||||
Log.w(TAG, "onTranslationCompleted: the view for autofill id " + autofillId
|
||||
+ " may be gone.");
|
||||
@@ -416,7 +420,11 @@ public class UiTranslationController {
|
||||
Log.w(TAG, "No AutofillId is set in ViewTranslationResponse");
|
||||
continue;
|
||||
}
|
||||
final View view = mViews.get(autofillId).get();
|
||||
final WeakReference<View> viewRef = mViews.get(autofillId);
|
||||
if (viewRef == null) {
|
||||
continue;
|
||||
}
|
||||
final View view = viewRef.get();
|
||||
if (view == null) {
|
||||
Log.w(TAG, "onTranslationCompleted: the view for autofill id " + autofillId
|
||||
+ " may be gone.");
|
||||
|
||||
Reference in New Issue
Block a user