1 /* 2 * Copyright (C) 2021 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 com.android.server.pm.permission; 18 19 import android.annotation.AppIdInt; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SpecialUsers.CanBeALL; 23 import android.annotation.UserIdInt; 24 import android.content.Context; 25 import android.content.pm.PackageManager; 26 import android.content.pm.PermissionGroupInfo; 27 import android.content.pm.PermissionInfo; 28 import android.content.pm.permission.SplitPermissionInfoParcelable; 29 import android.permission.IOnPermissionsChangeListener; 30 import android.permission.PermissionManager.PermissionState; 31 import android.permission.PermissionManagerInternal; 32 33 import com.android.server.pm.pkg.AndroidPackage; 34 import com.android.server.pm.pkg.PackageState; 35 36 import java.io.FileDescriptor; 37 import java.io.PrintWriter; 38 import java.util.List; 39 import java.util.Map; 40 import java.util.Set; 41 42 /** 43 * Interface for managing all permissions and handling permissions related tasks. 44 */ 45 public interface PermissionManagerServiceInterface extends PermissionManagerInternal { 46 /** 47 * Dump. 48 */ dump(FileDescriptor fd, PrintWriter pw, String[] args)49 void dump(FileDescriptor fd, PrintWriter pw, String[] args); 50 51 /** 52 * Retrieve all of the known permission groups in the system. 53 * 54 * @param flags additional option flags to modify the data returned 55 * @return a list of {@link PermissionGroupInfo} containing information about all of the known 56 * permission groups 57 */ getAllPermissionGroups( @ackageManager.PermissionGroupInfoFlags int flags)58 List<PermissionGroupInfo> getAllPermissionGroups( 59 @PackageManager.PermissionGroupInfoFlags int flags); 60 61 /** 62 * Retrieve all of the information we know about a particular group of permissions. 63 * 64 * @param groupName the fully qualified name (e.g. com.android.permission_group.APPS) of the 65 * permission you are interested in 66 * @param flags additional option flags to modify the data returned 67 * @return a {@link PermissionGroupInfo} containing information about the permission, or 68 * {@code null} if not found 69 */ getPermissionGroupInfo(String groupName, @PackageManager.PermissionGroupInfoFlags int flags)70 PermissionGroupInfo getPermissionGroupInfo(String groupName, 71 @PackageManager.PermissionGroupInfoFlags int flags); 72 73 /** 74 * Retrieve all of the information we know about a particular permission. 75 * 76 * @param permName the fully qualified name (e.g. com.android.permission.LOGIN) of the 77 * permission you are interested in 78 * @param flags additional option flags to modify the data returned 79 * @return a {@link PermissionInfo} containing information about the permission, or {@code null} 80 * if not found 81 */ getPermissionInfo(@onNull String permName, @PackageManager.PermissionInfoFlags int flags, @NonNull String opPackageName)82 PermissionInfo getPermissionInfo(@NonNull String permName, 83 @PackageManager.PermissionInfoFlags int flags, @NonNull String opPackageName); 84 85 /** 86 * Query for all of the permissions associated with a particular group. 87 * 88 * @param groupName the fully qualified name (e.g. com.android.permission.LOGIN) of the 89 * permission group you are interested in. Use {@code null} to find all of the 90 * permissions not associated with a group 91 * @param flags additional option flags to modify the data returned 92 * @return a list of {@link PermissionInfo} containing information about all of the permissions 93 * in the given group, or {@code null} if the group is not found 94 */ queryPermissionsByGroup(String groupName, @PackageManager.PermissionInfoFlags int flags)95 List<PermissionInfo> queryPermissionsByGroup(String groupName, 96 @PackageManager.PermissionInfoFlags int flags); 97 98 /** 99 * Add a new dynamic permission to the system. For this to work, your package must have defined 100 * a permission tree through the 101 * {@link android.R.styleable#AndroidManifestPermissionTree <permission-tree>} tag in its 102 * manifest. A package can only add permissions to trees that were defined by either its own 103 * package or another with the same user id; a permission is in a tree if it matches the name of 104 * the permission tree + ".": for example, "com.foo.bar" is a member of the permission tree 105 * "com.foo". 106 * <p> 107 * It is good to make your permission tree name descriptive, because you are taking possession 108 * of that entire set of permission names. Thus, it must be under a domain you control, with a 109 * suffix that will not match any normal permissions that may be declared in any applications 110 * that are part of that domain. 111 * <p> 112 * New permissions must be added before any .apks are installed that use those permissions. 113 * Permissions you add through this method are remembered across reboots of the device. If the 114 * given permission already exists, the info you supply here will be used to update it. 115 * 116 * @param info description of the permission to be added 117 * @param async whether the persistence of the permission should be asynchronous, allowing it to 118 * return quicker and batch a series of adds, at the expense of no guarantee the 119 * added permission will be retained if the device is rebooted before it is 120 * written. 121 * @return {@code true} if a new permission was created, {@code false} if an existing one was 122 * updated 123 * @throws SecurityException if you are not allowed to add the given permission name 124 * 125 * @see #removePermission(String) 126 */ addPermission(PermissionInfo info, boolean async)127 boolean addPermission(PermissionInfo info, boolean async); 128 129 /** 130 * Removes a permission that was previously added with 131 * {@link #addPermission(PermissionInfo, boolean)}. The same ownership rules apply -- you are 132 * only allowed to remove permissions that you are allowed to add. 133 * 134 * @param permName the name of the permission to remove 135 * @throws SecurityException if you are not allowed to remove the given permission name 136 * 137 * @see #addPermission(PermissionInfo, boolean) 138 */ removePermission(String permName)139 void removePermission(String permName); 140 141 /** 142 * Gets the permission state flags associated with a permission. 143 * 144 * @param packageName the package name for which to get the flags 145 * @param permName the permission for which to get the flags 146 * @param deviceId The device for which to get the flags 147 * @param userId the user for which to get permission flags 148 * @return the permission flags 149 */ getPermissionFlags(String packageName, String permName, String deviceId, @UserIdInt int userId)150 int getPermissionFlags(String packageName, String permName, String deviceId, 151 @UserIdInt int userId); 152 153 /** 154 * Updates the flags associated with a permission by replacing the flags in the specified mask 155 * with the provided flag values. 156 * 157 * @param packageName The package name for which to update the flags 158 * @param permName The permission for which to update the flags 159 * @param flagMask The flags which to replace 160 * @param flagValues The flags with which to replace 161 * @param deviceId The device for which to update the permission flags 162 * @param userId The user for which to update the permission flags 163 */ updatePermissionFlags(String packageName, String permName, int flagMask, int flagValues, boolean checkAdjustPolicyFlagPermission, String deviceId, @UserIdInt int userId)164 void updatePermissionFlags(String packageName, String permName, int flagMask, int flagValues, 165 boolean checkAdjustPolicyFlagPermission, String deviceId, 166 @UserIdInt int userId); 167 168 /** 169 * Update the permission flags for all packages and runtime permissions of a user in order 170 * to allow device or profile owner to remove POLICY_FIXED. 171 */ updatePermissionFlagsForAllApps(int flagMask, int flagValues, int userId)172 void updatePermissionFlagsForAllApps(int flagMask, int flagValues, int userId); 173 174 /** 175 * TODO: theianchen We should get rid of the IBinder interface which is an implementation detail 176 * 177 * Add a listener for permission changes for installed packages. 178 * @param listener the listener to add 179 */ addOnPermissionsChangeListener(IOnPermissionsChangeListener listener)180 void addOnPermissionsChangeListener(IOnPermissionsChangeListener listener); 181 182 /** 183 * Remove a listener for permission changes for installed packages. 184 * @param listener the listener to remove 185 */ removeOnPermissionsChangeListener(IOnPermissionsChangeListener listener)186 void removeOnPermissionsChangeListener(IOnPermissionsChangeListener listener); 187 188 /** 189 * addAllowlistedRestrictedPermission. TODO: theianchen add doc 190 */ addAllowlistedRestrictedPermission(@onNull String packageName, @NonNull String permName, @PackageManager.PermissionWhitelistFlags int flags, @UserIdInt int userId)191 boolean addAllowlistedRestrictedPermission(@NonNull String packageName, 192 @NonNull String permName, @PackageManager.PermissionWhitelistFlags int flags, 193 @UserIdInt int userId); 194 195 /** 196 * Gets the restricted permissions that have been allowlisted and the app is allowed to have 197 * them granted in their full form. 198 * <p> 199 * Permissions can be hard restricted which means that the app cannot hold them or soft 200 * restricted where the app can hold the permission but in a weaker form. Whether a permission 201 * is {@link PermissionInfo#FLAG_HARD_RESTRICTED hard restricted} or 202 * {@link PermissionInfo#FLAG_SOFT_RESTRICTED soft restricted} depends on the permission 203 * declaration. Allowlisting a hard restricted permission allows for the to hold that permission 204 * and allowlisting a soft restricted permission allows the app to hold the permission in its 205 * full, unrestricted form. 206 * <p> 207 * There are four allowlists: 208 * <ol> 209 * <li> 210 * One for cases where the system permission policy allowlists a permission. This list 211 * corresponds to the {@link PackageManager#FLAG_PERMISSION_WHITELIST_SYSTEM} flag. Can only be 212 * accessed by pre-installed holders of a dedicated permission. 213 * <li> 214 * One for cases where the system allowlists the permission when upgrading from an OS version in 215 * which the permission was not restricted to an OS version in which the permission is 216 * restricted. This list corresponds to the 217 * {@link PackageManager#FLAG_PERMISSION_WHITELIST_UPGRADE} flag. Can be accessed by 218 * pre-installed holders of a dedicated permission or the installer on record. 219 * <li> 220 * One for cases where the installer of the package allowlists a permission. This list 221 * corresponds to the {@link PackageManager#FLAG_PERMISSION_WHITELIST_INSTALLER} flag. Can be 222 * accessed by pre-installed holders of a dedicated permission or the installer on record. 223 * </ol> 224 * 225 * @param packageName the app for which to get allowlisted permissions 226 * @param flags the flag to determine which allowlist to query. Only one flag can be 227 * passed. 228 * @return the allowlisted permissions that are on any of the allowlists you query for 229 * @throws SecurityException if you try to access a allowlist that you have no access to 230 * 231 * @see #addAllowlistedRestrictedPermission(String, String, int) 232 * @see #removeAllowlistedRestrictedPermission(String, String, int) 233 * @see PackageManager#FLAG_PERMISSION_WHITELIST_SYSTEM 234 * @see PackageManager#FLAG_PERMISSION_WHITELIST_UPGRADE 235 * @see PackageManager#FLAG_PERMISSION_WHITELIST_INSTALLER 236 */ getAllowlistedRestrictedPermissions(@onNull String packageName, @PackageManager.PermissionWhitelistFlags int flags, @UserIdInt int userId)237 List<String> getAllowlistedRestrictedPermissions(@NonNull String packageName, 238 @PackageManager.PermissionWhitelistFlags int flags, @UserIdInt int userId); 239 240 /** 241 * Removes a allowlisted restricted permission for an app. 242 * <p> 243 * Permissions can be hard restricted which means that the app cannot hold them or soft 244 * restricted where the app can hold the permission but in a weaker form. Whether a permission 245 * is {@link PermissionInfo#FLAG_HARD_RESTRICTED hard restricted} or 246 * {@link PermissionInfo#FLAG_SOFT_RESTRICTED soft restricted} depends on the permission 247 * declaration. Allowlisting a hard restricted permission allows for the to hold that permission 248 * and allowlisting a soft restricted permission allows the app to hold the permission in its 249 * full, unrestricted form. 250 * <p>There are four allowlists: 251 * <ol> 252 * <li> 253 * One for cases where the system permission policy allowlists a permission. This list 254 * corresponds to the {@link PackageManager#FLAG_PERMISSION_WHITELIST_SYSTEM} flag. Can only be 255 * accessed by pre-installed holders of a dedicated permission. 256 * <li> 257 * One for cases where the system allowlists the permission when upgrading from an OS version in 258 * which the permission was not restricted to an OS version in which the permission is 259 * restricted. This list corresponds to the 260 * {@link PackageManager#FLAG_PERMISSION_WHITELIST_UPGRADE} flag. Can be accessed by 261 * pre-installed holders of a dedicated permission or the installer on record. 262 * <li> 263 * One for cases where the installer of the package allowlists a permission. This list 264 * corresponds to the {@link PackageManager#FLAG_PERMISSION_WHITELIST_INSTALLER} flag. Can be 265 * accessed by pre-installed holders of a dedicated permission or the installer on record. 266 * </ol> 267 * <p> 268 * You need to specify the allowlists for which to set the allowlisted permissions which will 269 * clear the previous allowlisted permissions and replace them with the provided ones. 270 * 271 * @param packageName the app for which to get allowlisted permissions 272 * @param permName the allowlisted permission to remove 273 * @param flags the allowlists from which to remove. Passing multiple flags updates all 274 * specified allowlists. 275 * @return whether the permission was removed from the allowlist 276 * @throws SecurityException if you try to modify a allowlist that you have no access to. 277 * 278 * @see #getAllowlistedRestrictedPermissions(String, int) 279 * @see #addAllowlistedRestrictedPermission(String, String, int) 280 * @see PackageManager#FLAG_PERMISSION_WHITELIST_SYSTEM 281 * @see PackageManager#FLAG_PERMISSION_WHITELIST_UPGRADE 282 * @see PackageManager#FLAG_PERMISSION_WHITELIST_INSTALLER 283 */ removeAllowlistedRestrictedPermission(@onNull String packageName, @NonNull String permName, @PackageManager.PermissionWhitelistFlags int flags, @UserIdInt int userId)284 boolean removeAllowlistedRestrictedPermission(@NonNull String packageName, 285 @NonNull String permName, @PackageManager.PermissionWhitelistFlags int flags, 286 @UserIdInt int userId); 287 288 /** 289 * Grant a runtime permission to an application which the application does not already have. The 290 * permission must have been requested by the application. If the application is not allowed to 291 * hold the permission, a {@link java.lang.SecurityException} is thrown. If the package or 292 * permission is invalid, a {@link java.lang.IllegalArgumentException} is thrown. 293 * <p> 294 * <strong>Note: </strong>Using this API requires holding 295 * {@code android.permission.GRANT_RUNTIME_PERMISSIONS} and if the user ID is not the current 296 * user {@code android.permission.INTERACT_ACROSS_USERS_FULL}. 297 * 298 * @param packageName the package to which to grant the permission 299 * @param permName the permission name to grant 300 * @param deviceId the device for which to grant the permission 301 * @param userId the user for which to grant the permission 302 * 303 * @see #revokeRuntimePermission(String, String, String, int, String) 304 */ grantRuntimePermission(String packageName, String permName, String deviceId, @UserIdInt int userId)305 void grantRuntimePermission(String packageName, String permName, String deviceId, 306 @UserIdInt int userId); 307 308 /** 309 * Revoke a runtime permission that was previously granted by 310 * {@link #grantRuntimePermission(String, String, String, int)}. The permission must 311 * have been requested by and granted to the application. If the application is not allowed to 312 * hold the permission, a {@link java.lang.SecurityException} is thrown. If the package or 313 * permission is invalid, a {@link java.lang.IllegalArgumentException} is thrown. 314 * <p> 315 * <strong>Note: </strong>Using this API requires holding 316 * {@code android.permission.REVOKE_RUNTIME_PERMISSIONS} and if the user ID is not the current 317 * user {@code android.permission.INTERACT_ACROSS_USERS_FULL}. 318 * 319 * @param packageName the package from which to revoke the permission 320 * @param permName the permission name to revoke 321 * @param deviceId the device for which to revoke the permission 322 * @param userId the user for which to revoke the permission 323 * @param reason the reason for the revoke, or {@code null} for unspecified 324 * 325 * @see #grantRuntimePermission(String, String, String, int) 326 */ revokeRuntimePermission(String packageName, String permName, String deviceId, @UserIdInt int userId, String reason)327 void revokeRuntimePermission(String packageName, String permName, String deviceId, 328 @UserIdInt int userId, String reason); 329 330 /** 331 * Revoke the POST_NOTIFICATIONS permission, without killing the app. This method must ONLY BE 332 * USED in CTS or local tests. 333 * 334 * @param packageName The package to be revoked 335 * @param userId The user for which to revoke 336 */ revokePostNotificationPermissionWithoutKillForTest(String packageName, int userId)337 void revokePostNotificationPermissionWithoutKillForTest(String packageName, int userId); 338 339 /** 340 * Get whether you should show UI with rationale for requesting a permission. You should do this 341 * only if you do not have the permission and the context in which the permission is requested 342 * does not clearly communicate to the user what would be the benefit from grating this 343 * permission. 344 * 345 * @param packageName the package name 346 * @param permName a permission your app wants to request 347 * @param deviceId the device for which to check the permission 348 * @param userId the user for which to check the permission 349 * @return whether you can show permission rationale UI 350 */ shouldShowRequestPermissionRationale(String packageName, String permName, String deviceId, @UserIdInt int userId)351 boolean shouldShowRequestPermissionRationale(String packageName, String permName, 352 String deviceId, @UserIdInt int userId); 353 354 /** 355 * Checks whether a particular permission has been revoked for a package by policy. Typically, 356 * the device owner or the profile owner may apply such a policy. The user cannot grant policy 357 * revoked permissions, hence the only way for an app to get such a permission is by a policy 358 * change. 359 * 360 * @param packageName the name of the package you are checking against 361 * @param permName the name of the permission you are checking for 362 * @param deviceId the device for which you are checking the permission 363 * @param userId the device for which you are checking the permission 364 * @return whether the permission is restricted by policy 365 */ isPermissionRevokedByPolicy(String packageName, String permName, String deviceId, @UserIdInt int userId)366 boolean isPermissionRevokedByPolicy(String packageName, String permName, 367 String deviceId, @UserIdInt int userId); 368 369 /** 370 * Get set of permissions that have been split into more granular or dependent permissions. 371 * 372 * <p>E.g. before {@link android.os.Build.VERSION_CODES#Q} an app that was granted 373 * {@link Manifest.permission#ACCESS_COARSE_LOCATION} could access the location while it was in 374 * foreground and background. On platforms after {@link android.os.Build.VERSION_CODES#Q} 375 * the location permission only grants location access while the app is in foreground. This 376 * would break apps that target before {@link android.os.Build.VERSION_CODES#Q}. Hence whenever 377 * such an old app asks for a location permission (i.e. the 378 * {@link PermissionManager.SplitPermissionInfo#getSplitPermission()}), then the 379 * {@link Manifest.permission#ACCESS_BACKGROUND_LOCATION} permission (inside 380 * {@link PermissionManager.SplitPermissionInfo#getNewPermissions}) is added. 381 * 382 * <p>Note: Regular apps do not have to worry about this. The platform and permission controller 383 * automatically add the new permissions where needed. 384 * 385 * @return All permissions that are split. 386 */ getSplitPermissions()387 List<SplitPermissionInfoParcelable> getSplitPermissions(); 388 389 /** 390 * Check whether a permission is granted or not to a package. 391 * 392 * @param pkgName package name 393 * @param permName permission name 394 * @param deviceId persistent device ID 395 * @param userId user ID 396 * @return permission result {@link PackageManager.PermissionResult} 397 */ checkPermission(String pkgName, String permName, String deviceId, @UserIdInt int userId)398 int checkPermission(String pkgName, String permName, String deviceId, 399 @UserIdInt int userId); 400 401 /** 402 * Check whether a permission is granted or not to an UID. 403 * 404 * @param uid UID 405 * @param permName permission name 406 * @param deviceId persistent device ID 407 * @return permission result {@link PackageManager.PermissionResult} 408 */ checkUidPermission(int uid, String permName, String deviceId)409 int checkUidPermission(int uid, String permName, String deviceId); 410 411 /** 412 * Returns one of the permission state 413 * {@link Context.PermissionRequestState#PERMISSION_REQUEST_STATE_GRANTED}, 414 * {@link Context.PermissionRequestState#PERMISSION_REQUEST_STATE_REQUESTABLE}, or 415 * {@link Context.PermissionRequestState#PERMISSION_REQUEST_STATE_UNREQUESTABLE} 416 * for permission request permission flow. 417 */ getPermissionRequestState(@onNull String packageName, @NonNull String permName, int deviceId, @NonNull String persistentDeviceId)418 int getPermissionRequestState(@NonNull String packageName, @NonNull String permName, 419 int deviceId, @NonNull String persistentDeviceId); 420 421 /** 422 * Gets the permission states for requested package, persistent device and user. 423 * <p> 424 * <strong>Note: </strong>Default device permissions are not inherited in this API. Returns the 425 * exact permission states for the requested device. 426 * 427 * @param packageName name of the package you are checking against 428 * @param deviceId id of the persistent device you are checking against 429 * @param userId id of the user for which to get permission flags 430 * @return mapping of all permission states keyed by their permission names 431 * 432 * @hide 433 */ getAllPermissionStates(@onNull String packageName, @NonNull String deviceId, @UserIdInt int userId)434 Map<String, PermissionState> getAllPermissionStates(@NonNull String packageName, 435 @NonNull String deviceId, @UserIdInt int userId); 436 437 /** 438 * Get all the package names requesting app op permissions. 439 * 440 * @return a map of app op permission names to package names requesting them 441 */ getAllAppOpPermissionPackages()442 Map<String, Set<String>> getAllAppOpPermissionPackages(); 443 444 /** 445 * Get whether permission review is required for a package. 446 * 447 * @param packageName the name of the package 448 * @param userId the user ID 449 * @return whether permission review is required 450 */ isPermissionsReviewRequired(@onNull String packageName, @UserIdInt int userId)451 boolean isPermissionsReviewRequired(@NonNull String packageName, 452 @UserIdInt int userId); 453 454 /** 455 * Reset the runtime permission state changes for a package for all devices. 456 * 457 * TODO(zhanghai): Turn this into package change callback? 458 */ resetRuntimePermissions(@onNull AndroidPackage pkg, @UserIdInt int userId)459 void resetRuntimePermissions(@NonNull AndroidPackage pkg, @UserIdInt int userId); 460 461 /** 462 * Reset the runtime permission state changes for all packages in a user. 463 * 464 * @param userId the user ID 465 */ resetRuntimePermissionsForUser(@serIdInt int userId)466 void resetRuntimePermissionsForUser(@UserIdInt int userId); 467 468 /** 469 * Read legacy permission state from package settings. 470 * 471 * TODO(zhanghai): This is a temporary method because we should not expose 472 * {@code PackageSetting} which is a implementation detail that permission should not know. 473 * Instead, it should retrieve the legacy state via a defined API. 474 */ readLegacyPermissionStateTEMP()475 void readLegacyPermissionStateTEMP(); 476 477 /** 478 * Write legacy permission state to package settings. 479 * 480 * TODO(zhanghai): This is a temporary method and should be removed once we migrated persistence 481 * for permission. 482 */ writeLegacyPermissionStateTEMP()483 void writeLegacyPermissionStateTEMP(); 484 485 /** 486 * Get all the permissions definitions from a package that's installed in the system. 487 * <p> 488 * A permission definition in a normal app may not be installed if it's overridden by the 489 * platform or system app that contains a conflicting definition after system upgrade. 490 * 491 * @param packageName the name of the package 492 * @return the names of the installed permissions 493 */ 494 @NonNull getInstalledPermissions(@onNull String packageName)495 Set<String> getInstalledPermissions(@NonNull String packageName); 496 497 /** 498 * Get all the permissions granted to a package. 499 * 500 * @param packageName package name 501 * @param userId user ID 502 * @return the names of the granted permissions 503 */ 504 @NonNull getGrantedPermissions(@onNull String packageName, @UserIdInt int userId)505 Set<String> getGrantedPermissions(@NonNull String packageName, @UserIdInt int userId); 506 507 /** 508 * Get the GIDs of a permission. 509 * 510 * @param permissionName the name of the permission 511 * @param userId the user ID 512 * @return the GIDs of the permission 513 */ 514 @NonNull getPermissionGids(@onNull String permissionName, @UserIdInt int userId)515 int[] getPermissionGids(@NonNull String permissionName, @UserIdInt int userId); 516 517 /** 518 * Get the packages that have requested an app op permission. 519 * 520 * @param permissionName the name of the app op permission 521 * @return the names of the packages that have requested the app op permission 522 */ 523 @NonNull getAppOpPermissionPackages(@onNull String permissionName)524 String[] getAppOpPermissionPackages(@NonNull String permissionName); 525 526 /** HACK HACK methods to allow for partial migration of data to the PermissionManager class */ 527 @Nullable getPermissionTEMP(@onNull String permName)528 Permission getPermissionTEMP(@NonNull String permName); 529 530 /** Get all permissions that have a certain protection */ 531 @NonNull getAllPermissionsWithProtection( @ermissionInfo.Protection int protection)532 List<PermissionInfo> getAllPermissionsWithProtection( 533 @PermissionInfo.Protection int protection); 534 535 /** Get all permissions that have certain protection flags */ getAllPermissionsWithProtectionFlags( @ermissionInfo.ProtectionFlags int protectionFlags)536 @NonNull List<PermissionInfo> getAllPermissionsWithProtectionFlags( 537 @PermissionInfo.ProtectionFlags int protectionFlags); 538 539 /** 540 * Get all the legacy permissions currently registered in the system. 541 * 542 * @return the legacy permissions 543 */ 544 @NonNull getLegacyPermissions()545 List<LegacyPermission> getLegacyPermissions(); 546 547 /** 548 * Get the legacy permission state of an app ID, either a package or a shared user. 549 * 550 * @param appId the app ID 551 * @return the legacy permission state 552 */ 553 @NonNull getLegacyPermissionState(@ppIdInt int appId)554 LegacyPermissionState getLegacyPermissionState(@AppIdInt int appId); 555 556 /** 557 * Read legacy permissions from legacy permission settings. 558 * 559 * TODO(zhanghai): This is a temporary method because we should not expose 560 * {@code LegacyPermissionSettings} which is a implementation detail that permission should not 561 * know. Instead, it should retrieve the legacy permissions via a defined API. 562 */ readLegacyPermissionsTEMP(@onNull LegacyPermissionSettings legacyPermissionSettings)563 void readLegacyPermissionsTEMP(@NonNull LegacyPermissionSettings legacyPermissionSettings); 564 565 /** 566 * Write legacy permissions to legacy permission settings. 567 * 568 * TODO(zhanghai): This is a temporary method and should be removed once we migrated persistence 569 * for permission. 570 */ writeLegacyPermissionsTEMP(@onNull LegacyPermissionSettings legacyPermissionSettings)571 void writeLegacyPermissionsTEMP(@NonNull LegacyPermissionSettings legacyPermissionSettings); 572 573 /** 574 * Get the fingerprint for default permission grants. 575 */ 576 @Nullable getDefaultPermissionGrantFingerprint(@serIdInt int userId)577 String getDefaultPermissionGrantFingerprint(@UserIdInt int userId); 578 579 /** 580 * Set the fingerprint for default permission grants. 581 */ setDefaultPermissionGrantFingerprint(@onNull String fingerprint, @UserIdInt int userId)582 void setDefaultPermissionGrantFingerprint(@NonNull String fingerprint, @UserIdInt int userId); 583 584 /** 585 * Callback when the system is ready. 586 */ onSystemReady()587 void onSystemReady(); 588 589 /** 590 * Callback when a storage volume is mounted, so that all packages on it become available. 591 * 592 * @param volumeUuid the UUID of the storage volume 593 * @param fingerprintChanged whether the current build fingerprint is different from what it was 594 * when this volume was last mounted 595 */ onStorageVolumeMounted(@onNull String volumeUuid, boolean fingerprintChanged)596 void onStorageVolumeMounted(@NonNull String volumeUuid, boolean fingerprintChanged); 597 598 /** 599 * Get the GIDs computed from the permission state of a UID, either a package or a shared user. 600 * 601 * @param uid the UID 602 * @return the GIDs for the UID 603 */ 604 @NonNull getGidsForUid(int uid)605 int[] getGidsForUid(int uid); 606 607 /** 608 * Callback when a user has been created. 609 * 610 * @param userId the created user ID 611 */ onUserCreated(@serIdInt int userId)612 void onUserCreated(@UserIdInt int userId); 613 614 /** 615 * Callback when a user has been removed. 616 * 617 * @param userId the removed user ID 618 */ onUserRemoved(@serIdInt int userId)619 void onUserRemoved(@UserIdInt int userId); 620 621 /** 622 * Callback when a package has been added. 623 * 624 * @param packageState the added package 625 * @param isInstantApp whether the added package is an instant app 626 * @param oldPkg the old package, or {@code null} if none 627 */ onPackageAdded(@onNull PackageState packageState, boolean isInstantApp, @Nullable AndroidPackage oldPkg)628 void onPackageAdded(@NonNull PackageState packageState, boolean isInstantApp, 629 @Nullable AndroidPackage oldPkg); 630 631 /** 632 * Callback when a package has been installed for a user. 633 * 634 * @param pkg the installed package 635 * @param previousAppId the previous app ID if the package is leaving a shared UID, 636 * or Process.INVALID_UID 637 * @param params the parameters passed in for package installation 638 * @param userId the user ID this package is installed for 639 */ onPackageInstalled(@onNull AndroidPackage pkg, int previousAppId, @NonNull PermissionManagerServiceInternal.PackageInstalledParams params, @UserIdInt int userId)640 void onPackageInstalled(@NonNull AndroidPackage pkg, int previousAppId, 641 @NonNull PermissionManagerServiceInternal.PackageInstalledParams params, 642 @UserIdInt int userId); 643 644 /** 645 * Callback when a package has been removed. 646 * 647 * @param pkg the removed package 648 */ onPackageRemoved(@onNull AndroidPackage pkg)649 void onPackageRemoved(@NonNull AndroidPackage pkg); 650 651 /** 652 * Callback when a package has been uninstalled. 653 * <p> 654 * The package may have been fully removed from the system, or only marked as uninstalled for 655 * this user but still installed for other users. 656 * 657 * @param packageName the name of the uninstalled package 658 * @param appId the app ID of the uninstalled package 659 * @param packageState the uninstalled package 660 * @param pkg the uninstalled package 661 * @param sharedUserPkgs the packages that are in the same shared user 662 * @param userId the user ID the package is uninstalled for 663 */ onPackageUninstalled(@onNull String packageName, int appId, @NonNull PackageState packageState, @Nullable AndroidPackage pkg, @NonNull List<AndroidPackage> sharedUserPkgs, @CanBeALL @UserIdInt int userId)664 void onPackageUninstalled(@NonNull String packageName, int appId, 665 @NonNull PackageState packageState, @Nullable AndroidPackage pkg, 666 @NonNull List<AndroidPackage> sharedUserPkgs, @CanBeALL @UserIdInt int userId); 667 } 668