1 #include <stdbool.h>
2 #include <stdint.h>
3 #include <stdlib.h>
4 #include <stddef.h>
5 #include <string.h>
6
7 #include <sys/system_properties.h>
8
9 #include <linux/api.h>
10 #include <arm/android/api.h>
11 #include <arm/linux/api.h>
12 #include <cpuinfo/log.h>
13
14 #if CPUINFO_MOCK
15 #include <cpuinfo-mock.h>
16
17 static struct cpuinfo_mock_property* cpuinfo_mock_properties = NULL;
18
cpuinfo_mock_android_properties(struct cpuinfo_mock_property * properties)19 void CPUINFO_ABI cpuinfo_mock_android_properties(struct cpuinfo_mock_property* properties) {
20 cpuinfo_log_info("Android properties mocking enabled");
21 cpuinfo_mock_properties = properties;
22 }
23
cpuinfo_android_property_get(const char * key,char * value)24 static int cpuinfo_android_property_get(const char* key, char* value) {
25 if (cpuinfo_mock_properties != NULL) {
26 for (const struct cpuinfo_mock_property* prop = cpuinfo_mock_properties; prop->key != NULL; prop++) {
27 if (strncmp(key, prop->key, CPUINFO_BUILD_PROP_NAME_MAX) == 0) {
28 strncpy(value, prop->value, CPUINFO_BUILD_PROP_VALUE_MAX);
29 return (int) strnlen(prop->value, CPUINFO_BUILD_PROP_VALUE_MAX);
30 }
31 }
32 }
33 *value = '\0';
34 return 0;
35 }
36 #else
cpuinfo_android_property_get(const char * key,char * value)37 static inline int cpuinfo_android_property_get(const char* key, char* value) {
38 return __system_property_get(key, value);
39 }
40 #endif
41
cpuinfo_arm_android_parse_properties(struct cpuinfo_android_properties properties[restrict static1])42 void cpuinfo_arm_android_parse_properties(struct cpuinfo_android_properties properties[restrict static 1]) {
43 const int ro_product_board_length =
44 cpuinfo_android_property_get("ro.product.board", properties->ro_product_board);
45 cpuinfo_log_debug("read ro.product.board = \"%.*s\"", ro_product_board_length, properties->ro_product_board);
46
47 const int ro_board_platform_length =
48 cpuinfo_android_property_get("ro.board.platform", properties->ro_board_platform);
49 cpuinfo_log_debug("read ro.board.platform = \"%.*s\"", ro_board_platform_length, properties->ro_board_platform);
50
51 const int ro_mediatek_platform_length =
52 cpuinfo_android_property_get("ro.mediatek.platform", properties->ro_mediatek_platform);
53 cpuinfo_log_debug("read ro.mediatek.platform = \"%.*s\"",
54 ro_mediatek_platform_length, properties->ro_mediatek_platform);
55
56 const int ro_arch_length =
57 cpuinfo_android_property_get("ro.arch", properties->ro_arch);
58 cpuinfo_log_debug("read ro.arch = \"%.*s\"", ro_arch_length, properties->ro_arch);
59
60 const int ro_chipname_length =
61 cpuinfo_android_property_get("ro.chipname", properties->ro_chipname);
62 cpuinfo_log_debug("read ro.chipname = \"%.*s\"", ro_chipname_length, properties->ro_chipname);
63
64 const int ro_hardware_chipname_length =
65 cpuinfo_android_property_get("ro.hardware.chipname", properties->ro_hardware_chipname);
66 cpuinfo_log_debug("read ro.hardware.chipname = \"%.*s\"", ro_hardware_chipname_length, properties->ro_hardware_chipname);
67 }
68