3a101abbee018dda59bf655d5bce8b0ea7f31cac
[platform/core/security/suspicious-activity-monitor.git] / device-agent / communication / src / sysinfo.cpp
1 /**
2  * Samsung Ukraine R&D Center (SRK under a contract between)
3  * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
5  */
6 /**
7  * @file   sysinfo.h
8  * @brief  System information collector
9  * @date   Created Feb 26, 2018
10  * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
11  */
12
13 #include "sysinfo.h"
14 #include <system/system_info.h>
15
16 namespace
17 {
18
19 const std::string UNDEFINED_VAL{"undefined"};
20
21 /**
22  * @brief getStringSystemProperty returns system property as std::string
23  * @param prop the requested system property key
24  * @return requested system property on success and "undefined" otherwise
25  */
26 bool getStringSystemProperty(system_info_key_e prop, std::string& property)
27 {
28     char* val;
29
30     if (0 == system_info_get_value_string(prop, &val)) {
31         property.assign(val);
32         free(val);
33         return true;
34     }
35
36     return false;
37 }
38
39 /**
40  * @brief getStringPlatformProperty returns platform property as std::string
41  * @param prop the requested platform property key
42  * @return requested platform property on success and "undefined" otherwise
43  */
44 bool getStringPlatformProperty(const char* prop, std::string& property)
45 {
46     char* val;
47
48     if (0 == system_info_get_platform_string(prop, &val)) {
49         property.assign(val);
50         free(val);
51         return true;
52     }
53
54     return false;
55 }
56
57 }
58
59 namespace NetworkManager
60 {
61
62 std::string SysInfo::model()
63 {
64     std::string prop;
65     if (!getStringSystemProperty(SYSTEM_INFO_KEY_MODEL, prop)
66             && !getStringPlatformProperty("tizen.org/system/model_name", prop)) {
67         prop = UNDEFINED_VAL;
68     }
69     return prop;
70 }
71
72 std::string SysInfo::type()
73 {
74     std::string prop;
75     if (!getStringPlatformProperty("com.samsung/build_config/product_type", prop)
76             && !getStringPlatformProperty("tizen.org/feature/profile", prop)) {
77         prop = UNDEFINED_VAL;
78     }
79     return prop;
80 }
81
82 std::string SysInfo::osVersion()
83 {
84     std::string prop;
85     if (!getStringPlatformProperty("tizen.org/feature/platform.version", prop)) {
86         prop = UNDEFINED_VAL;
87     }
88     return prop;
89 }
90
91 std::string SysInfo::osName()
92 {
93     std::string prop;
94     if (!getStringSystemProperty(SYSTEM_INFO_KEY_PLATFORM_NAME, prop)
95             && !getStringPlatformProperty("tizen.org/system/platform.name", prop)) {
96         prop = UNDEFINED_VAL;
97     }
98     return prop;
99 }
100
101 std::string SysInfo::swVersion()
102 {
103     std::string prop;
104     if (!getStringSystemProperty(SYSTEM_INFO_KEY_TIZEN_VERSION, prop)
105             && !getStringPlatformProperty("tizen.org/system/build.string", prop)) {
106         prop = UNDEFINED_VAL;
107     }
108     return prop;
109 }
110
111 }