AI智能
改变未来

给Android app添加default permission

这部分的修改主要是在Android源码的\\frameworks\\base\\services\\core\\java\\com\\android\\server\\pm\\DefaultPermissionGrantPolicy.java

首先给应用定义所需要的权限,例如:

private static final Set<String> XIAOGUIVOICE_PERMISSIONS = new ArraySet<>();static {XIAOGUIVOICE_PERMISSIONS.add(Manifest.permission.READ_PHONE_STATE);XIAOGUIVOICE_PERMISSIONS.add(Manifest.permission.RECORD_AUDIO);}

然后就是在private void grantDefaultSystemHandlerPermissions(int userId)加具体的权限,例如:

PackageParser.Package xiaoguivoicedemoPackage = getSystemPackageLPr(\"settings.halov.com.xiaoguivoicedemo\");if (printSpoolerPackage != null&& doesPackageSupportRuntimePermissions(xiaoguivoicedemoPackage)) {grantRuntimePermissionsLPw(xiaoguivoicedemoPackage, XIAOGUIVOICE_PERMISSIONS, true, userId);}

这两步就可以实现给某个应用加锁需要的权限了,很简单。

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 给Android app添加default permission