本文主要介绍授予第三方应用权限和自动获取USB权限
1.授予指定手动安装第三方应用权限
frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
// Now that we successfully installed the package, grant runtime
// permissions if requested before broadcasting the install. Also
// for legacy apps in permission review mode we clear the permission
// review flag which is used to emulate runtime permissions for
// legacy apps.
+ if (grantPermissions) {
+ if (grantPermissions || res.name.equals("package.name")) {
final int callingUid = Binder.getCallingUid();
mPermissionManager.grantRequestedRuntimePermissions(
res.pkg, res.newUsers, grantedPermissions, callingUid,
mPermissionCallback);
}
2. 默认授予所有第三方应用权限
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -1511,8 +1511,10 @@ public class PackageManagerService extends IPackageManager.Stub
InstallArgs args = data.args;
PackageInstalledInfo parentRes = data.res;
- final boolean grantPermissions = (args.installFlags
- & PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS) != 0;
+ //final boolean grantPermissions = (args.installFlags
+ //& PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS) != 0;
+ //Grant all permission to thirdParty app as default
+ final boolean grantPermissions = true;
3. 去掉USB权限弹窗
使用usb设备时会弹出弹窗提示申请权限,修改关闭弹窗提示,默认自动获取USB权限
(1)配置config_disableUsbPermissionDialogs属性,但会影响CTS测试
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2517,7 +2517,7 @@
<!-- If true, then we do not ask user for permission for apps to connect to USB devices.
Do not set this to true for production devices. Doing so will cause you to fail CTS. -->
- <bool name="config_disableUsbPermissionDialogs">false</bool>
+ <bool name="config_disableUsbPermissionDialogs">true</bool>
(2)在hasPermission默认return true
--- a/services/usb/java/com/android/server/usb/UsbPermissionManager.java
+++ b/services/usb/java/com/android/server/usb/UsbPermissionManager.java
@@ -133,7 +133,8 @@ class UsbPermissionManager {
*/
boolean hasPermission(@NonNull UsbDevice device, int uid) {
synchronized (mLock) {
- if (uid == Process.SYSTEM_UID || mDisablePermissionDialogs) {
+ //[Toast]add auto-granted USB permissions
+ if (uid == Process.SYSTEM_UID || mDisablePermissionDialogs || true) {
return true;
}
SparseBooleanArray uidList = mDevicePermissionMap.get(device.getDeviceName());
@@ -153,7 +154,8 @@ class UsbPermissionManager {
*/
boolean hasPermission(@NonNull UsbAccessory accessory, int uid) {
synchronized (mLock) {
- if (uid == Process.SYSTEM_UID || mDisablePermissionDialogs) {
+ //[Toast]add auto-granted USB permissions
+ if (uid == Process.SYSTEM_UID || mDisablePermissionDialogs || true) {
return true;
}
3.确认permission stauts
$ dumpsys package com.andorid.package_name
declared permissions:
android.permission.QUERY_ALL_PACKAGES: prot=normal, INSTALLED
requested permissions:
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.REORDER_TASKS
android.permission.WRITE_EXTERNAL_STORAGE: restricted=true
android.permission.WRITE_INTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE: restricted=true
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.READ_PHONE_STATE
android.permission.WAKE_LOCK
install permissions:
android.permission.CHANGE_WIFI_MULTICAST_STATE: granted=true
android.permission.INTERNET: granted=true
android.permission.REORDER_TASKS: granted=true
android.permission.ACCESS_NETWORK_STATE: granted=true
android.permission.ACCESS_WIFI_STATE: granted=true
android.permission.WAKE_LOCK: granted=true
User 0: ceDataInode=1551 installed=true hidden=false suspended=false stopped=false notLaunched=false enabled=0 instant=false virtual=false
gids=[3003]
runtime permissions:
android.permission.READ_EXTERNAL_STORAGE: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED|RESTRICTION_UPGRADE_EXEMPT]
android.permission.READ_PHONE_STATE: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED]
android.permission.WRITE_EXTERNAL_STORAGE: granted=false, flags=[ USER_SENSITIVE_WHEN_GRANTED|USER_SENSITIVE_WHEN_DENIED|RESTRICTION_UPGRADE_EXEMPT]