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