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

Commit 1e258ecf authored by Alexander Dorokhine's avatar Alexander Dorokhine Committed by Android (Google) Code Review
Browse files

Merge "Update framework from jetpack." into sc-dev

parents 2d4f2324 e85e9ef2
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import java.util.Objects;
 * @param <ValueType> The type of result object for successful calls.
 */
public final class AppSearchResult<ValueType> implements Parcelable {
    private static final String TAG = "AppSearchResult";

    /**
     * Result codes from {@link AppSearchSession} methods.
     * @hide
@@ -246,14 +248,22 @@ public final class AppSearchResult<ValueType> implements Parcelable {
    @NonNull
    public static <ValueType> AppSearchResult<ValueType> throwableToFailedResult(
            @NonNull Throwable t) {
        Log.d("AppSearchResult", "Converting throwable to failed result.", t);
        // Log for traceability. NOT_FOUND is logged at VERBOSE because this error can occur during
        // the regular operation of the system (b/183550974). Everything else is logged at DEBUG.
        if (t instanceof AppSearchException
                && ((AppSearchException) t).getResultCode() == RESULT_NOT_FOUND) {
            Log.v(TAG, "Converting throwable to failed result: " + t);
        } else {
            Log.d(TAG, "Converting throwable to failed result.", t);
        }

        if (t instanceof AppSearchException) {
            return ((AppSearchException) t).toAppSearchResult();
        }

        String exceptionClass = t.getClass().getSimpleName();
        @AppSearchResult.ResultCode int resultCode;
        if (t instanceof IllegalStateException) {
        if (t instanceof IllegalStateException || t instanceof NullPointerException) {
            resultCode = AppSearchResult.RESULT_INTERNAL_ERROR;
        } else if (t instanceof IllegalArgumentException) {
            resultCode = AppSearchResult.RESULT_INVALID_ARGUMENT;
@@ -262,6 +272,6 @@ public final class AppSearchResult<ValueType> implements Parcelable {
        } else {
            resultCode = AppSearchResult.RESULT_UNKNOWN_ERROR;
        }
        return AppSearchResult.newFailedResult(resultCode, t.getMessage());
        return AppSearchResult.newFailedResult(resultCode, exceptionClass + ": " + t.getMessage());
    }
}
+6 −6
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public final class AppSearchSchema {

    /** @hide */
    public AppSearchSchema(@NonNull Bundle bundle) {
        Preconditions.checkNotNull(bundle);
        Objects.requireNonNull(bundle);
        mBundle = bundle;
    }

@@ -125,7 +125,7 @@ public final class AppSearchSchema {

        /** Creates a new {@link AppSearchSchema.Builder}. */
        public Builder(@NonNull String schemaType) {
            Preconditions.checkNotNull(schemaType);
            Objects.requireNonNull(schemaType);
            mSchemaType = schemaType;
        }

@@ -133,7 +133,7 @@ public final class AppSearchSchema {
        @NonNull
        public AppSearchSchema.Builder addProperty(@NonNull PropertyConfig propertyConfig) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(propertyConfig);
            Objects.requireNonNull(propertyConfig);
            String name = propertyConfig.getName();
            if (!mPropertyNames.add(name)) {
                throw new IllegalSchemaException("Property defined more than once: " + name);
@@ -246,7 +246,7 @@ public final class AppSearchSchema {
        @Nullable private Integer mHashCode;

        PropertyConfig(@NonNull Bundle bundle) {
            mBundle = Preconditions.checkNotNull(bundle);
            mBundle = Objects.requireNonNull(bundle);
        }

        @Override
@@ -712,7 +712,7 @@ public final class AppSearchSchema {
        /** Returns the logical schema-type of the contents of this document property. */
        @NonNull
        public String getSchemaType() {
            return Preconditions.checkNotNull(mBundle.getString(SCHEMA_TYPE_FIELD));
            return Objects.requireNonNull(mBundle.getString(SCHEMA_TYPE_FIELD));
        }

        /**
@@ -755,7 +755,7 @@ public final class AppSearchSchema {
            @NonNull
            public DocumentPropertyConfig.Builder setSchemaType(@NonNull String schemaType) {
                Preconditions.checkState(!mBuilt, "Builder has already been used");
                Preconditions.checkNotNull(schemaType);
                Objects.requireNonNull(schemaType);
                mBundle.putString(SCHEMA_TYPE_FIELD, schemaType);
                return this;
            }
+37 −41
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;

/**
@@ -101,11 +102,11 @@ public class GenericDocument {
     * @hide
     */
    public GenericDocument(@NonNull Bundle bundle) {
        Preconditions.checkNotNull(bundle);
        Objects.requireNonNull(bundle);
        mBundle = bundle;
        mProperties = Preconditions.checkNotNull(bundle.getParcelable(PROPERTIES_FIELD));
        mUri = Preconditions.checkNotNull(mBundle.getString(URI_FIELD));
        mSchemaType = Preconditions.checkNotNull(mBundle.getString(SCHEMA_TYPE_FIELD));
        mProperties = Objects.requireNonNull(bundle.getParcelable(PROPERTIES_FIELD));
        mUri = Objects.requireNonNull(mBundle.getString(URI_FIELD));
        mSchemaType = Objects.requireNonNull(mBundle.getString(SCHEMA_TYPE_FIELD));
        mCreationTimestampMillis =
                mBundle.getLong(CREATION_TIMESTAMP_MILLIS_FIELD, System.currentTimeMillis());
    }
@@ -199,7 +200,7 @@ public class GenericDocument {
     */
    @Nullable
    public Object getProperty(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        Object property = mProperties.get(key);
        if (property instanceof ArrayList) {
            return getPropertyBytesArray(key);
@@ -218,7 +219,7 @@ public class GenericDocument {
     */
    @Nullable
    public String getPropertyString(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        String[] propertyArray = getPropertyStringArray(key);
        if (propertyArray == null || propertyArray.length == 0) {
            return null;
@@ -235,7 +236,7 @@ public class GenericDocument {
     *     there is no such key or the value is of a different type.
     */
    public long getPropertyLong(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        long[] propertyArray = getPropertyLongArray(key);
        if (propertyArray == null || propertyArray.length == 0) {
            return 0;
@@ -252,7 +253,7 @@ public class GenericDocument {
     *     if there is no such key or the value is of a different type.
     */
    public double getPropertyDouble(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        double[] propertyArray = getPropertyDoubleArray(key);
        if (propertyArray == null || propertyArray.length == 0) {
            return 0.0;
@@ -269,7 +270,7 @@ public class GenericDocument {
     *     false} if there is no such key or the value is of a different type.
     */
    public boolean getPropertyBoolean(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        boolean[] propertyArray = getPropertyBooleanArray(key);
        if (propertyArray == null || propertyArray.length == 0) {
            return false;
@@ -287,7 +288,7 @@ public class GenericDocument {
     */
    @Nullable
    public byte[] getPropertyBytes(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        byte[][] propertyArray = getPropertyBytesArray(key);
        if (propertyArray == null || propertyArray.length == 0) {
            return null;
@@ -305,7 +306,7 @@ public class GenericDocument {
     */
    @Nullable
    public GenericDocument getPropertyDocument(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        GenericDocument[] propertyArray = getPropertyDocumentArray(key);
        if (propertyArray == null || propertyArray.length == 0) {
            return null;
@@ -342,7 +343,7 @@ public class GenericDocument {
     */
    @Nullable
    public String[] getPropertyStringArray(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        return getAndCastPropertyArray(key, String[].class);
    }

@@ -355,7 +356,7 @@ public class GenericDocument {
     */
    @Nullable
    public long[] getPropertyLongArray(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        return getAndCastPropertyArray(key, long[].class);
    }

@@ -368,7 +369,7 @@ public class GenericDocument {
     */
    @Nullable
    public double[] getPropertyDoubleArray(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        return getAndCastPropertyArray(key, double[].class);
    }

@@ -381,7 +382,7 @@ public class GenericDocument {
     */
    @Nullable
    public boolean[] getPropertyBooleanArray(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        return getAndCastPropertyArray(key, boolean[].class);
    }

@@ -396,7 +397,7 @@ public class GenericDocument {
    @Nullable
    @SuppressWarnings("unchecked")
    public byte[][] getPropertyBytesArray(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        ArrayList<Bundle> bundles = getAndCastPropertyArray(key, ArrayList.class);
        if (bundles == null || bundles.size() == 0) {
            return null;
@@ -428,7 +429,7 @@ public class GenericDocument {
    @SuppressLint("ArrayReturn")
    @Nullable
    public GenericDocument[] getPropertyDocumentArray(@NonNull String key) {
        Preconditions.checkNotNull(key);
        Objects.requireNonNull(key);
        Parcelable[] bundles = getAndCastPropertyArray(key, Parcelable[].class);
        if (bundles == null || bundles.length == 0) {
            return null;
@@ -591,9 +592,9 @@ public class GenericDocument {
         */
        @SuppressWarnings("unchecked")
        public Builder(@NonNull String namespace, @NonNull String uri, @NonNull String schemaType) {
            Preconditions.checkNotNull(namespace);
            Preconditions.checkNotNull(uri);
            Preconditions.checkNotNull(schemaType);
            Objects.requireNonNull(namespace);
            Objects.requireNonNull(uri);
            Objects.requireNonNull(schemaType);
            mBuilderTypeInstance = (BuilderType) this;
            mBundle.putString(GenericDocument.NAMESPACE_FIELD, namespace);
            mBundle.putString(GenericDocument.URI_FIELD, uri);
@@ -682,8 +683,8 @@ public class GenericDocument {
        @NonNull
        public BuilderType setPropertyString(@NonNull String key, @NonNull String... values) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(key);
            Preconditions.checkNotNull(values);
            Objects.requireNonNull(key);
            Objects.requireNonNull(values);
            putInPropertyBundle(key, values);
            return mBuilderTypeInstance;
        }
@@ -694,15 +695,14 @@ public class GenericDocument {
         *
         * @param key the key associated with the {@code values}.
         * @param values the {@code boolean} values of the property.
         * @throws IllegalArgumentException if no values are provided or if values exceed maximum
         *     repeated property length.
         * @throws IllegalArgumentException if values exceed maximum repeated property length.
         * @throws IllegalStateException if the builder has already been used.
         */
        @NonNull
        public BuilderType setPropertyBoolean(@NonNull String key, @NonNull boolean... values) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(key);
            Preconditions.checkNotNull(values);
            Objects.requireNonNull(key);
            Objects.requireNonNull(values);
            putInPropertyBundle(key, values);
            return mBuilderTypeInstance;
        }
@@ -712,15 +712,14 @@ public class GenericDocument {
         *
         * @param key the key associated with the {@code values}.
         * @param values the {@code long} values of the property.
         * @throws IllegalArgumentException if no values are provided or if values exceed maximum
         *     repeated property length.
         * @throws IllegalArgumentException if values exceed maximum repeated property length.
         * @throws IllegalStateException if the builder has already been used.
         */
        @NonNull
        public BuilderType setPropertyLong(@NonNull String key, @NonNull long... values) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(key);
            Preconditions.checkNotNull(values);
            Objects.requireNonNull(key);
            Objects.requireNonNull(values);
            putInPropertyBundle(key, values);
            return mBuilderTypeInstance;
        }
@@ -730,15 +729,14 @@ public class GenericDocument {
         *
         * @param key the key associated with the {@code values}.
         * @param values the {@code double} values of the property.
         * @throws IllegalArgumentException if no values are provided or if values exceed maximum
         *     repeated property length.
         * @throws IllegalArgumentException if values exceed maximum repeated property length.
         * @throws IllegalStateException if the builder has already been used.
         */
        @NonNull
        public BuilderType setPropertyDouble(@NonNull String key, @NonNull double... values) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(key);
            Preconditions.checkNotNull(values);
            Objects.requireNonNull(key);
            Objects.requireNonNull(values);
            putInPropertyBundle(key, values);
            return mBuilderTypeInstance;
        }
@@ -755,8 +753,8 @@ public class GenericDocument {
        @NonNull
        public BuilderType setPropertyBytes(@NonNull String key, @NonNull byte[]... values) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(key);
            Preconditions.checkNotNull(values);
            Objects.requireNonNull(key);
            Objects.requireNonNull(values);
            putInPropertyBundle(key, values);
            return mBuilderTypeInstance;
        }
@@ -776,8 +774,8 @@ public class GenericDocument {
        public BuilderType setPropertyDocument(
                @NonNull String key, @NonNull GenericDocument... values) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(key);
            Preconditions.checkNotNull(values);
            Objects.requireNonNull(key);
            Objects.requireNonNull(values);
            putInPropertyBundle(key, values);
            return mBuilderTypeInstance;
        }
@@ -850,9 +848,7 @@ public class GenericDocument {
        }

        private static void validateRepeatedPropertyLength(@NonNull String key, int length) {
            if (length == 0) {
                throw new IllegalArgumentException("The input array is empty.");
            } else if (length > MAX_REPEATED_PROPERTY_LENGTH) {
            if (length > MAX_REPEATED_PROPERTY_LENGTH) {
                throw new IllegalArgumentException(
                        "Repeated property \""
                                + key
+10 −9
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
@@ -52,9 +53,9 @@ public final class GetByUriRequest {
            @NonNull String namespace,
            @NonNull Set<String> uris,
            @NonNull Map<String, List<String>> typePropertyPathsMap) {
        mNamespace = Preconditions.checkNotNull(namespace);
        mUris = Preconditions.checkNotNull(uris);
        mTypePropertyPathsMap = Preconditions.checkNotNull(typePropertyPathsMap);
        mNamespace = Objects.requireNonNull(namespace);
        mUris = Objects.requireNonNull(uris);
        mTypePropertyPathsMap = Objects.requireNonNull(typePropertyPathsMap);
    }

    /** Returns the namespace attached to the request. */
@@ -114,7 +115,7 @@ public final class GetByUriRequest {

        /** Creates a {@link GetByUriRequest.Builder} instance. */
        public Builder(@NonNull String namespace) {
            mNamespace = Preconditions.checkNotNull(namespace);
            mNamespace = Objects.requireNonNull(namespace);
        }

        /**
@@ -124,7 +125,7 @@ public final class GetByUriRequest {
         */
        @NonNull
        public Builder addUris(@NonNull String... uris) {
            Preconditions.checkNotNull(uris);
            Objects.requireNonNull(uris);
            return addUris(Arrays.asList(uris));
        }

@@ -136,7 +137,7 @@ public final class GetByUriRequest {
        @NonNull
        public Builder addUris(@NonNull Collection<String> uris) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(uris);
            Objects.requireNonNull(uris);
            mUris.addAll(uris);
            return this;
        }
@@ -161,11 +162,11 @@ public final class GetByUriRequest {
        public Builder addProjection(
                @NonNull String schemaType, @NonNull Collection<String> propertyPaths) {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
            Preconditions.checkNotNull(schemaType);
            Preconditions.checkNotNull(propertyPaths);
            Objects.requireNonNull(schemaType);
            Objects.requireNonNull(propertyPaths);
            List<String> propertyPathsList = new ArrayList<>(propertyPaths.size());
            for (String propertyPath : propertyPaths) {
                Preconditions.checkNotNull(propertyPath);
                Objects.requireNonNull(propertyPath);
                propertyPathsList.add(propertyPath);
            }
            mProjectionTypePropertyPaths.put(schemaType, propertyPathsList);
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.util.ArraySet;
import com.android.internal.util.Preconditions;

import java.util.ArrayList;
import java.util.Objects;
import java.util.Set;

/** The response class of {@link AppSearchSession#getSchema} */
@@ -34,7 +35,7 @@ public class GetSchemaResponse {
    private final Bundle mBundle;

    GetSchemaResponse(@NonNull Bundle bundle) {
        mBundle = Preconditions.checkNotNull(bundle);
        mBundle = Objects.requireNonNull(bundle);
    }

    /**
Loading