public final class

SetSchemaRequest.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.appsearch.app.SetSchemaRequest.Builder

Overview

Builder for SetSchemaRequest objects.

Summary

Constructors
publicBuilder()

Methods
public SetSchemaRequest.BuilderaddDocumentClasses(java.lang.Class<java.lang.Object> documentClasses[])

Adds one or more Document annotated classes to the schema.

public SetSchemaRequest.BuilderaddDocumentClasses(java.util.Collection<java.lang.Class> documentClasses)

Adds a collection of Document annotated classes to the schema.

public SetSchemaRequest.BuilderaddDocumentClassVisibleToConfig(java.lang.Class<java.lang.Object> documentClass, SchemaVisibilityConfig schemaVisibilityConfig)

Sets the documents from the provided schemaType can be read by the caller if they match the ALL visibility requirements set in SchemaVisibilityConfig.

public SetSchemaRequest.BuilderaddRequiredPermissionsForDocumentClassVisibility(java.lang.Class<java.lang.Object> documentClass, java.util.Set<java.lang.Integer> permissions)

Adds a set of required Android combination to the given schema type.

public SetSchemaRequest.BuilderaddRequiredPermissionsForSchemaTypeVisibility(java.lang.String schemaType, java.util.Set<java.lang.Integer> permissions)

Adds a set of required Android combination to the given schema type.

public SetSchemaRequest.BuilderaddSchemas(AppSearchSchema schemas[])

Adds one or more AppSearchSchema types to the schema.

public SetSchemaRequest.BuilderaddSchemas(java.util.Collection<AppSearchSchema> schemas)

Adds a collection of AppSearchSchema objects to the schema.

public SetSchemaRequest.BuilderaddSchemaTypeVisibleToConfig(java.lang.String schemaType, SchemaVisibilityConfig schemaVisibilityConfig)

Sets the documents from the provided schemaType can be read by the caller if they match the ALL visibility requirements set in SchemaVisibilityConfig.

public SetSchemaRequestbuild()

Builds a new SetSchemaRequest object.

public SetSchemaRequest.BuilderclearDocumentClassVisibleToConfigs(java.lang.Class<java.lang.Object> documentClass)

Clears all visible to SchemaVisibilityConfig for the given schema type.

public SetSchemaRequest.BuilderclearRequiredPermissionsForDocumentClassVisibility(java.lang.Class<java.lang.Object> documentClass)

Clears all required permissions combinations for the given schema type.

public SetSchemaRequest.BuilderclearRequiredPermissionsForSchemaTypeVisibility(java.lang.String schemaType)

Clears all required permissions combinations for the given schema type.

public SetSchemaRequest.BuilderclearSchemaTypeVisibleToConfigs(java.lang.String schemaType)

Clears all visible to SchemaVisibilityConfig for the given schema type.

public SetSchemaRequest.BuildersetDocumentClassDisplayedBySystem(java.lang.Class<java.lang.Object> documentClass, boolean displayed)

Sets whether or not documents from the provided Document annotated class will be displayed and visible on any system UI surface.

public SetSchemaRequest.BuildersetDocumentClassVisibilityForPackage(java.lang.Class<java.lang.Object> documentClass, boolean visible, PackageIdentifier packageIdentifier)

Sets whether or not documents from the provided Document annotated class can be read by the specified package.

public SetSchemaRequest.BuildersetForceOverride(boolean forceOverride)

Sets whether or not to override the current schema in the AppSearchSession database.

public SetSchemaRequest.BuildersetMigrator(java.lang.String schemaType, Migrator migrator)

Sets the Migrator associated with the given SchemaType.

public SetSchemaRequest.BuildersetMigrators(java.util.Map<java.lang.String, Migrator> migrators)

Sets a Map of Migrators.

public SetSchemaRequest.BuildersetPubliclyVisibleDocumentClass(java.lang.Class<java.lang.Object> documentClass, PackageIdentifier packageIdentifier)

Specify that the schema should be publicly available, to packages which already have visibility to packageIdentifier.

