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 | */ |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 16 | package android.service.autofill.augmented; |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 17 | |
| 18 | import android.annotation.NonNull; |
| 19 | import android.annotation.Nullable; |
| 20 | import android.annotation.SystemApi; |
Felipe Leme | 2cab38c | 2019-01-11 10:39:14 -0800 | [diff] [blame] | 21 | import android.annotation.TestApi; |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 22 | import android.view.autofill.AutofillId; |
| 23 | |
| 24 | import java.util.List; |
| 25 | |
| 26 | /** |
| 27 | * Response to a {@link FillRequest}. |
| 28 | * |
| 29 | * @hide |
| 30 | */ |
| 31 | @SystemApi |
Felipe Leme | 2cab38c | 2019-01-11 10:39:14 -0800 | [diff] [blame] | 32 | @TestApi |
Felipe Leme | 559e21d | 2019-01-18 17:57:21 -0800 | [diff] [blame] | 33 | public final class FillResponse { |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 34 | |
| 35 | private final FillWindow mFillWindow; |
| 36 | |
| 37 | private FillResponse(@NonNull Builder builder) { |
| 38 | mFillWindow = builder.mFillWindow; |
| 39 | } |
| 40 | |
| 41 | /** @hide */ |
| 42 | @Nullable |
| 43 | FillWindow getFillWindow() { |
| 44 | return mFillWindow; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Builder for {@link FillResponse} objects. |
| 49 | * |
| 50 | * @hide |
| 51 | */ |
| 52 | @SystemApi |
Felipe Leme | 2cab38c | 2019-01-11 10:39:14 -0800 | [diff] [blame] | 53 | @TestApi |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 54 | public static final class Builder { |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 55 | |
| 56 | private FillWindow mFillWindow; |
| 57 | |
| 58 | /** |
| 59 | * Sets the {@link FillWindow} used to display the Autofill UI. |
| 60 | * |
| 61 | * <p>Must be called when the service is handling the request so the Android System can |
| 62 | * properly synchronize the UI. |
| 63 | * |
| 64 | * @return this builder |
| 65 | */ |
| 66 | public Builder setFillWindow(@NonNull FillWindow fillWindow) { |
Felipe Leme | 559e21d | 2019-01-18 17:57:21 -0800 | [diff] [blame] | 67 | // TODO(b/123100712): check not null / unit test / throw exception if FillWindow not |
| 68 | // updated yet |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 69 | mFillWindow = fillWindow; |
| 70 | return this; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Tells the Android System that the given {@code ids} should not trigger further |
| 75 | * {@link FillRequest requests} when focused. |
| 76 | * |
| 77 | * @param ids ids of the fields that should be ignored |
| 78 | * |
| 79 | * @return this builder |
| 80 | */ |
| 81 | public Builder setIgnoredIds(@NonNull List<AutofillId> ids) { |
Felipe Leme | 559e21d | 2019-01-18 17:57:21 -0800 | [diff] [blame] | 82 | // TODO(b/123100695): implement / check not null / unit test |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 83 | return this; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Builds a new {@link FillResponse} instance. |
| 88 | * |
| 89 | * @throws IllegalStateException if any of the following conditions occur: |
| 90 | * <ol> |
| 91 | * <li>{@link #build()} was already called. |
| 92 | * <li>No call was made to {@link #setFillWindow(FillWindow)} or |
| 93 | * {@ling #setIgnoredIds(List<AutofillId>)}. |
| 94 | * </ol> |
| 95 | * |
| 96 | * @return A built response. |
| 97 | */ |
| 98 | public FillResponse build() { |
Felipe Leme | 559e21d | 2019-01-18 17:57:21 -0800 | [diff] [blame] | 99 | // TODO(b/123100712): check conditions / add unit test |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 100 | return new FillResponse(this); |
| 101 | } |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Felipe Leme | 559e21d | 2019-01-18 17:57:21 -0800 | [diff] [blame] | 104 | // TODO(b/123100811): implement to String |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 105 | } |