Update Framework from Jetpack.

Included changes:
* 509ebe: Rename getSchemasNotVisibleToSystemUi to setSchemaTypeDisplayedBySystem
* a532fe: Resolve merge conflicts from upstream sync.

Bug: 179143575
Bug: 175146044
Bug: 179160886
Bug: 175255572
Bug: 181887768
Test: Presubmit

Change-Id: I977baf47f6188e4c182a5cf96af4873d0e5284e0
This commit is contained in:
Alexander Dorokhine
2021-03-04 12:34:41 -08:00
parent 4e92407479
commit 73fb4da96d
16 changed files with 79 additions and 108 deletions

View File

@@ -207,7 +207,6 @@ package android.app.appsearch {
public static final class GetByUriRequest.Builder {
ctor public GetByUriRequest.Builder();
method @NonNull public android.app.appsearch.GetByUriRequest.Builder addProjection(@NonNull String, @NonNull java.lang.String...);
method @NonNull public android.app.appsearch.GetByUriRequest.Builder addProjection(@NonNull String, @NonNull java.util.Collection<java.lang.String>);
method @NonNull public android.app.appsearch.GetByUriRequest.Builder addUris(@NonNull java.lang.String...);
method @NonNull public android.app.appsearch.GetByUriRequest.Builder addUris(@NonNull java.util.Collection<java.lang.String>);
@@ -323,7 +322,6 @@ package android.app.appsearch {
method @NonNull public android.app.appsearch.SearchSpec.Builder addFilterPackageNames(@NonNull java.util.Collection<java.lang.String>);
method @NonNull public android.app.appsearch.SearchSpec.Builder addFilterSchemas(@NonNull java.lang.String...);
method @NonNull public android.app.appsearch.SearchSpec.Builder addFilterSchemas(@NonNull java.util.Collection<java.lang.String>);
method @NonNull public android.app.appsearch.SearchSpec.Builder addProjection(@NonNull String, @NonNull java.lang.String...);
method @NonNull public android.app.appsearch.SearchSpec.Builder addProjection(@NonNull String, @NonNull java.util.Collection<java.lang.String>);
method @NonNull public android.app.appsearch.SearchSpec build();
method @NonNull public android.app.appsearch.SearchSpec.Builder setMaxSnippetSize(@IntRange(from=0, to=android.app.appsearch.SearchSpec.MAX_SNIPPET_SIZE_LIMIT) int);
@@ -338,7 +336,8 @@ package android.app.appsearch {
public final class SetSchemaRequest {
method @NonNull public java.util.Map<java.lang.String,android.app.appsearch.AppSearchSchema.Migrator> getMigrators();
method @NonNull public java.util.Set<android.app.appsearch.AppSearchSchema> getSchemas();
method @NonNull public java.util.Set<java.lang.String> getSchemasNotVisibleToSystemUi();
method @NonNull public java.util.Set<java.lang.String> getSchemasNotDisplayedBySystem();
method @Deprecated @NonNull public java.util.Set<java.lang.String> getSchemasNotVisibleToSystemUi();
method @NonNull public java.util.Map<java.lang.String,java.util.Set<android.app.appsearch.PackageIdentifier>> getSchemasVisibleToPackages();
method public boolean isForceOverride();
}
@@ -350,8 +349,9 @@ package android.app.appsearch {
method @NonNull public android.app.appsearch.SetSchemaRequest build();
method @NonNull public android.app.appsearch.SetSchemaRequest.Builder setForceOverride(boolean);
method @NonNull public android.app.appsearch.SetSchemaRequest.Builder setMigrator(@NonNull String, @NonNull android.app.appsearch.AppSearchSchema.Migrator);
method @NonNull public android.app.appsearch.SetSchemaRequest.Builder setSchemaTypeDisplayedBySystem(@NonNull String, boolean);
method @NonNull public android.app.appsearch.SetSchemaRequest.Builder setSchemaTypeVisibilityForPackage(@NonNull String, boolean, @NonNull android.app.appsearch.PackageIdentifier);
method @NonNull public android.app.appsearch.SetSchemaRequest.Builder setSchemaTypeVisibilityForSystemUi(@NonNull String, boolean);
method @Deprecated @NonNull public android.app.appsearch.SetSchemaRequest.Builder setSchemaTypeVisibilityForSystemUi(@NonNull String, boolean);
}
public class SetSchemaResponse {

View File

@@ -317,7 +317,7 @@ public class AppSearchManager {
getPackageName(),
DEFAULT_DATABASE_NAME,
schemaBundles,
new ArrayList<>(request.getSchemasNotVisibleToSystemUi()),
new ArrayList<>(request.getSchemasNotDisplayedBySystem()),
/*schemasPackageAccessible=*/ Collections.emptyMap(),
request.isForceOverride(),
mContext.getUserId(),

View File

@@ -146,7 +146,7 @@ public final class AppSearchSession implements Closeable {
mPackageName,
mDatabaseName,
schemaBundles,
new ArrayList<>(request.getSchemasNotVisibleToSystemUi()),
new ArrayList<>(request.getSchemasNotDisplayedBySystem()),
schemasPackageAccessibleBundles,
request.isForceOverride(),
mUserId,

View File

@@ -96,7 +96,7 @@ public class GlobalSearchSession implements Closeable {
* SetSchemaRequest.Builder#setSchemaTypeVisibilityForPackage} when building a schema.
*
* <p>Document access can also be granted to system UIs by specifying {@link
* SetSchemaRequest.Builder#setSchemaTypeVisibilityForSystemUi} when building a schema.
* SetSchemaRequest.Builder#setSchemaTypeDisplayedBySystem} when building a schema.
*
* <p>See {@link AppSearchSession#search} for a detailed explanation on forming a query string.
*

View File

@@ -33,7 +33,7 @@ interface IAppSearchManager {
* @param packageName The name of the package that owns this schema.
* @param databaseName The name of the database where this schema lives.
* @param schemaBundles List of {@link AppSearchSchema} bundles.
* @param schemasNotPlatformSurfaceable Schema types that should not be surfaced on platform
* @param schemasNotDisplayedBySystem Schema types that should not be surfaced on platform
* surfaces.
* @param schemasPackageAccessibleBundles Schema types that are visible to the specified
* packages. The value List contains PackageIdentifier Bundles.
@@ -47,7 +47,7 @@ interface IAppSearchManager {
in String packageName,
in String databaseName,
in List<Bundle> schemaBundles,
in List<String> schemasNotPlatformSurfaceable,
in List<String> schemasNotDisplayedBySystem,
in Map<String, List<Bundle>> schemasPackageAccessibleBundles,
boolean forceOverride,
in int userId,

View File

@@ -166,29 +166,7 @@ public final class GetByUriRequest {
* all results, excepting any types that have their own, specific property paths set.
*
* @throws IllegalStateException if the builder has already been used.
* <p>{@see SearchSpec.Builder#addProjection(String, String...)}
*/
@NonNull
public Builder addProjection(@NonNull String schemaType, @NonNull String... propertyPaths) {
Preconditions.checkNotNull(propertyPaths);
return addProjection(schemaType, Arrays.asList(propertyPaths));
}
/**
* Adds property paths for the specified type to be used for projection. If property paths
* are added for a type, then only the properties referred to will be retrieved for results
* of that type. If a property path that is specified isn't present in a result, it will be
* ignored for that result. Property paths cannot be null.
*
* <p>If no property paths are added for a particular type, then all properties of results
* of that type will be retrieved.
*
* <p>If property path is added for the {@link
* GetByUriRequest#PROJECTION_SCHEMA_TYPE_WILDCARD}, then those property paths will apply to
* all results, excepting any types that have their own, specific property paths set.
*
* @throws IllegalStateException if the builder has already been used.
* <p>{@see SearchSpec.Builder#addProjection(String, String...)}
* @see SearchSpec.Builder#addProjection
*/
@NonNull
public Builder addProjection(

View File

@@ -202,14 +202,6 @@ public final class SearchResult {
*/
public static final String PROPERTY_PATH_FIELD = "propertyPath";
/**
* The index of matching value in its property. A property may have multiple values. This
* index indicates which value is the match.
*
* @hide
*/
public static final String VALUES_INDEX_FIELD = "valuesIndex";
/** @hide */
public static final String EXACT_MATCH_POSITION_LOWER_FIELD = "exactMatchPositionLower";
@@ -232,8 +224,7 @@ public final class SearchResult {
mBundle = Preconditions.checkNotNull(bundle);
Preconditions.checkNotNull(document);
mPropertyPath = Preconditions.checkNotNull(bundle.getString(PROPERTY_PATH_FIELD));
mFullText =
getPropertyValues(document, mPropertyPath, mBundle.getInt(VALUES_INDEX_FIELD));
mFullText = getPropertyValues(document, mPropertyPath);
}
/**
@@ -326,8 +317,7 @@ public final class SearchResult {
}
/** Extracts the matching string from the document. */
private static String getPropertyValues(
GenericDocument document, String propertyName, int valueIndex) {
private static String getPropertyValues(GenericDocument document, String propertyName) {
// In IcingLib snippeting is available for only 3 data types i.e String, double and
// long, so we need to check which of these three are requested.
// TODO (tytytyww): getPropertyStringArray takes property name, handle for property
@@ -337,7 +327,9 @@ public final class SearchResult {
if (values == null) {
throw new IllegalStateException("No content found for requested property path!");
}
return values[valueIndex];
// TODO(b/175146044): Return the proper match based on the index in the propertyName.
return values[0];
}
}

View File

@@ -534,28 +534,6 @@ public final class SearchSpec {
* }</pre>
*/
@NonNull
public SearchSpec.Builder addProjection(
@NonNull String schema, @NonNull String... propertyPaths) {
Preconditions.checkNotNull(propertyPaths);
return addProjection(schema, Arrays.asList(propertyPaths));
}
/**
* Adds property paths for the specified type to be used for projection. If property paths
* are added for a type, then only the properties referred to will be retrieved for results
* of that type. If a property path that is specified isn't present in a result, it will be
* ignored for that result. Property paths cannot be null.
*
* <p>If no property paths are added for a particular type, then all properties of results
* of that type will be retrieved.
*
* <p>If property path is added for the {@link SearchSpec#PROJECTION_SCHEMA_TYPE_WILDCARD},
* then those property paths will apply to all results, excepting any types that have their
* own, specific property paths set.
*
* <p>{@see SearchSpec.Builder#addProjection(String, String...)}
*/
@NonNull
public SearchSpec.Builder addProjection(
@NonNull String schema, @NonNull Collection<String> propertyPaths) {
Preconditions.checkState(!mBuilt, "Builder has already been used");

View File

@@ -71,19 +71,19 @@ import java.util.Set;
*/
public final class SetSchemaRequest {
private final Set<AppSearchSchema> mSchemas;
private final Set<String> mSchemasNotVisibleToSystemUi;
private final Set<String> mSchemasNotDisplayedBySystem;
private final Map<String, Set<PackageIdentifier>> mSchemasVisibleToPackages;
private final Map<String, AppSearchSchema.Migrator> mMigrators;
private final boolean mForceOverride;
SetSchemaRequest(
@NonNull Set<AppSearchSchema> schemas,
@NonNull Set<String> schemasNotVisibleToSystemUi,
@NonNull Set<String> schemasNotDisplayedBySystem,
@NonNull Map<String, Set<PackageIdentifier>> schemasVisibleToPackages,
@NonNull Map<String, AppSearchSchema.Migrator> migrators,
boolean forceOverride) {
mSchemas = Preconditions.checkNotNull(schemas);
mSchemasNotVisibleToSystemUi = Preconditions.checkNotNull(schemasNotVisibleToSystemUi);
mSchemasNotDisplayedBySystem = Preconditions.checkNotNull(schemasNotDisplayedBySystem);
mSchemasVisibleToPackages = Preconditions.checkNotNull(schemasVisibleToPackages);
mMigrators = Preconditions.checkNotNull(migrators);
mForceOverride = forceOverride;
@@ -95,13 +95,23 @@ public final class SetSchemaRequest {
return Collections.unmodifiableSet(mSchemas);
}
/**
* TODO(b/181887768): This method exists only for dogfooder transition and must be removed.
* @deprecated This method exists only for dogfooder transition and must be removed.
*/
@Deprecated
@NonNull
public Set<String> getSchemasNotVisibleToSystemUi() {
return getSchemasNotDisplayedBySystem();
}
/**
* Returns all the schema types that are opted out of being displayed and visible on any system
* UI surface.
*/
@NonNull
public Set<String> getSchemasNotVisibleToSystemUi() {
return Collections.unmodifiableSet(mSchemasNotVisibleToSystemUi);
public Set<String> getSchemasNotDisplayedBySystem() {
return Collections.unmodifiableSet(mSchemasNotDisplayedBySystem);
}
/**
@@ -151,7 +161,7 @@ public final class SetSchemaRequest {
*/
public static final class Builder {
private final Set<AppSearchSchema> mSchemas = new ArraySet<>();
private final Set<String> mSchemasNotVisibleToSystemUi = new ArraySet<>();
private final Set<String> mSchemasNotDisplayedBySystem = new ArraySet<>();
private final Map<String, Set<PackageIdentifier>> mSchemasVisibleToPackages =
new ArrayMap<>();
private final Map<String, AppSearchSchema.Migrator> mMigrators = new ArrayMap<>();
@@ -163,6 +173,8 @@ public final class SetSchemaRequest {
*
* <p>An {@link AppSearchSchema} object represents one type of structured data.
*
* <p>Any documents of these types will be displayed on system UI surfaces by default.
*
* @throws IllegalStateException if the builder has already been used.
*/
@NonNull
@@ -186,6 +198,17 @@ public final class SetSchemaRequest {
return this;
}
/**
* TODO(b/181887768): This method exists only for dogfooder transition and must be removed.
* @deprecated This method exists only for dogfooder transition and must be removed.
*/
@Deprecated
@NonNull
public Builder setSchemaTypeVisibilityForSystemUi(
@NonNull String schemaType, boolean displayed) {
return setSchemaTypeDisplayedBySystem(schemaType, displayed);
}
/**
* Sets whether or not documents from the provided {@code schemaType} will be displayed and
* visible on any system UI surface.
@@ -193,24 +216,26 @@ public final class SetSchemaRequest {
* <p>This setting applies to the provided {@code schemaType} only, and does not persist
* across {@link AppSearchSession#setSchema} calls.
*
* <p>By default, documents are displayed and visible on system UI surfaces.
* <p>The default behavior, if this method is not called, is to allow types to be displayed
* on system UI surfaces.
*
* @param schemaType The schema type to set visibility on.
* @param visible Whether the {@code schemaType} will be visible or not.
* @param schemaType The name of an {@link AppSearchSchema} within the same {@link
* SetSchemaRequest}, which will be configured.
* @param displayed Whether documents of this type will be displayed on system UI surfaces.
* @throws IllegalStateException if the builder has already been used.
*/
// Merged list available from getSchemasNotVisibleToSystemUi
// Merged list available from getSchemasNotDisplayedBySystem
@SuppressLint("MissingGetterMatchingBuilder")
@NonNull
public Builder setSchemaTypeVisibilityForSystemUi(
@NonNull String schemaType, boolean visible) {
public Builder setSchemaTypeDisplayedBySystem(
@NonNull String schemaType, boolean displayed) {
Preconditions.checkNotNull(schemaType);
Preconditions.checkState(!mBuilt, "Builder has already been used");
if (visible) {
mSchemasNotVisibleToSystemUi.remove(schemaType);
if (displayed) {
mSchemasNotDisplayedBySystem.remove(schemaType);
} else {
mSchemasNotVisibleToSystemUi.add(schemaType);
mSchemasNotDisplayedBySystem.add(schemaType);
}
return this;
}
@@ -315,9 +340,10 @@ public final class SetSchemaRequest {
Preconditions.checkState(!mBuilt, "Builder has already been used");
mBuilt = true;
// Verify that any schema types with visibility settings refer to a real schema.
// Verify that any schema types with display or visibility settings refer to a real
// schema.
// Create a copy because we're going to remove from the set for verification purposes.
Set<String> referencedSchemas = new ArraySet<>(mSchemasNotVisibleToSystemUi);
Set<String> referencedSchemas = new ArraySet<>(mSchemasNotDisplayedBySystem);
referencedSchemas.addAll(mSchemasVisibleToPackages.keySet());
for (AppSearchSchema schema : mSchemas) {
@@ -332,7 +358,7 @@ public final class SetSchemaRequest {
return new SetSchemaRequest(
mSchemas,
mSchemasNotVisibleToSystemUi,
mSchemasNotDisplayedBySystem,
mSchemasVisibleToPackages,
mMigrators,
mForceOverride);

View File

@@ -89,7 +89,7 @@ public class AppSearchManagerService extends SystemService {
@NonNull String packageName,
@NonNull String databaseName,
@NonNull List<Bundle> schemaBundles,
@NonNull List<String> schemasNotPlatformSurfaceable,
@NonNull List<String> schemasNotDisplayedBySystem,
@NonNull Map<String, List<Bundle>> schemasPackageAccessibleBundles,
boolean forceOverride,
@UserIdInt int userId,
@@ -125,7 +125,7 @@ public class AppSearchManagerService extends SystemService {
packageName,
databaseName,
schemas,
schemasNotPlatformSurfaceable,
schemasNotDisplayedBySystem,
schemasPackageAccessible,
forceOverride);
invokeCallbackOnResult(

View File

@@ -112,8 +112,6 @@ public class SearchResultToProtoConverter {
SnippetMatchProto snippetMatchProto, String propertyPath) {
Bundle bundle = new Bundle();
bundle.putString(SearchResult.MatchInfo.PROPERTY_PATH_FIELD, propertyPath);
bundle.putInt(
SearchResult.MatchInfo.VALUES_INDEX_FIELD, snippetMatchProto.getValuesIndex());
bundle.putInt(
SearchResult.MatchInfo.EXACT_MATCH_POSITION_LOWER_FIELD,
snippetMatchProto.getExactMatchPosition());

View File

@@ -1 +1 @@
I593dfd22279739e5f578e07d36a55cf02ee942c5
I42b89416968565ceb6483b400894f5b49524208c

View File

@@ -34,8 +34,8 @@ public interface GlobalSearchSessionShim extends Closeable {
* SetSchemaRequest.Builder#setDocumentClassVisibilityForPackage} when building a schema.
*
* <p>Document access can also be granted to system UIs by specifying {@link
* SetSchemaRequest.Builder#setSchemaTypeVisibilityForSystemUi}, or {@link
* SetSchemaRequest.Builder#setDocumentClassVisibilityForSystemUi} when building a schema.
* SetSchemaRequest.Builder#setSchemaTypeDisplayedBySystem}, or {@link
* SetSchemaRequest.Builder#setDocumentClassDisplayedBySystem} when building a schema.
*
* <p>See {@link AppSearchSessionShim#search} for a detailed explanation on forming a query
* string.

View File

@@ -21,6 +21,8 @@ import static com.google.common.truth.Truth.assertThat;
import android.os.Bundle;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
import java.util.List;
@@ -67,9 +69,9 @@ public class SearchSpecTest {
SearchSpec searchSpec =
new SearchSpec.Builder()
.setTermMatch(SearchSpec.TERM_MATCH_PREFIX)
.addProjection("TypeA", "field1", "field2.subfield2")
.addProjection("TypeB", "field7")
.addProjection("TypeC")
.addProjection("TypeA", ImmutableList.of("field1", "field2.subfield2"))
.addProjection("TypeB", ImmutableList.of("field7"))
.addProjection("TypeC", ImmutableList.of())
.build();
Map<String, List<String>> typePropertyPathMap = searchSpec.getProjections();

View File

@@ -42,13 +42,13 @@ public class SetSchemaRequestTest {
}
@Test
public void testInvalidSchemaReferences_fromSystemUiVisibility() {
public void testInvalidSchemaReferences_fromDisplayedBySystem() {
IllegalArgumentException expected =
expectThrows(
IllegalArgumentException.class,
() ->
new SetSchemaRequest.Builder()
.setSchemaTypeVisibilityForSystemUi("InvalidSchema", false)
.setSchemaTypeDisplayedBySystem("InvalidSchema", false)
.build());
assertThat(expected).hasMessageThat().contains("referenced, but were not added");
}
@@ -71,30 +71,30 @@ public class SetSchemaRequestTest {
}
@Test
public void testSchemaTypeVisibilityForSystemUi_visible() {
public void testSetSchemaTypeDisplayedBySystem_displayed() {
AppSearchSchema schema = new AppSearchSchema.Builder("Schema").build();
// By default, the schema is visible.
// By default, the schema is displayed.
SetSchemaRequest request = new SetSchemaRequest.Builder().addSchemas(schema).build();
assertThat(request.getSchemasNotVisibleToSystemUi()).isEmpty();
assertThat(request.getSchemasNotDisplayedBySystem()).isEmpty();
request =
new SetSchemaRequest.Builder()
.addSchemas(schema)
.setSchemaTypeVisibilityForSystemUi("Schema", true)
.setSchemaTypeDisplayedBySystem("Schema", true)
.build();
assertThat(request.getSchemasNotVisibleToSystemUi()).isEmpty();
assertThat(request.getSchemasNotDisplayedBySystem()).isEmpty();
}
@Test
public void testSchemaTypeVisibilityForSystemUi_notVisible() {
public void testSetSchemaTypeDisplayedBySystem_notDisplayed() {
AppSearchSchema schema = new AppSearchSchema.Builder("Schema").build();
SetSchemaRequest request =
new SetSchemaRequest.Builder()
.addSchemas(schema)
.setSchemaTypeVisibilityForSystemUi("Schema", false)
.setSchemaTypeDisplayedBySystem("Schema", false)
.build();
assertThat(request.getSchemasNotVisibleToSystemUi()).containsExactly("Schema");
assertThat(request.getSchemasNotDisplayedBySystem()).containsExactly("Schema");
}
@Test

View File

@@ -67,7 +67,6 @@ public class SnippetTest {
.setPropertyName(propertyKeyString)
.addSnippetMatches(
SnippetMatchProto.newBuilder()
.setValuesIndex(0)
.setExactMatchPosition(29)
.setExactMatchBytes(3)
.setWindowPosition(26)
@@ -174,7 +173,6 @@ public class SnippetTest {
.setPropertyName("sender.name")
.addSnippetMatches(
SnippetMatchProto.newBuilder()
.setValuesIndex(0)
.setExactMatchPosition(0)
.setExactMatchBytes(4)
.setWindowPosition(0)
@@ -186,7 +184,6 @@ public class SnippetTest {
.setPropertyName("sender.email")
.addSnippetMatches(
SnippetMatchProto.newBuilder()
.setValuesIndex(0)
.setExactMatchPosition(0)
.setExactMatchBytes(20)
.setWindowPosition(0)