当前位置:   article > 正文

Android 给 app默认权限(不弹窗申请权限)_defaultpermissiongrantpolicy.java

defaultpermissiongrantpolicy.java

1.系统app

系统app的权限默认开启,大家应该都知道是修改DefaultPermissionGrantPolicy.java。

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

在grantDefaultSystemHandlerPermissions中可以看到

  1. // Camera
  2. Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  3. PackageParser.Package cameraPackage = getDefaultSystemHandlerActivityPackageLPr(
  4. cameraIntent, userId);
  5. if (cameraPackage != null
  6. && doesPackageSupportRuntimePermissions(cameraPackage)) {
  7. grantRuntimePermissionsLPw(cameraPackage, CAMERA_PERMISSIONS, userId);
  8. grantRuntimePermissionsLPw(cameraPackage, MICROPHONE_PERMISSIONS, userId);
  9. grantRuntimePermissionsLPw(cameraPackage, STORAGE_PERMISSIONS, userId);
  10. }

从上面这段代码就可以看到Camera中默认打开了CAMERA_PERMISSIONS, MICROPHONE_PERMISSIONS, STORAGE_PERMISSIONS这三个Dangerous Permission。

2.第三方app

手动安装的第三方app的权限默认开启是修改PackageManagerService.java。

frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java

在grantPermissionsLPw函数中添加如下代码

  1. //Permissions for com.xxx.xxx
  2. if(pkg.packageName.contains("com.xxx.xxx")) {
  3. final int permsSize = pkg.requestedPermissions.size();
  4. for (int i=0; i<permsSize; i++) {
  5. final String name = pkg.requestedPermissions.get(i);
  6. final BasePermission bp = mSettings.mPermissions.get(name);
  7. if(null != bp && permissionsState.grantInstallPermission(bp) != PermissionsState.PERMISSION_OPERATION_FAILURE) {
  8. Slog.d(TAG, "zrx--- grant permission " + name + " to package " + pkg.packageName);
  9. changedInstallPermission = true;
  10. }
  11. }
  12. }

参考:

Android6.0 动态权限(Runtime Permission)_MyeDy的博客-CSDN博客_android runtime 权限

Android源码 第三方应用普通安装 app权限默认开启_fmc088的博客-CSDN博客

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号