# GlobalSearchSession

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#inhmethods)  

# GlobalSearchSession

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/app/appsearch/GlobalSearchSession "View this page in Kotlin")\|Java

`
public


class
GlobalSearchSession
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[Closeable](https://developer.android.com/reference/java/io/Closeable)`


`

|---|-------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.appsearch.GlobalSearchSession |

<br />

*** ** * ** ***

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

This class is thread safe.  
**See also:**

- [AppSearchSession](https://developer.android.com/reference/android/app/appsearch/AppSearchSession)

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ||
|-------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                                         | ` `[close](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#close())`() ` Closes the[GlobalSearchSession](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` void`                                                                                         | ` `[getByDocumentId](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#getByDocumentId(java.lang.String,%20java.lang.String,%20android.app.appsearch.GetByDocumentIdRequest,%20java.util.concurrent.Executor,%20android.app.appsearch.BatchResultCallback<java.lang.String,android.app.appsearch.GenericDocument>))`(`[String](https://developer.android.com/reference/java/lang/String)` packageName, `[String](https://developer.android.com/reference/java/lang/String)` databaseName, `[GetByDocumentIdRequest](https://developer.android.com/reference/android/app/appsearch/GetByDocumentIdRequest)` request, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[BatchResultCallback](https://developer.android.com/reference/android/app/appsearch/BatchResultCallback)`<`[String](https://developer.android.com/reference/java/lang/String)`, `[GenericDocument](https://developer.android.com/reference/android/app/appsearch/GenericDocument)`> callback) ` Retrieves[GenericDocument](https://developer.android.com/reference/android/app/appsearch/GenericDocument)documents, belonging to the specified package name and database name and identified by the namespace and ids in the request, from the[GlobalSearchSession](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession)database.                                                 |
| ` void`                                                                                         | ` `[getSchema](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#getSchema(java.lang.String,%20java.lang.String,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<android.app.appsearch.GetSchemaResponse>>))`(`[String](https://developer.android.com/reference/java/lang/String)` packageName, `[String](https://developer.android.com/reference/java/lang/String)` databaseName, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[AppSearchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchResult)`<`[GetSchemaResponse](https://developer.android.com/reference/android/app/appsearch/GetSchemaResponse)`>> callback) ` Retrieves the collection of schemas most recently successfully provided to[AppSearchSession.setSchema(SetSchemaRequest, Executor, Executor, Consumer)](https://developer.android.com/reference/android/app/appsearch/AppSearchSession#setSchema(android.app.appsearch.SetSchemaRequest,%20java.util.concurrent.Executor,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<android.app.appsearch.SetSchemaResponse>>))for any types belonging to the requested package and database that the caller has been granted access to. |
| ` void`                                                                                         | ` `[openBlobForRead](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#openBlobForRead(java.util.Set<android.app.appsearch.AppSearchBlobHandle>,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<android.app.appsearch.OpenBlobForReadResponse>>))`(`[Set](https://developer.android.com/reference/java/util/Set)`<`[AppSearchBlobHandle](https://developer.android.com/reference/android/app/appsearch/AppSearchBlobHandle)`> handles, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[AppSearchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchResult)`<`[OpenBlobForReadResponse](https://developer.android.com/reference/android/app/appsearch/OpenBlobForReadResponse)`>> callback) ` Opens a batch of AppSearch Blobs for reading.                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` void`                                                                                         | ` `[registerObserverCallback](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#registerObserverCallback(java.lang.String,%20android.app.appsearch.observer.ObserverSpec,%20java.util.concurrent.Executor,%20android.app.appsearch.observer.ObserverCallback))`(`[String](https://developer.android.com/reference/java/lang/String)` targetPackageName, `[ObserverSpec](https://developer.android.com/reference/android/app/appsearch/observer/ObserverSpec)` spec, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[ObserverCallback](https://developer.android.com/reference/android/app/appsearch/observer/ObserverCallback)` observer) ` Adds an[ObserverCallback](https://developer.android.com/reference/android/app/appsearch/observer/ObserverCallback)to monitor changes within the databases owned by`targetPackageName`if they match the given[ObserverSpec](https://developer.android.com/reference/android/app/appsearch/observer/ObserverSpec).                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                         | ` `[reportSystemUsage](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#reportSystemUsage(android.app.appsearch.ReportSystemUsageRequest,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<java.lang.Void>>))`(`[ReportSystemUsageRequest](https://developer.android.com/reference/android/app/appsearch/ReportSystemUsageRequest)` request, `[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[Consumer](https://developer.android.com/reference/java/util/function/Consumer)`<`[AppSearchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchResult)`<`[Void](https://developer.android.com/reference/java/lang/Void)`>> callback) ` Reports that a particular document has been used from a system surface.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` `[SearchResults](https://developer.android.com/reference/android/app/appsearch/SearchResults) | ` `[search](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#search(java.lang.String,%20android.app.appsearch.SearchSpec))`(`[String](https://developer.android.com/reference/java/lang/String)` queryExpression, `[SearchSpec](https://developer.android.com/reference/android/app/appsearch/SearchSpec)` searchSpec) ` Retrieves documents from all AppSearch databases that the querying application has access to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` void`                                                                                         | ` `[unregisterObserverCallback](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#unregisterObserverCallback(java.lang.String,%20android.app.appsearch.observer.ObserverCallback))`(`[String](https://developer.android.com/reference/java/lang/String)` targetPackageName, `[ObserverCallback](https://developer.android.com/reference/android/app/appsearch/observer/ObserverCallback)` observer) ` Removes previously registered[ObserverCallback](https://developer.android.com/reference/android/app/appsearch/observer/ObserverCallback)instances from the system.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[java.io.Closeable](https://developer.android.com/reference/java/io/Closeable)` ` |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||
| From interface` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Public methods

### close

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void close ()
```

Closes the[GlobalSearchSession](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession).

<br />

### getByDocumentId

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[T Extensions 3](https://developer.android.com/sdkExtensions)  

```
public void getByDocumentId (String packageName, 
                String databaseName, 
                GetByDocumentIdRequest request, 
                Executor executor, 
                BatchResultCallback<String, GenericDocument> callback)
```

Retrieves[GenericDocument](https://developer.android.com/reference/android/app/appsearch/GenericDocument)documents, belonging to the specified package name and database name and identified by the namespace and ids in the request, from the[GlobalSearchSession](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession)database. When a call is successful, the result will be returned in the successes section of the[AppSearchBatchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchBatchResult)object in the callback. If the package doesn't exist, database doesn't exist, or if the calling package doesn't have access, these failures will be reflected as[AppSearchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchResult)objects with a RESULT_NOT_FOUND status code in the failures section of the[AppSearchBatchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchBatchResult)object.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ||
|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `packageName`  | `String`: the name of the package to get from This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `databaseName` | `String`: the name of the database to get from This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `request`      | `GetByDocumentIdRequest`: a request containing a namespace and IDs to get documents for. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `executor`     | `Executor`: Executor on which to invoke the callback. This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `callback`     | `BatchResultCallback`: Callback to receive the pending result of performing this operation. The keys of the returned[AppSearchBatchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchBatchResult)are the input IDs. The values are the returned[GenericDocument](https://developer.android.com/reference/android/app/appsearch/GenericDocument)s on success, or a failed[AppSearchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchResult)otherwise. IDs that are not found will return a failed[AppSearchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchResult)with a result code of[AppSearchResult.RESULT_NOT_FOUND](https://developer.android.com/reference/android/app/appsearch/AppSearchResult#RESULT_NOT_FOUND). If an unexpected internal error occurs in the AppSearch service,[BatchResultCallback.onSystemError](https://developer.android.com/reference/android/app/appsearch/BatchResultCallback#onSystemError(java.lang.Throwable))will be invoked with a[Throwable](https://developer.android.com/reference/java/lang/Throwable). This value cannot be`null`. <br /> |

### getSchema

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[T Extensions 3](https://developer.android.com/sdkExtensions)  

```
public void getSchema (String packageName, 
                String databaseName, 
                Executor executor, 
                Consumer<AppSearchResult<GetSchemaResponse>> callback)
```

Retrieves the collection of schemas most recently successfully provided to[AppSearchSession.setSchema(SetSchemaRequest, Executor, Executor, Consumer)](https://developer.android.com/reference/android/app/appsearch/AppSearchSession#setSchema(android.app.appsearch.SetSchemaRequest,%20java.util.concurrent.Executor,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<android.app.appsearch.SetSchemaResponse>>))for any types belonging to the requested package and database that the caller has been granted access to.

If the requested package/database combination does not exist or the caller has not been granted access to it, then an empty GetSchemaResponse will be returned.

<br />

|                                                                                                                                                                                                                                                                                                                      Parameters                                                                                                                                                                                                                                                                                                                       ||
|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `packageName`  | `String`: the package that owns the requested[AppSearchSchema](https://developer.android.com/reference/android/app/appsearch/AppSearchSchema)instances. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `databaseName` | `String`: the database that owns the requested[AppSearchSchema](https://developer.android.com/reference/android/app/appsearch/AppSearchSchema)instances. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `executor`     | `Executor`: Executor on which to invoke the callback. This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `callback`     | `Consumer`: Callback to receive the pending[GetSchemaResponse](https://developer.android.com/reference/android/app/appsearch/GetSchemaResponse)containing the schemas that the caller has access to or an empty GetSchemaResponse if the request package and database does not exist, has not set a schema or contains no schemas that are accessible to the caller. This value cannot be`null`. <br />                                                                                                                                                                                                                               |

### openBlobForRead

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[T Extensions 17](https://developer.android.com/sdkExtensions)  

```
public void openBlobForRead (Set<AppSearchBlobHandle> handles, 
                Executor executor, 
                Consumer<AppSearchResult<OpenBlobForReadResponse>> callback)
```

Opens a batch of AppSearch Blobs for reading.

See[AppSearchSession.openBlobForRead](https://developer.android.com/reference/android/app/appsearch/AppSearchSession#openBlobForRead(java.util.Set<android.app.appsearch.AppSearchBlobHandle>,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<android.app.appsearch.OpenBlobForReadResponse>>))for a general description when a blob is for read.

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

<br />

|                                                                                                                                                                                                                                                                                                                    Parameters                                                                                                                                                                                                                                                                                                                     ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `handles`  | `Set`: The[AppSearchBlobHandle](https://developer.android.com/reference/android/app/appsearch/AppSearchBlobHandle)s that identifies the blobs. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `callback` | `Consumer`: Callback to receive the[OpenBlobForReadResponse](https://developer.android.com/reference/android/app/appsearch/OpenBlobForReadResponse). This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                               |

**See also:**

- [GenericDocument.Builder.setPropertyBlobHandle(String, AppSearchBlobHandle)](https://developer.android.com/reference/android/app/appsearch/GenericDocument.Builder#setPropertyBlobHandle(java.lang.String,%20android.app.appsearch.AppSearchBlobHandle[]))  

### registerObserverCallback

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[T Extensions 3](https://developer.android.com/sdkExtensions)  

```
public void registerObserverCallback (String targetPackageName, 
                ObserverSpec spec, 
                Executor executor, 
                ObserverCallback observer)
```

Adds an[ObserverCallback](https://developer.android.com/reference/android/app/appsearch/observer/ObserverCallback)to monitor changes within the databases owned by`targetPackageName`if they match the given[ObserverSpec](https://developer.android.com/reference/android/app/appsearch/observer/ObserverSpec).

The observer callback is only triggered for data that changes after it is registered. No notification about existing data is sent as a result of registering an observer. To find out about existing data, you must use the[GlobalSearchSession.search](https://developer.android.com/reference/android/app/appsearch/GlobalSearchSession#search(java.lang.String,%20android.app.appsearch.SearchSpec))API.

If the data owned by`targetPackageName`is not visible to you, the registration call will succeed but no notifications will be dispatched. Notifications could start flowing later if`targetPackageName`changes its schema visibility settings.

If no package matching`targetPackageName`exists on the system, the registration call will succeed but no notifications will be dispatched. Notifications could start flowing later if`targetPackageName`is installed and starts indexing data.

<br />

|                                                            Parameters                                                             ||
|---------------------|--------------------------------------------------------------------------------------------------------------|
| `targetPackageName` | `String`: Package whose changes to monitor This value cannot be`null`. <br />                                |
| `spec`              | `ObserverSpec`: Specification of what types of changes to listen for This value cannot be`null`. <br />      |
| `executor`          | `Executor`: Executor on which to call the`observer`callback methods. This value cannot be`null`. <br />      |
| `observer`          | `ObserverCallback`: Callback to trigger when a schema or document changes This value cannot be`null`. <br /> |

|                                                                                Throws                                                                                 ||
|-------------------------------------------------------------------------------------------------------------------|----------------------------------------------------|
| [AppSearchException](https://developer.android.com/reference/android/app/appsearch/exceptions/AppSearchException) | if an error occurs trying to register the observer |

### reportSystemUsage

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void reportSystemUsage (ReportSystemUsageRequest request, 
                Executor executor, 
                Consumer<AppSearchResult<Void>> callback)
```

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

See[AppSearchSession.reportUsage](https://developer.android.com/reference/android/app/appsearch/AppSearchSession#reportUsage(android.app.appsearch.ReportUsageRequest,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<java.lang.Void>>))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[AppSearchSession.reportUsage(ReportUsageRequest, Executor, Consumer)](https://developer.android.com/reference/android/app/appsearch/AppSearchSession#reportUsage(android.app.appsearch.ReportUsageRequest,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<java.lang.Void>>))and may be accessed using the constants[SearchSpec.RANKING_STRATEGY_SYSTEM_USAGE_COUNT](https://developer.android.com/reference/android/app/appsearch/SearchSpec#RANKING_STRATEGY_SYSTEM_USAGE_COUNT)and[SearchSpec.RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP](https://developer.android.com/reference/android/app/appsearch/SearchSpec#RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP).

<br />

|                                                                                                                                                                                                                                                                                                                    Parameters                                                                                                                                                                                                                                                                                                                     ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `request`  | `ReportSystemUsageRequest`: The usage reporting request. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `executor` | `Executor`: Executor on which to invoke the callback. This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `callback` | `Consumer`: Callback to receive errors. If the operation succeeds, the callback will be invoked with an[AppSearchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchResult)whose value is`null`. The callback will be invoked with an[AppSearchResult](https://developer.android.com/reference/android/app/appsearch/AppSearchResult)of[AppSearchResult.RESULT_SECURITY_ERROR](https://developer.android.com/reference/android/app/appsearch/AppSearchResult#RESULT_SECURITY_ERROR)if this API is invoked by an app which is not part of the system. <br />                                               |

### search

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public SearchResults search (String queryExpression, 
                SearchSpec searchSpec)
```

Retrieves documents from all AppSearch databases that the querying application has access to.

Applications can be granted access to documents by specifying[SetSchemaRequest.Builder.setSchemaTypeVisibilityForPackage(String, boolean, PackageIdentifier)](https://developer.android.com/reference/android/app/appsearch/SetSchemaRequest.Builder#setSchemaTypeVisibilityForPackage(java.lang.String,%20boolean,%20android.app.appsearch.PackageIdentifier)), or[ERROR(/android.app.appsearch.SetSchemaRequest.Builder#setDocumentClassVisibilityForPackage)](https://developer.android.com/)when building a schema.

Document access can also be granted to system UIs by specifying[SetSchemaRequest.Builder.setSchemaTypeDisplayedBySystem(String, boolean)](https://developer.android.com/reference/android/app/appsearch/SetSchemaRequest.Builder#setSchemaTypeDisplayedBySystem(java.lang.String,%20boolean)), or[ERROR(/android.app.appsearch.SetSchemaRequest.Builder#setDocumentClassDisplayedBySystem)](https://developer.android.com/)when building a schema.

See[AppSearchSession.search](https://developer.android.com/reference/android/app/appsearch/AppSearchSession#search(java.lang.String,%20android.app.appsearch.SearchSpec))for a detailed explanation on forming a query string.

This method is lightweight. The heavy work will be done in[SearchResults.getNextPage(Executor, Consumer)](https://developer.android.com/reference/android/app/appsearch/SearchResults#getNextPage(java.util.concurrent.Executor,%20java.util.function.Consumer<android.app.appsearch.AppSearchResult<java.util.List<android.app.appsearch.SearchResult>>>)).

<br />

|                                                                       Parameters                                                                        ||
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------|
| `queryExpression` | `String`: query string to search. This value cannot be`null`. <br />                                                                 |
| `searchSpec`      | `SearchSpec`: spec for setting document filters, adding projection, setting term match type, etc. This value cannot be`null`. <br /> |

|                                                                                                                                Returns                                                                                                                                ||
|----------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SearchResults](https://developer.android.com/reference/android/app/appsearch/SearchResults) | a[SearchResults](https://developer.android.com/reference/android/app/appsearch/SearchResults)object for retrieved matched documents. This value cannot be`null`. <br /> |

### unregisterObserverCallback

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in[T Extensions 3](https://developer.android.com/sdkExtensions)  

```
public void unregisterObserverCallback (String targetPackageName, 
                ObserverCallback observer)
```

Removes previously registered[ObserverCallback](https://developer.android.com/reference/android/app/appsearch/observer/ObserverCallback)instances from the system.

All instances of[ObserverCallback](https://developer.android.com/reference/android/app/appsearch/observer/ObserverCallback)which are registered to observe`targetPackageName`and compare equal to the provided callback using the provided argument's`ObserverCallback#equals`will be removed.

If no matching observers have been registered, this method has no effect. If multiple matching observers have been registered, all will be removed.

<br />

|                                                          Parameters                                                           ||
|---------------------|----------------------------------------------------------------------------------------------------------|
| `targetPackageName` | `String`: Package which the observers to be removed are listening to. This value cannot be`null`. <br /> |
| `observer`          | `ObserverCallback`: Callback to unregister. This value cannot be`null`. <br />                           |

|                                                                                                                                                              Throws                                                                                                                                                              ||
|-------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [AppSearchException](https://developer.android.com/reference/android/app/appsearch/exceptions/AppSearchException) | if an error occurs trying to remove the observer, such as a failure to communicate with the system service. Note that no error will be thrown if the provided observer doesn't match any registered observer. |