1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.service.autofill.augmented; 17 18 import static android.service.autofill.augmented.AugmentedAutofillService.sDebug; 19 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SystemApi; 23 import android.os.Bundle; 24 import android.service.autofill.Dataset; 25 import android.service.autofill.augmented.AugmentedAutofillService.AutofillProxy; 26 import android.util.Log; 27 28 import java.util.List; 29 30 /** 31 * Callback used to indicate at {@link FillRequest} has been fulfilled. 32 * 33 * @hide 34 */ 35 @SystemApi 36 public final class FillCallback { 37 38 private static final String TAG = FillCallback.class.getSimpleName(); 39 40 private final AutofillProxy mProxy; 41 FillCallback(@onNull AutofillProxy proxy)42 FillCallback(@NonNull AutofillProxy proxy) { 43 mProxy = proxy; 44 } 45 46 /** 47 * Sets the response associated with the request. 48 * 49 * @param response response associated with the request, or {@code null} if the service 50 * could not provide autofill for the request. 51 */ onSuccess(@ullable FillResponse response)52 public void onSuccess(@Nullable FillResponse response) { 53 if (sDebug) Log.d(TAG, "onSuccess(): " + response); 54 55 if (response == null) { 56 mProxy.logEvent(AutofillProxy.REPORT_EVENT_NO_RESPONSE); 57 mProxy.reportResult(/* inlineSuggestionsData */ null, /* clientState */ 58 null, /* showingFillWindow */ false); 59 return; 60 } 61 62 final List<Dataset> inlineSuggestions = response.getInlineSuggestions(); 63 final Bundle clientState = response.getClientState(); 64 final FillWindow fillWindow = response.getFillWindow(); 65 boolean showingFillWindow = false; 66 if (inlineSuggestions != null && !inlineSuggestions.isEmpty()) { 67 mProxy.logEvent(AutofillProxy.REPORT_EVENT_INLINE_RESPONSE); 68 } else if (fillWindow != null) { 69 fillWindow.show(); 70 showingFillWindow = true; 71 } 72 // We need to report result regardless of whether inline suggestions are returned or not. 73 mProxy.reportResult(inlineSuggestions, clientState, showingFillWindow); 74 75 // TODO(b/123099468): must notify the server so it can update the session state to avoid 76 // showing conflicting UIs (for example, if a new request is made to the main autofill 77 // service and it now wants to show something). 78 } 79 } 80