2.0_alpha release commit
[profile/ivi/system-info.git] / src / system_info.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 <string.h>
21
22 #include <vconf.h>
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 "TIZEN_N_SYSTEM_INFO"
33
34 #define SYSTEM_INFO_MAX -1
35
36 typedef struct {
37         system_info_key_e key;
38         system_info_data_type_e data_type;
39         system_info_get_value_cb get_value_cb;
40 } system_info_s;
41
42 typedef system_info_s * system_info_h;
43
44 system_info_s system_info_table[] = {
45
46 {
47          /**< The model of the device */
48         SYSTEM_INFO_KEY_MODEL,
49         SYSTEM_INFO_DATA_TYPE_STRING,
50         system_info_get_model
51 },
52
53 {
54          /**< The version of the Tizen supported by the platform */
55         SYSTEM_INFO_KEY_TIZEN_VERSION,
56         SYSTEM_INFO_DATA_TYPE_STRING,
57         system_info_get_tizen_version
58 },
59
60 {
61         /**< Indicates whether the device supports Bluetooth */
62         SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED,
63         SYSTEM_INFO_DATA_TYPE_BOOL,
64         system_info_get_bluetooth_supported
65 },
66
67 {
68         /**< The number of cameras in the device */
69         SYSTEM_INFO_KEY_CAMERA_COUNT,
70         SYSTEM_INFO_DATA_TYPE_INT,
71         system_info_get_camera_count
72 },
73
74 {
75         /**< Indicates whether the device supports FM radio */
76         SYSTEM_INFO_KEY_FMRADIO_SUPPORTED,
77         SYSTEM_INFO_DATA_TYPE_BOOL,
78         system_info_get_fmradio_supported
79 },
80
81 {
82         /**< Indicates whether the device supports GPS */
83         SYSTEM_INFO_KEY_GPS_SUPPORTED,
84         SYSTEM_INFO_DATA_TYPE_BOOL,
85         system_info_get_gps_supported
86 },
87
88 {
89         /**< The type of the keyboard */
90         SYSTEM_INFO_KEY_KEYBOARD_TYPE,
91         SYSTEM_INFO_DATA_TYPE_STRING,
92         system_info_get_keyboard_type
93 },
94
95 {
96         /**< The maximum number of concurrent touch points supported
97         in the device */
98         SYSTEM_INFO_KEY_MULTI_POINT_TOUCH_COUNT,
99         SYSTEM_INFO_DATA_TYPE_INT,
100         system_info_get_multi_point_touch_count
101 },
102
103 {
104         /**< The supported network type */
105         SYSTEM_INFO_KEY_NETWORK_TYPE,
106         SYSTEM_INFO_DATA_TYPE_STRING,
107         system_info_get_network_type
108 },
109
110 {
111         /**< Indicates whether the device supports NFC */
112         SYSTEM_INFO_KEY_NFC_SUPPORTED,
113         SYSTEM_INFO_DATA_TYPE_BOOL,
114         system_info_get_nfc_supported
115 },
116
117 {
118         /**< The supported version of the OpenGL ES */
119         SYSTEM_INFO_KEY_OPENGLES_VERSION,
120         SYSTEM_INFO_DATA_TYPE_STRING,
121         system_info_get_opengles_version
122 },
123
124 {
125         /**< The number of bits per pixel */
126         SYSTEM_INFO_KEY_SCREEN_BITS_PER_PIXEL,
127         SYSTEM_INFO_DATA_TYPE_INT,
128         system_info_get_screen_bits_per_pixel
129 },
130
131 {
132         /**< The height of the screen in pixels */
133         SYSTEM_INFO_KEY_SCREEN_HEIGHT,
134         SYSTEM_INFO_DATA_TYPE_INT,
135         system_info_get_screen_height
136 },
137
138 {
139         /**< The width of the screen in pixels */
140         SYSTEM_INFO_KEY_SCREEN_WIDTH,
141         SYSTEM_INFO_DATA_TYPE_INT,
142         system_info_get_screen_width
143 },
144
145 {
146         /**< Indicates whether the device supports TV-out */
147         SYSTEM_INFO_KEY_TVOUT_SUPPORTED,
148         SYSTEM_INFO_DATA_TYPE_BOOL,
149         system_info_get_tvout_supported
150 },
151
152 {
153          /**< Indicates whether the device supports Wi-Fi */
154         SYSTEM_INFO_KEY_WIFI_SUPPORTED,
155         SYSTEM_INFO_DATA_TYPE_BOOL,
156         system_info_get_wifi_supported
157 },
158
159 {
160          /**< The unique ID to identify GSM, and UMTS mobile devices */
161         SYSTEM_INFO_KEY_MOBILE_DEVICE_ID,
162         SYSTEM_INFO_DATA_TYPE_STRING,
163         system_info_get_mobile_device_id
164 },
165
166 {
167         /**< The sales code of the CSC */
168         SYSTEM_INFO_KEY_CSC_SALES_CODE,
169         SYSTEM_INFO_DATA_TYPE_STRING,
170         system_info_get_csc_sales_code
171 },
172
173 {
174         /**< The Name of the Platform */
175         SYSTEM_INFO_KEY_PLATFORM_NAME,
176         SYSTEM_INFO_DATA_TYPE_STRING,
177         system_info_get_platform_name
178 },
179
180 {
181         /**< The Name of the Tizen version */
182         SYSTEM_INFO_KEY_TIZEN_VERSION_NAME,
183         SYSTEM_INFO_DATA_TYPE_STRING,
184         system_info_get_tizen_version_name
185 },
186
187 {
188         /**< Indicates whether the device supports HAPTIC */
189         SYSTEM_INFO_KEY_HAPTIC_SUPPORTED,
190         SYSTEM_INFO_DATA_TYPE_BOOL,
191         system_info_get_haptic_supproted
192 },
193
194 {
195         /**< Indicates whether the device supports HAPTIC */
196         SYSTEM_INFO_KEY_WIFI_DIRECT_SUPPORTED,
197         SYSTEM_INFO_DATA_TYPE_BOOL,
198         system_info_get_wifi_direct_supported
199 },
200
201 {
202         /**< The height of the screen DPI */
203         SYSTEM_INFO_KEY_SCREEN_DPI,
204         SYSTEM_INFO_DATA_TYPE_INT,
205         system_info_get_screen_DPI
206 },
207
208 {
209         /**< The Device unique ID to identify */
210         SYSTEM_INFO_KEY_DEVICE_UUID,
211         SYSTEM_INFO_DATA_TYPE_STRING,
212         system_info_get_device_uuid
213 },
214
215 {
216         /**< Indicates whether the device supports GPS */
217         SYSTEM_INFO_KEY_CPS_SUPPORTED,
218         SYSTEM_INFO_DATA_TYPE_BOOL,
219         system_info_get_cps_supported
220 },
221
222 {
223         /**< Indicates whether the device supports GPS */
224         SYSTEM_INFO_KEY_WPS_SUPPORTED,
225         SYSTEM_INFO_DATA_TYPE_BOOL,
226         system_info_get_wps_supported
227 },
228
229 {
230         /**< Indicates whether the device supports USB host */
231         SYSTEM_INFO_KEY_USB_HOST_SUPPORTED,
232         SYSTEM_INFO_DATA_TYPE_BOOL,
233         system_info_get_usb_host_supported
234 },
235
236 {
237         /**< Indicates whether the device supports USB accessory */
238         SYSTEM_INFO_KEY_USB_ACCESSORY_SUPPORTED,
239         SYSTEM_INFO_DATA_TYPE_BOOL,
240         system_info_get_usb_accessory_supported
241 },
242
243 {
244         /**< The CORE CPU architecture of model */
245         SYSTEM_INFO_KEY_CORE_CPU_ARCH,
246         SYSTEM_INFO_DATA_TYPE_STRING,
247         system_info_get_core_cpu_arch
248 },
249
250 {
251         /**< The CORE FPU architecture of model */
252         SYSTEM_INFO_KEY_CORE_FPU_ARCH,
253         SYSTEM_INFO_DATA_TYPE_STRING,
254         system_info_get_core_fpu_arch
255 },
256
257 {
258         /**< Indicates whether the device supports front camera */
259         SYSTEM_INFO_KEY_FRONT_CAMERA_SUPPORTED,
260         SYSTEM_INFO_DATA_TYPE_BOOL,
261         system_info_get_front_camera_supported
262 },
263
264 {
265         /**< Indicates whether the device supports front camera auto focus */
266         SYSTEM_INFO_KEY_FRONT_CAMERA_AF_SUPPORTED,
267         SYSTEM_INFO_DATA_TYPE_BOOL,
268         system_info_get_front_camera_af_supported
269 },
270
271 {
272         /**< Indicates whether the device supports front camera flash */
273         SYSTEM_INFO_KEY_FRONT_CAMERA_FLASH_SUPPORTED,
274         SYSTEM_INFO_DATA_TYPE_BOOL,
275         system_info_get_front_camera_flash_supported
276 },
277
278 {
279         /**< Indicates whether the device supports back camera */
280         SYSTEM_INFO_KEY_BACK_CAMERA_SUPPORTED,
281         SYSTEM_INFO_DATA_TYPE_BOOL,
282         system_info_get_back_camera_supported
283 },
284
285 {
286         /**< Indicates whether the device supports back camera auto focus */
287         SYSTEM_INFO_KEY_BACK_CAMERA_AF_SUPPORTED,
288         SYSTEM_INFO_DATA_TYPE_BOOL,
289         system_info_get_back_camera_af_supported
290 },
291
292 {
293         /**< Indicates whether the device supports back camera flash */
294         SYSTEM_INFO_KEY_BACK_CAMERA_FLASH_SUPPORTED,
295         SYSTEM_INFO_DATA_TYPE_BOOL,
296         system_info_get_back_camera_flash_supported
297 },
298
299 {
300         /**< Indicates whether the device supports HDMI */
301         SYSTEM_INFO_KEY_HDMI_SUPPORTED,
302         SYSTEM_INFO_DATA_TYPE_BOOL,
303         system_info_get_hdmi_supported
304 },
305
306 {
307         /**< Indicates whether the device supports RCA */
308         SYSTEM_INFO_KEY_RCA_SUPPORTED,
309         SYSTEM_INFO_DATA_TYPE_BOOL,
310         system_info_get_rca_supported
311 },
312
313 {
314         /**< Indicates whether the device supports SIP VOIP */
315         SYSTEM_INFO_KEY_SIP_VOIP_SUPPORTED,
316         SYSTEM_INFO_DATA_TYPE_BOOL,
317         system_info_get_sip_voip_supported
318 },
319
320 {
321         /**< Indicates whether the device supports Microphone */
322         SYSTEM_INFO_KEY_MICROPHONE_SUPPORTED,
323         SYSTEM_INFO_DATA_TYPE_BOOL,
324         system_info_get_microphone_supported
325 },
326
327 {
328         /**< Indicates whether the device supports stt */
329         SYSTEM_INFO_KEY_SPEECH_RECOGNITION_SUPPORTED,
330         SYSTEM_INFO_DATA_TYPE_BOOL,
331         system_info_get_speech_recognition_supported
332 },
333
334 {
335         /**< Indicates whether the device supports barometer sensor */
336         SYSTEM_INFO_KEY_BAROMETER_SENSOR_SUPPORTED,
337         SYSTEM_INFO_DATA_TYPE_BOOL,
338         system_info_get_barometer_sensor_supported
339 },
340
341 {
342         /**< The supported texture format of the OpenGL ES */
343         SYSTEM_INFO_KEY_OPENGLES_TEXTURE_FORMAT,
344         SYSTEM_INFO_DATA_TYPE_STRING,
345         system_info_get_opengles_texture_format
346 },
347
348 {
349         /**< The CORE CPU frequency of model */
350         SYSTEM_INFO_KEY_CORE_CPU_FREQ,
351         SYSTEM_INFO_DATA_TYPE_DOUBLE,
352         system_info_get_core_cpu_freq
353 },
354
355 {
356         /**< The height of the physical screen size in millimeters */
357         SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT,
358         SYSTEM_INFO_DATA_TYPE_INT,
359         system_info_get_physical_screen_height
360 },
361
362 {
363         /**< The width of the physical screen size in millimeters */
364         SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH,
365         SYSTEM_INFO_DATA_TYPE_INT,
366         system_info_get_physical_screen_width
367 },
368
369 {
370         /**< The build string of the platform binary */
371         SYSTEM_INFO_KEY_BUILD_STRING,
372         SYSTEM_INFO_DATA_TYPE_STRING,
373         system_info_get_build_string
374 },
375
376 {
377         /**< The build date of the platform binary */
378         SYSTEM_INFO_KEY_BUILD_DATE,
379         SYSTEM_INFO_DATA_TYPE_STRING,
380         system_info_get_build_date
381 },
382
383 {
384         /**< The build time of the platform binary */
385         SYSTEM_INFO_KEY_BUILD_TIME,
386         SYSTEM_INFO_DATA_TYPE_STRING,
387         system_info_get_build_time
388 },
389
390 {
391         SYSTEM_INFO_MAX, -1, NULL
392 }
393
394 };
395
396 static system_info_mode_type_e system_info_system_info_model_type;
397 static int system_info_initialized;
398
399 int system_info_get_system_info_initialized()
400 {
401         return system_info_initialized;
402 }
403
404 void system_info_set_system_info_initialized(int value)
405 {
406         system_info_initialized = value;
407 }
408
409 system_info_mode_type_e system_info_get_system_info_model_type()
410 {
411         return system_info_system_info_model_type;
412 }
413
414 int system_info_init(void)
415 {
416         FILE *fp;
417         char str[MAXBUFSIZE];
418         extern char *strcasestr(const char *s, const char *find);
419
420         fp = popen("uname -m", "r");
421         if (NULL == fp) {
422                 LOGE("[%s] cannot execute uname command!!!", __func__);
423                 return SYSTEM_INFO_ERROR_IO_ERROR;
424         } else {
425                 while (fgets(str, MAXBUFSIZE, fp)) {
426                         if (strcasestr(str, "emulated")) {
427                                 system_info_system_info_model_type = SYSTEM_INFO_MODEL_TYPE_EMULATOR;
428                                 system_info_set_system_info_initialized(1);
429                                 pclose(fp);
430                                 return SYSTEM_INFO_ERROR_NONE;
431
432                         }
433                 }
434
435                 system_info_system_info_model_type = SYSTEM_INFO_MODEL_TYPE_TARGET;
436                 system_info_set_system_info_initialized(1);
437                 pclose(fp);
438                 return SYSTEM_INFO_ERROR_NONE;
439         }
440 }
441
442 static int system_info_get(system_info_key_e key, system_info_h *system_info)
443 {
444         int index = 0;
445         int ret_val;
446
447         if (0 == system_info_get_system_info_initialized()) {
448                 ret_val = system_info_init();
449                 if (ret_val) {
450                         LOGE("[%s] system information initialize fail!!!", __func__);
451                         return ret_val;
452                 }
453         }
454
455         while (system_info_table[index].key != SYSTEM_INFO_MAX) {
456                 if (system_info_table[index].key == key) {
457                         *system_info = &system_info_table[index];
458                         return 0;
459                 }
460
461                 index++;
462         }
463
464         return -1;
465 }
466
467 int system_info_get_value(system_info_key_e key, system_info_data_type_e data_type, void **value)
468 {
469         system_info_h system_info;
470         system_info_get_value_cb system_info_getter;
471
472         if (value == NULL) {
473                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid output param", __func__, SYSTEM_INFO_ERROR_INVALID_PARAMETER);
474                 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
475         }
476
477         if (system_info_get(key, &system_info)) {
478                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __func__, SYSTEM_INFO_ERROR_INVALID_PARAMETER);
479                 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
480         }
481
482         if (system_info->data_type != data_type) {
483                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid data type", __func__, SYSTEM_INFO_ERROR_INVALID_PARAMETER);
484                 return SYSTEM_INFO_ERROR_INVALID_PARAMETER;
485         }
486
487         system_info_getter = system_info->get_value_cb;
488
489         if (system_info_getter == NULL) {
490                 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system information", __func__, SYSTEM_INFO_ERROR_IO_ERROR);
491                 return SYSTEM_INFO_ERROR_IO_ERROR;
492         }
493
494         return system_info_getter(key, system_info->data_type, value);
495 }
496
497 int system_info_get_value_int(system_info_key_e key, int *value)
498 {
499         return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_INT, (void **)value);
500 }
501
502 int system_info_get_value_bool(system_info_key_e key, bool *value)
503 {
504         return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_BOOL, (void **)value);
505 }
506
507 int system_info_get_value_double(system_info_key_e key, double *value)
508 {
509         return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_DOUBLE, (void **)value);
510 }
511
512 int system_info_get_value_string(system_info_key_e key, char **value)
513 {
514         return system_info_get_value(key, SYSTEM_INFO_DATA_TYPE_STRING, (void **)value);
515 }