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

Commit 736cf72f 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 c7d31594 43fe0b1b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -583,9 +583,9 @@ public class GenericDocument {
         * @param schemaType the {@link AppSearchSchema} type of the {@link GenericDocument}. The
         *     provided {@code schemaType} must be defined using {@link AppSearchSession#setSchema}
         *     prior to inserting a document of this {@code schemaType} into the AppSearch index
         *     using {@link AppSearchSession#put}. Otherwise, the document will
         *     be rejected by {@link AppSearchSession#put} with result code
         *     {@link AppSearchResult#RESULT_NOT_FOUND}.
         *     using {@link AppSearchSession#put}. Otherwise, the document will be rejected by
         *     {@link AppSearchSession#put} with result code {@link
         *     AppSearchResult#RESULT_NOT_FOUND}.
         */
        @SuppressWarnings("unchecked")
        public Builder(@NonNull String uri, @NonNull String schemaType) {
+19 −5
Original line number Diff line number Diff line
@@ -28,9 +28,11 @@ import java.util.Collections;
import java.util.List;

/**
 * Encapsulates a request to index a document into an {@link AppSearchSession} database.
 * Encapsulates a request to index documents into an {@link AppSearchSession} database.
 *
 * <p>@see AppSearchSession#putDocuments
 *
 * @see AppSearchSession#put
 */
public final class PutDocumentsRequest {
    private final List<GenericDocument> mDocuments;
@@ -39,7 +41,7 @@ public final class PutDocumentsRequest {
        mDocuments = documents;
    }

    /** Returns the documents that are part of this request. */
    /** Returns a list of {@link GenericDocument} objects that are part of this request. */
    @NonNull
    public List<GenericDocument> getGenericDocuments() {
        return Collections.unmodifiableList(mDocuments);
@@ -54,14 +56,22 @@ public final class PutDocumentsRequest {
        private final List<GenericDocument> mDocuments = new ArrayList<>();
        private boolean mBuilt = false;

        /** Adds one or more {@link GenericDocument} objects to the request. */
        /**
         * Adds one or more {@link GenericDocument} objects to the request.
         *
         * @throws IllegalStateException if the builder has already been used.
         */
        @NonNull
        public Builder addGenericDocuments(@NonNull GenericDocument... documents) {
            Preconditions.checkNotNull(documents);
            return addGenericDocuments(Arrays.asList(documents));
        }

        /** Adds a collection of {@link GenericDocument} objects to the request. */
        /**
         * Adds a collection of {@link GenericDocument} objects to the request.
         *
         * @throws IllegalStateException if the builder has already been used.
         */
        @NonNull
        public Builder addGenericDocuments(
                @NonNull Collection<? extends GenericDocument> documents) {
@@ -71,7 +81,11 @@ public final class PutDocumentsRequest {
            return this;
        }

        /** Creates a new {@link PutDocumentsRequest} object. */
        /**
         * Creates a new {@link PutDocumentsRequest} object.
         *
         * @throws IllegalStateException if the builder has already been used.
         */
        @NonNull
        public PutDocumentsRequest build() {
            Preconditions.checkState(!mBuilt, "Builder has already been used");
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.appsearch.external.localstorage;

import android.annotation.NonNull;
import android.app.appsearch.exceptions.AppSearchException;

import com.android.server.appsearch.external.localstorage.stats.CallStats;
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;

/**
 * An interface for implementing client-defined logging AppSearch operations stats.
 *
 * <p>Any implementation needs to provide general information on how to log all the stats types.
 * (e.g. {@link CallStats})
 *
 * <p>All implementations of this interface must be thread safe.
 *
 * @hide
 */
public interface AppSearchLogger {
    /** Logs {@link CallStats} */
    void logStats(@NonNull CallStats stats) throws AppSearchException;

    /** Logs {@link PutDocumentStats} */
    void logStats(@NonNull PutDocumentStats stats) throws AppSearchException;

    // TODO(b/173532925) Add remaining logStats once we add all the stats.
}
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ class AppSearchMigrationHelperImpl implements AppSearchMigrationHelper {
        int currentVersion = mCurrentVersionMap.get(schemaType);
        int finalVersion = mFinalVersionMap.get(schemaType);
        try (FileOutputStream outputStream = new FileOutputStream(mFile)) {
            // TODO(b/177266929) change the output stream so that we can use it in platform
            // TODO(b/151178558) change the output stream so that we can use it in platform
            CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(outputStream);
            SearchResultPage searchResultPage =
                    mAppSearchImpl.query(
+200 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.appsearch.external.localstorage.stats;

import android.annotation.IntDef;
import android.annotation.NonNull;

import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * A class for setting basic information to log for all function calls.
 *
 * <p>This class can set which stats to log for both batch and non-batch {@link
 * android.app.appsearch.AppSearchSession} calls.
 *
 * <p>Some function calls like {@link android.app.appsearch.AppSearchSession#setSchema} have their
 * own detailed stats class {@link placeholder}. However, {@link CallStats} can still be used along
 * with the detailed stats class for easy aggregation/analysis with other function calls.
 *
 * @hide
 */
public class CallStats {
    @IntDef(
            value = {
                CALL_TYPE_UNKNOWN,
                CALL_TYPE_INITIALIZE,
                CALL_TYPE_SET_SCHEMA,
                CALL_TYPE_PUT_DOCUMENTS,
                CALL_TYPE_GET_DOCUMENTS,
                CALL_TYPE_REMOVE_DOCUMENTS,
                CALL_TYPE_PUT_DOCUMENT,
                CALL_TYPE_GET_DOCUMENT,
                CALL_TYPE_REMOVE_DOCUMENT,
                CALL_TYPE_QUERY,
                CALL_TYPE_OPTIMIZE,
                CALL_TYPE_FLUSH,
            })
    @Retention(RetentionPolicy.SOURCE)
    public @interface CallType {}

    public static final int CALL_TYPE_UNKNOWN = 0;
    public static final int CALL_TYPE_INITIALIZE = 1;
    public static final int CALL_TYPE_SET_SCHEMA = 2;
    public static final int CALL_TYPE_PUT_DOCUMENTS = 3;
    public static final int CALL_TYPE_GET_DOCUMENTS = 4;
    public static final int CALL_TYPE_REMOVE_DOCUMENTS = 5;
    public static final int CALL_TYPE_PUT_DOCUMENT = 6;
    public static final int CALL_TYPE_GET_DOCUMENT = 7;
    public static final int CALL_TYPE_REMOVE_DOCUMENT = 8;
    public static final int CALL_TYPE_QUERY = 9;
    public static final int CALL_TYPE_OPTIMIZE = 10;
    public static final int CALL_TYPE_FLUSH = 11;

    @NonNull private final GeneralStats mGeneralStats;
    @CallType private final int mCallType;
    private final int mEstimatedBinderLatencyMillis;
    private final int mNumOperationsSucceeded;
    private final int mNumOperationsFailed;

    CallStats(@NonNull Builder builder) {
        Preconditions.checkNotNull(builder);
        mGeneralStats = Preconditions.checkNotNull(builder.mGeneralStats);
        mCallType = builder.mCallType;
        mEstimatedBinderLatencyMillis = builder.mEstimatedBinderLatencyMillis;
        mNumOperationsSucceeded = builder.mNumOperationsSucceeded;
        mNumOperationsFailed = builder.mNumOperationsFailed;
    }

    /** Returns general information for the call. */
    @NonNull
    public GeneralStats getGeneralStats() {
        return mGeneralStats;
    }

    /** Returns type of the call. */
    @CallType
    public int getCallType() {
        return mCallType;
    }

    /** Returns estimated binder latency, in milliseconds */
    public int getEstimatedBinderLatencyMillis() {
        return mEstimatedBinderLatencyMillis;
    }

    /**
     * Returns number of operations succeeded.
     *
     * <p>For example, for {@link android.app.appsearch.AppSearchSession#put}, it is the total
     * number of individual successful put operations. In this case, how many documents are
     * successfully indexed.
     *
     * <p>For non-batch calls such as {@link android.app.appsearch.AppSearchSession#setSchema}, the
     * sum of {@link CallStats#getNumOperationsSucceeded()} and {@link
     * CallStats#getNumOperationsFailed()} is always 1 since there is only one operation.
     */
    public int getNumOperationsSucceeded() {
        return mNumOperationsSucceeded;
    }

    /**
     * Returns number of operations failed.
     *
     * <p>For example, for {@link android.app.appsearch.AppSearchSession#put}, it is the total
     * number of individual failed put operations. In this case, how many documents are failed to be
     * indexed.
     *
     * <p>For non-batch calls such as {@link android.app.appsearch.AppSearchSession#setSchema}, the
     * sum of {@link CallStats#getNumOperationsSucceeded()} and {@link
     * CallStats#getNumOperationsFailed()} is always 1 since there is only one operation.
     */
    public int getNumOperationsFailed() {
        return mNumOperationsFailed;
    }

    /** Builder for {@link CallStats}. */
    public static class Builder {
        @NonNull final GeneralStats mGeneralStats;
        @CallType int mCallType;
        int mEstimatedBinderLatencyMillis;
        int mNumOperationsSucceeded;
        int mNumOperationsFailed;

        /** Builder takes {@link GeneralStats} to hold general stats. */
        public Builder(@NonNull GeneralStats generalStats) {
            mGeneralStats = Preconditions.checkNotNull(generalStats);
        }

        /** Sets type of the call. */
        @NonNull
        public Builder setCallType(@CallType int callType) {
            mCallType = callType;
            return this;
        }

        /** Sets estimated binder latency, in milliseconds. */
        @NonNull
        public Builder setEstimatedBinderLatencyMillis(int estimatedBinderLatencyMillis) {
            mEstimatedBinderLatencyMillis = estimatedBinderLatencyMillis;
            return this;
        }

        /**
         * Sets number of operations succeeded.
         *
         * <p>For example, for {@link android.app.appsearch.AppSearchSession#put}, it is the total
         * number of individual successful put operations. In this case, how many documents are
         * successfully indexed.
         *
         * <p>For non-batch calls such as {@link android.app.appsearch.AppSearchSession#setSchema},
         * the sum of {@link CallStats#getNumOperationsSucceeded()} and {@link
         * CallStats#getNumOperationsFailed()} is always 1 since there is only one operation.
         */
        @NonNull
        public Builder setNumOperationsSucceeded(int numOperationsSucceeded) {
            mNumOperationsSucceeded = numOperationsSucceeded;
            return this;
        }

        /**
         * Sets number of operations failed.
         *
         * <p>For example, for {@link android.app.appsearch.AppSearchSession#put}, it is the total
         * number of individual failed put operations. In this case, how many documents are failed
         * to be indexed.
         *
         * <p>For non-batch calls such as {@link android.app.appsearch.AppSearchSession#setSchema},
         * the sum of {@link CallStats#getNumOperationsSucceeded()} and {@link
         * CallStats#getNumOperationsFailed()} is always 1 since there is only one operation.
         */
        @NonNull
        public Builder setNumOperationsFailed(int numOperationsFailed) {
            mNumOperationsFailed = numOperationsFailed;
            return this;
        }

        /** Creates {@link CallStats} object from {@link Builder} instance. */
        @NonNull
        public CallStats build() {
            return new CallStats(/* builder= */ this);
        }
    }
}
Loading