change xml file and way to read xml file
[framework/api/system-info.git] / src / system_info_device.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 ** Copyright (c) 1990- 1993, 1996 Open Software Foundation, Inc.
19 ** Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, Ca. &
20 ** Digital Equipment Corporation, Maynard, Mass.
21 ** Copyright (c) 1998 Microsoft.
22 ** To anyone who acknowledges that this file is provided "AS IS"
23 ** without any express or implied warranty: permission to use, copy,
24 ** modify, and distribute this file for any purpose is hereby
25 ** granted without fee, provided that the above copyright notices and
26 ** this notice appears in all source code copies, and that none of
27 ** the names of Open Software Foundation, Inc., Hewlett-Packard
28 ** Company, Microsoft, or Digital Equipment Corporation be used in
29 ** advertising or publicity pertaining to distribution of the software
30 ** without specific, written prior permission. Neither Open Software
31 ** Foundation, Inc., Hewlett-Packard Company, Microsoft, nor Digital
32 ** Equipment Corporation makes any representations about the
33 ** suitability of this software for any purpose.
34 **
35 ** This license applies to all the permissions of the below mentioned functions.
36 ** Functions: format_uuid_v3or5, uuid_create_sha1_from_name
37 */
38
39
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <stdint.h>
44
45 #include <vconf.h>
46 #include <vconf-internal-csc-keys.h>
47 #include <dlog.h>
48
49 #include <system_info.h>
50 #include <system_info_private.h>
51
52 #include <haptic.h>
53
54 #include <X11/extensions/XI2.h>
55 #include <X11/extensions/XI2proto.h>
56 #include <X11/Xlib.h>
57 #include <X11/Xatom.h>
58 #include <X11/extensions/XInput2.h>
59
60 #include <openssl/sha.h>
61 #include <arpa/inet.h>
62
63 #include <net_nfc.h>
64 #include <net_nfc_typedef.h>
65
66 #include <location.h>
67 #include <location-types.h>
68
69 #include <bluetooth-api.h>
70
71 #include <mm_radio.h>
72 #include <mm_types.h>
73
74 #include <sound_manager.h>
75 #include <sensor.h>
76
77 #define PROP_MULTITOUCH "EvdevMultitouch MultiTouch"
78 #define DEVICE_UUID_STRING_SIZE 37
79
80 #ifdef LOG_TAG
81 #undef LOG_TAG
82 #endif
83
84 #define LOG_TAG "CAPI_SYSTEM_INFO"
85
86 #define CAM_INI_FILE_PATH "/usr/etc/mmfw_camcorder.ini"
87 #define CAM_VIDEO_PRI_FILE_PATH "/usr/etc/mmfw_camcorder_dev_video_pri.ini"
88 #define CAM_VIDEO_SEC_FILE_PATH "/usr/etc/mmfw_camcorder_dev_video_sec.ini"
89
90 #define NFC_INFO_FILE_PATH "/etc/config/nfc/sysinfo-nfc-ug.xml"
91
92 static char *FRONT_CAM_PATH;
93 static char *BACK_CAM_PATH;
94
95 typedef struct {
96         uint32_t  time_low;
97         uint16_t  time_mid;
98         uint16_t  time_hi_and_version;
99         uint8_t  clock_seq_hi_and_reserved;
100         uint8_t  clock_seq_low;
101         uint8_t node[6];
102 } _UUID_OBJECT;
103
104 /*
105     Tizen Default vender key = f7884739-3c9f-5f7c-af-e1-fc9f5da56003
106      This value should be modified by each venders.
107 */
108 _UUID_OBJECT VenderKey = {0xf7884739, 0x3c9f, 0x5f7c, 0xaf, 0xe1, {0xfc, 0x9f, 0x5d, 0xa5, 0x60, 0x3} };
109 /*
110     format_uuid_v3or5 -- make a UUID from a (pseudo)random 128-bit
111     number
112 */
113 void format_uuid_v3or5(_UUID_OBJECT *uuid, unsigned char hash[16], int v)
114 {
115         /* convert UUID to local byte order */
116         memcpy(uuid, hash, sizeof(*uuid));
117         uuid->time_low = ntohl(uuid->time_low);
118         uuid->time_mid = ntohs(uuid->time_mid);
119         uuid->time_hi_and_version = ntohs(uuid->time_hi_and_version);
120
121         /* put in the variant and version bits */
122         uuid->time_hi_and_version &= 0x0FFF;
123         uuid->time_hi_and_version |= (v << 12);
124         uuid->clock_seq_hi_and_reserved &= 0x3F;
125         uuid->clock_seq_hi_and_reserved |= 0x80;
126 }
127
128 void uuid_create_sha1_from_name(_UUID_OBJECT *uuid, _UUID_OBJECT nsid, void *name, int namelen)
129 {
130         SHA_CTX c;
131         unsigned char hash[20];
132         _UUID_OBJECT net_nsid;
133
134         /* put name space ID in network byte order so it hashes the same
135            no matter what endian machine we're on */
136         net_nsid = nsid;
137         net_nsid.time_low = htonl(net_nsid.time_low);
138         net_nsid.time_mid = htons(net_nsid.time_mid);
139         net_nsid.time_hi_and_version = htons(net_nsid.time_hi_and_version);
140
141         SHA1_Init(&c);
142         SHA1_Update(&c, &net_nsid, sizeof(net_nsid));
143         SHA1_Update(&c, name, namelen);
144         SHA1_Final(hash, &c);
145
146         /* the hash is in network byte order at this point */
147         format_uuid_v3or5(uuid, hash, 5);
148 }
149
150 int uuid_object_to_string(_UUID_OBJECT uuid, char **device_uuid_string)
151 {
152         *device_uuid_string = (char *) calloc(1, DEVICE_UUID_STRING_SIZE + 1);
153
154         if (*device_uuid_string == NULL)
155                 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
156
157         snprintf(*device_uuid_string, DEVICE_UUID_STRING_SIZE, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
158                 (unsigned long)uuid.time_low,
159                 (unsigned int)uuid.time_mid,
160                 (unsigned int)uuid.time_hi_and_version,
161                 (unsigned int)uuid.clock_seq_hi_and_reserved,
162                 (unsigned int)uuid.clock_seq_low,
163                 (unsigned int)uuid.node[0],
164                 (unsigned int)uuid.node[1],
165                 (unsigned int)uuid.node[2],
166                 (unsigned int)uuid.node[3],
167                 (unsigned int)uuid.node[4],
168                 (unsigned int)uuid.node[5]);
169
170         return SYSTEM_INFO_ERROR_NONE;
171 }
172
173 extern char *strcasestr(const char *s, const char *find);
174
175 int xinput_extension_init(Display *disp)
176 {
177         int opcode;
178         int event, error;
179         int major = XI_2_Major, minor = XI_2_Minor;
180
181         if (!XQueryExtension(disp, "XInputExtension", &opcode, &event, &error)) {
182                 LOGE("XInput Extension isn't supported.");
183                 return SYSTEM_INFO_ERROR_IO_ERROR;
184         }
185
186         if (XIQueryVersion(disp, &major, &minor) == BadRequest) {
187                 LOGE("Failed to query XI version.");
188                 return SYSTEM_INFO_ERROR_IO_ERROR;
189         }
190
191         if (!(major >= XI_2_Major && minor >= XI_2_Minor)) {
192                 LOGE("XI2 is not supported ! (major:%d, minor:%d)", major, minor);
193                 return SYSTEM_INFO_ERROR_IO_ERROR;
194         }
195         return opcode;
196 }
197
198 int get_device_property_value(Display *disp, int deviceid, Atom prop)
199 {
200         Atom act_type;
201         unsigned long nitems, bytes_after;
202         unsigned char *data;
203         int act_format, ret = -1;
204
205         if (XIGetProperty(disp, deviceid, prop, 0, 1000, False,
206                                                         XA_INTEGER, &act_type, &act_format,
207                                                         &nitems, &bytes_after, &data) != Success) {
208                 LOGE("Failed to get XI2 device property !(deviceid=%d)", deviceid);
209                 return SYSTEM_INFO_ERROR_IO_ERROR;
210         }
211
212         if (!nitems)
213                 goto out;
214
215         ret = (int)*data;
216
217 out:
218         if (data)
219                 XFree(data);
220
221         return ret;
222 }
223
224 int get_multitouch_max_count(Display *disp)
225 {
226         int i;
227         int max_count;
228         int ndevices;
229         XIDeviceInfo *dev, *info = NULL;
230         Atom atomMultiTouch;
231         int xi_opcode = xinput_extension_init(disp);
232
233         if (0 >= xi_opcode) {
234                 LOGE("Failed to initialize X Input Extension !");
235                 return SYSTEM_INFO_ERROR_IO_ERROR;
236         }
237
238         atomMultiTouch = XInternAtom(disp, PROP_MULTITOUCH, True);
239
240         if (!atomMultiTouch) {
241                 LOGE("Failed to make an atom for multitouch property !");
242                 return SYSTEM_INFO_ERROR_IO_ERROR;
243         }
244
245         info = XIQueryDevice(disp, XIAllDevices, &ndevices);
246
247         if (!info) {
248                 LOGE("Failed to query XI device.");
249                 return SYSTEM_INFO_ERROR_IO_ERROR;
250         }
251
252         for (i = 0; i < ndevices ; i++) {
253                 dev = &info[i];
254
255                 switch (dev->use) {
256                 case XISlavePointer:
257                         if (strcasestr(dev->name, "virtual") && !strcasestr(dev->name, "maru"))
258                                 continue;
259                         if (strcasestr(dev->name, "extended"))
260                                 continue;
261                         if (!strcasestr(dev->name, "touch"))
262                                 continue;
263                         max_count = get_device_property_value(disp, dev->deviceid, atomMultiTouch);
264                         goto out;
265                 }
266         }
267
268         XIFreeDeviceInfo(info);
269         return -1;
270
271 out:
272         XIFreeDeviceInfo(info);
273         return max_count;
274 }
275
276 /**
277  * @brief Setting face direction path
278  *
279  */
280
281 void set_camera_direction_path(void)
282 {
283         char str[MAXBUFSIZE];
284         char tmpStr[MAXBUFSIZE];
285         int direction = -1;
286         FILE *info = NULL;
287
288         info = fopen(CAM_VIDEO_PRI_FILE_PATH, "r");
289
290         if (NULL != info) {
291                 while (fgets(str, MAXBUFSIZE, info)) {
292                         if (!strncmp(";", str, strlen(";")))
293                                 continue;
294                         else if (!strncmp("FacingDirection", str, strlen("FacingDirection"))) {
295                                 sscanf(str, "%s = %d", tmpStr, &direction);
296                                 if (direction == 1) {
297                                         FRONT_CAM_PATH = strdup(CAM_VIDEO_PRI_FILE_PATH);
298                                         BACK_CAM_PATH = strdup(CAM_VIDEO_SEC_FILE_PATH);
299                                         fclose(info);
300                                         return;
301                                 }
302                         } else
303                                 continue;
304                 }
305
306                 fclose(info);
307         }
308
309         /* default setting */
310         FRONT_CAM_PATH = strdup(CAM_VIDEO_SEC_FILE_PATH);
311         BACK_CAM_PATH = strdup(CAM_VIDEO_PRI_FILE_PATH);
312
313         return;
314 }
315
316 int system_info_get_bluetooth_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
317 {
318         bool *supported;
319
320         supported = (bool *)value;
321
322         if (bluetooth_is_supported())
323                         *supported = true;
324                 else
325                         *supported = false;
326
327         return SYSTEM_INFO_ERROR_NONE;
328 }
329
330 int system_info_get_camera_count(system_info_key_e key, system_info_data_type_e data_type, void **value)
331 {
332         int *count;
333         char str[MAXBUFSIZE];
334         char tmpStr[MAXBUFSIZE];
335         FILE *info = NULL;
336
337         count = (int *)value;
338         /* default camera count is 2*/
339         *count = 2;
340
341         info = fopen(CAM_INI_FILE_PATH, "r");
342         if (NULL == info) {
343                 LOGE("cannot file open %s file!!!", CAM_INI_FILE_PATH);
344                 return SYSTEM_INFO_ERROR_IO_ERROR;
345         } else {
346                 while (fgets(str, MAXBUFSIZE, info)) {
347                         if (!strncmp(";", str, strlen(";")))
348                                 continue;
349                         else if (!strncmp("DeviceCount", str, strlen("DeviceCount"))) {
350                                 sscanf(str, "%s = %d", tmpStr, count);
351                                 break;
352                         } else
353                                 continue;
354                 }
355         }
356         fclose(info);
357         return SYSTEM_INFO_ERROR_NONE;
358 }
359
360 int system_info_get_fmradio_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
361 {
362         bool *supported;
363         MMHandleType hradio;
364
365         supported = (bool *)value;
366
367         memset(&hradio, 0x0, sizeof(MMHandleType));
368
369         if (mm_radio_create(&hradio) == MM_ERROR_NONE) {
370                 if(mm_radio_realize(hradio) == MM_ERROR_NONE) {
371                         *supported = true;
372                         if (mm_radio_unrealize(hradio) == MM_ERROR_NONE) {
373                                 if (mm_radio_destroy(hradio) == MM_ERROR_NONE)
374                                         return SYSTEM_INFO_ERROR_NONE;
375                                 else {
376                                         LOGE("cannot destroy mm_radio handle!!!");
377                                         return SYSTEM_INFO_ERROR_IO_ERROR;
378                                 }
379                         } else {
380                                 LOGE("cannot unrealize mm_radio handle!!!");
381                                 return SYSTEM_INFO_ERROR_IO_ERROR;
382                         }
383                 } else {
384                         *supported = false;
385                         if (mm_radio_destroy(hradio) == MM_ERROR_NONE)
386                                 return SYSTEM_INFO_ERROR_NONE;
387                         else {
388                                 LOGE("cannot destroy mm_radio handle!!!");
389                                 return SYSTEM_INFO_ERROR_IO_ERROR;
390                         }
391                 }
392         } else {
393                 *supported = false;
394                 return SYSTEM_INFO_ERROR_NONE;
395         }
396 }
397
398 int system_info_get_gps_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
399 {
400         bool *supported;
401
402         supported = (bool *)value;
403
404         if (location_is_supported_method(LOCATION_METHOD_GPS))
405                 *supported = true;
406         else
407                 *supported = false;
408
409         return SYSTEM_INFO_ERROR_NONE;
410 }
411
412 int system_info_get_cps_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
413 {
414         bool *supported;
415
416         supported = (bool *)value;
417
418         if (location_is_supported_method(LOCATION_METHOD_CPS))
419                 *supported = true;
420         else
421                 *supported = false;
422
423         return SYSTEM_INFO_ERROR_NONE;
424 }
425
426 int system_info_get_wps_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
427 {
428         bool *supported;
429
430         supported = (bool *)value;
431
432         if (location_is_supported_method(LOCATION_METHOD_WPS))
433                 *supported = true;
434         else
435                 *supported = false;
436
437         return SYSTEM_INFO_ERROR_NONE;
438 }
439
440 int system_info_get_keyboard_type(system_info_key_e key, system_info_data_type_e data_type, void **value)
441 {
442         char *string = NULL;
443         char *model = "default";
444
445         if (system_info_get_value_from_xml(XML_FILE_PATH, model, "Keyboad_type", &string)) {
446                 LOGE("cannot get Keyboad_type info from %s!!!", XML_FILE_PATH);
447                 return SYSTEM_INFO_ERROR_IO_ERROR;
448         }
449
450         *value = string;
451
452         return SYSTEM_INFO_ERROR_NONE;
453 }
454
455 int system_info_get_multi_point_touch_count(system_info_key_e key, system_info_data_type_e data_type, void **value)
456 {
457         int *count;
458         Display *disp;
459
460         count = (int *)value;
461
462         disp = XOpenDisplay(NULL);
463
464         if (!disp) {
465                 LOGE("Failed to open display!");
466                 return SYSTEM_INFO_ERROR_IO_ERROR;
467         }
468
469         *count = get_multitouch_max_count(disp);
470
471         return SYSTEM_INFO_ERROR_NONE;
472 }
473
474 int system_info_get_nfc_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
475 {
476         bool *supported;
477         int nfc_supported = 0;
478
479         supported = (bool *)value;
480
481         if (NET_NFC_OK == net_nfc_is_supported(&nfc_supported))
482                 *supported = true;
483         else
484                 *supported = false;
485
486         return SYSTEM_INFO_ERROR_NONE;
487 }
488
489 int system_info_get_tvout_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
490 {
491         bool *supported;
492         char *string = NULL;
493         char *model = "default";
494
495         supported = (bool *)value;
496
497         if (system_info_get_value_from_xml(XML_FILE_PATH, model, "tv_out_support", &string)) {
498                 LOGE("cannot get tv_out_support info from %s!!!", NFC_INFO_FILE_PATH);
499                 return SYSTEM_INFO_ERROR_IO_ERROR;
500         }
501
502         if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
503                 *supported = true;
504         else
505                 *supported = false;
506
507         free(string);
508
509         return SYSTEM_INFO_ERROR_NONE;
510 }
511
512 int system_info_get_wifi_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
513 {
514         bool *supported;
515         char *string = NULL;
516         char *model = "default";
517
518         supported = (bool *)value;
519
520         if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
521         *supported = false;
522         return SYSTEM_INFO_ERROR_NONE;
523         }
524
525         if (system_info_get_value_from_xml(XML_FILE_PATH, model, "wifi_support", &string)) {
526                 LOGE("cannot get wifi_support info from %s!!!", NFC_INFO_FILE_PATH);
527                 return SYSTEM_INFO_ERROR_IO_ERROR;
528         }
529
530         if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
531                 *supported = true;
532         else
533                 *supported = false;
534
535         free(string);
536
537         return SYSTEM_INFO_ERROR_NONE;
538 }
539
540 int system_info_get_wifi_direct_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
541 {
542         bool *supported;
543         char *string = NULL;
544         char *model = "default";
545
546         supported = (bool *)value;
547
548         if (system_info_get_system_info_model_type() == SYSTEM_INFO_MODEL_TYPE_EMULATOR) {
549                 *supported = false;
550                 return SYSTEM_INFO_ERROR_NONE;
551         }
552
553         if (system_info_get_value_from_xml(XML_FILE_PATH, model, "wifi_direct_support", &string)) {
554                 LOGE("cannot get wifi_direct_support info from %s!!!", NFC_INFO_FILE_PATH);
555                 return SYSTEM_INFO_ERROR_IO_ERROR;
556         }
557
558         if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
559                 *supported = true;
560         else
561                 *supported = false;
562
563         free(string);
564
565         return SYSTEM_INFO_ERROR_NONE;
566 }
567
568 int system_info_get_haptic_supproted(system_info_key_e key, system_info_data_type_e data_type, void **value)
569 {
570         bool *supported;
571         int count;
572         int retVal;
573
574         supported = (bool *)value;
575
576         retVal = haptic_get_count(&count);
577         if (retVal < 0)
578                 return SYSTEM_INFO_ERROR_IO_ERROR;
579
580         if (count <= 0)
581                 *supported = false;
582         else
583                 *supported = true;
584
585         return SYSTEM_INFO_ERROR_NONE;
586 }
587
588 int system_info_get_csc_sales_code(system_info_key_e key, system_info_data_type_e data_type, void **value)
589 {
590         char *CSC_SALES_CODE;
591
592         CSC_SALES_CODE = (char *)value;
593
594         if (system_info_vconf_get_value_string(VCONFKEY_CSC_SALESCODE, &CSC_SALES_CODE))
595                 return SYSTEM_INFO_ERROR_IO_ERROR;
596
597         return SYSTEM_INFO_ERROR_NONE;
598 }
599
600 int system_info_get_device_uuid(system_info_key_e key, system_info_data_type_e data_type, void **value)
601 {
602         char *imei = NULL;
603         char *UUID;
604         _UUID_OBJECT device_uuid;
605         int retVal;
606
607         retVal = system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &imei);
608         if (SYSTEM_INFO_ERROR_NONE != retVal) {
609                 LOGE("cannot get an IMEI value!!!");
610                 return retVal;
611         }
612
613         if (imei) {
614                 uuid_create_sha1_from_name(&device_uuid, VenderKey, imei, strlen(imei));
615
616                 if (uuid_object_to_string(device_uuid, &UUID))
617                         return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
618
619                 *value = UUID;
620
621                 free(imei);
622                 return SYSTEM_INFO_ERROR_NONE;
623         } else {
624                 LOGE("imei is NULL!!!");
625                 return SYSTEM_INFO_ERROR_IO_ERROR;
626         }
627 }
628
629 int system_info_get_usb_host_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
630 {
631         bool *supported;
632         int usbhost_state = 0;
633
634         supported = (bool *)value;
635
636         if (vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhost_state))
637                 *supported = false;
638         else
639                 *supported = true;
640
641         return SYSTEM_INFO_ERROR_NONE;
642 }
643
644 int system_info_get_usb_accessory_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
645 {
646         bool *supported;
647         int usbhost_state = 0;
648
649         supported = (bool *)value;
650
651         if (vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &usbhost_state))
652                 *supported = false;
653         else
654                 *supported = true;
655
656         return SYSTEM_INFO_ERROR_NONE;
657 }
658
659 int system_info_get_front_camera_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
660 {
661         bool *supported;
662
663         supported = (bool *)value;
664
665         /* setting camera direction */
666         set_camera_direction_path();
667
668         /* There is no FacingDirection field in ini file */
669         if (!access(FRONT_CAM_PATH, R_OK))
670                 *supported = true;
671         else
672                 *supported = false;
673
674         /* free used memory for camera direction */
675         free(FRONT_CAM_PATH);
676         free(BACK_CAM_PATH);
677
678         return SYSTEM_INFO_ERROR_NONE;
679 }
680
681 int system_info_get_front_camera_af_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
682 {
683         bool *supported;
684         char str[MAXBUFSIZE];
685         char tmpStr[MAXBUFSIZE];
686         int tmpInt[6];
687         FILE *info = NULL;
688
689         supported = (bool *)value;
690         /* default value is false */
691         *supported = false;
692
693         /* setting camera direction */
694         set_camera_direction_path();
695
696         /* Return false, if there is no "/usr/etc/mmfw_camcorder_dev_video_sec.ini" file */
697         if (access(FRONT_CAM_PATH, R_OK))
698                 return SYSTEM_INFO_ERROR_NONE;
699
700         info = fopen(FRONT_CAM_PATH, "r");
701         if (NULL == info) {
702                 LOGE("cannot file open %s file!!!", FRONT_CAM_PATH);
703                 return SYSTEM_INFO_ERROR_IO_ERROR;
704         } else {
705                 while (fgets(str, MAXBUFSIZE, info)) {
706                         if (!strncmp(";", str, strlen(";")))
707                                 continue;
708                         else if (!strncmp("FocusMode", str, strlen("FocusMode"))) {
709                                 sscanf(str, "%s = %d,%d,%d,%d,%d,%d", tmpStr, &tmpInt[0], &tmpInt[1], &tmpInt[2], &tmpInt[3], &tmpInt[4], &tmpInt[5]);
710                                 if (tmpInt[2] != -255 || tmpInt[4] != -255)
711                                         *supported = true;
712                                 break;
713                         } else
714                                 continue;
715                 }
716         }
717
718         /* free used memory for camera direction */
719         free(FRONT_CAM_PATH);
720         free(BACK_CAM_PATH);
721
722         fclose(info);
723         return SYSTEM_INFO_ERROR_NONE;
724 }
725
726 int system_info_get_front_camera_flash_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
727 {
728         bool *supported;
729         char str[MAXBUFSIZE];
730         char tmpStr[MAXBUFSIZE];
731         int tmpInt[8];
732         int i = 0;
733         FILE *info = NULL;
734
735         supported = (bool *)value;
736         /* default value is false */
737         *supported = false;
738
739         /* setting camera direction */
740         set_camera_direction_path();
741
742         /* Return false, if there is no "/usr/etc/mmfw_camcorder_dev_video_sec.ini" file */
743         if (access(FRONT_CAM_PATH, R_OK))
744                 return SYSTEM_INFO_ERROR_NONE;
745
746         info = fopen(FRONT_CAM_PATH, "r");
747         if (NULL == info) {
748                 LOGE("cannot file open %s file!!!", FRONT_CAM_PATH);
749                 return SYSTEM_INFO_ERROR_IO_ERROR;
750         } else {
751                 while (fgets(str, MAXBUFSIZE, info)) {
752                         if (!strncmp(";", str, strlen(";")))
753                                 continue;
754                         else if (!strncmp("StrobeMode", str, strlen("StrobeMode"))) {
755                                 sscanf(str, "%s = %d,%d,%d,%d,%d,%d,%d,%d", tmpStr, &tmpInt[0], &tmpInt[1], &tmpInt[2], &tmpInt[3], &tmpInt[4], &tmpInt[5], &tmpInt[6], &tmpInt[7]);
756                                 for (i = 1; i < 8; i++) {
757                                         if (tmpInt[i] != -255)
758                                                 *supported = true;
759                                 }
760                                 break;
761                         } else
762                                 continue;
763                 }
764         }
765
766         /* free used memory for camera direction */
767         free(FRONT_CAM_PATH);
768         free(BACK_CAM_PATH);
769
770         fclose(info);
771         return SYSTEM_INFO_ERROR_NONE;
772 }
773
774 int system_info_get_back_camera_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
775 {
776         bool *supported;
777
778         supported = (bool *)value;
779
780         /* setting camera direction */
781         set_camera_direction_path();
782
783         if (!access(BACK_CAM_PATH, R_OK))
784                 *supported = true;
785         else
786                 *supported = false;
787
788         /* free used memory for camera direction */
789         free(FRONT_CAM_PATH);
790         free(BACK_CAM_PATH);
791
792         return SYSTEM_INFO_ERROR_NONE;
793 }
794
795 int system_info_get_back_camera_af_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
796 {
797         bool *supported;
798         char str[MAXBUFSIZE];
799         char tmpStr[MAXBUFSIZE];
800         int tmpInt[6];
801         FILE *info = NULL;
802
803         supported = (bool *)value;
804         /* default value is false */
805         *supported = false;
806
807         /* setting camera direction */
808         set_camera_direction_path();
809
810         /* Return false, if there is no "/usr/etc/mmfw_camcorder_dev_video_pri.ini" file */
811         if (access(BACK_CAM_PATH, R_OK))
812                 return SYSTEM_INFO_ERROR_NONE;
813
814         info = fopen(BACK_CAM_PATH, "r");
815         if (NULL == info) {
816                 LOGE("cannot file open %s file!!!", BACK_CAM_PATH);
817                 return SYSTEM_INFO_ERROR_IO_ERROR;
818         } else {
819                 while (fgets(str, MAXBUFSIZE, info)) {
820                         if (!strncmp(";", str, strlen(";")))
821                                 continue;
822                         else if (!strncmp("FocusMode", str, strlen("FocusMode"))) {
823                                 sscanf(str, "%s = %d,%d,%d,%d,%d,%d", tmpStr, &tmpInt[0], &tmpInt[1], &tmpInt[2], &tmpInt[3], &tmpInt[4], &tmpInt[5]);
824                                 if (tmpInt[2] != -255 || tmpInt[4] != -255)
825                                         *supported = true;
826                                 break;
827                         } else
828                                 continue;
829                 }
830         }
831
832         /* free used memory for camera direction */
833         free(FRONT_CAM_PATH);
834         free(BACK_CAM_PATH);
835
836         fclose(info);
837         return SYSTEM_INFO_ERROR_NONE;
838 }
839
840 int system_info_get_back_camera_flash_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
841 {
842         bool *supported;
843         char str[MAXBUFSIZE];
844         char tmpStr[MAXBUFSIZE];
845         int tmpInt[8];
846         int i = 0;
847         FILE *info = NULL;
848
849         supported = (bool *)value;
850         /* default value is false */
851         *supported = false;
852
853         /* setting camera direction */
854         set_camera_direction_path();
855
856         /* Return false, if there is no "/usr/etc/mmfw_camcorder_dev_video_pri.ini" file */
857         if (access(BACK_CAM_PATH, R_OK))
858                 return SYSTEM_INFO_ERROR_NONE;
859
860         info = fopen(BACK_CAM_PATH, "r");
861         if (NULL == info) {
862                 LOGE("cannot file open %s file!!!", BACK_CAM_PATH);
863                 return SYSTEM_INFO_ERROR_IO_ERROR;
864         } else {
865                 while (fgets(str, MAXBUFSIZE, info)) {
866                         if (!strncmp(";", str, strlen(";")))
867                                 continue;
868                         else if (!strncmp("StrobeMode", str, strlen("StrobeMode"))) {
869                                 sscanf(str, "%s = %d,%d,%d,%d,%d,%d,%d,%d", tmpStr, &tmpInt[0], &tmpInt[1], &tmpInt[2], &tmpInt[3], &tmpInt[4], &tmpInt[5], &tmpInt[6], &tmpInt[7]);
870                                 for (i = 1; i < 8; i++) {
871                                         if (tmpInt[i] != -255)
872                                                 *supported = true;
873                                 }
874                                 break;
875                         } else
876                                 continue;
877                 }
878         }
879
880         /* free used memory for camera direction */
881         free(FRONT_CAM_PATH);
882         free(BACK_CAM_PATH);
883
884         fclose(info);
885         return SYSTEM_INFO_ERROR_NONE;
886 }
887
888
889 int system_info_get_sip_voip_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
890 {
891         bool *supported;
892         char *string = NULL;
893         char *model = "default";
894
895         supported = (bool *)value;
896
897         if (system_info_get_value_from_xml(XML_FILE_PATH, model, "sip_voip_support", &string)) {
898                 LOGE("cannot get sip_voip_support info from %s!!!", NFC_INFO_FILE_PATH);
899                 return SYSTEM_INFO_ERROR_IO_ERROR;
900         }
901
902         if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
903                 *supported = true;
904         else
905                 *supported = false;
906
907         free(string);
908
909         return SYSTEM_INFO_ERROR_NONE;
910 }
911
912 int system_info_get_microphone_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
913 {
914         bool *supported;
915         sound_device_in_e in;
916         sound_device_out_e out;
917
918         supported = (bool *)value;
919
920         if (SOUND_MANAGER_ERROR_NONE == sound_manager_get_active_device(&in, &out)) {
921                 if (in == SOUND_DEVICE_IN_MIC)
922                         *supported = true;
923                 else
924                         *supported = false;
925         } else
926                 *supported = false;
927
928         return SYSTEM_INFO_ERROR_NONE;
929 }
930
931 int system_info_get_speech_recognition_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
932 {
933         bool *supported;
934         char *string = NULL;
935         char *model = "default";
936
937         supported = (bool *)value;
938
939         if (system_info_get_value_from_xml(XML_FILE_PATH, model, "speech_recognition_support", &string)) {
940                 LOGE("cannot get speech_recognition_support info from %s!!!", NFC_INFO_FILE_PATH);
941                 return SYSTEM_INFO_ERROR_IO_ERROR;
942         }
943
944         if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
945                 *supported = true;
946         else
947                 *supported = false;
948
949         free(string);
950
951         return SYSTEM_INFO_ERROR_NONE;
952 }
953
954 int system_info_get_barometer_sensor_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
955 {
956         bool *supported;
957
958         supported = (bool *)value;
959
960         if (sf_is_sensor_event_available(BAROMETER_SENSOR, 0))
961                 *supported = false;
962         else
963                 *supported = true;
964
965         return SYSTEM_INFO_ERROR_NONE;
966 }
967
968 int system_info_get_manufacturer(system_info_key_e key, system_info_data_type_e data_type, void **value)
969 {
970         char *string = NULL;
971         char *model = "default";
972
973         if (system_info_get_value_from_xml(XML_FILE_PATH, model, "MANUFACTURER", &string)) {
974                 LOGE("cannot get MANUFACTURER info from %s!!!", XML_FILE_PATH);
975                 return SYSTEM_INFO_ERROR_IO_ERROR;
976         }
977
978                                 *value = string;
979
980         return SYSTEM_INFO_ERROR_NONE;
981 }
982
983 int system_info_get_cp_interface(system_info_key_e key, system_info_data_type_e data_type, void **value)
984 {
985         char *string = NULL;
986         char *model = "default";
987
988         if (system_info_get_value_from_xml(XML_FILE_PATH, model, "CP_Interface", &string)) {
989                 LOGE("cannot get CP_Interface info from %s!!!", XML_FILE_PATH);
990                 return SYSTEM_INFO_ERROR_IO_ERROR;
991         }
992
993                                 *value = string;
994
995         return SYSTEM_INFO_ERROR_NONE;
996 }
997
998 int system_info_get_nfc_reserved_push_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
999 {
1000         bool *supported;
1001         char *string = NULL;
1002         char *model = "default";
1003
1004         supported = (bool *)value;
1005
1006         if (access(NFC_INFO_FILE_PATH, R_OK)) {
1007                 *supported = false;
1008                 return SYSTEM_INFO_ERROR_NONE;
1009         }
1010
1011         if (system_info_get_value_from_xml(NFC_INFO_FILE_PATH, model, "reserved-push-support", &string)) {
1012                 LOGE("cannot get reserved-push-support info from %s!!!", NFC_INFO_FILE_PATH);
1013                 return SYSTEM_INFO_ERROR_IO_ERROR;
1014         }
1015
1016         if (!strcmp(string, "true") || !strcmp(string, "TRUE"))
1017                 *supported = true;
1018         else
1019                 *supported = false;
1020
1021         free(string);
1022
1023         return SYSTEM_INFO_ERROR_NONE;
1024 }