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.
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.
35 ** This license applies to all the permissions of the below mentioned functions.
36 ** Functions: format_uuid_v3or5, uuid_create_sha1_from_name
46 #include <vconf-internal-csc-keys.h>
49 #include <system_info.h>
50 #include <system_info_private.h>
52 #include <devman_haptic.h>
54 #include <wifi-direct.h>
56 #include <X11/extensions/XI2.h>
57 #include <X11/extensions/XI2proto.h>
59 #include <X11/Xatom.h>
60 #include <X11/extensions/XInput2.h>
62 #include <openssl/sha.h>
63 #include <arpa/inet.h>
66 #include <net_nfc_typedef.h>
69 #include <location-types.h>
71 #include <bluetooth-api.h>
76 #include <sound_manager.h>
79 #define PROP_MULTITOUCH "EvdevMultitouch MultiTouch"
80 #define DEVICE_UUID_STRING_SIZE 37
86 #define LOG_TAG "TIZEN_N_SYSTEM_INFO"
88 #define CAM_INI_FILE_PATH "/usr/etc/mmfw_camcorder.ini"
89 #define CAM_VIDEO_PRI_FILE_PATH "/usr/etc/mmfw_camcorder_dev_video_pri.ini"
90 #define CAM_VIDEO_SEC_FILE_PATH "/usr/etc/mmfw_camcorder_dev_video_sec.ini"
92 static char *KEYBOARD_TYPE;
93 static char *FRONT_CAM_PATH;
94 static char *BACK_CAM_PATH;
95 static const bool TVOUT_SUPPORT = true;
96 static const bool SIP_VOIP_SUPPROT = true;
97 static const bool SPEECH_RECOGNITION_SUPPROT = true;
102 uint16_t time_hi_and_version;
103 uint8_t clock_seq_hi_and_reserved;
104 uint8_t clock_seq_low;
109 Tizen Default vender key = f7884739-3c9f-5f7c-af-e1-fc9f5da56003
110 This value should be modified by each venders.
112 _UUID_OBJECT VenderKey = {0xf7884739, 0x3c9f, 0x5f7c, 0xaf, 0xe1, {0xfc, 0x9f, 0x5d, 0xa5, 0x60, 0x3} };
114 format_uuid_v3or5 -- make a UUID from a (pseudo)random 128-bit
117 void format_uuid_v3or5(_UUID_OBJECT *uuid, unsigned char hash[16], int v)
119 /* convert UUID to local byte order */
120 memcpy(uuid, hash, sizeof(*uuid));
121 uuid->time_low = ntohl(uuid->time_low);
122 uuid->time_mid = ntohs(uuid->time_mid);
123 uuid->time_hi_and_version = ntohs(uuid->time_hi_and_version);
125 /* put in the variant and version bits */
126 uuid->time_hi_and_version &= 0x0FFF;
127 uuid->time_hi_and_version |= (v << 12);
128 uuid->clock_seq_hi_and_reserved &= 0x3F;
129 uuid->clock_seq_hi_and_reserved |= 0x80;
132 void uuid_create_sha1_from_name(_UUID_OBJECT *uuid, _UUID_OBJECT nsid, void *name, int namelen)
135 unsigned char hash[20];
136 _UUID_OBJECT net_nsid;
138 /* put name space ID in network byte order so it hashes the same
139 no matter what endian machine we're on */
141 net_nsid.time_low = htonl(net_nsid.time_low);
142 net_nsid.time_mid = htons(net_nsid.time_mid);
143 net_nsid.time_hi_and_version = htons(net_nsid.time_hi_and_version);
146 SHA1_Update(&c, &net_nsid, sizeof(net_nsid));
147 SHA1_Update(&c, name, namelen);
148 SHA1_Final(hash, &c);
150 /* the hash is in network byte order at this point */
151 format_uuid_v3or5(uuid, hash, 5);
154 int uuid_object_to_string(_UUID_OBJECT uuid, char **device_uuid_string)
156 *device_uuid_string = (char *) calloc(1, DEVICE_UUID_STRING_SIZE + 1);
158 if (*device_uuid_string == NULL)
159 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
161 snprintf(*device_uuid_string, DEVICE_UUID_STRING_SIZE, "%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
162 (unsigned long)uuid.time_low,
163 (unsigned int)uuid.time_mid,
164 (unsigned int)uuid.time_hi_and_version,
165 (unsigned int)uuid.clock_seq_hi_and_reserved,
166 (unsigned int)uuid.clock_seq_low,
167 (unsigned int)uuid.node[0],
168 (unsigned int)uuid.node[1],
169 (unsigned int)uuid.node[2],
170 (unsigned int)uuid.node[3],
171 (unsigned int)uuid.node[4],
172 (unsigned int)uuid.node[5]);
174 return SYSTEM_INFO_ERROR_NONE;
177 extern char *strcasestr(const char *s, const char *find);
179 int xinput_extension_init(Display *disp)
183 int major = XI_2_Major, minor = XI_2_Minor;
185 if (!XQueryExtension(disp, "XInputExtension", &opcode, &event, &error)) {
186 LOGE("[%s] XInput Extension isn't supported.", __func__);
187 return SYSTEM_INFO_ERROR_IO_ERROR;
190 if (XIQueryVersion(disp, &major, &minor) == BadRequest) {
191 LOGE("[%s] Failed to query XI version.", __func__);
192 return SYSTEM_INFO_ERROR_IO_ERROR;
195 if (!(major >= XI_2_Major && minor >= XI_2_Minor)) {
196 LOGE("[%s] XI2 is not supported ! (major:%d, minor:%d)", __func__, major, minor);
197 return SYSTEM_INFO_ERROR_IO_ERROR;
202 int get_device_property_value(Display *disp, int deviceid, Atom prop)
205 unsigned long nitems, bytes_after;
207 int act_format, ret = -1;
209 if (XIGetProperty(disp, deviceid, prop, 0, 1000, False,
210 XA_INTEGER, &act_type, &act_format,
211 &nitems, &bytes_after, &data) != Success) {
212 LOGE("[%s] Failed to get XI2 device property !(deviceid=%d)", __func__, deviceid);
213 return SYSTEM_INFO_ERROR_IO_ERROR;
228 int get_multitouch_max_count(Display *disp)
233 XIDeviceInfo *dev, *info = NULL;
235 int xi_opcode = xinput_extension_init(disp);
237 if (0 >= xi_opcode) {
238 LOGE("[%s] Failed to initialize X Input Extension !", __func__);
239 return SYSTEM_INFO_ERROR_IO_ERROR;
242 atomMultiTouch = XInternAtom(disp, PROP_MULTITOUCH, True);
244 if (!atomMultiTouch) {
245 LOGE("[%s] Failed to make an atom for multitouch property !", __func__);
246 return SYSTEM_INFO_ERROR_IO_ERROR;
249 info = XIQueryDevice(disp, XIAllDevices, &ndevices);
252 LOGE("[%s] Failed to query XI device.", __func__);
253 return SYSTEM_INFO_ERROR_IO_ERROR;
256 for (i = 0; i < ndevices ; i++) {
261 if (strcasestr(dev->name, "virtual") && !strcasestr(dev->name, "maru"))
263 if (strcasestr(dev->name, "extended"))
265 if (!strcasestr(dev->name, "touch"))
267 max_count = get_device_property_value(disp, dev->deviceid, atomMultiTouch);
275 XIFreeDeviceInfo(info);
280 * @brief Setting face direction path
284 void set_camera_direction_path(void)
286 char str[MAXBUFSIZE];
287 char tmpStr[MAXBUFSIZE];
291 info = fopen(CAM_VIDEO_PRI_FILE_PATH, "r");
294 while (fgets(str, MAXBUFSIZE, info)) {
295 if (!strncmp(";", str, strlen(";")))
297 else if (!strncmp("FacingDirection", str, strlen("FacingDirection"))) {
298 sscanf(str, "%s = %d", tmpStr, &direction);
299 if (direction == 1) {
300 FRONT_CAM_PATH = strdup(CAM_VIDEO_PRI_FILE_PATH);
301 BACK_CAM_PATH = strdup(CAM_VIDEO_SEC_FILE_PATH);
312 /* default setting */
313 FRONT_CAM_PATH = strdup(CAM_VIDEO_SEC_FILE_PATH);
314 BACK_CAM_PATH = strdup(CAM_VIDEO_PRI_FILE_PATH);
319 int system_info_get_bluetooth_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
323 supported = (bool *)value;
325 if (bluetooth_is_supported())
330 return SYSTEM_INFO_ERROR_NONE;
333 int system_info_get_camera_count(system_info_key_e key, system_info_data_type_e data_type, void **value)
336 char str[MAXBUFSIZE];
337 char tmpStr[MAXBUFSIZE];
340 count = (int *)value;
341 /* default camera count is 2*/
344 info = fopen(CAM_INI_FILE_PATH, "r");
346 LOGE("[%s] cannot file open %s file!!!", __func__, CAM_INI_FILE_PATH);
347 return SYSTEM_INFO_ERROR_IO_ERROR;
349 while (fgets(str, MAXBUFSIZE, info)) {
350 if (!strncmp(";", str, strlen(";")))
352 else if (!strncmp("DeviceCount", str, strlen("DeviceCount"))) {
353 sscanf(str, "%s = %d", tmpStr, count);
360 return SYSTEM_INFO_ERROR_NONE;
363 int system_info_get_fmradio_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
368 supported = (bool *)value;
370 memset(&hradio, 0x0, sizeof(MMHandleType));
372 if (MM_ERROR_NONE == mm_radio_create(&hradio))
377 mm_radio_destroy(hradio);
379 return SYSTEM_INFO_ERROR_NONE;
382 int system_info_get_gps_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
386 supported = (bool *)value;
388 if (location_is_supported_method(LOCATION_METHOD_GPS))
393 return SYSTEM_INFO_ERROR_NONE;
396 int system_info_get_cps_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
400 supported = (bool *)value;
402 if (location_is_supported_method(LOCATION_METHOD_CPS))
407 return SYSTEM_INFO_ERROR_NONE;
410 int system_info_get_wps_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
414 supported = (bool *)value;
416 if (location_is_supported_method(LOCATION_METHOD_WPS))
421 return SYSTEM_INFO_ERROR_NONE;
424 int system_info_get_keyboard_type(system_info_key_e key, system_info_data_type_e data_type, void **value)
428 if (KEYBOARD_TYPE != NULL) {
429 keyboard_type = strdup(KEYBOARD_TYPE);
431 if (keyboard_type == NULL) {
432 LOGE("[%s] OUT_OF_MEMORY(0x%08x)", __func__, SYSTEM_INFO_ERROR_OUT_OF_MEMORY);
433 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
436 *value = keyboard_type;
441 return SYSTEM_INFO_ERROR_NONE;
444 int system_info_get_multi_point_touch_count(system_info_key_e key, system_info_data_type_e data_type, void **value)
449 count = (int *)value;
451 disp = XOpenDisplay(NULL);
454 LOGE("[%s] Failed to open display!", __func__);
455 return SYSTEM_INFO_ERROR_IO_ERROR;
458 *count = get_multitouch_max_count(disp);
460 return SYSTEM_INFO_ERROR_NONE;
463 int system_info_get_nfc_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
466 int nfc_supported = 0;
468 supported = (bool *)value;
470 if (NET_NFC_OK == net_nfc_is_supported(&nfc_supported))
475 return SYSTEM_INFO_ERROR_NONE;
478 int system_info_get_tvout_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
482 supported = (bool *)value;
484 *supported = TVOUT_SUPPORT;
486 return SYSTEM_INFO_ERROR_NONE;
489 int system_info_get_wifi_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
493 supported = (bool *)value;
495 if (WIFI_ERROR_NONE == wifi_initialize())
502 return SYSTEM_INFO_ERROR_NONE;
505 int system_info_get_wifi_direct_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
509 supported = (bool *)value;
511 /* this is a temporary code by wifi-direct team request */
514 return SYSTEM_INFO_ERROR_NONE;
517 int system_info_get_haptic_supproted(system_info_key_e key, system_info_data_type_e data_type, void **value)
522 supported = (bool *)value;
524 count = device_haptic_get_device_count();
531 return SYSTEM_INFO_ERROR_NONE;
534 int system_info_get_csc_sales_code(system_info_key_e key, system_info_data_type_e data_type, void **value)
536 char *CSC_SALES_CODE;
538 CSC_SALES_CODE = (char *)value;
540 if (system_info_vconf_get_value_string(VCONFKEY_CSC_SALESCODE, &CSC_SALES_CODE))
541 return SYSTEM_INFO_ERROR_IO_ERROR;
543 return SYSTEM_INFO_ERROR_NONE;
546 int system_info_get_device_uuid(system_info_key_e key, system_info_data_type_e data_type, void **value)
550 _UUID_OBJECT device_uuid;
552 system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &imei);
555 uuid_create_sha1_from_name(&device_uuid, VenderKey, imei, strlen(imei));
557 if (uuid_object_to_string(device_uuid, &UUID))
558 return SYSTEM_INFO_ERROR_OUT_OF_MEMORY;
563 return SYSTEM_INFO_ERROR_NONE;
565 LOGE("[%s] imei is NULL!!!", __func__);
566 return SYSTEM_INFO_ERROR_IO_ERROR;
570 int system_info_get_usb_host_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
573 int usbhost_state = 0;
575 supported = (bool *)value;
577 if (vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhost_state))
582 return SYSTEM_INFO_ERROR_NONE;
585 int system_info_get_usb_accessory_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
588 int usbhost_state = 0;
590 supported = (bool *)value;
592 if (vconf_get_int(VCONFKEY_USB_ACCESSORY_STATUS, &usbhost_state))
597 return SYSTEM_INFO_ERROR_NONE;
600 int system_info_get_front_camera_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
604 supported = (bool *)value;
606 /* setting camera direction */
607 set_camera_direction_path();
609 /* There is no FacingDirection field in ini file */
610 if (!access(FRONT_CAM_PATH, R_OK))
615 /* free used memory for camera direction */
616 free(FRONT_CAM_PATH);
619 return SYSTEM_INFO_ERROR_NONE;
622 int system_info_get_front_camera_af_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
625 char str[MAXBUFSIZE];
626 char tmpStr[MAXBUFSIZE];
630 supported = (bool *)value;
631 /* default value is false */
634 /* setting camera direction */
635 set_camera_direction_path();
637 /* Return false, if there is no "/usr/etc/mmfw_camcorder_dev_video_sec.ini" file */
638 if (access(FRONT_CAM_PATH, R_OK))
639 return SYSTEM_INFO_ERROR_NONE;
641 info = fopen(FRONT_CAM_PATH, "r");
643 LOGE("[%s] cannot file open %s file!!!", __func__, FRONT_CAM_PATH);
644 return SYSTEM_INFO_ERROR_IO_ERROR;
646 while (fgets(str, MAXBUFSIZE, info)) {
647 if (!strncmp(";", str, strlen(";")))
649 else if (!strncmp("FocusMode", str, strlen("FocusMode"))) {
650 sscanf(str, "%s = %d,%d,%d,%d,%d,%d", tmpStr, &tmpInt[0], &tmpInt[1], &tmpInt[2], &tmpInt[3], &tmpInt[4], &tmpInt[5]);
651 if (tmpInt[2] != -255 || tmpInt[4] != -255)
659 /* free used memory for camera direction */
660 free(FRONT_CAM_PATH);
664 return SYSTEM_INFO_ERROR_NONE;
667 int system_info_get_front_camera_flash_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
670 char str[MAXBUFSIZE];
671 char tmpStr[MAXBUFSIZE];
676 supported = (bool *)value;
677 /* default value is false */
680 /* setting camera direction */
681 set_camera_direction_path();
683 /* Return false, if there is no "/usr/etc/mmfw_camcorder_dev_video_sec.ini" file */
684 if (access(FRONT_CAM_PATH, R_OK))
685 return SYSTEM_INFO_ERROR_NONE;
687 info = fopen(FRONT_CAM_PATH, "r");
689 LOGE("[%s] cannot file open %s file!!!", __func__, FRONT_CAM_PATH);
690 return SYSTEM_INFO_ERROR_IO_ERROR;
692 while (fgets(str, MAXBUFSIZE, info)) {
693 if (!strncmp(";", str, strlen(";")))
695 else if (!strncmp("StrobeMode", str, strlen("StrobeMode"))) {
696 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]);
697 for (i = 1; i < 8; i++) {
698 if (tmpInt[i] != -255)
707 /* free used memory for camera direction */
708 free(FRONT_CAM_PATH);
712 return SYSTEM_INFO_ERROR_NONE;
715 int system_info_get_back_camera_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
719 supported = (bool *)value;
721 /* setting camera direction */
722 set_camera_direction_path();
724 if (!access(BACK_CAM_PATH, R_OK))
729 /* free used memory for camera direction */
730 free(FRONT_CAM_PATH);
733 return SYSTEM_INFO_ERROR_NONE;
736 int system_info_get_back_camera_af_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
739 char str[MAXBUFSIZE];
740 char tmpStr[MAXBUFSIZE];
744 supported = (bool *)value;
745 /* default value is false */
748 /* setting camera direction */
749 set_camera_direction_path();
751 /* Return false, if there is no "/usr/etc/mmfw_camcorder_dev_video_pri.ini" file */
752 if (access(BACK_CAM_PATH, R_OK))
753 return SYSTEM_INFO_ERROR_NONE;
755 info = fopen(BACK_CAM_PATH, "r");
757 LOGE("[%s] cannot file open %s file!!!", __func__, BACK_CAM_PATH);
758 return SYSTEM_INFO_ERROR_IO_ERROR;
760 while (fgets(str, MAXBUFSIZE, info)) {
761 if (!strncmp(";", str, strlen(";")))
763 else if (!strncmp("FocusMode", str, strlen("FocusMode"))) {
764 sscanf(str, "%s = %d,%d,%d,%d,%d,%d", tmpStr, &tmpInt[0], &tmpInt[1], &tmpInt[2], &tmpInt[3], &tmpInt[4], &tmpInt[5]);
765 if (tmpInt[2] != -255 || tmpInt[4] != -255)
773 /* free used memory for camera direction */
774 free(FRONT_CAM_PATH);
778 return SYSTEM_INFO_ERROR_NONE;
781 int system_info_get_back_camera_flash_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
784 char str[MAXBUFSIZE];
785 char tmpStr[MAXBUFSIZE];
790 supported = (bool *)value;
791 /* default value is false */
794 /* setting camera direction */
795 set_camera_direction_path();
797 /* Return false, if there is no "/usr/etc/mmfw_camcorder_dev_video_pri.ini" file */
798 if (access(BACK_CAM_PATH, R_OK))
799 return SYSTEM_INFO_ERROR_NONE;
801 info = fopen(BACK_CAM_PATH, "r");
803 LOGE("[%s] cannot file open %s file!!!", __func__, BACK_CAM_PATH);
804 return SYSTEM_INFO_ERROR_IO_ERROR;
806 while (fgets(str, MAXBUFSIZE, info)) {
807 if (!strncmp(";", str, strlen(";")))
809 else if (!strncmp("StrobeMode", str, strlen("StrobeMode"))) {
810 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]);
811 for (i = 1; i < 8; i++) {
812 if (tmpInt[i] != -255)
821 /* free used memory for camera direction */
822 free(FRONT_CAM_PATH);
826 return SYSTEM_INFO_ERROR_NONE;
830 int system_info_get_sip_voip_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
834 supported = (bool *)value;
836 *supported = SIP_VOIP_SUPPROT;
838 return SYSTEM_INFO_ERROR_NONE;
841 int system_info_get_microphone_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
844 sound_device_in_e in;
845 sound_device_out_e out;
847 supported = (bool *)value;
849 if (SOUND_MANAGER_ERROR_NONE == sound_manager_get_active_device(&in, &out)) {
850 if (in == SOUND_DEVICE_IN_MIC)
857 return SYSTEM_INFO_ERROR_NONE;
860 int system_info_get_speech_recognition_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
864 supported = (bool *)value;
866 *supported = SPEECH_RECOGNITION_SUPPROT;
868 return SYSTEM_INFO_ERROR_NONE;
871 int system_info_get_barometer_sensor_supported(system_info_key_e key, system_info_data_type_e data_type, void **value)
875 supported = (bool *)value;
877 if (sf_is_sensor_event_available(BAROMETER_SENSOR, 0))
882 return SYSTEM_INFO_ERROR_NONE;