改善心得:[转]android安全机制分析(2)
来源:百度文库 编辑:中财网 时间:2024/05/04 20:05:18
Declaring and Enforcing Permissions
为了实现应用程序自己的权限,必须先在AndroidManifest.xml中使用一个或多个
例如,一个应用程序要控制谁可以启动其Activity可以声明此操作的权限如下:
android:description="@string/permdesc_deadlyActivity"
android:permissionGroup="android.permission-group.COST_MONEY"
android:protectionLevel="dangerous" />
...
注意,这两个标签和说明应用于的说明权限。用户在查看的权限列表(android:label)或单个权限( android:description)的细节时,这些内容被展现。标签应该简洁的介绍权限保护的关键功能。用几个简单的句子描述拥有该权限可以做什么。我们的惯例是用两个句子,第一句描述权限,第二句警告用户当授权该权限后会发生什么。
这里是一个CALL_PHONE权限的标签和描述的的例子:
phone numbers without your intervention. Maliciousapplications may
cause unexpected calls on your phone bill. Notethat this does not
allow the application to call emergency numbers.
可以通过shell命令 adb shell pm list permissions来查看现在系统上的权限定义。特别地,-s选项可以用简单的表格形式来给用户呈现权限。
$ adb shell pm list permissions -s
All Permissions:
Network communication: view Wi-Fi state, create Bluetooth connections, full
Internet access, view network state
Your location: access extra location provider commands, fine (GPS) location,
mock location sources for testing, coarse (network-based) location
Services that cost you money: send SMS messages, directly callphone numbers
...
Enforcing Permissions in AndroidManifest.xml
限制对整个系统组件或应用程序访问的高级别的权限在中AndroidManifest.xml应用。
高级别权限限制访问的系统或应用程序的全部组件都可以通过yourAndroidManifest.xml应用。所有这需要的是一个机器人,包括:对所需的组件权限属性,命名将使用它来控制存取权限。
活动权限(适用于
服务权限(适用于