当前位置:网站首页>NDK learning notes (VII) system configuration, users and groups

NDK learning notes (VII) system configuration, users and groups

2022-06-11 05:34:00 Come and go

1. The system configuration

Bionic Provides a set of functions that allow native applications to query Xu Tong's properties .

Need header file

#include <sys/system_properties.h>

Each system attribute complies with no more than PROP_NAME_MAX Attribute names with characters and no more than PROP_VALUE_MAX Attribute value of characters .

(1) Get the system attribute value by name

    char value[PROP_VALUE_MAX];
	// If the attribute is not defined , The return size is 0 Value 
    if (0 == __system_property_get("ro.product.model", value)) {
    

    } else {
    

        __android_log_print(ANDROID_LOG_INFO, "123321", "%s", value);
    }

effect
 Insert picture description here

(2) Get system properties by name

    const prop_info *p;
    // obtain ro.product.model System attribute 
    p = __system_property_find("ro.product.model");
    if (NULL == p) {
    

    } else {
    

        char name[PROP_NAME_MAX];
        char value[PROP_VALUE_MAX];
        // Get the system attribute name and value 
        if (0 == __system_property_read(p, name, value)) {
    

        } else {
    
            __android_log_print(ANDROID_LOG_INFO, "123321", "%s:%s", name, value);
        }
    }

effect
 Insert picture description here

2. Users and groups

Bionic Provide basic support for user and group information functions .
The required header file

 Insert a code chip here 

(1) Get the users and groups of the application ID

Users of normal applications ID And groups ID from 10000 At the beginning ;ID Small values are used for system services .

getuid()  user id
getgid()   Group id
__android_log_print(ANDROID_LOG_INFO, "123321", "%d:%d", getuid(), getgid());

effect

2020-04-05 16:48:25.825 13132-13132/com.example.testnt I/123321: 10069:10069

(2) Get the application user name

Installed applications get the user name assigned to the user .

    __android_log_print(ANDROID_LOG_INFO, "123321", "%s",getlogin());

effect

2020-04-05 16:52:42.705 13220-13220/com.example.testnt I/123321: u0_a69
原网站

版权声明
本文为[Come and go]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020538239630.html