blob: e65cf47e1645a84ebb47660881ed57a51512bb86 [file] [log] [blame]
Felipe Leme284ad1c2018-11-15 18:16:12 -08001/*
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 */
Felipe Leme749b8892018-12-03 16:30:30 -080016package android.service.autofill.augmented;
Felipe Leme284ad1c2018-11-15 18:16:12 -080017
Felipe Leme749b8892018-12-03 16:30:30 -080018import static android.service.autofill.augmented.AugmentedAutofillService.DEBUG;
Felipe Leme284ad1c2018-11-15 18:16:12 -080019
20import android.annotation.NonNull;
21import android.annotation.SystemApi;
22import android.os.RemoteException;
Felipe Leme749b8892018-12-03 16:30:30 -080023import android.service.autofill.augmented.AugmentedAutofillService.AutofillProxy;
Felipe Leme284ad1c2018-11-15 18:16:12 -080024import android.util.Log;
25import android.util.Pair;
26import android.view.autofill.AutofillId;
27import android.view.autofill.AutofillValue;
28
29import com.android.internal.util.Preconditions;
30
31import java.util.List;
32
33/**
34 * Object used to interact with the autofill system.
35 *
36 * @hide
37 */
38@SystemApi
39public final class FillController {
40 private static final String TAG = "FillController";
41
42 private final AutofillProxy mProxy;
43
44 FillController(@NonNull AutofillProxy proxy) {
45 mProxy = proxy;
46 }
47
48 /**
49 * Fills the activity with the provided values.
50 *
51 * <p>As a side effect, the {@link FillWindow} associated with the {@link FillResponse} will be
52 * automatically {@link FillWindow#destroy() destroyed}.
53 */
54 public void autofill(@NonNull List<Pair<AutofillId, AutofillValue>> values) {
55 Preconditions.checkNotNull(values);
56
57 if (DEBUG) {
58 Log.d(TAG, "autofill() with " + values.size() + " values");
59 }
60
61 try {
62 mProxy.autofill(values);
63 final FillWindow fillWindow = mProxy.getFillWindow();
64 if (fillWindow != null) {
65 fillWindow.destroy();
66 }
67 } catch (RemoteException e) {
68 e.rethrowAsRuntimeException();
69 }
70 }
71}