1 /**
2  * Copyright 2020, 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.app.appsearch.aidl;
17 
18 import android.os.Bundle;
19 import android.os.UserHandle;
20 
21 import android.app.appsearch.aidl.AppSearchAttributionSource;
22 import android.app.appsearch.aidl.AppSearchResultParcel;
23 import android.app.appsearch.aidl.IAppSearchBatchResultCallback;
24 import android.app.appsearch.aidl.IAppSearchObserverProxy;
25 import android.app.appsearch.aidl.IAppSearchResultCallback;
26 import android.app.appsearch.aidl.ExecuteAppFunctionAidlRequest;
27 import android.app.appsearch.aidl.DocumentsParcel;
28 import android.app.appsearch.aidl.GetDocumentsAidlRequest;
29 import android.app.appsearch.aidl.GetNamespacesAidlRequest;
30 import android.app.appsearch.aidl.GetNextPageAidlRequest;
31 import android.app.appsearch.aidl.GetSchemaAidlRequest;
32 import android.app.appsearch.aidl.GetStorageInfoAidlRequest;
33 import android.app.appsearch.aidl.GlobalSearchAidlRequest;
34 import android.app.appsearch.aidl.InitializeAidlRequest;
35 import android.app.appsearch.aidl.InvalidateNextPageTokenAidlRequest;
36 import android.app.appsearch.aidl.PersistToDiskAidlRequest;
37 import android.app.appsearch.aidl.PutDocumentsAidlRequest;
38 import android.app.appsearch.aidl.PutDocumentsFromFileAidlRequest;
39 import android.app.appsearch.aidl.RegisterObserverCallbackAidlRequest;
40 import android.app.appsearch.aidl.RemoveByDocumentIdAidlRequest;
41 import android.app.appsearch.aidl.RemoveByQueryAidlRequest;
42 import android.app.appsearch.aidl.ReportUsageAidlRequest;
43 import android.app.appsearch.aidl.SearchAidlRequest;
44 import android.app.appsearch.aidl.SearchSuggestionAidlRequest;
45 import android.app.appsearch.aidl.SetSchemaAidlRequest;
46 import android.app.appsearch.aidl.UnregisterObserverCallbackAidlRequest;
47 import android.app.appsearch.aidl.WriteSearchResultsToFileAidlRequest;
48 import android.app.appsearch.stats.SchemaMigrationStats;
49 import android.app.appsearch.AppSearchSchema;
50 import android.app.appsearch.InternalVisibilityConfig;
51 import android.app.appsearch.SearchSpec;
52 import android.app.appsearch.SearchSuggestionSpec;
53 import android.content.AttributionSource;
54 import android.os.ParcelFileDescriptor;
55 
56 /** {@hide} */
57 // Always add new functions in the end with the commented transaction id.
58 interface IAppSearchManager {
59     /**
60      * Creates and initializes AppSearchImpl for the calling app.
61      *
62      * @param request {@link InitializeAidlRequest} contains the input parameters for initialize
63      *     operation.
64      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
65      *     {@link AppSearchResult}<{@link Void}>.
66      */
initialize( in InitializeAidlRequest request, in IAppSearchResultCallback callback)67     void initialize(
68         in InitializeAidlRequest request,
69         in IAppSearchResultCallback callback) = 0;
70 
71     /**
72      * Updates the AppSearch schema for this database.
73      *
74      * @param request {@link SetSchemaAidlRequest} contains the input parameters for set schema
75      *     operation.
76      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
77      *     {@link AppSearchResult}<{@link InternalSetSchemaResponse}>.
78      */
setSchema( in SetSchemaAidlRequest request, in IAppSearchResultCallback callback)79     void setSchema(
80         in SetSchemaAidlRequest request,
81         in IAppSearchResultCallback callback) = 1;
82 
83     /**
84      * Retrieves the AppSearch schema for this database.
85      *
86      * @param request {@link GetSchemaAidlRequest} contains the input parameters for get schema
87      *     operation.
88      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
89      *     {@link AppSearchResult}<{@link Bundle}> where the bundle is a GetSchemaResponse.
90      */
getSchema( in GetSchemaAidlRequest request, in IAppSearchResultCallback callback)91     void getSchema(
92         in GetSchemaAidlRequest request,
93         in IAppSearchResultCallback callback) = 2;
94 
95     /**
96      * Retrieves the set of all namespaces in the current database with at least one document.
97      *
98      * @param request {@link GetNamespacesAidlRequest} contains the input parameters for get
99      *     namespaces operation.
100      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
101      *     {@link AppSearchResult}<{@link List}<{@link String}>>.
102      */
getNamespaces( in GetNamespacesAidlRequest request, in IAppSearchResultCallback callback)103     void getNamespaces(
104         in GetNamespacesAidlRequest request,
105         in IAppSearchResultCallback callback) = 3;
106 
107     /**
108      * Inserts documents into the index.
109      *
110      * @param request {@link PutDocumentsAidlRequest} contains the input parameters for
111      *     put documents operation.
112      * @param callback
113      *     If the call fails to start, {@link IAppSearchBatchResultCallback#onSystemError}
114      *     will be called with the cause throwable. Otherwise,
115      *     {@link IAppSearchBatchResultCallback#onResult} will be called with an
116      *     {@link AppSearchBatchResult}<{@link String}, {@link Void}>
117      *     where the keys are document IDs, and the values are {@code null}.
118      */
putDocuments( in PutDocumentsAidlRequest request, in IAppSearchBatchResultCallback callback)119     void putDocuments(
120         in PutDocumentsAidlRequest request,
121         in IAppSearchBatchResultCallback callback) = 4;
122 
123     /**
124      * Retrieves documents from the index.
125      *
126      * @param request {@link GetDocumentsAidlRequest} that contains the input parameters for the
127      *     get documents operation.
128      * @param callback
129      *     If the call fails to start, {@link IAppSearchBatchResultCallback#onSystemError}
130      *     will be called with the cause throwable. Otherwise,
131      *     {@link IAppSearchBatchResultCallback#onResult} will be called with an
132      *     {@link AppSearchBatchResult}<{@link String}, {@link Bundle}>
133      *     where the keys are document IDs, and the values are Document bundles.
134      */
getDocuments( in GetDocumentsAidlRequest request, in IAppSearchBatchResultCallback callback)135     void getDocuments(
136         in GetDocumentsAidlRequest request,
137         in IAppSearchBatchResultCallback callback) = 5;
138 
139     /**
140      * Searches a document based on a given specifications.
141      *
142      * @param request {@link QueryAidlRequest} that contains the input parameters for the search
143      *     operation
144      * @param callback {@link AppSearchResult}<{@link SearchResultPage}> of performing this
145      *     operation.
146      */
search( in SearchAidlRequest request, in IAppSearchResultCallback callback)147     void search(
148         in SearchAidlRequest request,
149         in IAppSearchResultCallback callback) = 6;
150 
151     /**
152      * Executes a global search, i.e. over all permitted databases, against the AppSearch index and
153      * returns results.
154      *
155      * @param request {@link GlobalSearchAidlRequest} that contains the input parameters for the
156      *     global search operation.
157      * @param callback {@link AppSearchResult}<{@link SearchResultPage}> of performing this
158      *     operation.
159      */
globalSearch( in GlobalSearchAidlRequest request, in IAppSearchResultCallback callback)160     void globalSearch(
161         in GlobalSearchAidlRequest request,
162         in IAppSearchResultCallback callback) = 7;
163 
164     /**
165      * Fetches the next page of results of a previously executed search. Results can be empty if
166      * next-page token is invalid or all pages have been returned.
167      *
168      * @param request {@link GetNextPageAidlRequest} that contains the input parameters for the
169      *     get next page operation.
170      * @param callback {@link AppSearchResult}<{@link SearchResultPage}> of performing this
171      *                  operation.
172      */
getNextPage( in GetNextPageAidlRequest request, in IAppSearchResultCallback callback)173     void getNextPage(
174         in GetNextPageAidlRequest request,
175         in IAppSearchResultCallback callback) = 8;
176 
177     /**
178      * Invalidates the next-page token so that no more results of the related search can be
179      * returned.
180      *
181      * @param request {@link InvalidateNextPageTokenAidlRequest} that contains the input parameters
182      *     for the invalidate next-page token operation.
183      */
184     void invalidateNextPageToken(in InvalidateNextPageTokenAidlRequest request) = 9;
185 
186     /**
187      * Searches a document based on a given specifications.
188      *
189      * <p>Documents will be save to the given ParcelFileDescriptor
190      *
191      * @param request {@link WriteSearchResultsToFileAidlRequest} that contains the input parameters
192      *     to write search results to a file.
193      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
194      *     {@link AppSearchResult}&lt;{@code Void}&gt;.
195      */
writeSearchResultsToFile( in WriteSearchResultsToFileAidlRequest request, in IAppSearchResultCallback callback)196     void writeSearchResultsToFile(
197         in WriteSearchResultsToFileAidlRequest request,
198         in IAppSearchResultCallback callback) = 10;
199 
200     /**
201      * Inserts documents from the given file into the index.
202      *
203      * <p>This method does not dispatch change notifications for the individual documents being
204      * inserted, so it is only appropriate to use for batch upload situations where a broader change
205      * notification will indicate what has changed, like schema migration.
206      *
207      * @param request {@link PutDocumentsFromFileAidlRequest} that contains the input parameters to
208      *     put documents from a file.
209      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
210      *     {@link AppSearchResult}&lt;{@link List}&lt;{@link Bundle}&gt;&gt;, where the value are
211      *     MigrationFailure bundles.
212      */
putDocumentsFromFile( in PutDocumentsFromFileAidlRequest request, in IAppSearchResultCallback callback)213     void putDocumentsFromFile(
214         in PutDocumentsFromFileAidlRequest request,
215         in IAppSearchResultCallback callback) = 11;
216 
217     /**
218      * Retrieves suggested Strings that could be used as {@code queryExpression} in search API.
219      *
220      * @param request {@link SearchSuggestionAidlRequest} contains the input parameters to retrieve
221      *     suggested Strings for search.
222      * @param callback {@link AppSearchResult}&lt;List&lt;{@link SearchSuggestionResult}&gt; of
223      *   performing this operation.
224      */
searchSuggestion( in SearchSuggestionAidlRequest request, in IAppSearchResultCallback callback)225     void searchSuggestion(
226             in SearchSuggestionAidlRequest request,
227             in IAppSearchResultCallback callback) = 12;
228 
229     /**
230      * Reports usage of a particular document by namespace and id.
231      *
232      * <p>A usage report represents an event in which a user interacted with or viewed a document.
233      *
234      * <p>For each call to {@link #reportUsage}, AppSearch updates usage count and usage recency
235      * metrics for that particular document. These metrics are used for ordering {@link #query}
236      * results by the {@link SearchSpec#RANKING_STRATEGY_USAGE_COUNT} and
237      * {@link SearchSpec#RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP} ranking strategies.
238      *
239      * <p>Reporting usage of a document is optional.
240      *
241      * @param request {@link ReportUsageAidlRequest} contains the input parameters for report
242      *     usage operation.
243      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
244      *     {@link AppSearchResult}&lt;{@link Void}&gt;.
245      */
reportUsage( in ReportUsageAidlRequest request, in IAppSearchResultCallback callback)246     void reportUsage(
247         in ReportUsageAidlRequest request,
248         in IAppSearchResultCallback callback) = 13;
249 
250     /**
251      * Removes documents by ID.
252      *
253      * @param request {@link RemoveByDocumentIdAidlRequest} contains the input parameters for remove
254      *     by id operation.
255      * @param callback
256      *     If the call fails to start, {@link IAppSearchBatchResultCallback#onSystemError}
257      *     will be called with the cause throwable. Otherwise,
258      *     {@link IAppSearchBatchResultCallback#onResult} will be called with an
259      *     {@link AppSearchBatchResult}&lt;{@link String}, {@link Void}&gt;
260      *     where the keys are document IDs. If a document doesn't exist, it will be reported as a
261      *     failure where the {@code throwable} is {@code null}.
262      */
removeByDocumentId( in RemoveByDocumentIdAidlRequest request, in IAppSearchBatchResultCallback callback)263     void removeByDocumentId(
264         in RemoveByDocumentIdAidlRequest request,
265         in IAppSearchBatchResultCallback callback) = 14;
266 
267     /**
268      * Removes documents by given query.
269      *
270      * @param request {@link RemoveByQueryAidlRequest} contains the input parameters for remove by
271      *     query operation.
272      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
273      *     {@link AppSearchResult}&lt;{@link Void}&gt;.
274      */
removeByQuery( in RemoveByQueryAidlRequest request, in IAppSearchResultCallback callback)275     void removeByQuery(
276         in RemoveByQueryAidlRequest request,
277         in IAppSearchResultCallback callback) = 15;
278 
279     /**
280      * Gets the storage info.
281      *
282      * @param request {@link GetStorageInfoAidlRequest} contains the input parameters to get
283      *     storage info operation.
284      * @param callback {@link IAppSearchResultCallback#onResult} will be called with an
285      *     {@link AppSearchResult}&lt;{@link Bundle}&gt;, where the value is a
286      *     {@link StorageInfo}.
287      */
getStorageInfo( in GetStorageInfoAidlRequest request, in IAppSearchResultCallback callback)288     void getStorageInfo(
289         in GetStorageInfoAidlRequest request,
290         in IAppSearchResultCallback callback) = 16;
291 
292     /**
293      * Persists all update/delete requests to the disk.
294      *
295      * @param request {@link PersistToDiskAidlRequest} contains the input parameters for set schema
296      *     operation.
297      */
298     void persistToDisk(in PersistToDiskAidlRequest request) = 17;
299 
300     /**
301      * Adds an observer to monitor changes within the databases owned by {@code observedPackage} if
302      * they match the given ObserverSpec.
303      *
304      * @param request {@link RegisterObserverCallbackAidlRequest} contains the input parameters
305      *     for register observer operation.
306      * @param observerProxy Callback to trigger when a schema or document changes
307      * @return the success or failure of this operation
308      */
registerObserverCallback( in RegisterObserverCallbackAidlRequest request, in IAppSearchObserverProxy observerProxy)309     AppSearchResultParcel registerObserverCallback(
310         in RegisterObserverCallbackAidlRequest request,
311         in IAppSearchObserverProxy observerProxy) = 18;
312 
313     /**
314      * Removes previously registered {@link ObserverCallback} instances from the system.
315      *
316      * @param request {@link UnregisterObserverCallbackAidlRequest} contains the input parameters
317      *     for unregister observer operation.
318      * @param observerProxy Observer callback to remove
319      * @return the success or failure of this operation
320      */
unregisterObserverCallback( in UnregisterObserverCallbackAidlRequest request, in IAppSearchObserverProxy observerProxy)321     AppSearchResultParcel unregisterObserverCallback(
322         in UnregisterObserverCallbackAidlRequest request,
323         in IAppSearchObserverProxy observerProxy) = 19;
324 
325     /**
326      * Executes an app function provided by {@link AppFunctionService} through the system.
327      *
328      * @param request the request to execute an app function.
329      * @param callback the callback to report the result.
330      */
executeAppFunction( in ExecuteAppFunctionAidlRequest request, in IAppSearchResultCallback callback)331    void executeAppFunction(
332        in ExecuteAppFunctionAidlRequest request,
333        in IAppSearchResultCallback callback) = 20;
334 
335     // next function transaction ID = 21;
336 }
337