[OTP] Handle Object Execute request 36/134936/2
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Tue, 20 Jun 2017 10:03:22 +0000 (15:33 +0530)
committerGowtham Anandha Babu <gowtham.ab@samsung.com>
Thu, 22 Jun 2017 07:11:06 +0000 (12:41 +0530)
Change-Id: I670c9ccd884b71236cfeea38ed3ac1cf21c02f02
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
bt-otp/CMakeLists.txt
bt-otp/bt-otpserver.c
bt-otp/bt-otpserver.h
packaging/bluetooth-frwk.spec
plugin/CMakeLists.txt
plugin/headed.c

index 1b72c55..599dfd6 100644 (file)
@@ -37,7 +37,7 @@ FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${otp_pkgs_LDFLAGS} -L${CMAKE_CURRENT_SOURCE_DIR}/../bt-api -lbluetooth-api)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${otp_pkgs_LDFLAGS} -L${CMAKE_CURRENT_SOURCE_DIR}/../bt-api -lbluetooth-api -ldl)
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.projectx.otp.service DESTINATION share/dbus-1/system-services)
index 2e88aa6..5361c71 100644 (file)
@@ -27,6 +27,7 @@
 #include <inttypes.h>
 #include <errno.h>
 #include <gio/gunixfdlist.h>
+#include <dlfcn.h>
 
 #include "bt-otpserver.h"
 #include "bluetooth-api.h"
@@ -297,7 +298,7 @@ int _bt_otp_prepare_ots(void)
        char *desc_uuid;
        bt_gatt_characteristic_property_t props;
        bt_gatt_permission_t perms;
