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_platform_bool(const char *key, bool *value)
248 supported = (bool *)value;
250 if (access(CONFIG_FILE_PATH, R_OK)) {
251 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
252 if (errno == EPERM || errno == EACCES)
253 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
254 return SYSTEM_INFO_ERROR_IO_ERROR;
257 ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, BOOL_TYPE, &string);
259 LOGE("cannot get %s", key);
263 if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
270 return SYSTEM_INFO_ERROR_NONE;
273 API int system_info_get_platform_int(const char *key, int *value)
279 ret_val = (int *)value;
281 if (access(CONFIG_FILE_PATH, R_OK)) {
282 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
283 if (errno == EPERM || errno == EACCES)
284 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
285 return SYSTEM_INFO_ERROR_IO_ERROR;
288 ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, INT_TYPE, &string);
290 LOGE("cannot get %s", key);
294 *ret_val = atoi(string);
298 return SYSTEM_INFO_ERROR_NONE;
301 API int system_info_get_platform_double(const char *key, double *value)
307 ret_val = (double *)value;
309 if (access(CONFIG_FILE_PATH, R_OK)) {
310 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
311 if (errno == EPERM || errno == EACCES)
312 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
313 return SYSTEM_INFO_ERROR_IO_ERROR;
316 ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, DBL_TYPE, &string);
318 LOGE("cannot get %s", key);
322 *ret_val = atof(string);
326 return SYSTEM_INFO_ERROR_NONE;
329 API int system_info_get_platform_string(const char *key, char **value)
334 if (access(CONFIG_FILE_PATH, R_OK)) {
335 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
336 if (errno == EPERM || errno == EACCES)
337 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
338 return SYSTEM_INFO_ERROR_IO_ERROR;
341 ret = system_info_get_no_file(key, (void**)&string);
344 return SYSTEM_INFO_ERROR_NONE;
347 ret = system_info_get_value_from_config_xml(PLATFORM_TAG, key, STR_TYPE, &string);
349 LOGE("cannot get %s", key);
355 return SYSTEM_INFO_ERROR_NONE;
358 API int system_info_get_custom_bool(const char *key, bool *value)
364 supported = (bool *)value;
366 if (access(CONFIG_FILE_PATH, R_OK)) {
367 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
368 if (errno == EPERM || errno == EACCES)
369 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
370 return SYSTEM_INFO_ERROR_IO_ERROR;
373 ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, BOOL_TYPE, &string);
375 LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
379 if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
386 return SYSTEM_INFO_ERROR_NONE;
389 API int system_info_get_custom_int(const char *key, int *value)
395 ret_val = (int *)value;
397 if (access(CONFIG_FILE_PATH, R_OK)) {
398 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
399 if (errno == EPERM || errno == EACCES)
400 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
401 return SYSTEM_INFO_ERROR_IO_ERROR;
404 ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, INT_TYPE, &string);
406 LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
410 *ret_val = atoi(string);
414 return SYSTEM_INFO_ERROR_NONE;
417 API int system_info_get_custom_double(const char *key, double *value)
423 ret_val = (double *)value;
425 if (access(CONFIG_FILE_PATH, R_OK)) {
426 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
427 if (errno == EPERM || errno == EACCES)
428 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
429 return SYSTEM_INFO_ERROR_IO_ERROR;
432 ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, DBL_TYPE, &string);
434 LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
438 *ret_val = atof(string);
442 return SYSTEM_INFO_ERROR_NONE;
445 API int system_info_get_custom_string(const char *key, char **value)
450 if (access(CONFIG_FILE_PATH, R_OK)) {
451 LOGE("cannot find file %s!!!", CONFIG_FILE_PATH);
452 if (errno == EPERM || errno == EACCES)
453 return SYSTEM_INFO_ERROR_PERMISSION_DENIED;
454 return SYSTEM_INFO_ERROR_IO_ERROR;
457 ret = system_info_get_value_from_config_xml(CUSTOM_TAG, key, STR_TYPE, &string);
459 LOGE("cannot get %s info from %s!!!", key, CONFIG_FILE_PATH);
465 return SYSTEM_INFO_ERROR_NONE;