android framework中添加自定义的permission

2014-12-19 15:27:32|分类:Android|举报|字号订阅

下载LOFTER客户端 在android的framework源码中添加自定义的permission以便限制应用程序调用自定义的系统接口, 在frameworks/base/core/res/AndroidManifest.xml 中添加:
<permission android:name="android.permission.ENTERPRISE_SETTINGS" android:label="@string/permlab_invoke_ivt_method" android:description="@string/permdesc_invoke_ivt_method" android:protectionLevel="dangerous" />
在frameworks/base/core/res/values/string.xml中添加 permlab_invoke_ivt_method 、permdesc_invoke_ivt_method的字符串资源
在被调用的接口处添加权限检验 public String getDeviceInfo() throws RemoteException { 。。。。。。 mContext.enforceCallingOrSelfPermission("android.permission.ENTERPRISE_SETTINGS", null); 。。。。。。 }
在调用该接口的应用程序的AndroidManifest.xml中需要添加该权限才可以正常调用该接口: <uses-permission android:name="android.permission.ENTERPRISE_SETTINGS"/>
其中的权限保护级别如下: protectionLevel分为四级: "normal" The default value. A lower-risk permission that gives requesting applications access to isolated application-level features, with minimal risk to other applications, the system, or the user. The system automatically grants this type of permission to a requesting application at installation, without asking for the user's explicit approval (though the user always has the option to review these permissions before installing).
"dangerous" A higher-risk permission that would give a requesting application access to private user data or control over the device that can negatively impact the user. Because this type of permission introduces potential risk, the system may not automatically grant it to the requesting application. For example, any dangerous permissions requested by an application may be displayed to the user and require confirmation before proceeding, or some other approach may be taken to avoid the user automatically allowing the use of such facilities.
"signature" A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.
"signatureOrSystem" A permission that the system grants only to applications that are in the Android system image or that are signed with the same certificates as those in the system image. Please avoid using this option, as the signature protection level should be sufficient for most needs and works regardless of exactly where applications are installed. The "signatureOrSystem" permission is used for certain special situations where multiple vendors have applications built into a system image and need to share specific features explicitly because they are being built together.
前面几个很好理解 现在重点记忆下最后一个signatureOrSystem 顾名思义就是在拥有权限的同时还必须满足signature一致或System级别APK才拥有! 现在做了如下尝试
Test Result: TestCustomPermission是我自定义了一个Activity的访问权限的APK TestPermission 去访问TestCustomPermission的Activity

EclipseSignature 中两个都用eclipse的签名 OtherSignature 中两个都用相同的另一种签名 DifferentSignature 中两个签名不想同 以下是测试结果:
APP级别 权限设置为signatureOrSystem 1. EclipseSignature 成功访问 ! 可以加入权限! 2. OtherSignature 成功访问 ! 可以加入权限! 3. DifferentSignature 访问失败!

权限设置为normal 1. DifferentSignature 成功访问 ! 可以加入权限!


System 级别 权限设置为signatureOrSystem 1. EclipseSignature 成功访问 ! 可以加入权限! 2. OtherSignature 成功访问 ! 可以加入权限! 3. DifferentSignature 成功访问 ! 可以加入权限!

TestCustomPermission再 system TestPermission 在APP 1.DifferentSignature 失败 2.签名相同成功!

最后一个实验 在TestCustomPermission中注册 signatureOrSystem!APP层访问 在framework API中验证!

更多相关文章

  1. android 权限大全
  2. Android应用程序获取ROOT权限的方法
  3. [Android基础]四大组件之ContentProvider
  4. Android默认给予USB读写权限,去掉授权对话框
  5. android 获取连接WiFi的名称SSID
  6. Android(安卓)3.0 访问WebService 出现 android.os.NetworkOnMai
  7. android 基于百度地图api获取经纬度
  8. android客户端程序访问服务器端webservice,几篇不错的文章!
  9. Android--permission大全

随机推荐

  1. Android(安卓)设置Dialog不允许返回或搜
  2. android 蓝牙隐藏对话框 后台配对
  3. Android实现定时执行某个任务
  4. android HAL层代码
  5. Android(安卓)微信分享icon黑边代码解决
  6. Android(安卓)提交数据到服务器的四种方
  7. 64Ubuntu报错Failed to get the adb vers
  8. 每次吃一点AndroidのAS问题大集合
  9. Android常用英文词汇(仅限自己收藏)
  10. 【Android】常用的adb命令