打印纸改善事例:android安全机制分析(2)

来源:百度文库 编辑:中财网 时间:2024/05/01 22:52:46
android安全机制分析(2)2011-03-27 21:55

Declaring and Enforcing Permissions

为了实现应用程序自己的权限,必须先在AndroidManifest.xml中使用一个或多个标签声明它们。
例如,一个应用程序要控制谁可以启动其Activity可以声明此操作的权限如下:

    package="com.me.app.myapp" >
            android:label="@string/permlab_deadlyActivity"
        android:description="@string/permdesc_deadlyActivity"
        android:permissionGroup="android.permission-group.COST_MONEY"
        android:protectionLevel="dangerous" />
    ...

属性是必需的描述在这个标签中,它告诉系统怎样通知用户当其它应用程序需要该权限或者谁可以持有该权限。

属性是可选的,用于帮助系统展示的权限给用户。您通常会希望将它设置为一个标准的系统组(在android.Manifest.permission_group中)或由自己定义了一个较罕见的案例。这是首选使用现有的组,用于简化权限UI展示给用户。

注意,这两个标签和说明应用于的说明权限。用户在查看的权限列表(android:label)或单个权限( android:description)的细节时,这些内容被展现。标签应该简洁的介绍权限保护的关键功能。用几个简单的句子描述拥有该权限可以做什么。我们的惯例是用两个句子,第一句描述权限,第二句警告用户当授权该权限后会发生什么。

这里是一个CALL_PHONE权限的标签和描述的的例子:

    directly callphone numbers
    Allows theapplication to call
        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应用。所有这需要的是一个机器人,包括:对所需的组件权限属性,命名将使用它来控制存取权限。
活动权限(适用于标签)限制谁可以启动相关的活动。检查duringContext.startActivity的权限()和Activity.startActivityForResult();如果调用方没有所要求的权限thenSecurityException是从调用抛出。
服务权限(适用于标记)限制谁可以启动或绑定到相关的服务。检查过程中的权限Context.startService(),Context.stopService()和Context.bindService();如果调用方没有所要求的权限,然后SecurityException的是从调用抛出。