From c153efec4fc5d20f4055f918d0de9582f72626e7 Mon Sep 17 00:00:00 2001 From: Alexander Dorokhine Date: Fri, 12 Mar 2021 21:26:10 -0800 Subject: [PATCH] Update Framework from Jetpack. Included changes: * b7eb43a: Require a namespace across APIs. * 4e92597: Require databaseName when creating session. Bug: 180460765 Bug: 181364730 Test: Presubmit Change-Id: I22a0f4a2bd38d9b2e4e70258184800d281e579f1 --- apex/appsearch/framework/api/current.txt | 22 ++++--- .../android/app/appsearch/AppSearchEmail.java | 6 +- .../app/appsearch/GenericDocument.java | 59 ++++++++++++++++++- .../app/appsearch/GetByUriRequest.java | 27 ++++++++- .../app/appsearch/RemoveByUriRequest.java | 26 +++++++- .../app/appsearch/ReportUsageRequest.java | 26 +++++++- .../GenericDocumentToProtoConverter.java | 4 +- .../testing/external/AppSearchTestUtils.java | 5 +- .../appsearch/AppSearchSessionUnitTest.java | 2 +- .../external/app/AppSearchEmailTest.java | 3 +- .../external/app/GenericDocumentTest.java | 4 +- .../external/app/PutDocumentsRequestTest.java | 4 +- .../localstorage/AppSearchImplTest.java | 26 ++++---- .../GenericDocumentToProtoConverterTest.java | 8 +-- 14 files changed, 168 insertions(+), 54 deletions(-) diff --git a/apex/appsearch/framework/api/current.txt b/apex/appsearch/framework/api/current.txt index 9de6ed2c7663d..ced187b6e54f8 100644 --- a/apex/appsearch/framework/api/current.txt +++ b/apex/appsearch/framework/api/current.txt @@ -179,14 +179,15 @@ package android.app.appsearch { method public int getScore(); method public long getTtlMillis(); method @NonNull public String getUri(); - field public static final String DEFAULT_NAMESPACE = ""; + field @Deprecated public static final String DEFAULT_NAMESPACE = ""; } public static class GenericDocument.Builder { - ctor public GenericDocument.Builder(@NonNull String, @NonNull String); + ctor @Deprecated public GenericDocument.Builder(@NonNull String, @NonNull String); + ctor public GenericDocument.Builder(@NonNull String, @NonNull String, @NonNull String); method @NonNull public android.app.appsearch.GenericDocument build(); method @NonNull public BuilderType setCreationTimestampMillis(long); - method @NonNull public BuilderType setNamespace(@NonNull String); + method @Deprecated @NonNull public BuilderType setNamespace(@NonNull String); method @NonNull public BuilderType setPropertyBoolean(@NonNull String, @NonNull boolean...); method @NonNull public BuilderType setPropertyBytes(@NonNull String, @NonNull byte[]...); method @NonNull public BuilderType setPropertyDocument(@NonNull String, @NonNull android.app.appsearch.GenericDocument...); @@ -205,12 +206,13 @@ package android.app.appsearch { } public static final class GetByUriRequest.Builder { - ctor public GetByUriRequest.Builder(); + ctor @Deprecated public GetByUriRequest.Builder(); + ctor public GetByUriRequest.Builder(@NonNull String); method @NonNull public android.app.appsearch.GetByUriRequest.Builder addProjection(@NonNull String, @NonNull java.util.Collection); 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); method @NonNull public android.app.appsearch.GetByUriRequest build(); - method @NonNull public android.app.appsearch.GetByUriRequest.Builder setNamespace(@NonNull String); + method @Deprecated @NonNull public android.app.appsearch.GetByUriRequest.Builder setNamespace(@NonNull String); } public class GlobalSearchSession implements java.io.Closeable { @@ -241,11 +243,12 @@ package android.app.appsearch { } public static final class RemoveByUriRequest.Builder { - ctor public RemoveByUriRequest.Builder(); + ctor @Deprecated public RemoveByUriRequest.Builder(); + ctor public RemoveByUriRequest.Builder(@NonNull String); method @NonNull public android.app.appsearch.RemoveByUriRequest.Builder addUris(@NonNull java.lang.String...); method @NonNull public android.app.appsearch.RemoveByUriRequest.Builder addUris(@NonNull java.util.Collection); method @NonNull public android.app.appsearch.RemoveByUriRequest build(); - method @NonNull public android.app.appsearch.RemoveByUriRequest.Builder setNamespace(@NonNull String); + method @Deprecated @NonNull public android.app.appsearch.RemoveByUriRequest.Builder setNamespace(@NonNull String); } public final class ReportUsageRequest { @@ -255,9 +258,10 @@ package android.app.appsearch { } public static final class ReportUsageRequest.Builder { - ctor public ReportUsageRequest.Builder(); + ctor @Deprecated public ReportUsageRequest.Builder(); + ctor public ReportUsageRequest.Builder(@NonNull String); method @NonNull public android.app.appsearch.ReportUsageRequest build(); - method @NonNull public android.app.appsearch.ReportUsageRequest.Builder setNamespace(@NonNull String); + method @Deprecated @NonNull public android.app.appsearch.ReportUsageRequest.Builder setNamespace(@NonNull String); method @NonNull public android.app.appsearch.ReportUsageRequest.Builder setUri(@NonNull String); method @NonNull public android.app.appsearch.ReportUsageRequest.Builder setUsageTimeMillis(long); } diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchEmail.java b/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchEmail.java index d3949047ec5db..77740f88de7ac 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchEmail.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchEmail.java @@ -152,14 +152,14 @@ public class AppSearchEmail extends GenericDocument { /** The builder class for {@link AppSearchEmail}. */ public static class Builder extends GenericDocument.Builder { - /** * Creates a new {@link AppSearchEmail.Builder} * + * @param namespace The namespace of the Email. * @param uri The Uri of the Email. */ - public Builder(@NonNull String uri) { - super(uri, SCHEMA_TYPE); + public Builder(@NonNull String namespace, @NonNull String uri) { + super(namespace, uri, SCHEMA_TYPE); } /** Sets the from address of {@link AppSearchEmail} */ diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java index 72bb9f3d07c80..4ce95ea358f45 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java @@ -46,8 +46,14 @@ import java.util.Set; public class GenericDocument { private static final String TAG = "AppSearchGenericDocumen"; - /** The default empty namespace. */ - public static final String DEFAULT_NAMESPACE = ""; + /** + * The default empty namespace. + * + *

TODO(b/181887768): This exists only for dogfooder transition and must be removed. + * + * @deprecated This exists only for dogfooder transition and must be removed. + */ + @Deprecated public static final String DEFAULT_NAMESPACE = ""; /** The maximum number of elements in a repeatable field. */ private static final int MAX_REPEATED_PROPERTY_LENGTH = 100; @@ -141,7 +147,7 @@ public class GenericDocument { /** Returns the namespace of the {@link GenericDocument}. */ @NonNull public String getNamespace() { - return mBundle.getString(NAMESPACE_FIELD, DEFAULT_NAMESPACE); + return mBundle.getString(NAMESPACE_FIELD, /*defaultValue=*/ ""); } /** Returns the {@link AppSearchSchema} type of the {@link GenericDocument}. */ @@ -579,6 +585,9 @@ public class GenericDocument { * *

Once {@link #build} is called, the instance can no longer be used. * + *

TODO(b/181887768): This method exists only for dogfooder transition and must be + * removed. + * * @param uri the URI to set for the {@link GenericDocument}. * @param schemaType the {@link AppSearchSchema} type of the {@link GenericDocument}. The * provided {@code schemaType} must be defined using {@link AppSearchSession#setSchema} @@ -586,7 +595,10 @@ public class GenericDocument { * using {@link AppSearchSession#put}. Otherwise, the document will be rejected by * {@link AppSearchSession#put} with result code {@link * AppSearchResult#RESULT_NOT_FOUND}. + * @deprecated Please supply the namespace in {@link #Builder(String, String, String)} + * instead. This method exists only for dogfooder transition and must be removed. */ + @Deprecated @SuppressWarnings("unchecked") public Builder(@NonNull String uri, @NonNull String schemaType) { Preconditions.checkNotNull(uri); @@ -603,6 +615,41 @@ public class GenericDocument { mBundle.putBundle(PROPERTIES_FIELD, mProperties); } + /** + * Creates a new {@link GenericDocument.Builder}. + * + *

Once {@link #build} is called, the instance can no longer be used. + * + *

URIs are unique within a namespace. + * + *

The number of namespaces per app should be kept small for efficiency reasons. + * + * @param namespace the namespace to set for the {@link GenericDocument}. + * @param uri the URI to set for the {@link GenericDocument}. + * @param schemaType the {@link AppSearchSchema} type of the {@link GenericDocument}. The + * provided {@code schemaType} must be defined using {@link AppSearchSession#setSchema} + * prior to inserting a document of this {@code schemaType} into the AppSearch index + * using {@link AppSearchSession#put}. Otherwise, the document will be rejected by + * {@link AppSearchSession#put} with result code {@link + * AppSearchResult#RESULT_NOT_FOUND}. + */ + @SuppressWarnings("unchecked") + public Builder(@NonNull String namespace, @NonNull String uri, @NonNull String schemaType) { + Preconditions.checkNotNull(namespace); + Preconditions.checkNotNull(uri); + Preconditions.checkNotNull(schemaType); + mBuilderTypeInstance = (BuilderType) this; + mBundle.putString(GenericDocument.NAMESPACE_FIELD, namespace); + mBundle.putString(GenericDocument.URI_FIELD, uri); + mBundle.putString(GenericDocument.SCHEMA_TYPE_FIELD, schemaType); + // Set current timestamp for creation timestamp by default. + mBundle.putLong( + GenericDocument.CREATION_TIMESTAMP_MILLIS_FIELD, System.currentTimeMillis()); + mBundle.putLong(GenericDocument.TTL_MILLIS_FIELD, DEFAULT_TTL_MILLIS); + mBundle.putInt(GenericDocument.SCORE_FIELD, DEFAULT_SCORE); + mBundle.putBundle(PROPERTIES_FIELD, mProperties); + } + /** * Sets the app-defined namespace this document resides in. No special values are reserved * or understood by the infrastructure. @@ -611,8 +658,14 @@ public class GenericDocument { * *

The number of namespaces per app should be kept small for efficiency reasons. * + *

TODO(b/181887768): This method exists only for dogfooder transition and must be + * removed. + * * @throws IllegalStateException if the builder has already been used. + * @deprecated Please supply the namespace in {@link #Builder(String, String, String)} + * instead. This method exists only for dogfooder transition and must be removed. */ + @Deprecated @NonNull public BuilderType setNamespace(@NonNull String namespace) { Preconditions.checkState(!mBuilt, "Builder has already been used"); diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java b/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java index 17266f82b6034..6881a27d6846e 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/GetByUriRequest.java @@ -107,19 +107,40 @@ public final class GetByUriRequest { *

Once {@link #build} is called, the instance can no longer be used. */ public static final class Builder { - private String mNamespace = GenericDocument.DEFAULT_NAMESPACE; + private String mNamespace; private final Set mUris = new ArraySet<>(); private final Map> mProjectionTypePropertyPaths = new ArrayMap<>(); private boolean mBuilt = false; + /** + * TODO(b/181887768): This method exists only for dogfooder transition and must be removed. + * + * @deprecated Please supply the namespace in {@link #Builder(String)} instead. This method + * exists only for dogfooder transition and must be removed. + */ + @Deprecated + public Builder() { + mNamespace = GenericDocument.DEFAULT_NAMESPACE; + } + + /** Creates a {@link GetByUriRequest.Builder} instance. */ + public Builder(@NonNull String namespace) { + mNamespace = Preconditions.checkNotNull(namespace); + } + /** * Sets the namespace to retrieve documents for. * - *

If this is not called, the namespace defaults to {@link - * GenericDocument#DEFAULT_NAMESPACE}. + *

If this is not called, the namespace defaults to an empty string. + * + *

TODO(b/181887768): This method exists only for dogfooder transition and must be + * removed. * * @throws IllegalStateException if the builder has already been used. + * @deprecated Please supply the namespace in {@link #Builder(String)} instead. This method + * exists only for dogfooder transition and must */ + @Deprecated @NonNull public Builder setNamespace(@NonNull String namespace) { Preconditions.checkState(!mBuilt, "Builder has already been used"); diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java b/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java index 39b53b604abbd..455cf3a26b50f 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/RemoveByUriRequest.java @@ -59,17 +59,39 @@ public final class RemoveByUriRequest { *

Once {@link #build} is called, the instance can no longer be used. */ public static final class Builder { - private String mNamespace = GenericDocument.DEFAULT_NAMESPACE; + private String mNamespace; private final Set mUris = new ArraySet<>(); private boolean mBuilt = false; + /** + * TODO(b/181887768): This method exists only for dogfooder transition and must be removed. + * + * @deprecated Please supply the namespace in {@link #Builder(String)} instead. This method + * exists only for dogfooder transition and must be removed. + */ + @Deprecated + public Builder() { + mNamespace = GenericDocument.DEFAULT_NAMESPACE; + } + + /** Creates a {@link RemoveByUriRequest.Builder} instance. */ + public Builder(@NonNull String namespace) { + mNamespace = Preconditions.checkNotNull(namespace); + } + /** * Sets the namespace to remove documents for. * - *

If this is not set, it defaults to {@link GenericDocument#DEFAULT_NAMESPACE}. + *

If this is not set, it defaults to an empty string. + * + *

TODO(b/181887768): This method exists only for dogfooder transition and must be + * removed. * * @throws IllegalStateException if the builder has already been used. + * @deprecated Please supply the namespace in {@link #Builder(String)} instead. This method + * exists only for dogfooder transition and must */ + @Deprecated @NonNull public Builder setNamespace(@NonNull String namespace) { Preconditions.checkState(!mBuilt, "Builder has already been used"); diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/ReportUsageRequest.java b/apex/appsearch/framework/java/external/android/app/appsearch/ReportUsageRequest.java index 2bfcf28554305..2cd08c631006b 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/ReportUsageRequest.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/ReportUsageRequest.java @@ -62,18 +62,40 @@ public final class ReportUsageRequest { /** Builder for {@link ReportUsageRequest} objects. */ public static final class Builder { - private String mNamespace = GenericDocument.DEFAULT_NAMESPACE; + private String mNamespace; private String mUri; private Long mUsageTimeMillis; private boolean mBuilt = false; + /** + * TODO(b/181887768): This method exists only for dogfooder transition and must be removed. + * + * @deprecated Please supply the namespace in {@link #Builder(String)} instead. This method + * exists only for dogfooder transition and must be removed. + */ + @Deprecated + public Builder() { + mNamespace = GenericDocument.DEFAULT_NAMESPACE; + } + + /** Creates a {@link ReportUsageRequest.Builder} instance. */ + public Builder(@NonNull String namespace) { + mNamespace = Preconditions.checkNotNull(namespace); + } + /** * Sets which namespace the document being used belongs to. * - *

If this is not set, it defaults to {@link GenericDocument#DEFAULT_NAMESPACE}. + *

If this is not set, it defaults to an empty string. + * + *

TODO(b/181887768): This method exists only for dogfooder transition and must be + * removed. * * @throws IllegalStateException if the builder has already been used + * @deprecated Please supply the namespace in {@link #Builder(String)} instead. This method + * exists only for dogfooder transition and must */ + @Deprecated @NonNull public ReportUsageRequest.Builder setNamespace(@NonNull String namespace) { Preconditions.checkState(!mBuilt, "Builder has already been used"); diff --git a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverter.java b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverter.java index a2386eccc2568..d6b9da8275155 100644 --- a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverter.java +++ b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverter.java @@ -102,8 +102,8 @@ public final class GenericDocumentToProtoConverter { public static GenericDocument toGenericDocument(@NonNull DocumentProto proto) { Preconditions.checkNotNull(proto); GenericDocument.Builder documentBuilder = - new GenericDocument.Builder<>(proto.getUri(), proto.getSchema()) - .setNamespace(proto.getNamespace()) + new GenericDocument.Builder<>( + proto.getNamespace(), proto.getUri(), proto.getSchema()) .setScore(proto.getScore()) .setTtlMillis(proto.getTtlMs()) .setCreationTimestampMillis(proto.getCreationTimestampMs()); diff --git a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java index 28b1e9983517b..4a3c7a53d43e1 100644 --- a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java +++ b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchTestUtils.java @@ -47,10 +47,7 @@ public class AppSearchTestUtils { AppSearchBatchResult result = checkIsBatchResultSuccess( session.getByUri( - new GetByUriRequest.Builder() - .setNamespace(namespace) - .addUris(uris) - .build())); + new GetByUriRequest.Builder(namespace).addUris(uris).build())); assertThat(result.getSuccesses()).hasSize(uris.length); assertThat(result.getFailures()).isEmpty(); List list = new ArrayList<>(uris.length); diff --git a/core/tests/coretests/src/android/app/appsearch/AppSearchSessionUnitTest.java b/core/tests/coretests/src/android/app/appsearch/AppSearchSessionUnitTest.java index fe31b907f0776..7ef1d5e426cc4 100644 --- a/core/tests/coretests/src/android/app/appsearch/AppSearchSessionUnitTest.java +++ b/core/tests/coretests/src/android/app/appsearch/AppSearchSessionUnitTest.java @@ -61,7 +61,7 @@ public class AppSearchSessionUnitTest { public void testPutDocument_throwsNullException() throws Exception { // Create a document AppSearchEmail inEmail = - new AppSearchEmail.Builder("uri1") + new AppSearchEmail.Builder("namespace", "uri1") .setFrom("from@example.com") .setTo("to1@example.com", "to2@example.com") .setSubject("testPut example") diff --git a/core/tests/coretests/src/android/app/appsearch/external/app/AppSearchEmailTest.java b/core/tests/coretests/src/android/app/appsearch/external/app/AppSearchEmailTest.java index 119b70ab04398..ed53d5f39a392 100644 --- a/core/tests/coretests/src/android/app/appsearch/external/app/AppSearchEmailTest.java +++ b/core/tests/coretests/src/android/app/appsearch/external/app/AppSearchEmailTest.java @@ -25,7 +25,7 @@ public class AppSearchEmailTest { @Test public void testBuildEmailAndGetValue() { AppSearchEmail email = - new AppSearchEmail.Builder("uri") + new AppSearchEmail.Builder("namespace", "uri") .setFrom("FakeFromAddress") .setCc("CC1", "CC2") // Score and Property are mixed into the middle to make sure @@ -37,6 +37,7 @@ public class AppSearchEmailTest { .setBody("EmailBody") .build(); + assertThat(email.getNamespace()).isEqualTo("namespace"); assertThat(email.getUri()).isEqualTo("uri"); assertThat(email.getFrom()).isEqualTo("FakeFromAddress"); assertThat(email.getTo()).isNull(); diff --git a/core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java b/core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java index af77b6c598b18..b884ddcd1420d 100644 --- a/core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java +++ b/core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java @@ -27,13 +27,13 @@ public class GenericDocumentTest { @Test public void testRecreateFromParcel() { GenericDocument inDoc = - new GenericDocument.Builder<>("uri1", "schema1") + new GenericDocument.Builder<>("namespace", "uri1", "schema1") .setScore(42) .setPropertyString("propString", "Hello") .setPropertyBytes("propBytes", new byte[][] {{1, 2}}) .setPropertyDocument( "propDocument", - new GenericDocument.Builder<>("uri2", "schema2") + new GenericDocument.Builder<>("namespace", "uri2", "schema2") .setPropertyString("propString", "Goodbye") .setPropertyBytes("propBytes", new byte[][] {{3, 4}}) .build()) diff --git a/core/tests/coretests/src/android/app/appsearch/external/app/PutDocumentsRequestTest.java b/core/tests/coretests/src/android/app/appsearch/external/app/PutDocumentsRequestTest.java index 7d175d9b31e51..76372141ca042 100644 --- a/core/tests/coretests/src/android/app/appsearch/external/app/PutDocumentsRequestTest.java +++ b/core/tests/coretests/src/android/app/appsearch/external/app/PutDocumentsRequestTest.java @@ -31,8 +31,8 @@ public class PutDocumentsRequestTest { public void addGenericDocument_byCollection() { Set emails = ImmutableSet.of( - new AppSearchEmail.Builder("test1").build(), - new AppSearchEmail.Builder("test2").build()); + new AppSearchEmail.Builder("namespace", "test1").build(), + new AppSearchEmail.Builder("namespace", "test2").build()); PutDocumentsRequest request = new PutDocumentsRequest.Builder().addGenericDocuments(emails).build(); diff --git a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java index 90ce6e2ac168a..c84c1cf8c8f18 100644 --- a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java +++ b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchImplTest.java @@ -415,9 +415,7 @@ public class AppSearchImplTest { + AppSearchImpl.CHECK_OPTIMIZE_INTERVAL; i++) { GenericDocument document = - new GenericDocument.Builder<>("uri" + i, "type") - .setNamespace("namespace") - .build(); + new GenericDocument.Builder<>("namespace", "uri" + i, "type").build(); mAppSearchImpl.putDocument("package", "database", document); } @@ -477,7 +475,7 @@ public class AppSearchImplTest { // Insert document GenericDocument document = - new GenericDocument.Builder<>("uri", "type").setNamespace("namespace").build(); + new GenericDocument.Builder<>("namespace", "uri", "type").build(); mAppSearchImpl.putDocument("package", "database", document); // Rewrite SearchSpec @@ -517,11 +515,11 @@ public class AppSearchImplTest { // Insert documents GenericDocument document1 = - new GenericDocument.Builder<>("uri", "typeA").setNamespace("namespace").build(); + new GenericDocument.Builder<>("namespace", "uri", "typeA").build(); mAppSearchImpl.putDocument("package", "database1", document1); GenericDocument document2 = - new GenericDocument.Builder<>("uri", "typeB").setNamespace("namespace").build(); + new GenericDocument.Builder<>("namespace", "uri", "typeB").build(); mAppSearchImpl.putDocument("package", "database2", document2); // Rewrite SearchSpec @@ -561,7 +559,7 @@ public class AppSearchImplTest { // Insert document GenericDocument document = - new GenericDocument.Builder<>("uri", "type").setNamespace("namespace").build(); + new GenericDocument.Builder<>("namespace", "uri", "type").build(); mAppSearchImpl.putDocument("package", "database", document); // If 'allowedPrefixedSchemas' is empty, this returns false since there's nothing to @@ -614,7 +612,7 @@ public class AppSearchImplTest { // Insert package1 document GenericDocument document = - new GenericDocument.Builder<>("uri", "schema1").setNamespace("namespace").build(); + new GenericDocument.Builder<>("namespace", "uri", "schema1").build(); mAppSearchImpl.putDocument("package1", "database1", document); // No query filters specified, package2 shouldn't be able to query for package1's documents. @@ -625,8 +623,7 @@ public class AppSearchImplTest { assertThat(searchResultPage.getResults()).isEmpty(); // Insert package2 document - document = - new GenericDocument.Builder<>("uri", "schema2").setNamespace("namespace").build(); + document = new GenericDocument.Builder<>("namespace", "uri", "schema2").build(); mAppSearchImpl.putDocument("package2", "database2", document); // No query filters specified. package2 should only get its own documents back. @@ -665,7 +662,7 @@ public class AppSearchImplTest { // Insert package1 document GenericDocument document = - new GenericDocument.Builder<>("uri", "schema1").setNamespace("namespace").build(); + new GenericDocument.Builder<>("namespace", "uri", "schema1").build(); mAppSearchImpl.putDocument("package1", "database1", document); // "package1" filter specified, but package2 shouldn't be able to query for package1's @@ -680,8 +677,7 @@ public class AppSearchImplTest { assertThat(searchResultPage.getResults()).isEmpty(); // Insert package2 document - document = - new GenericDocument.Builder<>("uri", "schema2").setNamespace("namespace").build(); + document = new GenericDocument.Builder<>("namespace", "uri", "schema2").build(); mAppSearchImpl.putDocument("package2", "database2", document); // "package2" filter specified, package2 should only get its own documents back. @@ -1128,9 +1124,7 @@ public class AppSearchImplTest { appSearchImpl.putDocument( "package", "database", - new GenericDocument.Builder<>("uri", "type") - .setNamespace("namespace") - .build()); + new GenericDocument.Builder<>("namespace", "uri", "type").build()); }); expectThrows( diff --git a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverterTest.java b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverterTest.java index 194be3761903b..70e1e05174ef3 100644 --- a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverterTest.java +++ b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/converter/GenericDocumentToProtoConverterTest.java @@ -36,23 +36,23 @@ public class GenericDocumentToProtoConverterTest { private static final byte[] BYTE_ARRAY_2 = new byte[] {(byte) 4, (byte) 5, (byte) 6, (byte) 7}; private static final GenericDocument DOCUMENT_PROPERTIES_1 = new GenericDocument.Builder>( - "sDocumentProperties1", "sDocumentPropertiesSchemaType1") + "namespace", "sDocumentProperties1", "sDocumentPropertiesSchemaType1") .setCreationTimestampMillis(12345L) .build(); private static final GenericDocument DOCUMENT_PROPERTIES_2 = new GenericDocument.Builder>( - "sDocumentProperties2", "sDocumentPropertiesSchemaType2") + "namespace", "sDocumentProperties2", "sDocumentPropertiesSchemaType2") .setCreationTimestampMillis(6789L) .build(); @Test public void testDocumentProtoConvert() { GenericDocument document = - new GenericDocument.Builder>("uri1", "schemaType1") + new GenericDocument.Builder>( + "namespace", "uri1", "schemaType1") .setCreationTimestampMillis(5L) .setScore(1) .setTtlMillis(1L) - .setNamespace("namespace") .setPropertyLong("longKey1", 1L) .setPropertyDouble("doubleKey1", 1.0) .setPropertyBoolean("booleanKey1", true)