public SetSchemaRequest.BuildersetPubliclyVisibleSchema(java.lang.String schema, PackageIdentifier packageIdentifier)

Specify that the schema should be publicly available, to packages which already have visibility to packageIdentifier.

public SetSchemaRequest.BuildersetSchemaTypeDisplayedBySystem(java.lang.String schemaType, boolean displayed)

Sets whether or not documents from the provided schemaType will be displayed and visible on any system UI surface.

public SetSchemaRequest.BuildersetSchemaTypeVisibilityForPackage(java.lang.String schemaType, boolean visible, PackageIdentifier packageIdentifier)

Sets whether or not documents from the provided schemaType can be read by the specified package.

public SetSchemaRequest.BuildersetVersion(int version)

Sets the version number of the overall AppSearchSchema in the database.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Methods

public SetSchemaRequest.Builder addSchemas(AppSearchSchema schemas[])

Adds one or more AppSearchSchema types to the schema.

An AppSearchSchema object represents one type of structured data.

Any documents of these types will be displayed on system UI surfaces by default.

public SetSchemaRequest.Builder addSchemas(java.util.Collection<AppSearchSchema> schemas)

Adds a collection of AppSearchSchema objects to the schema.

An AppSearchSchema object represents one type of structured data.

public SetSchemaRequest.Builder addDocumentClasses(java.lang.Class<java.lang.Object> documentClasses[])

Adds one or more Document annotated classes to the schema.

Merged list available from SetSchemaRequest.getSchemas().

Parameters:

documentClasses: classes annotated with Document.

public SetSchemaRequest.Builder addDocumentClasses(java.util.Collection<java.lang.Class> documentClasses)

Adds a collection of Document annotated classes to the schema.

This will also add all Document classes referenced by the schema via document properties.

Merged list available from SetSchemaRequest.getSchemas().

Parameters:

documentClasses: classes annotated with Document.

public SetSchemaRequest.Builder setSchemaTypeDisplayedBySystem(java.lang.String schemaType, boolean displayed)

Sets whether or not documents from the provided schemaType will be displayed and visible on any system UI surface.

This setting applies to the provided schemaType only, and does not persist across AppSearchSession.setSchemaAsync(SetSchemaRequest) calls.

The default behavior, if this method is not called, is to allow types to be displayed on system UI surfaces.

Parameters:

schemaType: The name of an AppSearchSchema within the same SetSchemaRequest, which will be configured.
displayed: Whether documents of this type will be displayed on system UI surfaces.

public SetSchemaRequest.Builder addRequiredPermissionsForSchemaTypeVisibility(java.lang.String schemaType, java.util.Set<java.lang.Integer> permissions)

Adds a set of required Android combination to the given schema type.

If the querier holds ALL of the required permissions in this combination, they will have access to read GenericDocument objects of the given schema type.

You can call this method to add multiple permission combinations, and the querier will have access if they holds ANY of the combinations.

The supported Permissions are SetSchemaRequest.READ_SMS, SetSchemaRequest.READ_CALENDAR, SetSchemaRequest.READ_CONTACTS, SetSchemaRequest.READ_EXTERNAL_STORAGE, SetSchemaRequest.READ_HOME_APP_SEARCH_DATA and SetSchemaRequest.READ_ASSISTANT_APP_SEARCH_DATA.

The relationship between permissions added in this method and package visibility setting SetSchemaRequest.Builder.setSchemaTypeVisibilityForPackage(String, boolean, PackageIdentifier) is "OR". The caller could access the schema if they match ANY requirements. If you want to set "AND" requirements like a caller must hold required permissions AND it is a specified package, please use SetSchemaRequest.Builder.addSchemaTypeVisibleToConfig(String, SchemaVisibilityConfig).

Parameters:

schemaType: The schema type to set visibility on.
permissions: A set of required Android permissions the caller need to hold to access GenericDocument objects that under the given schema.

See also:

public SetSchemaRequest.Builder clearRequiredPermissionsForSchemaTypeVisibility(java.lang.String schemaType)

