blob: 713cd109ef87348e1b93ce21a7c7c817e27f5ad1 [file] [log] [blame]
Svet Ganovadc1cf42015-06-15 16:36:24 -07001/*
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
17package android.content.pm;
18
Todd Kennedy82b08422017-09-28 13:32:05 -070019import android.annotation.IntDef;
20import android.annotation.NonNull;
21import android.annotation.Nullable;
Makoto Onuki2d5b4652016-03-11 16:09:54 -080022import android.content.ComponentName;
Todd Kennedy01ad0c72016-11-11 15:33:12 -080023import android.content.Intent;
Todd Kennedy18211fd2017-06-06 09:15:46 -070024import android.content.pm.PackageManager.ApplicationInfoFlags;
25import android.content.pm.PackageManager.ComponentInfoFlags;
Todd Kennedy18211fd2017-06-06 09:15:46 -070026import android.content.pm.PackageManager.PackageInfoFlags;
27import android.content.pm.PackageManager.ResolveInfoFlags;
Chad Brubaker06068612017-04-06 09:43:47 -070028import android.os.Bundle;
Makoto Onukic29f62c2016-06-07 12:19:46 -070029import android.util.SparseArray;
Todd Kennedy39bfee52016-02-24 10:28:21 -080030
Todd Kennedy82b08422017-09-28 13:32:05 -070031import java.lang.annotation.Retention;
32import java.lang.annotation.RetentionPolicy;
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -080033import java.util.List;
Svet Ganovadc1cf42015-06-15 16:36:24 -070034
35/**
36 * Package manager local system service interface.
37 *
38 * @hide Only for use within the system server.
39 */
40public abstract class PackageManagerInternal {
Todd Kennedy82b08422017-09-28 13:32:05 -070041 public static final int PACKAGE_SYSTEM = 0;
42 public static final int PACKAGE_SETUP_WIZARD = 1;
43 public static final int PACKAGE_INSTALLER = 2;
44 public static final int PACKAGE_VERIFIER = 3;
45 public static final int PACKAGE_BROWSER = 4;
46 @IntDef(value = {
47 PACKAGE_SYSTEM,
48 PACKAGE_SETUP_WIZARD,
49 PACKAGE_INSTALLER,
50 PACKAGE_VERIFIER,
51 PACKAGE_BROWSER,
52 })
53 @Retention(RetentionPolicy.SOURCE)
54 public @interface KnownPackage {}
Svet Ganovadc1cf42015-06-15 16:36:24 -070055
56 /**
57 * Provider for package names.
58 */
59 public interface PackagesProvider {
60
61 /**
62 * Gets the packages for a given user.
63 * @param userId The user id.
64 * @return The package names.
65 */
66 public String[] getPackages(int userId);
67 }
68
69 /**
Svetoslav0010b702015-06-30 18:05:26 -070070 * Provider for package names.
71 */
72 public interface SyncAdapterPackagesProvider {
73
74 /**
75 * Gets the sync adapter packages for given authority and user.
76 * @param authority The authority.
77 * @param userId The user id.
78 * @return The package names.
79 */
80 public String[] getPackages(String authority, int userId);
81 }
82
83 /**
Svet Ganovadc1cf42015-06-15 16:36:24 -070084 * Sets the location provider packages provider.
85 * @param provider The packages provider.
86 */
87 public abstract void setLocationPackagesProvider(PackagesProvider provider);
88
89 /**
Svet Ganovadc1cf42015-06-15 16:36:24 -070090 * Sets the voice interaction packages provider.
91 * @param provider The packages provider.
92 */
93 public abstract void setVoiceInteractionPackagesProvider(PackagesProvider provider);
Svetoslavcdfd2302015-06-25 19:07:31 -070094
95 /**
96 * Sets the SMS packages provider.
97 * @param provider The packages provider.
98 */
99 public abstract void setSmsAppPackagesProvider(PackagesProvider provider);
100
101 /**
102 * Sets the dialer packages provider.
103 * @param provider The packages provider.
104 */
105 public abstract void setDialerAppPackagesProvider(PackagesProvider provider);
106
107 /**
Sailesh Nepalcf855622015-07-28 19:22:14 -0700108 * Sets the sim call manager packages provider.
109 * @param provider The packages provider.
110 */
111 public abstract void setSimCallManagerPackagesProvider(PackagesProvider provider);
112
113 /**
Svetoslav0010b702015-06-30 18:05:26 -0700114 * Sets the sync adapter packages provider.
115 * @param provider The provider.
116 */
117 public abstract void setSyncAdapterPackagesprovider(SyncAdapterPackagesProvider provider);
118
119 /**
Svetoslavcdfd2302015-06-25 19:07:31 -0700120 * Requests granting of the default permissions to the current default SMS app.
121 * @param packageName The default SMS package name.
122 * @param userId The user for which to grant the permissions.
123 */
124 public abstract void grantDefaultPermissionsToDefaultSmsApp(String packageName, int userId);
125
126 /**
127 * Requests granting of the default permissions to the current default dialer app.
128 * @param packageName The default dialer package name.
129 * @param userId The user for which to grant the permissions.
130 */
131 public abstract void grantDefaultPermissionsToDefaultDialerApp(String packageName, int userId);
Sailesh Nepalcf855622015-07-28 19:22:14 -0700132
133 /**
134 * Requests granting of the default permissions to the current default sim call manager.
135 * @param packageName The default sim call manager package name.
136 * @param userId The user for which to grant the permissions.
137 */
138 public abstract void grantDefaultPermissionsToDefaultSimCallManager(String packageName,
139 int userId);
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -0800140
141 /**
142 * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has
143 * currently installed it. The apps are not preloaded.
144 * @param packageList List of package names to keep cached.
145 */
146 public abstract void setKeepUninstalledPackages(List<String> packageList);
Svet Ganov9c165d72015-12-01 19:52:26 -0800147
148 /**
149 * Gets whether some of the permissions used by this package require a user
150 * review before any of the app components can run.
151 * @param packageName The package name for which to check.
152 * @param userId The user under which to check.
153 * @return True a permissions review is required.
154 */
155 public abstract boolean isPermissionsReviewRequired(String packageName, int userId);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800156
157 /**
Todd Kennedy18211fd2017-06-06 09:15:46 -0700158 * Retrieve all of the information we know about a particular package/application.
159 * @param filterCallingUid The results will be filtered in the context of this UID instead
160 * of the calling UID.
161 * @see PackageManager#getPackageInfo(String, int)
Todd Kennedy39bfee52016-02-24 10:28:21 -0800162 */
Todd Kennedy18211fd2017-06-06 09:15:46 -0700163 public abstract PackageInfo getPackageInfo(String packageName,
164 @PackageInfoFlags int flags, int filterCallingUid, int userId);
165
166 /**
Christopher Tatea732f012017-10-26 17:26:53 -0700167 * Do a straight uid lookup for the given package/application in the given user.
168 * @see PackageManager#getPackageUidAsUser(String, int, int)
169 * @return The app's uid, or < 0 if the package was not found in that user
170 */
171 public abstract int getPackageUid(String packageName,
172 @PackageInfoFlags int flags, int userId);
173
174 /**
Todd Kennedy18211fd2017-06-06 09:15:46 -0700175 * Retrieve all of the information we know about a particular package/application.
176 * @param filterCallingUid The results will be filtered in the context of this UID instead
177 * of the calling UID.
178 * @see PackageManager#getApplicationInfo(String, int)
179 */
180 public abstract ApplicationInfo getApplicationInfo(String packageName,
181 @ApplicationInfoFlags int flags, int filterCallingUid, int userId);
182
183 /**
184 * Retrieve all of the information we know about a particular activity class.
185 * @param filterCallingUid The results will be filtered in the context of this UID instead
186 * of the calling UID.
187 * @see PackageManager#getActivityInfo(ComponentName, int)
188 */
189 public abstract ActivityInfo getActivityInfo(ComponentName component,
190 @ComponentInfoFlags int flags, int filterCallingUid, int userId);
191
192 /**
193 * Retrieve all activities that can be performed for the given intent.
194 * @param filterCallingUid The results will be filtered in the context of this UID instead
195 * of the calling UID.
196 * @see PackageManager#queryIntentActivities(Intent, int)
197 */
198 public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
199 @ResolveInfoFlags int flags, int filterCallingUid, int userId);
Makoto Onuki2d5b4652016-03-11 16:09:54 -0800200
201 /**
Todd Kennedy82b08422017-09-28 13:32:05 -0700202 * Retrieve all services that can be performed for the given intent.
203 * @see PackageManager#queryIntentServices(Intent, int)
204 */
205 public abstract List<ResolveInfo> queryIntentServices(
206 Intent intent, int flags, int callingUid, int userId);
207
208 /**
Makoto Onuki2d5b4652016-03-11 16:09:54 -0800209 * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}.
210 */
211 public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates,
212 int userId);
Makoto Onukic29f62c2016-06-07 12:19:46 -0700213
214 /**
215 * Called by DeviceOwnerManagerService to set the package names of device owner and profile
216 * owners.
217 */
218 public abstract void setDeviceAndProfileOwnerPackages(
219 int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners);
220
221 /**
Steven Ng9d48a732016-06-24 19:04:14 +0100222 * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}.
Makoto Onukic29f62c2016-06-07 12:19:46 -0700223 */
Steven Ng9d48a732016-06-24 19:04:14 +0100224 public abstract boolean isPackageDataProtected(int userId, String packageName);
Svet Ganov973edd192016-09-08 20:15:55 -0700225
226 /**
Dianne Hackborne07641d2016-11-09 15:07:23 -0800227 * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns
228 * {@code false}.
229 */
230 public abstract boolean isPackageEphemeral(int userId, String packageName);
231
232 /**
Svet Ganov973edd192016-09-08 20:15:55 -0700233 * Gets whether the package was ever launched.
234 * @param packageName The package name.
235 * @param userId The user for which to check.
236 * @return Whether was launched.
Amith Yamasani2cbfa1e2017-03-28 10:34:01 -0700237 * @throws IllegalArgumentException if the package is not found
Svet Ganov973edd192016-09-08 20:15:55 -0700238 */
239 public abstract boolean wasPackageEverLaunched(String packageName, int userId);
Nicolas Prevot700e1e72016-09-28 15:17:18 +0100240
241 /**
242 * Grants a runtime permission
243 * @param packageName The package name.
244 * @param name The name of the permission.
245 * @param userId The userId for which to grant the permission.
246 * @param overridePolicy If true, grant this permission even if it is fixed by policy.
247 */
248 public abstract void grantRuntimePermission(String packageName, String name, int userId,
249 boolean overridePolicy);
250
251 /**
252 * Revokes a runtime permission
253 * @param packageName The package name.
254 * @param name The name of the permission.
255 * @param userId The userId for which to revoke the permission.
256 * @param overridePolicy If true, revoke this permission even if it is fixed by policy.
257 */
258 public abstract void revokeRuntimePermission(String packageName, String name, int userId,
259 boolean overridePolicy);
260
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100261 /**
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000262 * Retrieve the official name associated with a uid. This name is
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100263 * guaranteed to never change, though it is possible for the underlying
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000264 * uid to be changed. That is, if you are storing information about
265 * uids in persistent storage, you should use the string returned
266 * by this function instead of the raw uid.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100267 *
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000268 * @param uid The uid for which you would like to retrieve a name.
269 * @return Returns a unique name for the given uid, or null if the
270 * uid is not currently assigned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100271 */
272 public abstract String getNameForUid(int uid);
273
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800274 /**
275 * Request to perform the second phase of ephemeral resolution.
276 * @param responseObj The response of the first phase of ephemeral resolution
277 * @param origIntent The original intent that triggered ephemeral resolution
278 * @param resolvedType The resolved type of the intent
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800279 * @param callingPackage The name of the package requesting the ephemeral application
Chad Brubaker06068612017-04-06 09:43:47 -0700280 * @param verificationBundle Optional bundle to pass to the installer for additional
281 * verification
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800282 * @param userId The ID of the user that triggered ephemeral resolution
283 */
Todd Kennedye9910222017-02-21 16:00:11 -0800284 public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj,
285 Intent origIntent, String resolvedType, String callingPackage,
Chad Brubaker06068612017-04-06 09:43:47 -0700286 Bundle verificationBundle, int userId);
Svetoslav Ganove080da92016-12-21 17:10:35 -0800287
288 /**
Todd Kennedy0e989d02017-01-13 14:15:36 -0800289 * Grants access to the package metadata for an ephemeral application.
290 * <p>
291 * When an ephemeral application explicitly tries to interact with a full
292 * install application [via an activity, service or provider that has been
293 * exposed using the {@code visibleToInstantApp} attribute], the normal
294 * application must be able to see metadata about the connecting ephemeral
295 * app. If the ephemeral application uses an implicit intent [ie action VIEW,
296 * category BROWSABLE], it remains hidden from the launched activity.
297 * <p>
298 * If the {@code sourceUid} is not for an ephemeral app or {@code targetUid}
299 * is not for a fully installed app, this method will be a no-op.
300 *
301 * @param userId the user
302 * @param intent the intent that triggered the grant
303 * @param targetAppId The app ID of the fully installed application
304 * @param ephemeralAppId The app ID of the ephemeral application
305 */
306 public abstract void grantEphemeralAccess(int userId, Intent intent,
307 int targetAppId, int ephemeralAppId);
308
Todd Kennedyb21be122017-03-24 14:10:01 -0700309 public abstract boolean isInstantAppInstallerComponent(ComponentName component);
Todd Kennedy0e989d02017-01-13 14:15:36 -0800310 /**
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800311 * Prunes instant apps and state associated with uninstalled
312 * instant apps according to the current platform policy.
313 */
314 public abstract void pruneInstantApps();
315
316 /**
Svetoslav Ganove080da92016-12-21 17:10:35 -0800317 * @return The SetupWizard package name.
318 */
319 public abstract String getSetupWizardPackageName();
Suprabh Shuklaaef25132017-01-23 18:09:03 -0800320
321 public interface ExternalSourcesPolicy {
322
323 int USER_TRUSTED = 0; // User has trusted the package to install apps
324 int USER_BLOCKED = 1; // User has blocked the package to install apps
325 int USER_DEFAULT = 2; // Default code to use when user response is unavailable
326
327 /**
328 * Checks the user preference for whether a package is trusted to request installs through
329 * package installer
330 *
331 * @param packageName The package to check for
332 * @param uid the uid in which the package is running
333 * @return {@link USER_TRUSTED} if the user has trusted the package, {@link USER_BLOCKED}
334 * if user has blocked requests from the package, {@link USER_DEFAULT} if the user response
335 * is not yet available
336 */
337 int getPackageTrustedToInstallApps(String packageName, int uid);
338 }
339
340 public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy);
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +0100341
342 /**
Dianne Hackbornb1e77762017-02-13 11:42:18 -0800343 * Return true if the given package is a persistent app process.
344 */
345 public abstract boolean isPackagePersistent(String packageName);
346
347 /**
Todd Kennedyc29b11a2017-10-23 15:55:59 -0700348 * Returns whether or not the given package represents a legacy system application released
349 * prior to runtime permissions.
350 */
351 public abstract boolean isLegacySystemApp(PackageParser.Package pkg);
352
353 /**
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +0100354 * Get all overlay packages for a user.
355 * @param userId The user for which to get the overlays.
356 * @return A list of overlay packages. An empty list is returned if the
357 * user has no installed overlay packages.
358 */
359 public abstract List<PackageInfo> getOverlayPackages(int userId);
360
361 /**
362 * Get the names of all target packages for a user.
363 * @param userId The user for which to get the package names.
364 * @return A list of target package names. This list includes the "android" package.
365 */
366 public abstract List<String> getTargetPackageNames(int userId);
367
368 /**
369 * Set which overlay to use for a package.
370 * @param userId The user for which to update the overlays.
371 * @param targetPackageName The package name of the package for which to update the overlays.
372 * @param overlayPackageNames The complete list of overlay packages that should be enabled for
373 * the target. Previously enabled overlays not specified in the list
374 * will be disabled. Pass in null or an empty list to disable
375 * all overlays. The order of the items is significant if several
376 * overlays modify the same resource.
377 * @return true if all packages names were known by the package manager, false otherwise
378 */
379 public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName,
380 List<String> overlayPackageNames);
Todd Kennedy4d1de7d2017-02-23 10:32:18 -0800381
382 /**
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700383 * Resolves an activity intent, allowing instant apps to be resolved.
Todd Kennedy4d1de7d2017-02-23 10:32:18 -0800384 */
385 public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
Todd Kennedy82b08422017-09-28 13:32:05 -0700386 int flags, int userId, boolean resolveForStart);
Chad Brubaker0f28a802017-03-29 14:05:52 -0700387
388 /**
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700389 * Resolves a service intent, allowing instant apps to be resolved.
390 */
Todd Kennedy82b08422017-09-28 13:32:05 -0700391 public abstract ResolveInfo resolveService(Intent intent, String resolvedType,
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700392 int flags, int userId, int callingUid);
393
Todd Kennedy82b08422017-09-28 13:32:05 -0700394 /**
395 * Resolves a content provider intent.
396 */
397 public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId);
398
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700399 /**
Chad Brubaker0f28a802017-03-29 14:05:52 -0700400 * Track the creator of a new isolated uid.
401 * @param isolatedUid The newly created isolated uid.
402 * @param ownerUid The uid of the app that created the isolated process.
403 */
404 public abstract void addIsolatedUid(int isolatedUid, int ownerUid);
405
406 /**
407 * Track removal of an isolated uid.
408 * @param isolatedUid isolated uid that is no longer being used.
409 */
410 public abstract void removeIsolatedUid(int isolatedUid);
Makoto Onukie92f7942017-04-26 14:38:18 -0700411
412 /**
413 * Return the taget SDK version for the app with the given UID.
414 */
415 public abstract int getUidTargetSdkVersion(int uid);
Makoto Onukiad623012017-05-15 09:29:34 -0700416
417 /** Whether the binder caller can access instant apps. */
Todd Kennedy3051caa2017-05-23 15:54:18 -0700418 public abstract boolean canAccessInstantApps(int callingUid, int userId);
Svet Ganovf935a702017-08-22 12:15:58 -0700419
420 /**
421 * Returns {@code true} if a given package has instant application meta-data.
422 * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc)
423 * associated with an instant app. It may be kept after the instant app has been uninstalled.
424 */
425 public abstract boolean hasInstantApplicationMetadata(String packageName, int userId);
Todd Kennedydf113c32017-08-31 16:10:29 -0700426
427 /**
428 * Updates a package last used time.
429 */
430 public abstract void notifyPackageUse(String packageName, int reason);
Todd Kennedy82b08422017-09-28 13:32:05 -0700431
432 /**
433 * Returns a package object for the given package name.
434 */
435 public abstract @Nullable PackageParser.Package getPackage(@NonNull String packageName);
436
437 /**
438 * Returns a package object for the disabled system package name.
439 */
440 public abstract @Nullable PackageParser.Package getDisabledPackage(@NonNull String packageName);
441
442 /**
443 * Returns whether or not the component is the resolver activity.
444 */
445 public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component);
446
447 /**
448 * Returns the package name for a known package.
449 */
450 public abstract @Nullable String getKnownPackageName(
451 @KnownPackage int knownPackage, int userId);
452
Todd Kennedy0eb97382017-10-03 16:57:22 -0700453 /**
454 * Returns whether the package is an instant app.
455 */
456 public abstract boolean isInstantApp(String packageName, int userId);
457
458 /**
459 * Returns whether the package is an instant app.
460 */
461 public abstract @Nullable String getInstantAppPackageName(int uid);
462
463 /**
464 * Returns whether or not access to the application should be filtered.
465 * <p>
466 * Access may be limited based upon whether the calling or target applications
467 * are instant applications.
468 *
469 * @see #canAccessInstantApps(int)
470 */
471 public abstract boolean filterAppAccess(
472 @Nullable PackageParser.Package pkg, int callingUid, int userId);
473
Todd Kennedy82b08422017-09-28 13:32:05 -0700474 /*
475 * NOTE: The following methods are temporary until permissions are extracted from
476 * the package manager into a component specifically for handling permissions.
477 */
Todd Kennedy82b08422017-09-28 13:32:05 -0700478 /** Returns the flags for the given permission. */
479 public abstract @Nullable int getPermissionFlagsTEMP(@NonNull String permName,
480 @NonNull String packageName, int userId);
481 /** Updates the flags for the given permission. */
482 public abstract void updatePermissionFlagsTEMP(@NonNull String permName,
483 @NonNull String packageName, int flagMask, int flagValues, int userId);
Svet Ganovadc1cf42015-06-15 16:36:24 -0700484}