SetSchemaRequest


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

Builder for SetSchemaRequest objects.

Constants

const 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

const 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

const 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

const 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

const 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

const 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 functions

(Mutable)Map<String!, Migrator!>

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

(Mutable)Map<String!, PackageIdentifier!>

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

(Mutable)Map<String!, (Mutable)Set<(Mutable)Set<Int!>!>!>

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

(Mutable)Set<AppSearchSchema!>

Returns the AppSearchSchema types that are part of this request.

(Mutable)Set<String!>

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

(Mutable)Map<String!, (Mutable)Set<SchemaVisibilityConfig!>!>

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

(Mutable)Map<String!, (Mutable)Set<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)
const val READ_ASSISTANT_APP_SEARCH_DATA = 6: Int

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)
const val READ_CALENDAR = 2: Int

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)
const val READ_CONTACTS = 3: Int

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)
const val READ_EXTERNAL_STORAGE = 4: Int

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)
const val READ_HOME_APP_SEARCH_DATA = 5: Int

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)
const val READ_SMS = 1: Int

The READ_SMS AppSearch supported in addRequiredPermissionsForSchemaTypeVisibility

Public functions

getMigrators

Added in 1.1.0-alpha06
fun getMigrators(): (Mutable)Map<String!, Migrator!>

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

getPubliclyVisibleSchemas

Added in 1.1.0-alpha06
fun getPubliclyVisibleSchemas(): (Mutable)Map<String!, PackageIdentifier!>

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

getRequiredPermissionsForSchemaTypeVisibility

Added in 1.1.0-alpha06
fun getRequiredPermissionsForSchemaTypeVisibility(): (Mutable)Map<String!, (Mutable)Set<(Mutable)Set<Int!>!>!>

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
(Mutable)Map<String!, (Mutable)Set<(Mutable)Set<Int!>!>!>

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
fun getSchemas(): (Mutable)Set<AppSearchSchema!>

Returns the AppSearchSchema types that are part of this request.

getSchemasNotDisplayedBySystem

Added in 1.1.0-alpha06
fun getSchemasNotDisplayedBySystem(): (Mutable)Set<String!>

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
fun getSchemasVisibleToConfigs(): (Mutable)Map<String!, (Mutable)Set<SchemaVisibilityConfig!>!>

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
fun getSchemasVisibleToPackages(): (Mutable)Map<String!, (Mutable)Set<PackageIdentifier!>!>

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
fun getVersion(): @IntRange(from = 1) Int

Returns the database overall schema version.

isForceOverride

Added in 1.1.0-alpha06
fun isForceOverride(): Boolean

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