Loading apex/appsearch/framework/java/android/app/appsearch/AppSearchEmail.java +27 −32 Original line number Diff line number Diff line Loading @@ -27,8 +27,6 @@ import android.app.appsearch.AppSearchSchema.PropertyConfig; * * <p>This class is a higher level implement of {@link GenericDocument}. * * <p>This class will eventually migrate to Jetpack, where it will become public API. * * @hide */ Loading Loading @@ -99,10 +97,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the from address of {@link AppSearchEmail}. * Gets the from address of {@link AppSearchEmail}. * * @return Returns the subject of {@link AppSearchEmail} or {@code null} if it's not been set * yet. * @return The subject of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String getFrom() { Loading @@ -110,10 +107,10 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the destination addresses of {@link AppSearchEmail}. * Gets the destination addresses of {@link AppSearchEmail}. * * @return Returns the destination addresses of {@link AppSearchEmail} or {@code null} if it's * not been set yet. * @return The destination addresses of {@link AppSearchEmail} or {@code null} if it's not * been set yet. */ @Nullable public String[] getTo() { Loading @@ -121,10 +118,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the CC list of {@link AppSearchEmail}. * Gets the CC list of {@link AppSearchEmail}. * * @return Returns the CC list of {@link AppSearchEmail} or {@code null} if it's not been set * yet. * @return The CC list of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String[] getCc() { Loading @@ -132,10 +128,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the BCC list of {@link AppSearchEmail}. * Gets the BCC list of {@link AppSearchEmail}. * * @return Returns the BCC list of {@link AppSearchEmail} or {@code null} if it's not been set * yet. * @return The BCC list of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String[] getBcc() { Loading @@ -143,10 +138,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the subject of {@link AppSearchEmail}. * Gets the subject of {@link AppSearchEmail}. * * @return Returns the value subject of {@link AppSearchEmail} or {@code null} if it's not been * set yet. * @return The value subject of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String getSubject() { Loading @@ -154,9 +148,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the body of {@link AppSearchEmail}. * Gets the body of {@link AppSearchEmail}. * * @return Returns the body of {@link AppSearchEmail} or {@code null} if it's not been set yet. * @return The body of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String getBody() { Loading @@ -169,7 +163,8 @@ public class AppSearchEmail extends GenericDocument { public static class Builder extends GenericDocument.Builder<AppSearchEmail.Builder> { /** * Create a new {@link AppSearchEmail.Builder} * Creates a new {@link AppSearchEmail.Builder} * * @param uri The Uri of the Email. */ public Builder(@NonNull String uri) { Loading @@ -177,56 +172,56 @@ public class AppSearchEmail extends GenericDocument { } /** * Set the from address of {@link AppSearchEmail} * Sets the from address of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setFrom(@NonNull String from) { setProperty(KEY_FROM, from); setPropertyString(KEY_FROM, from); return this; } /** * Set the destination address of {@link AppSearchEmail} * Sets the destination address of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setTo(@NonNull String... to) { setProperty(KEY_TO, to); setPropertyString(KEY_TO, to); return this; } /** * Set the CC list of {@link AppSearchEmail} * Sets the CC list of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setCc(@NonNull String... cc) { setProperty(KEY_CC, cc); setPropertyString(KEY_CC, cc); return this; } /** * Set the BCC list of {@link AppSearchEmail} * Sets the BCC list of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setBcc(@NonNull String... bcc) { setProperty(KEY_BCC, bcc); setPropertyString(KEY_BCC, bcc); return this; } /** * Set the subject of {@link AppSearchEmail} * Sets the subject of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setSubject(@NonNull String subject) { setProperty(KEY_SUBJECT, subject); setPropertyString(KEY_SUBJECT, subject); return this; } /** * Set the body of {@link AppSearchEmail} * Sets the body of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setBody(@NonNull String body) { setProperty(KEY_BODY, body); setPropertyString(KEY_BODY, body); return this; } Loading apex/appsearch/framework/java/android/app/appsearch/AppSearchSchema.java +88 −42 Original line number Diff line number Diff line Loading @@ -16,10 +16,12 @@ package android.app.appsearch; import android.annotation.SuppressLint; import android.os.Bundle; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.appsearch.exceptions.IllegalSchemaException; import android.util.ArraySet; Loading @@ -28,6 +30,8 @@ import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; /** Loading @@ -39,13 +43,8 @@ import java.util.Set; * @hide */ public final class AppSearchSchema { /** @hide */ public static final String SCHEMA_TYPE_FIELD = "schemaType"; /** @hide */ public static final String PROPERTIES_FIELD = "properties"; private static final String SCHEMA_TYPE_FIELD = "schemaType"; private static final String PROPERTIES_FIELD = "properties"; private final Bundle mBundle; Loading @@ -71,10 +70,35 @@ public final class AppSearchSchema { return mBundle.toString(); } /** Returns the name of this schema type, e.g. Email. */ @NonNull public String getSchemaTypeName() { return mBundle.getString(SCHEMA_TYPE_FIELD, ""); } /** * Returns the list of {@link PropertyConfig}s that are part of this schema. * * <p>This method creates a new list when called. */ @NonNull public List<PropertyConfig> getProperties() { ArrayList<Bundle> propertyBundles = mBundle.getParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD); if (propertyBundles.isEmpty()) { return Collections.emptyList(); } List<PropertyConfig> ret = new ArrayList<>(propertyBundles.size()); for (int i = 0; i < propertyBundles.size(); i++) { ret.add(new PropertyConfig(propertyBundles.get(i))); } return ret; } /** Builder for {@link AppSearchSchema objects}. */ public static final class Builder { private final String mTypeName; private final ArrayList<Bundle> mProperties = new ArrayList<>(); private final ArrayList<Bundle> mPropertyBundles = new ArrayList<>(); private final Set<String> mPropertyNames = new ArraySet<>(); private boolean mBuilt = false; Loading @@ -85,15 +109,19 @@ public final class AppSearchSchema { } /** Adds a property to the given type. */ // TODO(b/171360120): MissingGetterMatchingBuilder expects a method called getPropertys, but // we provide the (correct) method getProperties. Once the bug referenced in this TODO is // fixed, remove this SuppressLint. @SuppressLint("MissingGetterMatchingBuilder") @NonNull public AppSearchSchema.Builder addProperty(@NonNull PropertyConfig propertyConfig) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(propertyConfig); if (!mPropertyNames.add(propertyConfig.mName)) { throw new IllegalSchemaException( "Property defined more than once: " + propertyConfig.mName); String name = propertyConfig.getName(); if (!mPropertyNames.add(name)) { throw new IllegalSchemaException("Property defined more than once: " + name); } mProperties.add(propertyConfig.mBundle); mPropertyBundles.add(propertyConfig.mBundle); return this; } Loading @@ -107,7 +135,7 @@ public final class AppSearchSchema { Preconditions.checkState(!mBuilt, "Builder has already been used"); Bundle bundle = new Bundle(); bundle.putString(AppSearchSchema.SCHEMA_TYPE_FIELD, mTypeName); bundle.putParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD, mProperties); bundle.putParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD, mPropertyBundles); mBuilt = true; return new AppSearchSchema(bundle); } Loading @@ -120,29 +148,12 @@ public final class AppSearchSchema { * a property. */ public static final class PropertyConfig { /** @hide */ public static final String NAME_FIELD = "name"; /** @hide */ public static final String DATA_TYPE_FIELD = "dataType"; /** @hide */ public static final String SCHEMA_TYPE_FIELD = "schemaType"; /** @hide */ public static final String CARDINALITY_FIELD = "cardinality"; /** @hide */ public static final String INDEXING_TYPE_FIELD = "indexingType"; /** @hide */ public static final String TOKENIZER_TYPE_FIELD = "tokenizerType"; private static final String NAME_FIELD = "name"; private static final String DATA_TYPE_FIELD = "dataType"; private static final String SCHEMA_TYPE_FIELD = "schemaType"; private static final String CARDINALITY_FIELD = "cardinality"; private static final String INDEXING_TYPE_FIELD = "indexingType"; private static final String TOKENIZER_TYPE_FIELD = "tokenizerType"; /** * Physical data-types of the contents of the property. Loading Loading @@ -259,11 +270,9 @@ public final class AppSearchSchema { /** Tokenization for plain text. */ public static final int TOKENIZER_TYPE_PLAIN = 1; final String mName; final Bundle mBundle; PropertyConfig(@NonNull String name, @NonNull Bundle bundle) { mName = Preconditions.checkNotNull(name); PropertyConfig(@NonNull Bundle bundle) { mBundle = Preconditions.checkNotNull(bundle); } Loading @@ -272,6 +281,45 @@ public final class AppSearchSchema { return mBundle.toString(); } /** Returns the name of this property. */ @NonNull public String getName() { return mBundle.getString(NAME_FIELD, ""); } /** Returns the type of data the property contains (e.g. string, int, bytes, etc). */ public @DataType int getDataType() { return mBundle.getInt(DATA_TYPE_FIELD, -1); } /** * Returns the logical schema-type of the contents of this property. * * <p>Only set when {@link #getDataType} is set to {@link #DATA_TYPE_DOCUMENT}. * Otherwise, it is {@code null}. */ @Nullable public String getSchemaType() { return mBundle.getString(SCHEMA_TYPE_FIELD); } /** * Returns the cardinality of the property (whether it is optional, required or repeated). */ public @Cardinality int getCardinality() { return mBundle.getInt(CARDINALITY_FIELD, -1); } /** Returns how the property is indexed. */ public @IndexingType int getIndexingType() { return mBundle.getInt(INDEXING_TYPE_FIELD); } /** Returns how this property is tokenized (split into words). */ public @TokenizerType int getTokenizerType() { return mBundle.getInt(TOKENIZER_TYPE_FIELD); } /** * Builder for {@link PropertyConfig}. * Loading @@ -286,13 +334,11 @@ public final class AppSearchSchema { * is also required. */ public static final class Builder { private final String mName; private final Bundle mBundle = new Bundle(); private boolean mBuilt = false; /** Creates a new {@link PropertyConfig.Builder}. */ public Builder(@NonNull String propertyName) { mName = Preconditions.checkNotNull(propertyName); mBundle.putString(NAME_FIELD, propertyName); } Loading Loading @@ -386,7 +432,7 @@ public final class AppSearchSchema { throw new IllegalSchemaException("Missing field: cardinality"); } mBuilt = true; return new PropertyConfig(mName, mBundle); return new PropertyConfig(mBundle); } } } Loading apex/appsearch/framework/java/android/app/appsearch/GenericDocument.java +42 −37 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.android.internal.util.Preconditions; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Set; /** Loading Loading @@ -65,20 +66,14 @@ public class GenericDocument { /** The default time-to-live in millisecond of a document, which is infinity. */ private static final long DEFAULT_TTL_MILLIS = 0L; /** @hide */ public static final String PROPERTIES_FIELD = "properties"; /** @hide */ public static final String BYTE_ARRAY_FIELD = "byteArray"; static final String SCHEMA_TYPE_FIELD = "schemaType"; static final String URI_FIELD = "uri"; static final String SCORE_FIELD = "score"; static final String TTL_MILLIS_FIELD = "ttlMillis"; static final String CREATION_TIMESTAMP_MILLIS_FIELD = "creationTimestampMillis"; static final String NAMESPACE_FIELD = "namespace"; private static final String PROPERTIES_FIELD = "properties"; private static final String BYTE_ARRAY_FIELD = "byteArray"; private static final String SCHEMA_TYPE_FIELD = "schemaType"; private static final String URI_FIELD = "uri"; private static final String SCORE_FIELD = "score"; private static final String TTL_MILLIS_FIELD = "ttlMillis"; private static final String CREATION_TIMESTAMP_MILLIS_FIELD = "creationTimestampMillis"; private static final String NAMESPACE_FIELD = "namespace"; /** * The maximum number of indexed properties a document can have. Loading Loading @@ -190,6 +185,12 @@ public class GenericDocument { return mBundle.getInt(SCORE_FIELD, DEFAULT_SCORE); } /** Returns the names of all properties defined in this document. */ @NonNull public Set<String> getPropertyNames() { return Collections.unmodifiableSet(mProperties.keySet()); } /** * Retrieves a {@link String} value by key. * Loading Loading @@ -437,8 +438,6 @@ public class GenericDocument { @Override public boolean equals(@Nullable Object other) { // Check only proto's equality is sufficient here since all properties in // mProperties are ordered by keys and stored in proto. if (this == other) { return true; } Loading @@ -450,8 +449,8 @@ public class GenericDocument { } /** * Deeply checks two bundle is equally or not. * <p> Two bundle will be considered equally if they contains same content. * Deeply checks two bundles are equally or not. * <p> Two bundles will be considered equally if they contain same content. */ @SuppressWarnings("unchecked") private static boolean bundleEquals(Bundle one, Bundle two) { Loading Loading @@ -538,8 +537,8 @@ public class GenericDocument { /** * Calculates the hash code for a bundle. * <p> The hash code is only effected by the content in the bundle. Bundles will get * consistent hash code if they have same content. * <p> The hash code is only effected by the contents in the bundle. Bundles will get * consistent hash code if they have same contents. */ @SuppressWarnings("unchecked") private static int bundleHashCode(Bundle bundle) { Loading Loading @@ -648,8 +647,11 @@ public class GenericDocument { /** * The builder class for {@link GenericDocument}. * * @param <BuilderType> Type of subclass who extend this. * @param <BuilderType> Type of subclass who extends this. */ // This builder is specifically designed to be extended by classes deriving from // GenericDocument. @SuppressLint("StaticFinalBuilder") public static class Builder<BuilderType extends Builder> { private final Bundle mProperties = new Bundle(); Loading @@ -662,12 +664,11 @@ public class GenericDocument { * * @param uri The uri of {@link GenericDocument}. * @param schemaType The schema type of the {@link GenericDocument}. The passed-in * {@code schemaType} must be defined using {@code AppSearchManager#setSchema} prior * {@code schemaType} must be defined using {@link AppSearchSession#setSchema} prior * to inserting a document of this {@code schemaType} into the AppSearch index using * {@code AppSearchManager#putDocuments}. Otherwise, the document will be * rejected by {@code AppSearchManager#putDocuments}. * {@link AppSearchSession#putDocuments}. Otherwise, the document will be * rejected by {@link AppSearchSession#putDocuments}. */ //TODO(b/157082794) Linkify AppSearchManager once that API is public. @SuppressWarnings("unchecked") public Builder(@NonNull String uri, @NonNull String schemaType) { Preconditions.checkNotNull(uri); Loading @@ -685,9 +686,12 @@ public class GenericDocument { } /** * Set the app-defined namespace this Document resides in. No special values are * reserved or understood by the infrastructure. URIs are unique within a namespace. The * number of namespaces per app should be kept small for efficiency reasons. * Sets the app-defined namespace this Document resides in. No special values are * reserved or understood by the infrastructure. * * <p>URIs are unique within a namespace. * * <p>The number of namespaces per app should be kept small for efficiency reasons. */ @NonNull public BuilderType setNamespace(@NonNull String namespace) { Loading @@ -714,7 +718,7 @@ public class GenericDocument { } /** * Set the creation timestamp in milliseconds of the {@link GenericDocument}. Should be * Sets the creation timestamp of the {@link GenericDocument}, in milliseconds. Should be * set using a value obtained from the {@link System#currentTimeMillis()} time base. */ @NonNull Loading @@ -726,7 +730,7 @@ public class GenericDocument { } /** * Set the TTL (Time To Live) of the {@link GenericDocument}, in milliseconds. * Sets the TTL (Time To Live) of the {@link GenericDocument}, in milliseconds. * * <p>After this many milliseconds since the {@link #setCreationTimestampMillis creation * timestamp}, the document is deleted. Loading @@ -752,7 +756,7 @@ public class GenericDocument { * @param values The {@code String} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull String... values) { public BuilderType setPropertyString(@NonNull String key, @NonNull String... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -768,7 +772,7 @@ public class GenericDocument { * @param values The {@code boolean} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull boolean... values) { public BuilderType setPropertyBoolean(@NonNull String key, @NonNull boolean... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -784,7 +788,7 @@ public class GenericDocument { * @param values The {@code long} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull long... values) { public BuilderType setPropertyLong(@NonNull String key, @NonNull long... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -800,7 +804,7 @@ public class GenericDocument { * @param values The {@code double} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull double... values) { public BuilderType setPropertyDouble(@NonNull String key, @NonNull double... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -815,7 +819,7 @@ public class GenericDocument { * @param values The {@code byte[]} of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull byte[]... values) { public BuilderType setPropertyBytes(@NonNull String key, @NonNull byte[]... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -831,7 +835,8 @@ public class GenericDocument { * @param values The {@link GenericDocument} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull GenericDocument... values) { public BuilderType setPropertyDocument( @NonNull String key, @NonNull GenericDocument... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading apex/appsearch/framework/java/android/app/appsearch/GetByUriRequest.java +7 −9 Original line number Diff line number Diff line Loading @@ -17,12 +17,12 @@ package android.app.appsearch; import android.annotation.NonNull; import android.util.ArraySet; import com.android.internal.util.Preconditions; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Set; /** Loading @@ -40,18 +40,16 @@ public final class GetByUriRequest { mUris = uris; } /** @hide */ /** Returns the namespace to get documents from. */ @NonNull public String getNamespace() { return mNamespace; } /** @hide */ /** Returns the URIs to get from the namespace. */ @NonNull public Set<String> getUris() { return mUris; return Collections.unmodifiableSet(mUris); } /** Builder for {@link GetByUriRequest} objects. */ Loading @@ -75,14 +73,14 @@ public final class GetByUriRequest { /** Adds one or more URIs to the request. */ @NonNull public Builder addUris(@NonNull String... uris) { public Builder addUri(@NonNull String... uris) { Preconditions.checkNotNull(uris); return addUris(Arrays.asList(uris)); return addUri(Arrays.asList(uris)); } /** Adds one or more URIs to the request. */ @NonNull public Builder addUris(@NonNull Collection<String> uris) { public Builder addUri(@NonNull Collection<String> uris) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(uris); mUris.addAll(uris); Loading apex/appsearch/framework/java/android/app/appsearch/PutDocumentsRequest.java +8 −4 Original line number Diff line number Diff line Loading @@ -16,13 +16,16 @@ package android.app.appsearch; import android.annotation.NonNull; import android.annotation.SuppressLint; import android.annotation.NonNull; import android.app.appsearch.exceptions.AppSearchException; import com.android.internal.util.Preconditions; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; /** Loading @@ -38,11 +41,10 @@ public final class PutDocumentsRequest { mDocuments = documents; } /** @hide */ /** Returns the documents that are part of this request. */ @NonNull public List<GenericDocument> getDocuments() { return mDocuments; return Collections.unmodifiableList(mDocuments); } /** Builder for {@link PutDocumentsRequest} objects. */ Loading @@ -51,6 +53,7 @@ public final class PutDocumentsRequest { private boolean mBuilt = false; /** Adds one or more documents to the request. */ @SuppressLint("MissingGetterMatchingBuilder") // Merged list available from getDocuments() @NonNull public Builder addGenericDocument(@NonNull GenericDocument... documents) { Preconditions.checkNotNull(documents); Loading @@ -58,6 +61,7 @@ public final class PutDocumentsRequest { } /** Adds one or more documents to the request. */ @SuppressLint("MissingGetterMatchingBuilder") // Merged list available from getDocuments() @NonNull public Builder addGenericDocument(@NonNull Collection<GenericDocument> documents) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Loading Loading
apex/appsearch/framework/java/android/app/appsearch/AppSearchEmail.java +27 −32 Original line number Diff line number Diff line Loading @@ -27,8 +27,6 @@ import android.app.appsearch.AppSearchSchema.PropertyConfig; * * <p>This class is a higher level implement of {@link GenericDocument}. * * <p>This class will eventually migrate to Jetpack, where it will become public API. * * @hide */ Loading Loading @@ -99,10 +97,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the from address of {@link AppSearchEmail}. * Gets the from address of {@link AppSearchEmail}. * * @return Returns the subject of {@link AppSearchEmail} or {@code null} if it's not been set * yet. * @return The subject of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String getFrom() { Loading @@ -110,10 +107,10 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the destination addresses of {@link AppSearchEmail}. * Gets the destination addresses of {@link AppSearchEmail}. * * @return Returns the destination addresses of {@link AppSearchEmail} or {@code null} if it's * not been set yet. * @return The destination addresses of {@link AppSearchEmail} or {@code null} if it's not * been set yet. */ @Nullable public String[] getTo() { Loading @@ -121,10 +118,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the CC list of {@link AppSearchEmail}. * Gets the CC list of {@link AppSearchEmail}. * * @return Returns the CC list of {@link AppSearchEmail} or {@code null} if it's not been set * yet. * @return The CC list of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String[] getCc() { Loading @@ -132,10 +128,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the BCC list of {@link AppSearchEmail}. * Gets the BCC list of {@link AppSearchEmail}. * * @return Returns the BCC list of {@link AppSearchEmail} or {@code null} if it's not been set * yet. * @return The BCC list of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String[] getBcc() { Loading @@ -143,10 +138,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the subject of {@link AppSearchEmail}. * Gets the subject of {@link AppSearchEmail}. * * @return Returns the value subject of {@link AppSearchEmail} or {@code null} if it's not been * set yet. * @return The value subject of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String getSubject() { Loading @@ -154,9 +148,9 @@ public class AppSearchEmail extends GenericDocument { } /** * Get the body of {@link AppSearchEmail}. * Gets the body of {@link AppSearchEmail}. * * @return Returns the body of {@link AppSearchEmail} or {@code null} if it's not been set yet. * @return The body of {@link AppSearchEmail} or {@code null} if it's not been set yet. */ @Nullable public String getBody() { Loading @@ -169,7 +163,8 @@ public class AppSearchEmail extends GenericDocument { public static class Builder extends GenericDocument.Builder<AppSearchEmail.Builder> { /** * Create a new {@link AppSearchEmail.Builder} * Creates a new {@link AppSearchEmail.Builder} * * @param uri The Uri of the Email. */ public Builder(@NonNull String uri) { Loading @@ -177,56 +172,56 @@ public class AppSearchEmail extends GenericDocument { } /** * Set the from address of {@link AppSearchEmail} * Sets the from address of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setFrom(@NonNull String from) { setProperty(KEY_FROM, from); setPropertyString(KEY_FROM, from); return this; } /** * Set the destination address of {@link AppSearchEmail} * Sets the destination address of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setTo(@NonNull String... to) { setProperty(KEY_TO, to); setPropertyString(KEY_TO, to); return this; } /** * Set the CC list of {@link AppSearchEmail} * Sets the CC list of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setCc(@NonNull String... cc) { setProperty(KEY_CC, cc); setPropertyString(KEY_CC, cc); return this; } /** * Set the BCC list of {@link AppSearchEmail} * Sets the BCC list of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setBcc(@NonNull String... bcc) { setProperty(KEY_BCC, bcc); setPropertyString(KEY_BCC, bcc); return this; } /** * Set the subject of {@link AppSearchEmail} * Sets the subject of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setSubject(@NonNull String subject) { setProperty(KEY_SUBJECT, subject); setPropertyString(KEY_SUBJECT, subject); return this; } /** * Set the body of {@link AppSearchEmail} * Sets the body of {@link AppSearchEmail} */ @NonNull public AppSearchEmail.Builder setBody(@NonNull String body) { setProperty(KEY_BODY, body); setPropertyString(KEY_BODY, body); return this; } Loading
apex/appsearch/framework/java/android/app/appsearch/AppSearchSchema.java +88 −42 Original line number Diff line number Diff line Loading @@ -16,10 +16,12 @@ package android.app.appsearch; import android.annotation.SuppressLint; import android.os.Bundle; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.appsearch.exceptions.IllegalSchemaException; import android.util.ArraySet; Loading @@ -28,6 +30,8 @@ import com.android.internal.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; /** Loading @@ -39,13 +43,8 @@ import java.util.Set; * @hide */ public final class AppSearchSchema { /** @hide */ public static final String SCHEMA_TYPE_FIELD = "schemaType"; /** @hide */ public static final String PROPERTIES_FIELD = "properties"; private static final String SCHEMA_TYPE_FIELD = "schemaType"; private static final String PROPERTIES_FIELD = "properties"; private final Bundle mBundle; Loading @@ -71,10 +70,35 @@ public final class AppSearchSchema { return mBundle.toString(); } /** Returns the name of this schema type, e.g. Email. */ @NonNull public String getSchemaTypeName() { return mBundle.getString(SCHEMA_TYPE_FIELD, ""); } /** * Returns the list of {@link PropertyConfig}s that are part of this schema. * * <p>This method creates a new list when called. */ @NonNull public List<PropertyConfig> getProperties() { ArrayList<Bundle> propertyBundles = mBundle.getParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD); if (propertyBundles.isEmpty()) { return Collections.emptyList(); } List<PropertyConfig> ret = new ArrayList<>(propertyBundles.size()); for (int i = 0; i < propertyBundles.size(); i++) { ret.add(new PropertyConfig(propertyBundles.get(i))); } return ret; } /** Builder for {@link AppSearchSchema objects}. */ public static final class Builder { private final String mTypeName; private final ArrayList<Bundle> mProperties = new ArrayList<>(); private final ArrayList<Bundle> mPropertyBundles = new ArrayList<>(); private final Set<String> mPropertyNames = new ArraySet<>(); private boolean mBuilt = false; Loading @@ -85,15 +109,19 @@ public final class AppSearchSchema { } /** Adds a property to the given type. */ // TODO(b/171360120): MissingGetterMatchingBuilder expects a method called getPropertys, but // we provide the (correct) method getProperties. Once the bug referenced in this TODO is // fixed, remove this SuppressLint. @SuppressLint("MissingGetterMatchingBuilder") @NonNull public AppSearchSchema.Builder addProperty(@NonNull PropertyConfig propertyConfig) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(propertyConfig); if (!mPropertyNames.add(propertyConfig.mName)) { throw new IllegalSchemaException( "Property defined more than once: " + propertyConfig.mName); String name = propertyConfig.getName(); if (!mPropertyNames.add(name)) { throw new IllegalSchemaException("Property defined more than once: " + name); } mProperties.add(propertyConfig.mBundle); mPropertyBundles.add(propertyConfig.mBundle); return this; } Loading @@ -107,7 +135,7 @@ public final class AppSearchSchema { Preconditions.checkState(!mBuilt, "Builder has already been used"); Bundle bundle = new Bundle(); bundle.putString(AppSearchSchema.SCHEMA_TYPE_FIELD, mTypeName); bundle.putParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD, mProperties); bundle.putParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD, mPropertyBundles); mBuilt = true; return new AppSearchSchema(bundle); } Loading @@ -120,29 +148,12 @@ public final class AppSearchSchema { * a property. */ public static final class PropertyConfig { /** @hide */ public static final String NAME_FIELD = "name"; /** @hide */ public static final String DATA_TYPE_FIELD = "dataType"; /** @hide */ public static final String SCHEMA_TYPE_FIELD = "schemaType"; /** @hide */ public static final String CARDINALITY_FIELD = "cardinality"; /** @hide */ public static final String INDEXING_TYPE_FIELD = "indexingType"; /** @hide */ public static final String TOKENIZER_TYPE_FIELD = "tokenizerType"; private static final String NAME_FIELD = "name"; private static final String DATA_TYPE_FIELD = "dataType"; private static final String SCHEMA_TYPE_FIELD = "schemaType"; private static final String CARDINALITY_FIELD = "cardinality"; private static final String INDEXING_TYPE_FIELD = "indexingType"; private static final String TOKENIZER_TYPE_FIELD = "tokenizerType"; /** * Physical data-types of the contents of the property. Loading Loading @@ -259,11 +270,9 @@ public final class AppSearchSchema { /** Tokenization for plain text. */ public static final int TOKENIZER_TYPE_PLAIN = 1; final String mName; final Bundle mBundle; PropertyConfig(@NonNull String name, @NonNull Bundle bundle) { mName = Preconditions.checkNotNull(name); PropertyConfig(@NonNull Bundle bundle) { mBundle = Preconditions.checkNotNull(bundle); } Loading @@ -272,6 +281,45 @@ public final class AppSearchSchema { return mBundle.toString(); } /** Returns the name of this property. */ @NonNull public String getName() { return mBundle.getString(NAME_FIELD, ""); } /** Returns the type of data the property contains (e.g. string, int, bytes, etc). */ public @DataType int getDataType() { return mBundle.getInt(DATA_TYPE_FIELD, -1); } /** * Returns the logical schema-type of the contents of this property. * * <p>Only set when {@link #getDataType} is set to {@link #DATA_TYPE_DOCUMENT}. * Otherwise, it is {@code null}. */ @Nullable public String getSchemaType() { return mBundle.getString(SCHEMA_TYPE_FIELD); } /** * Returns the cardinality of the property (whether it is optional, required or repeated). */ public @Cardinality int getCardinality() { return mBundle.getInt(CARDINALITY_FIELD, -1); } /** Returns how the property is indexed. */ public @IndexingType int getIndexingType() { return mBundle.getInt(INDEXING_TYPE_FIELD); } /** Returns how this property is tokenized (split into words). */ public @TokenizerType int getTokenizerType() { return mBundle.getInt(TOKENIZER_TYPE_FIELD); } /** * Builder for {@link PropertyConfig}. * Loading @@ -286,13 +334,11 @@ public final class AppSearchSchema { * is also required. */ public static final class Builder { private final String mName; private final Bundle mBundle = new Bundle(); private boolean mBuilt = false; /** Creates a new {@link PropertyConfig.Builder}. */ public Builder(@NonNull String propertyName) { mName = Preconditions.checkNotNull(propertyName); mBundle.putString(NAME_FIELD, propertyName); } Loading Loading @@ -386,7 +432,7 @@ public final class AppSearchSchema { throw new IllegalSchemaException("Missing field: cardinality"); } mBuilt = true; return new PropertyConfig(mName, mBundle); return new PropertyConfig(mBundle); } } } Loading
apex/appsearch/framework/java/android/app/appsearch/GenericDocument.java +42 −37 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.android.internal.util.Preconditions; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Set; /** Loading Loading @@ -65,20 +66,14 @@ public class GenericDocument { /** The default time-to-live in millisecond of a document, which is infinity. */ private static final long DEFAULT_TTL_MILLIS = 0L; /** @hide */ public static final String PROPERTIES_FIELD = "properties"; /** @hide */ public static final String BYTE_ARRAY_FIELD = "byteArray"; static final String SCHEMA_TYPE_FIELD = "schemaType"; static final String URI_FIELD = "uri"; static final String SCORE_FIELD = "score"; static final String TTL_MILLIS_FIELD = "ttlMillis"; static final String CREATION_TIMESTAMP_MILLIS_FIELD = "creationTimestampMillis"; static final String NAMESPACE_FIELD = "namespace"; private static final String PROPERTIES_FIELD = "properties"; private static final String BYTE_ARRAY_FIELD = "byteArray"; private static final String SCHEMA_TYPE_FIELD = "schemaType"; private static final String URI_FIELD = "uri"; private static final String SCORE_FIELD = "score"; private static final String TTL_MILLIS_FIELD = "ttlMillis"; private static final String CREATION_TIMESTAMP_MILLIS_FIELD = "creationTimestampMillis"; private static final String NAMESPACE_FIELD = "namespace"; /** * The maximum number of indexed properties a document can have. Loading Loading @@ -190,6 +185,12 @@ public class GenericDocument { return mBundle.getInt(SCORE_FIELD, DEFAULT_SCORE); } /** Returns the names of all properties defined in this document. */ @NonNull public Set<String> getPropertyNames() { return Collections.unmodifiableSet(mProperties.keySet()); } /** * Retrieves a {@link String} value by key. * Loading Loading @@ -437,8 +438,6 @@ public class GenericDocument { @Override public boolean equals(@Nullable Object other) { // Check only proto's equality is sufficient here since all properties in // mProperties are ordered by keys and stored in proto. if (this == other) { return true; } Loading @@ -450,8 +449,8 @@ public class GenericDocument { } /** * Deeply checks two bundle is equally or not. * <p> Two bundle will be considered equally if they contains same content. * Deeply checks two bundles are equally or not. * <p> Two bundles will be considered equally if they contain same content. */ @SuppressWarnings("unchecked") private static boolean bundleEquals(Bundle one, Bundle two) { Loading Loading @@ -538,8 +537,8 @@ public class GenericDocument { /** * Calculates the hash code for a bundle. * <p> The hash code is only effected by the content in the bundle. Bundles will get * consistent hash code if they have same content. * <p> The hash code is only effected by the contents in the bundle. Bundles will get * consistent hash code if they have same contents. */ @SuppressWarnings("unchecked") private static int bundleHashCode(Bundle bundle) { Loading Loading @@ -648,8 +647,11 @@ public class GenericDocument { /** * The builder class for {@link GenericDocument}. * * @param <BuilderType> Type of subclass who extend this. * @param <BuilderType> Type of subclass who extends this. */ // This builder is specifically designed to be extended by classes deriving from // GenericDocument. @SuppressLint("StaticFinalBuilder") public static class Builder<BuilderType extends Builder> { private final Bundle mProperties = new Bundle(); Loading @@ -662,12 +664,11 @@ public class GenericDocument { * * @param uri The uri of {@link GenericDocument}. * @param schemaType The schema type of the {@link GenericDocument}. The passed-in * {@code schemaType} must be defined using {@code AppSearchManager#setSchema} prior * {@code schemaType} must be defined using {@link AppSearchSession#setSchema} prior * to inserting a document of this {@code schemaType} into the AppSearch index using * {@code AppSearchManager#putDocuments}. Otherwise, the document will be * rejected by {@code AppSearchManager#putDocuments}. * {@link AppSearchSession#putDocuments}. Otherwise, the document will be * rejected by {@link AppSearchSession#putDocuments}. */ //TODO(b/157082794) Linkify AppSearchManager once that API is public. @SuppressWarnings("unchecked") public Builder(@NonNull String uri, @NonNull String schemaType) { Preconditions.checkNotNull(uri); Loading @@ -685,9 +686,12 @@ public class GenericDocument { } /** * Set the app-defined namespace this Document resides in. No special values are * reserved or understood by the infrastructure. URIs are unique within a namespace. The * number of namespaces per app should be kept small for efficiency reasons. * Sets the app-defined namespace this Document resides in. No special values are * reserved or understood by the infrastructure. * * <p>URIs are unique within a namespace. * * <p>The number of namespaces per app should be kept small for efficiency reasons. */ @NonNull public BuilderType setNamespace(@NonNull String namespace) { Loading @@ -714,7 +718,7 @@ public class GenericDocument { } /** * Set the creation timestamp in milliseconds of the {@link GenericDocument}. Should be * Sets the creation timestamp of the {@link GenericDocument}, in milliseconds. Should be * set using a value obtained from the {@link System#currentTimeMillis()} time base. */ @NonNull Loading @@ -726,7 +730,7 @@ public class GenericDocument { } /** * Set the TTL (Time To Live) of the {@link GenericDocument}, in milliseconds. * Sets the TTL (Time To Live) of the {@link GenericDocument}, in milliseconds. * * <p>After this many milliseconds since the {@link #setCreationTimestampMillis creation * timestamp}, the document is deleted. Loading @@ -752,7 +756,7 @@ public class GenericDocument { * @param values The {@code String} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull String... values) { public BuilderType setPropertyString(@NonNull String key, @NonNull String... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -768,7 +772,7 @@ public class GenericDocument { * @param values The {@code boolean} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull boolean... values) { public BuilderType setPropertyBoolean(@NonNull String key, @NonNull boolean... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -784,7 +788,7 @@ public class GenericDocument { * @param values The {@code long} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull long... values) { public BuilderType setPropertyLong(@NonNull String key, @NonNull long... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -800,7 +804,7 @@ public class GenericDocument { * @param values The {@code double} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull double... values) { public BuilderType setPropertyDouble(@NonNull String key, @NonNull double... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -815,7 +819,7 @@ public class GenericDocument { * @param values The {@code byte[]} of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull byte[]... values) { public BuilderType setPropertyBytes(@NonNull String key, @NonNull byte[]... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading @@ -831,7 +835,8 @@ public class GenericDocument { * @param values The {@link GenericDocument} values of the property. */ @NonNull public BuilderType setProperty(@NonNull String key, @NonNull GenericDocument... values) { public BuilderType setPropertyDocument( @NonNull String key, @NonNull GenericDocument... values) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(key); Preconditions.checkNotNull(values); Loading
apex/appsearch/framework/java/android/app/appsearch/GetByUriRequest.java +7 −9 Original line number Diff line number Diff line Loading @@ -17,12 +17,12 @@ package android.app.appsearch; import android.annotation.NonNull; import android.util.ArraySet; import com.android.internal.util.Preconditions; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Set; /** Loading @@ -40,18 +40,16 @@ public final class GetByUriRequest { mUris = uris; } /** @hide */ /** Returns the namespace to get documents from. */ @NonNull public String getNamespace() { return mNamespace; } /** @hide */ /** Returns the URIs to get from the namespace. */ @NonNull public Set<String> getUris() { return mUris; return Collections.unmodifiableSet(mUris); } /** Builder for {@link GetByUriRequest} objects. */ Loading @@ -75,14 +73,14 @@ public final class GetByUriRequest { /** Adds one or more URIs to the request. */ @NonNull public Builder addUris(@NonNull String... uris) { public Builder addUri(@NonNull String... uris) { Preconditions.checkNotNull(uris); return addUris(Arrays.asList(uris)); return addUri(Arrays.asList(uris)); } /** Adds one or more URIs to the request. */ @NonNull public Builder addUris(@NonNull Collection<String> uris) { public Builder addUri(@NonNull Collection<String> uris) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Preconditions.checkNotNull(uris); mUris.addAll(uris); Loading
apex/appsearch/framework/java/android/app/appsearch/PutDocumentsRequest.java +8 −4 Original line number Diff line number Diff line Loading @@ -16,13 +16,16 @@ package android.app.appsearch; import android.annotation.NonNull; import android.annotation.SuppressLint; import android.annotation.NonNull; import android.app.appsearch.exceptions.AppSearchException; import com.android.internal.util.Preconditions; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; /** Loading @@ -38,11 +41,10 @@ public final class PutDocumentsRequest { mDocuments = documents; } /** @hide */ /** Returns the documents that are part of this request. */ @NonNull public List<GenericDocument> getDocuments() { return mDocuments; return Collections.unmodifiableList(mDocuments); } /** Builder for {@link PutDocumentsRequest} objects. */ Loading @@ -51,6 +53,7 @@ public final class PutDocumentsRequest { private boolean mBuilt = false; /** Adds one or more documents to the request. */ @SuppressLint("MissingGetterMatchingBuilder") // Merged list available from getDocuments() @NonNull public Builder addGenericDocument(@NonNull GenericDocument... documents) { Preconditions.checkNotNull(documents); Loading @@ -58,6 +61,7 @@ public final class PutDocumentsRequest { } /** Adds one or more documents to the request. */ @SuppressLint("MissingGetterMatchingBuilder") // Merged list available from getDocuments() @NonNull public Builder addGenericDocument(@NonNull Collection<GenericDocument> documents) { Preconditions.checkState(!mBuilt, "Builder has already been used"); Loading