Android attribute system usage

Source: Internet
Author: User


The following describes the specific application scenarios and methods:


Requirement: An application needs to operate mtd flash, which is a base-level interface operation. libmtd_flash.so is encapsulated for such interfaces,
If the application has no permission to access the device and the sdcard access is added to the multi-play verification, there are two solutions to this problem:
1. Create a service on the c ++ layer and use the binder as the Client Connection Bridge.
2. Use the property system that comes with android
Considering the use scenario, data volume, and complexity, the attribute system is used to share data.


1. First, we know:
Native code
When writing Native programs, you can use the property_get and property_set APIs to obtain and set properties. These two APIs must contain header files and link libcutil libraries.
Java code
Android provides the System. getProperty and System. setProperty methods in the Java library. Our Java program can use them to set and obtain properties.
Because we write code at the native layer, use property_get and property_set.

2. List the interface functions of the property system.


/* Property_get: returns the length of the value which will never be
** Greater than PROPERTY_VALUE_MAX-1 and will always be zero terminated.
** (The length does not include the terminating zero ).
**
** If the property read fails or returns an empty value, the default
** Value is used (if nonnull ).
*/
Int property_get (const char * key, char * value, const char * default_value );


/* Property_set: returns 0 on success, <0 on failure
*/
Int property_set (const char * key, const char * value );


OK. No initialization or other functions. You can use set or get directly, which is quite convenient.


3. Implementation and use
A. Directly compile an executable background process to run
B. read and set data in mtd flash, such as open/read/write/erase, and save the data to the memory.
You only need to get the property data to be directly searched from the memory.
C. For data rewriting operations such as write/erase in flash, synchronize data in the memory and attribute system.
D. access relevant data for upper-layer applications or other processes directly using property_get/property_set.

 

Advantage: A Background process serves all clients and maintains data consistency. The most important thing is to solve the permission problem, because the service process started by init has the root permission.

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.