Clears all required permissions combinations for the given schema type.

public SetSchemaRequest.Builder setSchemaTypeVisibilityForPackage(java.lang.String schemaType, boolean visible, PackageIdentifier packageIdentifier)

Sets whether or not documents from the provided schemaType can be read by the specified package.

Each package is represented by a PackageIdentifier, containing a package name and a byte array of type android.content.pm.PackageManager.

To opt into one-way data sharing with another application, the developer will need to explicitly grant the other application’s package name and certificate Read access to its data.

For two-way data sharing, both applications need to explicitly grant Read access to one another.

By default, data sharing between applications is disabled.

The relationship between permissions added in this method and package visibility setting SetSchemaRequest.Builder.setSchemaTypeVisibilityForPackage(String, boolean, PackageIdentifier) is "OR". The caller could access the schema if they match ANY requirements. If you want to set "AND" requirements like a caller must hold required permissions AND it is a specified package, please use SetSchemaRequest.Builder.addSchemaTypeVisibleToConfig(String, SchemaVisibilityConfig).

Parameters:

schemaType: The schema type to set visibility on.
visible: Whether the schemaType will be visible or not.
packageIdentifier: Represents the package that will be granted visibility.

public SetSchemaRequest.Builder setPubliclyVisibleSchema(java.lang.String schema, PackageIdentifier packageIdentifier)

Specify that the schema should be publicly available, to packages which already have visibility to packageIdentifier. This visibility is determined by the result of android.content.pm.PackageManager.

It is possible for the packageIdentifier parameter to be different from the package performing the indexing. This might happen in the case of an on-device indexer processing information about various packages. The visibility will be the same regardless of which package indexes the document, as the visibility is based on the packageIdentifier parameter.

If this is called repeatedly with the same schema, the PackageIdentifier in the last call will be used as the "from" package for that schema.

Calling this with packageIdentifier set to null is valid, and will remove public visibility for the schema.

Parameters:

schema: the schema to make publicly accessible.
packageIdentifier: if an app can see this package via PackageManager#canPackageQuery, it will be able to see the documents of type schema.

public SetSchemaRequest.Builder setPubliclyVisibleDocumentClass(java.lang.Class<java.lang.Object> documentClass, PackageIdentifier packageIdentifier)

Specify that the schema should be publicly available, to packages which already have visibility to packageIdentifier.

Parameters:

documentClass: the document to make publicly accessible.
packageIdentifier: if an app can see this package via PackageManager#canPackageQuery, it will be able to see the documents of type documentClass.

See also: SetSchemaRequest.Builder.setPubliclyVisibleSchema(String, PackageIdentifier)

public SetSchemaRequest.Builder addSchemaTypeVisibleToConfig(java.lang.String schemaType, SchemaVisibilityConfig schemaVisibilityConfig)

Sets the documents from the provided schemaType can be read by the caller if they match the ALL visibility requirements set in SchemaVisibilityConfig.

The requirements in a SchemaVisibilityConfig is "AND" relationship. A caller must match ALL requirements to access the schema. For example, a caller must hold required permissions AND it is a specified package.

You can call this method repeatedly to add multiple SchemaVisibilityConfigs, and the querier will have access if they match ANY of the SchemaVisibilityConfig.

Parameters:

schemaType: The schema type to set visibility on.
schemaVisibilityConfig: The SchemaVisibilityConfig holds all requirements that a call must to match to access the schema.

public SetSchemaRequest.Builder clearSchemaTypeVisibleToConfigs(java.lang.String schemaType)

Clears all visible to SchemaVisibilityConfig for the given schema type.

public SetSchemaRequest.Builder setMigrator(java.lang.String schemaType, Migrator migrator)

Sets the Migrator associated with the given SchemaType.

The Migrator migrates all GenericDocuments under given schema type from the current version number stored in AppSearch to the final version set via SetSchemaRequest.Builder.setVersion(int).

