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

Commit 16eea5bb authored by Alexander Dorokhine's avatar Alexander Dorokhine Committed by Automerger Merge Worker
Browse files

Merge "Update framework from jetpack." into sc-v2-dev am: b7e36190

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

Change-Id: I67cb4f636ed17e8e3959fa39d9a28192fbed54de
parents 053bfbfb b7e36190
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -96,6 +96,17 @@ public final class AppSearchBatchResult<KeyType, ValueType> {
        return Collections.unmodifiableMap(mAll);
        return Collections.unmodifiableMap(mAll);
    }
    }


    /**
     * Asserts that this {@link AppSearchBatchResult} has no failures.
     *
     * @hide
     */
    public void checkSuccess() {
        if (!isSuccess()) {
            throw new IllegalStateException("AppSearchBatchResult has failures: " + this);
        }
    }

    @Override
    @Override
    @NonNull
    @NonNull
    public String toString() {
    public String toString() {
+1 −1
Original line number Original line Diff line number Diff line
@@ -71,7 +71,7 @@ public final class SchemaMigrationUtil {


    /**
    /**
     * Checks the setSchema() call won't delete any types or has incompatible types after all {@link
     * Checks the setSchema() call won't delete any types or has incompatible types after all {@link
     * Migrator} has been triggered..
     * Migrator} has been triggered.
     */
     */
    public static void checkDeletedAndIncompatibleAfterMigration(
    public static void checkDeletedAndIncompatibleAfterMigration(
            @NonNull SetSchemaResponse setSchemaResponse, @NonNull Set<String> activeMigrators)
            @NonNull SetSchemaResponse setSchemaResponse, @NonNull Set<String> activeMigrators)
+10 −3
Original line number Original line Diff line number Diff line
@@ -363,6 +363,7 @@ public class AppSearchManagerService extends SystemService {
                        schemasVisibleToPackages.put(entry.getKey(), packageIdentifiers);
                        schemasVisibleToPackages.put(entry.getKey(), packageIdentifiers);
                    }
                    }
                    instance = mAppSearchUserInstanceManager.getUserInstance(targetUser);
                    instance = mAppSearchUserInstanceManager.getUserInstance(targetUser);
                    // TODO(b/173532925): Implement logging for statsBuilder
                    SetSchemaResponse setSchemaResponse = instance.getAppSearchImpl().setSchema(
                    SetSchemaResponse setSchemaResponse = instance.getAppSearchImpl().setSchema(
                            packageName,
                            packageName,
                            databaseName,
                            databaseName,
@@ -371,7 +372,8 @@ public class AppSearchManagerService extends SystemService {
                            schemasNotDisplayedBySystem,
                            schemasNotDisplayedBySystem,
                            schemasVisibleToPackages,
                            schemasVisibleToPackages,
                            forceOverride,
                            forceOverride,
                            schemaVersion);
                            schemaVersion,
                            /*setSchemaStatsBuilder=*/ null);
                    ++operationSuccessCount;
                    ++operationSuccessCount;
                    invokeCallbackOnResult(callback,
                    invokeCallbackOnResult(callback,
                            AppSearchResult.newSuccessfulResult(setSchemaResponse.getBundle()));
                            AppSearchResult.newSuccessfulResult(setSchemaResponse.getBundle()));
@@ -816,8 +818,10 @@ public class AppSearchManagerService extends SystemService {


                    AppSearchUserInstance instance =
                    AppSearchUserInstance instance =
                            mAppSearchUserInstanceManager.getUserInstance(targetUser);
                            mAppSearchUserInstanceManager.getUserInstance(targetUser);
                    // TODO(b/173532925): Implement logging for statsBuilder
                    SearchResultPage searchResultPage =
                    SearchResultPage searchResultPage =
                            instance.getAppSearchImpl().getNextPage(packageName, nextPageToken);
                            instance.getAppSearchImpl().getNextPage(
                                    packageName, nextPageToken, /*statsBuilder=*/ null);
                    invokeCallbackOnResult(
                    invokeCallbackOnResult(
                            callback,
                            callback,
                            AppSearchResult.newSuccessfulResult(searchResultPage.getBundle()));
                            AppSearchResult.newSuccessfulResult(searchResultPage.getBundle()));
@@ -898,8 +902,11 @@ public class AppSearchManagerService extends SystemService {
                                        outputStream, searchResultPage.getResults().get(i)
                                        outputStream, searchResultPage.getResults().get(i)
                                                .getGenericDocument().getBundle());
                                                .getGenericDocument().getBundle());
                            }
                            }
                            // TODO(b/173532925): Implement logging for statsBuilder
                            searchResultPage = instance.getAppSearchImpl().getNextPage(
                            searchResultPage = instance.getAppSearchImpl().getNextPage(
                                    packageName, searchResultPage.getNextPageToken());
                                    packageName,
                                    searchResultPage.getNextPageToken(),
                                    /*statsBuilder=*/ null);
                        }
                        }
                    }
                    }
                    invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null));
                    invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null));
