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

Commit 7b058623 authored by Alexander Dorokhine's avatar Alexander Dorokhine
Browse files

setSchema() API adjustments from API review.

Test: presubmit
Bug: 145635424
Change-Id: I548c2f986972c1a1fb5ef3ec55a5735b29e84b04
parent 70156bd8
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -40,43 +40,43 @@ public class AppSearchEmail extends AppSearchDocument {
    /** The name of the schema type for {@link AppSearchEmail} documents.*/
    public static final String SCHEMA_TYPE = "builtin:Email";

    public static final AppSearchSchema SCHEMA = AppSearchSchema.newBuilder(SCHEMA_TYPE)
            .addProperty(AppSearchSchema.newPropertyBuilder(KEY_FROM)
    public static final AppSearchSchema SCHEMA = new AppSearchSchema.Builder(SCHEMA_TYPE)
            .addProperty(new AppSearchSchema.PropertyConfig.Builder(KEY_FROM)
                    .setDataType(PropertyConfig.DATA_TYPE_STRING)
                    .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                    .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
                    .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                    .build()

            ).addProperty(AppSearchSchema.newPropertyBuilder(KEY_TO)
            ).addProperty(new AppSearchSchema.PropertyConfig.Builder(KEY_TO)
                    .setDataType(PropertyConfig.DATA_TYPE_STRING)
                    .setCardinality(PropertyConfig.CARDINALITY_REPEATED)
                    .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
                    .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                    .build()

            ).addProperty(AppSearchSchema.newPropertyBuilder(KEY_CC)
            ).addProperty(new AppSearchSchema.PropertyConfig.Builder(KEY_CC)
                    .setDataType(PropertyConfig.DATA_TYPE_STRING)
                    .setCardinality(PropertyConfig.CARDINALITY_REPEATED)
                    .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
                    .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                    .build()

            ).addProperty(AppSearchSchema.newPropertyBuilder(KEY_BCC)
            ).addProperty(new AppSearchSchema.PropertyConfig.Builder(KEY_BCC)
                    .setDataType(PropertyConfig.DATA_TYPE_STRING)
                    .setCardinality(PropertyConfig.CARDINALITY_REPEATED)
                    .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
                    .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                    .build()

            ).addProperty(AppSearchSchema.newPropertyBuilder(KEY_SUBJECT)
            ).addProperty(new AppSearchSchema.PropertyConfig.Builder(KEY_SUBJECT)
                    .setDataType(PropertyConfig.DATA_TYPE_STRING)
                    .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                    .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
                    .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                    .build()

            ).addProperty(AppSearchSchema.newPropertyBuilder(KEY_BODY)
            ).addProperty(new AppSearchSchema.PropertyConfig.Builder(KEY_BODY)
                    .setDataType(PropertyConfig.DATA_TYPE_STRING)
                    .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                    .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import java.util.function.BiConsumer;
 *
 * @hide
 */
// TODO(b/148046169): This class header needs a detailed example/tutorial.
@SystemService(Context.APP_SEARCH_SERVICE)
public class AppSearchManager {
    private final IAppSearchManager mService;
+20 −18
Original line number Diff line number Diff line
@@ -46,18 +46,6 @@ public final class AppSearchSchema {
        mProto = proto;
    }

    /** Creates a new {@link AppSearchSchema.Builder}. */
    @NonNull
    public static AppSearchSchema.Builder newBuilder(@NonNull String typeName) {
        return new AppSearchSchema.Builder(typeName);
    }

    /** Creates a new {@link PropertyConfig.Builder}. */
    @NonNull
    public static PropertyConfig.Builder newPropertyBuilder(@NonNull String propertyName) {
        return new PropertyConfig.Builder(propertyName);
    }

    /**
     * Returns the {@link SchemaTypeConfigProto} populated by this builder.
     * @hide
@@ -78,7 +66,8 @@ public final class AppSearchSchema {
        private final SchemaTypeConfigProto.Builder mProtoBuilder =
                SchemaTypeConfigProto.newBuilder();

        private Builder(@NonNull String typeName) {
        /** Creates a new {@link AppSearchSchema.Builder}. */
        public Builder(@NonNull String typeName) {
            mProtoBuilder.setSchemaType(typeName);
        }

@@ -115,7 +104,10 @@ public final class AppSearchSchema {
     * a property.
     */
    public static final class PropertyConfig {
        /** Physical data-types of the contents of the property. */
        /**
         * Physical data-types of the contents of the property.
         * @hide
         */
        // NOTE: The integer values of these constants must match the proto enum constants in
        // com.google.android.icing.proto.PropertyConfigProto.DataType.Code.
        @IntDef(prefix = {"DATA_TYPE_"}, value = {
@@ -144,7 +136,10 @@ public final class AppSearchSchema {
         */
        public static final int DATA_TYPE_DOCUMENT = 6;

        /** The cardinality of the property (whether it is required, optional or repeated). */
        /**
         * The cardinality of the property (whether it is required, optional or repeated).
         * @hide
         */
        // NOTE: The integer values of these constants must match the proto enum constants in
        // com.google.android.icing.proto.PropertyConfigProto.Cardinality.Code.
        @IntDef(prefix = {"CARDINALITY_"}, value = {
@@ -164,7 +159,10 @@ public final class AppSearchSchema {
        /** Exactly one value [1]. */
        public static final int CARDINALITY_REQUIRED = 3;

        /** Encapsulates the configurations on how AppSearch should query/index these terms. */
        /**
         * Encapsulates the configurations on how AppSearch should query/index these terms.
         * @hide
         */
        @IntDef(prefix = {"INDEXING_TYPE_"}, value = {
                INDEXING_TYPE_NONE,
                INDEXING_TYPE_EXACT_TERMS,
@@ -199,7 +197,10 @@ public final class AppSearchSchema {
         */
        public static final int INDEXING_TYPE_PREFIXES = 2;

        /** Configures how tokens should be extracted from this property. */
        /**
         * Configures how tokens should be extracted from this property.
         * @hide
         */
        // NOTE: The integer values of these constants must match the proto enum constants in
        // com.google.android.icing.proto.IndexingConfig.TokenizerType.Code.
        @IntDef(prefix = {"TOKENIZER_TYPE_"}, value = {
@@ -249,7 +250,8 @@ public final class AppSearchSchema {
                    mIndexingConfigProto =
                        com.google.android.icing.proto.IndexingConfig.newBuilder();

            private Builder(String propertyName) {
            /** Creates a new {@link PropertyConfig.Builder}. */
            public Builder(@NonNull String propertyName) {
                mPropertyConfigProto.setPropertyName(propertyName);
            }

+11 −11
Original line number Diff line number Diff line
@@ -36,14 +36,14 @@ import org.junit.Test;
public class AppSearchSchemaTest {
    @Test
    public void testGetProto_Email() {
        AppSearchSchema emailSchema = AppSearchSchema.newBuilder("Email")
                .addProperty(AppSearchSchema.newPropertyBuilder("subject")
        AppSearchSchema emailSchema = new AppSearchSchema.Builder("Email")
                .addProperty(new AppSearchSchema.PropertyConfig.Builder("subject")
                        .setDataType(PropertyConfig.DATA_TYPE_STRING)
                        .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                        .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                        .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
                        .build()
                ).addProperty(AppSearchSchema.newPropertyBuilder("body")
                ).addProperty(new AppSearchSchema.PropertyConfig.Builder("body")
                        .setDataType(PropertyConfig.DATA_TYPE_STRING)
                        .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                        .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
@@ -78,14 +78,14 @@ public class AppSearchSchemaTest {

    @Test
    public void testGetProto_MusicRecording() {
        AppSearchSchema musicRecordingSchema = AppSearchSchema.newBuilder("MusicRecording")
                .addProperty(AppSearchSchema.newPropertyBuilder("artist")
        AppSearchSchema musicRecordingSchema = new AppSearchSchema.Builder("MusicRecording")
                .addProperty(new AppSearchSchema.PropertyConfig.Builder("artist")
                        .setDataType(PropertyConfig.DATA_TYPE_STRING)
                        .setCardinality(PropertyConfig.CARDINALITY_REPEATED)
                        .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                        .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
                        .build()
                ).addProperty(AppSearchSchema.newPropertyBuilder("pubDate")
                ).addProperty(new AppSearchSchema.PropertyConfig.Builder("pubDate")
                        .setDataType(PropertyConfig.DATA_TYPE_INT64)
                        .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                        .setIndexingType(PropertyConfig.INDEXING_TYPE_NONE)
@@ -120,14 +120,14 @@ public class AppSearchSchemaTest {

    @Test
    public void testInvalidEnums() {
        PropertyConfig.Builder builder = AppSearchSchema.newPropertyBuilder("test");
        PropertyConfig.Builder builder = new AppSearchSchema.PropertyConfig.Builder("test");
        assertThrows(IllegalArgumentException.class, () -> builder.setDataType(99));
        assertThrows(IllegalArgumentException.class, () -> builder.setCardinality(99));
    }

    @Test
    public void testMissingFields() {
        PropertyConfig.Builder builder = AppSearchSchema.newPropertyBuilder("test");
        PropertyConfig.Builder builder = new AppSearchSchema.PropertyConfig.Builder("test");
        Exception e = expectThrows(IllegalSchemaException.class, builder::build);
        assertThat(e).hasMessageThat().contains("Missing field: dataType");

@@ -145,14 +145,14 @@ public class AppSearchSchemaTest {

    @Test
    public void testDuplicateProperties() {
        AppSearchSchema.Builder builder = AppSearchSchema.newBuilder("Email")
                .addProperty(AppSearchSchema.newPropertyBuilder("subject")
        AppSearchSchema.Builder builder = new AppSearchSchema.Builder("Email")
                .addProperty(new AppSearchSchema.PropertyConfig.Builder("subject")
                        .setDataType(PropertyConfig.DATA_TYPE_STRING)
                        .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                        .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)
                        .setTokenizerType(PropertyConfig.TOKENIZER_TYPE_PLAIN)
                        .build()
                ).addProperty(AppSearchSchema.newPropertyBuilder("subject")
                ).addProperty(new AppSearchSchema.PropertyConfig.Builder("subject")
                        .setDataType(PropertyConfig.DATA_TYPE_STRING)
                        .setCardinality(PropertyConfig.CARDINALITY_OPTIONAL)
                        .setIndexingType(PropertyConfig.INDEXING_TYPE_PREFIXES)