SetSchemaRequest


public final class SetSchemaRequest


Encapsulates a request to update the schema of an AppSearchSession database.

The schema is composed of a collection of 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 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 AppSearchSchema types
  • Addition of new properties to an existing 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 AppSearchSchema type
  • Removal of a property from an existing 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 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 setForceOverride 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 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 getIncompatibleTypes and getMigratedTypes. See the migration section below.

Summary

Nested types

public final class SetSchemaRequest.Builder

Builder for SetSchemaRequest objects.

Constants

static final int
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
READ_ASSISTANT_APP_SEARCH_DATA = 6

The READ_ASSISTANT_APP_SEARCH_DATA AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

static final int
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
READ_CALENDAR = 2

The READ_CALENDAR AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

static final int
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
READ_CONTACTS = 3

The READ_CONTACTS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

static final int
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
READ_EXTERNAL_STORAGE = 4

The READ_EXTERNAL_STORAGE AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

static final int
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
READ_HOME_APP_SEARCH_DATA = 5

The READ_HOME_APP_SEARCH_DATA AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

static final int
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
READ_SMS = 1

The READ_SMS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

Public methods

@NonNull Map<StringMigrator>

Returns the map of Migrator, the key will be the schema type of the Migrator associated with.

@NonNull Map<StringPackageIdentifier>

Returns a mapping of publicly visible schemas to the PackageIdentifier specifying the package the schemas are from.

@NonNull Map<StringSet<Set<Integer>>>

Returns a mapping of schema types to the Map of android.Manifest.permission combinations that querier must hold to access that schema type.

@NonNull Set<AppSearchSchema>

Returns the AppSearchSchema types that are part of this request.

@NonNull Set<String>

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

@NonNull Map<StringSet<SchemaVisibilityConfig>>

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

@NonNull Map<StringSet<PackageIdentifier>>

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

@IntRange(from = 1) int

Returns the database overall schema version.

boolean

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

Constants

READ_ASSISTANT_APP_SEARCH_DATA

Added in 1.1.0-alpha06
@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 READ_ASSISTANT_APP_SEARCH_DATA AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

READ_CALENDAR

Added in 1.1.0-alpha06
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_CALENDAR = 2

The READ_CALENDAR AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

READ_CONTACTS

Added in 1.1.0-alpha06
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_CONTACTS = 3

The READ_CONTACTS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

READ_EXTERNAL_STORAGE

Added in 1.1.0-alpha06
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_EXTERNAL_STORAGE = 4

The READ_EXTERNAL_STORAGE AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

READ_HOME_APP_SEARCH_DATA

Added in 1.1.0-alpha06
@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 READ_HOME_APP_SEARCH_DATA AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

READ_SMS

Added in 1.1.0-alpha06
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.ADD_PERMISSIONS_AND_GET_VISIBILITY)
public static final int READ_SMS = 1

The READ_SMS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

Public methods

getMigrators

Added in 1.1.0-alpha06
public @NonNull Map<StringMigratorgetMigrators()

Returns the map of Migrator, the key will be the schema type of the Migrator associated with.

getPubliclyVisibleSchemas

Added in 1.1.0-alpha06
public @NonNull Map<StringPackageIdentifiergetPubliclyVisibleSchemas()

Returns a mapping of publicly visible schemas to the PackageIdentifier specifying the package the schemas are from.

getRequiredPermissionsForSchemaTypeVisibility

Added in 1.1.0-alpha06
public @NonNull Map<StringSet<Set<Integer>>> getRequiredPermissionsForSchemaTypeVisibility()

Returns a mapping of schema types to the Map of android.Manifest.permission combinations that querier must hold to access that schema type.

The querier could read the GenericDocument objects under the schemaType if they holds ALL required permissions of ANY of the individual value sets.

For example, if the Map contains {{permissionA, PermissionB}, {PermissionC, PermissionD}, {PermissionE}}.

  • 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
@NonNull Map<StringSet<Set<Integer>>>

The map contains schema type and all combinations of required permission for querier to access it. The supported Permission are READ_SMS, READ_CALENDAR, READ_CONTACTS, READ_EXTERNAL_STORAGE, READ_HOME_APP_SEARCH_DATA and READ_ASSISTANT_APP_SEARCH_DATA.

getSchemas

Added in 1.1.0-alpha06
public @NonNull Set<AppSearchSchemagetSchemas()

Returns the AppSearchSchema types that are part of this request.

getSchemasNotDisplayedBySystem

Added in 1.1.0-alpha06
public @NonNull Set<StringgetSchemasNotDisplayedBySystem()

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-alpha06
public @NonNull Map<StringSet<SchemaVisibilityConfig>> getSchemasVisibleToConfigs()

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

It’s inefficient to call this method repeatedly.

getSchemasVisibleToPackages

Added in 1.1.0-alpha06
public @NonNull Map<StringSet<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.

getVersion

Added in 1.1.0-alpha06
public @IntRange(from = 1) int getVersion()

Returns the database overall schema version.

isForceOverride

Added in 1.1.0-alpha06
public boolean isForceOverride()

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