Loading services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSession.java +18 −3 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.app.appsearch.GenericDocument; import android.app.appsearch.GetByDocumentIdRequest; import android.app.appsearch.GetSchemaResponse; import android.app.appsearch.PutDocumentsRequest; import android.app.appsearch.RemoveByDocumentIdRequest; import android.app.appsearch.SearchResult; import android.app.appsearch.SearchResults; import android.app.appsearch.SearchSpec; Loading Loading @@ -146,6 +147,22 @@ public class FutureAppSearchSession implements Closeable { }); } /** Removes documents from the AppSearchSession database. */ public AndroidFuture<AppSearchBatchResult<String, Void>> remove( @NonNull RemoveByDocumentIdRequest removeRequest) { return getSessionAsync() .thenCompose( session -> { AndroidFuture<AppSearchBatchResult<String, Void>> settableBatchResultFuture = new AndroidFuture<>(); session.remove( removeRequest, mExecutor, new BatchResultCallbackAdapter<>(settableBatchResultFuture)); return settableBatchResultFuture; }); } /** * Retrieves documents from the open AppSearchSession that match a given query string and type * of search provided. Loading Loading @@ -200,9 +217,7 @@ public class FutureAppSearchSession implements Closeable { Objects.requireNonNull(namespace); GetByDocumentIdRequest request = new GetByDocumentIdRequest.Builder(namespace) .addIds(documentId) .build(); new GetByDocumentIdRequest.Builder(namespace).addIds(documentId).build(); return getSessionAsync() .thenCompose( session -> { Loading services/tests/appfunctions/src/com/android/server/appfunctions/FutureAppSearchSessionTest.kt +47 −10 Original line number Diff line number Diff line Loading @@ -19,8 +19,10 @@ import android.app.appfunctions.AppFunctionRuntimeMetadata import android.app.appfunctions.AppFunctionRuntimeMetadata.APP_FUNCTION_RUNTIME_NAMESPACE import android.app.appfunctions.AppFunctionRuntimeMetadata.createAppFunctionRuntimeSchema import android.app.appfunctions.AppFunctionRuntimeMetadata.createParentAppFunctionRuntimeSchema import android.app.appsearch.AppSearchBatchResult import android.app.appsearch.AppSearchManager import android.app.appsearch.PutDocumentsRequest import android.app.appsearch.RemoveByDocumentIdRequest import android.app.appsearch.SearchSpec import android.app.appsearch.SetSchemaRequest import androidx.test.platform.app.InstrumentationRegistry Loading Loading @@ -56,7 +58,7 @@ class FutureAppSearchSessionTest { SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME) createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() Loading @@ -74,7 +76,7 @@ class FutureAppSearchSessionTest { SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME) createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() val schema = session.setSchema(setSchemaRequest) Loading @@ -92,6 +94,40 @@ class FutureAppSearchSessionTest { } } @Test fun remove() { val searchContext = AppSearchManager.SearchContext.Builder(TEST_DB).build() FutureAppSearchSession(appSearchManager, testExecutor, searchContext).use { session -> val setSchemaRequest = SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() val schema = session.setSchema(setSchemaRequest) assertThat(schema.get()).isNotNull() val appFunctionRuntimeMetadata = AppFunctionRuntimeMetadata.Builder(TEST_PACKAGE_NAME, TEST_FUNCTION_ID, "").build() val putDocumentsRequest: PutDocumentsRequest = PutDocumentsRequest.Builder() .addGenericDocuments(appFunctionRuntimeMetadata) .build() val putResult = session.put(putDocumentsRequest) assertThat(putResult.get().isSuccess).isTrue() val removeDocumentRequest = RemoveByDocumentIdRequest.Builder(APP_FUNCTION_RUNTIME_NAMESPACE) .addIds(appFunctionRuntimeMetadata.id) .build() val removeResult: AppSearchBatchResult<String, Void> = session.remove(removeDocumentRequest).get() assertThat(removeResult).isNotNull() assertThat(removeResult.isSuccess).isTrue() } } @Test fun search() { val searchContext = AppSearchManager.SearchContext.Builder(TEST_DB).build() Loading @@ -100,7 +136,7 @@ class FutureAppSearchSessionTest { SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME) createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() val schema = session.setSchema(setSchemaRequest) Loading Loading @@ -132,7 +168,7 @@ class FutureAppSearchSessionTest { SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME) createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() val schema = session.setSchema(setSchemaRequest) Loading @@ -144,10 +180,11 @@ class FutureAppSearchSessionTest { .build() val putResult = session.put(putDocumentsRequest) val genricDocument = session val genricDocument = session .getByDocumentId( /* documentId= */ "${TEST_PACKAGE_NAME}/${TEST_FUNCTION_ID}", APP_FUNCTION_RUNTIME_NAMESPACE APP_FUNCTION_RUNTIME_NAMESPACE, ) .get() Loading Loading
services/appfunctions/java/com/android/server/appfunctions/FutureAppSearchSession.java +18 −3 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.app.appsearch.GenericDocument; import android.app.appsearch.GetByDocumentIdRequest; import android.app.appsearch.GetSchemaResponse; import android.app.appsearch.PutDocumentsRequest; import android.app.appsearch.RemoveByDocumentIdRequest; import android.app.appsearch.SearchResult; import android.app.appsearch.SearchResults; import android.app.appsearch.SearchSpec; Loading Loading @@ -146,6 +147,22 @@ public class FutureAppSearchSession implements Closeable { }); } /** Removes documents from the AppSearchSession database. */ public AndroidFuture<AppSearchBatchResult<String, Void>> remove( @NonNull RemoveByDocumentIdRequest removeRequest) { return getSessionAsync() .thenCompose( session -> { AndroidFuture<AppSearchBatchResult<String, Void>> settableBatchResultFuture = new AndroidFuture<>(); session.remove( removeRequest, mExecutor, new BatchResultCallbackAdapter<>(settableBatchResultFuture)); return settableBatchResultFuture; }); } /** * Retrieves documents from the open AppSearchSession that match a given query string and type * of search provided. Loading Loading @@ -200,9 +217,7 @@ public class FutureAppSearchSession implements Closeable { Objects.requireNonNull(namespace); GetByDocumentIdRequest request = new GetByDocumentIdRequest.Builder(namespace) .addIds(documentId) .build(); new GetByDocumentIdRequest.Builder(namespace).addIds(documentId).build(); return getSessionAsync() .thenCompose( session -> { Loading
services/tests/appfunctions/src/com/android/server/appfunctions/FutureAppSearchSessionTest.kt +47 −10 Original line number Diff line number Diff line Loading @@ -19,8 +19,10 @@ import android.app.appfunctions.AppFunctionRuntimeMetadata import android.app.appfunctions.AppFunctionRuntimeMetadata.APP_FUNCTION_RUNTIME_NAMESPACE import android.app.appfunctions.AppFunctionRuntimeMetadata.createAppFunctionRuntimeSchema import android.app.appfunctions.AppFunctionRuntimeMetadata.createParentAppFunctionRuntimeSchema import android.app.appsearch.AppSearchBatchResult import android.app.appsearch.AppSearchManager import android.app.appsearch.PutDocumentsRequest import android.app.appsearch.RemoveByDocumentIdRequest import android.app.appsearch.SearchSpec import android.app.appsearch.SetSchemaRequest import androidx.test.platform.app.InstrumentationRegistry Loading Loading @@ -56,7 +58,7 @@ class FutureAppSearchSessionTest { SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME) createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() Loading @@ -74,7 +76,7 @@ class FutureAppSearchSessionTest { SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME) createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() val schema = session.setSchema(setSchemaRequest) Loading @@ -92,6 +94,40 @@ class FutureAppSearchSessionTest { } } @Test fun remove() { val searchContext = AppSearchManager.SearchContext.Builder(TEST_DB).build() FutureAppSearchSession(appSearchManager, testExecutor, searchContext).use { session -> val setSchemaRequest = SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() val schema = session.setSchema(setSchemaRequest) assertThat(schema.get()).isNotNull() val appFunctionRuntimeMetadata = AppFunctionRuntimeMetadata.Builder(TEST_PACKAGE_NAME, TEST_FUNCTION_ID, "").build() val putDocumentsRequest: PutDocumentsRequest = PutDocumentsRequest.Builder() .addGenericDocuments(appFunctionRuntimeMetadata) .build() val putResult = session.put(putDocumentsRequest) assertThat(putResult.get().isSuccess).isTrue() val removeDocumentRequest = RemoveByDocumentIdRequest.Builder(APP_FUNCTION_RUNTIME_NAMESPACE) .addIds(appFunctionRuntimeMetadata.id) .build() val removeResult: AppSearchBatchResult<String, Void> = session.remove(removeDocumentRequest).get() assertThat(removeResult).isNotNull() assertThat(removeResult.isSuccess).isTrue() } } @Test fun search() { val searchContext = AppSearchManager.SearchContext.Builder(TEST_DB).build() Loading @@ -100,7 +136,7 @@ class FutureAppSearchSessionTest { SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME) createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() val schema = session.setSchema(setSchemaRequest) Loading Loading @@ -132,7 +168,7 @@ class FutureAppSearchSessionTest { SetSchemaRequest.Builder() .addSchemas( createParentAppFunctionRuntimeSchema(), createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME) createAppFunctionRuntimeSchema(TEST_PACKAGE_NAME), ) .build() val schema = session.setSchema(setSchemaRequest) Loading @@ -144,10 +180,11 @@ class FutureAppSearchSessionTest { .build() val putResult = session.put(putDocumentsRequest) val genricDocument = session val genricDocument = session .getByDocumentId( /* documentId= */ "${TEST_PACKAGE_NAME}/${TEST_FUNCTION_ID}", APP_FUNCTION_RUNTIME_NAMESPACE APP_FUNCTION_RUNTIME_NAMESPACE, ) .get() Loading