From 45bb21c98d59dfd308b8192c66d9699ec13f6567 Mon Sep 17 00:00:00 2001 From: Alexander Dorokhine Date: Thu, 29 Apr 2021 18:00:32 -0700 Subject: [PATCH] Update Framework from Jetpack. Included changes: * 4c1b251: Sync AppSearch with google3 update ag/14342999 (8f8b43) * cdf1913: Add a GenericDocument#toBuilder API. * 64f80f3: Improve snippeting and matching per API feedback. * 23dd35c: Move AppSearchEmail out of the prod tree into the test utils. Bug: 171882200 Bug: 186520196 Bug: 186717514 Test: Presubmit Change-Id: I9d8e1fb87e6e74c57a38f3a27cdd04a1a3ccf90b --- apex/appsearch/framework/api/current.txt | 6 +- .../app/appsearch/GenericDocument.java | 99 ++++++++++++++++++- .../android/app/appsearch/SearchResult.java | 39 +++++--- .../android/app/appsearch/SearchSpec.java | 18 +++- .../app/appsearch/util/BundleUtil.java | 24 +++++ .../SearchResultToProtoConverter.java | 2 +- apex/appsearch/synced_jetpack_changeid.txt | 2 +- apex/appsearch/testing/Android.bp | 1 + .../testing/AppSearchSessionShimImpl.java | 2 +- .../testing/external}/AppSearchEmail.java | 24 ++--- .../external/AppSearchSessionShim.java | 5 +- core/tests/coretests/Android.bp | 5 +- .../appsearch/AppSearchSessionUnitTest.java | 2 + .../external/app/AppSearchEmailTest.java | 2 + .../external/app/PutDocumentsRequestTest.java | 2 + .../external/util/BundleUtilTest.java | 11 +++ .../localstorage/AppSearchLoggerTest.java | 2 +- .../localstorage/converter/SnippetTest.java | 12 +-- 18 files changed, 212 insertions(+), 46 deletions(-) rename apex/appsearch/{framework/java/external/android/app/appsearch => testing/java/com/android/server/appsearch/testing/external}/AppSearchEmail.java (92%) diff --git a/apex/appsearch/framework/api/current.txt b/apex/appsearch/framework/api/current.txt index 7441b0f1e22b1..4dff436770283 100644 --- a/apex/appsearch/framework/api/current.txt +++ b/apex/appsearch/framework/api/current.txt @@ -289,14 +289,16 @@ package android.app.appsearch { public final class SearchResult { method @NonNull public String getDatabaseName(); method @NonNull public android.app.appsearch.GenericDocument getGenericDocument(); - method @NonNull public java.util.List getMatches(); + method @NonNull public java.util.List getMatchInfos(); + method @Deprecated @NonNull public java.util.List getMatches(); method @NonNull public String getPackageName(); method public double getRankingSignal(); } public static final class SearchResult.Builder { ctor public SearchResult.Builder(@NonNull String, @NonNull String); - method @NonNull public android.app.appsearch.SearchResult.Builder addMatch(@NonNull android.app.appsearch.SearchResult.MatchInfo); + method @Deprecated @NonNull public android.app.appsearch.SearchResult.Builder addMatch(@NonNull android.app.appsearch.SearchResult.MatchInfo); + method @NonNull public android.app.appsearch.SearchResult.Builder addMatchInfo(@NonNull android.app.appsearch.SearchResult.MatchInfo); method @NonNull public android.app.appsearch.SearchResult build(); method @NonNull public android.app.appsearch.SearchResult.Builder setGenericDocument(@NonNull android.app.appsearch.GenericDocument); method @NonNull public android.app.appsearch.SearchResult.Builder setRankingSignal(double); 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 85018ad6e9dbf..2e427497e16d6 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java @@ -843,6 +843,20 @@ public class GenericDocument { } } + /** + * Copies the contents of this {@link GenericDocument} into a new {@link + * GenericDocument.Builder}. + * + *

