16d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme/*
26d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * Copyright (C) 2016 The Android Open Source Project
36d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme *
46d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * Licensed under the Apache License, Version 2.0 (the "License");
56d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * you may not use this file except in compliance with the License.
66d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * You may obtain a copy of the License at
76d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme *
86d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme *      http://www.apache.org/licenses/LICENSE-2.0
96d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme *
106d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * Unless required by applicable law or agreed to in writing, software
116d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * distributed under the License is distributed on an "AS IS" BASIS,
126d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * See the License for the specific language governing permissions and
146d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme * limitations under the License.
156d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme */
16b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme
17782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganovpackage android.service.autofill;
186d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
1925960891466a5291c4e71309a07cb9f53fea9c16Felipe Lemeimport static android.service.autofill.AutofillServiceHelper.assertValid;
20c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmannimport static android.service.autofill.FillRequest.INVALID_REQUEST_ID;
219f9ee25515591ef33281708c0ab911962f4364a6Felipe Lemeimport static android.view.autofill.Helper.sDebug;
22d633f072552815301a559520a1f93eb7e79ba319Felipe Leme
2359c446403c8b54358be57ef569967a19657ff651Felipe Lemeimport android.annotation.IntDef;
240f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganovimport android.annotation.NonNull;
25436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Lemeimport android.annotation.Nullable;
2624d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Lemeimport android.annotation.TestApi;
272ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Lemeimport android.app.Activity;
280f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganovimport android.content.IntentSender;
29cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Lemeimport android.content.pm.ParceledListSlice;
306d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Lemeimport android.os.Bundle;
316d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Lemeimport android.os.Parcel;
326d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Lemeimport android.os.Parcelable;
33b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Lemeimport android.view.autofill.AutofillId;
3400c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganovimport android.widget.RemoteViews;
356d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
3617292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Lemeimport com.android.internal.util.Preconditions;
3717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme
3859c446403c8b54358be57ef569967a19657ff651Felipe Lemeimport java.lang.annotation.Retention;
3959c446403c8b54358be57ef569967a19657ff651Felipe Lemeimport java.lang.annotation.RetentionPolicy;
40fe35e69d964dbd09cc8e6390e41ca9347baea108Felipe Lemeimport java.util.ArrayList;
41c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Lemeimport java.util.Arrays;
42cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Lemeimport java.util.List;
43fe35e69d964dbd09cc8e6390e41ca9347baea108Felipe Leme
446d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme/**
4578172e70f4c5d776678551965db7c167ee11703eFelipe Leme * Response for an {@link
46e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme * AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)}.
476d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme *
482ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Leme * <p>See the main {@link AutofillService} documentation for more details and examples.
496d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme */
506d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Lemepublic final class FillResponse implements Parcelable {
51782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov
5259c446403c8b54358be57ef569967a19657ff651Felipe Leme    /**
53d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme     * Flag used to generate {@link FillEventHistory.Event events} of type
54d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme     * {@link FillEventHistory.Event#TYPE_CONTEXT_COMMITTED}&mdash;if this flag is not passed to
55d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme     * {@link Builder#setFlags(int)}, these events are not generated.
5659c446403c8b54358be57ef569967a19657ff651Felipe Leme     */
5759c446403c8b54358be57ef569967a19657ff651Felipe Leme    public static final int FLAG_TRACK_CONTEXT_COMMITED = 0x1;
5859c446403c8b54358be57ef569967a19657ff651Felipe Leme
5917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme    /**
60d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme     * Flag used to change the behavior of {@link FillResponse.Builder#disableAutofill(long)}&mdash;
61d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme     * when this flag is passed to {@link Builder#setFlags(int)}, autofill is disabled only for the
62d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme     * activiy that generated the {@link FillRequest}, not the whole app.
6317292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme     */
6417292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme    public static final int FLAG_DISABLE_ACTIVITY_ONLY = 0x2;
6517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme
6659c446403c8b54358be57ef569967a19657ff651Felipe Leme    /** @hide */
67ce8db9911494225fcd99711d7df85a130de5a6ceJeff Sharkey    @IntDef(flag = true, prefix = { "FLAG_" }, value = {
6817292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            FLAG_TRACK_CONTEXT_COMMITED,
6917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            FLAG_DISABLE_ACTIVITY_ONLY
7059c446403c8b54358be57ef569967a19657ff651Felipe Leme    })
7159c446403c8b54358be57ef569967a19657ff651Felipe Leme    @Retention(RetentionPolicy.SOURCE)
7259c446403c8b54358be57ef569967a19657ff651Felipe Leme    @interface FillResponseFlags {}
7359c446403c8b54358be57ef569967a19657ff651Felipe Leme
74cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme    private final @Nullable ParceledListSlice<Dataset> mDatasets;
75013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov    private final @Nullable SaveInfo mSaveInfo;
76013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov    private final @Nullable Bundle mClientState;
77013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov    private final @Nullable RemoteViews mPresentation;
78e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme    private final @Nullable RemoteViews mHeader;
79e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme    private final @Nullable RemoteViews mFooter;
80013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov    private final @Nullable IntentSender mAuthentication;
81013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov    private final @Nullable AutofillId[] mAuthenticationIds;
8201ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme    private final @Nullable AutofillId[] mIgnoredIds;
8317292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme    private final long mDisableDuration;
84452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme    private final @Nullable AutofillId[] mFieldClassificationIds;
8559c446403c8b54358be57ef569967a19657ff651Felipe Leme    private final int mFlags;
86c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann    private int mRequestId;
876d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
880f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov    private FillResponse(@NonNull Builder builder) {
89cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme        mDatasets = (builder.mDatasets != null) ? new ParceledListSlice<>(builder.mDatasets) : null;
906ee1ed48b583971915759ce8f6e506168f4dfa78Felipe Leme        mSaveInfo = builder.mSaveInfo;
916f12e67e1724cc52d0f5a5ca0b201a612d2859d8Felipe Leme        mClientState = builder.mClientState;
9200c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov        mPresentation = builder.mPresentation;
93e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        mHeader = builder.mHeader;
94e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        mFooter = builder.mFooter;
950f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov        mAuthentication = builder.mAuthentication;
96b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme        mAuthenticationIds = builder.mAuthenticationIds;
9701ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme        mIgnoredIds = builder.mIgnoredIds;
9817292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        mDisableDuration = builder.mDisableDuration;
99452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme        mFieldClassificationIds = builder.mFieldClassificationIds;
10059c446403c8b54358be57ef569967a19657ff651Felipe Leme        mFlags = builder.mFlags;
101c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann        mRequestId = INVALID_REQUEST_ID;
1026d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    }
1036d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
1046d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    /** @hide */
105013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov    public @Nullable Bundle getClientState() {
106013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov        return mClientState;
1076d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    }
1086d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
109436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme    /** @hide */
110cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme    public @Nullable List<Dataset> getDatasets() {
111cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme        return (mDatasets != null) ? mDatasets.getList() : null;
112436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme    }
113436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme
114436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme    /** @hide */
115f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme    public @Nullable SaveInfo getSaveInfo() {
116f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme        return mSaveInfo;
117436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme    }
118436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme
119436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme    /** @hide */
12000c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov    public @Nullable RemoteViews getPresentation() {
12100c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov        return mPresentation;
12200c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov    }
12300c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov
12400c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov    /** @hide */
125e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme    public @Nullable RemoteViews getHeader() {
126e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        return mHeader;
127e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme    }
128e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme
129e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme    /** @hide */
130e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme    public @Nullable RemoteViews getFooter() {
131e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        return mFooter;
132e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme    }
133e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme
134e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme    /** @hide */
1350f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov    public @Nullable IntentSender getAuthentication() {
1360f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov        return mAuthentication;
137436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme    }
138436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme
139b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme    /** @hide */
140b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme    public @Nullable AutofillId[] getAuthenticationIds() {
141b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme        return mAuthenticationIds;
142b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme    }
143b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme
14401ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme    /** @hide */
14501ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme    public @Nullable AutofillId[] getIgnoredIds() {
14601ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme        return mIgnoredIds;
14701ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme    }
14801ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme
14959c446403c8b54358be57ef569967a19657ff651Felipe Leme    /** @hide */
15017292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme    public long getDisableDuration() {
15117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        return mDisableDuration;
15217292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme    }
15317292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme
15417292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme    /** @hide */
155452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme    public @Nullable AutofillId[] getFieldClassificationIds() {
156452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme        return mFieldClassificationIds;
15724d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme    }
15824d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme
15924d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme    /** @hide */
16078172e70f4c5d776678551965db7c167ee11703eFelipe Leme    @TestApi
16159c446403c8b54358be57ef569967a19657ff651Felipe Leme    public int getFlags() {
16259c446403c8b54358be57ef569967a19657ff651Felipe Leme        return mFlags;
16359c446403c8b54358be57ef569967a19657ff651Felipe Leme    }
16459c446403c8b54358be57ef569967a19657ff651Felipe Leme
1656d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    /**
166c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann     * Associates a {@link FillResponse} to a request.
167c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann     *
168c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann     * <p>Set inside of the {@link FillCallback} code, not the {@link AutofillService}.
169c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann     *
170c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann     * @param requestId The id of the request to associate the response to.
171c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann     *
172c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann     * @hide
173c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann     */
174c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann    public void setRequestId(int requestId) {
175c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann        mRequestId = requestId;
176c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann    }
177c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann
178c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann    /** @hide */
179c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann    public int getRequestId() {
180c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann        return mRequestId;
181c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann    }
182c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann
183c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann    /**
1840f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov     * Builder for {@link FillResponse} objects. You must to provide at least
18500c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov     * one dataset or set an authentication intent with a presentation view.
1866d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme     */
1876d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    public static final class Builder {
188fe35e69d964dbd09cc8e6390e41ca9347baea108Felipe Leme        private ArrayList<Dataset> mDatasets;
189f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme        private SaveInfo mSaveInfo;
1906f12e67e1724cc52d0f5a5ca0b201a612d2859d8Felipe Leme        private Bundle mClientState;
19100c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov        private RemoteViews mPresentation;
192e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        private RemoteViews mHeader;
193e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        private RemoteViews mFooter;
1940f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov        private IntentSender mAuthentication;
195b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme        private AutofillId[] mAuthenticationIds;
19601ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme        private AutofillId[] mIgnoredIds;
19717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        private long mDisableDuration;
198452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme        private AutofillId[] mFieldClassificationIds;
19959c446403c8b54358be57ef569967a19657ff651Felipe Leme        private int mFlags;
2000f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov        private boolean mDestroyed;
2010f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov
202436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme        /**
203601d22007488145f8651930d23aeb7a7a95cc591Felipe Leme         * Triggers a custom UI before before autofilling the screen with any data set in this
204601d22007488145f8651930d23aeb7a7a95cc591Felipe Leme         * response.
205601d22007488145f8651930d23aeb7a7a95cc591Felipe Leme         *
206601d22007488145f8651930d23aeb7a7a95cc591Felipe Leme         * <p><b>Note:</b> Although the name of this method suggests that it should be used just for
207601d22007488145f8651930d23aeb7a7a95cc591Felipe Leme         * authentication flow, it can be used for other advanced flows; see {@link AutofillService}
208601d22007488145f8651930d23aeb7a7a95cc591Felipe Leme         * for examples.
209436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme         *
210782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * <p>This is typically useful when a user interaction is required to unlock their
211782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * data vault if you encrypt the data set labels and data set data. It is recommended
212782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * to encrypt only the sensitive data and not the data set labels which would allow
213782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * auth on the data set level leading to a better user experience. Note that if you
214782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * use sensitive data as a label, for example an email address, then it should also
215782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * be encrypted. The provided {@link android.app.PendingIntent intent} must be an
2162ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Leme         * {@link Activity} which implements your authentication flow. Also if you provide an auth
21700c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov         * intent you also need to specify the presentation view to be shown in the fill UI
218b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme         * for the user to trigger your authentication flow.
219436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme         *
220640f30a7763b0a4b80c767acb84c740aac04768bFelipe Leme         * <p>When a user triggers autofill, the system launches the provided intent
221cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme         * whose extras will have the
222cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme         * {@link android.view.autofill.AutofillManager#EXTRA_ASSIST_STRUCTURE screen
223a9379d0b44ca1f68a0036d2b65218e17fa348514Svetoslav Ganov         * content} and your {@link android.view.autofill.AutofillManager#EXTRA_CLIENT_STATE
2242ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Leme         * client state}. Once you complete your authentication flow you should set the
225b0a4057d44c6bde829a1c45f3d7cb92aab8a489bFelipe Leme         * {@link Activity} result to {@link android.app.Activity#RESULT_OK} and set the
226b0a4057d44c6bde829a1c45f3d7cb92aab8a489bFelipe Leme         * {@link android.view.autofill.AutofillManager#EXTRA_AUTHENTICATION_RESULT} extra
227b0a4057d44c6bde829a1c45f3d7cb92aab8a489bFelipe Leme         * with the fully populated {@link FillResponse response} (or {@code null} if the screen
228b0a4057d44c6bde829a1c45f3d7cb92aab8a489bFelipe Leme         * cannot be autofilled).
229b0a4057d44c6bde829a1c45f3d7cb92aab8a489bFelipe Leme         *
230b0a4057d44c6bde829a1c45f3d7cb92aab8a489bFelipe Leme         * <p>For example, if you provided an empty {@link FillResponse response} because the
231782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * user's data was locked and marked that the response needs an authentication then
232782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * in the response returned if authentication succeeds you need to provide all
233782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * available data sets some of which may need to be further authenticated, for
234b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme         * example a credit card whose CVV needs to be entered.
235436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme         *
236eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov         * <p>If you provide an authentication intent you must also provide a presentation
237eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov         * which is used to visualize visualize the response for triggering the authentication
238b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme         * flow.
239eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov         *
24017292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * <p><b>Note:</b> Do not make the provided pending intent
2410f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov         * immutable by using {@link android.app.PendingIntent#FLAG_IMMUTABLE} as the
242b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme         * platform needs to fill in the authentication arguments.
243436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme         *
24436b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         * <p>Theme does not work with RemoteViews layout. Avoid hardcoded text color
24536b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         * or background color: Autofill on different platforms may have different themes.
24636b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         *
247782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov         * @param authentication Intent to an activity with your authentication flow.
248eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov         * @param presentation The presentation to visualize the response.
2492c888424f84ce976a80293a59bac116425a3a1d9Felipe Leme         * @param ids id of Views that when focused will display the authentication UI.
250436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme         *
251b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme         * @return This builder.
25225960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         *
25325960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         * @throws IllegalArgumentException if any of the following occurs:
25425960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         * <ul>
25525960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         *   <li>{@code ids} is {@code null}</li>
25625960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         *   <li>{@code ids} is empty</li>
25725960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         *   <li>{@code ids} contains a {@code null} element</li>
25825960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         *   <li>both {@code authentication} and {@code presentation} are {@code null}</li>
25925960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         *   <li>both {@code authentication} and {@code presentation} are non-{@code null}</li>
26025960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme         * </ul>
261c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme         *
262e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * @throws IllegalStateException if a {@link #setHeader(RemoteViews) header} or a
263e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * {@link #setFooter(RemoteViews) footer} are already set for this builder.
264e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
2650f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov         * @see android.app.PendingIntent#getIntentSender()
266436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme         */
267b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme        public @NonNull Builder setAuthentication(@NonNull AutofillId[] ids,
268b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme                @Nullable IntentSender authentication, @Nullable RemoteViews presentation) {
2690f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            throwIfDestroyed();
27017292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            throwIfDisableAutofillCalled();
271e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            if (mHeader != null || mFooter != null) {
272e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme                throw new IllegalStateException("Already called #setHeader() or #setFooter()");
273e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            }
274e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme
275eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov            if (authentication == null ^ presentation == null) {
276eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov                throw new IllegalArgumentException("authentication and presentation"
277eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov                        + " must be both non-null or null");
278eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov            }
2790f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            mAuthentication = authentication;
280eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov            mPresentation = presentation;
28125960891466a5291c4e71309a07cb9f53fea9c16Felipe Leme            mAuthenticationIds = assertValid(ids);
282436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme            return this;
283436ab6a91d64ef6036c67bb361d807e398fb2c4cFelipe Leme        }
2846d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
2856d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        /**
286e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme         * Specifies views that should not trigger new
287e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme         * {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal,
288e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme         * FillCallback)} requests.
289e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme         *
2902ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Leme         * <p>This is typically used when the service cannot autofill the view; for example, a
2912ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Leme         * text field representing the result of a Captcha challenge.
292e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme         */
293e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme        public Builder setIgnoredIds(AutofillId...ids) {
29417292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            throwIfDestroyed();
29501ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme            mIgnoredIds = ids;
296e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme            return this;
297e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme        }
298e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme
299e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme        /**
30000c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov         * Adds a new {@link Dataset} to this response.
3016d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme         *
302cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme         * <p><b>Note: </b> on Android {@link android.os.Build.VERSION_CODES#O}, the total number of
303cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme         * datasets is limited by the Binder transaction size, so it's recommended to keep it
304cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme         * small (in the range of 10-20 at most) and use pagination by adding a fake
305c0c6ab4ac1500d2e15f1b28e27b0dd469bed1a6cFelipe Leme         * {@link Dataset.Builder#setAuthentication(IntentSender) authenticated dataset} at the end
306c0c6ab4ac1500d2e15f1b28e27b0dd469bed1a6cFelipe Leme         * with a presentation string like "Next 10" that would return a new {@link FillResponse}
307c0c6ab4ac1500d2e15f1b28e27b0dd469bed1a6cFelipe Leme         * with the next 10 datasets, and so on. This limitation was lifted on
308cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme         * Android {@link android.os.Build.VERSION_CODES#O_MR1}, although the Binder transaction
309cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme         * size can still be reached if each dataset itself is too big.
310cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme         *
31100c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov         * @return This builder.
3126d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme         */
313b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme        public @NonNull Builder addDataset(@Nullable Dataset dataset) {
3140f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            throwIfDestroyed();
31517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            throwIfDisableAutofillCalled();
3160f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            if (dataset == null) {
3170f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov                return this;
3180f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            }
3190f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            if (mDatasets == null) {
320fe35e69d964dbd09cc8e6390e41ca9347baea108Felipe Leme                mDatasets = new ArrayList<>();
3210f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            }
3220f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            if (!mDatasets.add(dataset)) {
3230f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov                return this;
3240f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            }
325f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme            return this;
326f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme        }
327f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme
3286d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        /**
329f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme         * Sets the {@link SaveInfo} associated with this response.
3306d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme         *
331f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme         * @return This builder.
3326d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme         */
333f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme        public @NonNull Builder setSaveInfo(@NonNull SaveInfo saveInfo) {
3340f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            throwIfDestroyed();
33517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            throwIfDisableAutofillCalled();
336f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme            mSaveInfo = saveInfo;
3376d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme            return this;
3386d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        }
3396d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
340e5f9c30688f0277505fb6b50ea385e5df6271ed8Felipe Leme        /**
341d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme         * Sets a bundle with state that is passed to subsequent APIs that manipulate this response.
342d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme         *
343d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme         * <p>You can use this bundle to store intermediate state that is passed to subsequent calls
344d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme         * to {@link AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal,
345d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme         * FillCallback)} and {@link AutofillService#onSaveRequest(SaveRequest, SaveCallback)}, and
346d37f53e6f712e0618891aabb1e6facb108cd0301Felipe Leme         * you can also retrieve it by calling {@link FillEventHistory.Event#getClientState()}.
34700c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov         *
34852d5d3dfc7d4d4b6dfed1686cc904c08d7433a04Felipe Leme         * <p>If this method is called on multiple {@link FillResponse} objects for the same
3492ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Leme         * screen, just the latest bundle is passed back to the service.
35052d5d3dfc7d4d4b6dfed1686cc904c08d7433a04Felipe Leme         *
351013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov         * @param clientState The custom client state.
35200c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov         * @return This builder.
3536d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme         */
354013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov        public Builder setClientState(@Nullable Bundle clientState) {
3550f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            throwIfDestroyed();
356b57080eb4142969a7e613f0a7ce557dc7cd23a40Felipe Leme            throwIfDisableAutofillCalled();
3576f12e67e1724cc52d0f5a5ca0b201a612d2859d8Felipe Leme            mClientState = clientState;
3586d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme            return this;
3596d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        }
3606d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
3616d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        /**
36278172e70f4c5d776678551965db7c167ee11703eFelipe Leme         * Sets which fields are used for
36378172e70f4c5d776678551965db7c167ee11703eFelipe Leme         * <a href="AutofillService.html#FieldClassification">field classification</a>
364452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme         *
36578172e70f4c5d776678551965db7c167ee11703eFelipe Leme         * <p><b>Note:</b> This method automatically adds the
36678172e70f4c5d776678551965db7c167ee11703eFelipe Leme         * {@link FillResponse#FLAG_TRACK_CONTEXT_COMMITED} to the {@link #setFlags(int) flags}.
36778172e70f4c5d776678551965db7c167ee11703eFelipe Leme
368452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme         * @throws IllegalArgumentException is length of {@code ids} args is more than
369452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme         * {@link UserData#getMaxFieldClassificationIdsSize()}.
370452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme         * @throws IllegalStateException if {@link #build()} or {@link #disableAutofill(long)} was
371452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme         * already called.
372452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme         * @throws NullPointerException if {@code ids} or any element on it is {@code null}.
37324d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme         */
374452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme        public Builder setFieldClassificationIds(@NonNull AutofillId... ids) {
37524d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme            throwIfDestroyed();
37624d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme            throwIfDisableAutofillCalled();
377452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme            Preconditions.checkArrayElementsNotNull(ids, "ids");
378452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme            Preconditions.checkArgumentInRange(ids.length, 1,
379452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme                    UserData.getMaxFieldClassificationIdsSize(), "ids length");
380452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme            mFieldClassificationIds = ids;
38178172e70f4c5d776678551965db7c167ee11703eFelipe Leme            mFlags |= FLAG_TRACK_CONTEXT_COMMITED;
38224d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme            return this;
38324d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme        }
38424d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme
38524d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme        /**
38659c446403c8b54358be57ef569967a19657ff651Felipe Leme         * Sets flags changing the response behavior.
38759c446403c8b54358be57ef569967a19657ff651Felipe Leme         *
38817292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * @param flags a combination of {@link #FLAG_TRACK_CONTEXT_COMMITED} and
38917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * {@link #FLAG_DISABLE_ACTIVITY_ONLY}, or {@code 0}.
39059c446403c8b54358be57ef569967a19657ff651Felipe Leme         *
39159c446403c8b54358be57ef569967a19657ff651Felipe Leme         * @return This builder.
39259c446403c8b54358be57ef569967a19657ff651Felipe Leme         */
39359c446403c8b54358be57ef569967a19657ff651Felipe Leme        public Builder setFlags(@FillResponseFlags int flags) {
39459c446403c8b54358be57ef569967a19657ff651Felipe Leme            throwIfDestroyed();
39517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            mFlags = Preconditions.checkFlagsArgument(flags,
39617292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme                    FLAG_TRACK_CONTEXT_COMMITED | FLAG_DISABLE_ACTIVITY_ONLY);
39717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            return this;
39817292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        }
39917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme
40017292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        /**
40117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * Disables autofill for the app or activity.
40217292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *
40317292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * <p>This method is useful to optimize performance in cases where the service knows it
40417292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * can not autofill an app&mdash;for example, when the service has a list of "blacklisted"
40517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * apps such as office suites.
40617292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *
40717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * <p>By default, it disables autofill for all activities in the app, unless the response is
40817292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * {@link #setFlags(int) flagged} with {@link #FLAG_DISABLE_ACTIVITY_ONLY}.
40917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *
41017292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * <p>Autofill for the app or activity is automatically re-enabled after any of the
41117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * following conditions:
41217292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *
41317292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * <ol>
41417292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *   <li>{@code duration} milliseconds have passed.
41517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *   <li>The autofill service for the user has changed.
41617292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *   <li>The device has rebooted.
41717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * </ol>
41817292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *
41917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * <p><b>Note:</b> Activities that are running when autofill is re-enabled remain
42017292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * disabled for autofill until they finish and restart.
42117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *
42217292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * @param duration duration to disable autofill, in milliseconds.
42317292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *
42417292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * @return this builder
42517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *
42617292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * @throws IllegalArgumentException if {@code duration} is not a positive number.
42717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * @throws IllegalStateException if either {@link #addDataset(Dataset)},
428b57080eb4142969a7e613f0a7ce557dc7cd23a40Felipe Leme         *       {@link #setAuthentication(AutofillId[], IntentSender, RemoteViews)},
429452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme         *       {@link #setSaveInfo(SaveInfo)}, {@link #setClientState(Bundle)}, or
43078172e70f4c5d776678551965db7c167ee11703eFelipe Leme         *       {@link #setFieldClassificationIds(AutofillId...)} was already called.
43117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         */
43217292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        public Builder disableAutofill(long duration) {
43317292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            throwIfDestroyed();
43417292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            if (duration <= 0) {
43517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme                throw new IllegalArgumentException("duration must be greater than 0");
43617292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            }
43724d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme            if (mAuthentication != null || mDatasets != null || mSaveInfo != null
438452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme                    || mFieldClassificationIds != null || mClientState != null) {
43917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme                throw new IllegalStateException("disableAutofill() must be the only method called");
44017292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            }
44117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme
44217292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            mDisableDuration = duration;
44359c446403c8b54358be57ef569967a19657ff651Felipe Leme            return this;
44459c446403c8b54358be57ef569967a19657ff651Felipe Leme        }
44559c446403c8b54358be57ef569967a19657ff651Felipe Leme
44659c446403c8b54358be57ef569967a19657ff651Felipe Leme        /**
447e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * Sets a header to be shown as the first element in the list of datasets.
448e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
449e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * <p>When this method is called, you must also {@link #addDataset(Dataset) add a dataset},
450e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * otherwise {@link #build()} throws an {@link IllegalStateException}. Similarly, this
451e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * method should only be used on {@link FillResponse FillResponses} that do not require
452e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * authentication (as the header could have been set directly in the main presentation in
453e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * these cases).
454e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
45536b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         * <p>Theme does not work with RemoteViews layout. Avoid hardcoded text color
45636b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         * or background color: Autofill on different platforms may have different themes.
45736b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         *
458e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * @param header a presentation to represent the header. This presentation is not clickable
459e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * &mdash;calling
460e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * {@link RemoteViews#setOnClickPendingIntent(int, android.app.PendingIntent)} on it would
461e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * have no effect.
462e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
463e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * @return this builder
464e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
465e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * @throws IllegalStateException if an
466e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * {@link #setAuthentication(AutofillId[], IntentSender, RemoteViews) authentication} was
467e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * already set for this builder.
468e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         */
469e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        // TODO(b/69796626): make it sticky / update javadoc
470e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        public Builder setHeader(@NonNull RemoteViews header) {
471e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            throwIfDestroyed();
472e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            throwIfAuthenticationCalled();
473e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            mHeader = Preconditions.checkNotNull(header);
474e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            return this;
475e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        }
476e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme
477e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        /**
478e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * Sets a footer to be shown as the last element in the list of datasets.
479e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
480e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * <p>When this method is called, you must also {@link #addDataset(Dataset) add a dataset},
481e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * otherwise {@link #build()} throws an {@link IllegalStateException}. Similarly, this
482e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * method should only be used on {@link FillResponse FillResponses} that do not require
483e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * authentication (as the footer could have been set directly in the main presentation in
484e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * these cases).
485e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
48636b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         * <p>Theme does not work with RemoteViews layout. Avoid hardcoded text color
48736b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         * or background color: Autofill on different platforms may have different themes.
48836b86c28f88e4c7853a4255a0fd9b754cbb547c4Dake Gu         *
489e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * @param footer a presentation to represent the footer. This presentation is not clickable
490e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * &mdash;calling
491e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * {@link RemoteViews#setOnClickPendingIntent(int, android.app.PendingIntent)} on it would
492e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * have no effect.
493e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
494e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * @return this builder
495e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *
496e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * @throws IllegalStateException if the FillResponse
497e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * {@link #setAuthentication(AutofillId[], IntentSender, RemoteViews)
498e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         * requires authentication}.
499e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         */
500e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        // TODO(b/69796626): make it sticky / update javadoc
501e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        public Builder setFooter(@NonNull RemoteViews footer) {
502e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            throwIfDestroyed();
503e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            throwIfAuthenticationCalled();
504e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            mFooter = Preconditions.checkNotNull(footer);
505e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            return this;
506e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        }
507e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme
508e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        /**
5092ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Leme         * Builds a new {@link FillResponse} instance.
5102ef19c1d73f89ca4718b5a8f0c2e7221621e844fFelipe Leme         *
51117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * @throws IllegalStateException if any of the following conditions occur:
51217292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * <ol>
51317292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *   <li>{@link #build()} was already called.
51417292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *   <li>No call was made to {@link #addDataset(Dataset)},
51517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         *       {@link #setAuthentication(AutofillId[], IntentSender, RemoteViews)},
516b57080eb4142969a7e613f0a7ce557dc7cd23a40Felipe Leme         *       {@link #setSaveInfo(SaveInfo)}, {@link #disableAutofill(long)},
517452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme         *       {@link #setClientState(Bundle)},
51878172e70f4c5d776678551965db7c167ee11703eFelipe Leme         *       or {@link #setFieldClassificationIds(AutofillId...)}.
519e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *   <li>{@link #setHeader(RemoteViews)} or {@link #setFooter(RemoteViews)} is called
520e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme         *       without any previous calls to {@link #addDataset(Dataset)}.
52117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme         * </ol>
52200c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov         *
52300c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov         * @return A built response.
5246d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme         */
5256d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        public FillResponse build() {
5260f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            throwIfDestroyed();
52717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            if (mAuthentication == null && mDatasets == null && mSaveInfo == null
528452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme                    && mDisableDuration == 0 && mFieldClassificationIds == null
529452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme                    && mClientState == null) {
53024d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme                throw new IllegalStateException("need to provide: at least one DataSet, or a "
53124d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme                        + "SaveInfo, or an authentication with a presentation, "
532b57080eb4142969a7e613f0a7ce557dc7cd23a40Felipe Leme                        + "or a FieldsDetection, or a client state, or disable autofill");
53300c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov            }
534e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            if (mDatasets == null && (mHeader != null || mFooter != null)) {
535e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme                throw new IllegalStateException(
536e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme                        "must add at least 1 dataset when using header or footer");
537e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            }
5380f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            mDestroyed = true;
5396d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme            return new FillResponse(this);
5406d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        }
5410f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov
5420f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov        private void throwIfDestroyed() {
5430f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            if (mDestroyed) {
5440f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov                throw new IllegalStateException("Already called #build()");
5450f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            }
5460f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov        }
54717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme
54817292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        private void throwIfDisableAutofillCalled() {
54917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            if (mDisableDuration > 0) {
55017292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme                throw new IllegalStateException("Already called #disableAutofill()");
55117292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            }
55217292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        }
553e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme
554e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        private void throwIfAuthenticationCalled() {
555e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            if (mAuthentication != null) {
556e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme                throw new IllegalStateException("Already called #setAuthentication()");
557e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            }
558e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        }
5596d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    }
5606d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
5616d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    /////////////////////////////////////
562b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme    // Object "contract" methods. //
5636d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    /////////////////////////////////////
5646d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    @Override
5656d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    public String toString() {
5669f9ee25515591ef33281708c0ab911962f4364a6Felipe Leme        if (!sDebug) return super.toString();
567f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme
568c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme        // TODO: create a dump() method instead
569da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        final StringBuilder builder = new StringBuilder(
570da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme                "FillResponse : [mRequestId=" + mRequestId);
571da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mDatasets != null) {
572da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", datasets=").append(mDatasets.getList());
573da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
574da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mSaveInfo != null) {
575da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", saveInfo=").append(mSaveInfo);
576da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
577da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mClientState != null) {
578da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", hasClientState");
579da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
580da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mPresentation != null) {
581da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", hasPresentation");
582da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
583da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mHeader != null) {
584da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", hasHeader");
585da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
586da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mFooter != null) {
587da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", hasFooter");
588da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
589da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mAuthentication != null) {
590da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", hasAuthentication");
591da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
592da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mAuthenticationIds != null) {
593da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", authenticationIds=").append(Arrays.toString(mAuthenticationIds));
594da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
595da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        builder.append(", disableDuration=").append(mDisableDuration);
596da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mFlags != 0) {
597da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(", flags=").append(mFlags);
598da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
599da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        if (mFieldClassificationIds != null) {
600da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme            builder.append(Arrays.toString(mFieldClassificationIds));
601da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        }
602da9ea34c029df809e6b833a483408662e13ca9a1Felipe Leme        return builder.append("]").toString();
6036d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    }
6046d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
6056d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    /////////////////////////////////////
606b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme    // Parcelable "contract" methods. //
6076d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    /////////////////////////////////////
6086d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
6096d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    @Override
6106d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    public int describeContents() {
6116d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        return 0;
6126d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    }
6136d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
6146d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    @Override
6156d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    public void writeToParcel(Parcel parcel, int flags) {
616cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme        parcel.writeParcelable(mDatasets, flags);
617f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme        parcel.writeParcelable(mSaveInfo, flags);
618013efe173e56612a910ebd8576480ce4ef005e3cSvet Ganov        parcel.writeParcelable(mClientState, flags);
619b3c3537566b5993a2abc01b63da9dbe6fd32e57aFelipe Leme        parcel.writeParcelableArray(mAuthenticationIds, flags);
62000c771dc7d8242362f1491ae4ce3efd641235b36Svet Ganov        parcel.writeParcelable(mAuthentication, flags);
621eb49515abd2353f32e0eb7b3964847c6399986c9Svet Ganov        parcel.writeParcelable(mPresentation, flags);
622e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        parcel.writeParcelable(mHeader, flags);
623e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme        parcel.writeParcelable(mFooter, flags);
62401ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme        parcel.writeParcelableArray(mIgnoredIds, flags);
62517292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme        parcel.writeLong(mDisableDuration);
626452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme        parcel.writeParcelableArray(mFieldClassificationIds, flags);
62759c446403c8b54358be57ef569967a19657ff651Felipe Leme        parcel.writeInt(mFlags);
628c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann        parcel.writeInt(mRequestId);
6296d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    }
6306d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
6316d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    public static final Parcelable.Creator<FillResponse> CREATOR =
6326d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme            new Parcelable.Creator<FillResponse>() {
6336d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        @Override
6340f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov        public FillResponse createFromParcel(Parcel parcel) {
6350f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            // Always go through the builder to ensure the data ingested by
6360f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            // the system obeys the contract of the builder to avoid attacks
6370f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            // using specially crafted parcels.
638782043caf81055aa1c331e9cc15b24a10e1bf17aSvet Ganov            final Builder builder = new Builder();
639cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme            final ParceledListSlice<Dataset> datasetSlice = parcel.readParcelable(null);
640cb96f3915525b4122e44f325bb477bcc72ff2d40Felipe Leme            final List<Dataset> datasets = (datasetSlice != null) ? datasetSlice.getList() : null;
6410f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            final int datasetCount = (datasets != null) ? datasets.size() : 0;
6420f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            for (int i = 0; i < datasetCount; i++) {
643fe35e69d964dbd09cc8e6390e41ca9347baea108Felipe Leme                builder.addDataset(datasets.get(i));
6440f4928f1f73407485d6d94beda1dba1a2360ebbfSvet Ganov            }
645f69761ffbe3098067ae720263ef05262f4b5d41eFelipe Leme            builder.setSaveInfo(parcel.readParcelable(null));
64601ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme            builder.setClientState(parcel.readParcelable(null));
647c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme
648c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme            // Sets authentication state.
649c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme            final AutofillId[] authenticationIds = parcel.readParcelableArray(null,
650c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme                    AutofillId.class);
651c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme            final IntentSender authentication = parcel.readParcelable(null);
652c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme            final RemoteViews presentation = parcel.readParcelable(null);
653c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme            if (authenticationIds != null) {
654c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme                builder.setAuthentication(authenticationIds, authentication, presentation);
655c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme            }
656e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            final RemoteViews header = parcel.readParcelable(null);
657e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            if (header != null) {
658e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme                builder.setHeader(header);
659e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            }
660e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            final RemoteViews footer = parcel.readParcelable(null);
661e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            if (footer != null) {
662e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme                builder.setFooter(footer);
663e9324786a7a6aba5b9196e0ce79e30ecd1168ec8Felipe Leme            }
664c2430f3c4d6e3b996917f57c8afb0b00b5bef45bFelipe Leme
66501ded104a139d9f68b0fa05c548c9261e61c75c1Felipe Leme            builder.setIgnoredIds(parcel.readParcelableArray(null, AutofillId.class));
66617292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            final long disableDuration = parcel.readLong();
66717292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            if (disableDuration > 0) {
66817292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme                builder.disableAutofill(disableDuration);
66917292d1a25a4d0c3910a687a4207e7ff5688be1dFelipe Leme            }
670452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme            final AutofillId[] fieldClassifactionIds =
671452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme                    parcel.readParcelableArray(null, AutofillId.class);
672452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme            if (fieldClassifactionIds != null) {
673452886a5b8d7cb94ba0c53e8976ff558980db1e5Felipe Leme                builder.setFieldClassificationIds(fieldClassifactionIds);
67424d7173cf1e3193bb48c9c6aed0261efe34f890bFelipe Leme            }
67559c446403c8b54358be57ef569967a19657ff651Felipe Leme            builder.setFlags(parcel.readInt());
676c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann
67759c446403c8b54358be57ef569967a19657ff651Felipe Leme            final FillResponse response = builder.build();
678c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann            response.setRequestId(parcel.readInt());
679c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann
680c7619632145c23e6b5dd45620094e0bc686ad2dbPhilip P. Moltmann            return response;
6816d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        }
6826d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme
6836d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        @Override
6846d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        public FillResponse[] newArray(int size) {
6856d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme            return new FillResponse[size];
6866d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme        }
6876d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme    };
6886d553874bed06280766ae24ea605f9bbde3f5a4aFelipe Leme}
689