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 
17 package android.app.appsearch;
18 
19 import android.annotation.NonNull;
20 
21 import com.google.common.util.concurrent.ListenableFuture;
22 
23 import java.io.Closeable;
24 import java.util.List;
25 
26 /**
27  * Encapsulates results of a search operation.
28  *
29  * <p>Each {@link AppSearchSessionShim#search} operation returns a list of {@link SearchResult}
30  * objects, referred to as a "page", limited by the size configured by {@link
31  * SearchSpec.Builder#setResultCountPerPage}.
32  *
33  * <p>To fetch a page of results, call {@link #getNextPageAsync()}.
34  *
35  * <p>All instances of {@link SearchResultsShim} must call {@link SearchResultsShim#close()} after
36  * the results are fetched.
37  *
38  * <p>This class is not thread safe.
39  */
40 public interface SearchResultsShim extends Closeable {
41     /**
42      * Retrieves the next page of {@link SearchResult} objects.
43      *
44      * <p>The page size is configured by {@link SearchSpec.Builder#setResultCountPerPage}.
45      *
46      * <p>Continue calling this method to access results until it returns an empty list, signifying
47      * there are no more results.
48      *
49      * @return a {@link ListenableFuture} which resolves to a list of {@link SearchResult} objects.
50      */
51     @NonNull
getNextPageAsync()52     ListenableFuture<List<SearchResult>> getNextPageAsync();
53 
54     @Override
close()55     void close();
56 }
57