1 /*
2  * Copyright (C) 2015 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 android.content.pm;
18 
19 import android.annotation.IntDef;
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.IntentSender;
26 import android.content.pm.PackageManager.ApplicationInfoFlags;
27 import android.content.pm.PackageManager.ComponentInfoFlags;
28 import android.content.pm.PackageManager.PackageInfoFlags;
29 import android.content.pm.PackageManager.ResolveInfoFlags;
30 import android.os.Bundle;
31 import android.os.PersistableBundle;
32 import android.util.ArraySet;
33 import android.util.SparseArray;
34 
35 import com.android.internal.util.function.TriFunction;
36 
37 import java.io.IOException;
38 import java.lang.annotation.Retention;
39 import java.lang.annotation.RetentionPolicy;
40 import java.util.List;
41 import java.util.function.BiFunction;
42 import java.util.function.Consumer;
43 
44 /**
45  * Package manager local system service interface.
46  *
47  * @hide Only for use within the system server.
48  */
49 public abstract class PackageManagerInternal {
50     public static final int PACKAGE_SYSTEM = 0;
51     public static final int PACKAGE_SETUP_WIZARD = 1;
52     public static final int PACKAGE_INSTALLER = 2;
53     public static final int PACKAGE_VERIFIER = 3;
54     public static final int PACKAGE_BROWSER = 4;
55     public static final int PACKAGE_SYSTEM_TEXT_CLASSIFIER = 5;
56     public static final int PACKAGE_PERMISSION_CONTROLLER = 6;
57     public static final int PACKAGE_WELLBEING = 7;
58     public static final int PACKAGE_DOCUMENTER = 8;
59     public static final int PACKAGE_CONFIGURATOR = 9;
60     public static final int PACKAGE_INCIDENT_REPORT_APPROVER = 10;
61     public static final int PACKAGE_APP_PREDICTOR = 11;
62     public static final int PACKAGE_TELEPHONY = 12;
63     @IntDef(value = {
64         PACKAGE_SYSTEM,
65         PACKAGE_SETUP_WIZARD,
66         PACKAGE_INSTALLER,
67         PACKAGE_VERIFIER,
68         PACKAGE_BROWSER,
69         PACKAGE_SYSTEM_TEXT_CLASSIFIER,
70         PACKAGE_PERMISSION_CONTROLLER,
71         PACKAGE_WELLBEING,
72         PACKAGE_DOCUMENTER,
73         PACKAGE_CONFIGURATOR,
74         PACKAGE_INCIDENT_REPORT_APPROVER,
75         PACKAGE_APP_PREDICTOR,
76         PACKAGE_TELEPHONY,
77     })
78     @Retention(RetentionPolicy.SOURCE)
79     public @interface KnownPackage {}
80 
81     /** Observer called whenever the list of packages changes */
82     public interface PackageListObserver {
83         /** A package was added to the system. */
onPackageAdded(@onNull String packageName, int uid)84         void onPackageAdded(@NonNull String packageName, int uid);
85         /** A package was changed - either installed for a specific user or updated. */
onPackageChanged(@onNull String packageName, int uid)86         default void onPackageChanged(@NonNull String packageName, int uid) {}
87         /** A package was removed from the system. */
onPackageRemoved(@onNull String packageName, int uid)88         void onPackageRemoved(@NonNull String packageName, int uid);
89     }
90 
91     /** Interface to override permission checks via composition */
92     public interface CheckPermissionDelegate {
93         /**
94          * Allows overriding check permission behavior.
95          *
96          * @param permName The permission to check.
97          * @param pkgName The package for which to check.
98          * @param userId The user for which to check.
99          * @param superImpl The super implementation.
100          * @return The check permission result.
101          */
checkPermission(String permName, String pkgName, int userId, TriFunction<String, String, Integer, Integer> superImpl)102         int checkPermission(String permName, String pkgName, int userId,
103                 TriFunction<String, String, Integer, Integer> superImpl);
104 
105         /**
106          * Allows overriding check UID permission behavior.
107          *
108          * @param permName The permission to check.
109          * @param uid The UID for which to check.
110          * @param superImpl The super implementation.
111          * @return The check permission result.
112          */
checkUidPermission(String permName, int uid, BiFunction<String, Integer, Integer> superImpl)113         int checkUidPermission(String permName, int uid,
114                 BiFunction<String, Integer, Integer> superImpl);
115     }
116 
117     /**
118      * Provider for package names.
119      */
120     public interface PackagesProvider {
121 
122         /**
123          * Gets the packages for a given user.
124          * @param userId The user id.
125          * @return The package names.
126          */
getPackages(int userId)127         public String[] getPackages(int userId);
128     }
129 
130     /**
131      * Provider for package names.
132      */
133     public interface SyncAdapterPackagesProvider {
134 
135         /**
136          * Gets the sync adapter packages for given authority and user.
137          * @param authority The authority.
138          * @param userId The user id.
139          * @return The package names.
140          */
getPackages(String authority, int userId)141         public String[] getPackages(String authority, int userId);
142     }
143 
144     /**
145      * Provider for default browser
146      */
147     public interface DefaultBrowserProvider {
148 
149         /**
150          * Get the package name of the default browser.
151          *
152          * @param userId the user id
153          *
154          * @return the package name of the default browser, or {@code null} if none
155          */
156         @Nullable
getDefaultBrowser(@serIdInt int userId)157         String getDefaultBrowser(@UserIdInt int userId);
158 
159         /**
160          * Set the package name of the default browser.
161          *
162          * @param packageName package name of the default browser, or {@code null} to remove
163          * @param userId the user id
164          *
165          * @return whether the default browser was successfully set.
166          */
setDefaultBrowser(@ullable String packageName, @UserIdInt int userId)167         boolean setDefaultBrowser(@Nullable String packageName, @UserIdInt int userId);
168 
169         /**
170          * Set the package name of the default browser asynchronously.
171          *
172          * @param packageName package name of the default browser, or {@code null} to remove
173          * @param userId the user id
174          */
setDefaultBrowserAsync(@ullable String packageName, @UserIdInt int userId)175         void setDefaultBrowserAsync(@Nullable String packageName, @UserIdInt int userId);
176     }
177 
178     /**
179      * Provider for default dialer
180      */
181     public interface DefaultDialerProvider {
182 
183         /**
184          * Get the package name of the default dialer.
185          *
186          * @param userId the user id
187          *
188          * @return the package name of the default dialer, or {@code null} if none
189          */
190         @Nullable
getDefaultDialer(@serIdInt int userId)191         String getDefaultDialer(@UserIdInt int userId);
192     }
193 
194     /**
195      * Provider for default home
196      */
197     public interface DefaultHomeProvider {
198 
199         /**
200          * Get the package name of the default home.
201          *
202          * @param userId the user id
203          *
204          * @return the package name of the default home, or {@code null} if none
205          */
206         @Nullable
getDefaultHome(@serIdInt int userId)207         String getDefaultHome(@UserIdInt int userId);
208 
209         /**
210          * Set the package name of the default home.
211          *
212          * @param packageName package name of the default home, or {@code null} to remove
213          * @param userId the user id
214          * @param callback the callback made after the default home as been updated
215          */
setDefaultHomeAsync(@ullable String packageName, @UserIdInt int userId, @NonNull Consumer<Boolean> callback)216         void setDefaultHomeAsync(@Nullable String packageName, @UserIdInt int userId,
217                 @NonNull Consumer<Boolean> callback);
218     }
219 
220     /**
221      * Sets the location provider packages provider.
222      * @param provider The packages provider.
223      */
setLocationPackagesProvider(PackagesProvider provider)224     public abstract void setLocationPackagesProvider(PackagesProvider provider);
225 
226     /**
227      * Set the location extra packages provider.
228      * @param provider The packages provider.
229      */
setLocationExtraPackagesProvider(PackagesProvider provider)230     public abstract  void setLocationExtraPackagesProvider(PackagesProvider provider);
231 
232     /**
233      * Sets the voice interaction packages provider.
234      * @param provider The packages provider.
235      */
setVoiceInteractionPackagesProvider(PackagesProvider provider)236     public abstract void setVoiceInteractionPackagesProvider(PackagesProvider provider);
237 
238     /**
239      * Sets the Use Open Wifi packages provider.
240      * @param provider The packages provider.
241      */
setUseOpenWifiAppPackagesProvider(PackagesProvider provider)242     public abstract void setUseOpenWifiAppPackagesProvider(PackagesProvider provider);
243 
244     /**
245      * Sets the sync adapter packages provider.
246      * @param provider The provider.
247      */
setSyncAdapterPackagesprovider(SyncAdapterPackagesProvider provider)248     public abstract void setSyncAdapterPackagesprovider(SyncAdapterPackagesProvider provider);
249 
250     /**
251      * Called when the package for the default SMS handler changed
252      *
253      * @param packageName the new sms package
254      * @param userId user for which the change was made
255      */
onDefaultSmsAppChanged(String packageName, int userId)256     public void onDefaultSmsAppChanged(String packageName, int userId) {}
257 
258     /**
259      * Called when the package for the default sim call manager changed
260      *
261      * @param packageName the new sms package
262      * @param userId user for which the change was made
263      */
onDefaultSimCallManagerAppChanged(String packageName, int userId)264     public void onDefaultSimCallManagerAppChanged(String packageName, int userId) {}
265 
266     /**
267      * Requests granting of the default permissions to the current default Use Open Wifi app.
268      * @param packageName The default use open wifi package name.
269      * @param userId The user for which to grant the permissions.
270      */
grantDefaultPermissionsToDefaultUseOpenWifiApp(String packageName, int userId)271     public abstract void grantDefaultPermissionsToDefaultUseOpenWifiApp(String packageName,
272             int userId);
273 
274     /**
275      * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has
276      * currently installed it. The apps are not preloaded.
277      * @param packageList List of package names to keep cached.
278      */
setKeepUninstalledPackages(List<String> packageList)279     public abstract void setKeepUninstalledPackages(List<String> packageList);
280 
281     /**
282      * Gets whether some of the permissions used by this package require a user
283      * review before any of the app components can run.
284      * @param packageName The package name for which to check.
285      * @param userId The user under which to check.
286      * @return True a permissions review is required.
287      */
isPermissionsReviewRequired(String packageName, int userId)288     public abstract boolean isPermissionsReviewRequired(String packageName, int userId);
289 
290     /**
291      * Retrieve all of the information we know about a particular package/application.
292      * @param filterCallingUid The results will be filtered in the context of this UID instead
293      * of the calling UID.
294      * @see PackageManager#getPackageInfo(String, int)
295      */
getPackageInfo(String packageName, @PackageInfoFlags int flags, int filterCallingUid, int userId)296     public abstract PackageInfo getPackageInfo(String packageName,
297             @PackageInfoFlags int flags, int filterCallingUid, int userId);
298 
299     /**
300      * Return a List of all application packages that are installed on the
301      * device, for a specific user. If flag GET_UNINSTALLED_PACKAGES has been
302      * set, a list of all applications including those deleted with
303      * {@code DONT_DELETE_DATA} (partially installed apps with data directory)
304      * will be returned.
305      *
306      * @param flags Additional option flags to modify the data returned.
307      * @param userId The user for whom the installed applications are to be
308      *            listed
309      * @param callingUid The uid of the original caller app
310      * @return A List of ApplicationInfo objects, one for each installed
311      *         application. In the unlikely case there are no installed
312      *         packages, an empty list is returned. If flag
313      *         {@code MATCH_UNINSTALLED_PACKAGES} is set, the application
314      *         information is retrieved from the list of uninstalled
315      *         applications (which includes installed applications as well as
316      *         applications with data directory i.e. applications which had been
317      *         deleted with {@code DONT_DELETE_DATA} flag set).
318      */
getInstalledApplications( @pplicationInfoFlags int flags, @UserIdInt int userId, int callingUid)319     public abstract List<ApplicationInfo> getInstalledApplications(
320             @ApplicationInfoFlags int flags, @UserIdInt int userId, int callingUid);
321 
322     /**
323      * Retrieve launcher extras for a suspended package provided to the system in
324      * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
325      * PersistableBundle, String)}.
326      *
327      * @param packageName The package for which to return launcher extras.
328      * @param userId The user for which to check.
329      * @return The launcher extras.
330      *
331      * @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
332      * PersistableBundle, String)
333      * @see PackageManager#isPackageSuspended()
334      */
getSuspendedPackageLauncherExtras(String packageName, int userId)335     public abstract Bundle getSuspendedPackageLauncherExtras(String packageName,
336             int userId);
337 
338     /**
339      * Internal api to query the suspended state of a package.
340      * @param packageName The package to check.
341      * @param userId The user id to check for.
342      * @return {@code true} if the package is suspended, {@code false} otherwise.
343      * @see PackageManager#isPackageSuspended(String)
344      */
isPackageSuspended(String packageName, int userId)345     public abstract boolean isPackageSuspended(String packageName, int userId);
346 
347     /**
348      * Get the name of the package that suspended the given package. Packages can be suspended by
349      * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or
350      * {@link android.Manifest.permission#SUSPEND_APPS}.
351      *
352      * @param suspendedPackage The package that has been suspended.
353      * @param userId The user for which to check.
354      * @return Name of the package that suspended the given package. Returns {@code null} if the
355      * given package is not currently suspended and the platform package name - i.e.
356      * {@code "android"} - if the package was suspended by a device admin.
357      */
getSuspendingPackage(String suspendedPackage, int userId)358     public abstract String getSuspendingPackage(String suspendedPackage, int userId);
359 
360     /**
361      * Get the information describing the dialog to be shown to the user when they try to launch a
362      * suspended application.
363      *
364      * @param suspendedPackage The package that has been suspended.
365      * @param userId The user for which to check.
366      * @return A {@link SuspendDialogInfo} object describing the dialog to be shown.
367      */
368     @Nullable
getSuspendedDialogInfo(String suspendedPackage, int userId)369     public abstract SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage, int userId);
370 
371     /**
372      * Gets any distraction flags set via
373      * {@link PackageManager#setDistractingPackageRestrictions(String[], int)}
374      *
375      * @param packageName
376      * @param userId
377      * @return A bitwise OR of any of the {@link PackageManager.DistractionRestriction}
378      */
getDistractingPackageRestrictions( String packageName, int userId)379     public abstract @PackageManager.DistractionRestriction int getDistractingPackageRestrictions(
380             String packageName, int userId);
381 
382     /**
383      * Do a straight uid lookup for the given package/application in the given user.
384      * @see PackageManager#getPackageUidAsUser(String, int, int)
385      * @return The app's uid, or < 0 if the package was not found in that user
386      */
getPackageUid(String packageName, @PackageInfoFlags int flags, int userId)387     public abstract int getPackageUid(String packageName,
388             @PackageInfoFlags int flags, int userId);
389 
390     /**
391      * Retrieve all of the information we know about a particular package/application.
392      * @param filterCallingUid The results will be filtered in the context of this UID instead
393      * of the calling UID.
394      * @see PackageManager#getApplicationInfo(String, int)
395      */
getApplicationInfo(String packageName, @ApplicationInfoFlags int flags, int filterCallingUid, int userId)396     public abstract ApplicationInfo getApplicationInfo(String packageName,
397             @ApplicationInfoFlags int flags, int filterCallingUid, int userId);
398 
399     /**
400      * Retrieve all of the information we know about a particular activity class.
401      * @param filterCallingUid The results will be filtered in the context of this UID instead
402      * of the calling UID.
403      * @see PackageManager#getActivityInfo(ComponentName, int)
404      */
getActivityInfo(ComponentName component, @ComponentInfoFlags int flags, int filterCallingUid, int userId)405     public abstract ActivityInfo getActivityInfo(ComponentName component,
406             @ComponentInfoFlags int flags, int filterCallingUid, int userId);
407 
408     /**
409      * Retrieve all activities that can be performed for the given intent.
410      * @param filterCallingUid The results will be filtered in the context of this UID instead
411      * of the calling UID.
412      * @see PackageManager#queryIntentActivities(Intent, int)
413      */
queryIntentActivities(Intent intent, @ResolveInfoFlags int flags, int filterCallingUid, int userId)414     public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
415             @ResolveInfoFlags int flags, int filterCallingUid, int userId);
416 
417     /**
418      * Retrieve all activities that can be performed for the given intent.
419      * @param filterCallingUid The results will be filtered in the context of this UID instead
420      * of the calling UID.
421      * @see PackageManager#queryIntentActivities(Intent, int)
422      */
queryIntentActivities( Intent intent, @Nullable String resolvedType, @ResolveInfoFlags int flags, int filterCallingUid, int userId)423     public abstract List<ResolveInfo> queryIntentActivities(
424             Intent intent, @Nullable String resolvedType, @ResolveInfoFlags int flags,
425             int filterCallingUid, int userId);
426 
427 
428     /**
429      * Retrieve all services that can be performed for the given intent.
430      * @see PackageManager#queryIntentServices(Intent, int)
431      */
queryIntentServices( Intent intent, int flags, int callingUid, int userId)432     public abstract List<ResolveInfo> queryIntentServices(
433             Intent intent, int flags, int callingUid, int userId);
434 
435     /**
436      * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}.
437      */
getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, int userId)438     public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates,
439             int userId);
440 
441     /**
442      * @return The default home activity component name.
443      */
getDefaultHomeActivity(int userId)444     public abstract ComponentName getDefaultHomeActivity(int userId);
445 
446     /**
447      * Called by DeviceOwnerManagerService to set the package names of device owner and profile
448      * owners.
449      */
setDeviceAndProfileOwnerPackages( int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners)450     public abstract void setDeviceAndProfileOwnerPackages(
451             int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners);
452 
453     /**
454      * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}.
455      */
isPackageDataProtected(int userId, String packageName)456     public abstract boolean isPackageDataProtected(int userId, String packageName);
457 
458     /**
459      * Returns {@code true} if a given package's state is protected, e.g. it cannot be force
460      * stopped, suspended, disabled or hidden. Otherwise, returns {@code false}.
461      */
isPackageStateProtected(String packageName, int userId)462     public abstract boolean isPackageStateProtected(String packageName, int userId);
463 
464     /**
465      * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns
466      * {@code false}.
467      */
isPackageEphemeral(int userId, String packageName)468     public abstract boolean isPackageEphemeral(int userId, String packageName);
469 
470     /**
471      * Gets whether the package was ever launched.
472      * @param packageName The package name.
473      * @param userId The user for which to check.
474      * @return Whether was launched.
475      * @throws IllegalArgumentException if the package is not found
476      */
wasPackageEverLaunched(String packageName, int userId)477     public abstract boolean wasPackageEverLaunched(String packageName, int userId);
478 
479     /**
480      * Grants a runtime permission
481      * @param packageName The package name.
482      * @param name The name of the permission.
483      * @param userId The userId for which to grant the permission.
484      * @param overridePolicy If true, grant this permission even if it is fixed by policy.
485      */
grantRuntimePermission(String packageName, String name, int userId, boolean overridePolicy)486     public abstract void grantRuntimePermission(String packageName, String name, int userId,
487             boolean overridePolicy);
488 
489     /**
490      * Revokes a runtime permission
491      * @param packageName The package name.
492      * @param name The name of the permission.
493      * @param userId The userId for which to revoke the permission.
494      * @param overridePolicy If true, revoke this permission even if it is fixed by policy.
495      */
revokeRuntimePermission(String packageName, String name, int userId, boolean overridePolicy)496     public abstract void revokeRuntimePermission(String packageName, String name, int userId,
497             boolean overridePolicy);
498 
499     /**
500      * Retrieve the official name associated with a uid. This name is
501      * guaranteed to never change, though it is possible for the underlying
502      * uid to be changed. That is, if you are storing information about
503      * uids in persistent storage, you should use the string returned
504      * by this function instead of the raw uid.
505      *
506      * @param uid The uid for which you would like to retrieve a name.
507      * @return Returns a unique name for the given uid, or null if the
508      * uid is not currently assigned.
509      */
getNameForUid(int uid)510     public abstract String getNameForUid(int uid);
511 
512     /**
513      * Request to perform the second phase of ephemeral resolution.
514      * @param responseObj The response of the first phase of ephemeral resolution
515      * @param origIntent The original intent that triggered ephemeral resolution
516      * @param resolvedType The resolved type of the intent
517      * @param callingPackage The name of the package requesting the ephemeral application
518      * @param verificationBundle Optional bundle to pass to the installer for additional
519      * verification
520      * @param userId The ID of the user that triggered ephemeral resolution
521      */
requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, Intent origIntent, String resolvedType, String callingPackage, Bundle verificationBundle, int userId)522     public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj,
523             Intent origIntent, String resolvedType, String callingPackage,
524             Bundle verificationBundle, int userId);
525 
526     /**
527      * Grants access to the package metadata for an ephemeral application.
528      * <p>
529      * When an ephemeral application explicitly tries to interact with a full
530      * install application [via an activity, service or provider that has been
531      * exposed using the {@code visibleToInstantApp} attribute], the normal
532      * application must be able to see metadata about the connecting ephemeral
533      * app. If the ephemeral application uses an implicit intent [ie action VIEW,
534      * category BROWSABLE], it remains hidden from the launched activity.
535      * <p>
536      * If the {@code sourceUid} is not for an ephemeral app or {@code targetUid}
537      * is not for a fully installed app, this method will be a no-op.
538      *
539      * @param userId the user
540      * @param intent the intent that triggered the grant
541      * @param targetAppId The app ID of the fully installed application
542      * @param ephemeralAppId The app ID of the ephemeral application
543      */
grantEphemeralAccess(int userId, Intent intent, int targetAppId, int ephemeralAppId)544     public abstract void grantEphemeralAccess(int userId, Intent intent,
545             int targetAppId, int ephemeralAppId);
546 
isInstantAppInstallerComponent(ComponentName component)547     public abstract boolean isInstantAppInstallerComponent(ComponentName component);
548     /**
549      * Prunes instant apps and state associated with uninstalled
550      * instant apps according to the current platform policy.
551      */
pruneInstantApps()552     public abstract void pruneInstantApps();
553 
554     /**
555      * @return The SetupWizard package name.
556      */
getSetupWizardPackageName()557     public abstract String getSetupWizardPackageName();
558 
559     public interface ExternalSourcesPolicy {
560 
561         int USER_TRUSTED = 0;   // User has trusted the package to install apps
562         int USER_BLOCKED = 1;   // User has blocked the package to install apps
563         int USER_DEFAULT = 2;   // Default code to use when user response is unavailable
564 
565         /**
566          * Checks the user preference for whether a package is trusted to request installs through
567          * package installer
568          *
569          * @param packageName The package to check for
570          * @param uid the uid in which the package is running
571          * @return {@link #USER_TRUSTED} if the user has trusted the package, {@link #USER_BLOCKED}
572          * if user has blocked requests from the package, {@link #USER_DEFAULT} if the user response
573          * is not yet available
574          */
getPackageTrustedToInstallApps(String packageName, int uid)575         int getPackageTrustedToInstallApps(String packageName, int uid);
576     }
577 
setExternalSourcesPolicy(ExternalSourcesPolicy policy)578     public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy);
579 
580     /**
581      * Return true if the given package is a persistent app process.
582      */
isPackagePersistent(String packageName)583     public abstract boolean isPackagePersistent(String packageName);
584 
585     /**
586      * Returns whether or not the given package represents a legacy system application released
587      * prior to runtime permissions.
588      */
isLegacySystemApp(PackageParser.Package pkg)589     public abstract boolean isLegacySystemApp(PackageParser.Package pkg);
590 
591     /**
592      * Get all overlay packages for a user.
593      * @param userId The user for which to get the overlays.
594      * @return A list of overlay packages. An empty list is returned if the
595      *         user has no installed overlay packages.
596      */
getOverlayPackages(int userId)597     public abstract List<PackageInfo> getOverlayPackages(int userId);
598 
599     /**
600      * Get the names of all target packages for a user.
601      * @param userId The user for which to get the package names.
602      * @return A list of target package names. This list includes the "android" package.
603      */
getTargetPackageNames(int userId)604     public abstract List<String> getTargetPackageNames(int userId);
605 
606     /**
607      * Set which overlay to use for a package.
608      * @param userId The user for which to update the overlays.
609      * @param targetPackageName The package name of the package for which to update the overlays.
610      * @param overlayPackageNames The complete list of overlay packages that should be enabled for
611      *                            the target. Previously enabled overlays not specified in the list
612      *                            will be disabled. Pass in null or an empty list to disable
613      *                            all overlays. The order of the items is significant if several
614      *                            overlays modify the same resource.
615      * @return true if all packages names were known by the package manager, false otherwise
616      */
setEnabledOverlayPackages(int userId, String targetPackageName, List<String> overlayPackageNames)617     public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName,
618             List<String> overlayPackageNames);
619 
620     /**
621      * Resolves an activity intent, allowing instant apps to be resolved.
622      */
resolveIntent(Intent intent, String resolvedType, int flags, int userId, boolean resolveForStart, int filterCallingUid)623     public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
624             int flags, int userId, boolean resolveForStart, int filterCallingUid);
625 
626     /**
627     * Resolves a service intent, allowing instant apps to be resolved.
628     */
resolveService(Intent intent, String resolvedType, int flags, int userId, int callingUid)629     public abstract ResolveInfo resolveService(Intent intent, String resolvedType,
630            int flags, int userId, int callingUid);
631 
632    /**
633     * Resolves a content provider intent.
634     */
resolveContentProvider(String name, int flags, int userId)635     public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId);
636 
637     /**
638      * Track the creator of a new isolated uid.
639      * @param isolatedUid The newly created isolated uid.
640      * @param ownerUid The uid of the app that created the isolated process.
641      */
addIsolatedUid(int isolatedUid, int ownerUid)642     public abstract void addIsolatedUid(int isolatedUid, int ownerUid);
643 
644     /**
645      * Track removal of an isolated uid.
646      * @param isolatedUid isolated uid that is no longer being used.
647      */
removeIsolatedUid(int isolatedUid)648     public abstract void removeIsolatedUid(int isolatedUid);
649 
650     /**
651      * Return the taget SDK version for the app with the given UID.
652      */
getUidTargetSdkVersion(int uid)653     public abstract int getUidTargetSdkVersion(int uid);
654 
655     /**
656      * Return the taget SDK version for the app with the given package name.
657      */
getPackageTargetSdkVersion(String packageName)658     public abstract int getPackageTargetSdkVersion(String packageName);
659 
660     /** Whether the binder caller can access instant apps. */
canAccessInstantApps(int callingUid, int userId)661     public abstract boolean canAccessInstantApps(int callingUid, int userId);
662 
663     /** Whether the binder caller can access the given component. */
canAccessComponent(int callingUid, ComponentName component, int userId)664     public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId);
665 
666     /**
667      * Returns {@code true} if a given package has instant application meta-data.
668      * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc)
669      * associated with an instant app. It may be kept after the instant app has been uninstalled.
670      */
hasInstantApplicationMetadata(String packageName, int userId)671     public abstract boolean hasInstantApplicationMetadata(String packageName, int userId);
672 
673     /**
674      * Updates a package last used time.
675      */
notifyPackageUse(String packageName, int reason)676     public abstract void notifyPackageUse(String packageName, int reason);
677 
678     /**
679      * Returns a package object for the given package name.
680      */
getPackage(@onNull String packageName)681     public abstract @Nullable PackageParser.Package getPackage(@NonNull String packageName);
682 
683     /**
684      * Returns a list without a change observer.
685      *
686      * @see #getPackageList(PackageListObserver)
687      */
getPackageList()688     public @NonNull PackageList getPackageList() {
689         return getPackageList(null);
690     }
691 
692     /**
693      * Returns the list of packages installed at the time of the method call.
694      * <p>The given observer is notified when the list of installed packages
695      * changes [eg. a package was installed or uninstalled]. It will not be
696      * notified if a package is updated.
697      * <p>The package list will not be updated automatically as packages are
698      * installed / uninstalled. Any changes must be handled within the observer.
699      */
getPackageList(@ullable PackageListObserver observer)700     public abstract @NonNull PackageList getPackageList(@Nullable PackageListObserver observer);
701 
702     /**
703      * Removes the observer.
704      * <p>Generally not needed. {@link #getPackageList(PackageListObserver)} will automatically
705      * remove the observer.
706      * <p>Does nothing if the observer isn't currently registered.
707      * <p>Observers are notified asynchronously and it's possible for an observer to be
708      * invoked after its been removed.
709      */
removePackageListObserver(@onNull PackageListObserver observer)710     public abstract void removePackageListObserver(@NonNull PackageListObserver observer);
711 
712     /**
713      * Returns a package object for the disabled system package name.
714      */
getDisabledSystemPackage( @onNull String packageName)715     public abstract @Nullable PackageParser.Package getDisabledSystemPackage(
716             @NonNull String packageName);
717 
718     /**
719      * Returns the package name for the disabled system package.
720      *
721      * This is equivalent to
722      * {@link #getDisabledSystemPackage(String)}.{@link PackageParser.Package#packageName}
723      */
getDisabledSystemPackageName(@onNull String packageName)724     public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName);
725 
726     /**
727      * Returns whether or not the component is the resolver activity.
728      */
isResolveActivityComponent(@onNull ComponentInfo component)729     public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component);
730 
731 
732     /**
733      * Returns a list of package names for a known package
734      */
getKnownPackageNames( @nownPackage int knownPackage, int userId)735     public abstract @NonNull String[] getKnownPackageNames(
736             @KnownPackage int knownPackage, int userId);
737 
738     /**
739      * Returns whether the package is an instant app.
740      */
isInstantApp(String packageName, int userId)741     public abstract boolean isInstantApp(String packageName, int userId);
742 
743     /**
744      * Returns whether the package is an instant app.
745      */
getInstantAppPackageName(int uid)746     public abstract @Nullable String getInstantAppPackageName(int uid);
747 
748     /**
749      * Returns whether or not access to the application should be filtered.
750      * <p>
751      * Access may be limited based upon whether the calling or target applications
752      * are instant applications.
753      *
754      * @see #canAccessInstantApps
755      */
filterAppAccess( @ullable PackageParser.Package pkg, int callingUid, int userId)756     public abstract boolean filterAppAccess(
757             @Nullable PackageParser.Package pkg, int callingUid, int userId);
758 
759     /*
760      * NOTE: The following methods are temporary until permissions are extracted from
761      * the package manager into a component specifically for handling permissions.
762      */
763     /** Returns the flags for the given permission. */
getPermissionFlagsTEMP(@onNull String permName, @NonNull String packageName, int userId)764     public abstract @Nullable int getPermissionFlagsTEMP(@NonNull String permName,
765             @NonNull String packageName, int userId);
766     /** Updates the flags for the given permission. */
updatePermissionFlagsTEMP(@onNull String permName, @NonNull String packageName, int flagMask, int flagValues, int userId)767     public abstract void updatePermissionFlagsTEMP(@NonNull String permName,
768             @NonNull String packageName, int flagMask, int flagValues, int userId);
769 
770     /** Returns whether the given package was signed by the platform */
isPlatformSigned(String pkg)771     public abstract boolean isPlatformSigned(String pkg);
772 
773     /**
774      * Returns true if it's still safe to restore data backed up from this app's version
775      * that was signed with restoringFromSigHash.
776      */
isDataRestoreSafe(@onNull byte[] restoringFromSigHash, @NonNull String packageName)777     public abstract boolean isDataRestoreSafe(@NonNull byte[] restoringFromSigHash,
778             @NonNull String packageName);
779 
780     /**
781      * Returns true if it's still safe to restore data backed up from this app's version
782      * that was signed with restoringFromSig.
783      */
isDataRestoreSafe(@onNull Signature restoringFromSig, @NonNull String packageName)784     public abstract boolean isDataRestoreSafe(@NonNull Signature restoringFromSig,
785             @NonNull String packageName);
786 
787     /**
788      * Returns {@code true} if the the signing information for {@code clientUid} is sufficient
789      * to gain access gated by {@code capability}.  This can happen if the two UIDs have the
790      * same signing information, if the signing information {@code clientUid} indicates that
791      * it has the signing certificate for {@code serverUid} in its signing history (if it was
792      * previously signed by it), or if the signing certificate for {@code clientUid} is in the
793      * signing history for {@code serverUid} and with the {@code capability} specified.
794      */
hasSignatureCapability(int serverUid, int clientUid, @PackageParser.SigningDetails.CertCapabilities int capability)795     public abstract boolean hasSignatureCapability(int serverUid, int clientUid,
796             @PackageParser.SigningDetails.CertCapabilities int capability);
797 
798     /**
799      * Get the delegate to influence permission checking.
800      *
801      * @return The delegate instance or null to clear.
802      */
getCheckPermissionDelegate()803     public abstract @Nullable CheckPermissionDelegate getCheckPermissionDelegate();
804 
805     /**
806      * Set a delegate to influence permission checking.
807      *
808      * @param delegate A delegate instance or null to clear.
809      */
setCheckPermissionDelegate(@ullable CheckPermissionDelegate delegate)810     public abstract void setCheckPermissionDelegate(@Nullable CheckPermissionDelegate delegate);
811 
812     /**
813      * Get appIds of all available apps which specified android:sharedUserId in the manifest.
814      *
815      * @return a SparseArray mapping from appId to it's sharedUserId.
816      */
getAppsWithSharedUserIds()817     public abstract SparseArray<String> getAppsWithSharedUserIds();
818 
819     /**
820      * Get the value of attribute android:sharedUserId for the given packageName if specified,
821      * otherwise {@code null}.
822      */
getSharedUserIdForPackage(@onNull String packageName)823     public abstract String getSharedUserIdForPackage(@NonNull String packageName);
824 
825     /**
826      * Get all packages which specified the given sharedUserId as android:sharedUserId attribute
827      * or an empty array if no package specified it.
828      */
getPackagesForSharedUserId(@onNull String sharedUserId, int userId)829     public abstract String[] getPackagesForSharedUserId(@NonNull String sharedUserId, int userId);
830 
831     /**
832      * Return if device is currently in a "core" boot environment, typically
833      * used to support full-disk encryption. Only apps marked with
834      * {@code coreApp} attribute are available.
835      */
isOnlyCoreApps()836     public abstract boolean isOnlyCoreApps();
837 
838     /**
839      * Make a best-effort attempt to provide the requested free disk space by
840      * deleting cached files.
841      *
842      * @throws IOException if the request was unable to be fulfilled.
843      */
freeStorage(String volumeUuid, long bytes, int storageFlags)844     public abstract void freeStorage(String volumeUuid, long bytes, int storageFlags)
845             throws IOException;
846 
847     /** Returns {@code true} if the specified component is enabled and matches the given flags. */
isEnabledAndMatches(@onNull ComponentInfo info, int flags, int userId)848     public abstract boolean isEnabledAndMatches(@NonNull ComponentInfo info, int flags, int userId);
849 
850     /** Returns {@code true} if the given user requires extra badging for icons. */
userNeedsBadging(int userId)851     public abstract boolean userNeedsBadging(int userId);
852 
853     /**
854      * Perform the given action for each package.
855      * Note that packages lock will be held while performin the actions.
856      *
857      * @param actionLocked action to be performed
858      */
forEachPackage(Consumer<PackageParser.Package> actionLocked)859     public abstract void forEachPackage(Consumer<PackageParser.Package> actionLocked);
860 
861     /**
862      * Perform the given action for each installed package for a user.
863      * Note that packages lock will be held while performin the actions.
864      */
forEachInstalledPackage( @onNull Consumer<PackageParser.Package> actionLocked, @UserIdInt int userId)865     public abstract void forEachInstalledPackage(
866             @NonNull Consumer<PackageParser.Package> actionLocked, @UserIdInt int userId);
867 
868     /** Returns the list of enabled components */
getEnabledComponents(String packageName, int userId)869     public abstract ArraySet<String> getEnabledComponents(String packageName, int userId);
870 
871     /** Returns the list of disabled components */
getDisabledComponents(String packageName, int userId)872     public abstract ArraySet<String> getDisabledComponents(String packageName, int userId);
873 
874     /** Returns whether the given package is enabled for the given user */
getApplicationEnabledState( String packageName, int userId)875     public abstract @PackageManager.EnabledState int getApplicationEnabledState(
876             String packageName, int userId);
877 
878     /**
879      * Extra field name for the token of a request to enable rollback for a
880      * package.
881      */
882     public static final String EXTRA_ENABLE_ROLLBACK_TOKEN =
883             "android.content.pm.extra.ENABLE_ROLLBACK_TOKEN";
884 
885     /**
886      * Extra field name for the installFlags of a request to enable rollback
887      * for a package.
888      */
889     public static final String EXTRA_ENABLE_ROLLBACK_INSTALL_FLAGS =
890             "android.content.pm.extra.ENABLE_ROLLBACK_INSTALL_FLAGS";
891 
892     /**
893      * Extra field name for the user id an install is associated with when
894      * enabling rollback.
895      */
896     public static final String EXTRA_ENABLE_ROLLBACK_USER =
897             "android.content.pm.extra.ENABLE_ROLLBACK_USER";
898 
899     /**
900      * Used as the {@code enableRollbackCode} argument for
901      * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that
902      * enabling rollback succeeded.
903      */
904     public static final int ENABLE_ROLLBACK_SUCCEEDED = 1;
905 
906     /**
907      * Used as the {@code enableRollbackCode} argument for
908      * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that
909      * enabling rollback failed.
910      */
911     public static final int ENABLE_ROLLBACK_FAILED = -1;
912 
913     /**
914      * Allows the rollback manager listening to the
915      * {@link Intent#ACTION_PACKAGE_ENABLE_ROLLBACK enable rollback broadcast}
916      * to respond to the package manager. The response must include the
917      * {@code enableRollbackCode} which is one of
918      * {@link PackageManager#ENABLE_ROLLBACK_SUCCEEDED} or
919      * {@link PackageManager#ENABLE_ROLLBACK_FAILED}.
920      *
921      * @param token pending package identifier as passed via the
922      *            {@link PackageManager#EXTRA_ENABLE_ROLLBACK_TOKEN} Intent extra.
923      * @param enableRollbackCode the status code result of enabling rollback
924      * @throws SecurityException if the caller does not have the
925      *            PACKAGE_ROLLBACK_AGENT permission.
926      */
setEnableRollbackCode(int token, int enableRollbackCode)927     public abstract void setEnableRollbackCode(int token, int enableRollbackCode);
928 
929     /**
930      * Ask the package manager to compile layouts in the given package.
931      */
compileLayouts(String packageName)932     public abstract boolean compileLayouts(String packageName);
933 
934     /*
935      * Inform the package manager that the pending package install identified by
936      * {@code token} can be completed.
937      */
finishPackageInstall(int token, boolean didLaunch)938     public abstract void finishPackageInstall(int token, boolean didLaunch);
939 
940     /**
941      * Remove the default browser stored in the legacy package settings.
942      *
943      * @param userId the user id
944      *
945      * @return the package name of the default browser, or {@code null} if none
946      */
947     @Nullable
removeLegacyDefaultBrowserPackageName(int userId)948     public abstract String removeLegacyDefaultBrowserPackageName(int userId);
949 
950     /**
951      * Sets the default browser provider.
952      *
953      * @param provider the provider
954      */
setDefaultBrowserProvider(@onNull DefaultBrowserProvider provider)955     public abstract void setDefaultBrowserProvider(@NonNull DefaultBrowserProvider provider);
956 
957     /**
958      * Sets the default dialer provider.
959      *
960      * @param provider the provider
961      */
setDefaultDialerProvider(@onNull DefaultDialerProvider provider)962     public abstract void setDefaultDialerProvider(@NonNull DefaultDialerProvider provider);
963 
964     /**
965      * Sets the default home provider.
966      *
967      * @param provider the provider
968      */
setDefaultHomeProvider(@onNull DefaultHomeProvider provider)969     public abstract void setDefaultHomeProvider(@NonNull DefaultHomeProvider provider);
970 
971     /**
972      * Returns {@code true} if given {@code packageName} is an apex package.
973      */
isApexPackage(String packageName)974     public abstract boolean isApexPackage(String packageName);
975 
976     /**
977      * Uninstalls given {@code packageName}.
978      *
979      * @param packageName apex package to uninstall.
980      * @param versionCode version of a package to uninstall.
981      * @param userId user to uninstall apex package for. Must be
982      *               {@link android.os.UserHandle#USER_ALL}, otherwise failure will be reported.
983      * @param intentSender a {@link IntentSender} to send result of an uninstall to.
984      */
uninstallApex(String packageName, long versionCode, int userId, IntentSender intentSender)985     public abstract void uninstallApex(String packageName, long versionCode, int userId,
986             IntentSender intentSender);
987 
988     /**
989      * Whether default permission grants have been performed for a user
990      * since the device booted.
991      *
992      * @param userId The user id.
993      * @return true if default permissions
994      */
wereDefaultPermissionsGrantedSinceBoot(int userId)995     public abstract boolean wereDefaultPermissionsGrantedSinceBoot(int userId);
996 
997     /**
998      * Get fingerprint of build that updated the runtime permissions for a user.
999      *
1000      * @param userId The user to update
1001      * @param fingerPrint The fingerprint to set
1002      */
setRuntimePermissionsFingerPrint(@onNull String fingerPrint, @UserIdInt int userId)1003     public abstract void setRuntimePermissionsFingerPrint(@NonNull String fingerPrint,
1004             @UserIdInt int userId);
1005 
1006     /**
1007      * Migrates legacy obb data to its new location.
1008      */
migrateLegacyObbData()1009     public abstract void migrateLegacyObbData();
1010 
1011     /**
1012      * Ensures that we block deletion of unused packages on user removal. This is purely for the
1013      * purpose of ensuring that b/141413692 is not reproducible on Q.
1014      */
notifyingOnNextUserRemovalForTest()1015     public abstract void notifyingOnNextUserRemovalForTest();
1016 
1017     /**
1018      * Notifies PackageManager of the removal of a user. This is purely for the purpose of ensuring
1019      * that b/141413692 is not reproducible on Q.
1020      */
userRemovedForTest()1021     public abstract void userRemovedForTest();
1022 }
1023