blob: 21f5f899e75c72e664dd58ddfff58635356b588f [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
Patrick Baumannde37e432019-08-28 09:51:29 -070019import android.annotation.AppIdInt;
Todd Kennedy82b08422017-09-28 13:32:05 -070020import android.annotation.IntDef;
21import android.annotation.NonNull;
22import android.annotation.Nullable;
Ricky Waicf134eb2018-10-10 09:26:32 +010023import android.annotation.UserIdInt;
Makoto Onuki2d5b4652016-03-11 16:09:54 -080024import android.content.ComponentName;
Patrick Baumann182ea1c2019-11-18 13:43:11 -080025import android.content.ContentResolver;
Todd Kennedy01ad0c72016-11-11 15:33:12 -080026import android.content.Intent;
Nikita Ioffef012a222019-03-05 22:37:55 +000027import android.content.IntentSender;
Todd Kennedy18211fd2017-06-06 09:15:46 -070028import android.content.pm.PackageManager.ApplicationInfoFlags;
29import android.content.pm.PackageManager.ComponentInfoFlags;
Todd Kennedy18211fd2017-06-06 09:15:46 -070030import android.content.pm.PackageManager.PackageInfoFlags;
31import android.content.pm.PackageManager.ResolveInfoFlags;
Winson14ff7172019-10-23 10:42:27 -070032import android.content.pm.parsing.AndroidPackage;
33import android.content.pm.parsing.ComponentParseUtils;
Chad Brubaker06068612017-04-06 09:43:47 -070034import android.os.Bundle;
Suprabh Shukla19b41f32018-03-26 22:35:13 -070035import android.os.PersistableBundle;
Eugene Suslaabdefba2018-11-09 18:06:43 -080036import android.util.ArraySet;
Makoto Onukic29f62c2016-06-07 12:19:46 -070037import android.util.SparseArray;
Todd Kennedy39bfee52016-02-24 10:28:21 -080038
Christopher Tatee4f5f2d2019-10-08 15:49:43 -070039import com.android.server.pm.PackageList;
40
Jeff Sharkey5790af02018-08-13 17:42:54 -060041import java.io.IOException;
Todd Kennedy82b08422017-09-28 13:32:05 -070042import java.lang.annotation.Retention;
43import java.lang.annotation.RetentionPolicy;
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -080044import java.util.List;
Eugene Suslaabdefba2018-11-09 18:06:43 -080045import java.util.function.Consumer;
Svet Ganovadc1cf42015-06-15 16:36:24 -070046
47/**
48 * Package manager local system service interface.
49 *
50 * @hide Only for use within the system server.
51 */
52public abstract class PackageManagerInternal {
Todd Kennedy82b08422017-09-28 13:32:05 -070053 public static final int PACKAGE_SYSTEM = 0;
54 public static final int PACKAGE_SETUP_WIZARD = 1;
55 public static final int PACKAGE_INSTALLER = 2;
56 public static final int PACKAGE_VERIFIER = 3;
57 public static final int PACKAGE_BROWSER = 4;
Makoto Onuki700feef2018-02-15 10:59:41 -080058 public static final int PACKAGE_SYSTEM_TEXT_CLASSIFIER = 5;
Philip P. Moltmann8943ad62018-07-25 12:12:30 -070059 public static final int PACKAGE_PERMISSION_CONTROLLER = 6;
Varun Shah5f303652018-11-16 18:11:19 -080060 public static final int PACKAGE_WELLBEING = 7;
Jeff Sharkey15707b32018-12-10 12:08:41 -070061 public static final int PACKAGE_DOCUMENTER = 8;
Stanislav Zholnin596437f2018-12-28 15:34:23 +000062 public static final int PACKAGE_CONFIGURATOR = 9;
Joe Onorato5a15b552018-12-18 10:40:04 -080063 public static final int PACKAGE_INCIDENT_REPORT_APPROVER = 10;
George Hodulikcd7695d2019-01-29 18:17:05 -080064 public static final int PACKAGE_APP_PREDICTOR = 11;
Chen Xu45c183d2019-10-07 00:24:41 -070065 public static final int PACKAGE_TELEPHONY = 12;
Todd Kennedy82b08422017-09-28 13:32:05 -070066 @IntDef(value = {
67 PACKAGE_SYSTEM,
68 PACKAGE_SETUP_WIZARD,
69 PACKAGE_INSTALLER,
70 PACKAGE_VERIFIER,
71 PACKAGE_BROWSER,
Makoto Onuki700feef2018-02-15 10:59:41 -080072 PACKAGE_SYSTEM_TEXT_CLASSIFIER,
Philip P. Moltmann8943ad62018-07-25 12:12:30 -070073 PACKAGE_PERMISSION_CONTROLLER,
Varun Shah5f303652018-11-16 18:11:19 -080074 PACKAGE_WELLBEING,
Jeff Sharkey15707b32018-12-10 12:08:41 -070075 PACKAGE_DOCUMENTER,
Stanislav Zholnin596437f2018-12-28 15:34:23 +000076 PACKAGE_CONFIGURATOR,
Joe Onorato5a15b552018-12-18 10:40:04 -080077 PACKAGE_INCIDENT_REPORT_APPROVER,
George Hodulikcd7695d2019-01-29 18:17:05 -080078 PACKAGE_APP_PREDICTOR,
Chen Xu45c183d2019-10-07 00:24:41 -070079 PACKAGE_TELEPHONY,
Todd Kennedy82b08422017-09-28 13:32:05 -070080 })
81 @Retention(RetentionPolicy.SOURCE)
82 public @interface KnownPackage {}
Svet Ganovadc1cf42015-06-15 16:36:24 -070083
Todd Kennedy42d61602017-12-12 14:44:19 -080084 /** Observer called whenever the list of packages changes */
85 public interface PackageListObserver {
86 /** A package was added to the system. */
Chenbo Fengde8e3b72019-02-21 14:24:24 -080087 void onPackageAdded(@NonNull String packageName, int uid);
Svet Ganovd8eb8b22019-04-05 18:52:08 -070088 /** A package was changed - either installed for a specific user or updated. */
89 default void onPackageChanged(@NonNull String packageName, int uid) {}
Todd Kennedy42d61602017-12-12 14:44:19 -080090 /** A package was removed from the system. */
Chenbo Fengde8e3b72019-02-21 14:24:24 -080091 void onPackageRemoved(@NonNull String packageName, int uid);
Todd Kennedy42d61602017-12-12 14:44:19 -080092 }
93
Svet Ganovadc1cf42015-06-15 16:36:24 -070094 /**
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +000095 * Called when the package for the default SMS handler changed
96 *
97 * @param packageName the new sms package
98 * @param userId user for which the change was made
Svetoslavcdfd2302015-06-25 19:07:31 -070099 */
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000100 public void onDefaultSmsAppChanged(String packageName, int userId) {}
Sailesh Nepalcf855622015-07-28 19:22:14 -0700101
102 /**
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000103 * Called when the package for the default sim call manager changed
104 *
105 * @param packageName the new sms package
106 * @param userId user for which the change was made
Sailesh Nepalcf855622015-07-28 19:22:14 -0700107 */
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000108 public void onDefaultSimCallManagerAppChanged(String packageName, int userId) {}
Fyodor Kupolovcb6fd802015-11-05 14:27:06 -0800109
110 /**
111 * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has
112 * currently installed it. The apps are not preloaded.
113 * @param packageList List of package names to keep cached.
114 */
115 public abstract void setKeepUninstalledPackages(List<String> packageList);
Svet Ganov9c165d72015-12-01 19:52:26 -0800116
117 /**
118 * Gets whether some of the permissions used by this package require a user
119 * review before any of the app components can run.
120 * @param packageName The package name for which to check.
121 * @param userId The user under which to check.
122 * @return True a permissions review is required.
123 */
124 public abstract boolean isPermissionsReviewRequired(String packageName, int userId);
Todd Kennedy39bfee52016-02-24 10:28:21 -0800125
126 /**
Todd Kennedy18211fd2017-06-06 09:15:46 -0700127 * Retrieve all of the information we know about a particular package/application.
128 * @param filterCallingUid The results will be filtered in the context of this UID instead
129 * of the calling UID.
130 * @see PackageManager#getPackageInfo(String, int)
Todd Kennedy39bfee52016-02-24 10:28:21 -0800131 */
Todd Kennedy18211fd2017-06-06 09:15:46 -0700132 public abstract PackageInfo getPackageInfo(String packageName,
133 @PackageInfoFlags int flags, int filterCallingUid, int userId);
134
135 /**
Ricky Waicf134eb2018-10-10 09:26:32 +0100136 * Return a List of all application packages that are installed on the
137 * device, for a specific user. If flag GET_UNINSTALLED_PACKAGES has been
138 * set, a list of all applications including those deleted with
139 * {@code DONT_DELETE_DATA} (partially installed apps with data directory)
140 * will be returned.
141 *
142 * @param flags Additional option flags to modify the data returned.
143 * @param userId The user for whom the installed applications are to be
144 * listed
145 * @param callingUid The uid of the original caller app
146 * @return A List of ApplicationInfo objects, one for each installed
147 * application. In the unlikely case there are no installed
148 * packages, an empty list is returned. If flag
149 * {@code MATCH_UNINSTALLED_PACKAGES} is set, the application
150 * information is retrieved from the list of uninstalled
151 * applications (which includes installed applications as well as
152 * applications with data directory i.e. applications which had been
153 * deleted with {@code DONT_DELETE_DATA} flag set).
154 */
155 public abstract List<ApplicationInfo> getInstalledApplications(
156 @ApplicationInfoFlags int flags, @UserIdInt int userId, int callingUid);
157
158 /**
Suprabh Shukla19b41f32018-03-26 22:35:13 -0700159 * Retrieve launcher extras for a suspended package provided to the system in
160 * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700161 * PersistableBundle, String)}.
Suprabh Shukla19b41f32018-03-26 22:35:13 -0700162 *
163 * @param packageName The package for which to return launcher extras.
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700164 * @param userId The user for which to check.
Suprabh Shukla19b41f32018-03-26 22:35:13 -0700165 * @return The launcher extras.
166 *
167 * @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle,
168 * PersistableBundle, String)
169 * @see PackageManager#isPackageSuspended()
170 */
171 public abstract Bundle getSuspendedPackageLauncherExtras(String packageName,
172 int userId);
173
174 /**
Suprabh Shukla69c71422018-04-02 18:39:01 -0700175 * Internal api to query the suspended state of a package.
176 * @param packageName The package to check.
177 * @param userId The user id to check for.
178 * @return {@code true} if the package is suspended, {@code false} otherwise.
179 * @see PackageManager#isPackageSuspended(String)
180 */
181 public abstract boolean isPackageSuspended(String packageName, int userId);
182
183 /**
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700184 * Get the name of the package that suspended the given package. Packages can be suspended by
185 * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or
186 * {@link android.Manifest.permission#SUSPEND_APPS}.
187 *
188 * @param suspendedPackage The package that has been suspended.
189 * @param userId The user for which to check.
190 * @return Name of the package that suspended the given package. Returns {@code null} if the
191 * given package is not currently suspended and the platform package name - i.e.
192 * {@code "android"} - if the package was suspended by a device admin.
193 */
194 public abstract String getSuspendingPackage(String suspendedPackage, int userId);
195
196 /**
Suprabh Shukla389cb6f2018-10-01 18:20:39 -0700197 * Get the information describing the dialog to be shown to the user when they try to launch a
198 * suspended application.
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700199 *
200 * @param suspendedPackage The package that has been suspended.
Suprabh Shuklad3278442019-08-27 15:58:03 -0700201 * @param suspendingPackage
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700202 * @param userId The user for which to check.
Suprabh Shukla389cb6f2018-10-01 18:20:39 -0700203 * @return A {@link SuspendDialogInfo} object describing the dialog to be shown.
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700204 */
Suprabh Shukla389cb6f2018-10-01 18:20:39 -0700205 @Nullable
Suprabh Shuklad3278442019-08-27 15:58:03 -0700206 public abstract SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage,
207 String suspendingPackage, int userId);
Suprabh Shukla3c3af142018-03-30 00:28:37 -0700208
209 /**
Suprabh Shukla79000492018-12-24 17:03:02 -0800210 * Gets any distraction flags set via
211 * {@link PackageManager#setDistractingPackageRestrictions(String[], int)}
212 *
213 * @param packageName
214 * @param userId
215 * @return A bitwise OR of any of the {@link PackageManager.DistractionRestriction}
216 */
217 public abstract @PackageManager.DistractionRestriction int getDistractingPackageRestrictions(
218 String packageName, int userId);
219
220 /**
Christopher Tatea732f012017-10-26 17:26:53 -0700221 * Do a straight uid lookup for the given package/application in the given user.
222 * @see PackageManager#getPackageUidAsUser(String, int, int)
223 * @return The app's uid, or < 0 if the package was not found in that user
224 */
225 public abstract int getPackageUid(String packageName,
226 @PackageInfoFlags int flags, int userId);
227
228 /**
Todd Kennedy18211fd2017-06-06 09:15:46 -0700229 * Retrieve all of the information we know about a particular package/application.
230 * @param filterCallingUid The results will be filtered in the context of this UID instead
231 * of the calling UID.
232 * @see PackageManager#getApplicationInfo(String, int)
233 */
234 public abstract ApplicationInfo getApplicationInfo(String packageName,
235 @ApplicationInfoFlags int flags, int filterCallingUid, int userId);
236
237 /**
238 * Retrieve all of the information we know about a particular activity class.
239 * @param filterCallingUid The results will be filtered in the context of this UID instead
240 * of the calling UID.
241 * @see PackageManager#getActivityInfo(ComponentName, int)
242 */
243 public abstract ActivityInfo getActivityInfo(ComponentName component,
244 @ComponentInfoFlags int flags, int filterCallingUid, int userId);
245
246 /**
247 * Retrieve all activities that can be performed for the given intent.
Patrick Baumann182ea1c2019-11-18 13:43:11 -0800248 * @param resolvedType the resolved type of the intent, which should be resolved via
249 * {@link Intent#resolveTypeIfNeeded(ContentResolver)} before passing to {@link PackageManager}
Todd Kennedy18211fd2017-06-06 09:15:46 -0700250 * @param filterCallingUid The results will be filtered in the context of this UID instead
251 * of the calling UID.
252 * @see PackageManager#queryIntentActivities(Intent, int)
253 */
Patrick Baumann182ea1c2019-11-18 13:43:11 -0800254 public abstract List<ResolveInfo> queryIntentActivities(
255 Intent intent, @Nullable String resolvedType, @ResolveInfoFlags int flags,
256 int filterCallingUid, int userId);
257
Makoto Onuki2d5b4652016-03-11 16:09:54 -0800258
259 /**
Todd Kennedy82b08422017-09-28 13:32:05 -0700260 * Retrieve all services that can be performed for the given intent.
261 * @see PackageManager#queryIntentServices(Intent, int)
262 */
263 public abstract List<ResolveInfo> queryIntentServices(
264 Intent intent, int flags, int callingUid, int userId);
265
266 /**
Makoto Onuki2d5b4652016-03-11 16:09:54 -0800267 * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}.
268 */
269 public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates,
270 int userId);
Makoto Onukic29f62c2016-06-07 12:19:46 -0700271
272 /**
Winson Chungc1674272018-02-21 10:15:17 -0800273 * @return The default home activity component name.
274 */
275 public abstract ComponentName getDefaultHomeActivity(int userId);
276
277 /**
Makoto Onukic29f62c2016-06-07 12:19:46 -0700278 * Called by DeviceOwnerManagerService to set the package names of device owner and profile
279 * owners.
280 */
281 public abstract void setDeviceAndProfileOwnerPackages(
282 int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners);
283
284 /**
Steven Ng9d48a732016-06-24 19:04:14 +0100285 * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}.
Makoto Onukic29f62c2016-06-07 12:19:46 -0700286 */
Steven Ng9d48a732016-06-24 19:04:14 +0100287 public abstract boolean isPackageDataProtected(int userId, String packageName);
Svet Ganov973edd192016-09-08 20:15:55 -0700288
289 /**
Benjamin Franzf81bf7f2018-03-26 16:23:04 +0100290 * Returns {@code true} if a given package's state is protected, e.g. it cannot be force
291 * stopped, suspended, disabled or hidden. Otherwise, returns {@code false}.
292 */
293 public abstract boolean isPackageStateProtected(String packageName, int userId);
294
295 /**
Dianne Hackborne07641d2016-11-09 15:07:23 -0800296 * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns
297 * {@code false}.
298 */
299 public abstract boolean isPackageEphemeral(int userId, String packageName);
300
301 /**
Svet Ganov973edd192016-09-08 20:15:55 -0700302 * Gets whether the package was ever launched.
303 * @param packageName The package name.
304 * @param userId The user for which to check.
305 * @return Whether was launched.
Amith Yamasani2cbfa1e2017-03-28 10:34:01 -0700306 * @throws IllegalArgumentException if the package is not found
Svet Ganov973edd192016-09-08 20:15:55 -0700307 */
308 public abstract boolean wasPackageEverLaunched(String packageName, int userId);
Nicolas Prevot700e1e72016-09-28 15:17:18 +0100309
310 /**
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000311 * Retrieve the official name associated with a uid. This name is
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100312 * guaranteed to never change, though it is possible for the underlying
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000313 * uid to be changed. That is, if you are storing information about
314 * uids in persistent storage, you should use the string returned
315 * by this function instead of the raw uid.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100316 *
Michal Karpinskicb67dc92016-12-13 18:20:23 +0000317 * @param uid The uid for which you would like to retrieve a name.
318 * @return Returns a unique name for the given uid, or null if the
319 * uid is not currently assigned.
Michal Karpinskif77ee4f2016-10-12 16:40:06 +0100320 */
321 public abstract String getNameForUid(int uid);
322
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800323 /**
Bookatz04d7ae52019-08-05 14:07:12 -0700324 * Marks a package as installed (or not installed) for a given user.
325 *
326 * @param pkg the package whose installation is to be set
327 * @param userId the user for whom to set it
328 * @param installed the new installed state
329 * @return true if the installed state changed as a result
330 */
Winson14ff7172019-10-23 10:42:27 -0700331 public abstract boolean setInstalled(AndroidPackage pkg,
Bookatz04d7ae52019-08-05 14:07:12 -0700332 @UserIdInt int userId, boolean installed);
333
334 /**
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800335 * Request to perform the second phase of ephemeral resolution.
336 * @param responseObj The response of the first phase of ephemeral resolution
337 * @param origIntent The original intent that triggered ephemeral resolution
338 * @param resolvedType The resolved type of the intent
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800339 * @param callingPackage The name of the package requesting the ephemeral application
Chad Brubaker06068612017-04-06 09:43:47 -0700340 * @param verificationBundle Optional bundle to pass to the installer for additional
341 * verification
Todd Kennedy01ad0c72016-11-11 15:33:12 -0800342 * @param userId The ID of the user that triggered ephemeral resolution
343 */
Todd Kennedye9910222017-02-21 16:00:11 -0800344 public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj,
345 Intent origIntent, String resolvedType, String callingPackage,
Chad Brubaker06068612017-04-06 09:43:47 -0700346 Bundle verificationBundle, int userId);
Svetoslav Ganove080da92016-12-21 17:10:35 -0800347
348 /**
Patrick Baumannde37e432019-08-28 09:51:29 -0700349 * Grants implicit access based on an interaction between two apps. This grants the target app
350 * access to the calling application's package metadata.
Todd Kennedy0e989d02017-01-13 14:15:36 -0800351 * <p>
Patrick Baumannde37e432019-08-28 09:51:29 -0700352 * When an application explicitly tries to interact with another application [via an
353 * activity, service or provider that is either declared in the caller's
354 * manifest via the {@code <queries>} tag or has been exposed via the target apps manifest using
355 * the {@code visibleToInstantApp} attribute], the target application must be able to see
356 * metadata about the calling app. If the calling application uses an implicit intent [ie
357 * action VIEW, category BROWSABLE], it remains hidden from the launched app.
Todd Kennedy0e989d02017-01-13 14:15:36 -0800358 * <p>
Todd Kennedy0e989d02017-01-13 14:15:36 -0800359 * @param userId the user
360 * @param intent the intent that triggered the grant
Patrick Baumannb6e72972019-09-20 07:54:47 -0700361 * @param callingUid The uid of the calling application
Patrick Baumannde37e432019-08-28 09:51:29 -0700362 * @param targetAppId The app ID of the target application
Todd Kennedy0e989d02017-01-13 14:15:36 -0800363 */
Patrick Baumannde37e432019-08-28 09:51:29 -0700364 public abstract void grantImplicitAccess(
Patrick Baumannb6e72972019-09-20 07:54:47 -0700365 @UserIdInt int userId, Intent intent, int callingUid,
Patrick Baumannde37e432019-08-28 09:51:29 -0700366 @AppIdInt int targetAppId);
Todd Kennedy0e989d02017-01-13 14:15:36 -0800367
Todd Kennedyb21be122017-03-24 14:10:01 -0700368 public abstract boolean isInstantAppInstallerComponent(ComponentName component);
Todd Kennedy0e989d02017-01-13 14:15:36 -0800369 /**
Svetoslav Ganov096d3042017-01-30 16:34:13 -0800370 * Prunes instant apps and state associated with uninstalled
371 * instant apps according to the current platform policy.
372 */
373 public abstract void pruneInstantApps();
374
375 /**
Svetoslav Ganove080da92016-12-21 17:10:35 -0800376 * @return The SetupWizard package name.
377 */
378 public abstract String getSetupWizardPackageName();
Suprabh Shuklaaef25132017-01-23 18:09:03 -0800379
380 public interface ExternalSourcesPolicy {
381
382 int USER_TRUSTED = 0; // User has trusted the package to install apps
383 int USER_BLOCKED = 1; // User has blocked the package to install apps
384 int USER_DEFAULT = 2; // Default code to use when user response is unavailable
385
386 /**
387 * Checks the user preference for whether a package is trusted to request installs through
388 * package installer
389 *
390 * @param packageName The package to check for
391 * @param uid the uid in which the package is running
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000392 * @return {@link #USER_TRUSTED} if the user has trusted the package, {@link #USER_BLOCKED}
393 * if user has blocked requests from the package, {@link #USER_DEFAULT} if the user response
Suprabh Shuklaaef25132017-01-23 18:09:03 -0800394 * is not yet available
395 */
396 int getPackageTrustedToInstallApps(String packageName, int uid);
397 }
398
399 public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy);
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +0100400
401 /**
Dianne Hackbornb1e77762017-02-13 11:42:18 -0800402 * Return true if the given package is a persistent app process.
403 */
404 public abstract boolean isPackagePersistent(String packageName);
405
406 /**
Todd Kennedyc29b11a2017-10-23 15:55:59 -0700407 * Returns whether or not the given package represents a legacy system application released
408 * prior to runtime permissions.
409 */
Winson14ff7172019-10-23 10:42:27 -0700410 public abstract boolean isLegacySystemApp(AndroidPackage pkg);
Todd Kennedyc29b11a2017-10-23 15:55:59 -0700411
412 /**
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +0100413 * Get all overlay packages for a user.
414 * @param userId The user for which to get the overlays.
415 * @return A list of overlay packages. An empty list is returned if the
416 * user has no installed overlay packages.
417 */
418 public abstract List<PackageInfo> getOverlayPackages(int userId);
419
420 /**
421 * Get the names of all target packages for a user.
422 * @param userId The user for which to get the package names.
423 * @return A list of target package names. This list includes the "android" package.
424 */
425 public abstract List<String> getTargetPackageNames(int userId);
426
427 /**
428 * Set which overlay to use for a package.
429 * @param userId The user for which to update the overlays.
430 * @param targetPackageName The package name of the package for which to update the overlays.
431 * @param overlayPackageNames The complete list of overlay packages that should be enabled for
432 * the target. Previously enabled overlays not specified in the list
433 * will be disabled. Pass in null or an empty list to disable
434 * all overlays. The order of the items is significant if several
435 * overlays modify the same resource.
436 * @return true if all packages names were known by the package manager, false otherwise
437 */
438 public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName,
439 List<String> overlayPackageNames);
Todd Kennedy4d1de7d2017-02-23 10:32:18 -0800440
441 /**
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700442 * Resolves an activity intent, allowing instant apps to be resolved.
Todd Kennedy4d1de7d2017-02-23 10:32:18 -0800443 */
444 public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType,
Patrick Baumann78380272018-04-04 10:41:01 -0700445 int flags, int userId, boolean resolveForStart, int filterCallingUid);
Chad Brubaker0f28a802017-03-29 14:05:52 -0700446
447 /**
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700448 * Resolves a service intent, allowing instant apps to be resolved.
449 */
Todd Kennedy82b08422017-09-28 13:32:05 -0700450 public abstract ResolveInfo resolveService(Intent intent, String resolvedType,
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700451 int flags, int userId, int callingUid);
452
Todd Kennedy82b08422017-09-28 13:32:05 -0700453 /**
454 * Resolves a content provider intent.
455 */
456 public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId);
457
Todd Kennedy51b3aac2017-03-30 17:50:42 -0700458 /**
Chad Brubaker0f28a802017-03-29 14:05:52 -0700459 * Track the creator of a new isolated uid.
460 * @param isolatedUid The newly created isolated uid.
461 * @param ownerUid The uid of the app that created the isolated process.
462 */
463 public abstract void addIsolatedUid(int isolatedUid, int ownerUid);
464
465 /**
466 * Track removal of an isolated uid.
467 * @param isolatedUid isolated uid that is no longer being used.
468 */
469 public abstract void removeIsolatedUid(int isolatedUid);
Makoto Onukie92f7942017-04-26 14:38:18 -0700470
471 /**
472 * Return the taget SDK version for the app with the given UID.
473 */
474 public abstract int getUidTargetSdkVersion(int uid);
Makoto Onukiad623012017-05-15 09:29:34 -0700475
Jeff Sharkey9252b342018-01-19 07:58:35 +0900476 /**
477 * Return the taget SDK version for the app with the given package name.
478 */
479 public abstract int getPackageTargetSdkVersion(String packageName);
480
Makoto Onukiad623012017-05-15 09:29:34 -0700481 /** Whether the binder caller can access instant apps. */
Todd Kennedy3051caa2017-05-23 15:54:18 -0700482 public abstract boolean canAccessInstantApps(int callingUid, int userId);
Svet Ganovf935a702017-08-22 12:15:58 -0700483
Todd Kennedy662504f2018-03-14 08:09:00 -0700484 /** Whether the binder caller can access the given component. */
485 public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId);
486
Svet Ganovf935a702017-08-22 12:15:58 -0700487 /**
488 * Returns {@code true} if a given package has instant application meta-data.
489 * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc)
490 * associated with an instant app. It may be kept after the instant app has been uninstalled.
491 */
492 public abstract boolean hasInstantApplicationMetadata(String packageName, int userId);
Todd Kennedydf113c32017-08-31 16:10:29 -0700493
494 /**
495 * Updates a package last used time.
496 */
497 public abstract void notifyPackageUse(String packageName, int reason);
Todd Kennedy82b08422017-09-28 13:32:05 -0700498
499 /**
500 * Returns a package object for the given package name.
501 */
Winson14ff7172019-10-23 10:42:27 -0700502 public abstract @Nullable AndroidPackage getPackage(@NonNull String packageName);
503
504 // TODO(b/135203078): PackageSetting can't be referenced directly. Should move to a server side
505 // internal PM which is aware of PS.
506 public abstract @Nullable Object getPackageSetting(String packageName);
Todd Kennedy82b08422017-09-28 13:32:05 -0700507
508 /**
Todd Kennedyca1ea172019-07-03 15:02:28 -0700509 * Returns a package for the given UID. If the UID is part of a shared user ID, one
510 * of the packages will be chosen to be returned.
511 */
Winson14ff7172019-10-23 10:42:27 -0700512 public abstract @Nullable AndroidPackage getPackage(int uid);
Todd Kennedyca1ea172019-07-03 15:02:28 -0700513
514 /**
Todd Kennedy42d61602017-12-12 14:44:19 -0800515 * Returns a list without a change observer.
516 *
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000517 * @see #getPackageList(PackageListObserver)
Todd Kennedy42d61602017-12-12 14:44:19 -0800518 */
519 public @NonNull PackageList getPackageList() {
520 return getPackageList(null);
521 }
522
523 /**
524 * Returns the list of packages installed at the time of the method call.
525 * <p>The given observer is notified when the list of installed packages
526 * changes [eg. a package was installed or uninstalled]. It will not be
527 * notified if a package is updated.
528 * <p>The package list will not be updated automatically as packages are
529 * installed / uninstalled. Any changes must be handled within the observer.
530 */
531 public abstract @NonNull PackageList getPackageList(@Nullable PackageListObserver observer);
532
533 /**
534 * Removes the observer.
535 * <p>Generally not needed. {@link #getPackageList(PackageListObserver)} will automatically
536 * remove the observer.
537 * <p>Does nothing if the observer isn't currently registered.
538 * <p>Observers are notified asynchronously and it's possible for an observer to be
539 * invoked after its been removed.
540 */
541 public abstract void removePackageListObserver(@NonNull PackageListObserver observer);
542
Winson14ff7172019-10-23 10:42:27 -0700543 // TODO(b/135203078): PackageSetting can't be referenced directly
Todd Kennedy42d61602017-12-12 14:44:19 -0800544 /**
Todd Kennedy82b08422017-09-28 13:32:05 -0700545 * Returns a package object for the disabled system package name.
546 */
Winson14ff7172019-10-23 10:42:27 -0700547 public abstract @Nullable Object getDisabledSystemPackage(@NonNull String packageName);
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000548
549 /**
550 * Returns the package name for the disabled system package.
551 *
552 * This is equivalent to
Winson14ff7172019-10-23 10:42:27 -0700553 * {@link #getDisabledSystemPackage(String)}
554 * .{@link com.android.server.pm.PackageSetting#pkg}
555 * .{@link AndroidPackage#getPackageName()}
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000556 */
557 public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName);
Todd Kennedy82b08422017-09-28 13:32:05 -0700558
559 /**
560 * Returns whether or not the component is the resolver activity.
561 */
562 public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component);
563
Chen Xu45c183d2019-10-07 00:24:41 -0700564
Todd Kennedy82b08422017-09-28 13:32:05 -0700565 /**
Chen Xu45c183d2019-10-07 00:24:41 -0700566 * Returns a list of package names for a known package
Todd Kennedy82b08422017-09-28 13:32:05 -0700567 */
Chen Xu45c183d2019-10-07 00:24:41 -0700568 public abstract @NonNull String[] getKnownPackageNames(
Todd Kennedy82b08422017-09-28 13:32:05 -0700569 @KnownPackage int knownPackage, int userId);
570
Todd Kennedy0eb97382017-10-03 16:57:22 -0700571 /**
572 * Returns whether the package is an instant app.
573 */
574 public abstract boolean isInstantApp(String packageName, int userId);
575
576 /**
577 * Returns whether the package is an instant app.
578 */
579 public abstract @Nullable String getInstantAppPackageName(int uid);
580
581 /**
582 * Returns whether or not access to the application should be filtered.
583 * <p>
584 * Access may be limited based upon whether the calling or target applications
585 * are instant applications.
586 *
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000587 * @see #canAccessInstantApps
Todd Kennedy0eb97382017-10-03 16:57:22 -0700588 */
589 public abstract boolean filterAppAccess(
Winson14ff7172019-10-23 10:42:27 -0700590 @NonNull AndroidPackage pkg, int callingUid, int userId);
Todd Kennedyc5b0e862019-07-16 09:47:58 -0700591
592 /**
593 * Returns whether or not access to the application should be filtered.
594 *
595 * @see #filterAppAccess(android.content.pm.PackageParser.Package, int, int)
596 */
597 public abstract boolean filterAppAccess(
598 @NonNull String packageName, int callingUid, int userId);
Todd Kennedy0eb97382017-10-03 16:57:22 -0700599
Philip P. Moltmannb0be05c2018-09-19 02:46:56 +0000600 /** Returns whether the given package was signed by the platform */
601 public abstract boolean isPlatformSigned(String pkg);
602
Michal Karpinski528c3e52018-02-07 17:47:10 +0000603 /**
604 * Returns true if it's still safe to restore data backed up from this app's version
605 * that was signed with restoringFromSigHash.
606 */
607 public abstract boolean isDataRestoreSafe(@NonNull byte[] restoringFromSigHash,
608 @NonNull String packageName);
609
610 /**
611 * Returns true if it's still safe to restore data backed up from this app's version
612 * that was signed with restoringFromSig.
613 */
614 public abstract boolean isDataRestoreSafe(@NonNull Signature restoringFromSig,
615 @NonNull String packageName);
Dan Cashman303c4bb2018-04-10 07:41:16 -0700616
Dan Cashman303c4bb2018-04-10 07:41:16 -0700617 /**
Todd Kennedycf827032018-07-03 13:17:22 -0700618 * Returns {@code true} if the the signing information for {@code clientUid} is sufficient
619 * to gain access gated by {@code capability}. This can happen if the two UIDs have the
620 * same signing information, if the signing information {@code clientUid} indicates that
621 * it has the signing certificate for {@code serverUid} in its signing history (if it was
622 * previously signed by it), or if the signing certificate for {@code clientUid} is in the
623 * signing history for {@code serverUid} and with the {@code capability} specified.
Dan Cashman303c4bb2018-04-10 07:41:16 -0700624 */
625 public abstract boolean hasSignatureCapability(int serverUid, int clientUid,
626 @PackageParser.SigningDetails.CertCapabilities int capability);
Svet Ganovd873ae62018-06-25 16:39:23 -0700627
628 /**
Sudheer Shanka0a541a52018-07-31 13:21:11 -0700629 * Get appIds of all available apps which specified android:sharedUserId in the manifest.
630 *
631 * @return a SparseArray mapping from appId to it's sharedUserId.
632 */
633 public abstract SparseArray<String> getAppsWithSharedUserIds();
Jeff Sharkey5790af02018-08-13 17:42:54 -0600634
635 /**
Sudheer Shanka2ac25a92018-10-25 10:59:32 -0700636 * Get the value of attribute android:sharedUserId for the given packageName if specified,
637 * otherwise {@code null}.
638 */
639 public abstract String getSharedUserIdForPackage(@NonNull String packageName);
640
641 /**
642 * Get all packages which specified the given sharedUserId as android:sharedUserId attribute
643 * or an empty array if no package specified it.
644 */
645 public abstract String[] getPackagesForSharedUserId(@NonNull String sharedUserId, int userId);
646
647 /**
Jeff Sharkey5790af02018-08-13 17:42:54 -0600648 * Return if device is currently in a "core" boot environment, typically
649 * used to support full-disk encryption. Only apps marked with
650 * {@code coreApp} attribute are available.
651 */
652 public abstract boolean isOnlyCoreApps();
653
654 /**
655 * Make a best-effort attempt to provide the requested free disk space by
656 * deleting cached files.
657 *
658 * @throws IOException if the request was unable to be fulfilled.
659 */
660 public abstract void freeStorage(String volumeUuid, long bytes, int storageFlags)
661 throws IOException;
Todd Kennedycf827032018-07-03 13:17:22 -0700662
663 /** Returns {@code true} if the specified component is enabled and matches the given flags. */
Winson14ff7172019-10-23 10:42:27 -0700664 public abstract boolean isEnabledAndMatches(
665 @NonNull ComponentParseUtils.ParsedComponent component, int flags, int userId);
Todd Kennedycf827032018-07-03 13:17:22 -0700666
667 /** Returns {@code true} if the given user requires extra badging for icons. */
668 public abstract boolean userNeedsBadging(int userId);
Eugene Suslaabdefba2018-11-09 18:06:43 -0800669
670 /**
671 * Perform the given action for each package.
672 * Note that packages lock will be held while performin the actions.
673 *
674 * @param actionLocked action to be performed
675 */
Winson14ff7172019-10-23 10:42:27 -0700676 public abstract void forEachPackage(Consumer<AndroidPackage> actionLocked);
Eugene Suslaabdefba2018-11-09 18:06:43 -0800677
Hai Zhangeb8b4602019-05-22 13:04:12 -0700678 /**
679 * Perform the given action for each installed package for a user.
680 * Note that packages lock will be held while performin the actions.
681 */
682 public abstract void forEachInstalledPackage(
Winson14ff7172019-10-23 10:42:27 -0700683 @NonNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId);
Hai Zhangeb8b4602019-05-22 13:04:12 -0700684
Eugene Suslaabdefba2018-11-09 18:06:43 -0800685 /** Returns the list of enabled components */
686 public abstract ArraySet<String> getEnabledComponents(String packageName, int userId);
687
688 /** Returns the list of disabled components */
689 public abstract ArraySet<String> getDisabledComponents(String packageName, int userId);
690
691 /** Returns whether the given package is enabled for the given user */
692 public abstract @PackageManager.EnabledState int getApplicationEnabledState(
693 String packageName, int userId);
Richard Uhlerb29f1452018-09-12 16:38:15 +0100694
695 /**
696 * Extra field name for the token of a request to enable rollback for a
697 * package.
698 */
699 public static final String EXTRA_ENABLE_ROLLBACK_TOKEN =
700 "android.content.pm.extra.ENABLE_ROLLBACK_TOKEN";
701
702 /**
703 * Extra field name for the installFlags of a request to enable rollback
704 * for a package.
705 */
706 public static final String EXTRA_ENABLE_ROLLBACK_INSTALL_FLAGS =
707 "android.content.pm.extra.ENABLE_ROLLBACK_INSTALL_FLAGS";
708
709 /**
Richard Uhler82913b72019-04-01 13:02:31 +0100710 * Extra field name for the user id an install is associated with when
711 * enabling rollback.
712 */
713 public static final String EXTRA_ENABLE_ROLLBACK_USER =
714 "android.content.pm.extra.ENABLE_ROLLBACK_USER";
715
716 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +0100717 * Used as the {@code enableRollbackCode} argument for
718 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that
719 * enabling rollback succeeded.
720 */
721 public static final int ENABLE_ROLLBACK_SUCCEEDED = 1;
722
723 /**
724 * Used as the {@code enableRollbackCode} argument for
725 * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that
726 * enabling rollback failed.
727 */
728 public static final int ENABLE_ROLLBACK_FAILED = -1;
729
730 /**
731 * Allows the rollback manager listening to the
732 * {@link Intent#ACTION_PACKAGE_ENABLE_ROLLBACK enable rollback broadcast}
733 * to respond to the package manager. The response must include the
734 * {@code enableRollbackCode} which is one of
735 * {@link PackageManager#ENABLE_ROLLBACK_SUCCEEDED} or
736 * {@link PackageManager#ENABLE_ROLLBACK_FAILED}.
737 *
738 * @param token pending package identifier as passed via the
739 * {@link PackageManager#EXTRA_ENABLE_ROLLBACK_TOKEN} Intent extra.
740 * @param enableRollbackCode the status code result of enabling rollback
741 * @throws SecurityException if the caller does not have the
742 * PACKAGE_ROLLBACK_AGENT permission.
743 */
744 public abstract void setEnableRollbackCode(int token, int enableRollbackCode);
Eric Holka1485f62019-01-07 13:58:25 -0800745
746 /**
747 * Ask the package manager to compile layouts in the given package.
748 */
749 public abstract boolean compileLayouts(String packageName);
Narayan Kamath869f7062019-01-10 12:24:15 +0000750
751 /*
752 * Inform the package manager that the pending package install identified by
753 * {@code token} can be completed.
754 */
755 public abstract void finishPackageInstall(int token, boolean didLaunch);
Hai Zhanga22cd832019-01-30 13:38:43 -0800756
757 /**
758 * Remove the default browser stored in the legacy package settings.
759 *
760 * @param userId the user id
761 *
762 * @return the package name of the default browser, or {@code null} if none
763 */
764 @Nullable
765 public abstract String removeLegacyDefaultBrowserPackageName(int userId);
Hai Zhang85fd0622019-02-01 14:06:04 -0800766
767 /**
Nikita Ioffef012a222019-03-05 22:37:55 +0000768 * Returns {@code true} if given {@code packageName} is an apex package.
769 */
770 public abstract boolean isApexPackage(String packageName);
771
772 /**
773 * Uninstalls given {@code packageName}.
774 *
775 * @param packageName apex package to uninstall.
776 * @param versionCode version of a package to uninstall.
777 * @param userId user to uninstall apex package for. Must be
778 * {@link android.os.UserHandle#USER_ALL}, otherwise failure will be reported.
779 * @param intentSender a {@link IntentSender} to send result of an uninstall to.
Gavin Corkery4fd10882019-11-28 15:37:51 +0000780 * @param flags flags about the uninstall.
Nikita Ioffef012a222019-03-05 22:37:55 +0000781 */
782 public abstract void uninstallApex(String packageName, long versionCode, int userId,
Gavin Corkery4fd10882019-11-28 15:37:51 +0000783 IntentSender intentSender, int flags);
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700784
785 /**
Philip P. Moltmann5f5783e2019-05-22 14:57:18 -0700786 * Get fingerprint of build that updated the runtime permissions for a user.
787 *
788 * @param userId The user to update
789 * @param fingerPrint The fingerprint to set
790 */
791 public abstract void setRuntimePermissionsFingerPrint(@NonNull String fingerPrint,
792 @UserIdInt int userId);
Narayan Kamath157dd1d2019-06-12 13:06:30 +0100793
794 /**
795 * Migrates legacy obb data to its new location.
796 */
797 public abstract void migrateLegacyObbData();
Todd Kennedy6ffc5a62019-07-03 09:35:31 -0700798
799 /**
800 * Writes all package manager settings to disk. If {@code async} is {@code true}, the
801 * settings are written at some point in the future. Otherwise, the call blocks until
802 * the settings have been written.
803 */
804 public abstract void writeSettings(boolean async);
Todd Kennedy230c0a72019-07-03 13:06:35 -0700805
806 /**
807 * Writes all permission settings for the given set of users to disk. If {@code async}
808 * is {@code true}, the settings are written at some point in the future. Otherwise,
809 * the call blocks until the settings have been written.
810 */
811 public abstract void writePermissionSettings(@NonNull @UserIdInt int[] userIds, boolean async);
812
813 /**
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700814 * Returns {@code true} if the caller is the installer of record for the given package.
815 * Otherwise, {@code false}.
816 */
817 public abstract boolean isCallerInstallerOfRecord(
Winson14ff7172019-10-23 10:42:27 -0700818 @NonNull AndroidPackage pkg, int callingUid);
Todd Kennedy583378d2019-07-12 06:50:30 -0700819
820 /** Returns whether or not default runtime permissions are granted for the given user */
821 public abstract boolean areDefaultRuntimePermissionsGranted(@UserIdInt int userId);
Todd Kennedyc5b0e862019-07-16 09:47:58 -0700822
823 /** Sets the enforcement of reading external storage */
824 public abstract void setReadExternalStorageEnforced(boolean enforced);
Svet Ganovadc1cf42015-06-15 16:36:24 -0700825}