Modify the hardcorded storage path to get the download path 85/68985/1 accepted/tizen/common/20160511.142125 accepted/tizen/ivi/20160512.050827 accepted/tizen/mobile/20160512.050819 accepted/tizen/tv/20160512.050748 accepted/tizen/wearable/20160512.050806 submit/tizen/20160511.024308
authorDoHyun Pyun <dh79.pyun@samsung.com>
Wed, 11 May 2016 02:17:10 +0000 (11:17 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Wed, 11 May 2016 02:17:10 +0000 (11:17 +0900)
The previous pbap download path is hardcorded. Instead of this
uses storage API and get the platform download path. And add the
storage privilege check logic.

Change-Id: If8c5d9a8565cc5e3ba39b4284553a98b325310b8
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-service/CMakeLists.txt
bt-service/bt-request-handler.c
bt-service/bt-service-pbap.c
bt-service/include/bt-service-common.h
packaging/bluetooth-frwk.spec

index 00a3acd..5d6da03 100644 (file)
@@ -65,6 +65,7 @@ SET(PKG_MODULES
        cynara-client
        cynara-creds-gdbus
        eventsystem
+       storage
 )
 
 IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_NETWORK_TETHERING_ENABLE")
index edae569..6890ceb 100644 (file)
@@ -2586,6 +2586,13 @@ gboolean __bt_service_check_privilege(int function_name,
         case BT_GATT_SET_PROPERTY_REQUEST:
         case BT_GATT_READ_CHARACTERISTIC:
         case BT_GATT_DISCOVER_CHARACTERISTICS_DESCRIPTOR:
+               case BT_PBAP_CONNECT:
+               case BT_PBAP_DISCONNECT:
+               case BT_PBAP_GET_PHONEBOOK_SIZE:
+               case BT_PBAP_GET_PHONEBOOK:
+               case BT_PBAP_GET_LIST:
+               case BT_PBAP_PULL_VCARD:
+               case BT_PBAP_PHONEBOOK_SEARCH:
                 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
                                                                                  BT_PRIVILEGE_PUBLIC);
 
@@ -2593,6 +2600,18 @@ gboolean __bt_service_check_privilege(int function_name,
                         BT_ERR("Fail to access: %s", BT_PRIVILEGE_PUBLIC);
                         result = FALSE;
                 }
+
+                               /* Need to check mediastorage privilege */
+                               if (function_name == BT_PBAP_GET_PHONEBOOK ||
+                                        function_name == BT_PBAP_PULL_VCARD) {
+                       ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
+                                                                    MEDIASTORAGE_PRIVILEGE);
+
+                       if (ret_val != CYNARA_API_ACCESS_ALLOWED) {
+                               BT_ERR("Fail to access: %s", MEDIASTORAGE_PRIVILEGE);
+                               result = FALSE;
+                       }
+                               }
         break;
 
         case BT_ENABLE_ADAPTER:
@@ -2627,13 +2646,6 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_LE_WRITE_HOST_SUGGESTED_DATA_LENGTH:
        case BT_LE_READ_HOST_SUGGESTED_DATA_LENGTH:
        case BT_LE_SET_DATA_LENGTH:
-       case BT_PBAP_CONNECT:
-       case BT_PBAP_DISCONNECT:
-       case BT_PBAP_GET_PHONEBOOK_SIZE:
-       case BT_PBAP_GET_PHONEBOOK:
-       case BT_PBAP_GET_LIST:
-       case BT_PBAP_PULL_VCARD:
-       case BT_PBAP_PHONEBOOK_SEARCH:
                 ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds,
                                                                                  BT_PRIVILEGE_PLATFORM);
 
index c190640..9e8e3b8 100644 (file)
@@ -24,6 +24,7 @@
 #include <syspopup_caller.h>
 #endif
 #include <vconf.h>
+#include <storage.h>
 
 #include "bt-internal-types.h"
 #include "bt-service-common.h"
@@ -44,6 +45,9 @@
 #define        PBAP_NUM_OF_FIELDS_ENTRY 29
 #define        PBAP_FIELD_ALL (0xFFFFFFFFFFFFFFFFULL)
 
