# GlobalSearchSession

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/app/GlobalSearchSession.java+class:androidx.appsearch.app.GlobalSearchSession) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
public interface GlobalSearchSession extends ReadOnlyGlobalSearchSession, Closeable
```

<br />

*** ** * ** ***

Provides a connection to all AppSearch databases the querying application has been granted access to.

In addition to the querying methods available in `https://developer.android.com/reference/androidx/appsearch/app/ReadOnlyGlobalSearchSession`, this interface may support write operations such as `https://developer.android.com/reference/androidx/appsearch/app/GlobalSearchSession#reportSystemUsageAsync(androidx.appsearch.app.ReportSystemUsageRequest)`.

All implementations of this interface must be thread safe.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession` |   |

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/appsearch/app/GlobalSearchSession#close()()` Closes the `https://developer.android.com/reference/androidx/appsearch/app/GlobalSearchSession`. |
| `default @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/appsearch/app/OpenBlobForReadResponse>` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.SCHEMA_BLOB_HANDLE) https://developer.android.com/reference/androidx/appsearch/app/GlobalSearchSession#openBlobForReadAsync(java.util.Set<androidx.appsearch.app.AppSearchBlobHandle>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/androidx/appsearch/app/AppSearchBlobHandle> handles)` Opens a batch of AppSearch Blobs for reading. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | `https://developer.android.com/reference/androidx/appsearch/app/GlobalSearchSession#reportSystemUsageAsync(androidx.appsearch.app.ReportSystemUsageRequest)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/ReportSystemUsageRequest request)` Reports that a particular document has been used from a system surface. |

### Inherited methods

From [androidx.appsearch.app.ReadOnlyGlobalSearchSession](https://developer.android.com/reference/androidx/appsearch/app/ReadOnlyGlobalSearchSession) `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/appsearch/app/AppSearchBatchResult<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/androidx/appsearch/app/GenericDocument>>` `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.GLOBAL_SEARCH_SESSION_GET_BY_ID)
https://developer.android.com/reference/androidx/appsearch/app/ReadOnlyGlobalSearchSession#getByDocumentIdAsync(java.lang.String,java.lang.String,androidx.appsearch.app.GetByDocumentIdRequest)(
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName,
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html databaseName,
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/GetByDocumentIdRequest request
)`

Retrieves `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` documents, belonging to the specified package name and database name and identified by the namespace and ids in the request, from the `https://developer.android.com/reference/androidx/appsearch/app/GlobalSearchSession` database.
`abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/Features` `https://developer.android.com/reference/androidx/appsearch/app/ReadOnlyGlobalSearchSession#getFeatures()()`

Returns the `https://developer.android.com/reference/androidx/appsearch/app/Features` to check for the availability of certain features for this session.
`abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/appsearch/app/GetSchemaResponse>` `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.GLOBAL_SEARCH_SESSION_GET_SCHEMA)
https://developer.android.com/reference/androidx/appsearch/app/ReadOnlyGlobalSearchSession#getSchemaAsync(java.lang.String,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html packageName, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html databaseName)`

Retrieves the collection of schemas most recently successfully provided to `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession#setSchemaAsync(androidx.appsearch.app.SetSchemaRequest)` for any types belonging to the requested package and database that the caller has been granted access to.
`abstract void` `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.GLOBAL_SEARCH_SESSION_REGISTER_OBSERVER_CALLBACK)
https://developer.android.com/reference/androidx/appsearch/app/ReadOnlyGlobalSearchSession#registerObserverCallback(java.lang.String,androidx.appsearch.observer.ObserverSpec,java.util.concurrent.Executor,androidx.appsearch.observer.ObserverCallback)(
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html targetPackageName,
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/observer/ObserverSpec spec,
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor,
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/observer/ObserverCallback observer
)`

Adds an `https://developer.android.com/reference/androidx/appsearch/observer/ObserverCallback` to monitor changes within the databases owned by `targetPackageName` if they match the given `https://developer.android.com/reference/androidx/appsearch/observer/ObserverSpec`.
`abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/SearchResults` `https://developer.android.com/reference/androidx/appsearch/app/ReadOnlyGlobalSearchSession#search(java.lang.String,androidx.appsearch.app.SearchSpec)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html queryExpression, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/app/SearchSpec searchSpec)`

Retrieves documents from all AppSearch databases that the querying application has access to.
`abstract void` `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.GLOBAL_SEARCH_SESSION_REGISTER_OBSERVER_CALLBACK)
https://developer.android.com/reference/androidx/appsearch/app/ReadOnlyGlobalSearchSession#unregisterObserverCallback(java.lang.String,androidx.appsearch.observer.ObserverCallback)(
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html targetPackageName,
@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/appsearch/observer/ObserverCallback observer
)`

Removes previously registered `https://developer.android.com/reference/androidx/appsearch/observer/ObserverCallback` instances from the system.

## Public methods

### close

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
abstract void close()
```

Closes the `https://developer.android.com/reference/androidx/appsearch/app/GlobalSearchSession`.

### openBlobForReadAsync

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_BLOB_HANDLE)
default @NonNull ListenableFuture<OpenBlobForReadResponse> openBlobForReadAsync(@NonNull Set<AppSearchBlobHandle> handles)
```

Opens a batch of AppSearch Blobs for reading.

See `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession#openBlobForReadAsync(java.util.Set<androidx.appsearch.app.AppSearchBlobHandle>)` for a general description when a blob is open for read.

The returned `https://developer.android.com/reference/androidx/appsearch/app/OpenBlobForReadResponse` must be closed after use to avoid resource leaks. Failing to close it will result in system file descriptor exhaustion.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/androidx/appsearch/app/AppSearchBlobHandle> handles` | The `https://developer.android.com/reference/androidx/appsearch/app/AppSearchBlobHandle`s that identifies the blobs. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/androidx/appsearch/app/OpenBlobForReadResponse>` | a response containing the readable file descriptors. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument.Builder#setPropertyBlobHandle(java.lang.String,androidx.appsearch.app.AppSearchBlobHandle...)` |   |

### reportSystemUsageAsync

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
abstract @NonNull ListenableFuture<Void> reportSystemUsageAsync(@NonNull ReportSystemUsageRequest request)
```

Reports that a particular document has been used from a system surface.

See `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession#reportUsageAsync(androidx.appsearch.app.ReportUsageRequest)` for a general description of document usage, as well as an API that can be used by the app itself.

Usage reported via this method is accounted separately from usage reported via `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession#reportUsageAsync(androidx.appsearch.app.ReportUsageRequest)` and may be accessed using the constants `https://developer.android.com/reference/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_SYSTEM_USAGE_COUNT()` and `https://developer.android.com/reference/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP()`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` | The pending result of performing this operation which resolves to `null` on success. The pending result will be completed with an `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException` with a code of `https://developer.android.com/reference/androidx/appsearch/app/AppSearchResult#RESULT_SECURITY_ERROR()` if this API is invoked by an app which is not part of the system. |