+40 −5
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.server.appsearch.external.localstorage.stats.OptimizeStats;
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
import com.android.server.appsearch.external.localstorage.stats.SetSchemaStats;
import com.android.server.appsearch.external.localstorage.visibilitystore.VisibilityStore;
import com.android.server.appsearch.external.localstorage.visibilitystore.VisibilityStore;


import com.google.android.icing.IcingSearchEngine;
import com.google.android.icing.IcingSearchEngine;
@@ -393,6 +394,7 @@ public final class AppSearchImpl implements Closeable {
     * @param forceOverride Whether to force-apply the schema even if it is incompatible. Documents
     * @param forceOverride Whether to force-apply the schema even if it is incompatible. Documents
     *     which do not comply with the new schema will be deleted.
     *     which do not comply with the new schema will be deleted.
     * @param version The overall version number of the request.
     * @param version The overall version number of the request.
     * @param setSchemaStatsBuilder Builder for {@link SetSchemaStats} to hold stats for setSchema
     * @return The response contains deleted schema types and incompatible schema types of this
     * @return The response contains deleted schema types and incompatible schema types of this
     *     call.
     *     call.
     * @throws AppSearchException On IcingSearchEngine error. If the status code is
     * @throws AppSearchException On IcingSearchEngine error. If the status code is
@@ -408,7 +410,8 @@ public final class AppSearchImpl implements Closeable {
            @NonNull List<String> schemasNotDisplayedBySystem,
            @NonNull List<String> schemasNotDisplayedBySystem,
            @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages,
            @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages,
            boolean forceOverride,
            boolean forceOverride,
            int version)
            int version,
            @Nullable SetSchemaStats.Builder setSchemaStatsBuilder)
            throws AppSearchException {
            throws AppSearchException {
        mReadWriteLock.writeLock().lock();
        mReadWriteLock.writeLock().lock();
        try {
        try {
@@ -438,6 +441,12 @@ public final class AppSearchImpl implements Closeable {
            mLogUtil.piiTrace(
            mLogUtil.piiTrace(
                    "setSchema, response", setSchemaResultProto.getStatus(), setSchemaResultProto);
                    "setSchema, response", setSchemaResultProto.getStatus(), setSchemaResultProto);


            if (setSchemaStatsBuilder != null) {
                setSchemaStatsBuilder.setStatusCode(
                        statusProtoToResultCode(setSchemaResultProto.getStatus()));
                AppSearchLoggerHelper.copyNativeStats(setSchemaResultProto, setSchemaStatsBuilder);
            }

            // Determine whether it succeeded.
            // Determine whether it succeeded.
            try {
            try {
                checkSuccess(setSchemaResultProto.getStatus());
                checkSuccess(setSchemaResultProto.getStatus());
@@ -1127,8 +1136,13 @@ public final class AppSearchImpl implements Closeable {
     * @throws AppSearchException on IcingSearchEngine error or if can't advance on nextPageToken.
     * @throws AppSearchException on IcingSearchEngine error or if can't advance on nextPageToken.
     */
     */
    @NonNull
    @NonNull
    public SearchResultPage getNextPage(@NonNull String packageName, long nextPageToken)
    public SearchResultPage getNextPage(
            @NonNull String packageName,
            long nextPageToken,
            @Nullable SearchStats.Builder statsBuilder)
            throws AppSearchException {
            throws AppSearchException {
        long totalLatencyStartMillis = SystemClock.elapsedRealtime();

        mReadWriteLock.readLock().lock();
        mReadWriteLock.readLock().lock();
        try {
        try {
            throwIfClosedLocked();
            throwIfClosedLocked();
@@ -1137,6 +1151,13 @@ public final class AppSearchImpl implements Closeable {
            checkNextPageToken(packageName, nextPageToken);
            checkNextPageToken(packageName, nextPageToken);
            SearchResultProto searchResultProto =
            SearchResultProto searchResultProto =
                    mIcingSearchEngineLocked.getNextPage(nextPageToken);
                    mIcingSearchEngineLocked.getNextPage(nextPageToken);

            if (statsBuilder != null) {
                statsBuilder.setStatusCode(statusProtoToResultCode(searchResultProto.getStatus()));
                AppSearchLoggerHelper.copyNativeStats(
                        searchResultProto.getQueryStats(), statsBuilder);
            }

            mLogUtil.piiTrace(
            mLogUtil.piiTrace(
                    "getNextPage, response",
                    "getNextPage, response",
                    searchResultProto.getResultsCount(),
                    searchResultProto.getResultsCount(),
@@ -1152,9 +1173,22 @@ public final class AppSearchImpl implements Closeable {
                    mNextPageTokensLocked.get(packageName).remove(nextPageToken);
                    mNextPageTokensLocked.get(packageName).remove(nextPageToken);
                }
                }
            }
            }
            return rewriteSearchResultProto(searchResultProto, mSchemaMapLocked);
            long rewriteSearchResultLatencyStartMillis = SystemClock.elapsedRealtime();
            SearchResultPage resultPage =
                    rewriteSearchResultProto(searchResultProto, mSchemaMapLocked);
            if (statsBuilder != null) {
                statsBuilder.setRewriteSearchResultLatencyMillis(
                        (int)
                                (SystemClock.elapsedRealtime()
                                        - rewriteSearchResultLatencyStartMillis));
            }
            return resultPage;
        } finally {
        } finally {
            mReadWriteLock.readLock().unlock();
            mReadWriteLock.readLock().unlock();
            if (statsBuilder != null) {
                statsBuilder.setTotalLatencyMillis(
                        (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis));
            }
        }
        }
    }
    }


@@ -1334,7 +1368,7 @@ public final class AppSearchImpl implements Closeable {
                        statusProtoToResultCode(deleteResultProto.getStatus()));
                        statusProtoToResultCode(deleteResultProto.getStatus()));
                // TODO(b/187206766) also log query stats here once IcingLib returns it
                // TODO(b/187206766) also log query stats here once IcingLib returns it
                AppSearchLoggerHelper.copyNativeStats(
                AppSearchLoggerHelper.copyNativeStats(
                        deleteResultProto.getDeleteStats(), removeStatsBuilder);
                        deleteResultProto.getDeleteByQueryStats(), removeStatsBuilder);
            }
            }


            // It seems that the caller wants to get success if the data matching the query is
            // It seems that the caller wants to get success if the data matching the query is
@@ -1343,7 +1377,8 @@ public final class AppSearchImpl implements Closeable {
                    deleteResultProto.getStatus(), StatusProto.Code.OK, StatusProto.Code.NOT_FOUND);
                    deleteResultProto.getStatus(), StatusProto.Code.OK, StatusProto.Code.NOT_FOUND);


            // Update derived maps
            // Update derived maps
            int numDocumentsDeleted = deleteResultProto.getDeleteStats().getNumDocumentsDeleted();
            int numDocumentsDeleted =
                    deleteResultProto.getDeleteByQueryStats().getNumDocumentsDeleted();
            updateDocumentCountAfterRemovalLocked(packageName, numDocumentsDeleted);
            updateDocumentCountAfterRemovalLocked(packageName, numDocumentsDeleted);
        } finally {
        } finally {
            mReadWriteLock.writeLock().unlock();
            mReadWriteLock.writeLock().unlock();
+4 −0
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.server.appsearch.external.localstorage.stats.OptimizeStats;
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats;
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
import com.android.server.appsearch.external.localstorage.stats.RemoveStats;
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
import com.android.server.appsearch.external.localstorage.stats.SearchStats;
import com.android.server.appsearch.external.localstorage.stats.SetSchemaStats;


/**
/**
 * An interface for implementing client-defined logging AppSearch operations stats.
 * An interface for implementing client-defined logging AppSearch operations stats.
@@ -54,5 +55,8 @@ public interface AppSearchLogger {
    /** Logs {@link OptimizeStats} */
    /** Logs {@link OptimizeStats} */
    void logStats(@NonNull OptimizeStats stats);
    void logStats(@NonNull OptimizeStats stats);


    /** Logs {@link SetSchemaStats} */
    void logStats(@NonNull SetSchemaStats stats);

    // TODO(b/173532925) Add remaining logStats once we add all the stats.
    // TODO(b/173532925) Add remaining logStats once we add all the stats.
}
}
Loading