summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cassie Wang <cassiewang@google.com> 2021-02-11 15:48:03 -0800
committer Cassie Wang <cassiewang@google.com> 2021-02-12 11:16:31 -0800
commite1d191c86b0dd434bcf7de724d98a4a541cc84ff (patch)
tree5b16ef9d4283b40e4a9cc5f87394fa4f09d75cae
parentbfde98c357623e417eaa667a3595665d56039013 (diff)
Check schemas using getSchema in VisibilityStore.
This switches away from the package-private hasSchemaTypeLocked method that is only package-private because VisibilityStore uses it. Instead, use the publicly-supported getSchema API. Using getSchema will be less efficient than hasSchemaTypeLocked, but it should only be called once during initialization so it won't be reoccuring. The change to remove hasSchemaTypeLocked from AppSearchImpl will be made upstream in go/ag/13556686 Bug: 180058203 Test: presubmit Change-Id: I2bafb8243bb15f321633eae5ed37676201e98c84
-rw-r--r--apex/appsearch/service/java/com/android/server/appsearch/VisibilityStore.java29
1 files changed, 22 insertions, 7 deletions
diff --git a/apex/appsearch/service/java/com/android/server/appsearch/VisibilityStore.java b/apex/appsearch/service/java/com/android/server/appsearch/VisibilityStore.java
index babcd25e3e26..7c92456bea49 100644
--- a/apex/appsearch/service/java/com/android/server/appsearch/VisibilityStore.java
+++ b/apex/appsearch/service/java/com/android/server/appsearch/VisibilityStore.java
@@ -218,9 +218,23 @@ public class VisibilityStore {
* @throws AppSearchException AppSearchException on AppSearchImpl error.
*/
public void initialize() throws AppSearchException {
- if (!mAppSearchImpl.hasSchemaTypeLocked(PACKAGE_NAME, DATABASE_NAME, VISIBILITY_TYPE)
- || !mAppSearchImpl.hasSchemaTypeLocked(
- PACKAGE_NAME, DATABASE_NAME, PACKAGE_ACCESSIBLE_TYPE)) {
+ List<AppSearchSchema> schemas = mAppSearchImpl.getSchema(PACKAGE_NAME, DATABASE_NAME);
+ boolean hasVisibilityType = false;
+ boolean hasPackageAccessibleType = false;
+ for (int i = 0; i < schemas.size(); i++) {
+ AppSearchSchema schema = schemas.get(i);
+ if (schema.getSchemaType().equals(VISIBILITY_TYPE)) {
+ hasVisibilityType = true;
+ } else if (schema.getSchemaType().equals(PACKAGE_ACCESSIBLE_TYPE)) {
+ hasPackageAccessibleType = true;
+ }
+
+ if (hasVisibilityType && hasPackageAccessibleType) {
+ // Found both our types, can exit early.
+ break;
+ }
+ }
+ if (!hasVisibilityType || !hasPackageAccessibleType) {
// Schema type doesn't exist yet. Add it.
mAppSearchImpl.setSchema(
PACKAGE_NAME,
@@ -250,10 +264,11 @@ public class VisibilityStore {
/*typePropertyPaths=*/ Collections.emptyMap());
// Update platform visibility settings
- String[] schemas =
+ String[] notPlatformSurfaceableSchemas =
document.getPropertyStringArray(NOT_PLATFORM_SURFACEABLE_PROPERTY);
- if (schemas != null) {
- mNotPlatformSurfaceableMap.put(prefix, new ArraySet<>(Arrays.asList(schemas)));
+ if (notPlatformSurfaceableSchemas != null) {
+ mNotPlatformSurfaceableMap.put(
+ prefix, new ArraySet<>(Arrays.asList(notPlatformSurfaceableSchemas)));
}
// Update 3p package visibility settings
@@ -333,7 +348,7 @@ public class VisibilityStore {
schemasPackageAccessible.entrySet()) {
for (int i = 0; i < entry.getValue().size(); i++) {
GenericDocument packageAccessibleDocument =
- new GenericDocument.Builder(/*uri=*/"", PACKAGE_ACCESSIBLE_TYPE)
+ new GenericDocument.Builder(/*uri=*/ "", PACKAGE_ACCESSIBLE_TYPE)
.setNamespace(NAMESPACE)
.setPropertyString(
PACKAGE_NAME_PROPERTY,