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.content.ComponentName;
20 import android.content.Intent;
21 import android.content.pm.PackageManager.ApplicationInfoFlags;
22 import android.content.pm.PackageManager.ComponentInfoFlags;
23 import android.content.pm.PackageManager.NameNotFoundException;
24 import android.content.pm.PackageManager.PackageInfoFlags;
25 import android.content.pm.PackageManager.ResolveInfoFlags;
26 import android.os.Bundle;
27 import android.util.SparseArray;
28 
29 import java.util.List;
30 
31 /**
32  * Package manager local system service interface.
33  *
34  * @hide Only for use within the system server.
35  */
36 public abstract class PackageManagerInternal {
37 
38     /**
39      * Provider for package names.
40      */
41     public interface PackagesProvider {
42 
43         /**
44          * Gets the packages for a given user.
45          * @param userId The user id.
46          * @return The package names.
47          */
getPackages(int userId)48         public String[] getPackages(int userId);
49     }
50 
51     /**
52      * Provider for package names.
53      */
54     public interface SyncAdapterPackagesProvider {
55 
56         /**
57          * Gets the sync adapter packages for given authority and user.
58          * @param authority The authority.
59          * @param userId The user id.
60          * @return The package names.
61          */
getPackages(String authority, int userId)62         public String[] getPackages(String authority, int userId);
63     }
64 
65     /**
66      * Sets the location provider packages provider.
67      * @param provider The packages provider.
68      */
setLocationPackagesProvider(PackagesProvider provider)69     public abstract void setLocationPackagesProvider(PackagesProvider provider);
70 
71     /**
72      * Sets the voice interaction packages provider.
73      * @param provider The packages provider.
74      */
setVoiceInteractionPackagesProvider(PackagesProvider provider)75     public abstract void setVoiceInteractionPackagesProvider(PackagesProvider provider);
76 
77     /**
78      * Sets the SMS packages provider.
79      * @param provider The packages provider.
80      */
setSmsAppPackagesProvider(PackagesProvider provider)81     public abstract void setSmsAppPackagesProvider(PackagesProvider provider);
82 
83     /**
84      * Sets the dialer packages provider.
85      * @param provider The packages provider.
86      */
setDialerAppPackagesProvider(PackagesProvider provider)87     public abstract void setDialerAppPackagesProvider(PackagesProvider provider);
88 
89     /**
90      * Sets the sim call manager packages provider.
91      * @param provider The packages provider.
92      */
setSimCallManagerPackagesProvider(PackagesProvider provider)93     public abstract void setSimCallManagerPackagesProvider(PackagesProvider provider);
94 
95     /**
96      * Sets the sync adapter packages provider.
97      * @param provider The provider.
98      */
setSyncAdapterPackagesprovider(SyncAdapterPackagesProvider provider)99     public abstract void setSyncAdapterPackagesprovider(SyncAdapterPackagesProvider provider);
100 
101     /**
102      * Requests granting of the default permissions to the current default SMS app.
103      * @param packageName The default SMS package name.
104      * @param userId The user for which to grant the permissions.
105      */
grantDefaultPermissionsToDefaultSmsApp(String packageName, int userId)106     public abstract void grantDefaultPermissionsToDefaultSmsApp(String packageName, int userId);
107 
108     /**
109      * Requests granting of the default permissions to the current default dialer app.
110      * @param packageName The default dialer package name.
111      * @param userId The user for which to grant the permissions.
112      */
grantDefaultPermissionsToDefaultDialerApp(String packageName, int userId)113     public abstract void grantDefaultPermissionsToDefaultDialerApp(String packageName, int userId);
114 
115     /**
116      * Requests granting of the default permissions to the current default sim call manager.
117      * @param packageName The default sim call manager package name.
118      * @param userId The user for which to grant the permissions.
119      */
grantDefaultPermissionsToDefaultSimCallManager(String packageName, int userId)120     public abstract void grantDefaultPermissionsToDefaultSimCallManager(String packageName,
121             int userId);
122 
123     /**
124      * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has
125      * currently installed it. The apps are not preloaded.
126      * @param packageList List of package names to keep cached.
127      */
setKeepUninstalledPackages(List<String> packageList)128     public abstract void setKeepUninstalledPackages(List<String> packageList);
129 
130     /**
131      * Gets whether some of the permissions used by this package require a user
132      * review before any of the app components can run.
133      * @param packageName The package name for which to check.
134      * @param userId The user under which to check.
135      * @return True a permissions review is required.
136      */
isPermissionsReviewRequired(String packageName, int userId)137     public abstract boolean isPermissionsReviewRequired(String packageName, int userId);
138 
139     /**
140      * Retrieve all of the information we know about a particular package/application.
141      * @param filterCallingUid The results will be filtered in the context of this UID instead
142      * of the calling UID.
143      * @see PackageManager#getPackageInfo(String, int)
144      */
getPackageInfo(String packageName, @PackageInfoFlags int flags, int filterCallingUid, int userId)145     public abstract PackageInfo getPackageInfo(String packageName,
146             @PackageInfoFlags int flags, int filterCallingUid, int userId);
147 
148     /**
149      * Retrieve all of the information we know about a particular package/application.
150      * @param filterCallingUid The results will be filtered in the context of this UID instead
151      * of the calling UID.
152      * @see PackageManager#getApplicationInfo(String, int)
153      */
getApplicationInfo(String packageName, @ApplicationInfoFlags int flags, int filterCallingUid, int userId)154     public abstract ApplicationInfo getApplicationInfo(String packageName,
155             @ApplicationInfoFlags int flags, int filterCallingUid, int userId);
156 
157     /**
158      * Retrieve all of the information we know about a particular activity class.
159      * @param filterCallingUid The results will be filtered in the context of this UID instead
160      * of the calling UID.
161      * @see PackageManager#getActivityInfo(ComponentName, int)
162      */
getActivityInfo(ComponentName component, @ComponentInfoFlags int flags, int filterCallingUid, int userId)163     public abstract ActivityInfo getActivityInfo(ComponentName component,
164             @ComponentInfoFlags int flags, int filterCallingUid, int userId);
165 
166     /**
167      * Retrieve all activities that can be performed for the given intent.
168      * @param filterCallingUid The results will be filtered in the context of this UID instead
169      * of the calling UID.
170      * @see PackageManager#queryIntentActivities(Intent, int)
171      */
queryIntentActivities(Intent intent, @ResolveInfoFlags int flags, int filterCallingUid, int userId)172     public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
173             @ResolveInfoFlags int flags, int filterCallingUid, int userId);
174 
175     /**
176      * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}.
177      */
getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, int userId)178     public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates,
179             int userId);
180 
181     /**
182      * Called by DeviceOwnerManagerService to set the package names of device owner and profile
183      * owners.
184      */
setDeviceAndProfileOwnerPackages( int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners)185     public abstract void setDeviceAndProfileOwnerPackages(
186             int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners);
187 
188     /**
189      * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}.
190      */
isPackageDataProtected(int userId, String packageName)191     public abstract boolean isPackageDataProtected(int userId, String packageName);
192 
193     /**
194      * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns
195      * {@code false}.
196      */
isPackageEphemeral(int userId, String packageName)197     public abstract boolean isPackageEphemeral(int userId, String packageName);
198 
199     /**
200      * Gets whether the package was ever launched.
201      * @param packageName The package name.
202      * @param userId The user for which to check.
203      * @return Whether was launched.
204      * @throws IllegalArgumentException if the package is not found
205      */
wasPackageEverLaunched(String packageName, int userId)206     public abstract boolean wasPackageEverLaunched(String packageName, int userId);
207 
208     /**
209      * Grants a runtime permission
210      * @param packageName The package name.
211      * @param name The name of the permission.
212      * @param userId The userId for which to grant the permission.
213      * @param overridePolicy If true, grant this permission even if it is fixed by policy.
214      */
grantRuntimePermission(String packageName, String name, int userId, boolean overridePolicy)215     public abstract void grantRuntimePermission(String packageName, String name, int userId,
216             boolean overridePolicy);
217 
218     /**
219      * Revokes a runtime permission
220      * @param packageName The package name.
221      * @param name The name of the permission.
222      * @param userId The userId for which to revoke the permission.
223      * @param overridePolicy If true, revoke this permission even if it is fixed by policy.
224      */
revokeRuntimePermission(String packageName, String name, int userId, boolean overridePolicy)225     public abstract void revokeRuntimePermission(String packageName, String name, int userId,
226             boolean overridePolicy);
227 
228     /**
229      * Retrieve the official name associated with a uid. This name is
230      * guaranteed to never change, though it is possible for the underlying
231      * uid to be changed. That is, if you are storing information about
232      * uids in persistent storage, you should use the string returned
233      * by this function instead of the raw uid.
234      *
235      * @param uid The uid for which you would like to retrieve a name.
236      * @return Returns a unique name for the given uid, or null if the
237      * uid is not currently assigned.
238      */
getNameForUid(int uid)239     public abstract String getNameForUid(int uid);
240 
241     /**
242      * Request to perform the second phase of ephemeral resolution.
243      * @param responseObj The response of the first phase of ephemeral resolution
244      * @param origIntent The original intent that triggered ephemeral resolution
245      * @param resolvedType The resolved type of the intent
246      * @param callingPackage The name of the package requesting the ephemeral application
247      * @param verificationBundle Optional bundle to pass to the installer for additional
248      * verification
249      * @param userId The ID of the user that triggered ephemeral resolution
250      */
requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, Intent origIntent, String resolvedType, String callingPackage, Bundle verificationBundle, int userId)251     public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj,
252             Intent origIntent, String resolvedType, String callingPackage,
253             Bundle verificationBundle, int userId);
254 
255     /**
256      * Grants access to the package metadata for an ephemeral application.
257      * <p>
258      * When an ephemeral application explicitly tries to interact with a full
259      * install application [via an activity, service or provider that has been
260      * exposed using the {@code visibleToInstantApp} attribute], the normal
261      * application must be able to see metadata about the connecting ephemeral
262      * app. If the ephemeral application uses an implicit intent [ie action VIEW,
263      * category BROWSABLE], it remains hidden from the launched activity.
264      * <p>
265      * If the {@code sourceUid} is not for an ephemeral app or {@code targetUid}
266      * is not for a fully installed app, this method will be a no-op.
267      *
268      * @param userId the user
269      * @param intent the intent that triggered the grant
270      * @param targetAppId The app ID of the fully installed application
271      * @param ephemeralAppId The app ID of the ephemeral application
272      */
grantEphemeralAccess(int userId, Intent intent, int targetAppId, int ephemeralAppId)273     public abstract void grantEphemeralAccess(int userId, Intent intent,
274             int targetAppId, int ephemeralAppId);
275 
isInstantAppInstallerComponent(ComponentName component)276     public abstract boolean isInstantAppInstallerComponent(ComponentName component);
277     /**
278      * Prunes instant apps and state associated with uninstalled
279      * instant apps according to the current platform policy.
280      */
pruneInstantApps()281     public abstract void pruneInstantApps();
282 
283     /**
284      * @return The SetupWizard package name.
285      */
getSetupWizardPackageName()286     public abstract String getSetupWizardPackageName();
287 
288     public interface ExternalSourcesPolicy {
289 
290         int USER_TRUSTED = 0;   // User has trusted the package to install apps
291         int USER_BLOCKED = 1;   // User has blocked the package to install apps
292         int USER_DEFAULT = 2;   // Default code to use when user response is unavailable
293 
294         /**
295          * Checks the user preference for whether a package is trusted to request installs through
296          * package installer
297          *
298          * @param packageName The package to check for
299          * @param uid the uid in which the package is running
300          * @return {@link USER_TRUSTED} if the user has trusted the package, {@link USER_BLOCKED}
301          * if user has blocked requests from the package, {@link USER_DEFAULT} if the user response
302          * is not yet available
303          */
getPackageTrustedToInstallApps(String packageName, int uid)304         int getPackageTrustedToInstallApps(String packageName, int uid);
305     }
306 
setExternalSourcesPolicy(ExternalSourcesPolicy policy)307     public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy);
308 
309     /**
310      * Return true if the given package is a persistent app process.
311      */
isPackagePersistent(String packageName)312     public abstract boolean isPackagePersistent(String packageName);
313 
314     /**
315      * Get all overlay packages for a user.
316      * @param userId The user for which to get the overlays.
317      * @return A list of overlay packages. An empty list is returned if the
318      *         user has no installed overlay packages.
319      */
getOverlayPackages(int userId)320     public abstract List<PackageInfo> getOverlayPackages(int userId);
321 
322     /**
323      * Get the names of all target packages for a user.
324      * @param userId The user for which to get the package names.
325      * @return A list of target package names. This list includes the "android" package.
326      */
getTargetPackageNames(int userId)327     public abstract List<String> getTargetPackageNames(int userId);
328 
329     /**
330      * Set which overlay to use for a package.
331      * @param userId The user for which to update the overlays.
332      * @param targetPackageName The package name of the package for which to update the overlays.
333      * @param overlayPackageNames The complete list of overlay packages that should be enabled for
334      *                            the target. Previously enabled overlays not specified in the list
335      *                            will be disabled. Pass in null or an empty list to disable
336      *                            all overlays. The order of the items is significant if several
337      *                            overlays modify the same resource.
338      * @return true if all packages names were known by the package manager, false otherwise
339      */
setEnabledOverlayPackages(int userId, String targetPackageName, List<String> overlayPackageNames)340     public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName,
341             List<String> overlayPackageNames);
342 
343     /**
344      * Resolves an activity intent, allowing instant apps to be resolved.
345      */
resolveIntent(Intent intent, String resolvedType, int flags, int userId)346     public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
347             int flags, int userId);
348 
349     /**
350     * Resolves a service intent, allowing instant apps to be resolved.
351     */
resolveService(Intent intent, String resolvedType, int flags, int userId, int callingUid)352    public abstract ResolveInfo resolveService(Intent intent, String resolvedType,
353            int flags, int userId, int callingUid);
354 
355     /**
356      * Track the creator of a new isolated uid.
357      * @param isolatedUid The newly created isolated uid.
358      * @param ownerUid The uid of the app that created the isolated process.
359      */
addIsolatedUid(int isolatedUid, int ownerUid)360     public abstract void addIsolatedUid(int isolatedUid, int ownerUid);
361 
362     /**
363      * Track removal of an isolated uid.
364      * @param isolatedUid isolated uid that is no longer being used.
365      */
removeIsolatedUid(int isolatedUid)366     public abstract void removeIsolatedUid(int isolatedUid);
367 
368     /**
369      * Return the taget SDK version for the app with the given UID.
370      */
getUidTargetSdkVersion(int uid)371     public abstract int getUidTargetSdkVersion(int uid);
372 
373     /** Whether the binder caller can access instant apps. */
canAccessInstantApps(int callingUid, int userId)374     public abstract boolean canAccessInstantApps(int callingUid, int userId);
375 }
376