SoFunction
Updated on 2025-03-11

How to modify device permissions in Android

This article describes the method of modifying device permissions in Android. Share it for your reference. The details are as follows:

Sometimes after we write the driver, we need to access the device in the upper layer program, but the device permissions after the android code are compiled are root, and other users cannot access (including system), so we just need to modify the device's permissions in the android source code.

The specific modification location is the definition of static struct perms_devperms[] in the system/core/init/ file of the source code. If you add the permissions of the device hidraw0, just add one line:

Copy the codeThe code is as follows:
{ "/dev/hidraw0", 0666, AID_ROOT, AID_ROOT, 0 }

In this way, after Android is started, the program will have access permissions.

Can also be changed to

Copy the codeThe code is as follows:
{ "/dev/hidraw0", 0600, AID_SYSTEM, AID_ROOT, 0 }

This requires a system to access. To obtain system permissions, please refer to "How to obtain system permissions by APK program

I hope this article will be helpful to everyone's Android programming design.