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

Commit 47a69b97 authored by Alexander Dorokhine's avatar Alexander Dorokhine Committed by Automerger Merge Worker
Browse files

Merge "Update framework from Jetpack." into sc-dev am: 1b907312

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14490402

Change-Id: I73b34b231a58368d61b0f9ea0809ee0a9abb2d24
parents f5c16880 1b907312
Loading
Loading
Loading
Loading
+90 −137
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ public final class AppSearchSchema {
    /** Builder for {@link AppSearchSchema objects}. */
    public static final class Builder {
        private final String mSchemaType;
        private final ArrayList<Bundle> mPropertyBundles = new ArrayList<>();
        private ArrayList<Bundle> mPropertyBundles = new ArrayList<>();
        private final Set<String> mPropertyNames = new ArraySet<>();
        private boolean mBuilt = false;

@@ -133,8 +133,8 @@ public final class AppSearchSchema {
        /** Adds a property to the given type. */
        @NonNull
        public AppSearchSchema.Builder addProperty(@NonNull PropertyConfig propertyConfig) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Objects.requireNonNull(propertyConfig);
            resetIfBuilt();
            String name = propertyConfig.getName();
            if (!mPropertyNames.add(name)) {
                throw new IllegalSchemaException("Property defined more than once: " + name);
@@ -143,20 +143,22 @@ public final class AppSearchSchema {
            return this;
        }

        /**
         * Constructs a new {@link AppSearchSchema} from the contents of this builder.
         *
         * <p>After calling this method, the builder must no longer be used.
         */
        /** Constructs a new {@link AppSearchSchema} from the contents of this builder. */
        @NonNull
        public AppSearchSchema build() {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Bundle bundle = new Bundle();
            bundle.putString(AppSearchSchema.SCHEMA_TYPE_FIELD, mSchemaType);
            bundle.putParcelableArrayList(AppSearchSchema.PROPERTIES_FIELD, mPropertyBundles);
            mBuilt = true;
            return new AppSearchSchema(bundle);
        }

        private void resetIfBuilt() {
            if (mBuilt) {
                mPropertyBundles = new ArrayList<>(mPropertyBundles);
                mBuilt = false;
            }
        }
    }

    /**
@@ -251,6 +253,7 @@ public final class AppSearchSchema {
        }

        @Override
        @NonNull
        public String toString() {
            return mBundle.toString();
        }
@@ -410,16 +413,14 @@ public final class AppSearchSchema {

        /** Builder for {@link StringPropertyConfig}. */
        public static final class Builder {
            private final Bundle mBundle = new Bundle();
            private boolean mBuilt = false;
            private final String mPropertyName;
            private @Cardinality int mCardinality = CARDINALITY_OPTIONAL;
            private @IndexingType int mIndexingType = INDEXING_TYPE_NONE;
            private @TokenizerType int mTokenizerType = TOKENIZER_TYPE_NONE;

            /** Creates a new {@link StringPropertyConfig.Builder}. */
            public Builder(@NonNull String propertyName) {
                mBundle.putString(NAME_FIELD, propertyName);
                mBundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_STRING);
                mBundle.putInt(CARDINALITY_FIELD, CARDINALITY_OPTIONAL);
                mBundle.putInt(INDEXING_TYPE_FIELD, INDEXING_TYPE_NONE);
                mBundle.putInt(TOKENIZER_TYPE_FIELD, TOKENIZER_TYPE_NONE);
                mPropertyName = Objects.requireNonNull(propertyName);
            }

            /**
@@ -431,10 +432,9 @@ public final class AppSearchSchema {
            @SuppressWarnings("MissingGetterMatchingBuilder") // getter defined in superclass
            @NonNull
            public StringPropertyConfig.Builder setCardinality(@Cardinality int cardinality) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkArgumentInRange(
                        cardinality, CARDINALITY_REPEATED, CARDINALITY_REQUIRED, "cardinality");
                mBundle.putInt(CARDINALITY_FIELD, cardinality);
                mCardinality = cardinality;
                return this;
            }

@@ -446,10 +446,9 @@ public final class AppSearchSchema {
             */
            @NonNull
            public StringPropertyConfig.Builder setIndexingType(@IndexingType int indexingType) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkArgumentInRange(
                        indexingType, INDEXING_TYPE_NONE, INDEXING_TYPE_PREFIXES, "indexingType");
                mBundle.putInt(INDEXING_TYPE_FIELD, indexingType);
                mIndexingType = indexingType;
                return this;
            }

@@ -466,25 +465,22 @@ public final class AppSearchSchema {
             */
            @NonNull
            public StringPropertyConfig.Builder setTokenizerType(@TokenizerType int tokenizerType) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkArgumentInRange(
                        tokenizerType, TOKENIZER_TYPE_NONE, TOKENIZER_TYPE_PLAIN, "tokenizerType");
                mBundle.putInt(TOKENIZER_TYPE_FIELD, tokenizerType);
                mTokenizerType = tokenizerType;
                return this;
            }

            /**
             * Constructs a new {@link StringPropertyConfig} from the contents of this builder.
             *
             * <p>After calling this method, the builder must no longer be used.
             *
             * @throws IllegalStateException if the builder has already been used
             */
            /** Constructs a new {@link StringPropertyConfig} from the contents of this builder. */
            @NonNull
            public StringPropertyConfig build() {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                mBuilt = true;
                return new StringPropertyConfig(mBundle);
                Bundle bundle = new Bundle();
                bundle.putString(NAME_FIELD, mPropertyName);
                bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_STRING);
                bundle.putInt(CARDINALITY_FIELD, mCardinality);
                bundle.putInt(INDEXING_TYPE_FIELD, mIndexingType);
                bundle.putInt(TOKENIZER_TYPE_FIELD, mTokenizerType);
                return new StringPropertyConfig(bundle);
            }
        }
    }
