"Android" uses the Persist property to invoke the script file

Source: Internet
Author: User

There are many properties in the Android system, and the properties are made up of two parts: name & Value, which can be used to record the exchange of information between system settings or processes. The Android system loads the system properties from the following files sequentially during the boot process:

1./default.prop

2./system/build.prop

3./system/default.prop

4./data/local.prop

  5./data/property/*

Properties are loaded in the order of the files above, and the property values that are loaded later update the original property values. After the system restarts, some properties disappear, but can be defined with "persist." As the starting property value, a copy is saved in the/data/property/directory when the property is set by the SetProp command in the system. This way, after the system restarts, the values of these persist properties will not disappear following the loading process.

If you want to add a new persist attribute to the system, the prefix must be defined in the property_perms[] matrix in the property_service.c file to satisfy the added property.

Property_perms[] = {    { "Net.dns", Aid_radio,0 },    { "net.", Aid_system,0 },    { "Dev.", Aid_system,0 },    { "Runtime.", Aid_system,0 },    { "sys.", Aid_system,0 },    { "service.", Aid_system,0 },    { "Persist.sys.", Aid_system,0 },    { "Persist.service.", Aid_system,0}, ... {NULL,0,0 }};

  Of course we can also add the persist property prefixes we need, such as "Persist.test." prefix, simply add {"persist.test.", Aid_system, 0} to the property_perms[] matrix.

  Using the Persist property to invoke a script file can be done in 3 steps: Add a script file, add a Persist property, and add a service in init.<device>.rc.

  Step1. Adding a script file

Put the script file "fortest.sh" in the source/system/core/rootdir/etc/directory, and of course it can be placed in another location. Then add the Product_copy_files command to the Device.mk file in the Source/device/vendor/device/ Directory

Product_copy_files +     =/system/core/rootdir/etc/fortest.sh:/system/etc/fortest.sh

The script file "fortest.sh" added in the source code can eventually be generated to the/system/etc/directory of the system via the Product_copy_files command. If you want to run the script file through the Persist property, it is not enough to add the script file to the system, because now the/system/etc/fortest.sh script does not have permission to execute .

In order to add user mode & file permissions to the script file, I have tried to add the in Boot section of the source init.<device>.rc

Chown /system/etc/ fortest.sh  /system/etc/fortest.sh

  However, after debugging, it is shown after Ls/system/etc/fortest.sh-al:-rw-r--r--root root/system/etc/ Fortest.sh, did not complete the expected target Ah, have tried to put the code in other sections, but has not been successful.

Finally, by implementing the UID & GID & Operation Permissions of the add file in Android_filesystem_config.h. Added in the android_files[] matrix in Android_filesystem_config.h

{00777, Aid_system,      Aid_shell,      "system/etc/fortest.sh"}

  

  Step2. Adding Persist properties

As can be known from the previous article, adding a custom persist property can use a prefix that already exists in the Android source code, but you can also use your own defined prefix. You only need to add a custom persist.test in the property_perms[] matrix in the propery_service.c file . Prefix.

This function can also be done previously with "SetProp Persist.test.test 0" in the init.<device>.rc file, but the init process will load Init.rc & init.< Each time the system restarts device>.rc files, so it is unavoidable to run the "setprop persist.test.test 0" command once. This causes Persist.test.test to revert to its original value every time after the system restarts. This is somewhat contradictory to what the persist property wants to achieve.

Add the custom Persist.test.test property to the source/device/vendor/device/boardconfig.mk file and set its default value to 1 or 0.

Persist.test.test   0

This allows the Persist.test.test property to be generated in the Default.prop in the system with an initial value of 0. In addition to the Add method, you can add custom properties to the source/device/manufacturer/device/system.prop.

  Step3. Adding a service in init.<device>.rc

  The introduction of init.rc can be referred to source/system/core/readme.txt. Init consists of 4 parts: Actions, Services, Commands & Options.

"Actions"

Actions are actually a set of named sequences of commands. Actions have a trigger condition that determines when the action is executed. When an event occurs that matches the trigger condition of the action, the action is added to the end of the pre-execution queue (unless it is already in the queue)

The commands in each action are executed sequentially. The INIT process is responsible for executing these sequence of commands between other activities (such as device creation/destruction, property settings, Process restarts).

"Services"

Services are programs that are started by Init and restarted (if necessary), of course, if these programs are present.

"Options"

The options is a service modifier that tells Init how and when to start the service.

Add a new service after the boot section in Init.<device>.rc, named New, with the corresponding script file location of/system/etc/fortest.sh, user & Group is set to root, auto-start is set to disable, and the service is started only once.

The Options command enables the service "new" to be turned on when the Persist.test.test attribute is changed.

new /system/etc/fortest.sh    user root    Group root    Disable    Oneshoton property: Pesist.test.test=1    newonproperty:persist.test.test=0      New

  Summary: This article mainly describes the process of adding persist properties, script files, and services, when the Persist property value changes, the service is turned on, and the script file is eventually called.

PS: I would like to have the help of the great God who has successfully added file permissions through the chmod command in the init.rc file. Thank you!

Reference article: http://www.cnblogs.com/leaven/archive/2010/12/25/1917007.html

Http://blog.sina.com.cn/s/blog_6b936f150101jhfl.html

"Android" uses the Persist property to invoke the script file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.