Update framework from jetpack.

Included changes:
* a8c984: Add more tests for logging
* 501a51: Remove some deprecated TODOs.
* 639f25: Add SchemaMigrationStats.
* 0b8885: Use consistent terminology for 3p and system access.
* 064c36: Add a CTS test for snippeting window sizes and max match counts.

Bug: 173532925
Bug: 187879464
Bug: 180058203
Test: Presubmit
Change-Id: I878fd6c7a42cccb237898392aac8c615830eb564
diff --git a/service/java/com/android/server/appsearch/AppSearchManagerService.java b/service/java/com/android/server/appsearch/AppSearchManagerService.java
index 400c241..ac584fe 100644
--- a/service/java/com/android/server/appsearch/AppSearchManagerService.java
+++ b/service/java/com/android/server/appsearch/AppSearchManagerService.java
@@ -333,7 +333,7 @@
                     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()) {
@@ -343,7 +343,7 @@
                             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(
@@ -352,7 +352,7 @@
                             schemas,
                             instance.getVisibilityStore(),
                             schemasNotDisplayedBySystem,
-                            schemasPackageAccessible,
+                            schemasVisibleToPackages,
                             forceOverride,
                             schemaVersion);
                     ++operationSuccessCount;
diff --git a/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java b/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
index 77a1bb4..4ad1c8c 100644
--- a/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
+++ b/service/java/com/android/server/appsearch/external/localstorage/AppSearchImpl.java
@@ -346,11 +346,11 @@
      * @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.
@@ -366,8 +366,8 @@
             @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 {
@@ -430,25 +430,25 @@
             }
 
             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(
@@ -737,6 +737,9 @@
             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);
             }
 
@@ -768,7 +771,7 @@
      * @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.
@@ -1465,7 +1468,6 @@
         mOptimizeIntervalCountLocked = 0;
         mSchemaMapLocked.clear();
         mNamespaceMapLocked.clear();
-
         if (initStatsBuilder != null) {
             initStatsBuilder
                     .setHasReset(true)
diff --git a/service/java/com/android/server/appsearch/external/localstorage/stats/SchemaMigrationStats.java b/service/java/com/android/server/appsearch/external/localstorage/stats/SchemaMigrationStats.java
new file mode 100644
index 0000000..6e1e2d5
--- /dev/null
+++ b/service/java/com/android/server/appsearch/external/localstorage/stats/SchemaMigrationStats.java
@@ -0,0 +1,189 @@
+/*
+ * 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);
+        }
+    }
+}
diff --git a/service/java/com/android/server/appsearch/external/localstorage/stats/SetSchemaStats.java b/service/java/com/android/server/appsearch/external/localstorage/stats/SetSchemaStats.java
index 56a546a..9d789a8 100644
--- a/service/java/com/android/server/appsearch/external/localstorage/stats/SetSchemaStats.java
+++ b/service/java/com/android/server/appsearch/external/localstorage/stats/SetSchemaStats.java
@@ -17,6 +17,7 @@
 package com.android.server.appsearch.external.localstorage.stats;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.appsearch.AppSearchResult;
 
 import java.util.Objects;
@@ -38,6 +39,12 @@
      */
     @AppSearchResult.ResultCode private final int mStatusCode;
 
+    /**
+     * Stores stats of SchemaMigration in SetSchema process. Is {@code null} if no schema migration
+     * is needed.
+     */
+    @Nullable private final SchemaMigrationStats mSchemaMigrationStats;
+
     private final int mTotalLatencyMillis;
 
     /** Overall time used for the native function call. */
@@ -63,6 +70,7 @@
         mPackageName = builder.mPackageName;
         mDatabase = builder.mDatabase;
         mStatusCode = builder.mStatusCode;
+        mSchemaMigrationStats = builder.mSchemaMigrationStats;
         mTotalLatencyMillis = builder.mTotalLatencyMillis;
         mNativeLatencyMillis = builder.mNativeLatencyMillis;
         mNewTypeCount = builder.mNewTypeCount;
@@ -90,6 +98,15 @@
         return mStatusCode;
     }
 
