Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.content.pm; |
| 18 | |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 19 | import android.annotation.AppIdInt; |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 20 | import android.annotation.IntDef; |
| 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 23 | import android.annotation.UserIdInt; |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
Patrick Baumann | 182ea1c | 2019-11-18 13:43:11 -0800 | [diff] [blame] | 25 | import android.content.ContentResolver; |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
Nikita Ioffe | f012a22 | 2019-03-05 22:37:55 +0000 | [diff] [blame] | 27 | import android.content.IntentSender; |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager.ApplicationInfoFlags; |
| 29 | import android.content.pm.PackageManager.ComponentInfoFlags; |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 30 | import android.content.pm.PackageManager.PackageInfoFlags; |
| 31 | import android.content.pm.PackageManager.ResolveInfoFlags; |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 32 | import android.content.pm.parsing.AndroidPackage; |
| 33 | import android.content.pm.parsing.ComponentParseUtils; |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 34 | import android.os.Bundle; |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 35 | import android.os.PersistableBundle; |
Dianne Hackborn | f6729fa | 2020-01-06 13:12:36 -0800 | [diff] [blame] | 36 | import android.util.ArrayMap; |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 37 | import android.util.ArraySet; |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 38 | import android.util.SparseArray; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 39 | |
Christopher Tate | e4f5f2d | 2019-10-08 15:49:43 -0700 | [diff] [blame] | 40 | import com.android.server.pm.PackageList; |
| 41 | |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 42 | import java.io.IOException; |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 43 | import java.lang.annotation.Retention; |
| 44 | import java.lang.annotation.RetentionPolicy; |
Ryan Mitchell | ee4a564 | 2019-10-16 08:32:55 -0700 | [diff] [blame] | 45 | import java.util.Collection; |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 46 | import java.util.List; |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 47 | import java.util.function.Consumer; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Package manager local system service interface. |
| 51 | * |
| 52 | * @hide Only for use within the system server. |
| 53 | */ |
| 54 | public abstract class PackageManagerInternal { |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 55 | public static final int PACKAGE_SYSTEM = 0; |
| 56 | public static final int PACKAGE_SETUP_WIZARD = 1; |
| 57 | public static final int PACKAGE_INSTALLER = 2; |
| 58 | public static final int PACKAGE_VERIFIER = 3; |
| 59 | public static final int PACKAGE_BROWSER = 4; |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 60 | public static final int PACKAGE_SYSTEM_TEXT_CLASSIFIER = 5; |
Philip P. Moltmann | 8943ad6 | 2018-07-25 12:12:30 -0700 | [diff] [blame] | 61 | public static final int PACKAGE_PERMISSION_CONTROLLER = 6; |
Varun Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 62 | public static final int PACKAGE_WELLBEING = 7; |
Jeff Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 63 | public static final int PACKAGE_DOCUMENTER = 8; |
Stanislav Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 64 | public static final int PACKAGE_CONFIGURATOR = 9; |
Joe Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 65 | public static final int PACKAGE_INCIDENT_REPORT_APPROVER = 10; |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 66 | public static final int PACKAGE_APP_PREDICTOR = 11; |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 67 | public static final int PACKAGE_TELEPHONY = 12; |
Eugene Susla | 1fa23ed0 | 2019-07-24 16:30:16 -0700 | [diff] [blame] | 68 | public static final int PACKAGE_WIFI = 13; |
| 69 | public static final int PACKAGE_COMPANION = 14; |
wayneyang | 8126b1f | 2020-01-09 14:10:31 +0800 | [diff] [blame] | 70 | public static final int PACKAGE_RETAIL_DEMO = 15; |
Eugene Susla | 1fa23ed0 | 2019-07-24 16:30:16 -0700 | [diff] [blame] | 71 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 72 | @IntDef(value = { |
Song Pan | 26dee80 | 2019-10-17 17:56:21 +0100 | [diff] [blame] | 73 | INTEGRITY_VERIFICATION_ALLOW, |
| 74 | INTEGRITY_VERIFICATION_REJECT, |
| 75 | }) |
| 76 | @Retention(RetentionPolicy.SOURCE) |
| 77 | public @interface IntegrityVerificationResult {} |
| 78 | |
| 79 | /** |
| 80 | * Used as the {@code verificationCode} argument for |
| 81 | * {@link PackageManagerInternal#setIntegrityVerificationResult(int, int)} to indicate that the |
| 82 | * integrity component allows the install to proceed. |
| 83 | */ |
| 84 | public static final int INTEGRITY_VERIFICATION_ALLOW = 1; |
| 85 | |
| 86 | /** |
| 87 | * Used as the {@code verificationCode} argument for |
| 88 | * {@link PackageManagerInternal#setIntegrityVerificationResult(int, int)} to indicate that the |
| 89 | * integrity component does not allow install to proceed. |
| 90 | */ |
| 91 | public static final int INTEGRITY_VERIFICATION_REJECT = 0; |
| 92 | |
| 93 | @IntDef(value = { |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 94 | PACKAGE_SYSTEM, |
| 95 | PACKAGE_SETUP_WIZARD, |
| 96 | PACKAGE_INSTALLER, |
| 97 | PACKAGE_VERIFIER, |
| 98 | PACKAGE_BROWSER, |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 99 | PACKAGE_SYSTEM_TEXT_CLASSIFIER, |
Philip P. Moltmann | 8943ad6 | 2018-07-25 12:12:30 -0700 | [diff] [blame] | 100 | PACKAGE_PERMISSION_CONTROLLER, |
Varun Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 101 | PACKAGE_WELLBEING, |
Jeff Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 102 | PACKAGE_DOCUMENTER, |
Stanislav Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 103 | PACKAGE_CONFIGURATOR, |
Joe Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 104 | PACKAGE_INCIDENT_REPORT_APPROVER, |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 105 | PACKAGE_APP_PREDICTOR, |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 106 | PACKAGE_TELEPHONY, |
Eugene Susla | 1fa23ed0 | 2019-07-24 16:30:16 -0700 | [diff] [blame] | 107 | PACKAGE_WIFI, |
| 108 | PACKAGE_COMPANION, |
wayneyang | 8126b1f | 2020-01-09 14:10:31 +0800 | [diff] [blame] | 109 | PACKAGE_RETAIL_DEMO, |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 110 | }) |
| 111 | @Retention(RetentionPolicy.SOURCE) |
| 112 | public @interface KnownPackage {} |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 113 | |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 114 | /** Observer called whenever the list of packages changes */ |
| 115 | public interface PackageListObserver { |
| 116 | /** A package was added to the system. */ |
Chenbo Feng | de8e3b7 | 2019-02-21 14:24:24 -0800 | [diff] [blame] | 117 | void onPackageAdded(@NonNull String packageName, int uid); |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 118 | /** A package was changed - either installed for a specific user or updated. */ |
| 119 | default void onPackageChanged(@NonNull String packageName, int uid) {} |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 120 | /** A package was removed from the system. */ |
Chenbo Feng | de8e3b7 | 2019-02-21 14:24:24 -0800 | [diff] [blame] | 121 | void onPackageRemoved(@NonNull String packageName, int uid); |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 124 | /** |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 125 | * Called when the package for the default SMS handler changed |
| 126 | * |
| 127 | * @param packageName the new sms package |
| 128 | * @param userId user for which the change was made |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 129 | */ |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 130 | public void onDefaultSmsAppChanged(String packageName, int userId) {} |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 133 | * Called when the package for the default sim call manager changed |
| 134 | * |
| 135 | * @param packageName the new sms package |
| 136 | * @param userId user for which the change was made |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 137 | */ |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 138 | public void onDefaultSimCallManagerAppChanged(String packageName, int userId) {} |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has |
| 142 | * currently installed it. The apps are not preloaded. |
| 143 | * @param packageList List of package names to keep cached. |
| 144 | */ |
| 145 | public abstract void setKeepUninstalledPackages(List<String> packageList); |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * Gets whether some of the permissions used by this package require a user |
| 149 | * review before any of the app components can run. |
| 150 | * @param packageName The package name for which to check. |
| 151 | * @param userId The user under which to check. |
| 152 | * @return True a permissions review is required. |
| 153 | */ |
| 154 | public abstract boolean isPermissionsReviewRequired(String packageName, int userId); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 155 | |
| 156 | /** |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 157 | * Retrieve all of the information we know about a particular package/application. |
| 158 | * @param filterCallingUid The results will be filtered in the context of this UID instead |
| 159 | * of the calling UID. |
| 160 | * @see PackageManager#getPackageInfo(String, int) |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 161 | */ |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 162 | public abstract PackageInfo getPackageInfo(String packageName, |
| 163 | @PackageInfoFlags int flags, int filterCallingUid, int userId); |
| 164 | |
| 165 | /** |
Ricky Wai | 5a8fe7a | 2019-12-13 15:20:47 +0000 | [diff] [blame] | 166 | * Retrieve CE data directory inode number of an application. |
| 167 | * Return 0 if there's error. |
| 168 | */ |
| 169 | public abstract long getCeDataInode(String packageName, int userId); |
| 170 | |
| 171 | /** |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 172 | * Return a List of all application packages that are installed on the |
| 173 | * device, for a specific user. If flag GET_UNINSTALLED_PACKAGES has been |
| 174 | * set, a list of all applications including those deleted with |
Sudheer Shanka | 31961ce | 2020-01-22 20:41:27 -0800 | [diff] [blame] | 175 | * {@code DELETE_KEEP_DATA} (partially installed apps with data directory) |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 176 | * will be returned. |
| 177 | * |
| 178 | * @param flags Additional option flags to modify the data returned. |
| 179 | * @param userId The user for whom the installed applications are to be |
| 180 | * listed |
| 181 | * @param callingUid The uid of the original caller app |
| 182 | * @return A List of ApplicationInfo objects, one for each installed |
| 183 | * application. In the unlikely case there are no installed |
| 184 | * packages, an empty list is returned. If flag |
| 185 | * {@code MATCH_UNINSTALLED_PACKAGES} is set, the application |
| 186 | * information is retrieved from the list of uninstalled |
| 187 | * applications (which includes installed applications as well as |
| 188 | * applications with data directory i.e. applications which had been |
Sudheer Shanka | 31961ce | 2020-01-22 20:41:27 -0800 | [diff] [blame] | 189 | * deleted with {@code DELETE_KEEP_DATA} flag set). |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 190 | */ |
| 191 | public abstract List<ApplicationInfo> getInstalledApplications( |
| 192 | @ApplicationInfoFlags int flags, @UserIdInt int userId, int callingUid); |
| 193 | |
| 194 | /** |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 195 | * Retrieve launcher extras for a suspended package provided to the system in |
| 196 | * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 197 | * PersistableBundle, String)}. |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 198 | * |
| 199 | * @param packageName The package for which to return launcher extras. |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 200 | * @param userId The user for which to check. |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 201 | * @return The launcher extras. |
| 202 | * |
| 203 | * @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, |
| 204 | * PersistableBundle, String) |
| 205 | * @see PackageManager#isPackageSuspended() |
| 206 | */ |
| 207 | public abstract Bundle getSuspendedPackageLauncherExtras(String packageName, |
| 208 | int userId); |
| 209 | |
| 210 | /** |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 211 | * Internal api to query the suspended state of a package. |
| 212 | * @param packageName The package to check. |
| 213 | * @param userId The user id to check for. |
| 214 | * @return {@code true} if the package is suspended, {@code false} otherwise. |
| 215 | * @see PackageManager#isPackageSuspended(String) |
| 216 | */ |
| 217 | public abstract boolean isPackageSuspended(String packageName, int userId); |
| 218 | |
| 219 | /** |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 220 | * Get the name of the package that suspended the given package. Packages can be suspended by |
| 221 | * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or |
| 222 | * {@link android.Manifest.permission#SUSPEND_APPS}. |
| 223 | * |
| 224 | * @param suspendedPackage The package that has been suspended. |
| 225 | * @param userId The user for which to check. |
| 226 | * @return Name of the package that suspended the given package. Returns {@code null} if the |
| 227 | * given package is not currently suspended and the platform package name - i.e. |
| 228 | * {@code "android"} - if the package was suspended by a device admin. |
| 229 | */ |
| 230 | public abstract String getSuspendingPackage(String suspendedPackage, int userId); |
| 231 | |
| 232 | /** |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 233 | * Get the information describing the dialog to be shown to the user when they try to launch a |
| 234 | * suspended application. |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 235 | * |
| 236 | * @param suspendedPackage The package that has been suspended. |
Suprabh Shukla | d327844 | 2019-08-27 15:58:03 -0700 | [diff] [blame] | 237 | * @param suspendingPackage |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 238 | * @param userId The user for which to check. |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 239 | * @return A {@link SuspendDialogInfo} object describing the dialog to be shown. |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 240 | */ |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 241 | @Nullable |
Suprabh Shukla | d327844 | 2019-08-27 15:58:03 -0700 | [diff] [blame] | 242 | public abstract SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage, |
| 243 | String suspendingPackage, int userId); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 244 | |
| 245 | /** |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 246 | * Gets any distraction flags set via |
| 247 | * {@link PackageManager#setDistractingPackageRestrictions(String[], int)} |
| 248 | * |
| 249 | * @param packageName |
| 250 | * @param userId |
| 251 | * @return A bitwise OR of any of the {@link PackageManager.DistractionRestriction} |
| 252 | */ |
| 253 | public abstract @PackageManager.DistractionRestriction int getDistractingPackageRestrictions( |
| 254 | String packageName, int userId); |
| 255 | |
| 256 | /** |
Patrick Baumann | 26050db | 2020-01-23 10:12:22 -0800 | [diff] [blame] | 257 | * Do a straight uid lookup for the given package/application in the given user. This enforces |
| 258 | * app visibility rules and permissions. Call {@link #getPackageUidInternal} for the internal |
| 259 | * implementation. |
| 260 | * @deprecated Use {@link PackageManager#getPackageUid(String, int)} |
| 261 | * @return The app's uid, or < 0 if the package was not found in that user |
| 262 | */ |
| 263 | @Deprecated |
| 264 | public abstract int getPackageUid(String packageName, |
| 265 | @PackageInfoFlags int flags, int userId); |
| 266 | |
| 267 | /** |
Christopher Tate | a732f01 | 2017-10-26 17:26:53 -0700 | [diff] [blame] | 268 | * Do a straight uid lookup for the given package/application in the given user. |
| 269 | * @see PackageManager#getPackageUidAsUser(String, int, int) |
| 270 | * @return The app's uid, or < 0 if the package was not found in that user |
Patrick Baumann | 26050db | 2020-01-23 10:12:22 -0800 | [diff] [blame] | 271 | * TODO(b/148235092): rename this to getPackageUid |
Christopher Tate | a732f01 | 2017-10-26 17:26:53 -0700 | [diff] [blame] | 272 | */ |
Patrick Baumann | 26050db | 2020-01-23 10:12:22 -0800 | [diff] [blame] | 273 | public abstract int getPackageUidInternal(String packageName, |
Christopher Tate | a732f01 | 2017-10-26 17:26:53 -0700 | [diff] [blame] | 274 | @PackageInfoFlags int flags, int userId); |
| 275 | |
| 276 | /** |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 277 | * Retrieve all of the information we know about a particular package/application. |
| 278 | * @param filterCallingUid The results will be filtered in the context of this UID instead |
| 279 | * of the calling UID. |
| 280 | * @see PackageManager#getApplicationInfo(String, int) |
| 281 | */ |
| 282 | public abstract ApplicationInfo getApplicationInfo(String packageName, |
| 283 | @ApplicationInfoFlags int flags, int filterCallingUid, int userId); |
| 284 | |
| 285 | /** |
| 286 | * Retrieve all of the information we know about a particular activity class. |
| 287 | * @param filterCallingUid The results will be filtered in the context of this UID instead |
| 288 | * of the calling UID. |
| 289 | * @see PackageManager#getActivityInfo(ComponentName, int) |
| 290 | */ |
| 291 | public abstract ActivityInfo getActivityInfo(ComponentName component, |
| 292 | @ComponentInfoFlags int flags, int filterCallingUid, int userId); |
| 293 | |
| 294 | /** |
| 295 | * Retrieve all activities that can be performed for the given intent. |
Patrick Baumann | 182ea1c | 2019-11-18 13:43:11 -0800 | [diff] [blame] | 296 | * @param resolvedType the resolved type of the intent, which should be resolved via |
| 297 | * {@link Intent#resolveTypeIfNeeded(ContentResolver)} before passing to {@link PackageManager} |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 298 | * @param filterCallingUid The results will be filtered in the context of this UID instead |
| 299 | * of the calling UID. |
| 300 | * @see PackageManager#queryIntentActivities(Intent, int) |
| 301 | */ |
Patrick Baumann | 182ea1c | 2019-11-18 13:43:11 -0800 | [diff] [blame] | 302 | public abstract List<ResolveInfo> queryIntentActivities( |
| 303 | Intent intent, @Nullable String resolvedType, @ResolveInfoFlags int flags, |
| 304 | int filterCallingUid, int userId); |
| 305 | |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 306 | |
| 307 | /** |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 308 | * Retrieve all services that can be performed for the given intent. |
| 309 | * @see PackageManager#queryIntentServices(Intent, int) |
| 310 | */ |
| 311 | public abstract List<ResolveInfo> queryIntentServices( |
| 312 | Intent intent, int flags, int callingUid, int userId); |
| 313 | |
| 314 | /** |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 315 | * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}. |
| 316 | */ |
| 317 | public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, |
| 318 | int userId); |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 319 | |
| 320 | /** |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 321 | * @return The default home activity component name. |
| 322 | */ |
| 323 | public abstract ComponentName getDefaultHomeActivity(int userId); |
| 324 | |
| 325 | /** |
Winson Chung | f2b4177 | 2019-11-06 15:00:48 -0800 | [diff] [blame] | 326 | * @return The SystemUI service component name. |
| 327 | */ |
| 328 | public abstract ComponentName getSystemUiServiceComponent(); |
| 329 | |
| 330 | /** |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 331 | * Called by DeviceOwnerManagerService to set the package names of device owner and profile |
| 332 | * owners. |
| 333 | */ |
| 334 | public abstract void setDeviceAndProfileOwnerPackages( |
| 335 | int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners); |
| 336 | |
| 337 | /** |
Srinivas Paladugu | 0bb962c | 2019-10-25 10:03:14 -0700 | [diff] [blame] | 338 | * Called by DevicePolicyManagerService to set the package names protected by the device |
| 339 | * owner. |
| 340 | */ |
| 341 | public abstract void setDeviceOwnerProtectedPackages(List<String> packageNames); |
| 342 | |
| 343 | /** |
Steven Ng | 9d48a73 | 2016-06-24 19:04:14 +0100 | [diff] [blame] | 344 | * Returns {@code true} if a given package can't be wiped. Otherwise, returns {@code false}. |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 345 | */ |
Steven Ng | 9d48a73 | 2016-06-24 19:04:14 +0100 | [diff] [blame] | 346 | public abstract boolean isPackageDataProtected(int userId, String packageName); |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 347 | |
| 348 | /** |
Benjamin Franz | f81bf7f | 2018-03-26 16:23:04 +0100 | [diff] [blame] | 349 | * Returns {@code true} if a given package's state is protected, e.g. it cannot be force |
| 350 | * stopped, suspended, disabled or hidden. Otherwise, returns {@code false}. |
| 351 | */ |
| 352 | public abstract boolean isPackageStateProtected(String packageName, int userId); |
| 353 | |
| 354 | /** |
Dianne Hackborn | e07641d | 2016-11-09 15:07:23 -0800 | [diff] [blame] | 355 | * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns |
| 356 | * {@code false}. |
| 357 | */ |
| 358 | public abstract boolean isPackageEphemeral(int userId, String packageName); |
| 359 | |
| 360 | /** |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 361 | * Gets whether the package was ever launched. |
| 362 | * @param packageName The package name. |
| 363 | * @param userId The user for which to check. |
| 364 | * @return Whether was launched. |
Amith Yamasani | 2cbfa1e | 2017-03-28 10:34:01 -0700 | [diff] [blame] | 365 | * @throws IllegalArgumentException if the package is not found |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 366 | */ |
| 367 | public abstract boolean wasPackageEverLaunched(String packageName, int userId); |
Nicolas Prevot | 700e1e7 | 2016-09-28 15:17:18 +0100 | [diff] [blame] | 368 | |
| 369 | /** |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 370 | * Retrieve the official name associated with a uid. This name is |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 371 | * guaranteed to never change, though it is possible for the underlying |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 372 | * uid to be changed. That is, if you are storing information about |
| 373 | * uids in persistent storage, you should use the string returned |
| 374 | * by this function instead of the raw uid. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 375 | * |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 376 | * @param uid The uid for which you would like to retrieve a name. |
| 377 | * @return Returns a unique name for the given uid, or null if the |
| 378 | * uid is not currently assigned. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 379 | */ |
| 380 | public abstract String getNameForUid(int uid); |
| 381 | |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 382 | /** |
Bookatz | 04d7ae5 | 2019-08-05 14:07:12 -0700 | [diff] [blame] | 383 | * Marks a package as installed (or not installed) for a given user. |
| 384 | * |
| 385 | * @param pkg the package whose installation is to be set |
| 386 | * @param userId the user for whom to set it |
| 387 | * @param installed the new installed state |
| 388 | * @return true if the installed state changed as a result |
| 389 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 390 | public abstract boolean setInstalled(AndroidPackage pkg, |
Bookatz | 04d7ae5 | 2019-08-05 14:07:12 -0700 | [diff] [blame] | 391 | @UserIdInt int userId, boolean installed); |
| 392 | |
| 393 | /** |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 394 | * Request to perform the second phase of ephemeral resolution. |
| 395 | * @param responseObj The response of the first phase of ephemeral resolution |
| 396 | * @param origIntent The original intent that triggered ephemeral resolution |
| 397 | * @param resolvedType The resolved type of the intent |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 398 | * @param callingPkg The app requesting the ephemeral application |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 399 | * @param callingFeatureId The feature in the package |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 400 | * @param isRequesterInstantApp Whether or not the app requesting the ephemeral application |
| 401 | * is an instant app |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 402 | * @param verificationBundle Optional bundle to pass to the installer for additional |
| 403 | * verification |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 404 | * @param userId The ID of the user that triggered ephemeral resolution |
| 405 | */ |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 406 | public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, |
Winson | 81fef84 | 2019-08-28 12:19:08 -0700 | [diff] [blame] | 407 | Intent origIntent, String resolvedType, String callingPkg, |
Philip P. Moltmann | 9c5226f | 2020-01-10 08:53:43 -0800 | [diff] [blame^] | 408 | @Nullable String callingFeatureId, boolean isRequesterInstantApp, |
| 409 | Bundle verificationBundle, int userId); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 410 | |
| 411 | /** |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 412 | * Grants implicit access based on an interaction between two apps. This grants the target app |
| 413 | * access to the calling application's package metadata. |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 414 | * <p> |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 415 | * When an application explicitly tries to interact with another application [via an |
| 416 | * activity, service or provider that is either declared in the caller's |
| 417 | * manifest via the {@code <queries>} tag or has been exposed via the target apps manifest using |
| 418 | * the {@code visibleToInstantApp} attribute], the target application must be able to see |
| 419 | * metadata about the calling app. If the calling application uses an implicit intent [ie |
| 420 | * action VIEW, category BROWSABLE], it remains hidden from the launched app. |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 421 | * <p> |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 422 | * @param userId the user |
| 423 | * @param intent the intent that triggered the grant |
Patrick Baumann | b6e7297 | 2019-09-20 07:54:47 -0700 | [diff] [blame] | 424 | * @param callingUid The uid of the calling application |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 425 | * @param targetAppId The app ID of the target application |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 426 | */ |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 427 | public abstract void grantImplicitAccess( |
Patrick Baumann | b6e7297 | 2019-09-20 07:54:47 -0700 | [diff] [blame] | 428 | @UserIdInt int userId, Intent intent, int callingUid, |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 429 | @AppIdInt int targetAppId); |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 430 | |
Todd Kennedy | b21be12 | 2017-03-24 14:10:01 -0700 | [diff] [blame] | 431 | public abstract boolean isInstantAppInstallerComponent(ComponentName component); |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 432 | /** |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 433 | * Prunes instant apps and state associated with uninstalled |
| 434 | * instant apps according to the current platform policy. |
| 435 | */ |
| 436 | public abstract void pruneInstantApps(); |
| 437 | |
| 438 | /** |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 439 | * @return The SetupWizard package name. |
| 440 | */ |
| 441 | public abstract String getSetupWizardPackageName(); |
Suprabh Shukla | aef2513 | 2017-01-23 18:09:03 -0800 | [diff] [blame] | 442 | |
| 443 | public interface ExternalSourcesPolicy { |
| 444 | |
| 445 | int USER_TRUSTED = 0; // User has trusted the package to install apps |
| 446 | int USER_BLOCKED = 1; // User has blocked the package to install apps |
| 447 | int USER_DEFAULT = 2; // Default code to use when user response is unavailable |
| 448 | |
| 449 | /** |
| 450 | * Checks the user preference for whether a package is trusted to request installs through |
| 451 | * package installer |
| 452 | * |
| 453 | * @param packageName The package to check for |
| 454 | * @param uid the uid in which the package is running |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 455 | * @return {@link #USER_TRUSTED} if the user has trusted the package, {@link #USER_BLOCKED} |
| 456 | * if user has blocked requests from the package, {@link #USER_DEFAULT} if the user response |
Suprabh Shukla | aef2513 | 2017-01-23 18:09:03 -0800 | [diff] [blame] | 457 | * is not yet available |
| 458 | */ |
| 459 | int getPackageTrustedToInstallApps(String packageName, int uid); |
| 460 | } |
| 461 | |
| 462 | public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy); |
MÃ¥rten Kongstad | eabc9e9 | 2015-12-15 16:40:23 +0100 | [diff] [blame] | 463 | |
| 464 | /** |
Dianne Hackborn | b1e7776 | 2017-02-13 11:42:18 -0800 | [diff] [blame] | 465 | * Return true if the given package is a persistent app process. |
| 466 | */ |
| 467 | public abstract boolean isPackagePersistent(String packageName); |
| 468 | |
| 469 | /** |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 470 | * Returns whether or not the given package represents a legacy system application released |
| 471 | * prior to runtime permissions. |
| 472 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 473 | public abstract boolean isLegacySystemApp(AndroidPackage pkg); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 474 | |
| 475 | /** |
MÃ¥rten Kongstad | eabc9e9 | 2015-12-15 16:40:23 +0100 | [diff] [blame] | 476 | * Get all overlay packages for a user. |
| 477 | * @param userId The user for which to get the overlays. |
| 478 | * @return A list of overlay packages. An empty list is returned if the |
| 479 | * user has no installed overlay packages. |
| 480 | */ |
| 481 | public abstract List<PackageInfo> getOverlayPackages(int userId); |
| 482 | |
| 483 | /** |
| 484 | * Get the names of all target packages for a user. |
| 485 | * @param userId The user for which to get the package names. |
| 486 | * @return A list of target package names. This list includes the "android" package. |
| 487 | */ |
| 488 | public abstract List<String> getTargetPackageNames(int userId); |
| 489 | |
| 490 | /** |
| 491 | * Set which overlay to use for a package. |
| 492 | * @param userId The user for which to update the overlays. |
| 493 | * @param targetPackageName The package name of the package for which to update the overlays. |
| 494 | * @param overlayPackageNames The complete list of overlay packages that should be enabled for |
| 495 | * the target. Previously enabled overlays not specified in the list |
| 496 | * will be disabled. Pass in null or an empty list to disable |
| 497 | * all overlays. The order of the items is significant if several |
| 498 | * overlays modify the same resource. |
Ryan Mitchell | ee4a564 | 2019-10-16 08:32:55 -0700 | [diff] [blame] | 499 | * @param outUpdatedPackageNames An output list that contains the package names of packages |
| 500 | * affected by the update of enabled overlays. |
MÃ¥rten Kongstad | eabc9e9 | 2015-12-15 16:40:23 +0100 | [diff] [blame] | 501 | * @return true if all packages names were known by the package manager, false otherwise |
| 502 | */ |
| 503 | public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName, |
Ryan Mitchell | ee4a564 | 2019-10-16 08:32:55 -0700 | [diff] [blame] | 504 | List<String> overlayPackageNames, Collection<String> outUpdatedPackageNames); |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 505 | |
| 506 | /** |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 507 | * Resolves an activity intent, allowing instant apps to be resolved. |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 508 | */ |
| 509 | public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 510 | int flags, int userId, boolean resolveForStart, int filterCallingUid); |
Chad Brubaker | 0f28a80 | 2017-03-29 14:05:52 -0700 | [diff] [blame] | 511 | |
| 512 | /** |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 513 | * Resolves a service intent, allowing instant apps to be resolved. |
| 514 | */ |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 515 | public abstract ResolveInfo resolveService(Intent intent, String resolvedType, |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 516 | int flags, int userId, int callingUid); |
| 517 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 518 | /** |
| 519 | * Resolves a content provider intent. |
| 520 | */ |
| 521 | public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId); |
| 522 | |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 523 | /** |
Chad Brubaker | 0f28a80 | 2017-03-29 14:05:52 -0700 | [diff] [blame] | 524 | * Track the creator of a new isolated uid. |
| 525 | * @param isolatedUid The newly created isolated uid. |
| 526 | * @param ownerUid The uid of the app that created the isolated process. |
| 527 | */ |
| 528 | public abstract void addIsolatedUid(int isolatedUid, int ownerUid); |
| 529 | |
| 530 | /** |
| 531 | * Track removal of an isolated uid. |
| 532 | * @param isolatedUid isolated uid that is no longer being used. |
| 533 | */ |
| 534 | public abstract void removeIsolatedUid(int isolatedUid); |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 535 | |
| 536 | /** |
| 537 | * Return the taget SDK version for the app with the given UID. |
| 538 | */ |
| 539 | public abstract int getUidTargetSdkVersion(int uid); |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 540 | |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 541 | /** |
| 542 | * Return the taget SDK version for the app with the given package name. |
| 543 | */ |
| 544 | public abstract int getPackageTargetSdkVersion(String packageName); |
| 545 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 546 | /** Whether the binder caller can access instant apps. */ |
Todd Kennedy | 3051caa | 2017-05-23 15:54:18 -0700 | [diff] [blame] | 547 | public abstract boolean canAccessInstantApps(int callingUid, int userId); |
Svet Ganov | f935a70 | 2017-08-22 12:15:58 -0700 | [diff] [blame] | 548 | |
Todd Kennedy | 662504f | 2018-03-14 08:09:00 -0700 | [diff] [blame] | 549 | /** Whether the binder caller can access the given component. */ |
| 550 | public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId); |
| 551 | |
Svet Ganov | f935a70 | 2017-08-22 12:15:58 -0700 | [diff] [blame] | 552 | /** |
| 553 | * Returns {@code true} if a given package has instant application meta-data. |
| 554 | * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc) |
| 555 | * associated with an instant app. It may be kept after the instant app has been uninstalled. |
| 556 | */ |
| 557 | public abstract boolean hasInstantApplicationMetadata(String packageName, int userId); |
Todd Kennedy | df113c3 | 2017-08-31 16:10:29 -0700 | [diff] [blame] | 558 | |
| 559 | /** |
| 560 | * Updates a package last used time. |
| 561 | */ |
| 562 | public abstract void notifyPackageUse(String packageName, int reason); |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 563 | |
| 564 | /** |
| 565 | * Returns a package object for the given package name. |
| 566 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 567 | public abstract @Nullable AndroidPackage getPackage(@NonNull String packageName); |
| 568 | |
| 569 | // TODO(b/135203078): PackageSetting can't be referenced directly. Should move to a server side |
| 570 | // internal PM which is aware of PS. |
| 571 | public abstract @Nullable Object getPackageSetting(String packageName); |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 572 | |
| 573 | /** |
Todd Kennedy | ca1ea17 | 2019-07-03 15:02:28 -0700 | [diff] [blame] | 574 | * Returns a package for the given UID. If the UID is part of a shared user ID, one |
| 575 | * of the packages will be chosen to be returned. |
| 576 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 577 | public abstract @Nullable AndroidPackage getPackage(int uid); |
Todd Kennedy | ca1ea17 | 2019-07-03 15:02:28 -0700 | [diff] [blame] | 578 | |
| 579 | /** |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 580 | * Returns a list without a change observer. |
| 581 | * |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 582 | * @see #getPackageList(PackageListObserver) |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 583 | */ |
| 584 | public @NonNull PackageList getPackageList() { |
| 585 | return getPackageList(null); |
| 586 | } |
| 587 | |
| 588 | /** |
| 589 | * Returns the list of packages installed at the time of the method call. |
| 590 | * <p>The given observer is notified when the list of installed packages |
| 591 | * changes [eg. a package was installed or uninstalled]. It will not be |
| 592 | * notified if a package is updated. |
| 593 | * <p>The package list will not be updated automatically as packages are |
| 594 | * installed / uninstalled. Any changes must be handled within the observer. |
| 595 | */ |
| 596 | public abstract @NonNull PackageList getPackageList(@Nullable PackageListObserver observer); |
| 597 | |
| 598 | /** |
| 599 | * Removes the observer. |
| 600 | * <p>Generally not needed. {@link #getPackageList(PackageListObserver)} will automatically |
| 601 | * remove the observer. |
| 602 | * <p>Does nothing if the observer isn't currently registered. |
| 603 | * <p>Observers are notified asynchronously and it's possible for an observer to be |
| 604 | * invoked after its been removed. |
| 605 | */ |
| 606 | public abstract void removePackageListObserver(@NonNull PackageListObserver observer); |
| 607 | |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 608 | // TODO(b/135203078): PackageSetting can't be referenced directly |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 609 | /** |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 610 | * Returns a package object for the disabled system package name. |
| 611 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 612 | public abstract @Nullable Object getDisabledSystemPackage(@NonNull String packageName); |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 613 | |
| 614 | /** |
| 615 | * Returns the package name for the disabled system package. |
| 616 | * |
| 617 | * This is equivalent to |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 618 | * {@link #getDisabledSystemPackage(String)} |
| 619 | * .{@link com.android.server.pm.PackageSetting#pkg} |
| 620 | * .{@link AndroidPackage#getPackageName()} |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 621 | */ |
| 622 | public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName); |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 623 | |
| 624 | /** |
| 625 | * Returns whether or not the component is the resolver activity. |
| 626 | */ |
| 627 | public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component); |
| 628 | |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 629 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 630 | /** |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 631 | * Returns a list of package names for a known package |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 632 | */ |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 633 | public abstract @NonNull String[] getKnownPackageNames( |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 634 | @KnownPackage int knownPackage, int userId); |
| 635 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 636 | /** |
| 637 | * Returns whether the package is an instant app. |
| 638 | */ |
| 639 | public abstract boolean isInstantApp(String packageName, int userId); |
| 640 | |
| 641 | /** |
| 642 | * Returns whether the package is an instant app. |
| 643 | */ |
| 644 | public abstract @Nullable String getInstantAppPackageName(int uid); |
| 645 | |
| 646 | /** |
| 647 | * Returns whether or not access to the application should be filtered. |
| 648 | * <p> |
| 649 | * Access may be limited based upon whether the calling or target applications |
| 650 | * are instant applications. |
| 651 | * |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 652 | * @see #canAccessInstantApps |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 653 | */ |
| 654 | public abstract boolean filterAppAccess( |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 655 | @NonNull AndroidPackage pkg, int callingUid, int userId); |
Todd Kennedy | c5b0e86 | 2019-07-16 09:47:58 -0700 | [diff] [blame] | 656 | |
| 657 | /** |
| 658 | * Returns whether or not access to the application should be filtered. |
| 659 | * |
| 660 | * @see #filterAppAccess(android.content.pm.PackageParser.Package, int, int) |
| 661 | */ |
| 662 | public abstract boolean filterAppAccess( |
| 663 | @NonNull String packageName, int callingUid, int userId); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 664 | |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 665 | /** Returns whether the given package was signed by the platform */ |
| 666 | public abstract boolean isPlatformSigned(String pkg); |
| 667 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 668 | /** |
| 669 | * Returns true if it's still safe to restore data backed up from this app's version |
| 670 | * that was signed with restoringFromSigHash. |
| 671 | */ |
| 672 | public abstract boolean isDataRestoreSafe(@NonNull byte[] restoringFromSigHash, |
| 673 | @NonNull String packageName); |
| 674 | |
| 675 | /** |
| 676 | * Returns true if it's still safe to restore data backed up from this app's version |
| 677 | * that was signed with restoringFromSig. |
| 678 | */ |
| 679 | public abstract boolean isDataRestoreSafe(@NonNull Signature restoringFromSig, |
| 680 | @NonNull String packageName); |
Dan Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 681 | |
Dan Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 682 | /** |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 683 | * Returns {@code true} if the the signing information for {@code clientUid} is sufficient |
| 684 | * to gain access gated by {@code capability}. This can happen if the two UIDs have the |
| 685 | * same signing information, if the signing information {@code clientUid} indicates that |
| 686 | * it has the signing certificate for {@code serverUid} in its signing history (if it was |
| 687 | * previously signed by it), or if the signing certificate for {@code clientUid} is in the |
| 688 | * signing history for {@code serverUid} and with the {@code capability} specified. |
Dan Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 689 | */ |
| 690 | public abstract boolean hasSignatureCapability(int serverUid, int clientUid, |
| 691 | @PackageParser.SigningDetails.CertCapabilities int capability); |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 692 | |
| 693 | /** |
Sudheer Shanka | 0a541a5 | 2018-07-31 13:21:11 -0700 | [diff] [blame] | 694 | * Get appIds of all available apps which specified android:sharedUserId in the manifest. |
| 695 | * |
| 696 | * @return a SparseArray mapping from appId to it's sharedUserId. |
| 697 | */ |
| 698 | public abstract SparseArray<String> getAppsWithSharedUserIds(); |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 699 | |
| 700 | /** |
Alan Stokes | 20fbef2 | 2019-12-17 15:33:12 +0000 | [diff] [blame] | 701 | * Get all packages which share the same userId as the specified package, or an empty array |
| 702 | * if the package does not have a shared userId. |
Sudheer Shanka | 2ac25a9 | 2018-10-25 10:59:32 -0700 | [diff] [blame] | 703 | */ |
Alan Stokes | 20fbef2 | 2019-12-17 15:33:12 +0000 | [diff] [blame] | 704 | @NonNull |
| 705 | public abstract String[] getSharedUserPackagesForPackage(@NonNull String packageName, |
| 706 | int userId); |
Sudheer Shanka | 2ac25a9 | 2018-10-25 10:59:32 -0700 | [diff] [blame] | 707 | |
| 708 | /** |
Dianne Hackborn | f6729fa | 2020-01-06 13:12:36 -0800 | [diff] [blame] | 709 | * Return the processes that have been declared for a uid. |
| 710 | * |
| 711 | * @param uid The uid to query. |
| 712 | * |
| 713 | * @return Returns null if there are no declared processes for the uid; otherwise, |
| 714 | * returns the set of processes it declared. |
| 715 | */ |
| 716 | public abstract ArrayMap<String, ProcessInfo> getProcessesForUid(int uid); |
| 717 | |
| 718 | /** |
| 719 | * Return the gids associated with a particular permission. |
| 720 | * |
| 721 | * @param permissionName The name of the permission to query. |
| 722 | * @param userId The user id the gids will be associated with. |
| 723 | * |
| 724 | * @return Returns null if there are no gids associated with the permission, otherwise an |
| 725 | * array if the gid ints. |
| 726 | */ |
| 727 | public abstract int[] getPermissionGids(String permissionName, int userId); |
| 728 | |
| 729 | /** |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 730 | * Return if device is currently in a "core" boot environment, typically |
| 731 | * used to support full-disk encryption. Only apps marked with |
| 732 | * {@code coreApp} attribute are available. |
| 733 | */ |
| 734 | public abstract boolean isOnlyCoreApps(); |
| 735 | |
| 736 | /** |
| 737 | * Make a best-effort attempt to provide the requested free disk space by |
| 738 | * deleting cached files. |
| 739 | * |
| 740 | * @throws IOException if the request was unable to be fulfilled. |
| 741 | */ |
| 742 | public abstract void freeStorage(String volumeUuid, long bytes, int storageFlags) |
| 743 | throws IOException; |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 744 | |
| 745 | /** Returns {@code true} if the specified component is enabled and matches the given flags. */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 746 | public abstract boolean isEnabledAndMatches( |
| 747 | @NonNull ComponentParseUtils.ParsedComponent component, int flags, int userId); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 748 | |
| 749 | /** Returns {@code true} if the given user requires extra badging for icons. */ |
| 750 | public abstract boolean userNeedsBadging(int userId); |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 751 | |
| 752 | /** |
| 753 | * Perform the given action for each package. |
| 754 | * Note that packages lock will be held while performin the actions. |
| 755 | * |
| 756 | * @param actionLocked action to be performed |
| 757 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 758 | public abstract void forEachPackage(Consumer<AndroidPackage> actionLocked); |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 759 | |
Hai Zhang | eb8b460 | 2019-05-22 13:04:12 -0700 | [diff] [blame] | 760 | /** |
| 761 | * Perform the given action for each installed package for a user. |
| 762 | * Note that packages lock will be held while performin the actions. |
| 763 | */ |
| 764 | public abstract void forEachInstalledPackage( |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 765 | @NonNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId); |
Hai Zhang | eb8b460 | 2019-05-22 13:04:12 -0700 | [diff] [blame] | 766 | |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 767 | /** Returns the list of enabled components */ |
| 768 | public abstract ArraySet<String> getEnabledComponents(String packageName, int userId); |
| 769 | |
| 770 | /** Returns the list of disabled components */ |
| 771 | public abstract ArraySet<String> getDisabledComponents(String packageName, int userId); |
| 772 | |
| 773 | /** Returns whether the given package is enabled for the given user */ |
| 774 | public abstract @PackageManager.EnabledState int getApplicationEnabledState( |
| 775 | String packageName, int userId); |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 776 | |
| 777 | /** |
| 778 | * Extra field name for the token of a request to enable rollback for a |
| 779 | * package. |
| 780 | */ |
| 781 | public static final String EXTRA_ENABLE_ROLLBACK_TOKEN = |
| 782 | "android.content.pm.extra.ENABLE_ROLLBACK_TOKEN"; |
| 783 | |
| 784 | /** |
| 785 | * Extra field name for the installFlags of a request to enable rollback |
| 786 | * for a package. |
| 787 | */ |
| 788 | public static final String EXTRA_ENABLE_ROLLBACK_INSTALL_FLAGS = |
| 789 | "android.content.pm.extra.ENABLE_ROLLBACK_INSTALL_FLAGS"; |
| 790 | |
| 791 | /** |
Richard Uhler | 82913b7 | 2019-04-01 13:02:31 +0100 | [diff] [blame] | 792 | * Extra field name for the user id an install is associated with when |
| 793 | * enabling rollback. |
| 794 | */ |
| 795 | public static final String EXTRA_ENABLE_ROLLBACK_USER = |
| 796 | "android.content.pm.extra.ENABLE_ROLLBACK_USER"; |
| 797 | |
| 798 | /** |
Richard Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 799 | * Used as the {@code enableRollbackCode} argument for |
| 800 | * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that |
| 801 | * enabling rollback succeeded. |
| 802 | */ |
| 803 | public static final int ENABLE_ROLLBACK_SUCCEEDED = 1; |
| 804 | |
| 805 | /** |
| 806 | * Used as the {@code enableRollbackCode} argument for |
| 807 | * {@link PackageManagerInternal#setEnableRollbackCode} to indicate that |
| 808 | * enabling rollback failed. |
| 809 | */ |
| 810 | public static final int ENABLE_ROLLBACK_FAILED = -1; |
| 811 | |
| 812 | /** |
| 813 | * Allows the rollback manager listening to the |
| 814 | * {@link Intent#ACTION_PACKAGE_ENABLE_ROLLBACK enable rollback broadcast} |
| 815 | * to respond to the package manager. The response must include the |
| 816 | * {@code enableRollbackCode} which is one of |
| 817 | * {@link PackageManager#ENABLE_ROLLBACK_SUCCEEDED} or |
| 818 | * {@link PackageManager#ENABLE_ROLLBACK_FAILED}. |
| 819 | * |
| 820 | * @param token pending package identifier as passed via the |
| 821 | * {@link PackageManager#EXTRA_ENABLE_ROLLBACK_TOKEN} Intent extra. |
| 822 | * @param enableRollbackCode the status code result of enabling rollback |
| 823 | * @throws SecurityException if the caller does not have the |
| 824 | * PACKAGE_ROLLBACK_AGENT permission. |
| 825 | */ |
| 826 | public abstract void setEnableRollbackCode(int token, int enableRollbackCode); |
Eric Holk | a1485f6 | 2019-01-07 13:58:25 -0800 | [diff] [blame] | 827 | |
| 828 | /** |
| 829 | * Ask the package manager to compile layouts in the given package. |
| 830 | */ |
| 831 | public abstract boolean compileLayouts(String packageName); |
Narayan Kamath | 869f706 | 2019-01-10 12:24:15 +0000 | [diff] [blame] | 832 | |
| 833 | /* |
| 834 | * Inform the package manager that the pending package install identified by |
| 835 | * {@code token} can be completed. |
| 836 | */ |
| 837 | public abstract void finishPackageInstall(int token, boolean didLaunch); |
Hai Zhang | a22cd83 | 2019-01-30 13:38:43 -0800 | [diff] [blame] | 838 | |
| 839 | /** |
| 840 | * Remove the default browser stored in the legacy package settings. |
| 841 | * |
| 842 | * @param userId the user id |
| 843 | * |
| 844 | * @return the package name of the default browser, or {@code null} if none |
| 845 | */ |
| 846 | @Nullable |
| 847 | public abstract String removeLegacyDefaultBrowserPackageName(int userId); |
Hai Zhang | 85fd062 | 2019-02-01 14:06:04 -0800 | [diff] [blame] | 848 | |
| 849 | /** |
Nikita Ioffe | f012a22 | 2019-03-05 22:37:55 +0000 | [diff] [blame] | 850 | * Returns {@code true} if given {@code packageName} is an apex package. |
| 851 | */ |
| 852 | public abstract boolean isApexPackage(String packageName); |
| 853 | |
| 854 | /** |
Mohammad Samiul Islam | 3fcecfc | 2019-12-20 17:46:01 +0000 | [diff] [blame] | 855 | * Returns list of {@code packageName} of apks inside the given apex. |
| 856 | * @param apexPackageName Package name of the apk container of apex |
| 857 | */ |
| 858 | public abstract List<String> getApksInApex(String apexPackageName); |
| 859 | |
| 860 | /** |
Nikita Ioffe | f012a22 | 2019-03-05 22:37:55 +0000 | [diff] [blame] | 861 | * Uninstalls given {@code packageName}. |
| 862 | * |
| 863 | * @param packageName apex package to uninstall. |
| 864 | * @param versionCode version of a package to uninstall. |
| 865 | * @param userId user to uninstall apex package for. Must be |
| 866 | * {@link android.os.UserHandle#USER_ALL}, otherwise failure will be reported. |
| 867 | * @param intentSender a {@link IntentSender} to send result of an uninstall to. |
Gavin Corkery | 4fd1088 | 2019-11-28 15:37:51 +0000 | [diff] [blame] | 868 | * @param flags flags about the uninstall. |
Nikita Ioffe | f012a22 | 2019-03-05 22:37:55 +0000 | [diff] [blame] | 869 | */ |
| 870 | public abstract void uninstallApex(String packageName, long versionCode, int userId, |
Gavin Corkery | 4fd1088 | 2019-11-28 15:37:51 +0000 | [diff] [blame] | 871 | IntentSender intentSender, int flags); |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 872 | |
| 873 | /** |
Philip P. Moltmann | 5f5783e | 2019-05-22 14:57:18 -0700 | [diff] [blame] | 874 | * Get fingerprint of build that updated the runtime permissions for a user. |
| 875 | * |
| 876 | * @param userId The user to update |
| 877 | * @param fingerPrint The fingerprint to set |
| 878 | */ |
| 879 | public abstract void setRuntimePermissionsFingerPrint(@NonNull String fingerPrint, |
| 880 | @UserIdInt int userId); |
Narayan Kamath | 157dd1d | 2019-06-12 13:06:30 +0100 | [diff] [blame] | 881 | |
| 882 | /** |
| 883 | * Migrates legacy obb data to its new location. |
| 884 | */ |
| 885 | public abstract void migrateLegacyObbData(); |
Todd Kennedy | 6ffc5a6 | 2019-07-03 09:35:31 -0700 | [diff] [blame] | 886 | |
| 887 | /** |
| 888 | * Writes all package manager settings to disk. If {@code async} is {@code true}, the |
| 889 | * settings are written at some point in the future. Otherwise, the call blocks until |
| 890 | * the settings have been written. |
| 891 | */ |
| 892 | public abstract void writeSettings(boolean async); |
Todd Kennedy | 230c0a7 | 2019-07-03 13:06:35 -0700 | [diff] [blame] | 893 | |
| 894 | /** |
| 895 | * Writes all permission settings for the given set of users to disk. If {@code async} |
| 896 | * is {@code true}, the settings are written at some point in the future. Otherwise, |
| 897 | * the call blocks until the settings have been written. |
| 898 | */ |
| 899 | public abstract void writePermissionSettings(@NonNull @UserIdInt int[] userIds, boolean async); |
| 900 | |
| 901 | /** |
Todd Kennedy | 7e3dd3a | 2019-07-08 10:34:29 -0700 | [diff] [blame] | 902 | * Returns {@code true} if the caller is the installer of record for the given package. |
| 903 | * Otherwise, {@code false}. |
| 904 | */ |
| 905 | public abstract boolean isCallerInstallerOfRecord( |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 906 | @NonNull AndroidPackage pkg, int callingUid); |
Todd Kennedy | 583378d | 2019-07-12 06:50:30 -0700 | [diff] [blame] | 907 | |
| 908 | /** Returns whether or not default runtime permissions are granted for the given user */ |
| 909 | public abstract boolean areDefaultRuntimePermissionsGranted(@UserIdInt int userId); |
Todd Kennedy | c5b0e86 | 2019-07-16 09:47:58 -0700 | [diff] [blame] | 910 | |
| 911 | /** Sets the enforcement of reading external storage */ |
| 912 | public abstract void setReadExternalStorageEnforced(boolean enforced); |
Song Pan | f93a39c | 2019-11-19 00:58:31 +0000 | [diff] [blame] | 913 | |
| 914 | /** |
| 915 | * Allows the integrity component to respond to the |
| 916 | * {@link Intent#ACTION_PACKAGE_NEEDS_INTEGRITY_VERIFICATION package verification |
| 917 | * broadcast} to respond to the package manager. The response must include |
| 918 | * the {@code verificationCode} which is one of |
Song Pan | 26dee80 | 2019-10-17 17:56:21 +0100 | [diff] [blame] | 919 | * {@link #INTEGRITY_VERIFICATION_ALLOW} and {@link #INTEGRITY_VERIFICATION_REJECT}. |
Song Pan | f93a39c | 2019-11-19 00:58:31 +0000 | [diff] [blame] | 920 | * |
| 921 | * @param verificationId pending package identifier as passed via the |
| 922 | * {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra. |
Song Pan | 26dee80 | 2019-10-17 17:56:21 +0100 | [diff] [blame] | 923 | * @param verificationResult either {@link #INTEGRITY_VERIFICATION_ALLOW} |
| 924 | * or {@link #INTEGRITY_VERIFICATION_REJECT}. |
Song Pan | f93a39c | 2019-11-19 00:58:31 +0000 | [diff] [blame] | 925 | */ |
Song Pan | 26dee80 | 2019-10-17 17:56:21 +0100 | [diff] [blame] | 926 | public abstract void setIntegrityVerificationResult(int verificationId, |
| 927 | @IntegrityVerificationResult int verificationResult); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 928 | } |