Loading apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java +10 −12 Original line number Diff line number Diff line Loading @@ -136,8 +136,6 @@ public final class AppSearchSession implements Closeable { * @param callback Callback to receive errors resulting from setting the schema. If the * operation succeeds, the callback will be invoked with {@code null}. */ // TODO(b/169883602): Change @code references to @link when setPlatformSurfaceable APIs are // exposed. public void setSchema( @NonNull SetSchemaRequest request, @NonNull Executor workExecutor, Loading @@ -152,7 +150,7 @@ public final class AppSearchSession implements Closeable { for (AppSearchSchema schema : request.getSchemas()) { schemaBundles.add(schema.getBundle()); } Map<String, List<Bundle>> schemasPackageAccessibleBundles = Map<String, List<Bundle>> schemasVisibleToPackagesBundles = new ArrayMap<>(request.getSchemasVisibleToPackagesInternal().size()); for (Map.Entry<String, Set<PackageIdentifier>> entry : request.getSchemasVisibleToPackagesInternal().entrySet()) { Loading @@ -160,7 +158,7 @@ public final class AppSearchSession implements Closeable { for (PackageIdentifier packageIdentifier : entry.getValue()) { packageIdentifierBundles.add(packageIdentifier.getBundle()); } schemasPackageAccessibleBundles.put(entry.getKey(), packageIdentifierBundles); schemasVisibleToPackagesBundles.put(entry.getKey(), packageIdentifierBundles); } // No need to trigger migration if user never set migrator Loading @@ -168,14 +166,14 @@ public final class AppSearchSession implements Closeable { setSchemaNoMigrations( request, schemaBundles, schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, callbackExecutor, callback); } else { setSchemaWithMigrations( request, schemaBundles, schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, workExecutor, callbackExecutor, callback); Loading Loading @@ -704,7 +702,7 @@ public final class AppSearchSession implements Closeable { private void setSchemaNoMigrations( @NonNull SetSchemaRequest request, @NonNull List<Bundle> schemaBundles, @NonNull Map<String, List<Bundle>> schemasPackageAccessibleBundles, @NonNull Map<String, List<Bundle>> schemasVisibleToPackagesBundles, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<AppSearchResult<SetSchemaResponse>> callback) { try { Loading @@ -713,7 +711,7 @@ public final class AppSearchSession implements Closeable { mDatabaseName, schemaBundles, new ArrayList<>(request.getSchemasNotDisplayedBySystem()), schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, request.isForceOverride(), request.getVersion(), mUserHandle, Loading Loading @@ -761,7 +759,7 @@ public final class AppSearchSession implements Closeable { private void setSchemaWithMigrations( @NonNull SetSchemaRequest request, @NonNull List<Bundle> schemaBundles, @NonNull Map<String, List<Bundle>> schemasPackageAccessibleBundles, @NonNull Map<String, List<Bundle>> schemasVisibleToPackagesBundles, @NonNull Executor workExecutor, @NonNull @CallbackExecutor Executor callbackExecutor, @NonNull Consumer<AppSearchResult<SetSchemaResponse>> callback) { Loading @@ -787,7 +785,7 @@ public final class AppSearchSession implements Closeable { // No need to trigger migration if no migrator is active. if (activeMigrators.isEmpty()) { setSchemaNoMigrations(request, schemaBundles, schemasPackageAccessibleBundles, setSchemaNoMigrations(request, schemaBundles, schemasVisibleToPackagesBundles, callbackExecutor, callback); return; } Loading @@ -801,7 +799,7 @@ public final class AppSearchSession implements Closeable { mDatabaseName, schemaBundles, new ArrayList<>(request.getSchemasNotDisplayedBySystem()), schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, /*forceOverride=*/ false, request.getVersion(), mUserHandle, Loading Loading @@ -853,7 +851,7 @@ public final class AppSearchSession implements Closeable { mDatabaseName, schemaBundles, new ArrayList<>(request.getSchemasNotDisplayedBySystem()), schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, /*forceOverride=*/ true, request.getVersion(), mUserHandle, Loading apex/appsearch/framework/java/android/app/appsearch/aidl/IAppSearchManager.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ interface IAppSearchManager { * @param schemaBundles List of {@link AppSearchSchema} bundles. * @param schemasNotDisplayedBySystem Schema types that should not be surfaced on platform * surfaces. * @param schemasPackageAccessibleBundles Schema types that are visible to the specified * @param schemasVisibleToPackagesBundles Schema types that are visible to the specified * packages. The value List contains PackageIdentifier Bundles. * @param forceOverride Whether to apply the new schema even if it is incompatible. All * incompatible documents will be deleted. Loading @@ -48,7 +48,7 @@ interface IAppSearchManager { in String databaseName, in List<Bundle> schemaBundles, in List<String> schemasNotDisplayedBySystem, in Map<String, List<Bundle>> schemasPackageAccessibleBundles, in Map<String, List<Bundle>> schemasVisibleToPackagesBundles, boolean forceOverride, in int schemaVersion, in UserHandle userHandle, Loading apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +3 −3 Original line number Diff line number Diff line Loading @@ -333,7 +333,7 @@ public class AppSearchManagerService extends SystemService { for (int i = 0; i < schemaBundles.size(); i++) { schemas.add(new AppSearchSchema(schemaBundles.get(i))); } Map<String, List<PackageIdentifier>> schemasPackageAccessible = Map<String, List<PackageIdentifier>> schemasVisibleToPackages = new ArrayMap<>(schemasVisibleToPackagesBundles.size()); for (Map.Entry<String, List<Bundle>> entry : schemasVisibleToPackagesBundles.entrySet()) { Loading @@ -343,7 +343,7 @@ public class AppSearchManagerService extends SystemService { packageIdentifiers.add( new PackageIdentifier(entry.getValue().get(i))); } schemasPackageAccessible.put(entry.getKey(), packageIdentifiers); schemasVisibleToPackages.put(entry.getKey(), packageIdentifiers); } instance = mAppSearchUserInstanceManager.getUserInstance(callingUser); SetSchemaResponse setSchemaResponse = instance.getAppSearchImpl().setSchema( Loading @@ -352,7 +352,7 @@ public class AppSearchManagerService extends SystemService { schemas, instance.getVisibilityStore(), schemasNotDisplayedBySystem, schemasPackageAccessible, schemasVisibleToPackages, forceOverride, schemaVersion); ++operationSuccessCount; Loading apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java +21 −19 Original line number Diff line number Diff line Loading @@ -346,11 +346,11 @@ public final class AppSearchImpl implements Closeable { * @param packageName The package name that owns the schemas. * @param databaseName The name of the database where this schema lives. * @param schemas Schemas to set for this app. * @param visibilityStore If set, {@code schemasNotPlatformSurfaceable} and {@code * schemasPackageAccessible} will be saved here if the schema is successfully applied. * @param schemasNotPlatformSurfaceable Schema types that should not be surfaced on platform * @param visibilityStore If set, {@code schemasNotDisplayedBySystem} and {@code * schemasVisibleToPackages} will be saved here if the schema is successfully applied. * @param schemasNotDisplayedBySystem Schema types that should not be surfaced on platform * surfaces. * @param schemasPackageAccessible Schema types that are visible to the specified packages. * @param schemasVisibleToPackages Schema types that are visible to the specified packages. * @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. Loading @@ -366,8 +366,8 @@ public final class AppSearchImpl implements Closeable { @NonNull String databaseName, @NonNull List<AppSearchSchema> schemas, @Nullable VisibilityStore visibilityStore, @NonNull List<String> schemasNotPlatformSurfaceable, @NonNull Map<String, List<PackageIdentifier>> schemasPackageAccessible, @NonNull List<String> schemasNotDisplayedBySystem, @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages, boolean forceOverride, int version) throws AppSearchException { Loading Loading @@ -430,25 +430,25 @@ public final class AppSearchImpl implements Closeable { } if (visibilityStore != null) { Set<String> prefixedSchemasNotPlatformSurfaceable = new ArraySet<>(schemasNotPlatformSurfaceable.size()); for (int i = 0; i < schemasNotPlatformSurfaceable.size(); i++) { prefixedSchemasNotPlatformSurfaceable.add( prefix + schemasNotPlatformSurfaceable.get(i)); Set<String> prefixedSchemasNotDisplayedBySystem = new ArraySet<>(schemasNotDisplayedBySystem.size()); for (int i = 0; i < schemasNotDisplayedBySystem.size(); i++) { prefixedSchemasNotDisplayedBySystem.add( prefix + schemasNotDisplayedBySystem.get(i)); } Map<String, List<PackageIdentifier>> prefixedSchemasPackageAccessible = new ArrayMap<>(schemasPackageAccessible.size()); Map<String, List<PackageIdentifier>> prefixedSchemasVisibleToPackages = new ArrayMap<>(schemasVisibleToPackages.size()); for (Map.Entry<String, List<PackageIdentifier>> entry : schemasPackageAccessible.entrySet()) { prefixedSchemasPackageAccessible.put(prefix + entry.getKey(), entry.getValue()); schemasVisibleToPackages.entrySet()) { prefixedSchemasVisibleToPackages.put(prefix + entry.getKey(), entry.getValue()); } visibilityStore.setVisibility( packageName, databaseName, prefixedSchemasNotPlatformSurfaceable, prefixedSchemasPackageAccessible); prefixedSchemasNotDisplayedBySystem, prefixedSchemasVisibleToPackages); } return SetSchemaResponseToProtoConverter.toSetSchemaResponse( Loading Loading @@ -737,6 +737,9 @@ public final class AppSearchImpl implements Closeable { if (!filterPackageNames.isEmpty() && !filterPackageNames.contains(packageName)) { // Client wanted to query over some packages that weren't its own. This isn't // allowed through local query so we can return early with no results. if (logger != null) { sStatsBuilder.setStatusCode(AppSearchResult.RESULT_SECURITY_ERROR); } return new SearchResultPage(Bundle.EMPTY); } Loading Loading @@ -768,7 +771,7 @@ public final class AppSearchImpl implements Closeable { * @param queryExpression Query String to search. * @param searchSpec Spec for setting filters, raw query etc. * @param callerPackageName Package name of the caller, should belong to the {@code * userContext}. * callerUserHandle}. * @param visibilityStore Optional visibility store to obtain system and package visibility * settings from * @param callerUid UID of the client making the globalQuery call. Loading Loading @@ -1465,7 +1468,6 @@ public final class AppSearchImpl implements Closeable { mOptimizeIntervalCountLocked = 0; mSchemaMapLocked.clear(); mNamespaceMapLocked.clear(); if (initStatsBuilder != null) { initStatsBuilder .setHasReset(true) Loading apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/stats/SchemaMigrationStats.java 0 → 100644 +189 −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.NonNull; import android.app.appsearch.SetSchemaRequest; import java.util.Objects; /** * Class holds detailed stats for Schema migration. * * @hide */ // TODO(b/173532925): Hides getter and setter functions for accessing {@code // mFirstSetSchemaLatencyMillis} and {@code mSecondSetSchemaLatencyMillis} field. public final class SchemaMigrationStats { /** GetSchema latency in milliseconds. */ private final int mGetSchemaLatencyMillis; /** * Latency of querying all documents that need to be migrated to new version and transforming * documents to new version in milliseconds. */ private final int mQueryAndTransformLatencyMillis; private final int mFirstSetSchemaLatencyMillis; private final int mSecondSetSchemaLatencyMillis; /** Latency of putting migrated document to Icing lib in milliseconds. */ private final int mSaveDocumentLatencyMillis; private final int mMigratedDocumentCount; private final int mSavedDocumentCount; SchemaMigrationStats(@NonNull Builder builder) { Objects.requireNonNull(builder); mGetSchemaLatencyMillis = builder.mGetSchemaLatencyMillis; mQueryAndTransformLatencyMillis = builder.mQueryAndTransformLatencyMillis; mFirstSetSchemaLatencyMillis = builder.mFirstSetSchemaLatencyMillis; mSecondSetSchemaLatencyMillis = builder.mSecondSetSchemaLatencyMillis; mSaveDocumentLatencyMillis = builder.mSaveDocumentLatencyMillis; mMigratedDocumentCount = builder.mMigratedDocumentCount; mSavedDocumentCount = builder.mSavedDocumentCount; } /** Returns GetSchema latency in milliseconds. */ public int getGetSchemaLatencyMillis() { return mGetSchemaLatencyMillis; } /** * Returns latency of querying all documents that need to be migrated to new version and * transforming documents to new version in milliseconds. */ public int getQueryAndTransformLatencyMillis() { return mQueryAndTransformLatencyMillis; } /** * Returns latency of first SetSchema action in milliseconds. * * <p>If all schema fields are backward compatible, the schema will be successful set to Icing. * Otherwise, we will retrieve incompatible types here. * * <p>Please see {@link SetSchemaRequest} for what is "incompatible". */ public int getFirstSetSchemaLatencyMillis() { return mFirstSetSchemaLatencyMillis; } /** * Returns latency of second SetSchema action in milliseconds. * * <p>If all schema fields are backward compatible, the schema will be successful set to Icing * in the first setSchema action and this value will be 0. Otherwise, schema types will be set * to Icing by this action. */ public int getSecondSetSchemaLatencyMillis() { return mSecondSetSchemaLatencyMillis; } /** Returns latency of putting migrated document to Icing lib in milliseconds. */ public int getSaveDocumentLatencyMillis() { return mSaveDocumentLatencyMillis; } /** Returns number of migrated documents. */ public int getMigratedDocumentCount() { return mMigratedDocumentCount; } /** Returns number of updated documents which are saved in Icing lib. */ public int getSavedDocumentCount() { return mSavedDocumentCount; } /** Builder for {@link SchemaMigrationStats}. */ public static class Builder { int mGetSchemaLatencyMillis; int mQueryAndTransformLatencyMillis; int mFirstSetSchemaLatencyMillis; int mSecondSetSchemaLatencyMillis; int mSaveDocumentLatencyMillis; int mMigratedDocumentCount; int mSavedDocumentCount; /** Sets latency for the GetSchema action in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setGetSchemaLatencyMillis(int getSchemaLatencyMillis) { mGetSchemaLatencyMillis = getSchemaLatencyMillis; return this; } /** * Sets latency for querying all documents that need to be migrated to new version and * transforming documents to new version in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setQueryAndTransformLatencyMillis( int queryAndTransformLatencyMillis) { mQueryAndTransformLatencyMillis = queryAndTransformLatencyMillis; return this; } /** Sets latency of first SetSchema action in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setFirstSetSchemaLatencyMillis( int firstSetSchemaLatencyMillis) { mFirstSetSchemaLatencyMillis = firstSetSchemaLatencyMillis; return this; } /** Sets latency of second SetSchema action in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setSecondSetSchemaLatencyMillis( int secondSetSchemaLatencyMillis) { mSecondSetSchemaLatencyMillis = secondSetSchemaLatencyMillis; return this; } /** Sets latency for putting migrated document to Icing lib in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setSaveDocumentLatencyMillis( int saveDocumentLatencyMillis) { mSaveDocumentLatencyMillis = saveDocumentLatencyMillis; return this; } /** Sets number of migrated documents. */ @NonNull public SchemaMigrationStats.Builder setMigratedDocumentCount(int migratedDocumentCount) { mMigratedDocumentCount = migratedDocumentCount; return this; } /** Sets number of updated documents which are saved in Icing lib. */ @NonNull public SchemaMigrationStats.Builder setSavedDocumentCount(int savedDocumentCount) { mSavedDocumentCount = savedDocumentCount; return this; } /** * Builds a new {@link SchemaMigrationStats} from the {@link SchemaMigrationStats.Builder}. */ @NonNull public SchemaMigrationStats build() { return new SchemaMigrationStats(/* builder= */ this); } } } Loading
apex/appsearch/framework/java/android/app/appsearch/AppSearchSession.java +10 −12 Original line number Diff line number Diff line Loading @@ -136,8 +136,6 @@ public final class AppSearchSession implements Closeable { * @param callback Callback to receive errors resulting from setting the schema. If the * operation succeeds, the callback will be invoked with {@code null}. */ // TODO(b/169883602): Change @code references to @link when setPlatformSurfaceable APIs are // exposed. public void setSchema( @NonNull SetSchemaRequest request, @NonNull Executor workExecutor, Loading @@ -152,7 +150,7 @@ public final class AppSearchSession implements Closeable { for (AppSearchSchema schema : request.getSchemas()) { schemaBundles.add(schema.getBundle()); } Map<String, List<Bundle>> schemasPackageAccessibleBundles = Map<String, List<Bundle>> schemasVisibleToPackagesBundles = new ArrayMap<>(request.getSchemasVisibleToPackagesInternal().size()); for (Map.Entry<String, Set<PackageIdentifier>> entry : request.getSchemasVisibleToPackagesInternal().entrySet()) { Loading @@ -160,7 +158,7 @@ public final class AppSearchSession implements Closeable { for (PackageIdentifier packageIdentifier : entry.getValue()) { packageIdentifierBundles.add(packageIdentifier.getBundle()); } schemasPackageAccessibleBundles.put(entry.getKey(), packageIdentifierBundles); schemasVisibleToPackagesBundles.put(entry.getKey(), packageIdentifierBundles); } // No need to trigger migration if user never set migrator Loading @@ -168,14 +166,14 @@ public final class AppSearchSession implements Closeable { setSchemaNoMigrations( request, schemaBundles, schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, callbackExecutor, callback); } else { setSchemaWithMigrations( request, schemaBundles, schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, workExecutor, callbackExecutor, callback); Loading Loading @@ -704,7 +702,7 @@ public final class AppSearchSession implements Closeable { private void setSchemaNoMigrations( @NonNull SetSchemaRequest request, @NonNull List<Bundle> schemaBundles, @NonNull Map<String, List<Bundle>> schemasPackageAccessibleBundles, @NonNull Map<String, List<Bundle>> schemasVisibleToPackagesBundles, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<AppSearchResult<SetSchemaResponse>> callback) { try { Loading @@ -713,7 +711,7 @@ public final class AppSearchSession implements Closeable { mDatabaseName, schemaBundles, new ArrayList<>(request.getSchemasNotDisplayedBySystem()), schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, request.isForceOverride(), request.getVersion(), mUserHandle, Loading Loading @@ -761,7 +759,7 @@ public final class AppSearchSession implements Closeable { private void setSchemaWithMigrations( @NonNull SetSchemaRequest request, @NonNull List<Bundle> schemaBundles, @NonNull Map<String, List<Bundle>> schemasPackageAccessibleBundles, @NonNull Map<String, List<Bundle>> schemasVisibleToPackagesBundles, @NonNull Executor workExecutor, @NonNull @CallbackExecutor Executor callbackExecutor, @NonNull Consumer<AppSearchResult<SetSchemaResponse>> callback) { Loading @@ -787,7 +785,7 @@ public final class AppSearchSession implements Closeable { // No need to trigger migration if no migrator is active. if (activeMigrators.isEmpty()) { setSchemaNoMigrations(request, schemaBundles, schemasPackageAccessibleBundles, setSchemaNoMigrations(request, schemaBundles, schemasVisibleToPackagesBundles, callbackExecutor, callback); return; } Loading @@ -801,7 +799,7 @@ public final class AppSearchSession implements Closeable { mDatabaseName, schemaBundles, new ArrayList<>(request.getSchemasNotDisplayedBySystem()), schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, /*forceOverride=*/ false, request.getVersion(), mUserHandle, Loading Loading @@ -853,7 +851,7 @@ public final class AppSearchSession implements Closeable { mDatabaseName, schemaBundles, new ArrayList<>(request.getSchemasNotDisplayedBySystem()), schemasPackageAccessibleBundles, schemasVisibleToPackagesBundles, /*forceOverride=*/ true, request.getVersion(), mUserHandle, Loading
apex/appsearch/framework/java/android/app/appsearch/aidl/IAppSearchManager.aidl +2 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ interface IAppSearchManager { * @param schemaBundles List of {@link AppSearchSchema} bundles. * @param schemasNotDisplayedBySystem Schema types that should not be surfaced on platform * surfaces. * @param schemasPackageAccessibleBundles Schema types that are visible to the specified * @param schemasVisibleToPackagesBundles Schema types that are visible to the specified * packages. The value List contains PackageIdentifier Bundles. * @param forceOverride Whether to apply the new schema even if it is incompatible. All * incompatible documents will be deleted. Loading @@ -48,7 +48,7 @@ interface IAppSearchManager { in String databaseName, in List<Bundle> schemaBundles, in List<String> schemasNotDisplayedBySystem, in Map<String, List<Bundle>> schemasPackageAccessibleBundles, in Map<String, List<Bundle>> schemasVisibleToPackagesBundles, boolean forceOverride, in int schemaVersion, in UserHandle userHandle, Loading
apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +3 −3 Original line number Diff line number Diff line Loading @@ -333,7 +333,7 @@ public class AppSearchManagerService extends SystemService { for (int i = 0; i < schemaBundles.size(); i++) { schemas.add(new AppSearchSchema(schemaBundles.get(i))); } Map<String, List<PackageIdentifier>> schemasPackageAccessible = Map<String, List<PackageIdentifier>> schemasVisibleToPackages = new ArrayMap<>(schemasVisibleToPackagesBundles.size()); for (Map.Entry<String, List<Bundle>> entry : schemasVisibleToPackagesBundles.entrySet()) { Loading @@ -343,7 +343,7 @@ public class AppSearchManagerService extends SystemService { packageIdentifiers.add( new PackageIdentifier(entry.getValue().get(i))); } schemasPackageAccessible.put(entry.getKey(), packageIdentifiers); schemasVisibleToPackages.put(entry.getKey(), packageIdentifiers); } instance = mAppSearchUserInstanceManager.getUserInstance(callingUser); SetSchemaResponse setSchemaResponse = instance.getAppSearchImpl().setSchema( Loading @@ -352,7 +352,7 @@ public class AppSearchManagerService extends SystemService { schemas, instance.getVisibilityStore(), schemasNotDisplayedBySystem, schemasPackageAccessible, schemasVisibleToPackages, forceOverride, schemaVersion); ++operationSuccessCount; Loading
apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java +21 −19 Original line number Diff line number Diff line Loading @@ -346,11 +346,11 @@ public final class AppSearchImpl implements Closeable { * @param packageName The package name that owns the schemas. * @param databaseName The name of the database where this schema lives. * @param schemas Schemas to set for this app. * @param visibilityStore If set, {@code schemasNotPlatformSurfaceable} and {@code * schemasPackageAccessible} will be saved here if the schema is successfully applied. * @param schemasNotPlatformSurfaceable Schema types that should not be surfaced on platform * @param visibilityStore If set, {@code schemasNotDisplayedBySystem} and {@code * schemasVisibleToPackages} will be saved here if the schema is successfully applied. * @param schemasNotDisplayedBySystem Schema types that should not be surfaced on platform * surfaces. * @param schemasPackageAccessible Schema types that are visible to the specified packages. * @param schemasVisibleToPackages Schema types that are visible to the specified packages. * @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. Loading @@ -366,8 +366,8 @@ public final class AppSearchImpl implements Closeable { @NonNull String databaseName, @NonNull List<AppSearchSchema> schemas, @Nullable VisibilityStore visibilityStore, @NonNull List<String> schemasNotPlatformSurfaceable, @NonNull Map<String, List<PackageIdentifier>> schemasPackageAccessible, @NonNull List<String> schemasNotDisplayedBySystem, @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages, boolean forceOverride, int version) throws AppSearchException { Loading Loading @@ -430,25 +430,25 @@ public final class AppSearchImpl implements Closeable { } if (visibilityStore != null) { Set<String> prefixedSchemasNotPlatformSurfaceable = new ArraySet<>(schemasNotPlatformSurfaceable.size()); for (int i = 0; i < schemasNotPlatformSurfaceable.size(); i++) { prefixedSchemasNotPlatformSurfaceable.add( prefix + schemasNotPlatformSurfaceable.get(i)); Set<String> prefixedSchemasNotDisplayedBySystem = new ArraySet<>(schemasNotDisplayedBySystem.size()); for (int i = 0; i < schemasNotDisplayedBySystem.size(); i++) { prefixedSchemasNotDisplayedBySystem.add( prefix + schemasNotDisplayedBySystem.get(i)); } Map<String, List<PackageIdentifier>> prefixedSchemasPackageAccessible = new ArrayMap<>(schemasPackageAccessible.size()); Map<String, List<PackageIdentifier>> prefixedSchemasVisibleToPackages = new ArrayMap<>(schemasVisibleToPackages.size()); for (Map.Entry<String, List<PackageIdentifier>> entry : schemasPackageAccessible.entrySet()) { prefixedSchemasPackageAccessible.put(prefix + entry.getKey(), entry.getValue()); schemasVisibleToPackages.entrySet()) { prefixedSchemasVisibleToPackages.put(prefix + entry.getKey(), entry.getValue()); } visibilityStore.setVisibility( packageName, databaseName, prefixedSchemasNotPlatformSurfaceable, prefixedSchemasPackageAccessible); prefixedSchemasNotDisplayedBySystem, prefixedSchemasVisibleToPackages); } return SetSchemaResponseToProtoConverter.toSetSchemaResponse( Loading Loading @@ -737,6 +737,9 @@ public final class AppSearchImpl implements Closeable { if (!filterPackageNames.isEmpty() && !filterPackageNames.contains(packageName)) { // Client wanted to query over some packages that weren't its own. This isn't // allowed through local query so we can return early with no results. if (logger != null) { sStatsBuilder.setStatusCode(AppSearchResult.RESULT_SECURITY_ERROR); } return new SearchResultPage(Bundle.EMPTY); } Loading Loading @@ -768,7 +771,7 @@ public final class AppSearchImpl implements Closeable { * @param queryExpression Query String to search. * @param searchSpec Spec for setting filters, raw query etc. * @param callerPackageName Package name of the caller, should belong to the {@code * userContext}. * callerUserHandle}. * @param visibilityStore Optional visibility store to obtain system and package visibility * settings from * @param callerUid UID of the client making the globalQuery call. Loading Loading @@ -1465,7 +1468,6 @@ public final class AppSearchImpl implements Closeable { mOptimizeIntervalCountLocked = 0; mSchemaMapLocked.clear(); mNamespaceMapLocked.clear(); if (initStatsBuilder != null) { initStatsBuilder .setHasReset(true) Loading
apex/appsearch/service/java/com/android/server/appsearch/external/localstorage/stats/SchemaMigrationStats.java 0 → 100644 +189 −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.NonNull; import android.app.appsearch.SetSchemaRequest; import java.util.Objects; /** * Class holds detailed stats for Schema migration. * * @hide */ // TODO(b/173532925): Hides getter and setter functions for accessing {@code // mFirstSetSchemaLatencyMillis} and {@code mSecondSetSchemaLatencyMillis} field. public final class SchemaMigrationStats { /** GetSchema latency in milliseconds. */ private final int mGetSchemaLatencyMillis; /** * Latency of querying all documents that need to be migrated to new version and transforming * documents to new version in milliseconds. */ private final int mQueryAndTransformLatencyMillis; private final int mFirstSetSchemaLatencyMillis; private final int mSecondSetSchemaLatencyMillis; /** Latency of putting migrated document to Icing lib in milliseconds. */ private final int mSaveDocumentLatencyMillis; private final int mMigratedDocumentCount; private final int mSavedDocumentCount; SchemaMigrationStats(@NonNull Builder builder) { Objects.requireNonNull(builder); mGetSchemaLatencyMillis = builder.mGetSchemaLatencyMillis; mQueryAndTransformLatencyMillis = builder.mQueryAndTransformLatencyMillis; mFirstSetSchemaLatencyMillis = builder.mFirstSetSchemaLatencyMillis; mSecondSetSchemaLatencyMillis = builder.mSecondSetSchemaLatencyMillis; mSaveDocumentLatencyMillis = builder.mSaveDocumentLatencyMillis; mMigratedDocumentCount = builder.mMigratedDocumentCount; mSavedDocumentCount = builder.mSavedDocumentCount; } /** Returns GetSchema latency in milliseconds. */ public int getGetSchemaLatencyMillis() { return mGetSchemaLatencyMillis; } /** * Returns latency of querying all documents that need to be migrated to new version and * transforming documents to new version in milliseconds. */ public int getQueryAndTransformLatencyMillis() { return mQueryAndTransformLatencyMillis; } /** * Returns latency of first SetSchema action in milliseconds. * * <p>If all schema fields are backward compatible, the schema will be successful set to Icing. * Otherwise, we will retrieve incompatible types here. * * <p>Please see {@link SetSchemaRequest} for what is "incompatible". */ public int getFirstSetSchemaLatencyMillis() { return mFirstSetSchemaLatencyMillis; } /** * Returns latency of second SetSchema action in milliseconds. * * <p>If all schema fields are backward compatible, the schema will be successful set to Icing * in the first setSchema action and this value will be 0. Otherwise, schema types will be set * to Icing by this action. */ public int getSecondSetSchemaLatencyMillis() { return mSecondSetSchemaLatencyMillis; } /** Returns latency of putting migrated document to Icing lib in milliseconds. */ public int getSaveDocumentLatencyMillis() { return mSaveDocumentLatencyMillis; } /** Returns number of migrated documents. */ public int getMigratedDocumentCount() { return mMigratedDocumentCount; } /** Returns number of updated documents which are saved in Icing lib. */ public int getSavedDocumentCount() { return mSavedDocumentCount; } /** Builder for {@link SchemaMigrationStats}. */ public static class Builder { int mGetSchemaLatencyMillis; int mQueryAndTransformLatencyMillis; int mFirstSetSchemaLatencyMillis; int mSecondSetSchemaLatencyMillis; int mSaveDocumentLatencyMillis; int mMigratedDocumentCount; int mSavedDocumentCount; /** Sets latency for the GetSchema action in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setGetSchemaLatencyMillis(int getSchemaLatencyMillis) { mGetSchemaLatencyMillis = getSchemaLatencyMillis; return this; } /** * Sets latency for querying all documents that need to be migrated to new version and * transforming documents to new version in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setQueryAndTransformLatencyMillis( int queryAndTransformLatencyMillis) { mQueryAndTransformLatencyMillis = queryAndTransformLatencyMillis; return this; } /** Sets latency of first SetSchema action in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setFirstSetSchemaLatencyMillis( int firstSetSchemaLatencyMillis) { mFirstSetSchemaLatencyMillis = firstSetSchemaLatencyMillis; return this; } /** Sets latency of second SetSchema action in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setSecondSetSchemaLatencyMillis( int secondSetSchemaLatencyMillis) { mSecondSetSchemaLatencyMillis = secondSetSchemaLatencyMillis; return this; } /** Sets latency for putting migrated document to Icing lib in milliseconds. */ @NonNull public SchemaMigrationStats.Builder setSaveDocumentLatencyMillis( int saveDocumentLatencyMillis) { mSaveDocumentLatencyMillis = saveDocumentLatencyMillis; return this; } /** Sets number of migrated documents. */ @NonNull public SchemaMigrationStats.Builder setMigratedDocumentCount(int migratedDocumentCount) { mMigratedDocumentCount = migratedDocumentCount; return this; } /** Sets number of updated documents which are saved in Icing lib. */ @NonNull public SchemaMigrationStats.Builder setSavedDocumentCount(int savedDocumentCount) { mSavedDocumentCount = savedDocumentCount; return this; } /** * Builds a new {@link SchemaMigrationStats} from the {@link SchemaMigrationStats.Builder}. */ @NonNull public SchemaMigrationStats build() { return new SchemaMigrationStats(/* builder= */ this); } } }