1 /*
2  * Copyright (C) 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 
17 package com.android.server.pm;
18 
19 
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.UserIdInt;
23 import android.content.ComponentName;
24 import android.content.Intent;
25 import android.content.IntentFilter;
26 import android.content.pm.ActivityInfo;
27 import android.content.pm.ApplicationInfo;
28 import android.content.pm.ComponentInfo;
29 import android.content.pm.InstallSourceInfo;
30 import android.content.pm.InstrumentationInfo;
31 import android.content.pm.KeySet;
32 import android.content.pm.PackageInfo;
33 import android.content.pm.PackageManager;
34 import android.content.pm.PackageManagerInternal;
35 import android.content.pm.ParceledListSlice;
36 import android.content.pm.ProcessInfo;
37 import android.content.pm.ProviderInfo;
38 import android.content.pm.ResolveInfo;
39 import android.content.pm.ServiceInfo;
40 import android.content.pm.SharedLibraryInfo;
41 import android.content.pm.SigningDetails;
42 import android.content.pm.UserInfo;
43 import android.content.pm.VersionedPackage;
44 import android.os.UserHandle;
45 import android.util.ArrayMap;
46 import android.util.ArraySet;
47 import android.util.Pair;
48 import android.util.SparseArray;
49 import android.util.proto.ProtoOutputStream;
50 
51 import com.android.internal.annotations.VisibleForTesting;
52 import com.android.server.pm.pkg.AndroidPackage;
53 import com.android.server.pm.pkg.PackageState;
54 import com.android.server.pm.pkg.PackageStateInternal;
55 import com.android.server.pm.pkg.SharedUserApi;
56 import com.android.server.pm.resolution.ComponentResolverApi;
57 import com.android.server.pm.snapshot.PackageDataSnapshot;
58 import com.android.server.utils.WatchedArrayMap;
59 import com.android.server.utils.WatchedLongSparseArray;
60 
61 import java.io.FileDescriptor;
62 import java.io.PrintWriter;
63 import java.util.Collection;
64 import java.util.List;
65 import java.util.Set;
66 
67 /**
68  * A {@link Computer} provides a set of functions that can operate on live data or snapshot
69  * data.  At this time, the {@link Computer} is implemented by the
70  * {@link ComputerEngine}, which is in turn extended by {@link ComputerLocked}.
71  *
72  * New functions must be added carefully.
73  * <ol>
74  * <li> New functions must be true functions with respect to data collected in a
75  * {@link PackageManagerService.Snapshot}.  Such data may never be modified from inside a {@link Computer}
76  * function.
77  * </li>
78  *
79  * <li> A new function must be implemented in {@link ComputerEngine}.
80  * </li>
81  *
82  * <li> A new function must be overridden in {@link ComputerLocked} if the function
83  * cannot safely access live data without holding the PackageManagerService lock.  The
84  * form of the {@link ComputerLocked} function must be a single call to the
85  * {@link ComputerEngine} implementation, wrapped in a <code>synchronized</code>
86  * block.  Functions in {@link ComputerLocked} should never include any other code.
87  * </li>
88  *
89  * Care must be taken when deciding if a function should be overridden in
90  * {@link ComputerLocked}.  The complex lock relationships of PackageManagerService
91  * and other managers (like PermissionManager) mean deadlock is possible.  On the
92  * other hand, not overriding in {@link ComputerLocked} may leave a function walking
93  * unstable data.
94  */
95 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
96 public interface Computer extends PackageDataSnapshot {
97 
getVersion()98     int getVersion();
99 
100     /**
101      * Administrative statistics: record that the snapshot has been used.  Every call
102      * to use() increments the usage counter.
103      */
use()104     Computer use();
105     /**
106      * Fetch the snapshot usage counter.
107      * @return The number of times this snapshot was used.
108      */
getUsed()109     default int getUsed() {
110         return 0;
111     }
queryIntentActivitiesInternal(Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, @PackageManagerInternal.PrivateResolveFlags long privateResolveFlags, int filterCallingUid, int userId, boolean resolveForStart, boolean allowDynamicSplits)112     @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType,
113             @PackageManager.ResolveInfoFlagsBits long flags,
114             @PackageManagerInternal.PrivateResolveFlags long privateResolveFlags,
115             int filterCallingUid, int userId, boolean resolveForStart, boolean allowDynamicSplits);
queryIntentActivitiesInternal(Intent intent, String resolvedType, long flags, int filterCallingUid, int userId)116     @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType,
117             long flags, int filterCallingUid, int userId);
queryIntentActivitiesInternal(Intent intent, String resolvedType, long flags, int userId)118     @NonNull List<ResolveInfo> queryIntentActivitiesInternal(Intent intent, String resolvedType,
119             long flags, int userId);
queryIntentServicesInternal(Intent intent, String resolvedType, long flags, int userId, int callingUid, boolean includeInstantApps)120     @NonNull List<ResolveInfo> queryIntentServicesInternal(Intent intent, String resolvedType,
121             long flags, int userId, int callingUid, boolean includeInstantApps);
queryIntentActivitiesInternalBody(Intent intent, String resolvedType, long flags, int filterCallingUid, int userId, boolean resolveForStart, boolean allowDynamicSplits, String pkgName, String instantAppPkgName)122     @NonNull QueryIntentActivitiesResult queryIntentActivitiesInternalBody(Intent intent,
123             String resolvedType, long flags, int filterCallingUid, int userId,
124             boolean resolveForStart, boolean allowDynamicSplits, String pkgName,
125             String instantAppPkgName);
getActivityInfo(ComponentName component, long flags, int userId)126     ActivityInfo getActivityInfo(ComponentName component, long flags, int userId);
127 
128     /**
129      * Similar to {@link Computer#getActivityInfo(android.content.ComponentName, long, int)} but
130      * only visible as internal service. This method bypass INTERACT_ACROSS_USERS or
131      * INTERACT_ACROSS_USERS_FULL permission checks and only to be used for intent resolution across
132      * chained cross profiles
133      */
getActivityInfoCrossProfile(ComponentName component, long flags, int userId)134     ActivityInfo getActivityInfoCrossProfile(ComponentName component, long flags, int userId);
135 
136     /**
137      * Important: The provided filterCallingUid is used exclusively to filter out activities
138      * that can be seen based on user state. It's typically the original caller uid prior
139      * to clearing. Because it can only be provided by trusted code, its value can be
140      * trusted and will be used as-is; unlike userId which will be validated by this method.
141      */
getActivityInfoInternal(ComponentName component, long flags, int filterCallingUid, int userId)142     ActivityInfo getActivityInfoInternal(ComponentName component, long flags,
143             int filterCallingUid, int userId);
getPackage(String packageName)144     AndroidPackage getPackage(String packageName);
getPackage(int uid)145     AndroidPackage getPackage(int uid);
generateApplicationInfoFromSettings(String packageName, long flags, int filterCallingUid, int userId)146     ApplicationInfo generateApplicationInfoFromSettings(String packageName, long flags,
147             int filterCallingUid, int userId);
getApplicationInfo(String packageName, long flags, int userId)148     ApplicationInfo getApplicationInfo(String packageName, long flags, int userId);
149 
150     /**
151      * Important: The provided filterCallingUid is used exclusively to filter out applications
152      * that can be seen based on user state. It's typically the original caller uid prior
153      * to clearing. Because it can only be provided by trusted code, its value can be
154      * trusted and will be used as-is; unlike userId which will be validated by this method.
155      */
getApplicationInfoInternal(String packageName, long flags, int filterCallingUid, int userId)156     ApplicationInfo getApplicationInfoInternal(String packageName, long flags,
157             int filterCallingUid, int userId);
158 
159     /**
160      * Report the 'Home' activity which is currently set as "always use this one". If non is set
161      * then reports the most likely home activity or null if there are more than one.
162      */
getDefaultHomeActivity(int userId)163     ComponentName getDefaultHomeActivity(int userId);
getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, int userId)164     ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, int userId);
getCrossProfileDomainPreferredLpr(Intent intent, String resolvedType, long flags, int sourceUserId, int parentUserId)165     CrossProfileDomainInfo getCrossProfileDomainPreferredLpr(Intent intent, String resolvedType,
166             long flags, int sourceUserId, int parentUserId);
getHomeIntent()167     Intent getHomeIntent();
getMatchingCrossProfileIntentFilters(Intent intent, String resolvedType, int userId)168     List<CrossProfileIntentFilter> getMatchingCrossProfileIntentFilters(Intent intent,
169             String resolvedType, int userId);
170 
171     /**
172      * Filters out ephemeral activities.
173      * <p>When resolving for an ephemeral app, only activities that 1) are defined in the
174      * ephemeral app or 2) marked with {@code visibleToEphemeral} are returned.
175      *
176      * @param resolveInfos The pre-filtered list of resolved activities
177      * @param ephemeralPkgName The ephemeral package name. If {@code null}, no filtering
178      *          is performed.
179      * @param intent
180      * @return A filtered list of resolved activities.
181      */
applyPostResolutionFilter(@onNull List<ResolveInfo> resolveInfos, String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid, boolean resolveForStart, int userId, Intent intent)182     List<ResolveInfo> applyPostResolutionFilter(@NonNull List<ResolveInfo> resolveInfos,
183             String ephemeralPkgName, boolean allowDynamicSplits, int filterCallingUid,
184             boolean resolveForStart, int userId, Intent intent);
generatePackageInfo(PackageStateInternal ps, long flags, int userId)185     PackageInfo generatePackageInfo(PackageStateInternal ps, long flags, int userId);
getPackageInfo(String packageName, long flags, int userId)186     PackageInfo getPackageInfo(String packageName, long flags, int userId);
getPackageInfoInternal(String packageName, long versionCode, long flags, int filterCallingUid, int userId)187     PackageInfo getPackageInfoInternal(String packageName, long versionCode, long flags,
188             int filterCallingUid, int userId);
189 
190     /**
191      * @return package names of all available {@link AndroidPackage} instances. This means any
192      * known {@link PackageState} instances without a {@link PackageState#getAndroidPackage()}
193      * will not be represented.
194      */
getAllAvailablePackageNames()195     String[] getAllAvailablePackageNames();
196 
getPackageStateInternal(String packageName)197     PackageStateInternal getPackageStateInternal(String packageName);
getPackageStateInternal(String packageName, int callingUid)198     PackageStateInternal getPackageStateInternal(String packageName, int callingUid);
getPackageStateFiltered(@onNull String packageName, int callingUid, @UserIdInt int userId)199     PackageStateInternal getPackageStateFiltered(@NonNull String packageName, int callingUid,
200             @UserIdInt int userId);
getInstalledPackages(long flags, int userId)201     ParceledListSlice<PackageInfo> getInstalledPackages(long flags, int userId);
createForwardingResolveInfoUnchecked(WatchedIntentFilter filter, int sourceUserId, int targetUserId)202     ResolveInfo createForwardingResolveInfoUnchecked(WatchedIntentFilter filter,
203             int sourceUserId, int targetUserId);
getServiceInfo(ComponentName component, long flags, int userId)204     ServiceInfo getServiceInfo(ComponentName component, long flags, int userId);
getSharedLibraryInfo(String name, long version)205     SharedLibraryInfo getSharedLibraryInfo(String name, long version);
getInstantAppPackageName(int callingUid)206     String getInstantAppPackageName(int callingUid);
resolveExternalPackageName(AndroidPackage pkg)207     String resolveExternalPackageName(AndroidPackage pkg);
resolveInternalPackageName(String packageName, long versionCode)208     String resolveInternalPackageName(String packageName, long versionCode);
getPackagesForUid(int uid)209     String[] getPackagesForUid(int uid);
getProfileParent(int userId)210     UserInfo getProfileParent(int userId);
canViewInstantApps(int callingUid, int userId)211     boolean canViewInstantApps(int callingUid, int userId);
filterSharedLibPackage(@ullable PackageStateInternal ps, int uid, int userId, long flags)212     boolean filterSharedLibPackage(@Nullable PackageStateInternal ps, int uid, int userId,
213             long flags);
isCallerSameApp(String packageName, int uid)214     boolean isCallerSameApp(String packageName, int uid);
215     /**
216      * Returns true if the package name and the uid represent the same app.
217      *
218      * @param resolveIsolatedUid if true, resolves an isolated uid into the real uid.
219      */
isCallerSameApp(String packageName, int uid, boolean resolveIsolatedUid)220     boolean isCallerSameApp(String packageName, int uid, boolean resolveIsolatedUid);
isComponentVisibleToInstantApp(@ullable ComponentName component)221     boolean isComponentVisibleToInstantApp(@Nullable ComponentName component);
isComponentVisibleToInstantApp(@ullable ComponentName component, @PackageManager.ComponentType int type)222     boolean isComponentVisibleToInstantApp(@Nullable ComponentName component,
223             @PackageManager.ComponentType int type);
224 
225     /**
226      * From Android R, camera intents have to match system apps. The only exception to this is if
227      * the DPC has set the camera persistent preferred activity. This case was introduced
228      * because it is important that the DPC has the ability to set both system and non-system
229      * camera persistent preferred activities.
230      *
231      * @return {@code true} if the intent is a camera intent and the persistent preferred
232      * activity was not set by the DPC.
233      */
isImplicitImageCaptureIntentAndNotSetByDpc(Intent intent, int userId, String resolvedType, long flags)234     boolean isImplicitImageCaptureIntentAndNotSetByDpc(Intent intent, int userId,
235             String resolvedType, long flags);
isInstantApp(String packageName, int userId)236     boolean isInstantApp(String packageName, int userId);
isInstantAppInternal(String packageName, @UserIdInt int userId, int callingUid)237     boolean isInstantAppInternal(String packageName, @UserIdInt int userId, int callingUid);
isSameProfileGroup(@serIdInt int callerUserId, @UserIdInt int userId)238     boolean isSameProfileGroup(@UserIdInt int callerUserId, @UserIdInt int userId);
shouldFilterApplication(@ullable PackageStateInternal ps, int callingUid, @Nullable ComponentName component, @PackageManager.ComponentType int componentType, int userId, boolean filterUninstall)239     boolean shouldFilterApplication(@Nullable PackageStateInternal ps, int callingUid,
240             @Nullable ComponentName component, @PackageManager.ComponentType int componentType,
241             int userId, boolean filterUninstall);
shouldFilterApplication(@ullable PackageStateInternal ps, int callingUid, @Nullable ComponentName component, @PackageManager.ComponentType int componentType, int userId)242     boolean shouldFilterApplication(@Nullable PackageStateInternal ps, int callingUid,
243             @Nullable ComponentName component, @PackageManager.ComponentType int componentType,
244             int userId);
shouldFilterApplication(@ullable PackageStateInternal ps, int callingUid, int userId)245     boolean shouldFilterApplication(@Nullable PackageStateInternal ps, int callingUid,
246             int userId);
shouldFilterApplication(@onNull SharedUserSetting sus, int callingUid, int userId)247     boolean shouldFilterApplication(@NonNull SharedUserSetting sus, int callingUid,
248             int userId);
249     /**
250      * Different form {@link #shouldFilterApplication(PackageStateInternal, int, int)}, the function
251      * returns {@code true} if the target package is not found in the device or uninstalled in the
252      * current user. Unless the caller's function needs to handle the package's uninstalled state
253      * by itself, using this function to keep the consistent behavior between conditions of package
254      * uninstalled and visibility not allowed to avoid the side channel leakage of package
255      * existence.
256      * <p>
257      * Package with {@link PackageManager#SYSTEM_APP_STATE_HIDDEN_UNTIL_INSTALLED_HIDDEN} is not
258      * treated as an uninstalled package for the carrier apps customization. Bypassing the
259      * uninstalled package check if the caller is system, shell or root uid.
260      */
shouldFilterApplicationIncludingUninstalled(@ullable PackageStateInternal ps, int callingUid, int userId)261     boolean shouldFilterApplicationIncludingUninstalled(@Nullable PackageStateInternal ps,
262             int callingUid, int userId);
263     /**
264      * Different from {@link #shouldFilterApplication(SharedUserSetting, int, int)}, the function
265      * returns {@code true} if packages with the same shared user are all uninstalled in the current
266      * user.
267      *
268      * @see #shouldFilterApplicationIncludingUninstalled(PackageStateInternal, int, int)
269      */
shouldFilterApplicationIncludingUninstalled(@onNull SharedUserSetting sus, int callingUid, int userId)270     boolean shouldFilterApplicationIncludingUninstalled(@NonNull SharedUserSetting sus,
271             int callingUid, int userId);
checkUidPermission(String permName, int uid)272     int checkUidPermission(String permName, int uid);
getPackageUidInternal(String packageName, long flags, int userId, int callingUid)273     int getPackageUidInternal(String packageName, long flags, int userId, int callingUid);
updateFlagsForApplication(long flags, int userId)274     long updateFlagsForApplication(long flags, int userId);
updateFlagsForComponent(long flags, int userId)275     long updateFlagsForComponent(long flags, int userId);
updateFlagsForPackage(long flags, int userId)276     long updateFlagsForPackage(long flags, int userId);
277 
278     /**
279      * Update given flags when being used to request {@link ResolveInfo}.
280      * <p>Instant apps are resolved specially, depending upon context. Minimally,
281      * {@code}flags{@code} must have the {@link PackageManager#MATCH_INSTANT}
282      * flag set. However, this flag is only honoured in three circumstances:
283      * <ul>
284      * <li>when called from a system process</li>
285      * <li>when the caller holds the permission {@code android.permission.ACCESS_INSTANT_APPS}</li>
286      * <li>when resolution occurs to start an activity with a {@code android.intent.action.VIEW}
287      * action and a {@code android.intent.category.BROWSABLE} category</li>
288      * </ul>
289      */
updateFlagsForResolve(long flags, int userId, int callingUid, boolean wantInstantApps, boolean isImplicitImageCaptureIntentAndNotSetByDpc)290     long updateFlagsForResolve(long flags, int userId, int callingUid, boolean wantInstantApps,
291             boolean isImplicitImageCaptureIntentAndNotSetByDpc);
updateFlagsForResolve(long flags, int userId, int callingUid, boolean wantInstantApps, boolean onlyExposedExplicitly, boolean isImplicitImageCaptureIntentAndNotSetByDpc)292     long updateFlagsForResolve(long flags, int userId, int callingUid, boolean wantInstantApps,
293             boolean onlyExposedExplicitly, boolean isImplicitImageCaptureIntentAndNotSetByDpc);
294 
295     /**
296      * Checks if the request is from the system or an app that has the appropriate cross-user
297      * permissions defined as follows:
298      * <ul>
299      * <li>INTERACT_ACROSS_USERS_FULL if {@code requireFullPermission} is true.</li>
300      * <li>INTERACT_ACROSS_USERS if the given {@code userId} is in a different profile group
301      * to the caller.</li>
302      * <li>Otherwise, INTERACT_ACROSS_PROFILES if the given {@code userId} is in the same profile
303      * group as the caller.</li>
304      * </ul>
305      *
306      * @param checkShell whether to prevent shell from access if there's a debugging restriction
307      * @param message the message to log on security exception
308      */
enforceCrossUserOrProfilePermission(int callingUid, @UserIdInt int userId, boolean requireFullPermission, boolean checkShell, String message)309     void enforceCrossUserOrProfilePermission(int callingUid, @UserIdInt int userId,
310             boolean requireFullPermission, boolean checkShell, String message);
311 
312     /**
313      * Enforces the request is from the system or an app that has INTERACT_ACROSS_USERS
314      * or INTERACT_ACROSS_USERS_FULL permissions, if the {@code userId} is not for the caller.
315      *
316      * @param checkShell whether to prevent shell from access if there's a debugging restriction
317      * @param message the message to log on security exception
318      */
enforceCrossUserPermission(int callingUid, @UserIdInt int userId, boolean requireFullPermission, boolean checkShell, String message)319     void enforceCrossUserPermission(int callingUid, @UserIdInt int userId,
320             boolean requireFullPermission, boolean checkShell, String message);
enforceCrossUserPermission(int callingUid, @UserIdInt int userId, boolean requireFullPermission, boolean checkShell, boolean requirePermissionWhenSameUser, String message)321     void enforceCrossUserPermission(int callingUid, @UserIdInt int userId,
322             boolean requireFullPermission, boolean checkShell,
323             boolean requirePermissionWhenSameUser, String message);
getSigningDetails(@onNull String packageName)324     SigningDetails getSigningDetails(@NonNull String packageName);
getSigningDetails(int uid)325     SigningDetails getSigningDetails(int uid);
filterAppAccess(AndroidPackage pkg, int callingUid, int userId)326     boolean filterAppAccess(AndroidPackage pkg, int callingUid, int userId);
filterAppAccess(String packageName, int callingUid, int userId, boolean filterUninstalled)327     boolean filterAppAccess(String packageName, int callingUid, int userId,
328             boolean filterUninstalled);
filterAppAccess(int uid, int callingUid)329     boolean filterAppAccess(int uid, int callingUid);
dump(int type, FileDescriptor fd, PrintWriter pw, DumpState dumpState)330     void dump(int type, FileDescriptor fd, PrintWriter pw, DumpState dumpState);
findPreferredActivityInternal( Intent intent, String resolvedType, long flags, List<ResolveInfo> query, boolean always, boolean removeMatches, boolean debug, int userId, boolean queryMayBeFiltered)331     PackageManagerService.FindPreferredActivityBodyResult findPreferredActivityInternal(
332             Intent intent, String resolvedType, long flags, List<ResolveInfo> query, boolean always,
333             boolean removeMatches, boolean debug, int userId, boolean queryMayBeFiltered);
findPersistentPreferredActivity(Intent intent, String resolvedType, long flags, List<ResolveInfo> query, boolean debug, int userId)334     ResolveInfo findPersistentPreferredActivity(Intent intent, String resolvedType, long flags,
335             List<ResolveInfo> query, boolean debug, int userId);
336 
getPreferredActivities(@serIdInt int userId)337     PreferredIntentResolver getPreferredActivities(@UserIdInt int userId);
338 
339     @NonNull
getPackageStates()340     ArrayMap<String, ? extends PackageStateInternal> getPackageStates();
341 
342     @NonNull
getDisabledSystemPackageStates()343     ArrayMap<String, ? extends PackageStateInternal> getDisabledSystemPackageStates();
344 
345     @Nullable
getRenamedPackage(@onNull String packageName)346     String getRenamedPackage(@NonNull String packageName);
347 
348     /**
349      * @return set of packages to notify
350      */
351     @NonNull
getNotifyPackagesForReplacedReceived(@onNull String[] packages)352     ArraySet<String> getNotifyPackagesForReplacedReceived(@NonNull String[] packages);
353 
354     @PackageManagerService.PackageStartability
getPackageStartability(boolean safeMode, @NonNull String packageName, int callingUid, @UserIdInt int userId)355     int getPackageStartability(boolean safeMode, @NonNull String packageName, int callingUid,
356             @UserIdInt int userId);
357 
isPackageAvailable(String packageName, @UserIdInt int userId)358     boolean isPackageAvailable(String packageName, @UserIdInt int userId);
359 
isApexPackage(String packageName)360     boolean isApexPackage(String packageName);
361 
362     @NonNull
currentToCanonicalPackageNames(@onNull String[] names)363     String[] currentToCanonicalPackageNames(@NonNull String[] names);
364 
365     @NonNull
canonicalToCurrentPackageNames(@onNull String[] names)366     String[] canonicalToCurrentPackageNames(@NonNull String[] names);
367 
368     @NonNull
getPackageGids(@onNull String packageName, @PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId)369     int[] getPackageGids(@NonNull String packageName,
370             @PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId);
371 
getTargetSdkVersion(@onNull String packageName)372     int getTargetSdkVersion(@NonNull String packageName);
373 
activitySupportsIntentAsUser(@onNull ComponentName resolveComponentName, @NonNull ComponentName component, @NonNull Intent intent, String resolvedType, int userId)374     boolean activitySupportsIntentAsUser(@NonNull ComponentName resolveComponentName,
375             @NonNull ComponentName component, @NonNull Intent intent, String resolvedType,
376             int userId);
377 
378     @Nullable
getReceiverInfo(@onNull ComponentName component, @PackageManager.ComponentInfoFlagsBits long flags, @UserIdInt int userId)379     ActivityInfo getReceiverInfo(@NonNull ComponentName component,
380             @PackageManager.ComponentInfoFlagsBits long flags, @UserIdInt int userId);
381 
382     @Nullable
getSharedLibraries(@onNull String packageName, @PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId)383     ParceledListSlice<SharedLibraryInfo> getSharedLibraries(@NonNull String packageName,
384             @PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId);
385 
canRequestPackageInstalls(@onNull String packageName, int callingUid, int userId, boolean throwIfPermNotDeclared)386     boolean canRequestPackageInstalls(@NonNull String packageName, int callingUid,
387             int userId, boolean throwIfPermNotDeclared);
388 
389     /**
390      * Returns true if the system or user is explicitly preventing an otherwise valid installer to
391      * complete an install. This includes checks like unknown sources and user restrictions.
392      */
isInstallDisabledForPackage(@onNull String packageName, int uid, @UserIdInt int userId)393     boolean isInstallDisabledForPackage(@NonNull String packageName, int uid,
394             @UserIdInt int userId);
395 
396     @Nullable
getPackagesUsingSharedLibrary(@onNull SharedLibraryInfo libInfo, @PackageManager.PackageInfoFlagsBits long flags, int callingUid, @UserIdInt int userId)397     List<VersionedPackage> getPackagesUsingSharedLibrary(@NonNull SharedLibraryInfo libInfo,
398             @PackageManager.PackageInfoFlagsBits long flags, int callingUid, @UserIdInt int userId);
399 
400     @Nullable
getDeclaredSharedLibraries( @onNull String packageName, @PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId)401     ParceledListSlice<SharedLibraryInfo> getDeclaredSharedLibraries(
402             @NonNull String packageName, @PackageManager.PackageInfoFlagsBits long flags,
403             @UserIdInt int userId);
404 
405     @Nullable
getProviderInfo(@onNull ComponentName component, @PackageManager.ComponentInfoFlagsBits long flags, @UserIdInt int userId)406     ProviderInfo getProviderInfo(@NonNull ComponentName component,
407             @PackageManager.ComponentInfoFlagsBits long flags, @UserIdInt int userId);
408 
409     @Nullable
getSystemSharedLibraryNames()410     String[] getSystemSharedLibraryNames();
411 
412     /**
413      * @return the state if the given package is installed and isn't filtered by visibility.
414      * Provides no guarantee that the package is in any usable state.
415      */
416     @Nullable
getPackageStateForInstalledAndFiltered(@onNull String packageName, int callingUid, @UserIdInt int userId)417     PackageStateInternal getPackageStateForInstalledAndFiltered(@NonNull String packageName,
418             int callingUid, @UserIdInt int userId);
419 
checkSignatures(@onNull String pkg1, @NonNull String pkg2, int userId)420     int checkSignatures(@NonNull String pkg1, @NonNull String pkg2, int userId);
421 
checkUidSignatures(int uid1, int uid2)422     int checkUidSignatures(int uid1, int uid2);
423 
checkUidSignaturesForAllUsers(int uid1, int uid2)424     int checkUidSignaturesForAllUsers(int uid1, int uid2);
425 
hasSigningCertificate(@onNull String packageName, @NonNull byte[] certificate, @PackageManager.CertificateInputType int type)426     boolean hasSigningCertificate(@NonNull String packageName, @NonNull byte[] certificate,
427             @PackageManager.CertificateInputType int type);
428 
hasUidSigningCertificate(int uid, @NonNull byte[] certificate, @PackageManager.CertificateInputType int type)429     boolean hasUidSigningCertificate(int uid, @NonNull byte[] certificate,
430             @PackageManager.CertificateInputType int type);
431 
432     @NonNull
getAllPackages()433     List<String> getAllPackages();
434 
435     @Nullable
getNameForUid(int uid)436     String getNameForUid(int uid);
437 
438     @Nullable
getNamesForUids(@onNull int[] uids)439     String[] getNamesForUids(@NonNull int[] uids);
440 
getUidForSharedUser(@onNull String sharedUserName)441     int getUidForSharedUser(@NonNull String sharedUserName);
442 
getFlagsForUid(int uid)443     int getFlagsForUid(int uid);
444 
getPrivateFlagsForUid(int uid)445     int getPrivateFlagsForUid(int uid);
446 
isUidPrivileged(int uid)447     boolean isUidPrivileged(int uid);
448 
449     @NonNull
getAppOpPermissionPackages(@onNull String permissionName, int userId)450     String[] getAppOpPermissionPackages(@NonNull String permissionName, int userId);
451 
452     @NonNull
getPackagesHoldingPermissions(@onNull String[] permissions, @PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId)453     ParceledListSlice<PackageInfo> getPackagesHoldingPermissions(@NonNull String[] permissions,
454             @PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId);
455 
456     @NonNull
getInstalledApplications( @ackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId, int callingUid)457     List<ApplicationInfo> getInstalledApplications(
458             @PackageManager.ApplicationInfoFlagsBits long flags, @UserIdInt int userId,
459             int callingUid);
460 
461     @Nullable
resolveContentProvider(@onNull String name, @PackageManager.ResolveInfoFlagsBits long flags, @UserIdInt int userId, int callingUid)462     ProviderInfo resolveContentProvider(@NonNull String name,
463             @PackageManager.ResolveInfoFlagsBits long flags, @UserIdInt int userId, int callingUid);
464 
465     @Nullable
getGrantImplicitAccessProviderInfo(int recipientUid, @NonNull String visibleAuthority)466     ProviderInfo getGrantImplicitAccessProviderInfo(int recipientUid,
467             @NonNull String visibleAuthority);
468 
querySyncProviders(boolean safeMode, @NonNull List<String> outNames, @NonNull List<ProviderInfo> outInfo)469     void querySyncProviders(boolean safeMode, @NonNull List<String> outNames,
470             @NonNull List<ProviderInfo> outInfo);
471 
472     @NonNull
queryContentProviders(@ullable String processName, int uid, @PackageManager.ComponentInfoFlagsBits long flags, @Nullable String metaDataKey)473     ParceledListSlice<ProviderInfo> queryContentProviders(@Nullable String processName, int uid,
474             @PackageManager.ComponentInfoFlagsBits long flags, @Nullable String metaDataKey);
475 
476     @Nullable
getInstrumentationInfoAsUser(@onNull ComponentName component, int flags, int userId)477     InstrumentationInfo getInstrumentationInfoAsUser(@NonNull ComponentName component, int flags,
478             int userId);
479 
480     @NonNull
queryInstrumentationAsUser( @onNull String targetPackage, int flags, int userId)481     ParceledListSlice<InstrumentationInfo> queryInstrumentationAsUser(
482             @NonNull String targetPackage, int flags, int userId);
483 
484     @NonNull
findSharedNonSystemLibraries( @onNull PackageStateInternal pkgSetting)485     List<PackageStateInternal> findSharedNonSystemLibraries(
486             @NonNull PackageStateInternal pkgSetting);
487 
getApplicationHiddenSettingAsUser(@onNull String packageName, @UserIdInt int userId)488     boolean getApplicationHiddenSettingAsUser(@NonNull String packageName, @UserIdInt int userId);
489 
isPackageSuspendedForUser(@onNull String packageName, @UserIdInt int userId)490     boolean isPackageSuspendedForUser(@NonNull String packageName, @UserIdInt int userId);
491 
isSuspendingAnyPackages(@onNull String suspendingPackage, @UserIdInt int userId)492     boolean isSuspendingAnyPackages(@NonNull String suspendingPackage, @UserIdInt int userId);
493 
494     @NonNull
getAllIntentFilters(@onNull String packageName)495     ParceledListSlice<IntentFilter> getAllIntentFilters(@NonNull String packageName);
496 
getBlockUninstallForUser(@onNull String packageName, @UserIdInt int userId)497     boolean getBlockUninstallForUser(@NonNull String packageName, @UserIdInt int userId);
498 
499     @Nullable
getInstallerPackageName(@onNull String packageName, @UserIdInt int userId)500     String getInstallerPackageName(@NonNull String packageName, @UserIdInt int userId);
501 
502     @Nullable
getInstallSourceInfo(@onNull String packageName, @UserIdInt int userId)503     InstallSourceInfo getInstallSourceInfo(@NonNull String packageName, @UserIdInt int userId);
504 
505     @PackageManager.EnabledState
getApplicationEnabledSetting(@onNull String packageName, @UserIdInt int userId)506     int getApplicationEnabledSetting(@NonNull String packageName, @UserIdInt int userId);
507 
508     @PackageManager.EnabledState
getComponentEnabledSetting(@onNull ComponentName component, int callingUid, @UserIdInt int userId)509     int getComponentEnabledSetting(@NonNull ComponentName component, int callingUid,
510             @UserIdInt int userId);
511 
512     @PackageManager.EnabledState
getComponentEnabledSettingInternal(@onNull ComponentName component, int callingUid, @UserIdInt int userId)513     int getComponentEnabledSettingInternal(@NonNull ComponentName component, int callingUid,
514             @UserIdInt int userId);
515 
516     /**
517      * @return true if the runtime app user enabled state, runtime component user enabled state,
518      * install-time app manifest enabled state, and install-time component manifest enabled state
519      * are all effectively enabled for the given component. Or if the component cannot be found,
520      * returns false.
521      */
isComponentEffectivelyEnabled(@onNull ComponentInfo componentInfo, @NonNull UserHandle userHandle)522     boolean isComponentEffectivelyEnabled(@NonNull ComponentInfo componentInfo,
523             @NonNull UserHandle userHandle);
524 
525     /**
526      * @return true if the runtime app user enabled state and the install-time app manifest enabled
527      * state are both effectively enabled for the given app. Or if the app cannot be found,
528      * returns false.
529      */
isApplicationEffectivelyEnabled(@onNull String packageName, @NonNull UserHandle userHandle)530     boolean isApplicationEffectivelyEnabled(@NonNull String packageName,
531             @NonNull UserHandle userHandle);
532 
533     @Nullable
getKeySetByAlias(@onNull String packageName, @NonNull String alias)534     KeySet getKeySetByAlias(@NonNull String packageName, @NonNull String alias);
535 
536     @Nullable
getSigningKeySet(@onNull String packageName)537     KeySet getSigningKeySet(@NonNull String packageName);
538 
isPackageSignedByKeySet(@onNull String packageName, @NonNull KeySet ks)539     boolean isPackageSignedByKeySet(@NonNull String packageName, @NonNull KeySet ks);
540 
isPackageSignedByKeySetExactly(@onNull String packageName, @NonNull KeySet ks)541     boolean isPackageSignedByKeySetExactly(@NonNull String packageName, @NonNull KeySet ks);
542 
543     /**
544      * See {@link AppsFilterSnapshot#getVisibilityAllowList(PackageStateInternal, int[], ArrayMap)}
545      */
546     @Nullable
getVisibilityAllowLists(@onNull String packageName, @UserIdInt int[] userIds)547     SparseArray<int[]> getVisibilityAllowLists(@NonNull String packageName,
548             @UserIdInt int[] userIds);
549 
550     /**
551      * See {@link AppsFilterSnapshot#getVisibilityAllowList(PackageStateInternal, int[], ArrayMap)}
552      */
553     @Nullable
getVisibilityAllowList(@onNull String packageName, @UserIdInt int userId)554     int[] getVisibilityAllowList(@NonNull String packageName, @UserIdInt int userId);
555 
556     /**
557      * Returns whether the given UID either declares &lt;queries&gt; element with the given package
558      * name in its app's manifest, has {@link android.Manifest.permission.QUERY_ALL_PACKAGES}, or
559      * package visibility filtering is enabled on it. If the UID is part of a shared user ID,
560      * return {@code true} if any one application belongs to the shared user ID meets the criteria.
561      */
canQueryPackage(int callingUid, @Nullable String targetPackageName)562     boolean canQueryPackage(int callingUid, @Nullable String targetPackageName);
563 
getPackageUid(@onNull String packageName, @PackageManager.PackageInfoFlagsBits long flags, @UserIdInt int userId)564     int getPackageUid(@NonNull String packageName, @PackageManager.PackageInfoFlagsBits long flags,
565             @UserIdInt int userId);
566 
canAccessComponent(int callingUid, @NonNull ComponentName component, @UserIdInt int userId)567     boolean canAccessComponent(int callingUid, @NonNull ComponentName component,
568             @UserIdInt int userId);
569 
isCallerInstallerOfRecord(@onNull AndroidPackage pkg, int callingUid)570     boolean isCallerInstallerOfRecord(@NonNull AndroidPackage pkg, int callingUid);
571 
572     @PackageManager.InstallReason
getInstallReason(@onNull String packageName, @UserIdInt int userId)573     int getInstallReason(@NonNull String packageName, @UserIdInt int userId);
574 
575     @NonNull
canPackageQuery(@onNull String sourcePackageName, @NonNull String[] targetPackageNames, @UserIdInt int userId)576     boolean[] canPackageQuery(@NonNull String sourcePackageName,
577             @NonNull String[] targetPackageNames, @UserIdInt int userId);
578 
canForwardTo(@onNull Intent intent, @Nullable String resolvedType, @UserIdInt int sourceUserId, @UserIdInt int targetUserId)579     boolean canForwardTo(@NonNull Intent intent, @Nullable String resolvedType,
580             @UserIdInt int sourceUserId, @UserIdInt int targetUserId);
581 
582     @NonNull
getPersistentApplications(boolean safeMode, int flags)583     List<ApplicationInfo> getPersistentApplications(boolean safeMode, int flags);
584 
585     @NonNull
getAppsWithSharedUserIds()586     SparseArray<String> getAppsWithSharedUserIds();
587 
588     @NonNull
getSharedUserPackagesForPackage(@onNull String packageName, @UserIdInt int userId)589     String[] getSharedUserPackagesForPackage(@NonNull String packageName, @UserIdInt int userId);
590 
591     @NonNull
getUnusedPackages(long downgradeTimeThresholdMillis)592     Set<String> getUnusedPackages(long downgradeTimeThresholdMillis);
593 
594     @Nullable
getHarmfulAppWarning(@onNull String packageName, @UserIdInt int userId)595     CharSequence getHarmfulAppWarning(@NonNull String packageName, @UserIdInt int userId);
596 
597     /**
598      * Only keep package names that refer to {@link PackageState#isSystem system} packages.
599      *
600      * @param pkgNames The packages to filter
601      *
602      * @return The filtered packages
603      */
604     @NonNull
filterOnlySystemPackages(@ullable String... pkgNames)605     String[] filterOnlySystemPackages(@Nullable String... pkgNames);
606 
607     // The methods in this block should be removed once SettingBase is interface snapshotted
608     @NonNull
getPackagesForAppId(int appId)609     List<AndroidPackage> getPackagesForAppId(int appId);
610 
getUidTargetSdkVersion(int uid)611     int getUidTargetSdkVersion(int uid);
612 
613     /**
614      * @see PackageManagerInternal#getProcessesForUid(int)
615      */
616     @Nullable
getProcessesForUid(int uid)617     ArrayMap<String, ProcessInfo> getProcessesForUid(int uid);
618     // End block
619 
getBlockUninstall(@serIdInt int userId, @NonNull String packageName)620     boolean getBlockUninstall(@UserIdInt int userId, @NonNull String packageName);
621 
622     @NonNull
getSharedLibraries()623     WatchedArrayMap<String, WatchedLongSparseArray<SharedLibraryInfo>> getSharedLibraries();
624 
625 
626     @Nullable
getPackageOrSharedUser(int appId)627     Pair<PackageStateInternal, SharedUserApi> getPackageOrSharedUser(int appId);
628 
629     @Nullable
getSharedUser(int sharedUserAppIde)630     SharedUserApi getSharedUser(int sharedUserAppIde);
631 
632     @NonNull
getSharedUserPackages(int sharedUserAppId)633     ArraySet<PackageStateInternal> getSharedUserPackages(int sharedUserAppId);
634 
635     @NonNull
getComponentResolver()636     ComponentResolverApi getComponentResolver();
637 
638     @Nullable
getDisabledSystemPackage(@onNull String packageName)639     PackageStateInternal getDisabledSystemPackage(@NonNull String packageName);
640 
641     @Nullable
getInstantAppInstallerInfo()642     ResolveInfo getInstantAppInstallerInfo();
643 
644     @NonNull
getFrozenPackages()645     WatchedArrayMap<String, Integer> getFrozenPackages();
646 
647     /**
648      * Verify that given package is currently frozen.
649      */
checkPackageFrozen(@onNull String packageName)650     void checkPackageFrozen(@NonNull String packageName);
651 
652     @Nullable
getInstantAppInstallerComponent()653     ComponentName getInstantAppInstallerComponent();
654 
dumpPermissions(@onNull PrintWriter pw, @NonNull String packageName, @NonNull ArraySet<String> permissionNames, @NonNull DumpState dumpState)655     void dumpPermissions(@NonNull PrintWriter pw, @NonNull String packageName,
656             @NonNull ArraySet<String> permissionNames, @NonNull DumpState dumpState);
657 
dumpPackages(PrintWriter pw, @NonNull String packageName, @NonNull ArraySet<String> permissionNames, @NonNull DumpState dumpState, boolean checkin)658     void dumpPackages(PrintWriter pw, @NonNull String packageName,
659             @NonNull ArraySet<String> permissionNames, @NonNull DumpState dumpState,
660             boolean checkin);
661 
dumpKeySet(@onNull PrintWriter pw, @NonNull String packageName, @NonNull DumpState dumpState)662     void dumpKeySet(@NonNull PrintWriter pw, @NonNull String packageName,
663             @NonNull DumpState dumpState);
664 
dumpSharedUsers(@onNull PrintWriter pw, @NonNull String packageName, @NonNull ArraySet<String> permissionNames, @NonNull DumpState dumpState, boolean checkin)665     void dumpSharedUsers(@NonNull PrintWriter pw, @NonNull String packageName,
666             @NonNull ArraySet<String> permissionNames,
667             @NonNull DumpState dumpState, boolean checkin);
668 
dumpSharedUsersProto(@onNull ProtoOutputStream proto)669     void dumpSharedUsersProto(@NonNull ProtoOutputStream proto);
670 
dumpPackagesProto(@onNull ProtoOutputStream proto)671     void dumpPackagesProto(@NonNull ProtoOutputStream proto);
672 
dumpSharedLibrariesProto(@onNull ProtoOutputStream protoOutputStream)673     void dumpSharedLibrariesProto(@NonNull ProtoOutputStream protoOutputStream);
674 
675     @NonNull
getVolumePackages(@onNull String volumeUuid)676     List<? extends PackageStateInternal> getVolumePackages(@NonNull String volumeUuid);
677 
678     @NonNull
getUserInfos()679     UserInfo[] getUserInfos();
680 
681     @NonNull
getAllSharedUsers()682     Collection<SharedUserSetting> getAllSharedUsers();
683 }
684