@@ -497,14 +493,12 @@ public final class AppSearchSchema {

        /** Builder for {@link Int64PropertyConfig}. */
        public static final class Builder {
            private final Bundle mBundle = new Bundle();
            private boolean mBuilt = false;
            private final String mPropertyName;
            private @Cardinality int mCardinality = CARDINALITY_OPTIONAL;

            /** Creates a new {@link Int64PropertyConfig.Builder}. */
            public Builder(@NonNull String propertyName) {
                mBundle.putString(NAME_FIELD, propertyName);
                mBundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_INT64);
                mBundle.putInt(CARDINALITY_FIELD, CARDINALITY_OPTIONAL);
                mPropertyName = Objects.requireNonNull(propertyName);
            }

            /**
@@ -516,25 +510,20 @@ public final class AppSearchSchema {
            @SuppressWarnings("MissingGetterMatchingBuilder") // getter defined in superclass
            @NonNull
            public Int64PropertyConfig.Builder setCardinality(@Cardinality int cardinality) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkArgumentInRange(
                        cardinality, CARDINALITY_REPEATED, CARDINALITY_REQUIRED, "cardinality");
                mBundle.putInt(CARDINALITY_FIELD, cardinality);
                mCardinality = cardinality;
                return this;
            }

            /**
             * Constructs a new {@link Int64PropertyConfig} from the contents of this builder.
             *
             * <p>After calling this method, the builder must no longer be used.
             *
             * @throws IllegalStateException if the builder has already been used
             */
            /** Constructs a new {@link Int64PropertyConfig} from the contents of this builder. */
            @NonNull
            public Int64PropertyConfig build() {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                mBuilt = true;
                return new Int64PropertyConfig(mBundle);
                Bundle bundle = new Bundle();
                bundle.putString(NAME_FIELD, mPropertyName);
                bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_INT64);
                bundle.putInt(CARDINALITY_FIELD, mCardinality);
                return new Int64PropertyConfig(bundle);
            }
        }
    }
@@ -547,14 +536,12 @@ public final class AppSearchSchema {

        /** Builder for {@link DoublePropertyConfig}. */
        public static final class Builder {
            private final Bundle mBundle = new Bundle();
            private boolean mBuilt = false;
            private final String mPropertyName;
            private @Cardinality int mCardinality = CARDINALITY_OPTIONAL;

            /** Creates a new {@link DoublePropertyConfig.Builder}. */
            public Builder(@NonNull String propertyName) {
                mBundle.putString(NAME_FIELD, propertyName);
                mBundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_DOUBLE);
                mBundle.putInt(CARDINALITY_FIELD, CARDINALITY_OPTIONAL);
                mPropertyName = Objects.requireNonNull(propertyName);
            }

            /**
@@ -566,25 +553,20 @@ public final class AppSearchSchema {
            @SuppressWarnings("MissingGetterMatchingBuilder") // getter defined in superclass
            @NonNull
            public DoublePropertyConfig.Builder setCardinality(@Cardinality int cardinality) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkArgumentInRange(
                        cardinality, CARDINALITY_REPEATED, CARDINALITY_REQUIRED, "cardinality");
                mBundle.putInt(CARDINALITY_FIELD, cardinality);
                mCardinality = cardinality;
                return this;
            }

            /**
             * Constructs a new {@link DoublePropertyConfig} from the contents of this builder.
             *
             * <p>After calling this method, the builder must no longer be used.
             *
             * @throws IllegalStateException if the builder has already been used
             */
            /** Constructs a new {@link DoublePropertyConfig} from the contents of this builder. */
            @NonNull
            public DoublePropertyConfig build() {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                mBuilt = true;
                return new DoublePropertyConfig(mBundle);
                Bundle bundle = new Bundle();
                bundle.putString(NAME_FIELD, mPropertyName);
                bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_DOUBLE);
                bundle.putInt(CARDINALITY_FIELD, mCardinality);
                return new DoublePropertyConfig(bundle);
            }
        }
    }
