1 /* 2 * Copyright (C) 2022 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 17 package com.android.server.pm; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Process; 22 import android.util.ArrayMap; 23 import android.util.SparseArray; 24 25 import com.android.internal.util.function.QuadFunction; 26 import com.android.server.pm.pkg.AndroidPackage; 27 import com.android.server.pm.pkg.PackageStateInternal; 28 import com.android.server.pm.snapshot.PackageDataSnapshot; 29 30 import java.io.PrintWriter; 31 32 /** 33 * Read-only interface used by computer and snapshots to query the visibility of packages 34 */ 35 public interface AppsFilterSnapshot { 36 /** 37 * Fetches all app Ids that a given setting is currently visible to, per provided user. This 38 * only includes UIDs >= {@link Process#FIRST_APPLICATION_UID} as all other UIDs can already see 39 * all applications. 40 * 41 * If the setting is visible to all UIDs, null is returned. If an app is not visible to any 42 * applications, the int array will be empty. 43 * 44 * @param snapshot the snapshot of the computer that contains all package information 45 * @param users the set of users that should be evaluated for this calculation 46 * @param existingSettings the set of all package settings that currently exist on device 47 * @return a SparseArray mapping userIds to a sorted int array of appIds that may view the 48 * provided setting or null if the app is visible to all and no allow list should be 49 * applied. 50 */ getVisibilityAllowList(PackageDataSnapshot snapshot, PackageStateInternal setting, int[] users, ArrayMap<String, ? extends PackageStateInternal> existingSettings)51 SparseArray<int[]> getVisibilityAllowList(PackageDataSnapshot snapshot, 52 PackageStateInternal setting, int[] users, 53 ArrayMap<String, ? extends PackageStateInternal> existingSettings); 54 55 /** 56 * Returns true if the calling package should not be able to see the target package, false if no 57 * filtering should be done. 58 * 59 * @param snapshot the snapshot of the computer that contains all package information 60 * @param callingUid the uid of the caller attempting to access a package 61 * @param callingSetting the setting attempting to access a package or null if it could not be 62 * found 63 * @param targetPkgSetting the package being accessed 64 * @param userId the user in which this access is being attempted 65 */ shouldFilterApplication(PackageDataSnapshot snapshot, int callingUid, @Nullable Object callingSetting, PackageStateInternal targetPkgSetting, int userId)66 boolean shouldFilterApplication(PackageDataSnapshot snapshot, int callingUid, 67 @Nullable Object callingSetting, PackageStateInternal targetPkgSetting, int userId); 68 69 /** 70 * Returns whether the querying package is allowed to see the target package. 71 * 72 * @param querying the querying package 73 * @param potentialTarget the package name of the target package 74 */ canQueryPackage(@onNull AndroidPackage querying, String potentialTarget)75 boolean canQueryPackage(@NonNull AndroidPackage querying, String potentialTarget); 76 77 /** 78 * Dump the packages that are queryable by the querying package. 79 * 80 * @param pw the output print writer 81 * @param filteringAppId the querying package's app ID 82 * @param dumpState the state of the dumping 83 * @param users the users for which the packages are installed 84 * @param getPackagesForUid the function that produces the package names for given uids 85 */ dumpQueries(PrintWriter pw, @Nullable Integer filteringAppId, DumpState dumpState, int[] users, QuadFunction<Integer, Integer, Integer, Boolean, String[]> getPackagesForUid)86 void dumpQueries(PrintWriter pw, @Nullable Integer filteringAppId, DumpState dumpState, 87 int[] users, 88 QuadFunction<Integer, Integer, Integer, Boolean, String[]> getPackagesForUid); 89 90 } 91