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 package com.android.server.appsearch.appsindexer; 17 18 import android.annotation.NonNull; 19 import android.annotation.WorkerThread; 20 import android.app.appsearch.AppSearchBatchResult; 21 import android.app.appsearch.AppSearchSchema; 22 import android.app.appsearch.AppSearchSession; 23 import android.app.appsearch.PutDocumentsRequest; 24 import android.app.appsearch.RemoveByDocumentIdRequest; 25 import android.app.appsearch.SearchResults; 26 import android.app.appsearch.SearchSpec; 27 import android.app.appsearch.SetSchemaRequest; 28 import android.app.appsearch.SetSchemaResponse; 29 import android.app.appsearch.exceptions.AppSearchException; 30 31 import java.io.Closeable; 32 33 /** 34 * A synchronous wrapper around {@link AppSearchSession}. This allows us to perform operations in 35 * AppSearch without needing to handle async calls. 36 * 37 * <p>Note that calling the methods in this class will park the calling thread. 38 * 39 * @see AppSearchSession 40 */ 41 // TODO(b/275592563): Sort methods so that they match the order in AppSearchSession 42 public interface SyncAppSearchSession extends Closeable { 43 /** 44 * Synchronously sets an {@link AppSearchSchema}. 45 * 46 * @see AppSearchSession#setSchema 47 */ 48 @NonNull 49 @WorkerThread setSchema(@onNull SetSchemaRequest setSchemaRequest)50 SetSchemaResponse setSchema(@NonNull SetSchemaRequest setSchemaRequest) 51 throws AppSearchException; 52 53 /** 54 * Synchronously inserts documents into AppSearch. 55 * 56 * @see AppSearchSession#put 57 */ 58 @NonNull 59 @WorkerThread put(@onNull PutDocumentsRequest request)60 AppSearchBatchResult<String, Void> put(@NonNull PutDocumentsRequest request) 61 throws AppSearchException; 62 63 /** 64 * Synchronously removes documents from AppSearch using a query and {@link SearchSpec}. 65 * 66 * @see AppSearchSession#remove 67 */ 68 @NonNull 69 @WorkerThread remove(@onNull String queryExpression, @NonNull SearchSpec searchSpec)70 Void remove(@NonNull String queryExpression, @NonNull SearchSpec searchSpec) 71 throws AppSearchException; 72 73 /** 74 * Synchronously removes documents from AppSearch using a list of document IDs. 75 * 76 * @see AppSearchSession#remove 77 */ 78 @NonNull 79 @WorkerThread remove(@onNull RemoveByDocumentIdRequest request)80 AppSearchBatchResult<String, Void> remove(@NonNull RemoveByDocumentIdRequest request) 81 throws AppSearchException; 82 83 /** 84 * Returns a synchronous version of {@link SearchResults}. 85 * 86 * <p>While the underlying method is not asynchronous, this method allows for convenience while 87 * synchronously searching AppSearch. 88 * 89 * @see AppSearchSession#search 90 */ 91 @NonNull 92 @WorkerThread search(@onNull String query, @NonNull SearchSpec searchSpec)93 SyncSearchResults search(@NonNull String query, @NonNull SearchSpec searchSpec) 94 throws AppSearchException; 95 96 /** 97 * Closes the session. 98 * 99 * @see AppSearchSession#close 100 */ 101 @Override close()102 void close(); 103 104 // TODO(b/275592563): Bring in additional methods such as getByDocumentId as needed 105 } 106