Android debugging node permission issues through demo

Android debugging node permission issues through demo

Recently, I received customer feedback that nodes cannot be controlled at the application layer, so I wrote a simple demo to verify the IO permissions of the node. The specific debugging step is to write a button click event. When the button is clicked, write the node that needs to be verified as 1. (The node defaults to 1, so write it as 0). Finally, read the node status through the cat command to verify whether the application layer has the IO permission to control the node. The specific modifications are as follows:

The specific code for implementing the click event function is as follows:

            public void onClick(View v) {

                try {
                    String filePath = "theNodePath";
                    FileWriter writer = new FileWriter(filePath);
                    writer.write("1");
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }


            }

After clicking the button Button, I read the current node status through the cat command and found that the value of the node has not changed. After grabbing the log and analyzing it, I saw Permission denied. It was determined that it was due to a lack of permissions. For this reason, we need to manually grant node permissions. The specific modifications are as follows. :

/device/pj/init.project.rc

+    chmod 777 theNodePath
+    chown system system theNodePath

Recompile and verify, the modification takes effect. After clicking the button again, read the current node status through the cat command. At this time, the value of the node has changed.

Guess you like

Origin blog.csdn.net/Jeffries_C/article/details/134649737