Android 6.0后 apk权限默认开启

Android6.0之后推出动态申请权限,所有敏感权限默认都是没有开启的状态,需要动态添加权限的。但是项目中有些三方预置的apk需要默认将权限开启。

权限组 权限
PHONE READ_PHONE_STATE
PHONE CALL_PHONE
PHONE READ_CALL_LOG
PHONE WRITE_CALL_LOG
PHONE ADD_VOICEMAIL
PHONE USE_SIP
PHONE PROCESS_OUTGOING_CALLS
CONTACTS READ_CONTACTS
CONTACTS WRITE_CONTACTS
CONTACTS GET_ACCOUNTS
LOCATION ACCESS_FINE_LOCATION
LOCATION ACCESS_COARSE_LOCATION
LOCATION ACCESS_BACKGROUND_LOCATION
CALENDAR READ_CALENDAR
CALENDAR WRITE_CALENDAR
SMS SEND_SMS
SMS RECEIVE_SMS
SMS READ_SMS
SMS RECEIVE_WAP_PUSH
SMS RECEIVE_MMS
SMS READ_CELL_BROADCASTS
MICROPHONE RECORD_AUDIO
CAMERA CAMERA
STORAGE READ_EXTERNAL_STORAGE
STORAGE WRITE_EXTERNAL_STORAGE
STORAGE ACCESS_MEDIA_LOCATION

1、预置应用默认权限管理类

DefaultPermissionGrantPolicy.java是对预置应用默认权限管理类

/frameworks/base/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
private void grantDefaultSystemHandlerPermissions(int userId) {
	Set TEST_PERMISSIONS = new ArraySet<>();
	TEST_PERMISSIONS.add(Manifest.permission.RECEIVE_SMS);
	TEST_PERMISSIONS.add(Manifest.permission.READ_PHONE_STATE);
	TEST_PERMISSIONS.add(Manifest.permission.PROCESS_OUTGOING_CALLS);
	grantPermissionsToSystemPackage("包名", userId,  TEST_PERMISSIONS);
}

2、手动安装应用默认权限管理类

PermissionManagerService是对手动安装的应用默认权限处理类

/frameworks/base/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
private void restorePermissionState(@NonNull PackageParser.Package pkg, boolean replace,
	    @Nullable String packageOfInterest, @Nullable PermissionCallback callback) {
	// IMPORTANT: There are two types of permissions: install and runtime.
	// Install time permissions are granted when the app is installed to
	// all device users and users added in the future. Runtime permissions
	// are granted at runtime explicitly to specific users. Normal and signature
	// protected permissions are install time permissions. Dangerous permissions
	// are install permissions if the app's target SDK is Lollipop MR1 or older,
	// otherwise they are runtime permissions. This function does not manage
	// runtime permissions except for the case an app targeting Lollipop MR1
	// being upgraded to target a newer SDK, in which case dangerous permissions
	// are transformed from install time to runtime ones.
	if(pkg.packageName.contains("包名")) {
		final int permsSize = pkg.requestedPermissions.size();
		for (int i=0; i

以上两种方式都对CTS/GTS有影响,需要apk自身向google申请白名单

你可能感兴趣的:(Android)