blob: cfe35b06115168d7b28d06ee4428cce572a4ca4a [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;
Ricky Waicf134eb2018-10-10 09:26:32 +010022import android.annotation.UserIdInt;
Makoto Onuki2d5b4652016-03-11 16:09:54 -080023import android.content.ComponentName;
Todd Kennedy01ad0c72016-11-11 15:33:12 -080024import android.content.Intent;
Todd Kennedy18211fd2017-06-06 09:15:46 -070025import android.content.pm.PackageManager.ApplicationInfoFlags;
26import android.content.pm.PackageManager.ComponentInfoFlags;
Todd Kennedy18211fd2017-06-06 09:15:46 -070027import android.content.pm.PackageManager.PackageInfoFlags;
28import android.content.pm.PackageManager.ResolveInfoFlags;
Chad Brubaker06068612017-04-06 09:43:47 -070029import android.os.Bundle;
Suprabh Shukla19b41f32018-03-26 22:35:13 -070030import android.os.PersistableBundle;
Eugene Suslaabdefba2018-11-09 18:06:43 -080031import android.util.ArraySet;
Makoto Onukic29f62c2016-06-07 12:19:46 -070032import android.util.SparseArray;
Todd Kennedy39bfee52016-02-24 10:28:21 -080033
Svet Ganovd873ae62018-06-25 16:39:23 -070034import com.android.internal.util.function.TriFunction;
35
Jeff Sharkey5790af02018-08-13 17:42:54 -060036import java.io.IOException;
Todd Kennedy82b08422017-09-28 13:32:05 -070037import java.lang.annotation.Retention;
38import java.lang.annotation.RetentionPolicy;
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -080039import java.util.List;
Svet Ganovd873ae62018-06-25 16:39:23 -070040import java.util.function.BiFunction;
Eugene Suslaabdefba2018-11-09 18:06:43 -080041import java.util.function.Consumer;
Svet Ganovadc1cf42015-06-15 16:36:24 -070042
43/**
44 * Package manager local system service interface.
45 *
46 * @hide Only for use within the system server.
47 */
48public abstract class PackageManagerInternal {
Todd Kennedy82b08422017-09-28 13:32:05 -070049 public static final int PACKAGE_SYSTEM = 0;
50 public static final int PACKAGE_SETUP_WIZARD = 1;
51 public static final int PACKAGE_INSTALLER = 2;
52 public static final int PACKAGE_VERIFIER = 3;
53 public static final int PACKAGE_BROWSER = 4;
Makoto Onuki700feef2018-02-15 10:59:41 -080054 public static final int PACKAGE_SYSTEM_TEXT_CLASSIFIER = 5;
Philip P. Moltmann8943ad62018-07-25 12:12:30 -070055 public static final int PACKAGE_PERMISSION_CONTROLLER = 6;
Varun Shah5f303652018-11-16 18:11:19 -080056 public static final int PACKAGE_WELLBEING = 7;
Jeff Sharkey15707b32018-12-10 12:08:41 -070057 public static final int PACKAGE_DOCUMENTER = 8;
Stanislav Zholnin596437f2018-12-28 15:34:23 +000058 public static final int PACKAGE_CONFIGURATOR = 9;
Joe Onorato5a15b552018-12-18 10:40:04 -080059 public static final int PACKAGE_INCIDENT_REPORT_APPROVER = 10;
George Hodulikcd7695d2019-01-29 18:17:05 -080060 public static final int PACKAGE_APP_PREDICTOR = 11;
Todd Kennedy82b08422017-09-28 13:32:05 -070061 @IntDef(value = {
62 PACKAGE_SYSTEM,
63 PACKAGE_SETUP_WIZARD,
64 PACKAGE_INSTALLER,
65 PACKAGE_VERIFIER,
66 PACKAGE_BROWSER,
Makoto Onuki700feef2018-02-15 10:59:41 -080067 PACKAGE_SYSTEM_TEXT_CLASSIFIER,
Philip P. Moltmann8943ad62018-07-25 12:12:30 -070068 PACKAGE_PERMISSION_CONTROLLER,
Varun Shah5f303652018-11-16 18:11:19 -080069 PACKAGE_WELLBEING,
Jeff Sharkey15707b32018-12-10 12:08:41 -070070 PACKAGE_DOCUMENTER,
Stanislav Zholnin596437f2018-12-28 15:34:23 +000071 PACKAGE_CONFIGURATOR,
Joe Onorato5a15b552018-12-18 10:40:04 -080072 PACKAGE_INCIDENT_REPORT_APPROVER,
George Hodulikcd7695d2019-01-29 18:17:05 -080073 PACKAGE_APP_PREDICTOR,
Todd Kennedy82b08422017-09-28 13:32:05 -070074 })
75 @Retention(RetentionPolicy.SOURCE)
76 public @interface KnownPackage {}
Svet Ganovadc1cf42015-06-15 16:36:24 -070077
Todd Kennedy42d61602017-12-12 14:44:19 -080078 /** Observer called whenever the list of packages changes */
79 public interface PackageListObserver {
80 /** A package was added to the system. */
81 void onPackageAdded(@NonNull String packageName);
82 /** A package was removed from the system. */
83 void onPackageRemoved(@NonNull String packageName);
84 }
85
Svet Ganovd873ae62018-06-25 16:39:23 -070086 /** Interface to override permission checks via composition */
87 public interface CheckPermissionDelegate {
88 /**
89 * Allows overriding check permission behavior.
90 *
91 * @param permName The permission to check.
92 * @param pkgName The package for which to check.
93 * @param userId The user for which to check.
94 * @param superImpl The super implementation.
95 * @return The check permission result.
96 */
97 int checkPermission(String permName, String pkgName, int userId,
98 TriFunction<String, String, Integer, Integer> superImpl);
99
100 /**
101 * Allows overriding check UID permission behavior.
102 *
103 * @param permName The permission to check.
104 * @param uid The UID for which to check.
105 * @param superImpl The super implementation.
106 * @return The check permission result.
107 */
108 int checkUidPermission(String permName, int uid,
109 BiFunction<String, Integer, Integer> superImpl);
110 }
111
Svet Ganovadc1cf42015-06-15 16:36:24 -0700112 /**
113 * Provider for package names.
114 */
115 public interface PackagesProvider {
116
117 /**
118 * Gets the packages for a given user.
119 * @param userId The user id.
120 * @return The package names.
121 */
122 public String[] getPackages(int userId);
123 }
124
125 /**
Svetoslav0010b702015-06-30 18:05:26 -0700126 * Provider for package names.
127 */
128 public interface SyncAdapterPackagesProvider {
129
130 /**
131 * Gets the sync adapter packages for given authority and user.
132 * @param authority The authority.
133 * @param userId The user id.
134 * @return The package names.
135 */
136 public String[] getPackages(String authority, int userId);
137 }
138
139 /**
Hai Zhang85fd0622019-02-01 14:06:04 -0800140 * Provider for default browser
141 */
142 public interface DefaultBrowserProvider {
143
144 /**
145 * Get the package name of the default browser.
146 *
147 * @param userId the user id
148 *
149 * @return the package name of the default browser, or {@code null} if none
150 */
151 @Nullable
152 String getDefaultBrowser(@UserIdInt int userId);
153
154 /**
155 * Set the package name of the default browser.
156 *
157 * @param packageName package name of the default browser, or {@code null} to remove
158 * @param userId the user id
159 *
160 * @return whether the default browser was successfully set.
161 */
162 boolean setDefaultBrowser(@Nullable String packageName, @UserIdInt int userId);
163 }
164
165 /**
Svet Ganovadc1cf42015-06-15 16:36:24 -0700166 * Sets the location provider packages provider.
167 * @param provider The packages provider.
168 */
169 public abstract void setLocationPackagesProvider(PackagesProvider provider);
170
171 /**
Wei Wangffb94e62019-01-14 00:05:45 -0800172 * Set the location extra packages provider.
173 * @param provider The packages provider.
174 */
175 public abstract void setLocationExtraPackagesProvider(PackagesProvider provider);
176
177 /**
Svet Ganovadc1cf42015-06-15 16:36:24 -0700178 * Sets the voice interaction packages provider.
179 * @param provider The packages provider.
180 */
181 public abstract void setVoiceInteractionPackagesProvider(PackagesProvider provider);
Svetoslavcdfd2302015-06-25 19:07:31 -0700182
183 /**
Eric Enslen1e423b92017-12-18 11:30:21 -0800184 * Sets the Use Open Wifi packages provider.
185 * @param provider The packages provider.
186 */
187 public abstract void setUseOpenWifiAppPackagesProvider(PackagesProvider provider);
188
189 /**
Svetoslav0010b702015-06-30 18:05:26 -0700190 * Sets the sync adapter packages provider.
191 * @param provider The provider.
192 */
193 public abstract void setSyncAdapterPackagesprovider(SyncAdapterPackagesProvider provider);
194
195 /**
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000196 * Called when the package for the default dialer changed
197 *
198 * @param packageName the new dialer package
199 * @param userId user for which the change was made
Svetoslavcdfd2302015-06-25 19:07:31 -0700200 */
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000201 public void onDefaultDialerAppChanged(String packageName, int userId) {}
Svetoslavcdfd2302015-06-25 19:07:31 -0700202
203 /**
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000204 * Called when the package for the default SMS handler changed
205 *
206 * @param packageName the new sms package
207 * @param userId user for which the change was made
Svetoslavcdfd2302015-06-25 19:07:31 -0700208 */
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000209 public void onDefaultSmsAppChanged(String packageName, int userId) {}
Sailesh Nepalcf855622015-07-28 19:22:14 -0700210
211 /**
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000212 * Called when the package for the default sim call manager changed
213 *
214 * @param packageName the new sms package
215 * @param userId user for which the change was made
Sailesh Nepalcf855622015-07-28 19:22:14 -0700216 */
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000217 public void onDefaultSimCallManagerAppChanged(String packageName, int userId) {}
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -0800218
219 /**
Eric Enslen1e423b92017-12-18 11:30:21 -0800220 * Requests granting of the default permissions to the current default Use Open Wifi app.
221 * @param packageName The default use open wifi package name.
222 * @param userId The user for which to grant the permissions.
223 */
224 public abstract void grantDefaultPermissionsToDefaultUseOpenWifiApp(String packageName,
225 int userId);
226
227 /**
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -0800228 * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has
229 * currently installed it. The apps are not preloaded.
230 * @param packageList List of package names to keep cached.
231 */
232 public abstract void setKeepUninstalledPackages(List<String> packageList);
Svet Ganov9c165d72015-12-01 19:52:26 -0800233
234 /**
235 * Gets whether some of the permissions used by this package require a user
236 * review before any of the app components can run.
237 * @param packageName The package name for which to check.
238 * @param userId The user under which to check.
239 * @return True a permissions review is required.
240 */
241 public abstract boolean isPermissionsReviewRequired(String packageName, int userId);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800242
243 /**
Todd Kennedy18211fd2017-06-06 09:15:46 -0700244 * Retrieve all of the information we know about a particular package/application.
245 * @param filterCallingUid The results will be filtered in the context of this UID instead
246 * of the calling UID.
247 * @see PackageManager#getPackageInfo(String, int)
Todd Kennedy39bfee52016-02-24 10:28:21 -0800248 */
Todd Kennedy18211fd2017-06-06 09:15:46 -0700249 public abstract PackageInfo getPackageInfo(String packageName,
250 @PackageInfoFlags int flags, int filterCallingUid, int userId);
251
252 /**
Ricky Waicf134eb2018-10-10 09:26:32 +0100253 * Return a List of all application packages that are installed on the
254 * device, for a specific user. If flag GET_UNINSTALLED_PACKAGES has been
255 * set, a list of all applications including those deleted with
256 * {@code DONT_DELETE_DATA} (partially installed apps with data directory)
257 * will be returned.
258 *
259 * @param flags Additional option flags to modify the data returned.
260 * @param userId The user for whom the installed applications are to be
261 * listed
262 * @param callingUid The uid of the original caller app
263 * @return A List of ApplicationInfo objects, one for each installed
264 * application. In the unlikely case there are no installed
265 * packages, an empty list is returned. If flag
266 * {@code MATCH_UNINSTALLED_PACKAGES} is set, the application
267 * information is retrieved from the list of uninstalled
268 * applications (which includes installed applications as well as
269 * applications with data directory i.e. applications which had been
270 * deleted with {@code DONT_DELETE_DATA} flag set).
271 */
272 public abstract List<ApplicationInfo> getInstalledApplications(
273 @ApplicationInfoFlags int flags, @UserIdInt int userId, int callingUid);
274
275 /**
Suprabh Shukla19b41f32018-03-26 22:35:13 -0700276 * Retrieve launcher extras for a suspended package provided to the system in
277 * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700278 * PersistableBundle, String)}.
Suprabh Shukla19b41f32018-03-26 22:35:13 -0700279 *
280 * @param packageName The package for which to return launcher extras.
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700281 * @param userId The user for which to check.
Suprabh Shukla19b41f32018-03-26 22:35:13 -0700282 * @return The launcher extras.
283 *
284 * @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
285 * PersistableBundle, String)
286 * @see PackageManager#isPackageSuspended()
287 */
288 public abstract Bundle getSuspendedPackageLauncherExtras(String packageName,
289 int userId);
290
291 /**
Suprabh Shukla69c71422018-04-02 18:39:01 -0700292 * Internal api to query the suspended state of a package.
293 * @param packageName The package to check.
294 * @param userId The user id to check for.
295 * @return {@code true} if the package is suspended, {@code false} otherwise.
296 * @see PackageManager#isPackageSuspended(String)
297 */
298 public abstract boolean isPackageSuspended(String packageName, int userId);
299
300 /**
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700301 * Get the name of the package that suspended the given package. Packages can be suspended by
302 * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or
303 * {@link android.Manifest.permission#SUSPEND_APPS}.
304 *
305 * @param suspendedPackage The package that has been suspended.
306 * @param userId The user for which to check.
307 * @return Name of the package that suspended the given package. Returns {@code null} if the
308 * given package is not currently suspended and the platform package name - i.e.
309 * {@code "android"} - if the package was suspended by a device admin.
310 */
311 public abstract String getSuspendingPackage(String suspendedPackage, int userId);
312
313 /**
Suprabh Shukla389cb6f2018-10-01 18:20:39 -0700314 * Get the information describing the dialog to be shown to the user when they try to launch a
315 * suspended application.
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700316 *
317 * @param suspendedPackage The package that has been suspended.
318 * @param userId The user for which to check.
Suprabh Shukla389cb6f2018-10-01 18:20:39 -0700319 * @return A {@link SuspendDialogInfo} object describing the dialog to be shown.
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700320 */
Suprabh Shukla389cb6f2018-10-01 18:20:39 -0700321 @Nullable
322 public abstract SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage, int userId);
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700323
324 /**
Suprabh Shukla79000492018-12-24 17:03:02 -0800325 * Gets any distraction flags set via
326 * {@link PackageManager#setDistractingPackageRestrictions(String[], int)}
327 *
328 * @param packageName
329 * @param userId
330 * @return A bitwise OR of any of the {@link PackageManager.DistractionRestriction}
331 */
332 public abstract @PackageManager.DistractionRestriction int getDistractingPackageRestrictions(
333 String packageName, int userId);
334
335 /**
Christopher Tatea732f012017-10-26 17:26:53 -0700336 * Do a straight uid lookup for the given package/application in the given user.
337 * @see PackageManager#getPackageUidAsUser(String, int, int)
338 * @return The app's uid, or < 0 if the package was not found in that user
339 */
340 public abstract int getPackageUid(String packageName,
341 @PackageInfoFlags int flags, int userId);
342
343 /**
Todd Kennedy18211fd2017-06-06 09:15:46 -0700344 * Retrieve all of the information we know about a particular package/application.
345 * @param filterCallingUid The results will be filtered in the context of this UID instead
346 * of the calling UID.
347 * @see PackageManager#getApplicationInfo(String, int)
348 */
349 public abstract ApplicationInfo getApplicationInfo(String packageName,
350 @ApplicationInfoFlags int flags, int filterCallingUid, int userId);
351
352 /**
353 * Retrieve all of the information we know about a particular activity class.
354 * @param filterCallingUid The results will be filtered in the context of this UID instead
355 * of the calling UID.
356 * @see PackageManager#getActivityInfo(ComponentName, int)
357 */
358 public abstract ActivityInfo getActivityInfo(ComponentName component,
359 @ComponentInfoFlags int flags, int filterCallingUid, int userId);
360
361 /**
362 * Retrieve all activities that can be performed for the given intent.
363 * @param filterCallingUid The results will be filtered in the context of this UID instead
364 * of the calling UID.
365 * @see PackageManager#queryIntentActivities(Intent, int)
366 */
367 public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
368 @ResolveInfoFlags int flags, int filterCallingUid, int userId);
Makoto Onuki2d5b4652016-03-11 16:09:54 -0800369
370 /**
Todd Kennedy82b08422017-09-28 13:32:05 -0700371 * Retrieve all services that can be performed for the given intent.
372 * @see PackageManager#queryIntentServices(Intent, int)
373 */
374 public abstract List<ResolveInfo> queryIntentServices(
375 Intent intent, int flags, int callingUid, int userId);
376
377 /**
Makoto Onuki2d5b4652016-03-11 16:09:54 -0800378 * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}.
379 */
380 public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates,
381 int userId);
Makoto Onukic29f62c2016-06-07 12:19:46 -0700382
383 /**
Winson Chungc1674272018-02-21 10:15:17 -0800384 * @return The default home activity component name.
385 */
386 public abstract ComponentName getDefaultHomeActivity(int userId);
387
388 /**
Makoto Onukic29f62c2016-06-07 12:19:46 -0700389 * Called by DeviceOwnerManagerService to set the package names of device owner and profile
390 * owners.
391 */
392 public abstract void setDeviceAndProfileOwnerPackages(
393 int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners);
394
395 /**
Steven Ng9d48a732016-06-24 19:04:14 +0100396 * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}.
Makoto Onukic29f62c2016-06-07 12:19:46 -0700397 */
Steven Ng9d48a732016-06-24 19:04:14 +0100398 public abstract boolean isPackageDataProtected(int userId, String packageName);
Svet Ganov973edd192016-09-08 20:15:55 -0700399
400 /**
Benjamin Franzf81bf7f2018-03-26 16:23:04 +0100401 * Returns {@code true} if a given package's state is protected, e.g. it cannot be force
402 * stopped, suspended, disabled or hidden. Otherwise, returns {@code false}.
403 */
404 public abstract boolean isPackageStateProtected(String packageName, int userId);
405
406 /**
Dianne Hackborne07641d2016-11-09 15:07:23 -0800407 * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns
408 * {@code false}.
409 */
410 public abstract boolean isPackageEphemeral(int userId, String packageName);
411
412 /**
Svet Ganov973edd192016-09-08 20:15:55 -0700413 * Gets whether the package was ever launched.
414 * @param packageName The package name.
415 * @param userId The user for which to check.
416 * @return Whether was launched.
Amith Yamasani2cbfa1e2017-03-28 10:34:01 -0700417 * @throws IllegalArgumentException if the package is not found
Svet Ganov973edd192016-09-08 20:15:55 -0700418 */
419 public abstract boolean wasPackageEverLaunched(String packageName, int userId);
Nicolas Prevot700e1e72016-09-28 15:17:18 +0100420
421 /**
422 * Grants a runtime permission
423 * @param packageName The package name.
424 * @param name The name of the permission.
425 * @param userId The userId for which to grant the permission.
426 * @param overridePolicy If true, grant this permission even if it is fixed by policy.
427 */
428 public abstract void grantRuntimePermission(String packageName, String name, int userId,
429 boolean overridePolicy);
430
431 /**
432 * Revokes a runtime permission
433 * @param packageName The package name.
434 * @param name The name of the permission.
435 * @param userId The userId for which to revoke the permission.
436 * @param overridePolicy If true, revoke this permission even if it is fixed by policy.
437 */
438 public abstract void revokeRuntimePermission(String packageName, String name, int userId,
439 boolean overridePolicy);
440
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100441 /**
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000442 * Retrieve the official name associated with a uid. This name is
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100443 * guaranteed to never change, though it is possible for the underlying
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000444 * uid to be changed. That is, if you are storing information about
445 * uids in persistent storage, you should use the string returned
446 * by this function instead of the raw uid.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100447 *
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000448 * @param uid The uid for which you would like to retrieve a name.
449 * @return Returns a unique name for the given uid, or null if the
450 * uid is not currently assigned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100451 */
452 public abstract String getNameForUid(int uid);
453
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800454 /**
455 * Request to perform the second phase of ephemeral resolution.
456 * @param responseObj The response of the first phase of ephemeral resolution
457 * @param origIntent The original intent that triggered ephemeral resolution
458 * @param resolvedType The resolved type of the intent
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800459 * @param callingPackage The name of the package requesting the ephemeral application
Chad Brubaker06068612017-04-06 09:43:47 -0700460 * @param verificationBundle Optional bundle to pass to the installer for additional
461 * verification
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800462 * @param userId The ID of the user that triggered ephemeral resolution
463 */
Todd Kennedye9910222017-02-21 16:00:11 -0800464 public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj,
465 Intent origIntent, String resolvedType, String callingPackage,
Chad Brubaker06068612017-04-06 09:43:47 -0700466 Bundle verificationBundle, int userId);
Svetoslav Ganove080da92016-12-21 17:10:35 -0800467
468 /**
Todd Kennedy0e989d02017-01-13 14:15:36 -0800469 * Grants access to the package metadata for an ephemeral application.
470 * <p>
471 * When an ephemeral application explicitly tries to interact with a full
472 * install application [via an activity, service or provider that has been
473 * exposed using the {@code visibleToInstantApp} attribute], the normal
474 * application must be able to see metadata about the connecting ephemeral
475 * app. If the ephemeral application uses an implicit intent [ie action VIEW,
476 * category BROWSABLE], it remains hidden from the launched activity.
477 * <p>
478 * If the {@code sourceUid} is not for an ephemeral app or {@code targetUid}
479 * is not for a fully installed app, this method will be a no-op.
480 *
481 * @param userId the user
482 * @param intent the intent that triggered the grant
483 * @param targetAppId The app ID of the fully installed application
484 * @param ephemeralAppId The app ID of the ephemeral application
485 */
486 public abstract void grantEphemeralAccess(int userId, Intent intent,
487 int targetAppId, int ephemeralAppId);
488
Todd Kennedyb21be122017-03-24 14:10:01 -0700489 public abstract boolean isInstantAppInstallerComponent(ComponentName component);
Todd Kennedy0e989d02017-01-13 14:15:36 -0800490 /**
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800491 * Prunes instant apps and state associated with uninstalled
492 * instant apps according to the current platform policy.
493 */
494 public abstract void pruneInstantApps();
495
496 /**
Svetoslav Ganove080da92016-12-21 17:10:35 -0800497 * @return The SetupWizard package name.
498 */
499 public abstract String getSetupWizardPackageName();
Suprabh Shuklaaef25132017-01-23 18:09:03 -0800500
501 public interface ExternalSourcesPolicy {
502
503 int USER_TRUSTED = 0; // User has trusted the package to install apps
504 int USER_BLOCKED = 1; // User has blocked the package to install apps
505 int USER_DEFAULT = 2; // Default code to use when user response is unavailable
506
507 /**
508 * Checks the user preference for whether a package is trusted to request installs through
509 * package installer
510 *
511 * @param packageName The package to check for
512 * @param uid the uid in which the package is running
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000513 * @return {@link #USER_TRUSTED} if the user has trusted the package, {@link #USER_BLOCKED}
514 * if user has blocked requests from the package, {@link #USER_DEFAULT} if the user response
Suprabh Shuklaaef25132017-01-23 18:09:03 -0800515 * is not yet available
516 */
517 int getPackageTrustedToInstallApps(String packageName, int uid);
518 }
519
520 public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy);
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +0100521
522 /**
Dianne Hackbornb1e77762017-02-13 11:42:18 -0800523 * Return true if the given package is a persistent app process.
524 */
525 public abstract boolean isPackagePersistent(String packageName);
526
527 /**
Todd Kennedyc29b11a2017-10-23 15:55:59 -0700528 * Returns whether or not the given package represents a legacy system application released
529 * prior to runtime permissions.
530 */
531 public abstract boolean isLegacySystemApp(PackageParser.Package pkg);
532
533 /**
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +0100534 * Get all overlay packages for a user.
535 * @param userId The user for which to get the overlays.
536 * @return A list of overlay packages. An empty list is returned if the
537 * user has no installed overlay packages.
538 */
539 public abstract List<PackageInfo> getOverlayPackages(int userId);
540
541 /**
542 * Get the names of all target packages for a user.
543 * @param userId The user for which to get the package names.
544 * @return A list of target package names. This list includes the "android" package.
545 */
546 public abstract List<String> getTargetPackageNames(int userId);
547
548 /**
549 * Set which overlay to use for a package.
550 * @param userId The user for which to update the overlays.
551 * @param targetPackageName The package name of the package for which to update the overlays.
552 * @param overlayPackageNames The complete list of overlay packages that should be enabled for
553 * the target. Previously enabled overlays not specified in the list
554 * will be disabled. Pass in null or an empty list to disable
555 * all overlays. The order of the items is significant if several
556 * overlays modify the same resource.
557 * @return true if all packages names were known by the package manager, false otherwise
558 */
559 public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName,
560 List<String> overlayPackageNames);
Todd Kennedy4d1de7d2017-02-23 10:32:18 -0800561
562 /**
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700563 * Resolves an activity intent, allowing instant apps to be resolved.
Todd Kennedy4d1de7d2017-02-23 10:32:18 -0800564 */
565 public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
Patrick Baumann78380272018-04-04 10:41:01 -0700566 int flags, int userId, boolean resolveForStart, int filterCallingUid);
Chad Brubaker0f28a802017-03-29 14:05:52 -0700567
568 /**
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700569 * Resolves a service intent, allowing instant apps to be resolved.
570 */
Todd Kennedy82b08422017-09-28 13:32:05 -0700571 public abstract ResolveInfo resolveService(Intent intent, String resolvedType,
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700572 int flags, int userId, int callingUid);
573
Todd Kennedy82b08422017-09-28 13:32:05 -0700574 /**
575 * Resolves a content provider intent.
576 */
577 public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId);
578
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700579 /**
Chad Brubaker0f28a802017-03-29 14:05:52 -0700580 * Track the creator of a new isolated uid.
581 * @param isolatedUid The newly created isolated uid.
582 * @param ownerUid The uid of the app that created the isolated process.
583 */
584 public abstract void addIsolatedUid(int isolatedUid, int ownerUid);
585
586 /**
587 * Track removal of an isolated uid.
588 * @param isolatedUid isolated uid that is no longer being used.
589 */
590 public abstract void removeIsolatedUid(int isolatedUid);
Makoto Onukie92f7942017-04-26 14:38:18 -0700591
592 /**
593 * Return the taget SDK version for the app with the given UID.
594 */
595 public abstract int getUidTargetSdkVersion(int uid);
Makoto Onukiad623012017-05-15 09:29:34 -0700596
Jeff Sharkey9252b342018-01-19 07:58:35 +0900597 /**
598 * Return the taget SDK version for the app with the given package name.
599 */
600 public abstract int getPackageTargetSdkVersion(String packageName);
601
Makoto Onukiad623012017-05-15 09:29:34 -0700602 /** Whether the binder caller can access instant apps. */
Todd Kennedy3051caa2017-05-23 15:54:18 -0700603 public abstract boolean canAccessInstantApps(int callingUid, int userId);
Svet Ganovf935a702017-08-22 12:15:58 -0700604
Todd Kennedy662504f2018-03-14 08:09:00 -0700605 /** Whether the binder caller can access the given component. */
606 public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId);
607
Svet Ganovf935a702017-08-22 12:15:58 -0700608 /**
609 * Returns {@code true} if a given package has instant application meta-data.
610 * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc)
611 * associated with an instant app. It may be kept after the instant app has been uninstalled.
612 */
613 public abstract boolean hasInstantApplicationMetadata(String packageName, int userId);
Todd Kennedydf113c32017-08-31 16:10:29 -0700614
615 /**
616 * Updates a package last used time.
617 */
618 public abstract void notifyPackageUse(String packageName, int reason);
Todd Kennedy82b08422017-09-28 13:32:05 -0700619
620 /**
621 * Returns a package object for the given package name.
622 */
623 public abstract @Nullable PackageParser.Package getPackage(@NonNull String packageName);
624
625 /**
Todd Kennedy42d61602017-12-12 14:44:19 -0800626 * Returns a list without a change observer.
627 *
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000628 * @see #getPackageList(PackageListObserver)
Todd Kennedy42d61602017-12-12 14:44:19 -0800629 */
630 public @NonNull PackageList getPackageList() {
631 return getPackageList(null);
632 }
633
634 /**
635 * Returns the list of packages installed at the time of the method call.
636 * <p>The given observer is notified when the list of installed packages
637 * changes [eg. a package was installed or uninstalled]. It will not be
638 * notified if a package is updated.
639 * <p>The package list will not be updated automatically as packages are
640 * installed / uninstalled. Any changes must be handled within the observer.
641 */
642 public abstract @NonNull PackageList getPackageList(@Nullable PackageListObserver observer);
643
644 /**
645 * Removes the observer.
646 * <p>Generally not needed. {@link #getPackageList(PackageListObserver)} will automatically
647 * remove the observer.
648 * <p>Does nothing if the observer isn't currently registered.
649 * <p>Observers are notified asynchronously and it's possible for an observer to be
650 * invoked after its been removed.
651 */
652 public abstract void removePackageListObserver(@NonNull PackageListObserver observer);
653
654 /**
Todd Kennedy82b08422017-09-28 13:32:05 -0700655 * Returns a package object for the disabled system package name.
656 */
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000657 public abstract @Nullable PackageParser.Package getDisabledSystemPackage(
658 @NonNull String packageName);
659
660 /**
661 * Returns the package name for the disabled system package.
662 *
663 * This is equivalent to
664 * {@link #getDisabledSystemPackage(String)}.{@link PackageParser.Package#packageName}
665 */
666 public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName);
Todd Kennedy82b08422017-09-28 13:32:05 -0700667
668 /**
669 * Returns whether or not the component is the resolver activity.
670 */
671 public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component);
672
673 /**
674 * Returns the package name for a known package.
675 */
676 public abstract @Nullable String getKnownPackageName(
677 @KnownPackage int knownPackage, int userId);
678
Todd Kennedy0eb97382017-10-03 16:57:22 -0700679 /**
680 * Returns whether the package is an instant app.
681 */
682 public abstract boolean isInstantApp(String packageName, int userId);
683
684 /**
685 * Returns whether the package is an instant app.
686 */
687 public abstract @Nullable String getInstantAppPackageName(int uid);
688
689 /**
690 * Returns whether or not access to the application should be filtered.
691 * <p>
692 * Access may be limited based upon whether the calling or target applications
693 * are instant applications.
694 *
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000695 * @see #canAccessInstantApps
Todd Kennedy0eb97382017-10-03 16:57:22 -0700696 */
697 public abstract boolean filterAppAccess(
698 @Nullable PackageParser.Package pkg, int callingUid, int userId);
699
Todd Kennedy82b08422017-09-28 13:32:05 -0700700 /*
701 * NOTE: The following methods are temporary until permissions are extracted from
702 * the package manager into a component specifically for handling permissions.
703 */
Todd Kennedy82b08422017-09-28 13:32:05 -0700704 /** Returns the flags for the given permission. */
705 public abstract @Nullable int getPermissionFlagsTEMP(@NonNull String permName,
706 @NonNull String packageName, int userId);
707 /** Updates the flags for the given permission. */
708 public abstract void updatePermissionFlagsTEMP(@NonNull String permName,
709 @NonNull String packageName, int flagMask, int flagValues, int userId);
Michal Karpinski528c3e52018-02-07 17:47:10 +0000710
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000711 /** Returns whether the given package was signed by the platform */
712 public abstract boolean isPlatformSigned(String pkg);
713
Michal Karpinski528c3e52018-02-07 17:47:10 +0000714 /**
715 * Returns true if it's still safe to restore data backed up from this app's version
716 * that was signed with restoringFromSigHash.
717 */
718 public abstract boolean isDataRestoreSafe(@NonNull byte[] restoringFromSigHash,
719 @NonNull String packageName);
720
721 /**
722 * Returns true if it's still safe to restore data backed up from this app's version
723 * that was signed with restoringFromSig.
724 */
725 public abstract boolean isDataRestoreSafe(@NonNull Signature restoringFromSig,
726 @NonNull String packageName);
Dan Cashman303c4bb2018-04-10 07:41:16 -0700727
Dan Cashman303c4bb2018-04-10 07:41:16 -0700728 /**
Todd Kennedycf827032018-07-03 13:17:22 -0700729 * Returns {@code true} if the the signing information for {@code clientUid} is sufficient
730 * to gain access gated by {@code capability}. This can happen if the two UIDs have the
731 * same signing information, if the signing information {@code clientUid} indicates that
732 * it has the signing certificate for {@code serverUid} in its signing history (if it was
733 * previously signed by it), or if the signing certificate for {@code clientUid} is in the
734 * signing history for {@code serverUid} and with the {@code capability} specified.
Dan Cashman303c4bb2018-04-10 07:41:16 -0700735 */
736 public abstract boolean hasSignatureCapability(int serverUid, int clientUid,
737 @PackageParser.SigningDetails.CertCapabilities int capability);
Svet Ganovd873ae62018-06-25 16:39:23 -0700738
739 /**
740 * Get the delegate to influence permission checking.
741 *
742 * @return The delegate instance or null to clear.
743 */
744 public abstract @Nullable CheckPermissionDelegate getCheckPermissionDelegate();
745
746 /**
747 * Set a delegate to influence permission checking.
748 *
749 * @param delegate A delegate instance or null to clear.
750 */
751 public abstract void setCheckPermissionDelegate(@Nullable CheckPermissionDelegate delegate);
Sudheer Shanka0a541a52018-07-31 13:21:11 -0700752
753 /**
754 * Get appIds of all available apps which specified android:sharedUserId in the manifest.
755 *
756 * @return a SparseArray mapping from appId to it's sharedUserId.
757 */
758 public abstract SparseArray<String> getAppsWithSharedUserIds();
Jeff Sharkey5790af02018-08-13 17:42:54 -0600759
760 /**
Sudheer Shanka2ac25a92018-10-25 10:59:32 -0700761 * Get the value of attribute android:sharedUserId for the given packageName if specified,
762 * otherwise {@code null}.
763 */
764 public abstract String getSharedUserIdForPackage(@NonNull String packageName);
765
766 /**
767 * Get all packages which specified the given sharedUserId as android:sharedUserId attribute
768 * or an empty array if no package specified it.
769 */
770 public abstract String[] getPackagesForSharedUserId(@NonNull String sharedUserId, int userId);
771
772 /**
Jeff Sharkey5790af02018-08-13 17:42:54 -0600773 * Return if device is currently in a "core" boot environment, typically
774 * used to support full-disk encryption. Only apps marked with
775 * {@code coreApp} attribute are available.
776 */
777 public abstract boolean isOnlyCoreApps();
778
779 /**
780 * Make a best-effort attempt to provide the requested free disk space by
781 * deleting cached files.
782 *
783 * @throws IOException if the request was unable to be fulfilled.
784 */
785 public abstract void freeStorage(String volumeUuid, long bytes, int storageFlags)
786 throws IOException;
Todd Kennedycf827032018-07-03 13:17:22 -0700787
788 /** Returns {@code true} if the specified component is enabled and matches the given flags. */
789 public abstract boolean isEnabledAndMatches(@NonNull ComponentInfo info, int flags, int userId);
790
791 /** Returns {@code true} if the given user requires extra badging for icons. */
792 public abstract boolean userNeedsBadging(int userId);
Eugene Suslaabdefba2018-11-09 18:06:43 -0800793
794 /**
795 * Perform the given action for each package.
796 * Note that packages lock will be held while performin the actions.
797 *
798 * @param actionLocked action to be performed
799 */
800 public abstract void forEachPackage(Consumer<PackageParser.Package> actionLocked);
801
802 /** Returns the list of enabled components */
803 public abstract ArraySet<String> getEnabledComponents(String packageName, int userId);
804
805 /** Returns the list of disabled components */
806 public abstract ArraySet<String> getDisabledComponents(String packageName, int userId);
807
808 /** Returns whether the given package is enabled for the given user */
809 public abstract @PackageManager.EnabledState int getApplicationEnabledState(
810 String packageName, int userId);
Richard Uhlerb29f1452018-09-12 16:38:15 +0100811
812 /**
813 * Extra field name for the token of a request to enable rollback for a
814 * package.
815 */
816 public static final String EXTRA_ENABLE_ROLLBACK_TOKEN =
817 "android.content.pm.extra.ENABLE_ROLLBACK_TOKEN";
818
819 /**
820 * Extra field name for the installFlags of a request to enable rollback
821 * for a package.
822 */
823 public static final String EXTRA_ENABLE_ROLLBACK_INSTALL_FLAGS =
824 "android.content.pm.extra.ENABLE_ROLLBACK_INSTALL_FLAGS";
825
826 /**
Narayan Kamath869f7062019-01-10 12:24:15 +0000827 * Extra field name for the set of installed users for a given rollback package.
828 */
829 public static final String EXTRA_ENABLE_ROLLBACK_INSTALLED_USERS =
830 "android.content.pm.extra.ENABLE_ROLLBACK_INSTALLED_USERS";
831
832 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +0100833 * Used as the {@code enableRollbackCode} argument for
834 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that
835 * enabling rollback succeeded.
836 */
837 public static final int ENABLE_ROLLBACK_SUCCEEDED = 1;
838
839 /**
840 * Used as the {@code enableRollbackCode} argument for
841 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that
842 * enabling rollback failed.
843 */
844 public static final int ENABLE_ROLLBACK_FAILED = -1;
845
846 /**
847 * Allows the rollback manager listening to the
848 * {@link Intent#ACTION_PACKAGE_ENABLE_ROLLBACK enable rollback broadcast}
849 * to respond to the package manager. The response must include the
850 * {@code enableRollbackCode} which is one of
851 * {@link PackageManager#ENABLE_ROLLBACK_SUCCEEDED} or
852 * {@link PackageManager#ENABLE_ROLLBACK_FAILED}.
853 *
854 * @param token pending package identifier as passed via the
855 * {@link PackageManager#EXTRA_ENABLE_ROLLBACK_TOKEN} Intent extra.
856 * @param enableRollbackCode the status code result of enabling rollback
857 * @throws SecurityException if the caller does not have the
858 * PACKAGE_ROLLBACK_AGENT permission.
859 */
860 public abstract void setEnableRollbackCode(int token, int enableRollbackCode);
Eric Holka1485f62019-01-07 13:58:25 -0800861
862 /**
863 * Ask the package manager to compile layouts in the given package.
864 */
865 public abstract boolean compileLayouts(String packageName);
Narayan Kamath869f7062019-01-10 12:24:15 +0000866
867 /*
868 * Inform the package manager that the pending package install identified by
869 * {@code token} can be completed.
870 */
871 public abstract void finishPackageInstall(int token, boolean didLaunch);
Hai Zhanga22cd832019-01-30 13:38:43 -0800872
873 /**
874 * Remove the default browser stored in the legacy package settings.
875 *
876 * @param userId the user id
877 *
878 * @return the package name of the default browser, or {@code null} if none
879 */
880 @Nullable
881 public abstract String removeLegacyDefaultBrowserPackageName(int userId);
Hai Zhang85fd0622019-02-01 14:06:04 -0800882
883 /**
884 * Sets the default browser provider.
885 *
886 * @param provider the provider
887 */
888 public abstract void setDefaultBrowserProvider(@NonNull DefaultBrowserProvider provider);
Svet Ganovadc1cf42015-06-15 16:36:24 -0700889}