2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <sys/types.h>
28 #include <iniparser.h>
30 #include <system_info.h>
31 #include <system_info_private.h>
34 #include <GLES/glext.h>
40 #define LOG_TAG "TIZEN_N_SYSTEM_INFO"
42 #define LIB_GLES_V1 "/usr/lib/libGLESv1_CM.so"
43 #define LIB_GLES_V2 "/usr/lib/libGLESv2.so"
45 #define SIZE_OF_MODEL_NAME 8
47 int system_info_get_model(system_info_key_e key, system_info_data_type_e data_type, void **value)
53 char tmpStr[MAXBUFSIZE];
55 extern char *strcasestr(const char *s, const char *find);
57 if (system_info_get_system_info_model_type() != SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
58 info = fopen(INFO_FILE_PATH, "r");
60 LOGE("[%s] cannot file open %s file!!!", __func__, INFO_FILE_PATH);
61 return SYSTEM_INFO_ERROR_IO_ERROR;
63 while (fgets(str, MAXBUFSIZE, info)) {
64 if (strncmp("Build", str, strlen("Build")))
68 if (strcasestr(str, "Tizen")) {
70 token = strtok(tmpStr, "_");
71 token = strtok(NULL, "_");
72 MODEL = strdup(token);
74 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
76 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
79 /* DEV, SEL, REL Target */
80 name = strchr(str, '=');
81 strncpy(tmpStr, name+1, SIZE_OF_MODEL_NAME);
82 tmpStr[SIZE_OF_MODEL_NAME] = '\0';
83 MODEL = strdup(tmpStr);
85 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
87 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
97 MODEL = strdup("Emulator");
99 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
100 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
106 return SYSTEM_INFO_ERROR_NONE;
109 int system_info_get_tizen_version(system_info_key_e key, system_info_data_type_e data_type, void **value)
111 char *TIZEN_VERSION = NULL;
116 char str[MAXBUFSIZE];
117 char tmpStr[MAXBUFSIZE];
121 info = fopen(INFO_FILE_PATH, "r");
123 LOGE("[%s] cannot file open %s file!!!", __func__, INFO_FILE_PATH);
124 return SYSTEM_INFO_ERROR_IO_ERROR;
126 while (fgets(str, MAXBUFSIZE, info)) {
127 if (!strncmp("Major", str, strlen("Major"))) {
128 name = strchr(str, '=');
130 strncpy(tmpStr, name, strlen(name)-2);
131 tmpStr[strlen(name)-2] = '\0';
132 major = strdup(tmpStr);
134 } else if (!strncmp("Minor", str, strlen("Minor"))) {
135 name = strchr(str, '=');
137 strncpy(tmpStr, name, strlen(name)-2);
138 tmpStr[strlen(name)-2] = '\0';
139 minor = strdup(tmpStr);
141 } else if (!strncmp("Order", str, strlen("Order"))) {
142 name = strchr(str, '=');
144 strncpy(tmpStr, name, strlen(name)-2);
145 tmpStr[strlen(name)-2] = '\0';
146 if (!strcmp(tmpStr, ""))
149 order = strdup(tmpStr);
157 TIZEN_VERSION = (char *)malloc(strlen(major)+strlen(minor)+strlen(order)+3);
159 if (TIZEN_VERSION == NULL) {
160 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
164 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
167 memset(TIZEN_VERSION, 0, strlen(major)+strlen(minor)+strlen(order)+3);
169 sprintf(TIZEN_VERSION, "%s.%s.%s", major, minor, order);
170 TIZEN_VERSION[strlen(TIZEN_VERSION)] = '\0';
172 *value = TIZEN_VERSION;
177 return SYSTEM_INFO_ERROR_NONE;
180 int system_info_get_platform_name(system_info_key_e key, system_info_data_type_e data_type, void **value)
182 char *PLATFORM_NAME = NULL;
184 PLATFORM_NAME = strdup("TIZEN");
185 if (PLATFORM_NAME == NULL) {
186 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
187 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
190 *value = PLATFORM_NAME;
192 return SYSTEM_INFO_ERROR_NONE;
195 int system_info_get_tizen_version_name(system_info_key_e key, system_info_data_type_e data_type, void **value)
197 char *TIZEN_VERSION_NAME = NULL;
199 char str[MAXBUFSIZE];
202 info = fopen(INFO_FILE_PATH, "r");
204 LOGE("[%s] cannot file open %s file!!!", __func__, INFO_FILE_PATH);
205 return SYSTEM_INFO_ERROR_IO_ERROR;
207 while (fgets(str, MAXBUFSIZE, info)) {
208 if (!strncmp("Major", str, strlen("Major"))) {
209 name = strchr(str, '=');
211 if (!strncmp("1", name, 1))
212 TIZEN_VERSION_NAME = strdup("Larkspur");
213 else if (!strncmp("2", name, 1))
214 TIZEN_VERSION_NAME = strdup("Magnolia");
216 TIZEN_VERSION_NAME = strdup("Unknown Version Name");
218 if (TIZEN_VERSION_NAME == NULL) {
219 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
221 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
229 *value = TIZEN_VERSION_NAME;
231 return SYSTEM_INFO_ERROR_NONE;
234 int system_info_get_opengles_version(system_info_key_e key, system_info_data_type_e data_type, void **value)
237 char *OPENGLES_VERSION = NULL;
238 int version_supported = 0;
240 if (!access(LIB_GLES_V1, R_OK))
241 version_supported += 1;
243 if (!access(LIB_GLES_V2, R_OK))
244 version_supported += 2;
246 switch (version_supported) {
263 if (version != NULL) {
264 OPENGLES_VERSION = strdup(version);
266 if (OPENGLES_VERSION == NULL) {
267 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
268 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
272 *value = OPENGLES_VERSION;
274 return SYSTEM_INFO_ERROR_NONE;
277 int system_info_get_core_cpu_arch(system_info_key_e key, system_info_data_type_e data_type, void **value)
280 char *CORE_CPU_ARCH = NULL;
282 char str[MAXBUFSIZE];
284 if (system_info_get_system_info_model_type() != SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
285 cpuinfo = fopen(CPU_INFO_FILE_PATH, "r");
286 if (NULL == cpuinfo) {
287 LOGE("[%s] cannot file open %s file!!!", __func__, CPU_INFO_FILE_PATH);
288 return SYSTEM_INFO_ERROR_IO_ERROR;
290 while (fgets(str, MAXBUFSIZE, cpuinfo)) {
291 if (!strncmp("Processor", str, strlen("Processor"))) {
292 name = strchr(str, ':');
293 if (!(strncmp("ARMv7", name+2, strlen("ARMv7"))))
294 CORE_CPU_ARCH = strdup("ARMv7");
295 else if (!(strncmp("ARMv6", name+2, strlen("ARMv6"))))
296 CORE_CPU_ARCH = strdup("ARMv6");
297 else if (!(strncmp("x86", name+2, strlen("x86"))))
298 CORE_CPU_ARCH = strdup("x86");
306 CORE_CPU_ARCH = NULL;
309 *value = CORE_CPU_ARCH;
311 return SYSTEM_INFO_ERROR_NONE;
314 int system_info_get_core_fpu_arch(system_info_key_e key, system_info_data_type_e data_type, void **value)
317 char *CORE_FPU_ARCH = NULL;
319 char str[MAXBUFSIZE];
321 if (system_info_get_system_info_model_type() != SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
322 cpuinfo = fopen(CPU_INFO_FILE_PATH, "r");
323 if (NULL == cpuinfo) {
324 LOGE("[%s] cannot file open %s file!!!", __func__, CPU_INFO_FILE_PATH);
325 return SYSTEM_INFO_ERROR_IO_ERROR;
327 while (fgets(str, MAXBUFSIZE, cpuinfo)) {
328 if (!strncmp("Features", str, strlen("Features"))) {
329 name = strchr(str, ':');
330 if (strstr(name+2, "vfpv3"))
331 CORE_FPU_ARCH = strdup("vfpv3");
332 else if (strstr(name+2, "vfpv2"))
333 CORE_FPU_ARCH = strdup("vfpv2");
334 else if (strstr(name+2, "sse2"))
335 CORE_FPU_ARCH = strdup("sse2");
336 else if (strstr(name+2, "sse3"))
337 CORE_FPU_ARCH = strdup("sse3");
338 else if (strstr(name+2, "ssse3"))
339 CORE_FPU_ARCH = strdup("ssse3");
347 CORE_FPU_ARCH = NULL;
350 *value = CORE_FPU_ARCH;
352 return SYSTEM_INFO_ERROR_NONE;
355 int system_info_get_core_cpu_freq(system_info_key_e key, system_info_data_type_e data_type, void **value)
358 FILE *cpuinfo, *cpuinfo_max_freq;
361 char str[MAXBUFSIZE];
363 if (system_info_get_system_info_model_type() != SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
364 cpuinfo_max_freq = fopen(CPU_INFO_MAX_FREQ_PATH, "r");
365 if (NULL == cpuinfo_max_freq) {
366 LOGE("[%s] cannot file open %s file!!!", __func__, CPU_INFO_MAX_FREQ_PATH);
367 return SYSTEM_INFO_ERROR_IO_ERROR;
369 if (fscanf(cpuinfo_max_freq, "%lf", &max_freq) < 1) {
370 fclose(cpuinfo_max_freq);
371 return SYSTEM_INFO_ERROR_IO_ERROR;
373 max_freq = max_freq / 1024;
377 cpuinfo = fopen(CPU_INFO_FILE_PATH, "r");
378 if (NULL == cpuinfo) {
379 LOGE("[%s] cannot file open %s file!!!", __func__, CPU_INFO_FILE_PATH);
380 return SYSTEM_INFO_ERROR_IO_ERROR;
382 while (fgets(str, MAXBUFSIZE, cpuinfo)) {
383 if (!strncmp("cpu MHz", str, strlen("cpu MHz"))) {
384 name = strchr(str, ':');
385 max_freq = atof(name+2);
392 count = (double *)value;
396 return SYSTEM_INFO_ERROR_NONE;
400 int system_info_get_opengles_texture_format(system_info_key_e key, system_info_data_type_e data_type, void **value)
403 char *OPENGLES_TEXTURE_FORMAT;
404 char textureformat[MAXBUFSIZE];
406 memset(textureformat, 0, MAXBUFSIZE);
408 if (!access(LIB_GLES_V1, R_OK)) {
409 strncpy(textureformat+cnt, "utc ", strlen("utc "));
410 cnt += strlen("utc ");
412 if (GL_OES_compressed_paletted_texture) {
413 strncpy(textureformat+cnt, "| ptc ", strlen("| ptc "));
414 cnt += strlen("| ptc ");
416 if (GL_OES_compressed_ETC1_RGB8_texture) {
417 strncpy(textureformat+cnt, "| etc ", strlen("| etc "));
418 cnt += strlen("| etc ");
420 if (GL_AMD_compressed_3DC_texture) {
421 strncpy(textureformat+cnt, "| 3dc ", strlen("| 3dc "));
422 cnt += strlen("| 3dc ");
424 if (GL_AMD_compressed_ATC_texture) {
425 strncpy(textureformat+cnt, "| atc ", strlen("| atc "));
426 cnt += strlen("| atc ");
428 if (GL_IMG_texture_compression_pvrtc) {
429 strncpy(textureformat+cnt, "| pvrtc", strlen("| pvrtc"));
430 cnt += strlen("| pvrtc");
433 OPENGLES_TEXTURE_FORMAT = strdup(textureformat);
435 if (OPENGLES_TEXTURE_FORMAT == NULL) {
436 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
437 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
440 *value = OPENGLES_TEXTURE_FORMAT;
442 return SYSTEM_INFO_ERROR_NONE;
445 int system_info_get_build_string(system_info_key_e key, system_info_data_type_e data_type, void **value)
447 char *BUILD_STRING = NULL;
449 char str[MAXBUFSIZE];
450 char tmpStr[MAXBUFSIZE];
453 info = fopen(INFO_FILE_PATH, "r");
455 LOGE("[%s] cannot file open %s file!!!", __func__, INFO_FILE_PATH);
456 return SYSTEM_INFO_ERROR_IO_ERROR;
458 while (fgets(str, MAXBUFSIZE, info)) {
459 if (!strncmp("Build", str, strlen("Build"))) {
460 name = strchr(str, '=');
462 strncpy(tmpStr, name, strlen(name)-2);
463 tmpStr[strlen(name)-2] = '\0';
465 BUILD_STRING = strdup(tmpStr);
466 if (BUILD_STRING == NULL) {
467 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
469 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
476 *value = BUILD_STRING;
478 return SYSTEM_INFO_ERROR_NONE;
481 int system_info_get_build_date(system_info_key_e key, system_info_data_type_e data_type, void **value)
483 char *BUILD_DATE = NULL;
485 char str[MAXBUFSIZE];
486 char tmpStr[MAXBUFSIZE];
489 info = fopen(INFO_FILE_PATH, "r");
491 LOGE("[%s] cannot file open %s file!!!", __func__, INFO_FILE_PATH);
492 return SYSTEM_INFO_ERROR_IO_ERROR;
494 while (fgets(str, MAXBUFSIZE, info)) {
495 if (!strncmp("Date", str, strlen("Date"))) {
496 name = strchr(str, '=');
498 strncpy(tmpStr, name, strlen(name)-2);
499 tmpStr[strlen(name)-2] = '\0';
501 BUILD_DATE = strdup(tmpStr);
502 if (BUILD_DATE == NULL) {
503 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
505 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
514 return SYSTEM_INFO_ERROR_NONE;
517 int system_info_get_build_time(system_info_key_e key, system_info_data_type_e data_type, void **value)
519 char *BUILD_TIME = NULL;
521 char str[MAXBUFSIZE];
522 char tmpStr[MAXBUFSIZE];
525 info = fopen(INFO_FILE_PATH, "r");
527 LOGE("[%s] cannot file open %s file!!!", __func__, INFO_FILE_PATH);
528 return SYSTEM_INFO_ERROR_IO_ERROR;
530 while (fgets(str, MAXBUFSIZE, info)) {
531 if (!strncmp("Time", str, strlen("Time"))) {
532 name = strchr(str, '=');
534 strncpy(tmpStr, name, strlen(name)-2);
535 tmpStr[strlen(name)-2] = '\0';
537 BUILD_TIME = strdup(tmpStr);
538 if (BUILD_TIME == NULL) {
539 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
541 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
550 return SYSTEM_INFO_ERROR_NONE;