@@ -597,14 +579,12 @@ public final class AppSearchSchema {

        /** Builder for {@link BooleanPropertyConfig}. */
        public static final class Builder {
            private final Bundle mBundle = new Bundle();
            private boolean mBuilt = false;
            private final String mPropertyName;
            private @Cardinality int mCardinality = CARDINALITY_OPTIONAL;

            /** Creates a new {@link BooleanPropertyConfig.Builder}. */
            public Builder(@NonNull String propertyName) {
                mBundle.putString(NAME_FIELD, propertyName);
                mBundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_BOOLEAN);
                mBundle.putInt(CARDINALITY_FIELD, CARDINALITY_OPTIONAL);
                mPropertyName = Objects.requireNonNull(propertyName);
            }

            /**
@@ -616,25 +596,20 @@ public final class AppSearchSchema {
            @SuppressWarnings("MissingGetterMatchingBuilder") // getter defined in superclass
            @NonNull
            public BooleanPropertyConfig.Builder setCardinality(@Cardinality int cardinality) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkArgumentInRange(
                        cardinality, CARDINALITY_REPEATED, CARDINALITY_REQUIRED, "cardinality");
                mBundle.putInt(CARDINALITY_FIELD, cardinality);
                mCardinality = cardinality;
                return this;
            }

            /**
             * Constructs a new {@link BooleanPropertyConfig} from the contents of this builder.
             *
             * <p>After calling this method, the builder must no longer be used.
             *
             * @throws IllegalStateException if the builder has already been used
             */
            /** Constructs a new {@link BooleanPropertyConfig} from the contents of this builder. */
            @NonNull
            public BooleanPropertyConfig build() {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                mBuilt = true;
                return new BooleanPropertyConfig(mBundle);
                Bundle bundle = new Bundle();
                bundle.putString(NAME_FIELD, mPropertyName);
                bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_BOOLEAN);
                bundle.putInt(CARDINALITY_FIELD, mCardinality);
                return new BooleanPropertyConfig(bundle);
            }
        }
    }
@@ -647,14 +622,12 @@ public final class AppSearchSchema {

        /** Builder for {@link BytesPropertyConfig}. */
        public static final class Builder {
            private final Bundle mBundle = new Bundle();
            private boolean mBuilt = false;
            private final String mPropertyName;
            private @Cardinality int mCardinality = CARDINALITY_OPTIONAL;

            /** Creates a new {@link BytesPropertyConfig.Builder}. */
            public Builder(@NonNull String propertyName) {
                mBundle.putString(NAME_FIELD, propertyName);
                mBundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_BYTES);
                mBundle.putInt(CARDINALITY_FIELD, CARDINALITY_OPTIONAL);
                mPropertyName = Objects.requireNonNull(propertyName);
            }

            /**
@@ -666,25 +639,20 @@ public final class AppSearchSchema {
            @SuppressWarnings("MissingGetterMatchingBuilder") // getter defined in superclass
            @NonNull
            public BytesPropertyConfig.Builder setCardinality(@Cardinality int cardinality) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkArgumentInRange(
                        cardinality, CARDINALITY_REPEATED, CARDINALITY_REQUIRED, "cardinality");
                mBundle.putInt(CARDINALITY_FIELD, cardinality);
                mCardinality = cardinality;
                return this;
            }

            /**
             * Constructs a new {@link BytesPropertyConfig} from the contents of this builder.
             *
             * <p>After calling this method, the builder must no longer be used.
             *
             * @throws IllegalStateException if the builder has already been used
             */
            /** Constructs a new {@link BytesPropertyConfig} from the contents of this builder. */
            @NonNull
            public BytesPropertyConfig build() {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                mBuilt = true;
                return new BytesPropertyConfig(mBundle);
                Bundle bundle = new Bundle();
                bundle.putString(NAME_FIELD, mPropertyName);
                bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_BYTES);
                bundle.putInt(CARDINALITY_FIELD, mCardinality);
                return new BytesPropertyConfig(bundle);
            }
        }
    }
