Loading apex/appsearch/framework/java/external/android/app/appsearch/AppSearchBatchResult.java +11 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,17 @@ public final class AppSearchBatchResult<KeyType, ValueType> { 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 @NonNull public String toString() { Loading apex/appsearch/framework/java/external/android/app/appsearch/util/SchemaMigrationUtil.java +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ public final class SchemaMigrationUtil { /** * 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( @NonNull SetSchemaResponse setSchemaResponse, @NonNull Set<String> activeMigrators) Loading apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +10 −3 Original line number Diff line number Diff line Loading @@ -363,6 +363,7 @@ public class AppSearchManagerService extends SystemService { schemasVisibleToPackages.put(entry.getKey(), packageIdentifiers); } instance = mAppSearchUserInstanceManager.getUserInstance(targetUser); // TODO(b/173532925): Implement logging for statsBuilder SetSchemaResponse setSchemaResponse = instance.getAppSearchImpl().setSchema( packageName, databaseName, Loading @@ -371,7 +372,8 @@ public class AppSearchManagerService extends SystemService { schemasNotDisplayedBySystem, schemasVisibleToPackages, forceOverride, schemaVersion); schemaVersion, /*setSchemaStatsBuilder=*/ null); ++operationSuccessCount; invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(setSchemaResponse.getBundle())); Loading Loading @@ -816,8 +818,10 @@ public class AppSearchManagerService extends SystemService { AppSearchUserInstance instance = mAppSearchUserInstanceManager.getUserInstance(targetUser); // TODO(b/173532925): Implement logging for statsBuilder SearchResultPage searchResultPage = instance.getAppSearchImpl().getNextPage(packageName, nextPageToken); instance.getAppSearchImpl().getNextPage( packageName, nextPageToken, /*statsBuilder=*/ null); invokeCallbackOnResult( callback, AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); Loading Loading @@ -898,8 +902,11 @@ public class AppSearchManagerService extends SystemService { outputStream, searchResultPage.getResults().get(i) .getGenericDocument().getBundle()); } // TODO(b/173532925): Implement logging for statsBuilder searchResultPage = instance.getAppSearchImpl().getNextPage( packageName, searchResultPage.getNextPageToken()); packageName, searchResultPage.getNextPageToken(), /*statsBuilder=*/ null); } } invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); Loading apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java +40 −5 Original line number Diff line number Diff line Loading @@ -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.RemoveStats; 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.google.android.icing.IcingSearchEngine; Loading Loading @@ -393,6 +394,7 @@ public final class AppSearchImpl implements Closeable { * @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. * @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 * call. * @throws AppSearchException On IcingSearchEngine error. If the status code is Loading @@ -408,7 +410,8 @@ public final class AppSearchImpl implements Closeable { @NonNull List<String> schemasNotDisplayedBySystem, @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages, boolean forceOverride, int version) int version, @Nullable SetSchemaStats.Builder setSchemaStatsBuilder) throws AppSearchException { mReadWriteLock.writeLock().lock(); try { Loading Loading @@ -438,6 +441,12 @@ public final class AppSearchImpl implements Closeable { mLogUtil.piiTrace( "setSchema, response", setSchemaResultProto.getStatus(), setSchemaResultProto); if (setSchemaStatsBuilder != null) { setSchemaStatsBuilder.setStatusCode( statusProtoToResultCode(setSchemaResultProto.getStatus())); AppSearchLoggerHelper.copyNativeStats(setSchemaResultProto, setSchemaStatsBuilder); } // Determine whether it succeeded. try { checkSuccess(setSchemaResultProto.getStatus()); Loading Loading @@ -1127,8 +1136,13 @@ public final class AppSearchImpl implements Closeable { * @throws AppSearchException on IcingSearchEngine error or if can't advance on nextPageToken. */ @NonNull public SearchResultPage getNextPage(@NonNull String packageName, long nextPageToken) public SearchResultPage getNextPage( @NonNull String packageName, long nextPageToken, @Nullable SearchStats.Builder statsBuilder) throws AppSearchException { long totalLatencyStartMillis = SystemClock.elapsedRealtime(); mReadWriteLock.readLock().lock(); try { throwIfClosedLocked(); Loading @@ -1137,6 +1151,13 @@ public final class AppSearchImpl implements Closeable { checkNextPageToken(packageName, nextPageToken); SearchResultProto searchResultProto = mIcingSearchEngineLocked.getNextPage(nextPageToken); if (statsBuilder != null) { statsBuilder.setStatusCode(statusProtoToResultCode(searchResultProto.getStatus())); AppSearchLoggerHelper.copyNativeStats( searchResultProto.getQueryStats(), statsBuilder); } mLogUtil.piiTrace( "getNextPage, response", searchResultProto.getResultsCount(), Loading @@ -1152,9 +1173,22 @@ public final class AppSearchImpl implements Closeable { 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 { mReadWriteLock.readLock().unlock(); if (statsBuilder != null) { statsBuilder.setTotalLatencyMillis( (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis)); } } } Loading Loading @@ -1334,7 +1368,7 @@ public final class AppSearchImpl implements Closeable { statusProtoToResultCode(deleteResultProto.getStatus())); // TODO(b/187206766) also log query stats here once IcingLib returns it AppSearchLoggerHelper.copyNativeStats( deleteResultProto.getDeleteStats(), removeStatsBuilder); deleteResultProto.getDeleteByQueryStats(), removeStatsBuilder); } // It seems that the caller wants to get success if the data matching the query is Loading @@ -1343,7 +1377,8 @@ public final class AppSearchImpl implements Closeable { deleteResultProto.getStatus(), StatusProto.Code.OK, StatusProto.Code.NOT_FOUND); // Update derived maps int numDocumentsDeleted = deleteResultProto.getDeleteStats().getNumDocumentsDeleted(); int numDocumentsDeleted = deleteResultProto.getDeleteByQueryStats().getNumDocumentsDeleted(); updateDocumentCountAfterRemovalLocked(packageName, numDocumentsDeleted); } finally { mReadWriteLock.writeLock().unlock(); Loading apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchLogger.java +4 −0 Original line number Diff line number Diff line Loading @@ -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.RemoveStats; 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. Loading Loading @@ -54,5 +55,8 @@ public interface AppSearchLogger { /** Logs {@link OptimizeStats} */ 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. } Loading
apex/appsearch/framework/java/external/android/app/appsearch/AppSearchBatchResult.java +11 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,17 @@ public final class AppSearchBatchResult<KeyType, ValueType> { 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 @NonNull public String toString() { Loading
apex/appsearch/framework/java/external/android/app/appsearch/util/SchemaMigrationUtil.java +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ public final class SchemaMigrationUtil { /** * 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( @NonNull SetSchemaResponse setSchemaResponse, @NonNull Set<String> activeMigrators) Loading
apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +10 −3 Original line number Diff line number Diff line Loading @@ -363,6 +363,7 @@ public class AppSearchManagerService extends SystemService { schemasVisibleToPackages.put(entry.getKey(), packageIdentifiers); } instance = mAppSearchUserInstanceManager.getUserInstance(targetUser); // TODO(b/173532925): Implement logging for statsBuilder SetSchemaResponse setSchemaResponse = instance.getAppSearchImpl().setSchema( packageName, databaseName, Loading @@ -371,7 +372,8 @@ public class AppSearchManagerService extends SystemService { schemasNotDisplayedBySystem, schemasVisibleToPackages, forceOverride, schemaVersion); schemaVersion, /*setSchemaStatsBuilder=*/ null); ++operationSuccessCount; invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(setSchemaResponse.getBundle())); Loading Loading @@ -816,8 +818,10 @@ public class AppSearchManagerService extends SystemService { AppSearchUserInstance instance = mAppSearchUserInstanceManager.getUserInstance(targetUser); // TODO(b/173532925): Implement logging for statsBuilder SearchResultPage searchResultPage = instance.getAppSearchImpl().getNextPage(packageName, nextPageToken); instance.getAppSearchImpl().getNextPage( packageName, nextPageToken, /*statsBuilder=*/ null); invokeCallbackOnResult( callback, AppSearchResult.newSuccessfulResult(searchResultPage.getBundle())); Loading Loading @@ -898,8 +902,11 @@ public class AppSearchManagerService extends SystemService { outputStream, searchResultPage.getResults().get(i) .getGenericDocument().getBundle()); } // TODO(b/173532925): Implement logging for statsBuilder searchResultPage = instance.getAppSearchImpl().getNextPage( packageName, searchResultPage.getNextPageToken()); packageName, searchResultPage.getNextPageToken(), /*statsBuilder=*/ null); } } invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); Loading
apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java +40 −5 Original line number Diff line number Diff line Loading @@ -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.RemoveStats; 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.google.android.icing.IcingSearchEngine; Loading Loading @@ -393,6 +394,7 @@ public final class AppSearchImpl implements Closeable { * @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. * @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 * call. * @throws AppSearchException On IcingSearchEngine error. If the status code is Loading @@ -408,7 +410,8 @@ public final class AppSearchImpl implements Closeable { @NonNull List<String> schemasNotDisplayedBySystem, @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages, boolean forceOverride, int version) int version, @Nullable SetSchemaStats.Builder setSchemaStatsBuilder) throws AppSearchException { mReadWriteLock.writeLock().lock(); try { Loading Loading @@ -438,6 +441,12 @@ public final class AppSearchImpl implements Closeable { mLogUtil.piiTrace( "setSchema, response", setSchemaResultProto.getStatus(), setSchemaResultProto); if (setSchemaStatsBuilder != null) { setSchemaStatsBuilder.setStatusCode( statusProtoToResultCode(setSchemaResultProto.getStatus())); AppSearchLoggerHelper.copyNativeStats(setSchemaResultProto, setSchemaStatsBuilder); } // Determine whether it succeeded. try { checkSuccess(setSchemaResultProto.getStatus()); Loading Loading @@ -1127,8 +1136,13 @@ public final class AppSearchImpl implements Closeable { * @throws AppSearchException on IcingSearchEngine error or if can't advance on nextPageToken. */ @NonNull public SearchResultPage getNextPage(@NonNull String packageName, long nextPageToken) public SearchResultPage getNextPage( @NonNull String packageName, long nextPageToken, @Nullable SearchStats.Builder statsBuilder) throws AppSearchException { long totalLatencyStartMillis = SystemClock.elapsedRealtime(); mReadWriteLock.readLock().lock(); try { throwIfClosedLocked(); Loading @@ -1137,6 +1151,13 @@ public final class AppSearchImpl implements Closeable { checkNextPageToken(packageName, nextPageToken); SearchResultProto searchResultProto = mIcingSearchEngineLocked.getNextPage(nextPageToken); if (statsBuilder != null) { statsBuilder.setStatusCode(statusProtoToResultCode(searchResultProto.getStatus())); AppSearchLoggerHelper.copyNativeStats( searchResultProto.getQueryStats(), statsBuilder); } mLogUtil.piiTrace( "getNextPage, response", searchResultProto.getResultsCount(), Loading @@ -1152,9 +1173,22 @@ public final class AppSearchImpl implements Closeable { 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 { mReadWriteLock.readLock().unlock(); if (statsBuilder != null) { statsBuilder.setTotalLatencyMillis( (int) (SystemClock.elapsedRealtime() - totalLatencyStartMillis)); } } } Loading Loading @@ -1334,7 +1368,7 @@ public final class AppSearchImpl implements Closeable { statusProtoToResultCode(deleteResultProto.getStatus())); // TODO(b/187206766) also log query stats here once IcingLib returns it AppSearchLoggerHelper.copyNativeStats( deleteResultProto.getDeleteStats(), removeStatsBuilder); deleteResultProto.getDeleteByQueryStats(), removeStatsBuilder); } // It seems that the caller wants to get success if the data matching the query is Loading @@ -1343,7 +1377,8 @@ public final class AppSearchImpl implements Closeable { deleteResultProto.getStatus(), StatusProto.Code.OK, StatusProto.Code.NOT_FOUND); // Update derived maps int numDocumentsDeleted = deleteResultProto.getDeleteStats().getNumDocumentsDeleted(); int numDocumentsDeleted = deleteResultProto.getDeleteByQueryStats().getNumDocumentsDeleted(); updateDocumentCountAfterRemovalLocked(packageName, numDocumentsDeleted); } finally { mReadWriteLock.writeLock().unlock(); Loading
apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchLogger.java +4 −0 Original line number Diff line number Diff line Loading @@ -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.RemoveStats; 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. Loading Loading @@ -54,5 +55,8 @@ public interface AppSearchLogger { /** Logs {@link OptimizeStats} */ 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. }