• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 com.android.server.appfunctions;
18 
19 import android.annotation.NonNull;
20 import android.app.appsearch.AppSearchResult;
21 import android.app.appsearch.AppSearchSession;
22 import android.app.appsearch.SearchResult;
23 import android.app.appsearch.SearchResults;
24 
25 import com.android.internal.infra.AndroidFuture;
26 
27 import java.io.Closeable;
28 import java.io.IOException;
29 import java.util.List;
30 
31 /** A future API wrapper of {@link android.app.appsearch.SearchResults}. */
32 public interface FutureSearchResults extends Closeable {
33 
34     /** Converts a failed app search result codes into an exception. */
35     @NonNull
failedResultToException(@onNull AppSearchResult<?> appSearchResult)36     public static Exception failedResultToException(@NonNull AppSearchResult<?> appSearchResult) {
37         return switch (appSearchResult.getResultCode()) {
38             case AppSearchResult.RESULT_INVALID_ARGUMENT ->
39                     new IllegalArgumentException(appSearchResult.getErrorMessage());
40             case AppSearchResult.RESULT_IO_ERROR ->
41                     new IOException(appSearchResult.getErrorMessage());
42             case AppSearchResult.RESULT_SECURITY_ERROR ->
43                     new SecurityException(appSearchResult.getErrorMessage());
44             default -> new IllegalStateException(appSearchResult.getErrorMessage());
45         };
46     }
47 
48     /**
49      * Retrieves the next page of {@link SearchResult} objects from the {@link AppSearchSession}
50      * database.
51      *
52      * <p>Continue calling this method to access results until it returns an empty list, signifying
53      * there are no more results.
54      */
getNextPage()55     AndroidFuture<List<SearchResult>> getNextPage();
56 
57     @Override
close()58     void close();
59 }
60