@@ -715,20 +683,13 @@ public final class AppSearchSchema {
            return mBundle.getBoolean(INDEX_NESTED_PROPERTIES_FIELD);
        }

        /**
         * Builder for {@link DocumentPropertyConfig}.
         *
         * <p>The following properties must be set, or {@link DocumentPropertyConfig} construction
         * will fail:
         *
         * <ul>
         *   <li>cardinality
         *   <li>schemaType
         * </ul>
         */
        /** Builder for {@link DocumentPropertyConfig}. */
        public static final class Builder {
            private final Bundle mBundle = new Bundle();
            private boolean mBuilt = false;
            private final String mPropertyName;
            // TODO(b/181887768): This should be final
            private String mSchemaType;
            private @Cardinality int mCardinality = CARDINALITY_OPTIONAL;
            private boolean mShouldIndexNestedProperties = false;

            /**
             * Creates a new {@link DocumentPropertyConfig.Builder}.
@@ -740,11 +701,8 @@ public final class AppSearchSchema {
             *     Documents of different types cannot be mixed into a single property.
             */
            public Builder(@NonNull String propertyName, @NonNull String schemaType) {
                mBundle.putString(NAME_FIELD, propertyName);
                mBundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_DOCUMENT);
                mBundle.putInt(CARDINALITY_FIELD, CARDINALITY_OPTIONAL);
                mBundle.putBoolean(INDEX_NESTED_PROPERTIES_FIELD, false);
                mBundle.putString(SCHEMA_TYPE_FIELD, schemaType);
                mPropertyName = Objects.requireNonNull(propertyName);
                mSchemaType = Objects.requireNonNull(schemaType);
            }

            /**
@@ -754,10 +712,8 @@ public final class AppSearchSchema {
            @Deprecated
            @UnsupportedAppUsage
            public Builder(@NonNull String propertyName) {
                mBundle.putString(NAME_FIELD, propertyName);
                mBundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_DOCUMENT);
                mBundle.putInt(CARDINALITY_FIELD, CARDINALITY_OPTIONAL);
                mBundle.putBoolean(INDEX_NESTED_PROPERTIES_FIELD, false);
                mPropertyName = Objects.requireNonNull(propertyName);
                mSchemaType = null;
            }

            /**
@@ -768,7 +724,7 @@ public final class AppSearchSchema {
            @UnsupportedAppUsage
            @NonNull
            public Builder setSchemaType(@NonNull String schemaType) {
                mBundle.putString(SCHEMA_TYPE_FIELD, schemaType);
                mSchemaType = Objects.requireNonNull(schemaType);
                return this;
            }

@@ -781,10 +737,9 @@ public final class AppSearchSchema {
            @SuppressWarnings("MissingGetterMatchingBuilder") // getter defined in superclass
            @NonNull
            public DocumentPropertyConfig.Builder setCardinality(@Cardinality int cardinality) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkArgumentInRange(
                        cardinality, CARDINALITY_REPEATED, CARDINALITY_REQUIRED, "cardinality");
                mBundle.putInt(CARDINALITY_FIELD, cardinality);
                mCardinality = cardinality;
                return this;
            }

@@ -798,8 +753,7 @@ public final class AppSearchSchema {
            @NonNull
            public DocumentPropertyConfig.Builder setShouldIndexNestedProperties(
                    boolean indexNestedProperties) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                mBundle.putBoolean(INDEX_NESTED_PROPERTIES_FIELD, indexNestedProperties);
                mShouldIndexNestedProperties = indexNestedProperties;
                return this;
            }

@@ -815,19 +769,18 @@ public final class AppSearchSchema {
                return setShouldIndexNestedProperties(indexNestedProperties);
            }

            /**
             * Constructs a new {@link PropertyConfig} from the contents of this builder.
             *
             * <p>After calling this method, the builder must no longer be used.
             *
             * @throws IllegalStateException if the builder has already been used (e.g. missing
             *     {@code dataType}).
             */
            /** Constructs a new {@link PropertyConfig} from the contents of this builder. */
            @NonNull
            public DocumentPropertyConfig build() {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                mBuilt = true;
                return new DocumentPropertyConfig(mBundle);
                Bundle bundle = new Bundle();
                bundle.putString(NAME_FIELD, mPropertyName);
                bundle.putInt(DATA_TYPE_FIELD, DATA_TYPE_DOCUMENT);
                bundle.putInt(CARDINALITY_FIELD, mCardinality);
                bundle.putBoolean(INDEX_NESTED_PROPERTIES_FIELD, mShouldIndexNestedProperties);
                // TODO(b/181887768): Remove checkNotNull after the deprecated constructor (which
                //  is the only way to get null here) is removed
                bundle.putString(SCHEMA_TYPE_FIELD, Objects.requireNonNull(mSchemaType));
                return new DocumentPropertyConfig(bundle);
            }
        }
    }
