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