The returned builder is a deep copy whose data is separate from this document. + * + * @hide + */ + @NonNull + public GenericDocument.Builder> toBuilder() { + Bundle clonedBundle = BundleUtil.deepCopy(mBundle); + return new GenericDocument.Builder<>(clonedBundle); + } + @Override public boolean equals(@Nullable Object other) { if (this == other) { @@ -936,8 +950,8 @@ public class GenericDocument { @SuppressLint("StaticFinalBuilder") public static class Builder { - private final Bundle mProperties = new Bundle(); - private final Bundle mBundle = new Bundle(); + private final Bundle mBundle; + private final Bundle mProperties; private final BuilderType mBuilderTypeInstance; private boolean mBuilt = false; @@ -964,6 +978,8 @@ public class GenericDocument { Objects.requireNonNull(namespace); Objects.requireNonNull(id); Objects.requireNonNull(schemaType); + + mBundle = new Bundle(); mBuilderTypeInstance = (BuilderType) this; mBundle.putString(GenericDocument.NAMESPACE_FIELD, namespace); mBundle.putString(GenericDocument.ID_FIELD, id); @@ -973,9 +989,72 @@ public class GenericDocument { GenericDocument.CREATION_TIMESTAMP_MILLIS_FIELD, System.currentTimeMillis()); mBundle.putLong(GenericDocument.TTL_MILLIS_FIELD, DEFAULT_TTL_MILLIS); mBundle.putInt(GenericDocument.SCORE_FIELD, DEFAULT_SCORE); + + mProperties = new Bundle(); mBundle.putBundle(PROPERTIES_FIELD, mProperties); } + /** Creates a new {@link GenericDocument.Builder} from the given Bundle. */ + @SuppressWarnings("unchecked") + Builder(@NonNull Bundle bundle) { + mBundle = Objects.requireNonNull(bundle); + mProperties = mBundle.getBundle(PROPERTIES_FIELD); + mBuilderTypeInstance = (BuilderType) this; + } + + /** + * Sets the app-defined namespace this document resides in, changing the value provided in + * the constructor. No special values are reserved or understood by the infrastructure. + * + *

Document IDs are unique within a namespace. + * + *

The number of namespaces per app should be kept small for efficiency reasons. + * + * @throws IllegalStateException if the builder has already been used. + * @hide + */ + @NonNull + public BuilderType setNamespace(@NonNull String namespace) { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + Objects.requireNonNull(namespace); + mBundle.putString(GenericDocument.NAMESPACE_FIELD, namespace); + return mBuilderTypeInstance; + } + + /** + * Sets the ID of this document, changing the value provided in the constructor. No special + * values are reserved or understood by the infrastructure. + * + *

Document IDs are unique within a namespace. + * + * @throws IllegalStateException if the builder has already been used. + * @hide + */ + @NonNull + public BuilderType setId(@NonNull String id) { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + Objects.requireNonNull(id); + mBundle.putString(GenericDocument.ID_FIELD, id); + return mBuilderTypeInstance; + } + + /** + * Sets the schema type of this document, changing the value provided in the constructor. + * + *

To successfully index a document, the schema type must match the name of an {@link + * AppSearchSchema} object previously provided to {@link AppSearchSession#setSchema}. + * + * @throws IllegalStateException if the builder has already been used. + * @hide + */ + @NonNull + public BuilderType setSchemaType(@NonNull String schemaType) { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + Objects.requireNonNull(schemaType); + mBundle.putString(GenericDocument.SCHEMA_TYPE_FIELD, schemaType); + return mBuilderTypeInstance; + } + /** * Sets the score of the {@link GenericDocument}. * @@ -1156,6 +1235,22 @@ public class GenericDocument { return mBuilderTypeInstance; } + /** + * Clears the value for the property with the given name. + * + *

Note that this method does not support property paths. + * + * @param name The name of the property to clear. + * @hide + */ + @NonNull + public BuilderType clearProperty(@NonNull String name) { + Preconditions.checkState(!mBuilt, "Builder has already been used"); + Objects.requireNonNull(name); + mProperties.remove(name); + return mBuilderTypeInstance; + } + private void putInPropertyBundle(@NonNull String name, @NonNull String[] values) throws IllegalArgumentException { validateRepeatedPropertyLength(name, values.length); diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/SearchResult.java b/apex/appsearch/framework/java/external/android/app/appsearch/SearchResult.java index 4fc654f7e5d25..b648071a93c17 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/SearchResult.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/SearchResult.java @@ -34,7 +34,7 @@ import java.util.Objects; *

    *
  • The document which matched, using {@link #getGenericDocument} *
  • Information about which properties in the document matched, and "snippet" information - * containing textual summaries of the document's matches, using {@link #getMatches} + * containing textual summaries of the document's matches, using {@link #getMatchInfos} *
* *

"Snippet" refers to a substring of text from the content of document that is returned as a @@ -44,7 +44,7 @@ import java.util.Objects; */ public final class SearchResult { static final String DOCUMENT_FIELD = "document"; - static final String MATCHES_FIELD = "matches"; + static final String MATCH_INFOS_FIELD = "matchInfos"; static final String PACKAGE_NAME_FIELD = "packageName"; static final String DATABASE_NAME_FIELD = "databaseName"; static final String RANKING_SIGNAL_FIELD = "rankingSignal"; @@ -55,7 +55,7 @@ public final class SearchResult { @Nullable private GenericDocument mDocument; /** Cache of the inflated matches. Comes from inflating mMatchBundles at first use. */ - @Nullable private List mMatches; + @Nullable private List mMatchInfos; /** @hide */ public SearchResult(@NonNull Bundle bundle) { @@ -82,8 +82,16 @@ public final class SearchResult { return mDocument; } + /** @deprecated This method exists only for dogfooder transition and must be removed. */ + @Deprecated + @NonNull + public List getMatches() { + return getMatchInfos(); + } + /** - * Contains a list of Snippets that matched the request. + * Returns a list of {@link MatchInfo}s providing information about how the document in {@link + * #getGenericDocument} matched the query. * * @return List of matches based on {@link SearchSpec}. If snippeting is disabled using {@link * SearchSpec.Builder#setSnippetCount} or {@link @@ -91,17 +99,17 @@ public final class SearchResult { * method returns an empty list. */ @NonNull - public List getMatches() { - if (mMatches == null) { + public List getMatchInfos() { + if (mMatchInfos == null) { List matchBundles = - Objects.requireNonNull(mBundle.getParcelableArrayList(MATCHES_FIELD)); - mMatches = new ArrayList<>(matchBundles.size()); + Objects.requireNonNull(mBundle.getParcelableArrayList(MATCH_INFOS_FIELD)); + mMatchInfos = new ArrayList<>(matchBundles.size()); for (int i = 0; i < matchBundles.size(); i++) { MatchInfo matchInfo = new MatchInfo(matchBundles.get(i), getGenericDocument()); - mMatches.add(matchInfo); + mMatchInfos.add(matchInfo); } } - return mMatches; + return mMatchInfos; } /** @@ -184,9 +192,16 @@ public final class SearchResult { return this; } - /** Adds another match to this SearchResult. */ + /** @deprecated this method exists only for dogfooder transition and must be removed */ + @Deprecated @NonNull public Builder addMatch(@NonNull MatchInfo matchInfo) { + return addMatchInfo(matchInfo); + } + + /** Adds another match to this SearchResult. */ + @NonNull + public Builder addMatchInfo(@NonNull MatchInfo matchInfo) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkState( matchInfo.mDocument == null, @@ -212,7 +227,7 @@ public final class SearchResult { @NonNull public SearchResult build() { Preconditions.checkState(!mBuilt, "Builder has already been used"); - mBundle.putParcelableArrayList(MATCHES_FIELD, mMatchInfos); + mBundle.putParcelableArrayList(MATCH_INFOS_FIELD, mMatchInfos); mBuilt = true; return new SearchResult(mBundle); } diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/SearchSpec.java b/apex/appsearch/framework/java/external/android/app/appsearch/SearchSpec.java index 20e5b9da8d53b..1c57c75307833 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/SearchSpec.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/SearchSpec.java @@ -323,6 +323,7 @@ public final class SearchSpec { mBundle = new Bundle(); mBundle.putInt(NUM_PER_PAGE_FIELD, DEFAULT_NUM_PER_PAGE); mBundle.putInt(TERM_MATCH_TYPE_FIELD, TERM_MATCH_PREFIX); + mBundle.putInt(SNIPPET_COUNT_PER_PROPERTY_FIELD, MAX_SNIPPET_PER_PROPERTY_COUNT); } /** @@ -471,8 +472,11 @@ public final class SearchSpec { * Only the first {@code snippetCount} documents based on the ranking strategy will have * snippet information provided. * - *

If set to 0 (default), snippeting is disabled and {@link SearchResult#getMatches} will - * return {@code null} for that result. + *

The list returned from {@link SearchResult#getMatchInfos} will contain at most this + * many entries. + * + *

If set to 0 (default), snippeting is disabled and the list returned from {@link + * SearchResult#getMatchInfos} will be empty. */ @NonNull public SearchSpec.Builder setSnippetCount( @@ -485,10 +489,14 @@ public final class SearchSpec { /** * Sets {@code snippetCountPerProperty}. Only the first {@code snippetCountPerProperty} - * snippets for each property of {@link GenericDocument} will contain snippet information. + * snippets for each property of each {@link GenericDocument} will contain snippet + * information. * - *

If set to 0, snippeting is disabled and {@link SearchResult#getMatches} will return - * {@code null} for that result. + *

If set to 0, snippeting is disabled and the list returned from {@link + * SearchResult#getMatchInfos} will be empty. + * + *

The default behavior is to snippet all matches a property contains, up to the maximum + * value of 10,000. */ @NonNull public SearchSpec.Builder setSnippetCountPerProperty( diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/util/BundleUtil.java b/apex/appsearch/framework/java/external/android/app/appsearch/util/BundleUtil.java index 14dd472c9b9cc..e77043f3867cd 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/util/BundleUtil.java +++ b/apex/appsearch/framework/java/external/android/app/appsearch/util/BundleUtil.java @@ -16,8 +16,10 @@ package android.app.appsearch.util; +import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Bundle; +import android.os.Parcel; import android.util.SparseArray; import java.util.ArrayList; @@ -224,4 +226,26 @@ public final class BundleUtil { } return Arrays.hashCode(hashCodes); } + + /** + * Deeply clones a Bundle. + * + *

Values which are Bundles, Lists or Arrays are deeply copied themselves. + */ + @NonNull + public static Bundle deepCopy(@NonNull Bundle bundle) { + // Write bundle to bytes + Parcel parcel = Parcel.obtain(); + try { + parcel.writeBundle(bundle); + byte[] serializedMessage = parcel.marshall(); + + // Read bundle from bytes + parcel.unmarshall(serializedMessage, 0, serializedMessage.length); + parcel.setDataPosition(0); + return parcel.readBundle(); + } finally { + parcel.recycle(); + } + } } diff --git a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SearchResultToProtoConverter.java b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SearchResultToProtoConverter.java index 84220d72cbab2..ecc774c289ed6 100644 --- a/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SearchResultToProtoConverter.java +++ b/apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/converter/SearchResultToProtoConverter.java @@ -116,7 +116,7 @@ public class SearchResultToProtoConverter { for (int j = 0; j < entry.getSnippetMatchesCount(); j++) { SearchResult.MatchInfo matchInfo = toMatchInfo(entry.getSnippetMatches(j), entry.getPropertyName()); - builder.addMatch(matchInfo); + builder.addMatchInfo(matchInfo); } } } diff --git a/apex/appsearch/synced_jetpack_changeid.txt b/apex/appsearch/synced_jetpack_changeid.txt index 10bba13a8e2ff..277740f339c53 100644 --- a/apex/appsearch/synced_jetpack_changeid.txt +++ b/apex/appsearch/synced_jetpack_changeid.txt @@ -1 +1 @@ -I19dac52031c47099f621eced9f148931f1021f25 +Ic6be29e84e7c6f31cdae37973850bb3395920326 diff --git a/apex/appsearch/testing/Android.bp b/apex/appsearch/testing/Android.bp index 2518394d55d66..ec649410872fb 100644 --- a/apex/appsearch/testing/Android.bp +++ b/apex/appsearch/testing/Android.bp @@ -31,6 +31,7 @@ java_library { "truth-prebuilt", ], visibility: [ + "//frameworks/base/core/tests/coretests", "//cts/hostsidetests/appsearch", "//cts/tests/appsearch", "//vendor:__subpackages__", diff --git a/apex/appsearch/testing/java/com/android/server/appsearch/testing/AppSearchSessionShimImpl.java b/apex/appsearch/testing/java/com/android/server/appsearch/testing/AppSearchSessionShimImpl.java index 930cd60beb58f..941cea9bc97a9 100644 --- a/apex/appsearch/testing/java/com/android/server/appsearch/testing/AppSearchSessionShimImpl.java +++ b/apex/appsearch/testing/java/com/android/server/appsearch/testing/AppSearchSessionShimImpl.java @@ -179,7 +179,7 @@ public class AppSearchSessionShimImpl implements AppSearchSessionShim { @Override @NonNull - public ListenableFuture maybeFlush() { + public ListenableFuture requestFlush() { SettableFuture> future = SettableFuture.create(); // The data in platform will be flushed by scheduled task. AppSearchSession won't do // anything extra flush. diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchEmail.java b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchEmail.java similarity index 92% rename from apex/appsearch/framework/java/external/android/app/appsearch/AppSearchEmail.java rename to apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchEmail.java index d99c73f8f64bf..845274d1f8440 100644 --- a/apex/appsearch/framework/java/external/android/app/appsearch/AppSearchEmail.java +++ b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchEmail.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 The Android Open Source Project + * Copyright 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,19 @@ * limitations under the License. */ -package android.app.appsearch; +package com.android.server.appsearch.testing; import android.annotation.NonNull; import android.annotation.Nullable; +import android.app.appsearch.AppSearchSchema; import android.app.appsearch.AppSearchSchema.PropertyConfig; import android.app.appsearch.AppSearchSchema.StringPropertyConfig; +import android.app.appsearch.GenericDocument; /** * Encapsulates a {@link GenericDocument} that represent an email. * *

This class is a higher level implement of {@link GenericDocument}. - * - * @hide */ public class AppSearchEmail extends GenericDocument { /** The name of the schema type for {@link AppSearchEmail} documents. */ @@ -151,9 +151,9 @@ public class AppSearchEmail extends GenericDocument { } /** The builder class for {@link AppSearchEmail}. */ - public static class Builder extends GenericDocument.Builder { + public static class Builder extends GenericDocument.Builder { /** - * Creates a new {@link AppSearchEmail.Builder} + * Creates a new {@link Builder} * * @param namespace The namespace of the Email. * @param id The ID of the Email. @@ -164,42 +164,42 @@ public class AppSearchEmail extends GenericDocument { /** Sets the from address of {@link AppSearchEmail} */ @NonNull - public AppSearchEmail.Builder setFrom(@NonNull String from) { + public Builder setFrom(@NonNull String from) { setPropertyString(KEY_FROM, from); return this; } /** Sets the destination address of {@link AppSearchEmail} */ @NonNull - public AppSearchEmail.Builder setTo(@NonNull String... to) { + public Builder setTo(@NonNull String... to) { setPropertyString(KEY_TO, to); return this; } /** Sets the CC list of {@link AppSearchEmail} */ @NonNull - public AppSearchEmail.Builder setCc(@NonNull String... cc) { + public Builder setCc(@NonNull String... cc) { setPropertyString(KEY_CC, cc); return this; } /** Sets the BCC list of {@link AppSearchEmail} */ @NonNull - public AppSearchEmail.Builder setBcc(@NonNull String... bcc) { + public Builder setBcc(@NonNull String... bcc) { setPropertyString(KEY_BCC, bcc); return this; } /** Sets the subject of {@link AppSearchEmail} */ @NonNull - public AppSearchEmail.Builder setSubject(@NonNull String subject) { + public Builder setSubject(@NonNull String subject) { setPropertyString(KEY_SUBJECT, subject); return this; } /** Sets the body of {@link AppSearchEmail} */ @NonNull - public AppSearchEmail.Builder setBody(@NonNull String body) { + public Builder setBody(@NonNull String body) { setPropertyString(KEY_BODY, body); return this; } diff --git a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java index 345b059d037c2..a70d9b5facc32 100644 --- a/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java +++ b/apex/appsearch/testing/java/com/android/server/appsearch/testing/external/AppSearchSessionShim.java @@ -240,13 +240,16 @@ public interface AppSearchSessionShim extends Closeable { /** * Flush all schema and document updates, additions, and deletes to disk if possible. * + *

The request is not guaranteed to be handled and may be ignored by some implementations of + * AppSearchSessionShim. + * * @return The pending result of performing this operation. {@link * android.app.appsearch.exceptions.AppSearchException} with {@link * AppSearchResult#RESULT_INTERNAL_ERROR} will be set to the future if we hit error when * save to disk. */ @NonNull - ListenableFuture maybeFlush(); + ListenableFuture requestFlush(); /** * Closes the {@link AppSearchSessionShim} to persist all schema and document updates, diff --git a/core/tests/coretests/Android.bp b/core/tests/coretests/Android.bp index e1d44dc9a3cf9..415b1f27b5bb5 100644 --- a/core/tests/coretests/Android.bp +++ b/core/tests/coretests/Android.bp @@ -52,7 +52,8 @@ android_test { "truth-prebuilt", "print-test-util-lib", "testng", - "servicestests-utils" + "servicestests-utils", + "AppSearchTestUtils", ], libs: [ @@ -66,7 +67,7 @@ android_test { "framework-res", ], jni_libs: [ - "libpowermanagertest_jni", + "libpowermanagertest_jni", ], platform_apis: true, diff --git a/core/tests/coretests/src/android/app/appsearch/AppSearchSessionUnitTest.java b/core/tests/coretests/src/android/app/appsearch/AppSearchSessionUnitTest.java index 3d18337ab257b..d51004c085857 100644 --- a/core/tests/coretests/src/android/app/appsearch/AppSearchSessionUnitTest.java +++ b/core/tests/coretests/src/android/app/appsearch/AppSearchSessionUnitTest.java @@ -25,6 +25,8 @@ import android.content.Context; import androidx.test.core.app.ApplicationProvider; +import com.android.server.appsearch.testing.AppSearchEmail; + import org.junit.Before; import org.junit.Test; 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 3989ec7c95d68..29b0228c93b3d 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 @@ -18,6 +18,8 @@ package android.app.appsearch; import static com.google.common.truth.Truth.assertThat; +import com.android.server.appsearch.testing.AppSearchEmail; + import org.junit.Test; public class AppSearchEmailTest { 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 a1f7986f62df4..6fad4b8dcdac8 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 @@ -19,6 +19,8 @@ package android.app.appsearch; import static com.google.common.truth.Truth.assertThat; +import com.android.server.appsearch.testing.AppSearchEmail; + import com.google.common.collect.ImmutableSet; import org.junit.Test; diff --git a/core/tests/coretests/src/android/app/appsearch/external/util/BundleUtilTest.java b/core/tests/coretests/src/android/app/appsearch/external/util/BundleUtilTest.java index ece37f8054cf8..680ce52be4d64 100644 --- a/core/tests/coretests/src/android/app/appsearch/external/util/BundleUtilTest.java +++ b/core/tests/coretests/src/android/app/appsearch/external/util/BundleUtilTest.java @@ -213,6 +213,17 @@ public class BundleUtilTest { .isNotEqualTo(BundleUtil.deepHashCode(inputs[1])); } + @Test + public void testDeepCopy() { + Bundle input = createThoroughBundle(); + Bundle output = BundleUtil.deepCopy(input); + assertThat(input).isNotSameInstanceAs(output); + assertThat(BundleUtil.deepEquals(input, output)).isTrue(); + + output.getIntegerArrayList("integerArrayList").add(5); + assertThat(BundleUtil.deepEquals(input, output)).isFalse(); + } + private static Bundle createThoroughBundle() { Bundle toy1 = new Bundle(); toy1.putString("a", "a"); diff --git a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchLoggerTest.java b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchLoggerTest.java index 5989bb65bd393..2aad275ba62e6 100644 --- a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchLoggerTest.java +++ b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/AppSearchLoggerTest.java @@ -102,7 +102,7 @@ public class AppSearchLoggerTest { int nativeIndexRestorationCause = InitializeStatsProto.RecoveryCause.INCONSISTENT_WITH_GROUND_TRUTH_VALUE; int nativeSchemaStoreRecoveryCause = - InitializeStatsProto.RecoveryCause.TOTAL_CHECKSUM_MISMATCH_VALUE; + InitializeStatsProto.RecoveryCause.SCHEMA_CHANGES_OUT_OF_SYNC_VALUE; int nativeDocumentStoreRecoveryLatencyMillis = 7; int nativeIndexRestorationLatencyMillis = 8; int nativeSchemaStoreRecoveryLatencyMillis = 9; diff --git a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/converter/SnippetTest.java b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/converter/SnippetTest.java index d0ce31720fe3b..8fe1139a771de 100644 --- a/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/converter/SnippetTest.java +++ b/services/tests/servicestests/src/com/android/server/appsearch/external/localstorage/converter/SnippetTest.java @@ -96,7 +96,7 @@ public class SnippetTest { Collections.singletonList(DATABASE_NAME), SCHEMA_MAP); assertThat(searchResultPage.getResults()).hasSize(1); - SearchResult.MatchInfo match = searchResultPage.getResults().get(0).getMatches().get(0); + SearchResult.MatchInfo match = searchResultPage.getResults().get(0).getMatchInfos().get(0); assertThat(match.getPropertyPath()).isEqualTo(propertyKeyString); assertThat(match.getFullText()).isEqualTo(propertyValueString); assertThat(match.getExactMatch()).isEqualTo(exactMatch); @@ -142,7 +142,7 @@ public class SnippetTest { Collections.singletonList(DATABASE_NAME), SCHEMA_MAP); assertThat(searchResultPage.getResults()).hasSize(1); - assertThat(searchResultPage.getResults().get(0).getMatches()).isEmpty(); + assertThat(searchResultPage.getResults().get(0).getMatchInfos()).isEmpty(); } @Test @@ -198,7 +198,7 @@ public class SnippetTest { Collections.singletonList(DATABASE_NAME), SCHEMA_MAP); assertThat(searchResultPage.getResults()).hasSize(1); - SearchResult.MatchInfo match1 = searchResultPage.getResults().get(0).getMatches().get(0); + SearchResult.MatchInfo match1 = searchResultPage.getResults().get(0).getMatchInfos().get(0); assertThat(match1.getPropertyPath()).isEqualTo("senderName"); assertThat(match1.getFullText()).isEqualTo("Test Name Jr."); assertThat(match1.getExactMatchRange()) @@ -208,7 +208,7 @@ public class SnippetTest { .isEqualTo(new SearchResult.MatchRange(/*lower=*/ 0, /*upper=*/ 9)); assertThat(match1.getSnippet()).isEqualTo("Test Name"); - SearchResult.MatchInfo match2 = searchResultPage.getResults().get(0).getMatches().get(1); + SearchResult.MatchInfo match2 = searchResultPage.getResults().get(0).getMatchInfos().get(1); assertThat(match2.getPropertyPath()).isEqualTo("senderEmail"); assertThat(match2.getFullText()).isEqualTo("TestNameJr@gmail.com"); assertThat(match2.getExactMatchRange()) @@ -281,7 +281,7 @@ public class SnippetTest { Collections.singletonList(DATABASE_NAME), SCHEMA_MAP); assertThat(searchResultPage.getResults()).hasSize(1); - SearchResult.MatchInfo match1 = searchResultPage.getResults().get(0).getMatches().get(0); + SearchResult.MatchInfo match1 = searchResultPage.getResults().get(0).getMatchInfos().get(0); assertThat(match1.getPropertyPath()).isEqualTo("sender.name"); assertThat(match1.getFullText()).isEqualTo("Test Name Jr."); assertThat(match1.getExactMatchRange()) @@ -291,7 +291,7 @@ public class SnippetTest { .isEqualTo(new SearchResult.MatchRange(/*lower=*/ 0, /*upper=*/ 9)); assertThat(match1.getSnippet()).isEqualTo("Test Name"); - SearchResult.MatchInfo match2 = searchResultPage.getResults().get(0).getMatches().get(1); + SearchResult.MatchInfo match2 = searchResultPage.getResults().get(0).getMatchInfos().get(1); assertThat(match2.getPropertyPath()).isEqualTo("sender.email[1]"); assertThat(match2.getFullText()).isEqualTo("TestNameJr2@gmail.com"); assertThat(match2.getExactMatchRange())