# SetSchemaRequest

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

*** ** * ** ***


```
public final class SetSchemaRequest
```

<br />

*** ** * ** ***

Encapsulates a request to update the schema of an `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession` database.

The schema is composed of a collection of `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema` objects, each of which defines a unique type of data.

The first call to SetSchemaRequest will set the provided schema and store it within the `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession` database.

Subsequent calls will compare the provided schema to the previously saved schema, to determine how to treat existing documents.

The following types of schema modifications are always safe and are made without deleting any existing documents:

- Addition of new `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema` types
- Addition of new properties to an existing `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema` type
- Changing the cardinality of a property to be less restrictive

The following types of schema changes are not backwards compatible:

- Removal of an existing `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema` type
- Removal of a property from an existing `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema` type
- Changing the data type of an existing property
- Changing the cardinality of a property to be more restrictive

Providing a schema with incompatible changes, will throw an `https://developer.android.com/reference/androidx/appsearch/exceptions/AppSearchException`, with a message describing the incompatibility. As a result, the previously set schema will remain unchanged.

Backward incompatible changes can be made by :

- setting `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#setForceOverride(boolean)` method to `true`. This deletes all documents that are incompatible with the new schema. The new schema is then saved and persisted to disk.
- Add a `https://developer.android.com/reference/androidx/appsearch/app/Migrator` for each incompatible type and make no deletion. The migrator will migrate documents from its old schema version to the new version. Migrated types will be set into both `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaResponse#getIncompatibleTypes()` and `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaResponse#getMigratedTypes()`. See the migration section below.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession#setSchemaAsync(androidx.appsearch.app.SetSchemaRequest)` |   |
| `https://developer.android.com/reference/androidx/appsearch/app/Migrator` |   |

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder` Builder for `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest` objects. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#PRIVATE_COMPUTE_CORE_UID_ACCESS() = 12` The visibility access for Private Compute Core. |
| `static final int` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.ADD_PERMISSIONS_AND_GET_VISIBILITY) https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_ASSISTANT_APP_SEARCH_DATA() = 6` The `https://developer.android.com/reference/android/Manifest.permission.html#READ_ASSISTANT_APP_SEARCH_DATA` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)` |
| `static final int` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.ADD_PERMISSIONS_AND_GET_VISIBILITY) https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_CALENDAR() = 2` The `https://developer.android.com/reference/android/Manifest.permission.html#READ_CALENDAR` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)` |
| `static final int` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.ADD_PERMISSIONS_AND_GET_VISIBILITY) https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_CONTACTS() = 3` The `https://developer.android.com/reference/android/Manifest.permission.html#READ_CONTACTS` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)` |
| `static final int` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.ADD_PERMISSIONS_AND_GET_VISIBILITY) https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_EXTERNAL_STORAGE() = 4` The `https://developer.android.com/reference/android/Manifest.permission.html#READ_EXTERNAL_STORAGE` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)` |
| `static final int` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.ADD_PERMISSIONS_AND_GET_VISIBILITY) https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_HOME_APP_SEARCH_DATA() = 5` The `https://developer.android.com/reference/android/Manifest.permission.html#READ_HOME_APP_SEARCH_DATA` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)` |
| `static final int` | `@https://developer.android.com/reference/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/androidx/appsearch/app/Features.ADD_PERMISSIONS_AND_GET_VISIBILITY) https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_SMS() = 1` The `https://developer.android.com/reference/android/Manifest.permission.html#READ_SMS` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)` |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html other)` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/androidx/appsearch/app/Migrator>` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getMigrators()()` Returns the map of `https://developer.android.com/reference/androidx/appsearch/app/Migrator`, the key will be the schema type of the `https://developer.android.com/reference/androidx/appsearch/app/Migrator` associated with. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/androidx/appsearch/app/PackageIdentifier>` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getPubliclyVisibleSchemas()()` Returns a mapping of publicly visible schemas to the `https://developer.android.com/reference/androidx/appsearch/app/PackageIdentifier` specifying the package the schemas are from. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/Integer.html>>>` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getRequiredPermissionsForSchemaTypeVisibility()()` Returns a mapping of schema types to the Map of `https://developer.android.com/reference/android/Manifest.permission.html` combinations that querier must hold to access that schema type. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema>` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getSchemas()()` Returns the `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema` types that are part of this request. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getSchemasNotDisplayedBySystem()()` Returns all the schema types that are opted out of being displayed and visible on any system UI surface. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/androidx/appsearch/app/SchemaVisibilityConfig>>` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getSchemasVisibleToConfigs()()` Returns a mapping of schema types to the set of `https://developer.android.com/reference/androidx/appsearch/app/SchemaVisibilityConfig` that have access to that schema type. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/androidx/appsearch/app/PackageIdentifier>>` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getSchemasVisibleToPackages()()` Returns a mapping of schema types to the set of packages that have access to that schema type. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/String.html>>` | `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getSchemasWipeoutAccountPropertyPaths()()` Returns a map containing all schema types that have been configured for account wipeout, mapped to the specific property paths within those schemas that hold the account identifiers. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) int` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#getVersion()()` Returns the database overall schema version. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#hashCode()()` |
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#isForceOverride()()` Returns whether this request will force the schema to be overridden. |

## Constants

### PRIVATE_COMPUTE_CORE_UID_ACCESS

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

```
public static final int PRIVATE_COMPUTE_CORE_UID_ACCESS = 12
```

The visibility access for Private Compute Core.

