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 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 23 | import android.content.Intent; |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager.ApplicationInfoFlags; |
| 25 | import android.content.pm.PackageManager.ComponentInfoFlags; |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 26 | import android.content.pm.PackageManager.PackageInfoFlags; |
| 27 | import android.content.pm.PackageManager.ResolveInfoFlags; |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 28 | import android.os.Bundle; |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 29 | import android.os.PersistableBundle; |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 30 | import android.util.SparseArray; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 31 | |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 32 | import com.android.internal.util.function.TriFunction; |
| 33 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 34 | import java.lang.annotation.Retention; |
| 35 | import java.lang.annotation.RetentionPolicy; |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 36 | import java.util.List; |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 37 | import java.util.function.BiFunction; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Package manager local system service interface. |
| 41 | * |
| 42 | * @hide Only for use within the system server. |
| 43 | */ |
| 44 | public abstract class PackageManagerInternal { |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 45 | public static final int PACKAGE_SYSTEM = 0; |
| 46 | public static final int PACKAGE_SETUP_WIZARD = 1; |
| 47 | public static final int PACKAGE_INSTALLER = 2; |
| 48 | public static final int PACKAGE_VERIFIER = 3; |
| 49 | public static final int PACKAGE_BROWSER = 4; |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 50 | public static final int PACKAGE_SYSTEM_TEXT_CLASSIFIER = 5; |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 51 | @IntDef(value = { |
| 52 | PACKAGE_SYSTEM, |
| 53 | PACKAGE_SETUP_WIZARD, |
| 54 | PACKAGE_INSTALLER, |
| 55 | PACKAGE_VERIFIER, |
| 56 | PACKAGE_BROWSER, |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 57 | PACKAGE_SYSTEM_TEXT_CLASSIFIER, |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 58 | }) |
| 59 | @Retention(RetentionPolicy.SOURCE) |
| 60 | public @interface KnownPackage {} |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 61 | |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 62 | /** Observer called whenever the list of packages changes */ |
| 63 | public interface PackageListObserver { |
| 64 | /** A package was added to the system. */ |
| 65 | void onPackageAdded(@NonNull String packageName); |
| 66 | /** A package was removed from the system. */ |
| 67 | void onPackageRemoved(@NonNull String packageName); |
| 68 | } |
| 69 | |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 70 | /** Interface to override permission checks via composition */ |
| 71 | public interface CheckPermissionDelegate { |
| 72 | /** |
| 73 | * Allows overriding check permission behavior. |
| 74 | * |
| 75 | * @param permName The permission to check. |
| 76 | * @param pkgName The package for which to check. |
| 77 | * @param userId The user for which to check. |
| 78 | * @param superImpl The super implementation. |
| 79 | * @return The check permission result. |
| 80 | */ |
| 81 | int checkPermission(String permName, String pkgName, int userId, |
| 82 | TriFunction<String, String, Integer, Integer> superImpl); |
| 83 | |
| 84 | /** |
| 85 | * Allows overriding check UID permission behavior. |
| 86 | * |
| 87 | * @param permName The permission to check. |
| 88 | * @param uid The UID for which to check. |
| 89 | * @param superImpl The super implementation. |
| 90 | * @return The check permission result. |
| 91 | */ |
| 92 | int checkUidPermission(String permName, int uid, |
| 93 | BiFunction<String, Integer, Integer> superImpl); |
| 94 | } |
| 95 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Provider for package names. |
| 98 | */ |
| 99 | public interface PackagesProvider { |
| 100 | |
| 101 | /** |
| 102 | * Gets the packages for a given user. |
| 103 | * @param userId The user id. |
| 104 | * @return The package names. |
| 105 | */ |
| 106 | public String[] getPackages(int userId); |
| 107 | } |
| 108 | |
| 109 | /** |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 110 | * Provider for package names. |
| 111 | */ |
| 112 | public interface SyncAdapterPackagesProvider { |
| 113 | |
| 114 | /** |
| 115 | * Gets the sync adapter packages for given authority and user. |
| 116 | * @param authority The authority. |
| 117 | * @param userId The user id. |
| 118 | * @return The package names. |
| 119 | */ |
| 120 | public String[] getPackages(String authority, int userId); |
| 121 | } |
| 122 | |
| 123 | /** |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 124 | * Sets the location provider packages provider. |
| 125 | * @param provider The packages provider. |
| 126 | */ |
| 127 | public abstract void setLocationPackagesProvider(PackagesProvider provider); |
| 128 | |
| 129 | /** |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 130 | * Sets the voice interaction packages provider. |
| 131 | * @param provider The packages provider. |
| 132 | */ |
| 133 | public abstract void setVoiceInteractionPackagesProvider(PackagesProvider provider); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * Sets the SMS packages provider. |
| 137 | * @param provider The packages provider. |
| 138 | */ |
| 139 | public abstract void setSmsAppPackagesProvider(PackagesProvider provider); |
| 140 | |
| 141 | /** |
| 142 | * Sets the dialer packages provider. |
| 143 | * @param provider The packages provider. |
| 144 | */ |
| 145 | public abstract void setDialerAppPackagesProvider(PackagesProvider provider); |
| 146 | |
| 147 | /** |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 148 | * Sets the sim call manager packages provider. |
| 149 | * @param provider The packages provider. |
| 150 | */ |
| 151 | public abstract void setSimCallManagerPackagesProvider(PackagesProvider provider); |
| 152 | |
| 153 | /** |
Eric Enslen | 1e423b9 | 2017-12-18 11:30:21 -0800 | [diff] [blame] | 154 | * Sets the Use Open Wifi packages provider. |
| 155 | * @param provider The packages provider. |
| 156 | */ |
| 157 | public abstract void setUseOpenWifiAppPackagesProvider(PackagesProvider provider); |
| 158 | |
| 159 | /** |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 160 | * Sets the sync adapter packages provider. |
| 161 | * @param provider The provider. |
| 162 | */ |
| 163 | public abstract void setSyncAdapterPackagesprovider(SyncAdapterPackagesProvider provider); |
| 164 | |
| 165 | /** |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 166 | * Requests granting of the default permissions to the current default SMS app. |
| 167 | * @param packageName The default SMS package name. |
| 168 | * @param userId The user for which to grant the permissions. |
| 169 | */ |
| 170 | public abstract void grantDefaultPermissionsToDefaultSmsApp(String packageName, int userId); |
| 171 | |
| 172 | /** |
| 173 | * Requests granting of the default permissions to the current default dialer app. |
| 174 | * @param packageName The default dialer package name. |
| 175 | * @param userId The user for which to grant the permissions. |
| 176 | */ |
| 177 | public abstract void grantDefaultPermissionsToDefaultDialerApp(String packageName, int userId); |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * Requests granting of the default permissions to the current default sim call manager. |
| 181 | * @param packageName The default sim call manager package name. |
| 182 | * @param userId The user for which to grant the permissions. |
| 183 | */ |
| 184 | public abstract void grantDefaultPermissionsToDefaultSimCallManager(String packageName, |
| 185 | int userId); |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 186 | |
| 187 | /** |
Eric Enslen | 1e423b9 | 2017-12-18 11:30:21 -0800 | [diff] [blame] | 188 | * Requests granting of the default permissions to the current default Use Open Wifi app. |
| 189 | * @param packageName The default use open wifi package name. |
| 190 | * @param userId The user for which to grant the permissions. |
| 191 | */ |
| 192 | public abstract void grantDefaultPermissionsToDefaultUseOpenWifiApp(String packageName, |
| 193 | int userId); |
| 194 | |
| 195 | /** |
Fyodor Kupolov | cb6fd80 | 2015-11-05 14:27:06 -0800 | [diff] [blame] | 196 | * Sets a list of apps to keep in PM's internal data structures and as APKs even if no user has |
| 197 | * currently installed it. The apps are not preloaded. |
| 198 | * @param packageList List of package names to keep cached. |
| 199 | */ |
| 200 | public abstract void setKeepUninstalledPackages(List<String> packageList); |
Svet Ganov | 9c165d7 | 2015-12-01 19:52:26 -0800 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * Gets whether some of the permissions used by this package require a user |
| 204 | * review before any of the app components can run. |
| 205 | * @param packageName The package name for which to check. |
| 206 | * @param userId The user under which to check. |
| 207 | * @return True a permissions review is required. |
| 208 | */ |
| 209 | public abstract boolean isPermissionsReviewRequired(String packageName, int userId); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 210 | |
| 211 | /** |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 212 | * Retrieve all of the information we know about a particular package/application. |
| 213 | * @param filterCallingUid The results will be filtered in the context of this UID instead |
| 214 | * of the calling UID. |
| 215 | * @see PackageManager#getPackageInfo(String, int) |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 216 | */ |
Todd Kennedy | 18211fd | 2017-06-06 09:15:46 -0700 | [diff] [blame] | 217 | public abstract PackageInfo getPackageInfo(String packageName, |
| 218 | @PackageInfoFlags int flags, int filterCallingUid, int userId); |
| 219 | |
| 220 | /** |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 221 | * Retrieve launcher extras for a suspended package provided to the system in |
| 222 | * {@link PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 223 | * PersistableBundle, String)}. |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 224 | * |
| 225 | * @param packageName The package for which to return launcher extras. |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 226 | * @param userId The user for which to check. |
Suprabh Shukla | 19b41f3 | 2018-03-26 22:35:13 -0700 | [diff] [blame] | 227 | * @return The launcher extras. |
| 228 | * |
| 229 | * @see PackageManager#setPackagesSuspended(String[], boolean, PersistableBundle, |
| 230 | * PersistableBundle, String) |
| 231 | * @see PackageManager#isPackageSuspended() |
| 232 | */ |
| 233 | public abstract Bundle getSuspendedPackageLauncherExtras(String packageName, |
| 234 | int userId); |
| 235 | |
| 236 | /** |
Suprabh Shukla | 69c7142 | 2018-04-02 18:39:01 -0700 | [diff] [blame] | 237 | * Internal api to query the suspended state of a package. |
| 238 | * @param packageName The package to check. |
| 239 | * @param userId The user id to check for. |
| 240 | * @return {@code true} if the package is suspended, {@code false} otherwise. |
| 241 | * @see PackageManager#isPackageSuspended(String) |
| 242 | */ |
| 243 | public abstract boolean isPackageSuspended(String packageName, int userId); |
| 244 | |
| 245 | /** |
Suprabh Shukla | 3c3af14 | 2018-03-30 00:28:37 -0700 | [diff] [blame] | 246 | * Get the name of the package that suspended the given package. Packages can be suspended by |
| 247 | * device administrators or apps holding {@link android.Manifest.permission#MANAGE_USERS} or |
| 248 | * {@link android.Manifest.permission#SUSPEND_APPS}. |
| 249 | * |
| 250 | * @param suspendedPackage The package that has been suspended. |
| 251 | * @param userId The user for which to check. |
| 252 | * @return Name of the package that suspended the given package. Returns {@code null} if the |
| 253 | * given package is not currently suspended and the platform package name - i.e. |
| 254 | * {@code "android"} - if the package was suspended by a device admin. |
| 255 | */ |
| 256 | public abstract String getSuspendingPackage(String suspendedPackage, int userId); |
| 257 | |
| 258 | /** |
| 259 | * Get the dialog message to be shown to the user when they try to launch a suspended |
| 260 | * application. |
| 261 | * |
| 262 | * @param suspendedPackage The package that has been suspended. |
| 263 | * @param userId The user for which to check. |
| 264 | * @return The dialog message to be shown to the user. |
| 265 | */ |
| 266 | public abstract String getSuspendedDialogMessage(String suspendedPackage, int userId); |
| 267 | |
| 268 | /** |
Christopher Tate | a732f01 | 2017-10-26 17:26:53 -0700 | [diff] [blame] | 269 | * Do a straight uid lookup for the given package/application in the given user. |
| 270 | * @see PackageManager#getPackageUidAsUser(String, int, int) |
| 271 | * @return The app's uid, or < 0 if the package was not found in that user |
| 272 | */ |
| 273 | public abstract int getPackageUid(String packageName, |
| 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. |
| 296 | * @param filterCallingUid The results will be filtered in the context of this UID instead |
| 297 | * of the calling UID. |
| 298 | * @see PackageManager#queryIntentActivities(Intent, int) |
| 299 | */ |
| 300 | public abstract List<ResolveInfo> queryIntentActivities(Intent intent, |
| 301 | @ResolveInfoFlags int flags, int filterCallingUid, int userId); |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 302 | |
| 303 | /** |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 304 | * Retrieve all services that can be performed for the given intent. |
| 305 | * @see PackageManager#queryIntentServices(Intent, int) |
| 306 | */ |
| 307 | public abstract List<ResolveInfo> queryIntentServices( |
| 308 | Intent intent, int flags, int callingUid, int userId); |
| 309 | |
| 310 | /** |
Makoto Onuki | 2d5b465 | 2016-03-11 16:09:54 -0800 | [diff] [blame] | 311 | * Interface to {@link com.android.server.pm.PackageManagerService#getHomeActivitiesAsUser}. |
| 312 | */ |
| 313 | public abstract ComponentName getHomeActivitiesAsUser(List<ResolveInfo> allHomeCandidates, |
| 314 | int userId); |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 315 | |
| 316 | /** |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 317 | * @return The default home activity component name. |
| 318 | */ |
| 319 | public abstract ComponentName getDefaultHomeActivity(int userId); |
| 320 | |
| 321 | /** |
Makoto Onuki | c29f62c | 2016-06-07 12:19:46 -0700 | [diff] [blame] | 322 | * Called by DeviceOwnerManagerService to set the package names of device owner and profile |
| 323 | * owners. |
| 324 | */ |
| 325 | public abstract void setDeviceAndProfileOwnerPackages( |
| 326 | int deviceOwnerUserId, String deviceOwner, SparseArray<String> profileOwners); |
| 327 | |
| 328 | /** |
Steven Ng | 9d48a73 | 2016-06-24 19:04:14 +0100 | [diff] [blame] | 329 | * 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] | 330 | */ |
Steven Ng | 9d48a73 | 2016-06-24 19:04:14 +0100 | [diff] [blame] | 331 | public abstract boolean isPackageDataProtected(int userId, String packageName); |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 332 | |
| 333 | /** |
Benjamin Franz | f81bf7f | 2018-03-26 16:23:04 +0100 | [diff] [blame] | 334 | * Returns {@code true} if a given package's state is protected, e.g. it cannot be force |
| 335 | * stopped, suspended, disabled or hidden. Otherwise, returns {@code false}. |
| 336 | */ |
| 337 | public abstract boolean isPackageStateProtected(String packageName, int userId); |
| 338 | |
| 339 | /** |
Dianne Hackborn | e07641d | 2016-11-09 15:07:23 -0800 | [diff] [blame] | 340 | * Returns {@code true} if a given package is installed as ephemeral. Otherwise, returns |
| 341 | * {@code false}. |
| 342 | */ |
| 343 | public abstract boolean isPackageEphemeral(int userId, String packageName); |
| 344 | |
| 345 | /** |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 346 | * Gets whether the package was ever launched. |
| 347 | * @param packageName The package name. |
| 348 | * @param userId The user for which to check. |
| 349 | * @return Whether was launched. |
Amith Yamasani | 2cbfa1e | 2017-03-28 10:34:01 -0700 | [diff] [blame] | 350 | * @throws IllegalArgumentException if the package is not found |
Svet Ganov | 973edd19 | 2016-09-08 20:15:55 -0700 | [diff] [blame] | 351 | */ |
| 352 | public abstract boolean wasPackageEverLaunched(String packageName, int userId); |
Nicolas Prevot | 700e1e7 | 2016-09-28 15:17:18 +0100 | [diff] [blame] | 353 | |
| 354 | /** |
| 355 | * Grants a runtime permission |
| 356 | * @param packageName The package name. |
| 357 | * @param name The name of the permission. |
| 358 | * @param userId The userId for which to grant the permission. |
| 359 | * @param overridePolicy If true, grant this permission even if it is fixed by policy. |
| 360 | */ |
| 361 | public abstract void grantRuntimePermission(String packageName, String name, int userId, |
| 362 | boolean overridePolicy); |
| 363 | |
| 364 | /** |
| 365 | * Revokes a runtime permission |
| 366 | * @param packageName The package name. |
| 367 | * @param name The name of the permission. |
| 368 | * @param userId The userId for which to revoke the permission. |
| 369 | * @param overridePolicy If true, revoke this permission even if it is fixed by policy. |
| 370 | */ |
| 371 | public abstract void revokeRuntimePermission(String packageName, String name, int userId, |
| 372 | boolean overridePolicy); |
| 373 | |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 374 | /** |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 375 | * Retrieve the official name associated with a uid. This name is |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 376 | * guaranteed to never change, though it is possible for the underlying |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 377 | * uid to be changed. That is, if you are storing information about |
| 378 | * uids in persistent storage, you should use the string returned |
| 379 | * by this function instead of the raw uid. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 380 | * |
Michal Karpinski | cb67dc9 | 2016-12-13 18:20:23 +0000 | [diff] [blame] | 381 | * @param uid The uid for which you would like to retrieve a name. |
| 382 | * @return Returns a unique name for the given uid, or null if the |
| 383 | * uid is not currently assigned. |
Michal Karpinski | f77ee4f | 2016-10-12 16:40:06 +0100 | [diff] [blame] | 384 | */ |
| 385 | public abstract String getNameForUid(int uid); |
| 386 | |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 387 | /** |
| 388 | * Request to perform the second phase of ephemeral resolution. |
| 389 | * @param responseObj The response of the first phase of ephemeral resolution |
| 390 | * @param origIntent The original intent that triggered ephemeral resolution |
| 391 | * @param resolvedType The resolved type of the intent |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 392 | * @param callingPackage The name of the package requesting the ephemeral application |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 393 | * @param verificationBundle Optional bundle to pass to the installer for additional |
| 394 | * verification |
Todd Kennedy | 01ad0c7 | 2016-11-11 15:33:12 -0800 | [diff] [blame] | 395 | * @param userId The ID of the user that triggered ephemeral resolution |
| 396 | */ |
Todd Kennedy | e991022 | 2017-02-21 16:00:11 -0800 | [diff] [blame] | 397 | public abstract void requestInstantAppResolutionPhaseTwo(AuxiliaryResolveInfo responseObj, |
| 398 | Intent origIntent, String resolvedType, String callingPackage, |
Chad Brubaker | 0606861 | 2017-04-06 09:43:47 -0700 | [diff] [blame] | 399 | Bundle verificationBundle, int userId); |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 400 | |
| 401 | /** |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 402 | * Grants access to the package metadata for an ephemeral application. |
| 403 | * <p> |
| 404 | * When an ephemeral application explicitly tries to interact with a full |
| 405 | * install application [via an activity, service or provider that has been |
| 406 | * exposed using the {@code visibleToInstantApp} attribute], the normal |
| 407 | * application must be able to see metadata about the connecting ephemeral |
| 408 | * app. If the ephemeral application uses an implicit intent [ie action VIEW, |
| 409 | * category BROWSABLE], it remains hidden from the launched activity. |
| 410 | * <p> |
| 411 | * If the {@code sourceUid} is not for an ephemeral app or {@code targetUid} |
| 412 | * is not for a fully installed app, this method will be a no-op. |
| 413 | * |
| 414 | * @param userId the user |
| 415 | * @param intent the intent that triggered the grant |
| 416 | * @param targetAppId The app ID of the fully installed application |
| 417 | * @param ephemeralAppId The app ID of the ephemeral application |
| 418 | */ |
| 419 | public abstract void grantEphemeralAccess(int userId, Intent intent, |
| 420 | int targetAppId, int ephemeralAppId); |
| 421 | |
Todd Kennedy | b21be12 | 2017-03-24 14:10:01 -0700 | [diff] [blame] | 422 | public abstract boolean isInstantAppInstallerComponent(ComponentName component); |
Todd Kennedy | 0e989d0 | 2017-01-13 14:15:36 -0800 | [diff] [blame] | 423 | /** |
Svetoslav Ganov | 096d304 | 2017-01-30 16:34:13 -0800 | [diff] [blame] | 424 | * Prunes instant apps and state associated with uninstalled |
| 425 | * instant apps according to the current platform policy. |
| 426 | */ |
| 427 | public abstract void pruneInstantApps(); |
| 428 | |
| 429 | /** |
Svetoslav Ganov | e080da9 | 2016-12-21 17:10:35 -0800 | [diff] [blame] | 430 | * @return The SetupWizard package name. |
| 431 | */ |
| 432 | public abstract String getSetupWizardPackageName(); |
Suprabh Shukla | aef2513 | 2017-01-23 18:09:03 -0800 | [diff] [blame] | 433 | |
| 434 | public interface ExternalSourcesPolicy { |
| 435 | |
| 436 | int USER_TRUSTED = 0; // User has trusted the package to install apps |
| 437 | int USER_BLOCKED = 1; // User has blocked the package to install apps |
| 438 | int USER_DEFAULT = 2; // Default code to use when user response is unavailable |
| 439 | |
| 440 | /** |
| 441 | * Checks the user preference for whether a package is trusted to request installs through |
| 442 | * package installer |
| 443 | * |
| 444 | * @param packageName The package to check for |
| 445 | * @param uid the uid in which the package is running |
| 446 | * @return {@link USER_TRUSTED} if the user has trusted the package, {@link USER_BLOCKED} |
| 447 | * if user has blocked requests from the package, {@link USER_DEFAULT} if the user response |
| 448 | * is not yet available |
| 449 | */ |
| 450 | int getPackageTrustedToInstallApps(String packageName, int uid); |
| 451 | } |
| 452 | |
| 453 | public abstract void setExternalSourcesPolicy(ExternalSourcesPolicy policy); |
MÃ¥rten Kongstad | eabc9e9 | 2015-12-15 16:40:23 +0100 | [diff] [blame] | 454 | |
| 455 | /** |
Dianne Hackborn | b1e7776 | 2017-02-13 11:42:18 -0800 | [diff] [blame] | 456 | * Return true if the given package is a persistent app process. |
| 457 | */ |
| 458 | public abstract boolean isPackagePersistent(String packageName); |
| 459 | |
| 460 | /** |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 461 | * Returns whether or not the given package represents a legacy system application released |
| 462 | * prior to runtime permissions. |
| 463 | */ |
| 464 | public abstract boolean isLegacySystemApp(PackageParser.Package pkg); |
| 465 | |
| 466 | /** |
MÃ¥rten Kongstad | eabc9e9 | 2015-12-15 16:40:23 +0100 | [diff] [blame] | 467 | * Get all overlay packages for a user. |
| 468 | * @param userId The user for which to get the overlays. |
| 469 | * @return A list of overlay packages. An empty list is returned if the |
| 470 | * user has no installed overlay packages. |
| 471 | */ |
| 472 | public abstract List<PackageInfo> getOverlayPackages(int userId); |
| 473 | |
| 474 | /** |
| 475 | * Get the names of all target packages for a user. |
| 476 | * @param userId The user for which to get the package names. |
| 477 | * @return A list of target package names. This list includes the "android" package. |
| 478 | */ |
| 479 | public abstract List<String> getTargetPackageNames(int userId); |
| 480 | |
| 481 | /** |
| 482 | * Set which overlay to use for a package. |
| 483 | * @param userId The user for which to update the overlays. |
| 484 | * @param targetPackageName The package name of the package for which to update the overlays. |
| 485 | * @param overlayPackageNames The complete list of overlay packages that should be enabled for |
| 486 | * the target. Previously enabled overlays not specified in the list |
| 487 | * will be disabled. Pass in null or an empty list to disable |
| 488 | * all overlays. The order of the items is significant if several |
| 489 | * overlays modify the same resource. |
| 490 | * @return true if all packages names were known by the package manager, false otherwise |
| 491 | */ |
| 492 | public abstract boolean setEnabledOverlayPackages(int userId, String targetPackageName, |
| 493 | List<String> overlayPackageNames); |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 494 | |
| 495 | /** |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 496 | * Resolves an activity intent, allowing instant apps to be resolved. |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 497 | */ |
| 498 | public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 499 | int flags, int userId, boolean resolveForStart, int filterCallingUid); |
Chad Brubaker | 0f28a80 | 2017-03-29 14:05:52 -0700 | [diff] [blame] | 500 | |
| 501 | /** |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 502 | * Resolves a service intent, allowing instant apps to be resolved. |
| 503 | */ |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 504 | public abstract ResolveInfo resolveService(Intent intent, String resolvedType, |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 505 | int flags, int userId, int callingUid); |
| 506 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 507 | /** |
| 508 | * Resolves a content provider intent. |
| 509 | */ |
| 510 | public abstract ProviderInfo resolveContentProvider(String name, int flags, int userId); |
| 511 | |
Todd Kennedy | 51b3aac | 2017-03-30 17:50:42 -0700 | [diff] [blame] | 512 | /** |
Chad Brubaker | 0f28a80 | 2017-03-29 14:05:52 -0700 | [diff] [blame] | 513 | * Track the creator of a new isolated uid. |
| 514 | * @param isolatedUid The newly created isolated uid. |
| 515 | * @param ownerUid The uid of the app that created the isolated process. |
| 516 | */ |
| 517 | public abstract void addIsolatedUid(int isolatedUid, int ownerUid); |
| 518 | |
| 519 | /** |
| 520 | * Track removal of an isolated uid. |
| 521 | * @param isolatedUid isolated uid that is no longer being used. |
| 522 | */ |
| 523 | public abstract void removeIsolatedUid(int isolatedUid); |
Makoto Onuki | e92f794 | 2017-04-26 14:38:18 -0700 | [diff] [blame] | 524 | |
| 525 | /** |
| 526 | * Return the taget SDK version for the app with the given UID. |
| 527 | */ |
| 528 | public abstract int getUidTargetSdkVersion(int uid); |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 529 | |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 530 | /** |
| 531 | * Return the taget SDK version for the app with the given package name. |
| 532 | */ |
| 533 | public abstract int getPackageTargetSdkVersion(String packageName); |
| 534 | |
Makoto Onuki | ad62301 | 2017-05-15 09:29:34 -0700 | [diff] [blame] | 535 | /** Whether the binder caller can access instant apps. */ |
Todd Kennedy | 3051caa | 2017-05-23 15:54:18 -0700 | [diff] [blame] | 536 | public abstract boolean canAccessInstantApps(int callingUid, int userId); |
Svet Ganov | f935a70 | 2017-08-22 12:15:58 -0700 | [diff] [blame] | 537 | |
Todd Kennedy | 662504f | 2018-03-14 08:09:00 -0700 | [diff] [blame] | 538 | /** Whether the binder caller can access the given component. */ |
| 539 | public abstract boolean canAccessComponent(int callingUid, ComponentName component, int userId); |
| 540 | |
Svet Ganov | f935a70 | 2017-08-22 12:15:58 -0700 | [diff] [blame] | 541 | /** |
| 542 | * Returns {@code true} if a given package has instant application meta-data. |
| 543 | * Otherwise, returns {@code false}. Meta-data is state (eg. cookie, app icon, etc) |
| 544 | * associated with an instant app. It may be kept after the instant app has been uninstalled. |
| 545 | */ |
| 546 | public abstract boolean hasInstantApplicationMetadata(String packageName, int userId); |
Todd Kennedy | df113c3 | 2017-08-31 16:10:29 -0700 | [diff] [blame] | 547 | |
| 548 | /** |
| 549 | * Updates a package last used time. |
| 550 | */ |
| 551 | public abstract void notifyPackageUse(String packageName, int reason); |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 552 | |
| 553 | /** |
| 554 | * Returns a package object for the given package name. |
| 555 | */ |
| 556 | public abstract @Nullable PackageParser.Package getPackage(@NonNull String packageName); |
| 557 | |
| 558 | /** |
Todd Kennedy | 42d6160 | 2017-12-12 14:44:19 -0800 | [diff] [blame] | 559 | * Returns a list without a change observer. |
| 560 | * |
| 561 | * {@see #getPackageList(PackageListObserver)} |
| 562 | */ |
| 563 | public @NonNull PackageList getPackageList() { |
| 564 | return getPackageList(null); |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Returns the list of packages installed at the time of the method call. |
| 569 | * <p>The given observer is notified when the list of installed packages |
| 570 | * changes [eg. a package was installed or uninstalled]. It will not be |
| 571 | * notified if a package is updated. |
| 572 | * <p>The package list will not be updated automatically as packages are |
| 573 | * installed / uninstalled. Any changes must be handled within the observer. |
| 574 | */ |
| 575 | public abstract @NonNull PackageList getPackageList(@Nullable PackageListObserver observer); |
| 576 | |
| 577 | /** |
| 578 | * Removes the observer. |
| 579 | * <p>Generally not needed. {@link #getPackageList(PackageListObserver)} will automatically |
| 580 | * remove the observer. |
| 581 | * <p>Does nothing if the observer isn't currently registered. |
| 582 | * <p>Observers are notified asynchronously and it's possible for an observer to be |
| 583 | * invoked after its been removed. |
| 584 | */ |
| 585 | public abstract void removePackageListObserver(@NonNull PackageListObserver observer); |
| 586 | |
| 587 | /** |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 588 | * Returns a package object for the disabled system package name. |
| 589 | */ |
| 590 | public abstract @Nullable PackageParser.Package getDisabledPackage(@NonNull String packageName); |
| 591 | |
| 592 | /** |
| 593 | * Returns whether or not the component is the resolver activity. |
| 594 | */ |
| 595 | public abstract boolean isResolveActivityComponent(@NonNull ComponentInfo component); |
| 596 | |
| 597 | /** |
| 598 | * Returns the package name for a known package. |
| 599 | */ |
| 600 | public abstract @Nullable String getKnownPackageName( |
| 601 | @KnownPackage int knownPackage, int userId); |
| 602 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 603 | /** |
| 604 | * Returns whether the package is an instant app. |
| 605 | */ |
| 606 | public abstract boolean isInstantApp(String packageName, int userId); |
| 607 | |
| 608 | /** |
| 609 | * Returns whether the package is an instant app. |
| 610 | */ |
| 611 | public abstract @Nullable String getInstantAppPackageName(int uid); |
| 612 | |
| 613 | /** |
| 614 | * Returns whether or not access to the application should be filtered. |
| 615 | * <p> |
| 616 | * Access may be limited based upon whether the calling or target applications |
| 617 | * are instant applications. |
| 618 | * |
| 619 | * @see #canAccessInstantApps(int) |
| 620 | */ |
| 621 | public abstract boolean filterAppAccess( |
| 622 | @Nullable PackageParser.Package pkg, int callingUid, int userId); |
| 623 | |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 624 | /* |
| 625 | * NOTE: The following methods are temporary until permissions are extracted from |
| 626 | * the package manager into a component specifically for handling permissions. |
| 627 | */ |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 628 | /** Returns the flags for the given permission. */ |
| 629 | public abstract @Nullable int getPermissionFlagsTEMP(@NonNull String permName, |
| 630 | @NonNull String packageName, int userId); |
| 631 | /** Updates the flags for the given permission. */ |
| 632 | public abstract void updatePermissionFlagsTEMP(@NonNull String permName, |
| 633 | @NonNull String packageName, int flagMask, int flagValues, int userId); |
Michal Karpinski | 528c3e5 | 2018-02-07 17:47:10 +0000 | [diff] [blame] | 634 | |
| 635 | /** |
| 636 | * Returns true if it's still safe to restore data backed up from this app's version |
| 637 | * that was signed with restoringFromSigHash. |
| 638 | */ |
| 639 | public abstract boolean isDataRestoreSafe(@NonNull byte[] restoringFromSigHash, |
| 640 | @NonNull String packageName); |
| 641 | |
| 642 | /** |
| 643 | * Returns true if it's still safe to restore data backed up from this app's version |
| 644 | * that was signed with restoringFromSig. |
| 645 | */ |
| 646 | public abstract boolean isDataRestoreSafe(@NonNull Signature restoringFromSig, |
| 647 | @NonNull String packageName); |
Dan Cashman | 303c4bb | 2018-04-10 07:41:16 -0700 | [diff] [blame] | 648 | |
| 649 | |
| 650 | /** |
| 651 | * Returns true if the the signing information for {@code clientUid} is sufficient to gain |
| 652 | * access gated by {@code capability}. This can happen if the two UIDs have the same signing |
| 653 | * information, if the signing information {@code clientUid} indicates that it has the signing |
| 654 | * certificate for {@code serverUid} in its signing history (if it was previously signed by it), |
| 655 | * or if the signing certificate for {@code clientUid} is in ths signing history for {@code |
| 656 | * serverUid} and with the {@code capability} specified. |
| 657 | */ |
| 658 | public abstract boolean hasSignatureCapability(int serverUid, int clientUid, |
| 659 | @PackageParser.SigningDetails.CertCapabilities int capability); |
Svet Ganov | d873ae6 | 2018-06-25 16:39:23 -0700 | [diff] [blame] | 660 | |
| 661 | /** |
| 662 | * Get the delegate to influence permission checking. |
| 663 | * |
| 664 | * @return The delegate instance or null to clear. |
| 665 | */ |
| 666 | public abstract @Nullable CheckPermissionDelegate getCheckPermissionDelegate(); |
| 667 | |
| 668 | /** |
| 669 | * Set a delegate to influence permission checking. |
| 670 | * |
| 671 | * @param delegate A delegate instance or null to clear. |
| 672 | */ |
| 673 | public abstract void setCheckPermissionDelegate(@Nullable CheckPermissionDelegate delegate); |
Sudheer Shanka | 0a541a5 | 2018-07-31 13:21:11 -0700 | [diff] [blame^] | 674 | |
| 675 | /** |
| 676 | * Get appIds of all available apps which specified android:sharedUserId in the manifest. |
| 677 | * |
| 678 | * @return a SparseArray mapping from appId to it's sharedUserId. |
| 679 | */ |
| 680 | public abstract SparseArray<String> getAppsWithSharedUserIds(); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 681 | } |