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; |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 36 | import android.util.ArraySet; |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 37 | import android.util.SparseArray; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 38 | |
Christopher Tate | e4f5f2d | 2019-10-08 15:49:43 -0700 | [diff] [blame] | 39 | import com.android.server.pm.PackageList; |
| 40 | |
Jeff Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 41 | import java.io.IOException; |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 42 | import java.lang.annotation.Retention; |
| 43 | import java.lang.annotation.RetentionPolicy; |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 44 | import java.util.List; |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 45 | import java.util.function.Consumer; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Package manager local system service interface. |
| 49 | * |
| 50 | * @hide Only for use within the system server. |
| 51 | */ |
| 52 | public abstract class PackageManagerInternal { |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 53 | 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 Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 58 | public static final int PACKAGE_SYSTEM_TEXT_CLASSIFIER = 5; |
Philip P. Moltmann | 8943ad6 | 2018-07-25 12:12:30 -0700 | [diff] [blame] | 59 | public static final int PACKAGE_PERMISSION_CONTROLLER = 6; |
Varun Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 60 | public static final int PACKAGE_WELLBEING = 7; |
Jeff Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 61 | public static final int PACKAGE_DOCUMENTER = 8; |
Stanislav Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 62 | public static final int PACKAGE_CONFIGURATOR = 9; |
Joe Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 63 | public static final int PACKAGE_INCIDENT_REPORT_APPROVER = 10; |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 64 | public static final int PACKAGE_APP_PREDICTOR = 11; |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 65 | public static final int PACKAGE_TELEPHONY = 12; |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 66 | @IntDef(value = { |
| 67 | PACKAGE_SYSTEM, |
| 68 | PACKAGE_SETUP_WIZARD, |
| 69 | PACKAGE_INSTALLER, |
| 70 | PACKAGE_VERIFIER, |
| 71 | PACKAGE_BROWSER, |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 72 | PACKAGE_SYSTEM_TEXT_CLASSIFIER, |
Philip P. Moltmann | 8943ad6 | 2018-07-25 12:12:30 -0700 | [diff] [blame] | 73 | PACKAGE_PERMISSION_CONTROLLER, |
Varun Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 74 | PACKAGE_WELLBEING, |
Jeff Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 75 | PACKAGE_DOCUMENTER, |
Stanislav Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 76 | PACKAGE_CONFIGURATOR, |
Joe Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 77 | PACKAGE_INCIDENT_REPORT_APPROVER, |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 78 | PACKAGE_APP_PREDICTOR, |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 79 | PACKAGE_TELEPHONY, |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 80 | }) |
| 81 | @Retention(RetentionPolicy.SOURCE) |
| 82 | public @interface KnownPackage {} |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 83 | |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 84 | /** Observer called whenever the list of packages changes */ |
| 85 | public interface PackageListObserver { |
| 86 | /** A package was added to the system. */ |
Chenbo Feng | de8e3b7 | 2019-02-21 14:24:24 -0800 | [diff] [blame] | 87 | void onPackageAdded(@NonNull String packageName, int uid); |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 88 | /** A package was changed - either installed for a specific user or updated. */ |
| 89 | default void onPackageChanged(@NonNull String packageName, int uid) {} |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 90 | /** A package was removed from the system. */ |
Chenbo Feng | de8e3b7 | 2019-02-21 14:24:24 -0800 | [diff] [blame] | 91 | void onPackageRemoved(@NonNull String packageName, int uid); |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 94 | /** |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 95 | * 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 |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 99 | */ |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 100 | public void onDefaultSmsAppChanged(String packageName, int userId) {} |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 101 | |
| 102 | /** |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 103 | * 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 Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 107 | */ |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 108 | public void onDefaultSimCallManagerAppChanged(String packageName, int userId) {} |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 109 | |
| 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 Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 116 | |
| 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 Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 125 | |
| 126 | /** |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 127 | * 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 Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 131 | */ |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 132 | public abstract PackageInfo getPackageInfo(String packageName, |
| 133 | @PackageInfoFlags int flags, int filterCallingUid, int userId); |
| 134 | |
| 135 | /** |
Ricky Wai | cf134eb | 2018-10-10 09:26:32 +0100 | [diff] [blame] | 136 | * 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 Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 159 | * Retrieve launcher extras for a suspended package provided to the system in |
| 160 | * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 161 | * PersistableBundle, String)}. |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 162 | * |
| 163 | * @param packageName The package for which to return launcher extras. |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 164 | * @param userId The user for which to check. |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 165 | * @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 Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 175 | * 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 Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 184 | * 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 Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 197 | * Get the information describing the dialog to be shown to the user when they try to launch a |
| 198 | * suspended application. |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 199 | * |
| 200 | * @param suspendedPackage The package that has been suspended. |
Suprabh Shukla | d327844 | 2019-08-27 15:58:03 -0700 | [diff] [blame] | 201 | * @param suspendingPackage |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 202 | * @param userId The user for which to check. |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 203 | * @return A {@link SuspendDialogInfo} object describing the dialog to be shown. |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 204 | */ |
Suprabh Shukla | 389cb6f | 2018-10-01 18:20:39 -0700 | [diff] [blame] | 205 | @Nullable |
Suprabh Shukla | d327844 | 2019-08-27 15:58:03 -0700 | [diff] [blame] | 206 | public abstract SuspendDialogInfo getSuspendedDialogInfo(String suspendedPackage, |
| 207 | String suspendingPackage, int userId); |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 208 | |
| 209 | /** |
Suprabh Shukla | 7900049 | 2018-12-24 17:03:02 -0800 | [diff] [blame] | 210 | * 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 Tate | a732f01 | 2017-10-26 17:26:53 -0700 | [diff] [blame] | 221 | * 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 Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 229 | * 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 Baumann | 182ea1c | 2019-11-18 13:43:11 -0800 | [diff] [blame] | 248 | * @param resolvedType the resolved type of the intent, which should be resolved via |
| 249 | * {@link Intent#resolveTypeIfNeeded(ContentResolver)} before passing to {@link PackageManager} |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 250 | * @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 Baumann | 182ea1c | 2019-11-18 13:43:11 -0800 | [diff] [blame] | 254 | public abstract List<ResolveInfo> queryIntentActivities( |
| 255 | Intent intent, @Nullable String resolvedType, @ResolveInfoFlags int flags, |
| 256 | int filterCallingUid, int userId); |
| 257 | |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 258 | |
| 259 | /** |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 260 | * 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 Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 267 | * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}. |
| 268 | */ |
| 269 | public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, |
| 270 | int userId); |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 271 | |
| 272 | /** |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 273 | * @return The default home activity component name. |
| 274 | */ |
| 275 | public abstract ComponentName getDefaultHomeActivity(int userId); |
| 276 | |
| 277 | /** |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 278 | * 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 Ng | 9d48a73 | 2016-06-24 19:04:14 +0100 | [diff] [blame] | 285 | * 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] | 286 | */ |
Steven Ng | 9d48a73 | 2016-06-24 19:04:14 +0100 | [diff] [blame] | 287 | public abstract boolean isPackageDataProtected(int userId, String packageName); |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
Benjamin Franz | f81bf7f | 2018-03-26 16:23:04 +0100 | [diff] [blame] | 290 | * 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 Hackborn | e07641d | 2016-11-09 15:07:23 -0800 | [diff] [blame] | 296 | * 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 Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 302 | * 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 Yamasani | 2cbfa1e | 2017-03-28 10:34:01 -0700 | [diff] [blame] | 306 | * @throws IllegalArgumentException if the package is not found |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 307 | */ |
| 308 | public abstract boolean wasPackageEverLaunched(String packageName, int userId); |
Nicolas Prevot | 700e1e7 | 2016-09-28 15:17:18 +0100 | [diff] [blame] | 309 | |
| 310 | /** |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 311 | * Retrieve the official name associated with a uid. This name is |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 312 | * guaranteed to never change, though it is possible for the underlying |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 313 | * 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 Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 316 | * |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 317 | * @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 Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 320 | */ |
| 321 | public abstract String getNameForUid(int uid); |
| 322 | |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 323 | /** |
Bookatz | 04d7ae5 | 2019-08-05 14:07:12 -0700 | [diff] [blame] | 324 | * 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 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 331 | public abstract boolean setInstalled(AndroidPackage pkg, |
Bookatz | 04d7ae5 | 2019-08-05 14:07:12 -0700 | [diff] [blame] | 332 | @UserIdInt int userId, boolean installed); |
| 333 | |
| 334 | /** |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 335 | * 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 Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 339 | * @param callingPackage The name of the package requesting the ephemeral application |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 340 | * @param verificationBundle Optional bundle to pass to the installer for additional |
| 341 | * verification |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 342 | * @param userId The ID of the user that triggered ephemeral resolution |
| 343 | */ |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 344 | public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, |
| 345 | Intent origIntent, String resolvedType, String callingPackage, |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 346 | Bundle verificationBundle, int userId); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 347 | |
| 348 | /** |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 349 | * 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 Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 351 | * <p> |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 352 | * 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 Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 358 | * <p> |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 359 | * @param userId the user |
| 360 | * @param intent the intent that triggered the grant |
Patrick Baumann | b6e7297 | 2019-09-20 07:54:47 -0700 | [diff] [blame] | 361 | * @param callingUid The uid of the calling application |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 362 | * @param targetAppId The app ID of the target application |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 363 | */ |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 364 | public abstract void grantImplicitAccess( |
Patrick Baumann | b6e7297 | 2019-09-20 07:54:47 -0700 | [diff] [blame] | 365 | @UserIdInt int userId, Intent intent, int callingUid, |
Patrick Baumann | de37e43 | 2019-08-28 09:51:29 -0700 | [diff] [blame] | 366 | @AppIdInt int targetAppId); |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 367 | |
Todd Kennedy | b21be12 | 2017-03-24 14:10:01 -0700 | [diff] [blame] | 368 | public abstract boolean isInstantAppInstallerComponent(ComponentName component); |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 369 | /** |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 370 | * 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 Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 376 | * @return The SetupWizard package name. |
| 377 | */ |
| 378 | public abstract String getSetupWizardPackageName(); |
Suprabh Shukla | aef2513 | 2017-01-23 18:09:03 -0800 | [diff] [blame] | 379 | |
| 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. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 392 | * @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 Shukla | aef2513 | 2017-01-23 18:09:03 -0800 | [diff] [blame] | 394 | * is not yet available |
| 395 | */ |
| 396 | int getPackageTrustedToInstallApps(String packageName, int uid); |
| 397 | } |
| 398 | |
| 399 | public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy); |
MÃ¥rten Kongstad | eabc9e9 | 2015-12-15 16:40:23 +0100 | [diff] [blame] | 400 | |
| 401 | /** |
Dianne Hackborn | b1e7776 | 2017-02-13 11:42:18 -0800 | [diff] [blame] | 402 | * Return true if the given package is a persistent app process. |
| 403 | */ |
| 404 | public abstract boolean isPackagePersistent(String packageName); |
| 405 | |
| 406 | /** |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 407 | * Returns whether or not the given package represents a legacy system application released |
| 408 | * prior to runtime permissions. |
| 409 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 410 | public abstract boolean isLegacySystemApp(AndroidPackage pkg); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 411 | |
| 412 | /** |
MÃ¥rten Kongstad | eabc9e9 | 2015-12-15 16:40:23 +0100 | [diff] [blame] | 413 | * 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 Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 440 | |
| 441 | /** |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 442 | * Resolves an activity intent, allowing instant apps to be resolved. |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 443 | */ |
| 444 | public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 445 | int flags, int userId, boolean resolveForStart, int filterCallingUid); |
Chad Brubaker | 0f28a80 | 2017-03-29 14:05:52 -0700 | [diff] [blame] | 446 | |
| 447 | /** |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 448 | * Resolves a service intent, allowing instant apps to be resolved. |
| 449 | */ |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 450 | public abstract ResolveInfo resolveService(Intent intent, String resolvedType, |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 451 | int flags, int userId, int callingUid); |
| 452 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 453 | /** |
| 454 | * Resolves a content provider intent. |
| 455 | */ |
| 456 | public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId); |
| 457 | |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 458 | /** |
Chad Brubaker | 0f28a80 | 2017-03-29 14:05:52 -0700 | [diff] [blame] | 459 | * 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 Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * Return the taget SDK version for the app with the given UID. |
| 473 | */ |
| 474 | public abstract int getUidTargetSdkVersion(int uid); |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 475 | |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 476 | /** |
| 477 | * Return the taget SDK version for the app with the given package name. |
| 478 | */ |
| 479 | public abstract int getPackageTargetSdkVersion(String packageName); |
| 480 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 481 | /** Whether the binder caller can access instant apps. */ |
Todd Kennedy | 3051caa | 2017-05-23 15:54:18 -0700 | [diff] [blame] | 482 | public abstract boolean canAccessInstantApps(int callingUid, int userId); |
Svet Ganov | f935a70 | 2017-08-22 12:15:58 -0700 | [diff] [blame] | 483 | |
Todd Kennedy | 662504f | 2018-03-14 08:09:00 -0700 | [diff] [blame] | 484 | /** Whether the binder caller can access the given component. */ |
| 485 | public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId); |
| 486 | |
Svet Ganov | f935a70 | 2017-08-22 12:15:58 -0700 | [diff] [blame] | 487 | /** |
| 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 Kennedy | df113c3 | 2017-08-31 16:10:29 -0700 | [diff] [blame] | 493 | |
| 494 | /** |
| 495 | * Updates a package last used time. |
| 496 | */ |
| 497 | public abstract void notifyPackageUse(String packageName, int reason); |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 498 | |
| 499 | /** |
| 500 | * Returns a package object for the given package name. |
| 501 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 502 | 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 Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 507 | |
| 508 | /** |
Todd Kennedy | ca1ea17 | 2019-07-03 15:02:28 -0700 | [diff] [blame] | 509 | * 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 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 512 | public abstract @Nullable AndroidPackage getPackage(int uid); |
Todd Kennedy | ca1ea17 | 2019-07-03 15:02:28 -0700 | [diff] [blame] | 513 | |
| 514 | /** |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 515 | * Returns a list without a change observer. |
| 516 | * |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 517 | * @see #getPackageList(PackageListObserver) |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 518 | */ |
| 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 | |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 543 | // TODO(b/135203078): PackageSetting can't be referenced directly |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 544 | /** |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 545 | * Returns a package object for the disabled system package name. |
| 546 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 547 | public abstract @Nullable Object getDisabledSystemPackage(@NonNull String packageName); |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 548 | |
| 549 | /** |
| 550 | * Returns the package name for the disabled system package. |
| 551 | * |
| 552 | * This is equivalent to |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 553 | * {@link #getDisabledSystemPackage(String)} |
| 554 | * .{@link com.android.server.pm.PackageSetting#pkg} |
| 555 | * .{@link AndroidPackage#getPackageName()} |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 556 | */ |
| 557 | public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName); |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 558 | |
| 559 | /** |
| 560 | * Returns whether or not the component is the resolver activity. |
| 561 | */ |
| 562 | public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component); |
| 563 | |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 564 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 565 | /** |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 566 | * Returns a list of package names for a known package |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 567 | */ |
Chen Xu | 45c183d | 2019-10-07 00:24:41 -0700 | [diff] [blame] | 568 | public abstract @NonNull String[] getKnownPackageNames( |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 569 | @KnownPackage int knownPackage, int userId); |
| 570 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 571 | /** |
| 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. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 587 | * @see #canAccessInstantApps |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 588 | */ |
| 589 | public abstract boolean filterAppAccess( |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 590 | @NonNull AndroidPackage pkg, int callingUid, int userId); |
Todd Kennedy | c5b0e86 | 2019-07-16 09:47:58 -0700 | [diff] [blame] | 591 | |
| 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 Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 599 | |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 600 | /** Returns whether the given package was signed by the platform */ |
| 601 | public abstract boolean isPlatformSigned(String pkg); |
| 602 | |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 603 | /** |
| 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 Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 616 | |
Dan Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 617 | /** |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 618 | * 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 Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 624 | */ |
| 625 | public abstract boolean hasSignatureCapability(int serverUid, int clientUid, |
| 626 | @PackageParser.SigningDetails.CertCapabilities int capability); |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 627 | |
| 628 | /** |
Sudheer Shanka | 0a541a5 | 2018-07-31 13:21:11 -0700 | [diff] [blame] | 629 | * 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 Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 634 | |
| 635 | /** |
Sudheer Shanka | 2ac25a9 | 2018-10-25 10:59:32 -0700 | [diff] [blame] | 636 | * 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 Sharkey | 5790af0 | 2018-08-13 17:42:54 -0600 | [diff] [blame] | 648 | * 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 Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 662 | |
| 663 | /** 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] | 664 | public abstract boolean isEnabledAndMatches( |
| 665 | @NonNull ComponentParseUtils.ParsedComponent component, int flags, int userId); |
Todd Kennedy | cf82703 | 2018-07-03 13:17:22 -0700 | [diff] [blame] | 666 | |
| 667 | /** Returns {@code true} if the given user requires extra badging for icons. */ |
| 668 | public abstract boolean userNeedsBadging(int userId); |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 669 | |
| 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 | */ |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 676 | public abstract void forEachPackage(Consumer<AndroidPackage> actionLocked); |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 677 | |
Hai Zhang | eb8b460 | 2019-05-22 13:04:12 -0700 | [diff] [blame] | 678 | /** |
| 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( |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 683 | @NonNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId); |
Hai Zhang | eb8b460 | 2019-05-22 13:04:12 -0700 | [diff] [blame] | 684 | |
Eugene Susla | abdefba | 2018-11-09 18:06:43 -0800 | [diff] [blame] | 685 | /** 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 Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 694 | |
| 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 Uhler | 82913b7 | 2019-04-01 13:02:31 +0100 | [diff] [blame] | 710 | * 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 Uhler | b29f145 | 2018-09-12 16:38:15 +0100 | [diff] [blame] | 717 | * 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 Holk | a1485f6 | 2019-01-07 13:58:25 -0800 | [diff] [blame] | 745 | |
| 746 | /** |
| 747 | * Ask the package manager to compile layouts in the given package. |
| 748 | */ |
| 749 | public abstract boolean compileLayouts(String packageName); |
Narayan Kamath | 869f706 | 2019-01-10 12:24:15 +0000 | [diff] [blame] | 750 | |
| 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 Zhang | a22cd83 | 2019-01-30 13:38:43 -0800 | [diff] [blame] | 756 | |
| 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 Zhang | 85fd062 | 2019-02-01 14:06:04 -0800 | [diff] [blame] | 766 | |
| 767 | /** |
Nikita Ioffe | f012a22 | 2019-03-05 22:37:55 +0000 | [diff] [blame] | 768 | * 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 Corkery | 4fd1088 | 2019-11-28 15:37:51 +0000 | [diff] [blame] | 780 | * @param flags flags about the uninstall. |
Nikita Ioffe | f012a22 | 2019-03-05 22:37:55 +0000 | [diff] [blame] | 781 | */ |
| 782 | public abstract void uninstallApex(String packageName, long versionCode, int userId, |
Gavin Corkery | 4fd1088 | 2019-11-28 15:37:51 +0000 | [diff] [blame] | 783 | IntentSender intentSender, int flags); |
Svet Ganov | d8eb8b2 | 2019-04-05 18:52:08 -0700 | [diff] [blame] | 784 | |
| 785 | /** |
Philip P. Moltmann | 5f5783e | 2019-05-22 14:57:18 -0700 | [diff] [blame] | 786 | * 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 Kamath | 157dd1d | 2019-06-12 13:06:30 +0100 | [diff] [blame] | 793 | |
| 794 | /** |
| 795 | * Migrates legacy obb data to its new location. |
| 796 | */ |
| 797 | public abstract void migrateLegacyObbData(); |
Todd Kennedy | 6ffc5a6 | 2019-07-03 09:35:31 -0700 | [diff] [blame] | 798 | |
| 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 Kennedy | 230c0a7 | 2019-07-03 13:06:35 -0700 | [diff] [blame] | 805 | |
| 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 Kennedy | 7e3dd3a | 2019-07-08 10:34:29 -0700 | [diff] [blame] | 814 | * 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( |
Winson | 14ff717 | 2019-10-23 10:42:27 -0700 | [diff] [blame] | 818 | @NonNull AndroidPackage pkg, int callingUid); |
Todd Kennedy | 583378d | 2019-07-12 06:50:30 -0700 | [diff] [blame] | 819 | |
| 820 | /** Returns whether or not default runtime permissions are granted for the given user */ |
| 821 | public abstract boolean areDefaultRuntimePermissionsGranted(@UserIdInt int userId); |
Todd Kennedy | c5b0e86 | 2019-07-16 09:47:58 -0700 | [diff] [blame] | 822 | |
| 823 | /** Sets the enforcement of reading external storage */ |
| 824 | public abstract void setReadExternalStorageEnforced(boolean enforced); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 825 | } |