Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4e2c49d authored by Feng Cao's avatar Feng Cao
Browse files

Fixed NPE in the InlineSuggestionFactory for augmented autofill request

Test: manual verification
Bug: 149940463

Change-Id: I5fa48ca463654e5f86c834f71ab6d625e8992c5e
parent 2cf1cf43
Loading
Loading
Loading
Loading
+18 −22
Original line number Diff line number Diff line
@@ -72,12 +72,9 @@ public final class InlineSuggestionFactory {
     */
    public static InlineSuggestionsResponse createInlineSuggestionsResponse(
            @NonNull InlineSuggestionsRequest request, @NonNull FillResponse response,
            @Nullable String filterText,
            @Nullable List<InlinePresentation> inlineActions,
            @NonNull AutofillId autofillId,
            @NonNull Context context,
            @NonNull AutoFillUI.AutoFillUiCallback client,
            @NonNull Runnable onErrorCallback,
            @Nullable String filterText, @Nullable List<InlinePresentation> 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<Dataset, Integer> 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<InlinePresentation> inlineActions, @NonNull AutofillId autofillId,
            @NonNull Context context, @NonNull Runnable onErrorCallback,
            @NonNull BiConsumer<Dataset, Integer> onClickFactory,
            @Nullable RemoteInlineSuggestionRenderService remoteRenderService) {

        final ArrayList<InlineSuggestion> 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<Dataset, Integer> 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);