Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Create new System Permission in through AOSP source code.

Tags:

I was wondering how one can edit Android OS source code to impose a new permission. For example like we have BLUETOOTH permission, if the device offers a new sensor, then how appropriate permission can be created in order for applications to use the new sensor, at application level using manifest entry for the new permission available in android rom.

Does anybody know how new Permissions are created on the OS level in AOSP source code??

And i think if we have modified the android source to add the new permission we must compile the our custom SDK for using permission in application development, otherwise the existing SDK will give compile time error, as it wont recognize our custom permission...

Any ideas, thoughts highly appreciated.

like image 370
user2074216 Avatar asked Feb 15 '13 03:02

user2074216


People also ask

How do I set custom permissions on Android?

You can use the sharedUserId attribute in the AndroidManifest. xml 's manifest tag of each package to have them assigned the same user ID. By doing this, for purposes of security the two packages are then treated as being the same app, with the same user ID and file permissions.

How do I set custom permissions in Android dialog?

requestPermissions(thisActivity, new String[]{Manifest. permission. READ_CONTACTS}, MY_PERMISSIONS_REQUEST_READ_CONTACTS); Android system creates a popup dialog to request permission.

How do I request runtime permission on Android?

checkSelfPermission(String perm); It returns an integer value of PERMISSION_GRANTED or PERMISSION_DENIED. Note: If a user declines a permission that is critical in the app, then shouldShowRequestPermissionRationale(String permission); is used to describe the user the need for the permission.

What permissions do Android apps require?

Android apps must request permission to access sensitive user data (such as contacts and SMS), as well as certain system features (such as camera and internet). Depending on the feature, the system might grant the permission automatically or might prompt the user to approve the request.

What is the purpose of permission?

The purpose of a permission is to protect the privacy of an Android user. Android apps must request permission to access sensitive user data (such as contacts and SMS), as well as certain system features (such as camera and internet). Depending on the feature, the system might grant the permission automatically or might prompt ...

How to restrict who can start or bind to an Android service?

Permissions applied using the android:permission attribute to the <service> tag in the manifest restrict who can start or bind to the associated Service. The permission is checked during Context.startService(), Context.stopService() and Context.bindService().

What is system permission prompt?

The system permission prompt that appears when your app requests a runtime permission. Runtime permissions, also known as dangerous permissions, give your app additional access to restricted data, and they allow your app to perform restricted actions that more substantially affect the system and other apps.


1 Answers

In framework/base/data/etc/platform.xml

You can define your newly created permission with a corresponding gid.

<permissions>

    <!-- ================================================================== -->
    <!-- ================================================================== -->
    <!-- ================================================================== -->

    <!-- The following tags are associating low-level group IDs with
         permission names.  By specifying such a mapping, you are saying
         that any application process granted the given permission will
         also be running with the given group ID attached to its process,
         so it can perform any filesystem (read, write, execute) operations
         allowed for that group. -->

    <permission name="android.permission.BLUETOOTH_ADMIN" >
        <group gid="net_bt_admin" />
    </permission>

    <permission name="android.permission.BLUETOOTH" >
        <group gid="net_bt" />
    </permission>

    <permission name="android.permission.BLUETOOTH_STACK" >
        <group gid="net_bt_stack" />
    </permission>

    <permission name="android.permission.NET_TUNNELING" >
        <group gid="vpn" />
    </permission>

    <permission name="android.permission.INTERNET" >
        <group gid="inet" />
    </permission>

    <permission name="android.permission.CAMERA" >
        <group gid="camera" />
    </permission>

    <permission name="android.permission.READ_LOGS" >
        <group gid="log" />
    </permission>

    ...
</permission>

Other permission definitions is not in the above file, because there are actually two kinds of permission in Android as shown in the following figure. Only permissions that enforced by Linux Kernel are defined in that file.

Permission Enforcement in Android

Other permissions like ACCESS_FINE_LOCATION, READ_CONTACTS, etc are defines in the AndroidManifest.xml in system applications(packages/.../AndroidManifest.xml) and framework(frameworks/base/core/res/AndroidManifest.xml).

After you adding your permission and related code, compile and build the project according to Building Instruction

like image 61
StarPinkER Avatar answered Oct 29 '22 20:10

StarPinkER