A Migrator will be invoked if the current version number stored in AppSearch is different from the final version set via SetSchemaRequest.Builder.setVersion(int) and Migrator.shouldMigrate(int, int) returns true.

The target schema type of the output GenericDocument of Migrator.onUpgrade(int, int, GenericDocument) or Migrator.onDowngrade(int, int, GenericDocument) must exist in this SetSchemaRequest.

Parameters:

schemaType: The schema type to set migrator on.
migrator: The migrator translates a document from its current version to the final version set via SetSchemaRequest.Builder.setVersion(int).

See also: SetSchemaRequest.Builder.setVersion(int), SetSchemaRequest.Builder.addSchemas(AppSearchSchema...), AppSearchSession.setSchemaAsync(SetSchemaRequest)

public SetSchemaRequest.Builder setMigrators(java.util.Map<java.lang.String, Migrator> migrators)

Sets a Map of Migrators.

The key of the map is the schema type that the Migrator value applies to.

The Migrator migrates all GenericDocuments under given schema type from the current version number stored in AppSearch to the final version set via SetSchemaRequest.Builder.setVersion(int).

A Migrator will be invoked if the current version number stored in AppSearch is different from the final version set via SetSchemaRequest.Builder.setVersion(int) and Migrator.shouldMigrate(int, int) returns true.

The target schema type of the output GenericDocument of Migrator.onUpgrade(int, int, GenericDocument) or Migrator.onDowngrade(int, int, GenericDocument) must exist in this SetSchemaRequest.

Parameters:

migrators: A java.util.Map of migrators that translate a document from its current version to the final version set via SetSchemaRequest.Builder.setVersion(int). The key of the map is the schema type that the Migrator value applies to.

See also: SetSchemaRequest.Builder.setVersion(int), SetSchemaRequest.Builder.addSchemas(AppSearchSchema...), AppSearchSession.setSchemaAsync(SetSchemaRequest)

public SetSchemaRequest.Builder setDocumentClassDisplayedBySystem(java.lang.Class<java.lang.Object> documentClass, boolean displayed)

Sets whether or not documents from the provided Document annotated class will be displayed and visible on any system UI surface.

This setting applies to the provided Document annotated class only, and does not persist across AppSearchSession.setSchemaAsync(SetSchemaRequest) calls.

The default behavior, if this method is not called, is to allow types to be displayed on system UI surfaces.

Merged list available from SetSchemaRequest.getSchemasNotDisplayedBySystem().

Parameters:

documentClass: A class annotated with Document, the visibility of which will be configured
displayed: Whether documents of this type will be displayed on system UI surfaces.

public SetSchemaRequest.Builder setDocumentClassVisibilityForPackage(java.lang.Class<java.lang.Object> documentClass, boolean visible, PackageIdentifier packageIdentifier)

Sets whether or not documents from the provided Document annotated class can be read by the specified package.

Each package is represented by a PackageIdentifier, containing a package name and a byte array of type android.content.pm.PackageManager.

To opt into one-way data sharing with another application, the developer will need to explicitly grant the other application’s package name and certificate Read access to its data.

For two-way data sharing, both applications need to explicitly grant Read access to one another.

By default, app data sharing between applications is disabled.

The relationship between visible packages added in this method and permission visibility setting SetSchemaRequest.Builder.addRequiredPermissionsForSchemaTypeVisibility(String, Set) is "OR". The caller could access the schema if they match ANY requirements. If you want to set "AND" requirements like a caller must hold required permissions AND it is a specified package, please use SetSchemaRequest.Builder.addSchemaTypeVisibleToConfig(String, SchemaVisibilityConfig).

Merged list available from SetSchemaRequest.getSchemasVisibleToPackages().

Parameters:

documentClass: The Document class to set visibility on.
visible: Whether the documentClass will be visible or not.
packageIdentifier: Represents the package that will be granted visibility.

public SetSchemaRequest.Builder addRequiredPermissionsForDocumentClassVisibility(java.lang.Class<java.lang.Object> documentClass, java.util.Set<java.lang.Integer> permissions)

