android 默认勾选权限_Android 默认打开应用权限

问题描述

系统预装APK和后安装的APK,默认全部打开应用,不弹窗提醒!,不弹窗提醒!,不弹窗提醒!。

解决方法

1、系统预装应用

W:\Code\RK3399PRO_HDMI_ANDROID8\frameworks\base\services\core\java\com\android\server\pm\DefaultPermissionGrantPolicy.java文件内的

private void grantDefaultSystemHandlerPermissions(int userId)

方法中增加如下代码:

synchronized (mService.mPackages) {

//以下代码为增加的部分

PackageParser.Package EV_DesktopPckg = getPackageLPr( "com.example.desktop");

if (EV_DesktopPckg != null) {

grantRuntimePermissionsLPw(EV_DesktopPckg, MICROPHONE_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, STORAGE_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, CONTACTS_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, PHONE_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, CALENDAR_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, CAMERA_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, LOCATION_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, SENSORS_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, SMS_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_DesktopPckg, STORAGE_PERMISSIONS, true, userId);

}

PackageParser.Package EV_WebViewTestPckg = getPackageLPr( "com.example.webviewtest");

if (EV_WebViewTestPckg != null) {

grantRuntimePermissionsLPw(EV_WebViewTestPckg, MICROPHONE_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, STORAGE_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, CONTACTS_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, PHONE_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, CALENDAR_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, CAMERA_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, LOCATION_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, SENSORS_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, SMS_PERMISSIONS, true, userId);

grantRuntimePermissionsLPw(EV_WebViewTestPckg, STORAGE_PERMISSIONS, true, userId);

}

说明:如果有其它预装应用程序,以此类推

2、后安装的应用

在W:\Code\RK3399PRO_HDMI_ANDROID8\frameworks\base\services\core\java\com\android\server\pm\PackageManagerService.java的

private void handlePackagePostInstall(PackageInstalledInfo res, boolean grantPermissions,

boolean killApp, boolean virtualPreload, String[] grantedPermissions,

boolean launchedForRestore, String installerPackage,

IPackageInstallObserver2 installObserver)

其中部分代码修改如下即可

// 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(true

//if (grantPermissions

// ||

// res.name.equals("com.example.desktop") ||

// res.name.equals("com.example.webviewtest") ||

// res.name.equals("com.example.desktop")

) {

grantRequestedRuntimePermissions(res.pkg, res.newUsers, grantedPermissions);

}

源码中默认的为grantPermissions,可根据需求增加自己的应用,该修改为所有应用都打开权限

以上方法针对危险权限((Dangerous Permission)),但还有其他系统权限权限想要默认开启无法用此方法。

PACKAGE_USAGE_STATS权限

​该权限可使应用统计其他应用使用情况,想要默认开启

​先在AndroidMainfests.xml中增加

tools:ignore="ProtectedPermissions" />

​再使用ADB命令开启

pm grant com.example.hello android.permission.PACKAGE_USAGE_STATS

WRITE_SETTINGS权限

​该权限可用于修改系统设置,如修改系统亮度等。

​需要默认开启该权限,需使用系统签名

​先在AndroidMainfests.xml中增加

​和

android:sharedUserId="android.uid.system"

​再在该预装应用的Android.mk中增加如下

LOCAL_CERTIFICATE := platform

最后编译系统烧录固件即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值