refactoring for model-config
[framework/api/system-info.git] / src / system_info_platform.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <string.h>
22
23 #include <dlog.h>
24
25 #include <system_info.h>
26 #include <system_info_private.h>
27
28 #ifdef LOG_TAG
29 #undef LOG_TAG
30 #endif
31
32 #define LOG_TAG "CAPI_SYSTEM_INFO"
33
34 int system_info_get_model(system_info_key_e key, system_info_data_type_e data_type, void **value)
35 {
36         return system_info_ini_get_string(INFO_FILE_PATH, "version:model", (char **)value);
37 }
38
39 int system_info_get_build_string(system_info_key_e key, system_info_data_type_e data_type, void **value)
40 {
41         return system_info_ini_get_string(INFO_FILE_PATH, "version:build", (char **)value);
42 }
43
44 int system_info_get_build_date(system_info_key_e key, system_info_data_type_e data_type, void **value)
45 {
46         return system_info_ini_get_string(INFO_FILE_PATH, "build:date", (char **)value);
47 }
48
49 int system_info_get_build_time(system_info_key_e key, system_info_data_type_e data_type, void **value)
50 {
51         return system_info_ini_get_string(INFO_FILE_PATH, "build:time", (char **)value);
52 }
53
54 int system_info_get_tizen_version(system_info_key_e key, system_info_data_type_e data_type, void **value)
55 {
56         return system_info_get_platform_string("tizen.org/feature/platform.version", (char**)value);
57 }
58
59 int system_info_get_core_cpu_arch(system_info_key_e key, system_info_data_type_e data_type, void **value)
60 {
61         bool cpu_arch;
62         char *CORE_CPU_ARCH = NULL;
63
64         if (system_info_get_platform_bool("tizen.org/feature/platform.core.cpu.arch.armv6", &cpu_arch) == SYSTEM_INFO_ERROR_NONE
65                 && cpu_arch == true)
66                 CORE_CPU_ARCH = strdup("armv6");
67         else if (system_info_get_platform_bool("tizen.org/feature/platform.core.cpu.arch.armv7", &cpu_arch) == SYSTEM_INFO_ERROR_NONE
68                 && cpu_arch == true)
69                 CORE_CPU_ARCH = strdup("armv7");
70         else if (system_info_get_platform_bool("tizen.org/feature/platform.core.cpu.arch.x86", &cpu_arch) == SYSTEM_INFO_ERROR_NONE
71                 && cpu_arch == true)
72                 CORE_CPU_ARCH = strdup("x86");
73
74                 if (CORE_CPU_ARCH == NULL) {
75                 LOGE("Unknown cpu");
76                 return SYSTEM_INFO_ERROR_IO_ERROR;
77         }
78
79         *value = CORE_CPU_ARCH;
80
81         return SYSTEM_INFO_ERROR_NONE;
82 }
83
84 int system_info_get_core_fpu_arch(system_info_key_e key, system_info_data_type_e data_type, void **value)
85 {
86         bool fpu_arch;
87         char *CORE_FPU_ARCH = NULL;
88
89         if (system_info_get_platform_bool("tizen.org/feature/platform.core.fpu.arch.sse2", &fpu_arch) == SYSTEM_INFO_ERROR_NONE
90                 && fpu_arch == true)
91                                         CORE_FPU_ARCH = strdup("sse2");
92         else if (system_info_get_platform_bool("tizen.org/feature/platform.core.fpu.arch.sse3", &fpu_arch) == SYSTEM_INFO_ERROR_NONE
93                 && fpu_arch == true)
94                 CORE_FPU_ARCH = strdup("sse3");
95         else if (system_info_get_platform_bool("tizen.org/feature/platform.core.fpu.arch.ssse3", &fpu_arch) == SYSTEM_INFO_ERROR_NONE
96                 && fpu_arch == true)
97                 CORE_FPU_ARCH = strdup("ssse3");
98         else if (system_info_get_platform_bool("tizen.org/feature/platform.core.fpu.arch.vfpv2", &fpu_arch) == SYSTEM_INFO_ERROR_NONE
99                 && fpu_arch == true)
100                 CORE_FPU_ARCH = strdup("vfpv2");
101         else if (system_info_get_platform_bool("tizen.org/feature/platform.core.fpu.arch.vfpv3", &fpu_arch) == SYSTEM_INFO_ERROR_NONE
102                 && fpu_arch == true)
103                 CORE_FPU_ARCH = strdup("vfpv3");
104
105                                 if (CORE_FPU_ARCH == NULL) {
106                 LOGE("Unknown fpu");
107                 return SYSTEM_INFO_ERROR_IO_ERROR;
108         }
109
110         *value = CORE_FPU_ARCH;
111
112         return SYSTEM_INFO_ERROR_NONE;
113 }
114
115 int system_info_get_core_cpu_freq(system_info_key_e key, system_info_data_type_e data_type, void **value)
116 {
117         double *count;
118         FILE *cpuinfo, *cpuinfo_max_freq;
119         double max_freq = 0.0;
120         char *name;
121         char str[MAXBUFSIZE];
122
123         if (system_info_get_system_info_model_type() != SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
124                 cpuinfo_max_freq = fopen(CPU_INFO_MAX_FREQ_PATH, "r");
125                 if (NULL == cpuinfo_max_freq) {
126                         LOGE("cannot file open %s file!!!", CPU_INFO_MAX_FREQ_PATH);
127                         return SYSTEM_INFO_ERROR_IO_ERROR;
128                 } else {
129                         if (fscanf(cpuinfo_max_freq, "%lf", &max_freq) < 1) {
130                                 fclose(cpuinfo_max_freq);
131                                 return SYSTEM_INFO_ERROR_IO_ERROR;
132                         }
133                         max_freq = max_freq / 1024;
134                 }
135                 fclose(cpuinfo_max_freq);
136         } else {
137                 /* Emulator */
138                 cpuinfo = fopen(CPU_INFO_FILE_PATH, "r");
139                 if (NULL == cpuinfo) {
140                         LOGE("cannot file open %s file!!!", CPU_INFO_FILE_PATH);
141                         return SYSTEM_INFO_ERROR_IO_ERROR;
142                 } else {
143                         while (fgets(str, MAXBUFSIZE, cpuinfo)) {
144                                 if (!strncmp("cpu MHz", str, strlen("cpu MHz"))) {
145                                         name = strchr(str, ':');
146                                         max_freq = atof(name+2);
147                                         break;
148                                 }
149                         }
150                 }
151                 fclose(cpuinfo);
152         }
153
154         count = (double *)value;
155
156         *count = max_freq;
157
158         return SYSTEM_INFO_ERROR_NONE;
159 }
160
161 int system_info_get_platform_name(system_info_key_e key, system_info_data_type_e data_type, void **value)
162 {
163         return system_info_get_platform_string("tizen.org/system/platform.name", (char**)value);
164         }
165
166 int system_info_get_tizen_version_name(system_info_key_e key, system_info_data_type_e data_type, void **value)
167 {
168         char *TIZEN_VERSION_NAME = NULL;
169         char *name = NULL;
170         char str[MAXBUFSIZE];
171         char tmpStr[MAXBUFSIZE];
172         int tmpStrlen = 0;
173         FILE *info;
174         extern char *strcasestr(const char *s, const char *find);
175
176         info = fopen(OS_RELEASE_FILE_PATH, "r");
177         if (NULL == info) {
178                 LOGE("cannot file open %s file!!!", OS_RELEASE_FILE_PATH);
179                 return SYSTEM_INFO_ERROR_IO_ERROR;
180         }
181
182         while (fgets(str, MAXBUFSIZE, info)) {
183                 if (strcasestr(str, "VERSION")) {
184                         name = strchr(str, ',');
185                         name += 2;
186                         tmpStrlen = strlen(name);
187
188                         strncpy(tmpStr, name, tmpStrlen-2);
189                         tmpStr[tmpStrlen-2] = '\0';
190
191                         TIZEN_VERSION_NAME = strdup(tmpStr);
192                         if (TIZEN_VERSION_NAME == NULL) {
193                                 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
194                                 fclose(info);
195                                 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
196                         }
197                         break;
198                 }
199         }
200
201         *value = TIZEN_VERSION_NAME;
202         fclose(info);
203         return SYSTEM_INFO_ERROR_NONE;
204 }
205
206 int system_info_get_opengles_version(system_info_key_e key, system_info_data_type_e data_type, void **value)
207 {
208         bool glversion = 0;
209         char *version;
210         char *OPENGLES_VERSION = NULL;
211         int version_supported = 0;
212
213         if (system_info_get_platform_bool("tizen.org/feature/opengles.version.1_1", &glversion) == SYSTEM_INFO_ERROR_NONE
214                 && glversion == true)
215                 version_supported += 1;
216
217         if (system_info_get_platform_bool("tizen.org/feature/opengles.version.2_0", &glversion) == SYSTEM_INFO_ERROR_NONE
218                 && glversion == true)
219                 version_supported += 2;
220
221         switch (version_supported) {
222         case 1:
223                 version = "1.1";
224                 break;
225
226         case 2:
227                 version = "2.0";
228                 break;
229
230         case 3:
231                 version = "1.1/2.0";
232                 break;
233         default:
234                 version = NULL;
235                                 break;
236 }
237
238         if (version != NULL) {
239                 OPENGLES_VERSION = strdup(version);
240
241                 if (OPENGLES_VERSION == NULL) {
242                                         LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
243                                         return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
244                                 }
245         }
246
247         *value = OPENGLES_VERSION;
248
249                 return SYSTEM_INFO_ERROR_NONE;
250         }
251
252 int system_info_get_opengles_texture_format(system_info_key_e key, system_info_data_type_e data_type, void **value)
253 {
254         bool texture;
255         char *OPENGLES_TEXTURE_FORMAT;
256         char textureformat[MAXBUFSIZE];
257
258         textureformat[0] = '\0';
259
260         if (system_info_get_platform_bool("tizen.org/feature/opengles.texture_format.utc", &texture) == SYSTEM_INFO_ERROR_NONE
261                 && texture == true)
262                 strcat(textureformat, "utc ");
263         if (system_info_get_platform_bool("tizen.org/feature/opengles.texture_format.ptc", &texture) == SYSTEM_INFO_ERROR_NONE
264                 && texture == true)
265                 strcat(textureformat, "| ptc ");
266         if (system_info_get_platform_bool("tizen.org/feature/opengles.texture_format.etc", &texture) == SYSTEM_INFO_ERROR_NONE
267                 && texture == true)
268                 strcat(textureformat, "| etc ");
269         if (system_info_get_platform_bool("tizen.org/feature/opengles.texture_format.3dc", &texture) == SYSTEM_INFO_ERROR_NONE
270                 && texture == true)
271                 strcat(textureformat, "| 3dc ");
272         if (system_info_get_platform_bool("tizen.org/feature/opengles.texture_format.atc", &texture) == SYSTEM_INFO_ERROR_NONE
273                 && texture == true)
274                 strcat(textureformat, "| atc ");
275         if (system_info_get_platform_bool("tizen.org/feature/opengles.texture_format.pvrtc", &texture) == SYSTEM_INFO_ERROR_NONE
276                 && texture == true)
277                 strcat(textureformat, "| pvrtc");
278
279         OPENGLES_TEXTURE_FORMAT = strdup(textureformat);
280
281         if (OPENGLES_TEXTURE_FORMAT == NULL) {
282                 LOGE("OUT_OF_MEMORY(0x%08x)", SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
283                 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
284         }
285
286         *value = OPENGLES_TEXTURE_FORMAT;
287
288         return SYSTEM_INFO_ERROR_NONE;
289 }
290
291 int system_info_get_mms_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
292 {
293         return system_info_get_platform_bool("tizen.org/feature/network.telephony.mms", (bool *)value);
294         }
295
296 int system_info_get_sms_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
297 {
298         return system_info_get_platform_bool("tizen.org/feature/network.telephony.sms", (bool *)value);
299         }
300
301 int system_info_get_cbs_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
302 {
303         return system_info_get_platform_bool("tizen.org/feature/network.telephony.cbs", (bool *)value);
304 }
305
306 int system_info_get_graphics_hwaccel_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
307 {
308         return system_info_get_platform_bool("tizen.org/feature/graphics.acceleration", (bool *)value);
309 }
310
311 int system_info_get_feature_pinch_zoom_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
312 {
313         return system_info_get_platform_bool("tizen.org/feature/multi_point_touch.pinch_zoom", (bool *)value);
314 }
315
316 int system_info_get_feature_auto_rotation_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
317 {
318         return system_info_get_platform_bool("tizen.org/feature/screen.auto_rotation", (bool *)value);
319 }