+116 −51

File changed.

Preview size limit exceeded, changes collapsed.

+22 −29
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ import android.annotation.NonNull;
import android.util.ArrayMap;
import android.util.ArraySet;

import com.android.internal.util.Preconditions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -102,15 +100,11 @@ public final class GetByDocumentIdRequest {
        return mTypePropertyPathsMap;
    }

    /**
     * Builder for {@link GetByDocumentIdRequest} objects.
     *
     * <p>Once {@link #build} is called, the instance can no longer be used.
     */
    /** Builder for {@link GetByDocumentIdRequest} objects. */
    public static final class Builder {
        private final String mNamespace;
        private final Set<String> mIds = new ArraySet<>();
        private final Map<String, List<String>> mProjectionTypePropertyPaths = new ArrayMap<>();
        private ArraySet<String> mIds = new ArraySet<>();
        private ArrayMap<String, List<String>> mProjectionTypePropertyPaths = new ArrayMap<>();
        private boolean mBuilt = false;

        /** Creates a {@link GetByDocumentIdRequest.Builder} instance. */
@@ -118,26 +112,19 @@ public final class GetByDocumentIdRequest {
            mNamespace = Objects.requireNonNull(namespace);
        }

        /**
         * Adds one or more document IDs to the request.
         *
         * @throws IllegalStateException if the builder has already been used.
         */
        /** Adds one or more document IDs to the request. */
        @NonNull
        public Builder addIds(@NonNull String... ids) {
            Objects.requireNonNull(ids);
            resetIfBuilt();
            return addIds(Arrays.asList(ids));
        }

        /**
         * Adds a collection of IDs to the request.
         *
         * @throws IllegalStateException if the builder has already been used.
         */
        /** Adds a collection of IDs to the request. */
        @NonNull
        public Builder addIds(@NonNull Collection<String> ids) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Objects.requireNonNull(ids);
            resetIfBuilt();
            mIds.addAll(ids);
            return this;
        }
@@ -156,15 +143,14 @@ public final class GetByDocumentIdRequest {
         * apply to all results, excepting any types that have their own, specific property paths
         * set.
         *
         * @throws IllegalStateException if the builder has already been used.
         * @see SearchSpec.Builder#addProjection
         */
        @NonNull
        public Builder addProjection(
                @NonNull String schemaType, @NonNull Collection<String> propertyPaths) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Objects.requireNonNull(schemaType);
            Objects.requireNonNull(propertyPaths);
            resetIfBuilt();
            List<String> propertyPathsList = new ArrayList<>(propertyPaths.size());
            for (String propertyPath : propertyPaths) {
                Objects.requireNonNull(propertyPath);
@@ -174,16 +160,23 @@ public final class GetByDocumentIdRequest {
            return this;
        }

        /**
         * Builds a new {@link GetByDocumentIdRequest}.
         *
         * @throws IllegalStateException if the builder has already been used.
         */
        /** Builds a new {@link GetByDocumentIdRequest}. */
        @NonNull
        public GetByDocumentIdRequest build() {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            mBuilt = true;
            return new GetByDocumentIdRequest(mNamespace, mIds, mProjectionTypePropertyPaths);
            return new GetByDocumentIdRequest(
                    mNamespace, new ArraySet<>(mIds), new ArrayMap<>(mProjectionTypePropertyPaths));
        }

        private void resetIfBuilt() {
            if (mBuilt) {
                mIds = new ArraySet<>(mIds);
                // No need to clone each propertyPathsList inside mProjectionTypePropertyPaths since
                // the builder only replaces it, never adds to it. So even if the builder is used
                // again, the previous one will remain with the object.
                mProjectionTypePropertyPaths = new ArrayMap<>(mProjectionTypePropertyPaths);
                mBuilt = false;
            }
        }
    }
}
+11 −4

File changed.

Preview size limit exceeded, changes collapsed.

+14 −25

File changed.

Preview size limit exceeded, changes collapsed.

Loading