Adds a set of required Android combination to the given schema type.

If the querier holds ALL of the required permissions in this combination, they will have access to read GenericDocument objects of the given schema type.

You can call this method to add multiple permission combinations, and the querier will have access if they holds ANY of the combinations.

The supported Permissions are SetSchemaRequest.READ_SMS, SetSchemaRequest.READ_CALENDAR, SetSchemaRequest.READ_CONTACTS, SetSchemaRequest.READ_EXTERNAL_STORAGE, SetSchemaRequest.READ_HOME_APP_SEARCH_DATA and SetSchemaRequest.READ_ASSISTANT_APP_SEARCH_DATA.

The relationship between visible packages added in this method and permission visibility setting SetSchemaRequest.Builder.addRequiredPermissionsForSchemaTypeVisibility(String, Set) is "OR". The caller could access the schema if they match ANY requirements. If you want to set "AND" requirements like a caller must hold required permissions AND it is a specified package, please use SetSchemaRequest.Builder.addSchemaTypeVisibleToConfig(String, SchemaVisibilityConfig).

Merged map available from SetSchemaRequest.getRequiredPermissionsForSchemaTypeVisibility().

Parameters:

documentClass: The Document class to set visibility on.
permissions: A set of required Android permissions the caller need to hold to access GenericDocument objects that under the given schema.

See also:

public SetSchemaRequest.Builder clearRequiredPermissionsForDocumentClassVisibility(java.lang.Class<java.lang.Object> documentClass)

Clears all required permissions combinations for the given schema type.

public SetSchemaRequest.Builder addDocumentClassVisibleToConfig(java.lang.Class<java.lang.Object> documentClass, SchemaVisibilityConfig schemaVisibilityConfig)

Sets the documents from the provided schemaType can be read by the caller if they match the ALL visibility requirements set in SchemaVisibilityConfig.

The requirements in a SchemaVisibilityConfig is "AND" relationship. A caller must match ALL requirements to access the schema. For example, a caller must hold required permissions AND it is a specified package.

You can call this method repeatedly to add multiple SchemaVisibilityConfigs, and the querier will have access if they match ANY of the SchemaVisibilityConfig.

Parameters:

documentClass: A class annotated with Document, the visibility of which will be configured
schemaVisibilityConfig: The SchemaVisibilityConfig holds all requirements that a call must to match to access the schema.

public SetSchemaRequest.Builder clearDocumentClassVisibleToConfigs(java.lang.Class<java.lang.Object> documentClass)

Clears all visible to SchemaVisibilityConfig for the given schema type.

public SetSchemaRequest.Builder setForceOverride(boolean forceOverride)

Sets whether or not to override the current schema in the AppSearchSession database.

Call this method whenever backward incompatible changes need to be made by setting forceOverride to true. As a result, during execution of the setSchema operation, all documents that are incompatible with the new schema will be deleted and the new schema will be saved and persisted.

By default, this is false.

public SetSchemaRequest.Builder setVersion(int version)

Sets the version number of the overall AppSearchSchema in the database.

The AppSearchSession database can only ever hold documents for one version at a time.

Setting a version number that is different from the version number currently stored in AppSearch will result in AppSearch calling the Migrators provided to AppSearchSession.setSchemaAsync(SetSchemaRequest) to migrate the documents already in AppSearch from the previous version to the one set in this request. The version number can be updated without any other changes to the set of schemas.

The version number can stay the same, increase, or decrease relative to the current version number that is already stored in the AppSearchSession database.

The version of an empty database will always be 0. You cannot set version to the SetSchemaRequest, if it doesn't contains any AppSearchSchema.

Parameters:

version: A positive integer representing the version of the entire set of schemas represents the version of the whole schema in the AppSearchSession database, default version is 1.

See also: AppSearchSession.setSchemaAsync(SetSchemaRequest), Migrator, SetSchemaRequest.Builder.setMigrator(String, Migrator)

public SetSchemaRequest build()

Builds a new SetSchemaRequest object.