当前位置:   article > 正文

Android12 授予APK默认权限_getdefaultproviderauthoritypackage

getdefaultproviderauthoritypackage

不同于以往的Android版本 可以直接在此处设置:

Android/frameworks/base/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java

  1. private void grantDefaultSystemHandlerPermissions(PackageManagerWrapper pm, int userId) {
  2. Log.i(TAG, "Granting permissions to default platform handlers for user " + userId);
  3. ..........省略代码
  4. // Installer
  5. grantSystemFixedPermissionsToSystemPackage(pm,
  6. ArrayUtils.firstOrNull(getKnownPackages(
  7. PackageManagerInternal.PACKAGE_INSTALLER, userId)),
  8. userId, STORAGE_PERMISSIONS);
  9. // Verifier
  10. final String verifier = ArrayUtils.firstOrNull(getKnownPackages(
  11. PackageManagerInternal.PACKAGE_VERIFIER, userId));
  12. grantSystemFixedPermissionsToSystemPackage(pm, verifier, userId, STORAGE_PERMISSIONS);
  13. grantPermissionsToSystemPackage(pm, verifier, userId, PHONE_PERMISSIONS, SMS_PERMISSIONS);
  14. // SetupWizard
  15. grantPermissionsToSystemPackage(pm,
  16. ArrayUtils.firstOrNull(getKnownPackages(
  17. PackageManagerInternal.PACKAGE_SETUP_WIZARD, userId)), userId,
  18. PHONE_PERMISSIONS, CONTACTS_PERMISSIONS, ALWAYS_LOCATION_PERMISSIONS,
  19. CAMERA_PERMISSIONS);
  20. // Camera
  21. grantPermissionsToSystemPackage(pm,
  22. getDefaultSystemHandlerActivityPackage(pm, MediaStore.ACTION_IMAGE_CAPTURE, userId),
  23. userId, CAMERA_PERMISSIONS, MICROPHONE_PERMISSIONS, STORAGE_PERMISSIONS);
  24. // Sound recorder
  25. grantPermissionsToSystemPackage(pm,
  26. getDefaultSystemHandlerActivityPackage(pm,
  27. MediaStore.Audio.Media.RECORD_SOUND_ACTION, userId),
  28. userId, MICROPHONE_PERMISSIONS);
  29. // Media provider
  30. grantSystemFixedPermissionsToSystemPackage(pm,
  31. getDefaultProviderAuthorityPackage(MediaStore.AUTHORITY, userId), userId,
  32. STORAGE_PERMISSIONS);
  33. // Downloads provider
  34. grantSystemFixedPermissionsToSystemPackage(pm,
  35. getDefaultProviderAuthorityPackage("downloads", userId), userId,
  36. STORAGE_PERMISSIONS);
  37. // Downloads UI
  38. grantSystemFixedPermissionsToSystemPackage(pm,
  39. getDefaultSystemHandlerActivityPackage(pm,
  40. DownloadManager.ACTION_VIEW_DOWNLOADS, userId),
  41. userId, STORAGE_PERMISSIONS);
  42. // Storage provider
  43. grantSystemFixedPermissionsToSystemPackage(pm,
  44. getDefaultProviderAuthorityPackage("com.android.externalstorage.documents", userId),
  45. userId, STORAGE_PERMISSIONS);
  46. // CertInstaller
  47. grantSystemFixedPermissionsToSystemPackage(pm,
  48. getDefaultSystemHandlerActivityPackage(pm, Credentials.INSTALL_ACTION, userId),
  49. userId, STORAGE_PERMISSIONS);

 授予权限类型参考下表:

 比如 为DemoAPK添加定位&通话以及访问内存权限.

  1. // DemoAPK
  2. grantPermissionsToSystemPackage(pm, "com.test.demoApk",
  3. userId, PHONE_PERMISSIONS, ALWAYS_LOCATION_PERMISSIONS, STORAGE_PERMISSIONS);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/261336
推荐阅读
相关标签
  

闽ICP备14008679号