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.GlobalSearchSession; 21 import android.app.appsearch.SearchResults; 22 import android.app.appsearch.SearchSpec; 23 import android.app.appsearch.exceptions.AppSearchException; 24 25 import java.io.Closeable; 26 27 /** 28 * A synchronous wrapper around {@link GlobalSearchSession}. This allows us to call globalSearch 29 * synchronously. 30 * 31 * <p>Note that while calling the methods in this class will park the calling thread, and only one 32 * {@link GlobalSearchSession} wil be created, multiple threads may call {@link #search} at the same 33 * time. It is up to the caller of this class to ensure this does not cause issues. 34 * 35 * @see GlobalSearchSession 36 */ 37 public interface SyncGlobalSearchSession extends Closeable { 38 /** 39 * Returns a synchronous version of {@link SearchResults}. 40 * 41 * <p>While the underlying method is not asynchronous, this method allows for convenience while 42 * synchronously searching globally. 43 * 44 * @see GlobalSearchSession#search 45 */ 46 @NonNull 47 @WorkerThread search(@onNull String query, @NonNull SearchSpec searchSpec)48 SyncSearchResults search(@NonNull String query, @NonNull SearchSpec searchSpec) 49 throws AppSearchException; 50 51 /** 52 * Closes the global session. 53 * 54 * @see GlobalSearchSession#close 55 */ 56 @Override close()57 void close(); 58 } 59