+#define PBAP_DEFAULT_DOWNLAOD_PATH "/opt/usr/media/Downloads"
+#define PBAP_DEFAULT_FILE_NAME "pb.vcf"
+
 char *FIELDS[] = {
                "VERSION",
                "FN",
@@ -777,15 +781,18 @@ int __bt_pbap_call_get_phonebook(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
        BT_DBG("+");
 
        int i;
+       int ret;
        char *format_str = NULL;
        char *fields_str = NULL;
        char *order_str = NULL;
-       char *target_file = "/opt/usr/media/Downloads/pb.vcf";
+       char *download_path = NULL;
+       char *target_file = NULL;
        bt_pbap_pull_parameters_t *app_param = pbap_data->app_param;
        GVariantBuilder builder;
        GVariantBuilder inner_builder;
        GVariant *filters;
 
+
        g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
        g_variant_builder_init (&inner_builder, G_VARIANT_TYPE_ARRAY);
 
@@ -842,6 +849,22 @@ int __bt_pbap_call_get_phonebook(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
 //
 //****************************
 
+       ret = storage_get_directory(STORAGE_TYPE_INTERNAL,
+                       STORAGE_DIRECTORY_DOWNLOADS, &download_path);
+
+       if (ret != STORAGE_ERROR_NONE) {
+               target_file = g_strdup_printf("%s/%s", PBAP_DEFAULT_DOWNLAOD_PATH,
+                                                       PBAP_DEFAULT_FILE_NAME);
+       } else {
+               target_file = g_strdup_printf("%s/%s", download_path,
+                                       PBAP_DEFAULT_FILE_NAME);
+
+               if (download_path)
+                       free(download_path);
+       }
+
+       DBG_SECURE("Target flie: %s", target_file);
+
        g_dbus_proxy_call(proxy, "PullAll",
                        g_variant_new("(s@a{sv})", target_file, filters),
                        G_DBUS_CALL_FLAGS_NONE, -1, NULL,
@@ -912,9 +935,11 @@ int __bt_pbap_call_get_vcard(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
        BT_DBG("+");
 
        int i;
+       int ret;
        char *format_str = NULL;
        char *fields_str = NULL;
-       char *target_file = "/opt/usr/media/Downloads/pb.vcf";
+       char *target_file = NULL;
+       char *download_path = NULL;
        char *vcard_handle = NULL;
        char vcard[10] = { 0, };
        GVariantBuilder builder;
@@ -965,6 +990,23 @@ int __bt_pbap_call_get_vcard(GDBusProxy *proxy, bt_pbap_data_t *pbap_data)
        BT_DBG("Handle: %s", vcard);
        vcard_handle = g_strdup(vcard);
        BT_DBG("vcard_handle: %s", vcard_handle);
+
+       ret = storage_get_directory(STORAGE_TYPE_INTERNAL,
+                       STORAGE_DIRECTORY_DOWNLOADS, &download_path);
+
+       if (ret != STORAGE_ERROR_NONE) {
+               target_file = g_strdup_printf("%s/%s", PBAP_DEFAULT_DOWNLAOD_PATH,
+                                                       PBAP_DEFAULT_FILE_NAME);
+       } else {
+               target_file = g_strdup_printf("%s/%s", download_path,
+                                       PBAP_DEFAULT_FILE_NAME);
+
+               if (download_path)
+                       free(download_path);
+       }
+
+       DBG_SECURE("Target flie: %s", target_file);
+
        GVariant *temp = g_variant_new("(ss@a{sv})", vcard_handle, target_file, filters);
 
        g_dbus_proxy_call(proxy, "Pull",
index 3a41e00..b01b955 100755 (executable)
@@ -226,6 +226,7 @@ extern "C" {
 /* Privilege */
 #define BT_PRIVILEGE_PUBLIC "http://tizen.org/privilege/bluetooth"
 #define BT_PRIVILEGE_PLATFORM "http://tizen.org/privilege/bluetooth.admin"
+#define MEDIASTORAGE_PRIVILEGE "http://tizen.org/privilege/mediastorage"
 
 /* BD Address type */
 #define BDADDR_BREDR           0x00
index eebefa8..c15b637 100644 (file)
@@ -56,6 +56,7 @@ BuildRequires:  cmake
 BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(cynara-creds-gdbus)
 BuildRequires:  pkgconfig(libtzplatform-config)
+BuildRequires:  pkgconfig(storage)
 
 Requires(post): /usr/bin/vconftool
 Requires(post): /sbin/ldconfig