Loading apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java +17 −2 Original line number Diff line number Diff line Loading @@ -96,8 +96,13 @@ public class SetSchemaResponse { } /** * Returns a {@link Set} of schema type that were deleted by the {@link * AppSearchSession#setSchema} call. * Returns a {@link Set} of deleted schema types. * * <p>A "deleted" type is a schema type that was previously a part of the database schema but * was not present in the {@link SetSchemaRequest} object provided in the * {@link AppSearchSession#setSchema) call. * * <p>Documents for a deleted type are removed from the database. */ @NonNull public Set<String> getDeletedTypes() { Loading @@ -113,6 +118,15 @@ public class SetSchemaResponse { /** * Returns a {@link Set} of schema type that were migrated by the {@link * AppSearchSession#setSchema} call. * * <p>A "migrated" type is a schema type that has triggered a {@link Migrator} instance to * migrate documents of the schema type to another schema type, or to another version of the * schema type. * * <p>If a document fails to be migrated, a {@link MigrationFailure} will be generated for that * document. * * @see Migrator */ @NonNull public Set<String> getMigratedTypes() { Loading @@ -132,6 +146,7 @@ public class SetSchemaResponse { * <p>If a {@link Migrator} is provided for this type and the migration is success triggered. * The type will also appear in {@link #getMigratedTypes()}. * * @see SetSchemaRequest * @see AppSearchSession#setSchema * @see SetSchemaRequest.Builder#setForceOverride */ Loading apex/appsearch/framework/java/external/android/app/appsearch/exceptions/AppSearchException.java +7 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ public class AppSearchException extends Exception { * Initializes an {@link AppSearchException} with a result code and message. * * @param resultCode One of the constants documented in {@link AppSearchResult#getResultCode}. * @param message The detail message (which is saved for later retrieval by the {@link * #getMessage()} method). */ public AppSearchException( @AppSearchResult.ResultCode int resultCode, @Nullable String message) { Loading @@ -52,6 +54,11 @@ public class AppSearchException extends Exception { * Initializes an {@link AppSearchException} with a result code, message and cause. * * @param resultCode One of the constants documented in {@link AppSearchResult#getResultCode}. * @param message The detail message (which is saved for later retrieval by the {@link * #getMessage()} method). * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} * method). (A null value is permitted, and indicates that the cause is nonexistent or * unknown.) */ public AppSearchException( @AppSearchResult.ResultCode int resultCode, Loading apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +6 −3 Original line number Diff line number Diff line Loading @@ -501,7 +501,8 @@ public class AppSearchManagerService extends SystemService { packageName, databaseName, queryExpression, new SearchSpec(searchSpecBundle)); new SearchSpec(searchSpecBundle), /*logger=*/ null); invokeCallbackOnResult( callback, AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); Loading Loading @@ -535,7 +536,8 @@ public class AppSearchManagerService extends SystemService { queryExpression, new SearchSpec(searchSpecBundle), packageName, callingUid); callingUid, /*logger=*/ null); invokeCallbackOnResult( callback, AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); Loading Loading @@ -609,7 +611,8 @@ public class AppSearchManagerService extends SystemService { packageName, databaseName, queryExpression, new SearchSpec(searchSpecBundle)); new SearchSpec(searchSpecBundle), /*logger=*/ null); while (!searchResultPage.getResults().isEmpty()) { for (int i = 0; i < searchResultPage.getResults().size(); i++) { AppSearchMigrationHelper.writeBundleToOutputStream( Loading apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -149,7 +149,8 @@ public final class ImplInstanceManager { private AppSearchImpl createImpl(@NonNull Context context, @UserIdInt int userId) throws AppSearchException { File appSearchDir = getAppSearchDir(userId); return AppSearchImpl.create(appSearchDir, context, userId, mGlobalQuerierPackage); return AppSearchImpl.create( appSearchDir, context, userId, mGlobalQuerierPackage, /*logger=*/ null); } /** Loading apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java +151 −15 Original line number Diff line number Diff line Loading @@ -54,7 +54,9 @@ import com.android.server.appsearch.external.localstorage.converter.SearchResult import com.android.server.appsearch.external.localstorage.converter.SearchSpecToProtoConverter; import com.android.server.appsearch.external.localstorage.converter.SetSchemaResponseToProtoConverter; import com.android.server.appsearch.external.localstorage.converter.TypePropertyPathToProtoConverter; import com.android.server.appsearch.external.localstorage.stats.InitializeStats; import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats; import com.android.server.appsearch.external.localstorage.stats.SearchStats; import com.google.android.icing.IcingSearchEngine; import com.google.android.icing.proto.DeleteByQueryResultProto; Loading Loading @@ -178,28 +180,63 @@ public final class AppSearchImpl implements Closeable { /** * Creates and initializes an instance of {@link AppSearchImpl} which writes data to the given * folder. * * <p>Clients can pass a {@link AppSearchLogger} here through their AppSearchSession, but it * can't be saved inside {@link AppSearchImpl}, because the impl will be shared by all the * sessions for the same package in JetPack. * * <p>Instead, logger instance needs to be passed to each individual method, like create, query * and putDocument. * * @param logger collects stats for initialization if provided. */ @NonNull public static AppSearchImpl create( @NonNull File icingDir, @NonNull Context context, int userId, @NonNull String globalQuerierPackage) @NonNull String globalQuerierPackage, @Nullable AppSearchLogger logger) throws AppSearchException { Objects.requireNonNull(icingDir); Objects.requireNonNull(context); Objects.requireNonNull(globalQuerierPackage); long totalLatencyStartMillis = SystemClock.elapsedRealtime(); InitializeStats.Builder initStatsBuilder = null; if (logger != null) { initStatsBuilder = new InitializeStats.Builder(); } AppSearchImpl appSearchImpl = new AppSearchImpl(icingDir, context, userId, globalQuerierPackage); new AppSearchImpl( icingDir, context, userId, globalQuerierPackage, initStatsBuilder); long prepareVisibilityStoreLatencyStartMillis = SystemClock.elapsedRealtime(); appSearchImpl.initializeVisibilityStore(); long prepareVisibilityStoreLatencyEndMillis = SystemClock.elapsedRealtime(); if (logger != null && initStatsBuilder != null) { initStatsBuilder .setTotalLatencyMillis( (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis)) .setPrepareVisibilityStoreLatencyMillis( (int) (prepareVisibilityStoreLatencyEndMillis - prepareVisibilityStoreLatencyStartMillis)); logger.logStats(initStatsBuilder.build()); } return appSearchImpl; } /** @param initStatsBuilder collects stats for initialization if provided. */ private AppSearchImpl( @NonNull File icingDir, @NonNull Context context, int userId, @NonNull String globalQuerierPackage) @NonNull String globalQuerierPackage, @Nullable InitializeStats.Builder initStatsBuilder) throws AppSearchException { mReadWriteLock.writeLock().lock(); Loading @@ -211,13 +248,24 @@ public final class AppSearchImpl implements Closeable { .setBaseDir(icingDir.getAbsolutePath()) .build(); mIcingSearchEngineLocked = new IcingSearchEngine(options); mVisibilityStoreLocked = new VisibilityStore(this, context, userId, globalQuerierPackage); InitializeResultProto initializeResultProto = mIcingSearchEngineLocked.initialize(); if (initStatsBuilder != null) { initStatsBuilder .setStatusCode( statusProtoToAppSearchException(initializeResultProto.getStatus()) .getResultCode()) // TODO(b/173532925) how to get DeSyncs value .setHasDeSync(false); AppSearchLoggerHelper.copyNativeStats( initializeResultProto.getInitializeStats(), initStatsBuilder); } long prepareSchemaAndNamespacesLatencyStartMillis = SystemClock.elapsedRealtime(); SchemaProto schemaProto; GetAllNamespacesResultProto getAllNamespacesResultProto; GetAllNamespacesResultProto getAllNamespacesResultProto = null; try { checkSuccess(initializeResultProto.getStatus()); schemaProto = getSchemaProtoLocked(); Loading @@ -225,6 +273,17 @@ public final class AppSearchImpl implements Closeable { checkSuccess(getAllNamespacesResultProto.getStatus()); } catch (AppSearchException e) { Log.w(TAG, "Error initializing, resetting IcingSearchEngine.", e); if (initStatsBuilder != null && getAllNamespacesResultProto != null) { initStatsBuilder .setStatusCode( statusProtoToAppSearchException( getAllNamespacesResultProto.getStatus()) .getResultCode()) .setPrepareSchemaAndNamespacesLatencyMillis( (int) (SystemClock.elapsedRealtime() - prepareSchemaAndNamespacesLatencyStartMillis)); } // Some error. Reset and see if it fixes it. resetLocked(); return; Loading @@ -240,6 +299,14 @@ public final class AppSearchImpl implements Closeable { for (String prefixedNamespace : getAllNamespacesResultProto.getNamespacesList()) { addToMap(mNamespaceMapLocked, getPrefix(prefixedNamespace), prefixedNamespace); } // logging prepare_schema_and_namespaces latency if (initStatsBuilder != null) { initStatsBuilder.setPrepareSchemaAndNamespacesLatencyMillis( (int) (SystemClock.elapsedRealtime() - prepareSchemaAndNamespacesLatencyStartMillis)); } } finally { mReadWriteLock.writeLock().unlock(); } Loading Loading @@ -539,7 +606,7 @@ public final class AppSearchImpl implements Closeable { addToMap(mNamespaceMapLocked, prefix, documentBuilder.getNamespace()); // Logging stats if (logger != null) { if (logger != null && pStatsBuilder != null) { pStatsBuilder .getGeneralStatsBuilder() .setStatusCode( Loading @@ -562,7 +629,7 @@ public final class AppSearchImpl implements Closeable { } finally { mReadWriteLock.writeLock().unlock(); if (logger != null) { if (logger != null && pStatsBuilder != null) { long totalEndTimeMillis = SystemClock.elapsedRealtime(); pStatsBuilder .getGeneralStatsBuilder() Loading Loading @@ -644,6 +711,7 @@ public final class AppSearchImpl implements Closeable { * @param databaseName The databaseName this query for. * @param queryExpression Query String to search. * @param searchSpec Spec for setting filters, raw query etc. * @param logger logger to collect query stats * @return The results of performing this search. It may contain an empty list of results if no * documents matched the query. * @throws AppSearchException on IcingSearchEngine error. Loading @@ -653,8 +721,17 @@ public final class AppSearchImpl implements Closeable { @NonNull String packageName, @NonNull String databaseName, @NonNull String queryExpression, @NonNull SearchSpec searchSpec) @NonNull SearchSpec searchSpec, @Nullable AppSearchLogger logger) throws AppSearchException { long totalLatencyStartMillis = SystemClock.elapsedRealtime(); SearchStats.Builder sStatsBuilder = null; if (logger != null) { sStatsBuilder = new SearchStats.Builder(SearchStats.VISIBILITY_SCOPE_LOCAL, packageName) .setDatabase(databaseName); } mReadWriteLock.readLock().lock(); try { throwIfClosedLocked(); Loading @@ -673,9 +750,15 @@ public final class AppSearchImpl implements Closeable { Collections.singleton(createPrefix(packageName, databaseName)), allowedPrefixedSchemas, queryExpression, searchSpec); searchSpec, sStatsBuilder); } finally { mReadWriteLock.readLock().unlock(); if (logger != null && sStatsBuilder != null) { sStatsBuilder.setTotalLatencyMillis( (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis)); logger.logStats(sStatsBuilder.build()); } } } Loading @@ -689,6 +772,7 @@ public final class AppSearchImpl implements Closeable { * @param searchSpec Spec for setting filters, raw query etc. * @param callerPackageName Package name of the caller, should belong to the {@code callerUid}. * @param callerUid UID of the client making the globalQuery call. * @param logger logger to collect globalQuery stats * @return The results of performing this search. It may contain an empty list of results if no * documents matched the query. * @throws AppSearchException on IcingSearchEngine error. Loading @@ -698,8 +782,16 @@ public final class AppSearchImpl implements Closeable { @NonNull String queryExpression, @NonNull SearchSpec searchSpec, @NonNull String callerPackageName, int callerUid) int callerUid, @Nullable AppSearchLogger logger) throws AppSearchException { long totalLatencyStartMillis = SystemClock.elapsedRealtime(); SearchStats.Builder sStatsBuilder = null; if (logger != null) { sStatsBuilder = new SearchStats.Builder(SearchStats.VISIBILITY_SCOPE_GLOBAL, callerPackageName); } mReadWriteLock.readLock().lock(); try { throwIfClosedLocked(); Loading Loading @@ -754,9 +846,19 @@ public final class AppSearchImpl implements Closeable { } return doQueryLocked( prefixFilters, allowedPrefixedSchemas, queryExpression, searchSpec); prefixFilters, allowedPrefixedSchemas, queryExpression, searchSpec, sStatsBuilder); } finally { mReadWriteLock.readLock().unlock(); if (logger != null && sStatsBuilder != null) { sStatsBuilder.setTotalLatencyMillis( (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis)); logger.logStats(sStatsBuilder.build()); } } } Loading Loading @@ -794,8 +896,11 @@ public final class AppSearchImpl implements Closeable { @NonNull Set<String> prefixes, @NonNull Set<String> allowedPrefixedSchemas, @NonNull String queryExpression, @NonNull SearchSpec searchSpec) @NonNull SearchSpec searchSpec, @Nullable SearchStats.Builder sStatsBuilder) throws AppSearchException { long rewriteSearchSpecLatencyStartMillis = SystemClock.elapsedRealtime(); SearchSpecProto.Builder searchSpecBuilder = SearchSpecToProtoConverter.toSearchSpecProto(searchSpec).toBuilder() .setQuery(queryExpression); Loading @@ -804,9 +909,17 @@ public final class AppSearchImpl implements Closeable { // sending request to Icing. if (!rewriteSearchSpecForPrefixesLocked( searchSpecBuilder, prefixes, allowedPrefixedSchemas)) { if (sStatsBuilder != null) { sStatsBuilder.setRewriteSearchSpecLatencyMillis( (int) (SystemClock.elapsedRealtime() - rewriteSearchSpecLatencyStartMillis)); } return new SearchResultPage(Bundle.EMPTY); } // rewriteSearchSpec, rewriteResultSpec and convertScoringSpec are all counted in // rewriteSearchSpecLatencyMillis ResultSpecProto.Builder resultSpecBuilder = SearchSpecToProtoConverter.toResultSpecProto(searchSpec).toBuilder(); Loading @@ -822,15 +935,38 @@ public final class AppSearchImpl implements Closeable { addPerNamespaceResultGroupingsLocked( resultSpecBuilder, prefixes, searchSpec.getResultGroupingLimit()); } rewriteResultSpecForPrefixesLocked(resultSpecBuilder, prefixes, allowedPrefixedSchemas); rewriteResultSpecForPrefixesLocked(resultSpecBuilder, prefixes, allowedPrefixedSchemas); ScoringSpecProto scoringSpec = SearchSpecToProtoConverter.toScoringSpecProto(searchSpec); long rewriteSearchSpecLatencyEndMillis = SystemClock.elapsedRealtime(); SearchResultProto searchResultProto = mIcingSearchEngineLocked.search( searchSpecBuilder.build(), scoringSpec, resultSpecBuilder.build()); if (sStatsBuilder != null) { sStatsBuilder .setStatusCode( statusProtoToAppSearchException(searchResultProto.getStatus()) .getResultCode()) .setRewriteSearchSpecLatencyMillis( (int) (rewriteSearchSpecLatencyEndMillis - rewriteSearchSpecLatencyStartMillis)); AppSearchLoggerHelper.copyNativeStats(searchResultProto.getQueryStats(), sStatsBuilder); } checkSuccess(searchResultProto.getStatus()); return rewriteSearchResultProto(searchResultProto, mSchemaMapLocked); long rewriteSearchResultLatencyStartMillis = SystemClock.elapsedRealtime(); SearchResultPage resultPage = rewriteSearchResultProto(searchResultProto, mSchemaMapLocked); if (sStatsBuilder != null) { sStatsBuilder.setRewriteSearchResultLatencyMillis( (int) (SystemClock.elapsedRealtime() - rewriteSearchResultLatencyStartMillis)); } return resultPage; } /** Loading Loading
apex/appsearch/framework/java/external/android/app/appsearch/SetSchemaResponse.java +17 −2 Original line number Diff line number Diff line Loading @@ -96,8 +96,13 @@ public class SetSchemaResponse { } /** * Returns a {@link Set} of schema type that were deleted by the {@link * AppSearchSession#setSchema} call. * Returns a {@link Set} of deleted schema types. * * <p>A "deleted" type is a schema type that was previously a part of the database schema but * was not present in the {@link SetSchemaRequest} object provided in the * {@link AppSearchSession#setSchema) call. * * <p>Documents for a deleted type are removed from the database. */ @NonNull public Set<String> getDeletedTypes() { Loading @@ -113,6 +118,15 @@ public class SetSchemaResponse { /** * Returns a {@link Set} of schema type that were migrated by the {@link * AppSearchSession#setSchema} call. * * <p>A "migrated" type is a schema type that has triggered a {@link Migrator} instance to * migrate documents of the schema type to another schema type, or to another version of the * schema type. * * <p>If a document fails to be migrated, a {@link MigrationFailure} will be generated for that * document. * * @see Migrator */ @NonNull public Set<String> getMigratedTypes() { Loading @@ -132,6 +146,7 @@ public class SetSchemaResponse { * <p>If a {@link Migrator} is provided for this type and the migration is success triggered. * The type will also appear in {@link #getMigratedTypes()}. * * @see SetSchemaRequest * @see AppSearchSession#setSchema * @see SetSchemaRequest.Builder#setForceOverride */ Loading
apex/appsearch/framework/java/external/android/app/appsearch/exceptions/AppSearchException.java +7 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ public class AppSearchException extends Exception { * Initializes an {@link AppSearchException} with a result code and message. * * @param resultCode One of the constants documented in {@link AppSearchResult#getResultCode}. * @param message The detail message (which is saved for later retrieval by the {@link * #getMessage()} method). */ public AppSearchException( @AppSearchResult.ResultCode int resultCode, @Nullable String message) { Loading @@ -52,6 +54,11 @@ public class AppSearchException extends Exception { * Initializes an {@link AppSearchException} with a result code, message and cause. * * @param resultCode One of the constants documented in {@link AppSearchResult#getResultCode}. * @param message The detail message (which is saved for later retrieval by the {@link * #getMessage()} method). * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} * method). (A null value is permitted, and indicates that the cause is nonexistent or * unknown.) */ public AppSearchException( @AppSearchResult.ResultCode int resultCode, Loading
apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +6 −3 Original line number Diff line number Diff line Loading @@ -501,7 +501,8 @@ public class AppSearchManagerService extends SystemService { packageName, databaseName, queryExpression, new SearchSpec(searchSpecBundle)); new SearchSpec(searchSpecBundle), /*logger=*/ null); invokeCallbackOnResult( callback, AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); Loading Loading @@ -535,7 +536,8 @@ public class AppSearchManagerService extends SystemService { queryExpression, new SearchSpec(searchSpecBundle), packageName, callingUid); callingUid, /*logger=*/ null); invokeCallbackOnResult( callback, AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); Loading Loading @@ -609,7 +611,8 @@ public class AppSearchManagerService extends SystemService { packageName, databaseName, queryExpression, new SearchSpec(searchSpecBundle)); new SearchSpec(searchSpecBundle), /*logger=*/ null); while (!searchResultPage.getResults().isEmpty()) { for (int i = 0; i < searchResultPage.getResults().size(); i++) { AppSearchMigrationHelper.writeBundleToOutputStream( Loading
apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -149,7 +149,8 @@ public final class ImplInstanceManager { private AppSearchImpl createImpl(@NonNull Context context, @UserIdInt int userId) throws AppSearchException { File appSearchDir = getAppSearchDir(userId); return AppSearchImpl.create(appSearchDir, context, userId, mGlobalQuerierPackage); return AppSearchImpl.create( appSearchDir, context, userId, mGlobalQuerierPackage, /*logger=*/ null); } /** Loading
apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java +151 −15 Original line number Diff line number Diff line Loading @@ -54,7 +54,9 @@ import com.android.server.appsearch.external.localstorage.converter.SearchResult import com.android.server.appsearch.external.localstorage.converter.SearchSpecToProtoConverter; import com.android.server.appsearch.external.localstorage.converter.SetSchemaResponseToProtoConverter; import com.android.server.appsearch.external.localstorage.converter.TypePropertyPathToProtoConverter; import com.android.server.appsearch.external.localstorage.stats.InitializeStats; import com.android.server.appsearch.external.localstorage.stats.PutDocumentStats; import com.android.server.appsearch.external.localstorage.stats.SearchStats; import com.google.android.icing.IcingSearchEngine; import com.google.android.icing.proto.DeleteByQueryResultProto; Loading Loading @@ -178,28 +180,63 @@ public final class AppSearchImpl implements Closeable { /** * Creates and initializes an instance of {@link AppSearchImpl} which writes data to the given * folder. * * <p>Clients can pass a {@link AppSearchLogger} here through their AppSearchSession, but it * can't be saved inside {@link AppSearchImpl}, because the impl will be shared by all the * sessions for the same package in JetPack. * * <p>Instead, logger instance needs to be passed to each individual method, like create, query * and putDocument. * * @param logger collects stats for initialization if provided. */ @NonNull public static AppSearchImpl create( @NonNull File icingDir, @NonNull Context context, int userId, @NonNull String globalQuerierPackage) @NonNull String globalQuerierPackage, @Nullable AppSearchLogger logger) throws AppSearchException { Objects.requireNonNull(icingDir); Objects.requireNonNull(context); Objects.requireNonNull(globalQuerierPackage); long totalLatencyStartMillis = SystemClock.elapsedRealtime(); InitializeStats.Builder initStatsBuilder = null; if (logger != null) { initStatsBuilder = new InitializeStats.Builder(); } AppSearchImpl appSearchImpl = new AppSearchImpl(icingDir, context, userId, globalQuerierPackage); new AppSearchImpl( icingDir, context, userId, globalQuerierPackage, initStatsBuilder); long prepareVisibilityStoreLatencyStartMillis = SystemClock.elapsedRealtime(); appSearchImpl.initializeVisibilityStore(); long prepareVisibilityStoreLatencyEndMillis = SystemClock.elapsedRealtime(); if (logger != null && initStatsBuilder != null) { initStatsBuilder .setTotalLatencyMillis( (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis)) .setPrepareVisibilityStoreLatencyMillis( (int) (prepareVisibilityStoreLatencyEndMillis - prepareVisibilityStoreLatencyStartMillis)); logger.logStats(initStatsBuilder.build()); } return appSearchImpl; } /** @param initStatsBuilder collects stats for initialization if provided. */ private AppSearchImpl( @NonNull File icingDir, @NonNull Context context, int userId, @NonNull String globalQuerierPackage) @NonNull String globalQuerierPackage, @Nullable InitializeStats.Builder initStatsBuilder) throws AppSearchException { mReadWriteLock.writeLock().lock(); Loading @@ -211,13 +248,24 @@ public final class AppSearchImpl implements Closeable { .setBaseDir(icingDir.getAbsolutePath()) .build(); mIcingSearchEngineLocked = new IcingSearchEngine(options); mVisibilityStoreLocked = new VisibilityStore(this, context, userId, globalQuerierPackage); InitializeResultProto initializeResultProto = mIcingSearchEngineLocked.initialize(); if (initStatsBuilder != null) { initStatsBuilder .setStatusCode( statusProtoToAppSearchException(initializeResultProto.getStatus()) .getResultCode()) // TODO(b/173532925) how to get DeSyncs value .setHasDeSync(false); AppSearchLoggerHelper.copyNativeStats( initializeResultProto.getInitializeStats(), initStatsBuilder); } long prepareSchemaAndNamespacesLatencyStartMillis = SystemClock.elapsedRealtime(); SchemaProto schemaProto; GetAllNamespacesResultProto getAllNamespacesResultProto; GetAllNamespacesResultProto getAllNamespacesResultProto = null; try { checkSuccess(initializeResultProto.getStatus()); schemaProto = getSchemaProtoLocked(); Loading @@ -225,6 +273,17 @@ public final class AppSearchImpl implements Closeable { checkSuccess(getAllNamespacesResultProto.getStatus()); } catch (AppSearchException e) { Log.w(TAG, "Error initializing, resetting IcingSearchEngine.", e); if (initStatsBuilder != null && getAllNamespacesResultProto != null) { initStatsBuilder .setStatusCode( statusProtoToAppSearchException( getAllNamespacesResultProto.getStatus()) .getResultCode()) .setPrepareSchemaAndNamespacesLatencyMillis( (int) (SystemClock.elapsedRealtime() - prepareSchemaAndNamespacesLatencyStartMillis)); } // Some error. Reset and see if it fixes it. resetLocked(); return; Loading @@ -240,6 +299,14 @@ public final class AppSearchImpl implements Closeable { for (String prefixedNamespace : getAllNamespacesResultProto.getNamespacesList()) { addToMap(mNamespaceMapLocked, getPrefix(prefixedNamespace), prefixedNamespace); } // logging prepare_schema_and_namespaces latency if (initStatsBuilder != null) { initStatsBuilder.setPrepareSchemaAndNamespacesLatencyMillis( (int) (SystemClock.elapsedRealtime() - prepareSchemaAndNamespacesLatencyStartMillis)); } } finally { mReadWriteLock.writeLock().unlock(); } Loading Loading @@ -539,7 +606,7 @@ public final class AppSearchImpl implements Closeable { addToMap(mNamespaceMapLocked, prefix, documentBuilder.getNamespace()); // Logging stats if (logger != null) { if (logger != null && pStatsBuilder != null) { pStatsBuilder .getGeneralStatsBuilder() .setStatusCode( Loading @@ -562,7 +629,7 @@ public final class AppSearchImpl implements Closeable { } finally { mReadWriteLock.writeLock().unlock(); if (logger != null) { if (logger != null && pStatsBuilder != null) { long totalEndTimeMillis = SystemClock.elapsedRealtime(); pStatsBuilder .getGeneralStatsBuilder() Loading Loading @@ -644,6 +711,7 @@ public final class AppSearchImpl implements Closeable { * @param databaseName The databaseName this query for. * @param queryExpression Query String to search. * @param searchSpec Spec for setting filters, raw query etc. * @param logger logger to collect query stats * @return The results of performing this search. It may contain an empty list of results if no * documents matched the query. * @throws AppSearchException on IcingSearchEngine error. Loading @@ -653,8 +721,17 @@ public final class AppSearchImpl implements Closeable { @NonNull String packageName, @NonNull String databaseName, @NonNull String queryExpression, @NonNull SearchSpec searchSpec) @NonNull SearchSpec searchSpec, @Nullable AppSearchLogger logger) throws AppSearchException { long totalLatencyStartMillis = SystemClock.elapsedRealtime(); SearchStats.Builder sStatsBuilder = null; if (logger != null) { sStatsBuilder = new SearchStats.Builder(SearchStats.VISIBILITY_SCOPE_LOCAL, packageName) .setDatabase(databaseName); } mReadWriteLock.readLock().lock(); try { throwIfClosedLocked(); Loading @@ -673,9 +750,15 @@ public final class AppSearchImpl implements Closeable { Collections.singleton(createPrefix(packageName, databaseName)), allowedPrefixedSchemas, queryExpression, searchSpec); searchSpec, sStatsBuilder); } finally { mReadWriteLock.readLock().unlock(); if (logger != null && sStatsBuilder != null) { sStatsBuilder.setTotalLatencyMillis( (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis)); logger.logStats(sStatsBuilder.build()); } } } Loading @@ -689,6 +772,7 @@ public final class AppSearchImpl implements Closeable { * @param searchSpec Spec for setting filters, raw query etc. * @param callerPackageName Package name of the caller, should belong to the {@code callerUid}. * @param callerUid UID of the client making the globalQuery call. * @param logger logger to collect globalQuery stats * @return The results of performing this search. It may contain an empty list of results if no * documents matched the query. * @throws AppSearchException on IcingSearchEngine error. Loading @@ -698,8 +782,16 @@ public final class AppSearchImpl implements Closeable { @NonNull String queryExpression, @NonNull SearchSpec searchSpec, @NonNull String callerPackageName, int callerUid) int callerUid, @Nullable AppSearchLogger logger) throws AppSearchException { long totalLatencyStartMillis = SystemClock.elapsedRealtime(); SearchStats.Builder sStatsBuilder = null; if (logger != null) { sStatsBuilder = new SearchStats.Builder(SearchStats.VISIBILITY_SCOPE_GLOBAL, callerPackageName); } mReadWriteLock.readLock().lock(); try { throwIfClosedLocked(); Loading Loading @@ -754,9 +846,19 @@ public final class AppSearchImpl implements Closeable { } return doQueryLocked( prefixFilters, allowedPrefixedSchemas, queryExpression, searchSpec); prefixFilters, allowedPrefixedSchemas, queryExpression, searchSpec, sStatsBuilder); } finally { mReadWriteLock.readLock().unlock(); if (logger != null && sStatsBuilder != null) { sStatsBuilder.setTotalLatencyMillis( (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis)); logger.logStats(sStatsBuilder.build()); } } } Loading Loading @@ -794,8 +896,11 @@ public final class AppSearchImpl implements Closeable { @NonNull Set<String> prefixes, @NonNull Set<String> allowedPrefixedSchemas, @NonNull String queryExpression, @NonNull SearchSpec searchSpec) @NonNull SearchSpec searchSpec, @Nullable SearchStats.Builder sStatsBuilder) throws AppSearchException { long rewriteSearchSpecLatencyStartMillis = SystemClock.elapsedRealtime(); SearchSpecProto.Builder searchSpecBuilder = SearchSpecToProtoConverter.toSearchSpecProto(searchSpec).toBuilder() .setQuery(queryExpression); Loading @@ -804,9 +909,17 @@ public final class AppSearchImpl implements Closeable { // sending request to Icing. if (!rewriteSearchSpecForPrefixesLocked( searchSpecBuilder, prefixes, allowedPrefixedSchemas)) { if (sStatsBuilder != null) { sStatsBuilder.setRewriteSearchSpecLatencyMillis( (int) (SystemClock.elapsedRealtime() - rewriteSearchSpecLatencyStartMillis)); } return new SearchResultPage(Bundle.EMPTY); } // rewriteSearchSpec, rewriteResultSpec and convertScoringSpec are all counted in // rewriteSearchSpecLatencyMillis ResultSpecProto.Builder resultSpecBuilder = SearchSpecToProtoConverter.toResultSpecProto(searchSpec).toBuilder(); Loading @@ -822,15 +935,38 @@ public final class AppSearchImpl implements Closeable { addPerNamespaceResultGroupingsLocked( resultSpecBuilder, prefixes, searchSpec.getResultGroupingLimit()); } rewriteResultSpecForPrefixesLocked(resultSpecBuilder, prefixes, allowedPrefixedSchemas); rewriteResultSpecForPrefixesLocked(resultSpecBuilder, prefixes, allowedPrefixedSchemas); ScoringSpecProto scoringSpec = SearchSpecToProtoConverter.toScoringSpecProto(searchSpec); long rewriteSearchSpecLatencyEndMillis = SystemClock.elapsedRealtime(); SearchResultProto searchResultProto = mIcingSearchEngineLocked.search( searchSpecBuilder.build(), scoringSpec, resultSpecBuilder.build()); if (sStatsBuilder != null) { sStatsBuilder .setStatusCode( statusProtoToAppSearchException(searchResultProto.getStatus()) .getResultCode()) .setRewriteSearchSpecLatencyMillis( (int) (rewriteSearchSpecLatencyEndMillis - rewriteSearchSpecLatencyStartMillis)); AppSearchLoggerHelper.copyNativeStats(searchResultProto.getQueryStats(), sStatsBuilder); } checkSuccess(searchResultProto.getStatus()); return rewriteSearchResultProto(searchResultProto, mSchemaMapLocked); long rewriteSearchResultLatencyStartMillis = SystemClock.elapsedRealtime(); SearchResultPage resultPage = rewriteSearchResultProto(searchResultProto, mSchemaMapLocked); if (sStatsBuilder != null) { sStatsBuilder.setRewriteSearchResultLatencyMillis( (int) (SystemClock.elapsedRealtime() - rewriteSearchResultLatencyStartMillis)); } return resultPage; } /** Loading