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.AppSearchBatchResult; 21 import android.app.appsearch.AppSearchResult; 22 import android.app.appsearch.AppSearchSession; 23 import android.app.appsearch.GenericDocument; 24 import android.app.appsearch.GetByDocumentIdRequest; 25 import android.app.appsearch.GetSchemaResponse; 26 import android.app.appsearch.PutDocumentsRequest; 27 import android.app.appsearch.RemoveByDocumentIdRequest; 28 import android.app.appsearch.SearchResult; 29 import android.app.appsearch.SearchSpec; 30 import android.app.appsearch.SetSchemaRequest; 31 import android.app.appsearch.SetSchemaResponse; 32 33 import com.android.internal.infra.AndroidFuture; 34 35 import java.io.Closeable; 36 import java.io.IOException; 37 import java.util.List; 38 39 /** A future API wrapper of {@link AppSearchSession} APIs. */ 40 public interface FutureAppSearchSession extends Closeable { 41 42 /** 43 * Sets the schema that represents the organizational structure of data within the AppSearch 44 * database. 45 */ setSchema(@onNull SetSchemaRequest setSchemaRequest)46 AndroidFuture<SetSchemaResponse> setSchema(@NonNull SetSchemaRequest setSchemaRequest); 47 48 /** Retrieves the schema most recently successfully provided to {@code setSchema}. */ getSchema()49 AndroidFuture<GetSchemaResponse> getSchema(); 50 51 /** Indexes documents into the {@link AppSearchSession} database. */ put( @onNull PutDocumentsRequest putDocumentsRequest)52 AndroidFuture<AppSearchBatchResult<String, Void>> put( 53 @NonNull PutDocumentsRequest putDocumentsRequest); 54 55 /** Removes {@link GenericDocument} from the index by Query. */ remove( @onNull RemoveByDocumentIdRequest removeRequest)56 AndroidFuture<AppSearchBatchResult<String, Void>> remove( 57 @NonNull RemoveByDocumentIdRequest removeRequest); 58 59 /** 60 * Gets {@link GenericDocument} objects by document IDs in a namespace from the {@link 61 * AppSearchSession} database. 62 */ getByDocumentId( @onNull GetByDocumentIdRequest getRequest)63 AndroidFuture<AppSearchBatchResult<String, GenericDocument>> getByDocumentId( 64 @NonNull GetByDocumentIdRequest getRequest); 65 66 /** 67 * Retrieves documents from the open {@link AppSearchSession} that match a given query string 68 * and type of search provided. 69 */ search( @onNull String queryExpression, @NonNull SearchSpec searchSpec)70 AndroidFuture<FutureSearchResults> search( 71 @NonNull String queryExpression, @NonNull SearchSpec searchSpec); 72 73 @Override close()74 void close(); 75 } 76