-       char supp_feat[OTP_FEATURE_LENGTH] = { 0x8C, 0x00, 0x00, 0x00,
+       char supp_feat[OTP_FEATURE_LENGTH] = { 0x9C, 0x00, 0x00, 0x00,
                                                0x80, 0x00, 0x00, 0x00 };
 
        ret = bluetooth_gatt_init();
@@ -685,7 +686,7 @@ static void _bt_otp_method(GDBusConnection *connection,
                GDir *dir = NULL;
                GError *error = NULL;
                const gchar *filename = NULL;
-               char absolute_path[ABSOLUTE_PATH_MAX_LENGTH];
+               char absolute_path[BT_FILE_PATH_MAX_LEN];
                GSList *list = NULL, *l = NULL;
                struct stat st;
                struct object_metadata *object = NULL;
@@ -738,7 +739,7 @@ static void _bt_otp_method(GDBusConnection *connection,
                        object->curr_size = (uint32_t) st.st_size;
                        object->alloc_size = (uint32_t) st.st_size;
                        object->id = object_id;
-                       object->props = OBJECT_READ;
+                       object->props = OBJECT_READ | OBJECT_WRITE | OBJECT_EXECUTE;
 
                        otp_object_list = g_slist_append(otp_object_list,
                                                                object);
@@ -1072,6 +1073,43 @@ static void _bt_otp_free_oacp_op()
        }
 }
 
+int _bt_otp_send_launch_request(char *absolute_path)
+{
+       void *handle;
+       char *error;
+       int ret;
+
+       /* check ARCH 64 or 32*/
+       if (!access(FILEPATH_ARCH_64, 0)) {
+               BT_INFO("plugin loading for ARCH 64");
+               handle = dlopen(HEADED_PLUGIN_FILEPATH64, RTLD_NOW);
+       } else {
+               BT_INFO("plugin loading for ARCH 32");
+               handle = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
+       }
+
+       if (!handle) {
+               BT_ERR("Can not load plugin %s", dlerror());
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       dlerror();      /* Clear any existing error */
+
+       int (*fun)(char *) = (int (*)(char *))dlsym(handle,
+                                       "bt_app_control_send_launch_request");
+
+       if ((error = dlerror()) != NULL)  {
+               BT_ERR("Can not load symbol : %s", dlerror());
+               dlclose(handle);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       ret = fun(absolute_path);
+       dlclose(handle);
+
+       return ret;
+}
+
 int _bt_otp_oacp_write_cb(char *value, int len, int offset,
                                                        char *remote_addr, struct indicate_info *info)
 {
@@ -1081,6 +1119,7 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
        uint32_t object_offset, length, object_size;
        uint8_t mode = 0;
        char *uuid;
+       char absolute_path[BT_FILE_PATH_MAX_LEN] = {0, };
 
        BT_INFO("OACP Opcode 0x%d", opcode);
 
@@ -1122,7 +1161,22 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
                ret = OACP_OPCODE_NOT_SUPPORTED;
                break;
        case OACP_EXECUTE:
-               ret = OACP_OPCODE_NOT_SUPPORTED;
+               if (!selected_object) {
+                       BT_DBG("Object not selected");
+                       ret = OACP_OPERATION_FAILED;
+                       goto fail;
+               }
+
+               snprintf(absolute_path, sizeof(absolute_path), "file://%s%s", directory,
+                                                       selected_object->name);
+
+               BT_DBG("absolute_path = [%s]", absolute_path);
+
+               app_err = _bt_otp_send_launch_request(absolute_path);
+               if (app_err == BLUETOOTH_ERROR_NONE)
+                       ret = OACP_SUCCESS;
+               else
+                       ret = OACP_OPERATION_FAILED;
                break;
        case OACP_READ:
        case OACP_WRITE:
index 6b10630..365f13a 100755 (executable)
 
 #define BT_OTC_INTERFACE_NAME  "org.projectx.otc_channel"
 
+#define HEADED_PLUGIN_FILEPATH "/usr/lib/bt-plugin-headed.so"
+#define HEADED_PLUGIN_FILEPATH64 "/usr/lib64/bt-plugin-headed.so"
+#define FILEPATH_ARCH_64 "/usr/lib64"
+
 #define BT_FILE_PATH_MAX_LEN 262
 #define BT_L2CAP_BUFFER_LEN 672
 
@@ -71,7 +75,6 @@
 
 /* Object Metadata Length */
 #define OTP_FEATURE_LENGTH             8
-#define ABSOLUTE_PATH_MAX_LENGTH       200
 
 /* Object ID range defined by SIG. */
 #define OBJECT_START_ID        256
index 00b16d0..7bc2f59 100644 (file)
@@ -40,6 +40,7 @@ BuildRequires:  pkgconfig(cynara-creds-gdbus)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(capi-appfw-app-control)
 
 Requires(post): /usr/bin/vconftool
 Requires(post): /sbin/ldconfig
index d46b329..31469ff 100755 (executable)
@@ -22,6 +22,7 @@ PKG_CHECK_MODULES(pkgs_headed REQUIRED
        capi-system-info
        capi-network-tethering
        capi-content-mime-type
+       capi-appfw-app-control
        )
 
 FOREACH(flag ${pkgs_headed_CFLAGS})
index ea00b61..8ed7698 100644 (file)
@@ -24,6 +24,7 @@
 #include <bundle_internal.h>
 #include <tethering.h>
 #include <mime_type.h>
+#include <app_control.h>
 
 #include "plugin.h"
 #include "bluetooth-api.h"
@@ -290,6 +291,27 @@ void bt_destroy_popup_all(void)
        syspopup_destroy_all();
 }
 
+int bt_app_control_send_launch_request(char *absolute_path)
+{
+       BT_DBG("+");
+
+       app_control_h app_control;
+       int ret;
+
+       app_control_create(&app_control);
+       app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
+       app_control_set_uri(app_control, absolute_path);
+       app_control_set_mime(app_control, "*/*");
+
+       if (app_control_send_launch_request(app_control, NULL, NULL) == APP_CONTROL_ERROR_NONE)
+               ret = BLUETOOTH_ERROR_NONE;
+       else
+               ret = BLUETOOTH_ERROR_INTERNAL;
+
+       app_control_destroy(app_control);
+
+       return ret;
+}
 
 extern struct bluetooth_headed_plugin_t headed_plugin
 __attribute__ ((visibility("default")));