SetSchemaRequest.Builder

public static final classSetSchemaRequest.BuilderextendsObject

Builder forSetSchemaRequest objects.

Public Constructor Summary

Public Method Summary

SetSchemaRequest.Builder
addRequiredPermissionsForSchemaTypeVisibility(StringschemaType, Set<Integer> permissions)
Adds a set of required AndroidManifest.permission combination to the given schema type.
SetSchemaRequest.Builder
addSchemaTypeVisibleToConfig(StringschemaType, SchemaVisibilityConfigschemaVisibilityConfig)
Sets the documents from the providedschemaTypecan be read by the caller if they match the ALL visibility requirements set in SchemaVisibilityConfig.
SetSchemaRequest.Builder
addSchemas(Collection<AppSearchSchema> schemas)
Adds a collection ofAppSearchSchema objects to the schema.
SetSchemaRequest.Builder
addSchemas(AppSearchSchema... schemas)
Adds one or moreAppSearchSchema types to the schema.
SetSchemaRequest
build()
Builds a newSetSchemaRequest object.
SetSchemaRequest.Builder
clearRequiredPermissionsForSchemaTypeVisibility(StringschemaType)
Clears all required permissions combinations for the given schema type.
SetSchemaRequest.Builder
clearSchemaTypeVisibleToConfigs(StringschemaType)
Clears all visible to SchemaVisibilityConfigfor the given schema type.
SetSchemaRequest.Builder
setForceOverride(boolean forceOverride)
Sets whether or not to override the current schema in theAppSearchClient database.
SetSchemaRequest.Builder
setMigrator(StringschemaType, Migrator migrator)
Sets theMigrator associated with the given SchemaType.
SetSchemaRequest.Builder
setMigrators(Map<String,Migrator> migrators)
Sets a Map ofMigrators.
SetSchemaRequest.Builder
setPubliclyVisibleSchema(Stringschema, PackageIdentifier packageIdentifier)
Specify that the schema should be publicly available, to packages which already have visibility topackageIdentifier.
SetSchemaRequest.Builder
setSchemaTypeDisplayedBySystem(StringschemaType, boolean displayed)
Sets whether or not documents from the providedschemaTypewill be displayed and visible on any system UI surface.
SetSchemaRequest.Builder
setSchemaTypeVisibilityForPackage(StringschemaType, boolean visible,PackageIdentifier packageIdentifier)
Sets whether or not documents from the providedschemaTypecan be read by the specified package.
SetSchemaRequest.Builder
setVersion(int version)
Sets the version number of the overallAppSearchSchema in the database.

Inherited Method Summary

Public Constructors

publicBuilder()

Public Methods

publicSetSchemaRequest.Builder addRequiredPermissionsForSchemaTypeVisibility (StringschemaType,Set<Integer> permissions)

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

If the querier holds ALL of the required permissions in this combination, they will have access to readGenericDocument 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 areSetSchemaRequest.READ_SMS, SetSchemaRequest.READ_CALENDAR, SetSchemaRequest.READ_CONTACTS, SetSchemaRequest.READ_EXTERNAL_STORAGE, SetSchemaRequest.READ_HOME_APP_SEARCH_DATAand SetSchemaRequest.READ_ASSISTANT_APP_SEARCH_DATA.

The relationship between permissions added in this method and package visibility setting 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 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.
Throws
IllegalArgumentException – if input unsupported permission.

publicSetSchemaRequest.Builder addSchemaTypeVisibleToConfig(String schemaType,SchemaVisibilityConfig schemaVisibilityConfig)

Sets the documents from the providedschemaTypecan be read by the caller if they match the ALL visibility requirements set inSchemaVisibilityConfig.

The requirements in aSchemaVisibilityConfig 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 multipleSchemaVisibilityConfigs, and the querier will have access if they match ANY of theSchemaVisibilityConfig.

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

publicSetSchemaRequest.Builder addSchemas(Collection<AppSearchSchema> schemas)

Adds a collection ofAppSearchSchema objects to the schema.

AnAppSearchSchema object represents one type of structured data.

publicSetSchemaRequest.Builder addSchemas(AppSearchSchema... schemas)

Adds one or moreAppSearchSchema types to the schema.

AnAppSearchSchema object represents one type of structured data.

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

publicSetSchemaRequest build()

Builds a newSetSchemaRequest object.

Throws
IllegalArgumentException if schema types were referenced, but the correspondingAppSearchSchema type was never added.

publicSetSchemaRequest.Builder clearRequiredPermissionsForSchemaTypeVisibility (String schemaType)

Clears all required permissions combinations for the given schema type.

publicSetSchemaRequest.Builder clearSchemaTypeVisibleToConfigs(String schemaType)

Clears all visible toSchemaVisibilityConfig for the given schema type.

publicSetSchemaRequest.Builder setForceOverride(boolean forceOverride)

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

Call this method whenever backward incompatible changes need to be made by setting forceOverridetotrue.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 isfalse.

publicSetSchemaRequest.Builder setMigrator(StringschemaType,Migrator migrator)

Sets theMigrator associated with the given SchemaType.

TheMigrator migrates allGenericDocuments under given schema type from the current version number stored in AppSearch to the final version set via setVersion(int).

AMigrator will be invoked if the current version number stored in AppSearch is different from the final version set via setVersion(int)and Migrator.shouldMigrate(int, int)returnstrue.

The target schema type of the outputGenericDocument 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 setVersion(int).

publicSetSchemaRequest.Builder setMigrators(Map<String,Migrator> migrators)

Sets a Map ofMigrators.

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

TheMigrator migrates allGenericDocuments under given schema type from the current version number stored in AppSearch to the final version set via setVersion(int).

AMigrator will be invoked if the current version number stored in AppSearch is different from the final version set via setVersion(int)and Migrator.shouldMigrate(int, int)returnstrue.

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

Parameters
migrators AMapof migrators that translate a document from its current version to the final version set via setVersion(int).The key of the map is the schema type that the Migrator value applies to.

publicSetSchemaRequest.Builder setPubliclyVisibleSchema(String schema,PackageIdentifier packageIdentifier)

Specify that the schema should be publicly available, to packages which already have visibility topackageIdentifier.This visibility is determined by the result of PackageManager.canPackageQuery(String, String).

It is possible for the packageIdentifier parameter to be different from the package performing the inde xing. 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, thePackageIdentifier 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 typeschema.

publicSetSchemaRequest.Builder setSchemaTypeDisplayedBySystem(String schemaType, boolean displayed)

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

This setting applies to the providedschemaTypeonly, and does not persist across AppSearchClient.setSchema(SetSchemaRequest, String)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 anAppSearchSchema within the sameSetSchemaRequest, which will be configured.
displayed Whether documents of this type will be displayed on system UI surfaces.

publicSetSchemaRequest.Builder setSchemaTypeVisibilityForPackage(String schemaType, boolean visible,PackageIdentifier packageIdentifier)

Sets whether or not documents from the providedschemaTypecan be read by the specified package.

Each package is represented by aPackageIdentifier, containing a package name and a byte array of type PackageManager.CERT_INPUT_SHA256.

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 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 addSchemaTypeVisibleToConfig(String, SchemaVisibilityConfig).

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

publicSetSchemaRequest.Builder setVersion(int version)

Sets the version number of the overallAppSearchSchema in the database.

TheAppSearchClient 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 theMigrators provided to AppSearchClient.setSchema(SetSchemaRequest, String)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 theAppSearchClient database.

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

Parameters
version A positive integer representing the version of the entire set of schemas represents the version of the whole schema in theAppSearchClient database, default version is 1.
Throws
IllegalArgumentException if the version is negative.