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 | |
| 18 | import android.annotation.NonNull; |
| 19 | import android.annotation.Nullable; |
| 20 | import android.annotation.SystemApi; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | import android.view.autofill.AutofillId; |
| 24 | |
| 25 | import java.util.List; |
| 26 | |
| 27 | /** |
| 28 | * Response to a {@link FillRequest}. |
| 29 | * |
| 30 | * @hide |
| 31 | */ |
| 32 | @SystemApi |
| 33 | public final class FillResponse implements Parcelable { |
| 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 |
| 53 | public static class Builder { |
| 54 | |
| 55 | private FillWindow mFillWindow; |
| 56 | |
| 57 | /** |
| 58 | * Sets the {@link FillWindow} used to display the Autofill UI. |
| 59 | * |
| 60 | * <p>Must be called when the service is handling the request so the Android System can |
| 61 | * properly synchronize the UI. |
| 62 | * |
| 63 | * @return this builder |
| 64 | */ |
| 65 | public Builder setFillWindow(@NonNull FillWindow fillWindow) { |
| 66 | // TODO(b/111330312): implement / check not null / unit test |
| 67 | // TODO(b/111330312): throw exception if FillWindow not updated yet |
| 68 | mFillWindow = fillWindow; |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Tells the Android System that the given {@code ids} should not trigger further |
| 74 | * {@link FillRequest requests} when focused. |
| 75 | * |
| 76 | * @param ids ids of the fields that should be ignored |
| 77 | * |
| 78 | * @return this builder |
| 79 | */ |
| 80 | public Builder setIgnoredIds(@NonNull List<AutofillId> ids) { |
| 81 | // TODO(b/111330312): implement / check not null / unit test |
| 82 | return this; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Builds a new {@link FillResponse} instance. |
| 87 | * |
| 88 | * @throws IllegalStateException if any of the following conditions occur: |
| 89 | * <ol> |
| 90 | * <li>{@link #build()} was already called. |
| 91 | * <li>No call was made to {@link #setFillWindow(FillWindow)} or |
| 92 | * {@ling #setIgnoredIds(List<AutofillId>)}. |
| 93 | * </ol> |
| 94 | * |
| 95 | * @return A built response. |
| 96 | */ |
| 97 | public FillResponse build() { |
| 98 | // TODO(b/111330312): check conditions / add unit test |
| 99 | return new FillResponse(this); |
| 100 | } |
| 101 | |
| 102 | // TODO(b/111330312): add methods to disable app / activity, either here or on manager |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public int describeContents() { |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void writeToParcel(Parcel parcel, int flags) { |
| 112 | // TODO(b/111330312): implement |
| 113 | } |
| 114 | |
| 115 | public static final Parcelable.Creator<FillResponse> CREATOR = |
| 116 | new Parcelable.Creator<FillResponse>() { |
| 117 | |
| 118 | @Override |
| 119 | public FillResponse createFromParcel(Parcel parcel) { |
| 120 | // TODO(b/111330312): implement |
| 121 | return null; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public FillResponse[] newArray(int size) { |
| 126 | return new FillResponse[size]; |
| 127 | } |
| 128 | }; |
| 129 | } |