2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.service.autofill;
19 import android.annotation.Nullable;
20 import android.app.Activity;
21 import android.os.RemoteException;
24 * Handles autofill requests from the {@link AutofillService} into the {@link Activity} being
27 public final class FillCallback {
28 private final IFillCallback mCallback;
29 private final int mRequestId;
30 private boolean mCalled;
33 public FillCallback(IFillCallback callback, int requestId) {
35 mRequestId = requestId;
39 * Notifies the Android System that an
40 * {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal,
41 * FillCallback)} was successfully fulfilled by the service.
43 * @param response autofill information for that activity, or {@code null} when the activity
44 * cannot be autofilled (for example, if it only contains read-only fields). See
45 * {@link FillResponse} for examples.
47 public void onSuccess(@Nullable FillResponse response) {
51 mCallback.onSuccess(response, mRequestId);
52 } catch (RemoteException e) {
53 e.rethrowAsRuntimeException();
58 * Notifies the Android System that an
59 * {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal,
60 * FillCallback)} could not be fulfilled by the service.
62 * @param message error message to be displayed to the user.
64 public void onFailure(@Nullable CharSequence message) {
68 mCallback.onFailure(message);
69 } catch (RemoteException e) {
70 e.rethrowAsRuntimeException();
74 private void assertNotCalled() {
76 throw new IllegalStateException("Already called");