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