Set and obtain global system attributes for Android framework development

Source: Internet
Author: User

Android command line/C Language/java settings to obtain system attributes

Set and obtain the SystemProperty attribute in Java:

SystemProperties.getInt("persist.sys.boot_music_control", 0)SystemProperties.set("persist.sys.boot_music_control", ""+value);



In C ++, obtain the attribute values set in the Java layer:

           char boot_music_control[PROPERTY_VALUE_MAX];            if (property_get("persist.sys.boot_music_control", boot_music_control, 0) != 0) {                mediastatus = mediaplayer->setDataSource(pBackupSoundFileName, NULL);            }



1. Interface for setting and obtaining shell properties
2 interfaces for setting and obtaining properties in c/c ++
3 interfaces for setting and obtaining Java properties


Android provides a set of methods for setting and obtaining system parameters. These parameters can be set and obtained statically or dynamically in the android system, use the SystemProperty class (this class is only used in framework or system-level applications). There are a lot of SystemProperties in the code. set ()/SystemProperties. get (); these two interfaces can be used to read/set system attributes. As the name suggests, system attributes must be globally shared to the entire system. Generally, the execution of programs is independent of each other by process. How can we achieve global sharing?

How does System Properties (SystemProperty details and principles) be implemented?

Attribute system is an important feature of android. It runs as a service and manages system configurations and statuses. All these configurations and statuses are attributes.

Each attribute is a key-value pair, and its type is a string.

These attributes may be the usage status of some resources, the execution status of processes, and the special attributes of the system ......
Command Line (shell) properties setting and obtaining Interfaces

Getprop "key"

Setprop "key" "value"

Interfaces for setting and obtaining properties in c/c ++

The code is defined in:


system/core/libcutils/properties.c #define PROPERTY_KEY_MAX   32#define PROPERTY_VALUE_MAX  92 int property_get(const char *key, char*value, const char *default_value);int property_set(const char *key, constchar *value);int property_list(void (*propfn)(const char *key, constchar *value, void*cookie), void *cookie);   

Usage:

#include "cutils/properties.h" char prop[PROPERTY_VALUE_MAX] = "000";if(property_get("prop_name", prop, NULL) != 0) {    ...}

Note:

The returned value of property_get is the string length of the get-to-get attribute value.
Prop_name is the property name.
Prop is the place where the property value string is stored.

Interfaces for setting and obtaining Java properties

Frameworks/base/core/java/android/OS/SystemProperties. java


public static final int PROP_NAME_MAX = 31;public static final int PROP_VALUE_MAX = 91;public static String get(String key) ;public static String get(String key, String def) ;public static int getInt(String key,int def) ;public static long getLong(String key,long def) ;public static boolean getBoolean(String key, boolean def) ;public static void set(String key, String val) ;public static void addChangeCallback(Runnable callback) ;



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.