1 /*
2  * Copyright (C) 2021 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 
17 package android.service.autofill;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 
22 import java.lang.annotation.Retention;
23 import java.lang.annotation.RetentionPolicy;
24 import java.util.Set;
25 
26 /**
27  * Handles the response to
28  * {@link AutofillService#onSavedDatasetsInfoRequest(SavedDatasetsInfoCallback)}.
29  * <p>
30  * Use {@link #onSuccess(Set)} to return the computed info about the datasets the user saved to this
31  * service. If there was an error querying the info, or if the service is unable to do so at this
32  * time (for example, if the user isn't logged in), call {@link #onError(int)}.
33  * <p>
34  * This callback can be used only once.
35  */
36 public interface SavedDatasetsInfoCallback {
37 
38     /** @hide */
39     @IntDef(prefix = {"ERROR_"}, value = {
40             ERROR_OTHER,
41             ERROR_UNSUPPORTED,
42             ERROR_NEEDS_USER_ACTION
43     })
44     @Retention(RetentionPolicy.SOURCE)
45     @interface Error {
46     }
47 
48     /**
49      * The result could not be computed for any other reason.
50      */
51     int ERROR_OTHER = 0;
52     /**
53      * The service does not support this request.
54      */
55     int ERROR_UNSUPPORTED = 1;
56     /**
57      * The result cannot be computed until the user takes some action, such as setting up their
58      * account.
59      */
60     int ERROR_NEEDS_USER_ACTION = 2;
61 
62     /**
63      * Successfully respond to the request with the info on each type of saved datasets.
64      */
onSuccess(@onNull Set<SavedDatasetsInfo> results)65     void onSuccess(@NonNull Set<SavedDatasetsInfo> results);
66 
67     /**
68      * Respond to the request with an error. System settings may display a suitable notice to the
69      * user.
70      */
onError(@rror int error)71     void onError(@Error int error);
72 }
73