Commit summary:
[platform/core/security/suspicious-activity-monitor.git] / daemon / 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  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 /**
19  * @file   sysinfo.h
20  * @brief  System information collector
21  * @date   Created Feb 26, 2018
22  * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
23  */
24
25 #include <system/system_info.h>
26
27 #include "sysinfo.h"
28
29 namespace
30 {
31
32 const std::string UNDEFINED_VAL{"undefined"};
33
34 /**
35  * @brief getStringSystemProperty returns system property as std::string
36  * @param prop the requested system property key
37  * @return requested system property on success and "undefined" otherwise
38  */
39 bool getStringSystemProperty(system_info_key_e prop, std::string& property)
40 {
41     char* val = NULL;
42
43     if (0 == system_info_get_value_string(prop, &val)) {
44         property.assign(val);
45         free(val);
46         return true;
47     }
48
49     return false;
50 }
51
52 /**
53  * @brief getStringPlatformProperty returns platform property as std::string
54  * @param prop the requested platform property key
55  * @return requested platform property on success and "undefined" otherwise
56  */
57 bool getStringPlatformProperty(const char* prop, std::string& property)
58 {
59     char* val = NULL;
60
61     if (0 == system_info_get_platform_string(prop, &val)) {
62         property.assign(val);
63         free(val);
64         return true;
65     }
66
67     return false;
68 }
69
70 }
71
72 namespace agent
73 {
74
75 std::string SysInfo::model()
76 {
77     std::string prop;
78     if (!getStringSystemProperty(SYSTEM_INFO_KEY_MODEL, prop)
79             && !getStringPlatformProperty("tizen.org/system/model_name", prop)) {
80         prop = UNDEFINED_VAL;
81     }
82     return prop;
83 }
84
85 std::string SysInfo::type()
86 {
87     std::string prop;
88     if (!getStringPlatformProperty("com.samsung/build_config/product_type", prop)
89             && !getStringPlatformProperty("tizen.org/feature/profile", prop)) {
90         prop = UNDEFINED_VAL;
91     }
92     return prop;
93 }
94
95 std::string SysInfo::osVersion()
96 {
97     std::string prop;
98     if (!getStringPlatformProperty("tizen.org/feature/platform.version", prop)) {
99         prop = UNDEFINED_VAL;
100     }
101     return prop;
102 }
103
104 std::string SysInfo::osName()
105 {
106     std::string prop;
107     if (!getStringSystemProperty(SYSTEM_INFO_KEY_PLATFORM_NAME, prop)
108             && !getStringPlatformProperty("tizen.org/system/platform.name", prop)) {
109         prop = UNDEFINED_VAL;
110     }
111     return prop;
112 }
113
114 std::string SysInfo::swVersion()
115 {
116     std::string prop;
117     if (!getStringSystemProperty(SYSTEM_INFO_KEY_TIZEN_VERSION, prop)
118             && !getStringPlatformProperty("tizen.org/system/build.string", prop)) {
119         prop = UNDEFINED_VAL;
120     }
121     return prop;
122 }
123
124 std::string SysInfo::tizenId()
125 {
126     std::string prop;
127     if (!getStringPlatformProperty("tizen.org/system/tizenid", prop)) {
128         prop = UNDEFINED_VAL;
129     }
130     return prop;
131 }
132
133 }