From d4e2c49d6a36ed0c4b9e46b6f913d03bb0c6b766 Mon Sep 17 00:00:00 2001 From: Feng Cao Date: Thu, 20 Feb 2020 18:27:28 -0800 Subject: [PATCH] Fixed NPE in the InlineSuggestionFactory for augmented autofill request Test: manual verification Bug: 149940463 Change-Id: I5fa48ca463654e5f86c834f71ab6d625e8992c5e --- .../autofill/ui/InlineSuggestionFactory.java | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java b/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java index a8886fc06c5af..9420d0bcc7bbf 100644 --- a/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java +++ b/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java @@ -72,12 +72,9 @@ public final class InlineSuggestionFactory { */ public static InlineSuggestionsResponse createInlineSuggestionsResponse( @NonNull InlineSuggestionsRequest request, @NonNull FillResponse response, - @Nullable String filterText, - @Nullable List inlineActions, - @NonNull AutofillId autofillId, - @NonNull Context context, - @NonNull AutoFillUI.AutoFillUiCallback client, - @NonNull Runnable onErrorCallback, + @Nullable String filterText, @Nullable List inlineActions, + @NonNull AutofillId autofillId, @NonNull Context context, + @NonNull AutoFillUI.AutoFillUiCallback client, @NonNull Runnable onErrorCallback, @Nullable RemoteInlineSuggestionRenderService remoteRenderService) { if (sDebug) Slog.d(TAG, "createInlineSuggestionsResponse called"); final BiConsumer onClickFactory; @@ -94,10 +91,11 @@ public final class InlineSuggestionFactory { final Dataset[] datasets = datasetList == null ? null : datasetList.toArray(new Dataset[]{}); - - return createInlineSuggestionsResponseInternal(/* isAugmented= */ false, request, response, - datasets, filterText, inlineActions, autofillId, context, onErrorCallback, - onClickFactory, remoteRenderService); + final InlinePresentation inlineAuthentication = + response.getAuthentication() == null ? null : response.getInlinePresentation(); + return createInlineSuggestionsResponseInternal(/* isAugmented= */ false, request, + datasets, filterText, inlineAuthentication, inlineActions, autofillId, context, + onErrorCallback, onClickFactory, remoteRenderService); } /** @@ -105,33 +103,31 @@ public final class InlineSuggestionFactory { * autofill service. */ public static InlineSuggestionsResponse createAugmentedInlineSuggestionsResponse( - @NonNull InlineSuggestionsRequest request, - @NonNull Dataset[] datasets, - @NonNull AutofillId autofillId, - @NonNull Context context, + @NonNull InlineSuggestionsRequest request, @NonNull Dataset[] datasets, + @NonNull AutofillId autofillId, @NonNull Context context, @NonNull InlineSuggestionUiCallback inlineSuggestionUiCallback, @NonNull Runnable onErrorCallback, @Nullable RemoteInlineSuggestionRenderService remoteRenderService) { if (sDebug) Slog.d(TAG, "createAugmentedInlineSuggestionsResponse called"); return createInlineSuggestionsResponseInternal(/* isAugmented= */ true, request, - /* fillResponse= */ null, datasets, /* filterText= */ null, + datasets, /* filterText= */ null, /* inlineAuthentication= */ null, /* inlineActions= */ null, autofillId, context, onErrorCallback, - (dataset, fieldIndex) -> + (dataset, datasetIndex) -> inlineSuggestionUiCallback.autofill(dataset), remoteRenderService); } private static InlineSuggestionsResponse createInlineSuggestionsResponseInternal( boolean isAugmented, @NonNull InlineSuggestionsRequest request, - @Nullable FillResponse response, @Nullable Dataset[] datasets, - @Nullable String filterText, + @Nullable Dataset[] datasets, @Nullable String filterText, + @Nullable InlinePresentation inlineAuthentication, @Nullable List inlineActions, @NonNull AutofillId autofillId, @NonNull Context context, @NonNull Runnable onErrorCallback, @NonNull BiConsumer onClickFactory, @Nullable RemoteInlineSuggestionRenderService remoteRenderService) { final ArrayList inlineSuggestions = new ArrayList<>(); - if (response.getAuthentication() != null) { - InlineSuggestion inlineAuthSuggestion = createInlineAuthSuggestion(response, + if (inlineAuthentication != null) { + InlineSuggestion inlineAuthSuggestion = createInlineAuthSuggestion(inlineAuthentication, remoteRenderService, onClickFactory, onErrorCallback, request.getHostInputToken()); inlineSuggestions.add(inlineAuthSuggestion); @@ -250,11 +246,11 @@ public final class InlineSuggestionFactory { return inlineSuggestion; } - private static InlineSuggestion createInlineAuthSuggestion(@NonNull FillResponse response, + private static InlineSuggestion createInlineAuthSuggestion( + @NonNull InlinePresentation inlinePresentation, @NonNull RemoteInlineSuggestionRenderService remoteRenderService, @NonNull BiConsumer onClickFactory, @NonNull Runnable onErrorCallback, @Nullable IBinder hostInputToken) { - final InlinePresentation inlinePresentation = response.getInlinePresentation(); final InlineSuggestionInfo inlineSuggestionInfo = new InlineSuggestionInfo( inlinePresentation.getInlinePresentationSpec(), InlineSuggestionInfo.SOURCE_AUTOFILL, null, InlineSuggestionInfo.TYPE_SUGGESTION);