What is the use of <permission-group> in android?

18,960

Solution 1

The tag permission-group is just used to group one or more permissions under a particular category. From the developer's site http://developer.android.com/guide/topics/manifest/permission-group-element.html

Declares a name for a logical grouping of related permissions. Individual 
permission join the group through the permissionGroup attribute of the
<permission> element. Members of a group are presented together in the 
user interface.

Note that this element does not declare a permission itself, only a category in 
which permissions can be placed. See the <permission> element for element for
information on declaring permissions and assigning them to groups.

For example, the messages related permissions, say android.permission.SEND_SMS, RECEIVE_SMS and all the permissions related to messages are grouped under android.permission-group.MESSAGES to have a common icon.

From AndroidManifest.xml of android source https://github.com/android/platform_frameworks_base/blob/master/core/res/AndroidManifest.xml

 <permission-group android:name="android.permission-group.MESSAGES"
    android:label="@string/permgrouplab_messages"
    android:icon="@drawable/perm_group_messages"
    android:description="@string/permgroupdesc_messages"
    android:permissionGroupFlags="personalInfo"
    android:priority="360"/>

  <!-- Allows an application to monitor incoming SMS messages, to record
     or perform processing on them. -->
<permission android:name="android.permission.RECEIVE_SMS"
    android:permissionGroup="android.permission-group.MESSAGES"
    android:protectionLevel="dangerous"
    android:label="@string/permlab_receiveSms"
    android:description="@string/permdesc_receiveSms" />

<!-- Allows an application to send SMS messages. -->
<permission android:name="android.permission.SEND_SMS"
    android:permissionGroup="android.permission-group.MESSAGES"
    android:protectionLevel="dangerous"
    android:permissionFlags="costsMoney"
    android:label="@string/permlab_sendSms"
    android:description="@string/permdesc_sendSms" />

Here, the android.permission-group.MESSAGES categorises these permissions under a common icon and name in permissions when your applications uses these permissions.

Give

<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

in a sample application to see the result. Those two permissions will be grouped into a common category.

Note the Receive and send sms categorised into a group

The costs money is because of the android:permissionFlags="costsMoney" in SEND_SMS permission. Hence permission-group is only used to categorise the permissions. It cannot be used as in to group one or more permissions.

Solution 2

The permission-group tag allows you to create a group of custom permissions.

Declares a name for a logical grouping of related permissions. Individual permission join the group through the permissionGroup attribute of the permission element.

It basically allows you to organize your permissions in an orderly fashion.

And permission-group defines a label for a set of permissions (both those declared in the manifest with permission elements and those declared elsewhere). It affects only how the permissions are grouped when presented to the user. The permission-group element does not specify which permissions belong to the group; it just gives the group a name.

<manifest . . . >

<permission-group android:description="string resource"
              android:icon="drawable resource"
              android:label="string resource"
              android:name="SomeGroup" />

<permission android:description="string resource"
        android:icon="drawable resource"
        android:label="string resource"
        android:name="SomePermission"
        android:permissionGroup="SomeGroup"
        android:protectionLevel=["normal" | "dangerous" | 
                                 "signature" | "signatureOrSystem"] />

    <uses-permission android:name="SomePermission" />
    . . .
    <application . . .>
        <activity android:name="com.some.activity"
                  android:permission="SomePermission"
                  . . . >
            . . .
        </activity>
    </application>
</manifest>
Share:
18,960

Related videos on Youtube

Shree
Author by

Shree

Updated on June 04, 2022

Comments

  • Shree
    Shree almost 2 years

    From android documentation, Its clear that Using "permission-group" we can create a permission group. Using "permission" element in android manifest file, we can define a permission. This permission can be added to permission-group.

    if we name this permission-group as "com.example.permission-group" can we use it in another application using "uses-permission". If we can use, whether can we access all the permissions of this group.

    If the above case is wrong, Then how can we make use of "permission-group"

  • Shree
    Shree almost 11 years
    Thanks for the info, Thats what i got it from android doc. But here we created the permission-group with some name, and it holds some permissions. My question is whether can we access This permission-group in any other application, so that application can access all the permissions of this permission group
  • David Freitag
    David Freitag almost 11 years
    You could try creating an Android Library that contains nothing but a manifest file containing the necessary <permission-group> and <permission> definitions. You might be able to access those definitions from your application through the library. How to create a library: developer.android.com/tools/projects/projects-eclipse.html