+    /**
+     * Returns the status of schema migration, if migration is executed during the SetSchema
+     * process. Otherwise, returns {@code null}.
+     */
+    @Nullable
+    public SchemaMigrationStats getSchemaMigrationStats() {
+        return mSchemaMigrationStats;
+    }
+
     /** Returns the total latency of the SetSchema action. */
     public int getTotalLatencyMillis() {
         return mTotalLatencyMillis;
@@ -140,6 +157,7 @@
         @NonNull final String mPackageName;
         @NonNull final String mDatabase;
         @AppSearchResult.ResultCode int mStatusCode;
+        @Nullable SchemaMigrationStats mSchemaMigrationStats;
         int mTotalLatencyMillis;
         int mNativeLatencyMillis;
         int mNewTypeCount;
@@ -161,7 +179,14 @@
             return this;
         }
 
-        /** Sets total latency for the SetSchema action. */
+        /** Sets the status of schema migration. */
+        @NonNull
+        public Builder setSchemaMigrationStats(@NonNull SchemaMigrationStats schemaMigrationStats) {
+            mSchemaMigrationStats = Objects.requireNonNull(schemaMigrationStats);
+            return this;
+        }
+
+        /** Sets total latency for the SetSchema action in milliseconds. */
         @NonNull
         public Builder setTotalLatencyMillis(int totalLatencyMillis) {
             mTotalLatencyMillis = totalLatencyMillis;
diff --git a/service/java/com/android/server/appsearch/visibilitystore/NotPlatformSurfaceableMap.java b/service/java/com/android/server/appsearch/visibilitystore/NotDisplayedBySystemMap.java
similarity index 95%
rename from service/java/com/android/server/appsearch/visibilitystore/NotPlatformSurfaceableMap.java
rename to service/java/com/android/server/appsearch/visibilitystore/NotDisplayedBySystemMap.java
index 9e36fd0..95905af 100644
--- a/service/java/com/android/server/appsearch/visibilitystore/NotPlatformSurfaceableMap.java
+++ b/service/java/com/android/server/appsearch/visibilitystore/NotDisplayedBySystemMap.java
@@ -27,7 +27,7 @@
  *
  * This object is not thread safe.
  */
-class NotPlatformSurfaceableMap {
+class NotDisplayedBySystemMap {
     /**
      * Maps packages to databases to the set of prefixed schemas that are platform-hidden within
      * that database.
@@ -39,7 +39,7 @@
      *
      * <p>Any existing mappings for this prefix are overwritten.
      */
-    public void setNotPlatformSurfaceable(
+    public void setNotDisplayedBySystem(
             @NonNull String packageName,
             @NonNull String databaseName,
             @NonNull Set<String> prefixedSchemas) {
@@ -55,7 +55,7 @@
      * Returns whether the given prefixed schema is platform surfaceable (has not opted out) in the
      * given database.
      */
-    public boolean isSchemaPlatformSurfaceable(
+    public boolean isSchemaDisplayedBySystem(
             @NonNull String packageName,
             @NonNull String databaseName,
             @NonNull String prefixedSchema) {
diff --git a/service/java/com/android/server/appsearch/visibilitystore/VisibilityDocument.java b/service/java/com/android/server/appsearch/visibilitystore/VisibilityDocument.java
index 1771b1d..b010870 100644
--- a/service/java/com/android/server/appsearch/visibilitystore/VisibilityDocument.java
+++ b/service/java/com/android/server/appsearch/visibilitystore/VisibilityDocument.java
@@ -28,10 +28,10 @@
     /**
      * Property that holds the list of platform-hidden schemas, as part of the visibility settings.
      */
-    private static final String NOT_PLATFORM_SURFACEABLE_PROPERTY = "notPlatformSurfaceable";
+    private static final String NOT_DISPLAYED_BY_SYSTEM_PROPERTY = "notPlatformSurfaceable";
 
     /** Property that holds nested documents of package accessible schemas. */
-    private static final String PACKAGE_ACCESSIBLE_PROPERTY = "packageAccessible";
+    private static final String VISIBLE_TO_PACKAGES_PROPERTY = "packageAccessible";
 
     /**
      * Schema for the VisibilityStore's documents.
@@ -41,11 +41,11 @@
      */
     public static final AppSearchSchema SCHEMA = new AppSearchSchema.Builder(SCHEMA_TYPE)
             .addProperty(new AppSearchSchema.StringPropertyConfig.Builder(
-                    NOT_PLATFORM_SURFACEABLE_PROPERTY)
+                    NOT_DISPLAYED_BY_SYSTEM_PROPERTY)
                     .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_REPEATED)
                     .build())
             .addProperty(new AppSearchSchema.DocumentPropertyConfig.Builder(
-                    PACKAGE_ACCESSIBLE_PROPERTY, PackageAccessibleDocument.SCHEMA_TYPE)
+                    VISIBLE_TO_PACKAGES_PROPERTY, VisibleToPackagesDocument.SCHEMA_TYPE)
                     .setCardinality(AppSearchSchema.PropertyConfig.CARDINALITY_REPEATED)
                     .build())
             .build();
@@ -55,13 +55,13 @@
     }
 
     @Nullable
-    public String[] getNotPlatformSurfaceableSchemas() {
-        return getPropertyStringArray(NOT_PLATFORM_SURFACEABLE_PROPERTY);
+    public String[] getNotDisplayedBySystem() {
+        return getPropertyStringArray(NOT_DISPLAYED_BY_SYSTEM_PROPERTY);
     }
 
     @Nullable
-    public GenericDocument[] getPackageAccessibleSchemas() {
-        return getPropertyDocumentArray(PACKAGE_ACCESSIBLE_PROPERTY);
+    public GenericDocument[] getVisibleToPackages() {
+        return getPropertyDocumentArray(VISIBLE_TO_PACKAGES_PROPERTY);
     }
 
     /** Builder for {@link VisibilityDocument}. */
@@ -72,17 +72,15 @@
 
         /** Sets which prefixed schemas have opted out of platform surfacing. */
         @NonNull
-        public Builder setSchemasNotPlatformSurfaceable(
-                @NonNull String[] notPlatformSurfaceableSchemas) {
-            return setPropertyString(
-                    NOT_PLATFORM_SURFACEABLE_PROPERTY, notPlatformSurfaceableSchemas);
+        public Builder setNotDisplayedBySystem(@NonNull String[] notDisplayedBySystemSchemas) {
+            return setPropertyString(NOT_DISPLAYED_BY_SYSTEM_PROPERTY, notDisplayedBySystemSchemas);
         }
 
         /** Sets which prefixed schemas have configured package access. */
         @NonNull
-        public Builder setPackageAccessibleSchemas(
-                @NonNull PackageAccessibleDocument[] packageAccessibleSchemas) {
-            return setPropertyDocument(PACKAGE_ACCESSIBLE_PROPERTY, packageAccessibleSchemas);
+        public Builder setVisibleToPackages(
+                @NonNull VisibleToPackagesDocument[] visibleToPackagesDocuments) {
+            return setPropertyDocument(VISIBLE_TO_PACKAGES_PROPERTY, visibleToPackagesDocuments);
         }
     }
 }
diff --git a/service/java/com/android/server/appsearch/visibilitystore/VisibilityStore.java b/service/java/com/android/server/appsearch/visibilitystore/VisibilityStore.java
index ae1ec56..a096aef 100644
--- a/service/java/com/android/server/appsearch/visibilitystore/VisibilityStore.java
+++ b/service/java/com/android/server/appsearch/visibilitystore/VisibilityStore.java
@@ -66,9 +66,6 @@
  * @hide
  */
 public class VisibilityStore {
-    /** No-op uid that won't have any visibility settings. */
-    public static final int NO_OP_UID = -1;
-
     /** Version for the visibility schema */
     private static final int SCHEMA_VERSION = 0;
 
@@ -92,11 +89,10 @@
     private final Context mUserContext;
 
     /** Stores the schemas that are platform-hidden. All values are prefixed. */
-    private final NotPlatformSurfaceableMap mNotPlatformSurfaceableMap =
-            new NotPlatformSurfaceableMap();
+    private final NotDisplayedBySystemMap mNotDisplayedBySystemMap = new NotDisplayedBySystemMap();
 
-    /** Stores the schemas that are package accessible. All values are prefixed. */
-    private final PackageAccessibleMap mPackageAccessibleMap = new PackageAccessibleMap();
+    /** Stores the schemas that are visible to 3p packages. All values are prefixed. */
+    private final VisibleToPackagesMap mVisibleToPackagesMap = new VisibleToPackagesMap();
 
     /**
      * Creates and initializes VisibilityStore.
@@ -118,28 +114,28 @@
 
         GetSchemaResponse getSchemaResponse = mAppSearchImpl.getSchema(PACKAGE_NAME, DATABASE_NAME);
         boolean hasVisibilityType = false;
-        boolean hasPackageAccessibleType = false;
+        boolean hasVisibleToPackagesType = false;
         for (AppSearchSchema schema : getSchemaResponse.getSchemas()) {
             if (schema.getSchemaType().equals(VisibilityDocument.SCHEMA_TYPE)) {
                 hasVisibilityType = true;
-            } else if (schema.getSchemaType().equals(PackageAccessibleDocument.SCHEMA_TYPE)) {
-                hasPackageAccessibleType = true;
+            } else if (schema.getSchemaType().equals(VisibleToPackagesDocument.SCHEMA_TYPE)) {
+                hasVisibleToPackagesType = true;
             }
 
-            if (hasVisibilityType && hasPackageAccessibleType) {
+            if (hasVisibilityType && hasVisibleToPackagesType) {
                 // Found both our types, can exit early.
                 break;
             }
         }
-        if (!hasVisibilityType || !hasPackageAccessibleType) {
+        if (!hasVisibilityType || !hasVisibleToPackagesType) {
             // Schema type doesn't exist yet. Add it.
             mAppSearchImpl.setSchema(
                     PACKAGE_NAME,
                     DATABASE_NAME,
-                    Arrays.asList(VisibilityDocument.SCHEMA, PackageAccessibleDocument.SCHEMA),
+                    Arrays.asList(VisibilityDocument.SCHEMA, VisibleToPackagesDocument.SCHEMA),
                     /*visibilityStore=*/ null,  // Avoid recursive calls
-                    /*schemasNotPlatformSurfaceable=*/ Collections.emptyList(),
-                    /*schemasPackageAccessible=*/ Collections.emptyMap(),
+                    /*schemasNotDisplayedBySystem=*/ Collections.emptyList(),
+                    /*schemasVisibleToPackages=*/ Collections.emptyMap(),
                     /*forceOverride=*/ false,
                     /*version=*/ SCHEMA_VERSION);
         }
@@ -177,26 +173,25 @@
                 }
 
                 // Update platform visibility settings
-                String[] notPlatformSurfaceableSchemas =
-                        visibilityDocument.getNotPlatformSurfaceableSchemas();
-                if (notPlatformSurfaceableSchemas != null) {
-                    mNotPlatformSurfaceableMap.setNotPlatformSurfaceable(
+                String[] notDisplayedBySystemSchemas = visibilityDocument.getNotDisplayedBySystem();
+                if (notDisplayedBySystemSchemas != null) {
+                    mNotDisplayedBySystemMap.setNotDisplayedBySystem(
                             packageName,
                             databaseName,
-                            new ArraySet<>(notPlatformSurfaceableSchemas));
+                            new ArraySet<>(notDisplayedBySystemSchemas));
                 }
 
                 // Update 3p package visibility settings
                 Map<String, Set<PackageIdentifier>> schemaToPackageIdentifierMap = new ArrayMap<>();
-                GenericDocument[] packageAccessibleDocuments =
-                        visibilityDocument.getPackageAccessibleSchemas();
-                if (packageAccessibleDocuments != null) {
-                    for (int i = 0; i < packageAccessibleDocuments.length; i++) {
-                        PackageAccessibleDocument packageAccessibleDocument =
-                                new PackageAccessibleDocument(packageAccessibleDocuments[i]);
+                GenericDocument[] visibleToPackagesDocuments =
+                        visibilityDocument.getVisibleToPackages();
+                if (visibleToPackagesDocuments != null) {
+                    for (int i = 0; i < visibleToPackagesDocuments.length; i++) {
+                        VisibleToPackagesDocument visibleToPackagesDocument =
+                                new VisibleToPackagesDocument(visibleToPackagesDocuments[i]);
                         PackageIdentifier packageIdentifier =
-                                packageAccessibleDocument.getPackageIdentifier();
-                        String prefixedSchema = packageAccessibleDocument.getAccessibleSchemaType();
+                                visibleToPackagesDocument.getPackageIdentifier();
+                        String prefixedSchema = visibleToPackagesDocument.getAccessibleSchemaType();
                         Set<PackageIdentifier> packageIdentifiers =
                                 schemaToPackageIdentifierMap.get(prefixedSchema);
                         if (packageIdentifiers == null) {
@@ -206,7 +201,7 @@
                         schemaToPackageIdentifierMap.put(prefixedSchema, packageIdentifiers);
                     }
                 }
-                mPackageAccessibleMap.setPackageAccessible(
+                mVisibleToPackagesMap.setVisibleToPackages(
                         packageName, databaseName, schemaToPackageIdentifierMap);
             }
         }
@@ -216,51 +211,51 @@
      * Sets visibility settings for the given database. Any previous visibility settings will be
      * overwritten.
      *
-     * @param packageName Package of app that owns the {@code schemasNotPlatformSurfaceable}.
-     * @param databaseName Database that owns the {@code schemasNotPlatformSurfaceable}.
-     * @param schemasNotPlatformSurfaceable Set of prefixed schemas that should be hidden from the
+     * @param packageName Package of app that owns the schemas.
+     * @param databaseName Database that owns the schemas.
+     * @param schemasNotDisplayedBySystem Set of prefixed schemas that should be hidden from the
      *     platform.
-     * @param schemasPackageAccessible Map of prefixed schemas to a list of package identifiers that
+     * @param schemasVisibleToPackages Map of prefixed schemas to a list of package identifiers that
      *     have access to the schema.
      * @throws AppSearchException on AppSearchImpl error.
      */
     public void setVisibility(
             @NonNull String packageName,
             @NonNull String databaseName,
-            @NonNull Set<String> schemasNotPlatformSurfaceable,
-            @NonNull Map<String, List<PackageIdentifier>> schemasPackageAccessible)
+            @NonNull Set<String> schemasNotDisplayedBySystem,
+            @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages)
             throws AppSearchException {
         Objects.requireNonNull(packageName);
         Objects.requireNonNull(databaseName);
-        Objects.requireNonNull(schemasNotPlatformSurfaceable);
-        Objects.requireNonNull(schemasPackageAccessible);
+        Objects.requireNonNull(schemasNotDisplayedBySystem);
+        Objects.requireNonNull(schemasVisibleToPackages);
 
         // Persist the document
         VisibilityDocument.Builder visibilityDocument =
                 new VisibilityDocument.Builder(
                         NAMESPACE, /*id=*/ getVisibilityDocumentId(packageName, databaseName));
-        if (!schemasNotPlatformSurfaceable.isEmpty()) {
-            visibilityDocument.setSchemasNotPlatformSurfaceable(
-                    schemasNotPlatformSurfaceable.toArray(new String[0]));
+        if (!schemasNotDisplayedBySystem.isEmpty()) {
+            visibilityDocument.setNotDisplayedBySystem(
+                    schemasNotDisplayedBySystem.toArray(new String[0]));
         }
 
         Map<String, Set<PackageIdentifier>> schemaToPackageIdentifierMap = new ArrayMap<>();
-        List<PackageAccessibleDocument> packageAccessibleDocuments = new ArrayList<>();
+        List<VisibleToPackagesDocument> visibleToPackagesDocuments = new ArrayList<>();
         for (Map.Entry<String, List<PackageIdentifier>> entry :
-                schemasPackageAccessible.entrySet()) {
+                schemasVisibleToPackages.entrySet()) {
             for (int i = 0; i < entry.getValue().size(); i++) {
-                PackageAccessibleDocument packageAccessibleDocument =
-                        new PackageAccessibleDocument.Builder(NAMESPACE, /*id=*/ "")
+                VisibleToPackagesDocument visibleToPackagesDocument =
+                        new VisibleToPackagesDocument.Builder(NAMESPACE, /*id=*/ "")
                                 .setAccessibleSchemaType(entry.getKey())
                                 .setPackageIdentifier(entry.getValue().get(i))
                                 .build();
-                packageAccessibleDocuments.add(packageAccessibleDocument);
+                visibleToPackagesDocuments.add(visibleToPackagesDocument);
             }
             schemaToPackageIdentifierMap.put(entry.getKey(), new ArraySet<>(entry.getValue()));
         }
-        if (!packageAccessibleDocuments.isEmpty()) {
-            visibilityDocument.setPackageAccessibleSchemas(
-                    packageAccessibleDocuments.toArray(new PackageAccessibleDocument[0]));
+        if (!visibleToPackagesDocuments.isEmpty()) {
+            visibilityDocument.setVisibleToPackages(
+                    visibleToPackagesDocuments.toArray(new VisibleToPackagesDocument[0]));
         }
 
         mAppSearchImpl.putDocument(
@@ -269,9 +264,9 @@
         mAppSearchImpl.persistToDisk(PersistType.Code.LITE);
 
         // Update derived data structures.
-        mNotPlatformSurfaceableMap.setNotPlatformSurfaceable(
-                packageName, databaseName, schemasNotPlatformSurfaceable);
-        mPackageAccessibleMap.setPackageAccessible(
+        mNotDisplayedBySystemMap.setNotDisplayedBySystem(
+                packageName, databaseName, schemasNotDisplayedBySystem);
+        mVisibleToPackagesMap.setVisibleToPackages(
                 packageName, databaseName, schemaToPackageIdentifierMap);
     }
 
@@ -313,13 +308,13 @@
         }
 
         if (callerHasSystemAccess
-                && mNotPlatformSurfaceableMap.isSchemaPlatformSurfaceable(
+                && mNotDisplayedBySystemMap.isSchemaDisplayedBySystem(
                 packageName, databaseName, prefixedSchema)) {
             return true;
         }
 
         // May not be platform surfaceable, but might still be accessible through 3p access.
-        return isSchemaPackageAccessible(packageName, databaseName, prefixedSchema, callerUid);
+        return isSchemaVisibleToPackages(packageName, databaseName, prefixedSchema, callerUid);
     }
 
     /**
@@ -331,13 +326,13 @@
      * certificate was once used to sign the package, the package will still be granted access. This
      * does not handle packages that have been signed by multiple certificates.
      */
-    private boolean isSchemaPackageAccessible(
+    private boolean isSchemaVisibleToPackages(
             @NonNull String packageName,
             @NonNull String databaseName,
             @NonNull String prefixedSchema,
             int callerUid) {
         Set<PackageIdentifier> packageIdentifiers =
-                mPackageAccessibleMap.getAccessiblePackages(
+                mVisibleToPackagesMap.getAccessiblePackages(
                         packageName, databaseName, prefixedSchema);
         if (packageIdentifiers.isEmpty()) {
             return false;
diff --git a/service/java/com/android/server/appsearch/visibilitystore/PackageAccessibleDocument.java b/service/java/com/android/server/appsearch/visibilitystore/VisibleToPackagesDocument.java
similarity index 90%
rename from service/java/com/android/server/appsearch/visibilitystore/PackageAccessibleDocument.java
rename to service/java/com/android/server/appsearch/visibilitystore/VisibleToPackagesDocument.java
index 0b4e196..8d50339 100644
--- a/service/java/com/android/server/appsearch/visibilitystore/PackageAccessibleDocument.java
+++ b/service/java/com/android/server/appsearch/visibilitystore/VisibleToPackagesDocument.java
@@ -26,7 +26,7 @@
  *
  * @see android.app.appsearch.SetSchemaRequest.Builder#setSchemaTypeVisibilityForPackage
  */
-class PackageAccessibleDocument extends GenericDocument {
+class VisibleToPackagesDocument extends GenericDocument {
     /** Schema type for nested documents that hold package accessible information. */
     public static final String SCHEMA_TYPE = "PackageAccessibleType";
 
@@ -59,7 +59,7 @@
                     .build())
             .build();
 
-    public PackageAccessibleDocument(@NonNull GenericDocument genericDocument) {
+    VisibleToPackagesDocument(@NonNull GenericDocument genericDocument) {
         super(genericDocument);
     }
 
@@ -76,9 +76,9 @@
         return new PackageIdentifier(packageName, sha256Cert);
     }
 
-    /** Builder for {@link PackageAccessibleDocument} instances. */
-    public static class Builder extends GenericDocument.Builder<PackageAccessibleDocument.Builder> {
-        public Builder(@NonNull String namespace, @NonNull String id) {
+    /** Builder for {@link VisibleToPackagesDocument} instances. */
+    public static class Builder extends GenericDocument.Builder<VisibleToPackagesDocument.Builder> {
+        Builder(@NonNull String namespace, @NonNull String id) {
             super(namespace, id, SCHEMA_TYPE);
         }
 
@@ -98,8 +98,8 @@
 
         @Override
         @NonNull
-        public PackageAccessibleDocument build() {
-            return new PackageAccessibleDocument(super.build());
+        public VisibleToPackagesDocument build() {
+            return new VisibleToPackagesDocument(super.build());
         }
     }
 }
diff --git a/service/java/com/android/server/appsearch/visibilitystore/PackageAccessibleMap.java b/service/java/com/android/server/appsearch/visibilitystore/VisibleToPackagesMap.java
similarity index 97%
rename from service/java/com/android/server/appsearch/visibilitystore/PackageAccessibleMap.java
rename to service/java/com/android/server/appsearch/visibilitystore/VisibleToPackagesMap.java
index cff729a..e2b51a7 100644
--- a/service/java/com/android/server/appsearch/visibilitystore/PackageAccessibleMap.java
+++ b/service/java/com/android/server/appsearch/visibilitystore/VisibleToPackagesMap.java
@@ -29,7 +29,7 @@
  *
  * This object is not thread safe.
  */
-class PackageAccessibleMap {
+class VisibleToPackagesMap {
     /**
      * Maps packages to databases to prefixed schemas to PackageIdentifiers that have access to that
      * schema.
@@ -42,7 +42,7 @@
      *
      * <p>Any existing mappings for this prefix are overwritten.
      */
-    public void setPackageAccessible(
+    public void setVisibleToPackages(
             @NonNull String packageName,
             @NonNull String databaseName,
             @NonNull Map<String, Set<PackageIdentifier>> schemaToPackageIdentifier) {