Fix the svace issue (172902, 183416)
[apps/native/ug-bluetooth-efl.git] / common / src / libraries / bt-util.c
index f3cd598..420660d 100644 (file)
@@ -7,7 +7,7 @@
 *           GirishAshok Joshi <girish.joshi@samsung.com>
 *           DoHyun Pyun <dh79.pyun@samsung.com>
 *
-* Licensed under the Flora License, Version 1.0 (the "License");
+* Licensed under the Flora License, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 #include <aul.h>
 #include <notification.h>
 #include <dpm/restriction.h>
-#ifndef TIZEN_PROFILE_TV
+
+// #ifndef TIZEN_PROFILE_TV
 #include <contacts.h>
 #include <dirent.h>
 #include <fcntl.h>
-#endif
+// #endif
+
+#include <stdlib.h>
+#include <system_info.h>
 
 #include "bt-main-ug.h"
 #include "bt-util.h"
@@ -313,13 +317,12 @@ gboolean _bt_util_is_battery_low(void)
 {
        FN_START;
 
-#ifdef TIZEN_COMMON
-       return FALSE;
-#endif
-
        int value = 0;
        int charging = 0;
 
+       if (TIZEN_COMMON)
+               return FALSE;
+
        if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, (void *)&charging))
                BT_ERR("Get the battery charging status fail");
 
@@ -507,17 +510,20 @@ gboolean _bt_util_is_profile_connected(int connected_type, unsigned char *addr)
        case BT_HID_CONNECTED:
                profile = BT_PROFILE_HID;
                break;
-#ifdef TIZEN_FEATURE_BT_HOG
        case BT_LE_HID_CONNECTED:
-               profile = BT_PROFILE_GATT;
-               break;
-#endif
+               if (TIZEN_FEATURE_BT_HOG) {
+                       profile = BT_PROFILE_GATT;
+                       break;
+               } else {
+                       goto _default_;
+               }
        case BT_NETWORK_CONNECTED:
                profile = BT_PROFILE_NAP;
                break;
        case BT_NETWORK_SERVER_CONNECTED:
                profile = BT_PROFILE_NAP_SERVER;
                break;
+_default_:
        default:
                BT_ERR("Unknown type!");
                return FALSE;
@@ -686,16 +692,14 @@ int _bt_util_check_any_profile_connected(bt_dev_t *dev)
                        goto done;
        }
 
-#ifdef TIZEN_FEATURE_BT_HOG
        /* TODO : other GATT device scenario should be considered.
           In this case, only HOG device scenario is considered. */
-       if (dev->is_le_device) {
+       if (TIZEN_FEATURE_BT_HOG && dev->is_le_device) {
                connected = _bt_util_is_profile_connected(BT_LE_HID_CONNECTED,
                                dev->bd_addr);
                if (connected)
                        goto done;
        }
-#endif
 
        FN_END;
 done:
@@ -787,7 +791,7 @@ void _bt_util_destroy_dpm_context(void *ug_data)
 
        ugd = (bt_ug_data *)ug_data;
 
-       ret = dpm_context_remove_policy_changed_cb(ugd->dpm_handle, ugd->dpm_callback_id);
+       ret = dpm_remove_policy_changed_cb(ugd->dpm_handle, ugd->dpm_callback_id);
        if (ret != DPM_ERROR_NONE)
                BT_ERR("Fail to remove callback [%d]", ret);
 
@@ -823,7 +827,6 @@ gboolean _bt_util_is_dpm_restricted(void *handle)
        return (dpm_state == 0) ? TRUE : FALSE;
 }
 
-#ifndef TIZEN_PROFILE_TV
 static bool __bt_util_file_exists(const char *file)
 {
        bool res = false;
@@ -885,7 +888,7 @@ static bool __bt_util_write_vcard_to_file(int fd, contacts_record_h record, bool
                }
 
                size_left = strlen(vcard_buff);
-               while (size_left) {
+               while (size_left > 0) {
                        int written = write(fd, vcard_buff, size_left);
                        if (written == -1) {
                                BT_ERR("write() failed: %d", errno);
@@ -939,6 +942,9 @@ char *_bt_util_vcard_create_from_id(int id, bool my_profile, const char *working
        bool ok = false;
        int ret;
 
+       if (TIZEN_PROFILE_TV)
+               return 0;
+
        BT_DBG("id = %i my_profile = %d", id, my_profile);
 
        ret = contacts_connect();
@@ -962,6 +968,8 @@ char *_bt_util_vcard_create_from_id(int id, bool my_profile, const char *working
                else
                        contacts_record_get_str_p(record, _contacts_person.display_name, &display_name);
 
+               (void) display_name; /* Ignore unused variable for dummy contacts.h */
+
                vcard_path = __bt_util_make_vcard_file_path(working_dir, "Contact");
                if (!vcard_path) {
                        BT_ERR("_make_vcard_file_path() failed");
@@ -1014,6 +1022,9 @@ char *_bt_util_vcard_create_from_id_list(const int *id_list, int count, const ch
        bool ok = false;
        int ret;
 
+       if (TIZEN_PROFILE_TV)
+               return 0;
+
        if (!id_list || count <= 0)
                return NULL;
 
@@ -1065,4 +1076,37 @@ char *_bt_util_vcard_create_from_id_list(const int *id_list, int count, const ch
 
        return vcard_path;
 }
-#endif
+
+tizen_profile_t _get_tizen_profile()
+{
+       static tizen_profile_t profile = _PROFILE_UNKNOWN;
+       char *profileName;
+
+       if (__builtin_expect(profile != _PROFILE_UNKNOWN, 1))
+               return profile;
+
+       system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+       switch (*profileName) {
+               case 'm':
+               case 'M':
+                       profile = _PROFILE_MOBILE;
+                       break;
+               case 'w':
+               case 'W':
+                       profile = _PROFILE_WEARABLE;
+                       break;
+               case 't':
+               case 'T':
+                       profile = _PROFILE_TV;
+                       break;
+               case 'i':
+               case 'I':
+                       profile = _PROFILE_IVI;
+                       break;
+               default: // common or unknown ==> ALL ARE COMMON.
+                       profile = _PROFILE_COMMON;
+       }
+       free(profileName);
+
+       return profile;
+}