Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 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.intelligence; |
| 17 | |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 18 | import static android.service.intelligence.SmartSuggestionsService.DEBUG; |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 19 | |
| 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.SystemApi; |
| 22 | import android.os.RemoteException; |
Felipe Leme | ecb08be | 2018-11-27 15:48:47 -0800 | [diff] [blame] | 23 | import android.service.intelligence.SmartSuggestionsService.AutofillProxy; |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 24 | import android.util.Log; |
| 25 | import android.util.Pair; |
| 26 | import android.view.autofill.AutofillId; |
| 27 | import android.view.autofill.AutofillValue; |
| 28 | |
| 29 | import com.android.internal.util.Preconditions; |
| 30 | |
| 31 | import java.util.List; |
| 32 | |
| 33 | /** |
| 34 | * Object used to interact with the autofill system. |
| 35 | * |
| 36 | * @hide |
| 37 | */ |
| 38 | @SystemApi |
| 39 | public 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 | } |