1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.server.appsearch.external.localstorage.visibilitystore; 17 18 import android.annotation.NonNull; 19 import android.app.appsearch.PackageIdentifier; 20 import android.app.appsearch.exceptions.AppSearchException; 21 22 import com.android.internal.annotations.VisibleForTesting; 23 24 import java.util.List; 25 import java.util.Map; 26 import java.util.Set; 27 28 /** 29 * An interface for classes that store and validate document visibility data. 30 * 31 * @hide 32 */ 33 public interface VisibilityStore { 34 /** 35 * These cannot have any of the special characters used by AppSearchImpl (e.g. {@code 36 * AppSearchImpl#PACKAGE_DELIMITER} or {@code AppSearchImpl#DATABASE_DELIMITER}. 37 */ 38 String PACKAGE_NAME = "VS#Pkg"; 39 40 @VisibleForTesting String DATABASE_NAME = "VS#Db"; 41 42 /** 43 * Sets visibility settings for the given database. Any previous visibility settings will be 44 * overwritten. 45 * 46 * @param packageName Package of app that owns the schemas. 47 * @param databaseName Database that owns the schemas. 48 * @param schemasNotDisplayedBySystem Set of prefixed schemas that should be hidden from 49 * platform surfaces. 50 * @param schemasVisibleToPackages Map of prefixed schemas to a list of package identifiers that 51 * have access to the schema. 52 * @throws AppSearchException on AppSearchImpl error. 53 */ setVisibility( @onNull String packageName, @NonNull String databaseName, @NonNull Set<String> schemasNotDisplayedBySystem, @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages)54 void setVisibility( 55 @NonNull String packageName, 56 @NonNull String databaseName, 57 @NonNull Set<String> schemasNotDisplayedBySystem, 58 @NonNull Map<String, List<PackageIdentifier>> schemasVisibleToPackages) 59 throws AppSearchException; 60 61 /** 62 * Checks whether the given package has access to system-surfaceable schemas. 63 * 64 * @param callerUid UID of the app that wants to see the data. 65 */ isSchemaSearchableByCaller( @onNull String packageName, @NonNull String databaseName, @NonNull String prefixedSchema, int callerUid, boolean callerHasSystemAccess)66 boolean isSchemaSearchableByCaller( 67 @NonNull String packageName, 68 @NonNull String databaseName, 69 @NonNull String prefixedSchema, 70 int callerUid, 71 boolean callerHasSystemAccess); 72 } 73