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.
26 #include <system_info.h>
27 #include <system_info_private.h>
28 #include <sys/utsname.h>
34 #define LOG_TAG "CAPI_SYSTEM_INFO"
36 #define SYSTEM_INFO_MAX -1
39 system_info_key_e key;
40 system_info_data_type_e data_type;
41 system_info_get_value_cb get_value_cb;
44 typedef system_info_s * system_info_h;
46 system_info_s system_info_table[] = {
49 /**< The model of the device */
50 SYSTEM_INFO_KEY_MODEL,
51 SYSTEM_INFO_DATA_TYPE_STRING,
56 /**< The version of the Tizen supported by the platform */
57 SYSTEM_INFO_KEY_TIZEN_VERSION,
58 SYSTEM_INFO_DATA_TYPE_STRING,
59 system_info_get_tizen_version
63 /**< The height of the screen in pixels */
64 SYSTEM_INFO_KEY_SCREEN_HEIGHT,
65 SYSTEM_INFO_DATA_TYPE_INT,
66 system_info_get_screen_height
70 /**< The width of the screen in pixels */
71 SYSTEM_INFO_KEY_SCREEN_WIDTH,
72 SYSTEM_INFO_DATA_TYPE_INT,
73 system_info_get_screen_width
77 /**< The Name of the Platform */
78 SYSTEM_INFO_KEY_PLATFORM_NAME,
79 SYSTEM_INFO_DATA_TYPE_STRING,
80 system_info_get_platform_name
84 /**< The Name of the Tizen version */
85 SYSTEM_INFO_KEY_TIZEN_VERSION_NAME,
86 SYSTEM_INFO_DATA_TYPE_STRING,
87 system_info_get_tizen_version_name
91 /**< The CORE CPU architecture of model */
92 SYSTEM_INFO_KEY_CORE_CPU_ARCH,
93 SYSTEM_INFO_DATA_TYPE_STRING,
94 system_info_get_core_cpu_arch
98 /**< The CORE CPU frequency of model */
99 SYSTEM_INFO_KEY_CORE_CPU_FREQ,
100 SYSTEM_INFO_DATA_TYPE_DOUBLE,
101 system_info_get_core_cpu_freq
105 /**< The height of the physical screen size in millimeters */
106 SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT,
107 SYSTEM_INFO_DATA_TYPE_INT,
108 system_info_get_physical_screen_height
112 /**< The width of the physical screen size in millimeters */
113 SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH,
114 SYSTEM_INFO_DATA_TYPE_INT,
115 system_info_get_physical_screen_width
119 /**< The build string of the platform binary */
120 SYSTEM_INFO_KEY_BUILD_STRING,
121 SYSTEM_INFO_DATA_TYPE_STRING,
122 system_info_get_build_string
126 /**< The build date of the platform binary */
127 SYSTEM_INFO_KEY_BUILD_DATE,
128 SYSTEM_INFO_DATA_TYPE_STRING,
129 system_info_get_build_date
133 /**< The build time of the platform binary */
134 SYSTEM_INFO_KEY_BUILD_TIME,
135 SYSTEM_INFO_DATA_TYPE_STRING,
136 system_info_get_build_time
140 /**< The manufacturer of the device */
141 SYSTEM_INFO_KEY_MANUFACTURER,
142 SYSTEM_INFO_DATA_TYPE_STRING,
143 system_info_get_manufacturer
147 /**< Indicates whether the device supports tethering */
148 SYSTEM_INFO_KEY_TETHERING_SUPPORTED,
149 SYSTEM_INFO_DATA_TYPE_BOOL,
150 system_info_get_tethering_supported
154 SYSTEM_INFO_MAX, -1, NULL
159 static system_info_mode_type_e system_info_system_info_model_type;
161 system_info_mode_type_e system_info_get_system_info_model_type(void)
163 return system_info_system_info_model_type;
166 void __attribute__((constructor)) system_info_init(void)
171 ret = system_info_get_platform_string("tizen.org/system/model_name", &str);
173 if (ret != SYSTEM_INFO_ERROR_NONE) {
174 LOGE("initialize error");
179 LOGE("Failed to get model name");
184 for (i = 0 ; i < len ; i++) {
185 str[i] = toupper(str[i]);
188 if (!strcmp(str, "EMULATOR"))
189 system_info_system_info_model_type = SYSTEM_INFO_MODEL_TYPE_EMULATOR;
191 system_info_system_info_model_type = SYSTEM_INFO_MODEL_TYPE_TARGET;
196 static int system_info_get(system_info_key_e key, system_info_h *system_info)
200 while (system_info_table[index].key != SYSTEM_INFO_MAX) {
201 if (system_info_table[index].key == key) {
202 *system_info = &system_info_table[index];
212 int system_info_get_value(system_info_key_e key, system_info_data_type_e data_type, void **value)
214 system_info_h system_info;
215 system_info_get_value_cb system_info_getter;
218 LOGE("INVALID_PARAMETER(0x%08x) : invalid output param", SYSTEM_INFO_ERROR_INVALID_PARAMETER);
219 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
222 if (system_info_get(key, &system_info)) {
223 LOGE("INVALID_PARAMETER(0x%08x) : invalid key", SYSTEM_INFO_ERROR_INVALID_PARAMETER);
224 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
227 if (system_info->data_type != data_type) {
228 LOGE("INVALID_PARAMETER(0x%08x) : invalid data type", SYSTEM_INFO_ERROR_INVALID_PARAMETER);
229 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
232 system_info_getter = system_info->get_value_cb;
234 if (system_info_getter == NULL) {
235 LOGE("IO_ERROR(0x%08x) : failed to call getter for the system information", SYSTEM_INFO_ERROR_IO_ERROR);
236 return SYSTEM_INFO_ERROR_IO_ERROR;
239 return system_info_getter(key, system_info->data_type, value);
242 API int system_info_get_value_int(system_info_key_e key, int *value)
244 return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_INT, (void **)value);
247 API int system_info_get_value_bool(system_info_key_e key, bool *value)
249 return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_BOOL, (void **)value);
252 API int system_info_get_value_double(system_info_key_e key, double *value)
254 return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_DOUBLE, (void **)value);
257 API int system_info_get_value_string(system_info_key_e key, char **value)
259 return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_STRING, (void **)value);
262 API int system_info_get_platform_bool(const char *key, bool *value)
268 supported = (bool *)value;
270 if (access(CONFIG_FILE_PATH, R_OK)) {
271 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
272 if (errno == EPERM || errno == EACCES)
273 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
274 return SYSTEM_INFO_ERROR_IO_ERROR;
277 ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, BOOL_TYPE, &string);
279 LOGE("cannot get %s", key);
283 if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
290 return SYSTEM_INFO_ERROR_NONE;
293 API int system_info_get_platform_int(const char *key, int *value)
299 ret_val = (int *)value;
301 if (access(CONFIG_FILE_PATH, R_OK)) {
302 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
303 if (errno == EPERM || errno == EACCES)
304 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
305 return SYSTEM_INFO_ERROR_IO_ERROR;
308 ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, INT_TYPE, &string);
310 LOGE("cannot get %s", key);
314 *ret_val = atoi(string);
318 return SYSTEM_INFO_ERROR_NONE;
321 API int system_info_get_platform_double(const char *key, double *value)
327 ret_val = (double *)value;
329 if (access(CONFIG_FILE_PATH, R_OK)) {
330 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
331 if (errno == EPERM || errno == EACCES)
332 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
333 return SYSTEM_INFO_ERROR_IO_ERROR;
336 ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, DBL_TYPE, &string);
338 LOGE("cannot get %s", key);
342 *ret_val = atof(string);
346 return SYSTEM_INFO_ERROR_NONE;
349 API int system_info_get_platform_string(const char *key, char **value)
354 if (access(CONFIG_FILE_PATH, R_OK)) {
355 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
356 if (errno == EPERM || errno == EACCES)
357 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
358 return SYSTEM_INFO_ERROR_IO_ERROR;
361 ret = system_info_get_file(key, (void**)&string);
364 return SYSTEM_INFO_ERROR_NONE;
367 ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, STR_TYPE, &string);
369 LOGE("cannot get %s", key);
375 return SYSTEM_INFO_ERROR_NONE;
378 API int system_info_get_custom_bool(const char *key, bool *value)
384 supported = (bool *)value;
386 if (access(CONFIG_FILE_PATH, R_OK)) {
387 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
388 if (errno == EPERM || errno == EACCES)
389 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
390 return SYSTEM_INFO_ERROR_IO_ERROR;
393 ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, BOOL_TYPE, &string);
395 LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
399 if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
406 return SYSTEM_INFO_ERROR_NONE;
409 API int system_info_get_custom_int(const char *key, int *value)
415 ret_val = (int *)value;
417 if (access(CONFIG_FILE_PATH, R_OK)) {
418 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
419 if (errno == EPERM || errno == EACCES)
420 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
421 return SYSTEM_INFO_ERROR_IO_ERROR;
424 ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, INT_TYPE, &string);
426 LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
430 *ret_val = atoi(string);
434 return SYSTEM_INFO_ERROR_NONE;
437 API int system_info_get_custom_double(const char *key, double *value)
443 ret_val = (double *)value;
445 if (access(CONFIG_FILE_PATH, R_OK)) {
446 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
447 if (errno == EPERM || errno == EACCES)
448 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
449 return SYSTEM_INFO_ERROR_IO_ERROR;
452 ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, DBL_TYPE, &string);
454 LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
458 *ret_val = atof(string);
462 return SYSTEM_INFO_ERROR_NONE;
465 API int system_info_get_custom_string(const char *key, char **value)
470 if (access(CONFIG_FILE_PATH, R_OK)) {
471 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
472 if (errno == EPERM || errno == EACCES)
473 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
474 return SYSTEM_INFO_ERROR_IO_ERROR;
477 ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, STR_TYPE, &string);
479 LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
485 return SYSTEM_INFO_ERROR_NONE;