1、给预置APP设置默认权限
framework/base/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java
270 public void grantDefaultPermissions(int userId) { 271 grantPermissionsToSysComponentsAndPrivApps(userId); 272 grantDefaultSystemHandlerPermissions(userId); 273 grantDefaultPermissionExceptions(userId); 274 }grantPermissionsToSysComponentsAndPrivApps 给系统组件及priv app默认全部权限
grantDefaultSystemHandlerPermissions 给默认启动应用权限,例如系统默认Camera Media 等
grantDefaultPermissionExceptions 根据 system/etc/default-permissions.xml 配置给设置默认权限
2、安装应用时设置权限
frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
void doHandleMessage(Message msg) { case POST_INSTALL: { if (DEBUG_INSTALL) Log.v(TAG, "Handling post-install for " + msg.arg1); PostInstallData data = mRunningInstalls.get(msg.arg1); final boolean didRestore = (msg.arg2 != 0); mRunningInstalls.delete(msg.arg1); if (data != null) { InstallArgs args = data.args; PackageInstalledInfo parentRes = data.res; //final boolean grantPermissions = (args.installFlags // & PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS) != 0; // 默认设置权限为true final boolean grantPermissions = true; final boolean killApp = (args.installFlags & PackageManager.INSTALL_DONT_KILL_APP) == 0; final boolean virtualPreload = ((args.installFlags & PackageManager.INSTALL_VIRTUAL_PRELOAD) != 0); ... ... } break; }final boolean grantPermissions = true; 设置grant权限为true,默认就是开放所有权限
3、默认无用户确认权限弹框
packages/apps/PackageInstaller/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java
private boolean showNextPermissionGroupGrantRequest() { final int groupCount = mRequestGrantPermissionGroups.size(); int currentIndex = 0; for (GroupState groupState : mRequestGrantPermissionGroups.values()) { if (groupState.mState == GroupState.STATE_UNKNOWN) { // 注释掉用户确认弹框 /*CharSequence appLabel = mAppPermissions.getAppLabel(); CharSequence desc = null; if (AppPermissionGroup.isStrictOpEnable()) { String info = ""; AppPermissionGroup group = mAppPermissions.getPermissionGroup(groupState .mGroup.getName()); ... ... if (AppPermissionGroup.isStrictOpEnable()) { mViewHandler.updateUi(groupState.mGroup.getName(), groupCount, currentIndex, Icon.createWithResource(resources, icon), message, true); } else { mViewHandler.updateUi(groupState.mGroup.getName(), groupCount, currentIndex, Icon.createWithResource(resources, icon), message, groupState.mGroup.isUserSet()); }*/ // 默认直接设置权限为true onPermissionGrantResult(groupState.mGroup.getName(), true, true); return true; } currentIndex++; } return false; }