Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c153efec authored by Alexander Dorokhine's avatar Alexander Dorokhine Committed by Terry Wang
Browse files

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
parent c02dcf75
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -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<BuilderType extends android.app.appsearch.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<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>);
    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<java.lang.String>);
    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);
  }
+3 −3
Original line number Diff line number Diff line
@@ -152,14 +152,14 @@ public class AppSearchEmail extends GenericDocument {

    /** The builder class for {@link AppSearchEmail}. */
    public static class Builder extends GenericDocument.Builder<AppSearchEmail.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} */
+56 −3
Original line number Diff line number Diff line
@@ -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.
     *
     * <p>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 {
         *
         * <p>Once {@link #build} is called, the instance can no longer be used.
         *
         * <p>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}.
         *
         * <p>Once {@link #build} is called, the instance can no longer be used.
         *
         * <p>URIs are unique within a namespace.
         *
         * <p>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 {
         *
         * <p>The number of namespaces per app should be kept small for efficiency reasons.
         *
         * <p>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");
+24 −3
Original line number Diff line number Diff line
@@ -107,19 +107,40 @@ public final class GetByUriRequest {
     * <p>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<String> mUris = new ArraySet<>();
        private final Map<String, List<String>> 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.
         *
         * <p>If this is not called, the namespace defaults to {@link
         * GenericDocument#DEFAULT_NAMESPACE}.
         * <p>If this is not called, the namespace defaults to an empty string.
         *
         * <p>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");
+24 −2
Original line number Diff line number Diff line
@@ -59,17 +59,39 @@ public final class RemoveByUriRequest {
     * <p>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<String> 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.
         *
         * <p>If this is not set, it defaults to {@link GenericDocument#DEFAULT_NAMESPACE}.
         * <p>If this is not set, it defaults to an empty string.
         *
         * <p>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");
Loading