A schema with this permission requires callers to have a UID for which `https://developer.android.com/reference/android/os/Process.html#isPrivateComputeCoreUid(int)` returns true to access the data.

This permission can be combined with other permissions in the same set. In such cases, the caller must both have a Private Compute Core UID and hold all other permissions in the set to gain access.

### READ_ASSISTANT_APP_SEARCH_DATA

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.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_ASSISTANT_APP_SEARCH_DATA = 6
```

The `https://developer.android.com/reference/android/Manifest.permission.html#READ_ASSISTANT_APP_SEARCH_DATA` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)`

### READ_CALENDAR

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.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_CALENDAR = 2
```

The `https://developer.android.com/reference/android/Manifest.permission.html#READ_CALENDAR` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)`

### READ_CONTACTS

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.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_CONTACTS = 3
```

The `https://developer.android.com/reference/android/Manifest.permission.html#READ_CONTACTS` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)`

### READ_EXTERNAL_STORAGE

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.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_EXTERNAL_STORAGE = 4
```

The `https://developer.android.com/reference/android/Manifest.permission.html#READ_EXTERNAL_STORAGE` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)`

### READ_HOME_APP_SEARCH_DATA

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.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_HOME_APP_SEARCH_DATA = 5
```

The `https://developer.android.com/reference/android/Manifest.permission.html#READ_HOME_APP_SEARCH_DATA` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)`

### READ_SMS

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.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_SMS = 1
```

The `https://developer.android.com/reference/android/Manifest.permission.html#READ_SMS` AppSearch supported in `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest.Builder#addRequiredPermissionsForSchemaTypeVisibility(java.lang.String,java.util.Set<java.lang.Integer>)`

## Public methods

### equals

```
public boolean equals(@Nullable Object other)
```

### getMigrators

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

```
public @NonNull Map<String, Migrator> getMigrators()
```

Returns the map of `https://developer.android.com/reference/androidx/appsearch/app/Migrator`, the key will be the schema type of the `https://developer.android.com/reference/androidx/appsearch/app/Migrator` associated with.

### getPubliclyVisibleSchemas

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

```
public @NonNull Map<String, PackageIdentifier> getPubliclyVisibleSchemas()
```

Returns a mapping of publicly visible schemas to the `https://developer.android.com/reference/androidx/appsearch/app/PackageIdentifier` specifying the package the schemas are from.

### getRequiredPermissionsForSchemaTypeVisibility

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

```
public @NonNull Map<String, Set<Set<Integer>>> getRequiredPermissionsForSchemaTypeVisibility()
```

Returns a mapping of schema types to the Map of `https://developer.android.com/reference/android/Manifest.permission.html` combinations that querier must hold to access that schema type.

The querier could read the `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument` objects under the `schemaType` if they holds ALL required permissions of ANY of the individual value sets.

For example, if the Map contains `{ % verbatim %}{ {permissionA, PermissionB},
{PermissionC, PermissionD}, {PermissionE}}{ % endverbatim %}`.

- A querier holds both PermissionA and PermissionB has access.
- A querier holds both PermissionC and PermissionD has access.
- A querier holds only PermissionE has access.
- A querier holds both PermissionA and PermissionE has access.
- A querier holds only PermissionA doesn't have access.
- A querier holds both PermissionA and PermissionC doesn't have access.

It's inefficient to call this method repeatedly.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/Integer.html>>>` | The map contains schema type and all combinations of required permission for querier to access it. The supported Permission are `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_SMS()`, `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_CALENDAR()`, `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_CONTACTS()`, `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_EXTERNAL_STORAGE()`, `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_HOME_APP_SEARCH_DATA()` and `https://developer.android.com/reference/androidx/appsearch/app/SetSchemaRequest#READ_ASSISTANT_APP_SEARCH_DATA()`. |

### getSchemas

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

```
public @NonNull Set<AppSearchSchema> getSchemas()
```

Returns the `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema` types that are part of this request.

### getSchemasNotDisplayedBySystem

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

```
public @NonNull Set<String> getSchemasNotDisplayedBySystem()
```

Returns all the schema types that are opted out of being displayed and visible on any system UI surface.

### getSchemasVisibleToConfigs

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

```
public @NonNull Map<String, Set<SchemaVisibilityConfig>> getSchemasVisibleToConfigs()
```

Returns a mapping of schema types to the set of `https://developer.android.com/reference/androidx/appsearch/app/SchemaVisibilityConfig` that have access to that schema type.

It's inefficient to call this method repeatedly.

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

### getSchemasVisibleToPackages

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

```
public @NonNull Map<String, Set<PackageIdentifier>> getSchemasVisibleToPackages()
```

Returns a mapping of schema types to the set of packages that have access to that schema type.

It's inefficient to call this method repeatedly.

### getSchemasWipeoutAccountPropertyPaths

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

```
@ExperimentalAppSearchApi
public @NonNull Map<String, Set<String>> getSchemasWipeoutAccountPropertyPaths()
```

Returns a map containing all schema types that have been configured for account wipeout, mapped to the specific property paths within those schemas that hold the account identifiers.

This method performs a deep copy to ensure the returned map and its contained sets are immutable from external modifications.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/String.html>>` | A map where keys are schema type names, and values are sets of `https://developer.android.com/reference/androidx/appsearch/app/PropertyPath` strings configured for account wipeout for that schema type. |

### getVersion

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

```
public @IntRange(from = 1) int getVersion()
```

Returns the database overall schema version.

### hashCode

```
public int hashCode()
```

### isForceOverride

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

```
public boolean isForceOverride()
```

Returns whether this request will force the schema to be overridden.