我是靠谱客的博主 刻苦板栗,最近开发中收集的这篇文章主要介绍android 代码中加权限,android framework中添加自定义权限,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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中验证!

最后

以上就是刻苦板栗为你收集整理的android 代码中加权限,android framework中添加自定义权限的全部内容,希望文章能够帮你解决android 代码中加权限,android framework中添加自定义权限所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部