Android permission之android:protectionLevel

参考资料:

http://yelinsen.iteye.com/blog/983509

http://www.xuebuyuan.com/1873075.html

Android对这些权限进行了四类分级,不同级别的权限对应不同的认证方式。

    
normal
:低风险权限,只要申请了就可以使用(在AndroidManifest.xml中添加<uses-permission>标                            签),安 装时不需要用户确认;


dangerous:高风险权限,安装时需要用户的确认才可使用;


signature: 只有当申请权限的应用程序的数字签名与声明此权限的应用程序的数字签名相同时(如果是申请系                          统权限,则需要与系统签名相同),才能将权限授给它;


signatureOrSystem:签名相同,或者申请权限的应用为系统应用(在system image中)。

上述四类权限级别同样可用于自定义权限中。如果开发者需要对自己的应用程序(或部分应用)进行访问控制,则可以通过在AndroidManifest.xml中添加<permission>标签,将其属性中的protectionLevel设置为上述四类级别中的某一种来实现。

通常情况下,对于需要付费的操作以及可能涉及到用户隐私的操作,我们都会格外敏感。

出于上述考虑以及更多的安全考虑,Android中对一些访问进行了限制,如网络访问(需付费)以及获取联系人(涉及隐私)等。应用程序如果想要进行此类访问,则需要申请相应权限。Android对这些权限进行了四类分级,不同级别的权限对应不同的认证方式。

"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  访问失败!

Java代码   收藏代码
  1. 04-01 11:03:31.453: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{43f38bb0 com.test.testpermission/.TestPermission}  
  2. 04-01 11:03:55.285: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.test.testpermission/.TestPermission }  
  3. 04-01 11:03:55.365: INFO/ActivityManager(58): Start proc com.test.testpermission for activity com.test.testpermission/.TestPermission: pid=1273 uid=10037 gids={1015}  
  4. 04-01 11:03:55.876: WARN/Resources(1273): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f050000}  
  5. 04-01 11:03:56.026: INFO/ActivityManager(58): Displayed activity com.test.testpermission/.TestPermission: 672 ms (total 672 ms)  
  6. 04-01 11:03:57.305: INFO/ActivityManager(58): Starting activity: Intent { cmp=com.test.testcustompermission/.TestCustomPermission }  
  7. 04-01 11:03:57.305: WARN/ActivityManager(58): Permission Denial: starting Intent { cmp=com.test.testcustompermission/.TestCustomPermission } from ProcessRecord{43f9de88 1273:com.test.testpermission/10037} (pid=1273, uid=10037) requires com.test.TESTCUSTOMPERMISSION  
  8. 04-01 11:03:57.305: DEBUG/AndroidRuntime(1273): Shutting down VM  
  9. 04-01 11:03:57.315: WARN/dalvikvm(1273): threadid=1: thread exiting with uncaught exception (group=0x4001d800)  
  10. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273): FATAL EXCEPTION: main  
  11. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.test.testcustompermission/.TestCustomPermission } from ProcessRecord{43f9de88 1273:com.test.testpermission/10037} (pid=1273, uid=10037) requires com.test.TESTCUSTOMPERMISSION  
  12. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.os.Parcel.readException(Parcel.java:1247)  
  13. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.os.Parcel.readException(Parcel.java:1235)  
  14. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)  
  15. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)  
  16. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.app.Activity.startActivityForResult(Activity.java:2817)  
  17. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.app.Activity.startActivity(Activity.java:2923)  
  18. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at com.test.testpermission.TestPermission.onClick(TestPermission.java:27)  
  19. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.view.View.performClick(View.java:2408)  
  20. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.view.View$PerformClick.run(View.java:8816)  
  21. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.os.Handler.handleCallback(Handler.java:587)  
  22. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.os.Handler.dispatchMessage(Handler.java:92)  
  23. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.os.Looper.loop(Looper.java:123)  
  24. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at android.app.ActivityThread.main(ActivityThread.java:4627)  
  25. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at java.lang.reflect.Method.invokeNative(Native Method)  
  26. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at java.lang.reflect.Method.invoke(Method.java:521)  
  27. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)  
  28. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)  
  29. 04-01 11:03:57.325: ERROR/AndroidRuntime(1273):     at dalvik.system.NativeStart.main(Native Method)  
  30. 04-01 11:03:57.335: WARN/ActivityManager(58):   Force finishing activity com.test.testpermission/.TestPermission  
  31. 04-01 11:03:57.836: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{43fa0440 com.test.testpermission/.TestPermission}  
  32. 04-01 11:03:58.856: INFO/Process(1273): Sending signal. PID: 1273 SIG: 9  
  33. 04-01 11:03:58.876: INFO/ActivityManager(58): Process com.test.testpermission (pid 1273) has died.  
  34. 04-01 11:03:58.876: INFO/WindowManager(58): WIN DEATH: Window{4405d010 com.test.testpermission/com.test.testpermission.TestPermission paused=false}  
  35. 04-01 11:03:58.916: WARN/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 1273 uid 10037  
  36. 04-01 11:04:08.169: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{43fa0440 com.test.testpermission/.TestPermission}  


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



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


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



最后一个实验
在TestCustomPermission中注册 signatureOrSystem!APP层访问 在framework API中验证!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值