Plugin: Implementation for PROPERTY_RESULT 30/189530/1
authorSunmin Lee <sunm.lee@samsung.com>
Fri, 14 Sep 2018 01:21:26 +0000 (10:21 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Mon, 17 Sep 2018 10:04:40 +0000 (19:04 +0900)
Get update result through the dbus method.

Change-Id: I017095cb78b01b8066ef20a7dc5d13971b08169a
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
packaging/update-control.spec
src/plugin/CMakeLists.txt
src/plugin/plugin.c

index 58ca3e81a886c5d890b79278174bd948293be33d..5235f4f81a2a1e6c08bccaae65d9243b4d1965ca 100644 (file)
@@ -17,7 +17,7 @@ BuildRequires:  pkgconfig(gio-2.0)
 BuildRequires:  pkgconfig(message-port)
 BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(alarm-service)
-BuildRequires:  pkgconfig(libcurl)
+BuildRequires:  pkgconfig(libtzplatform-config)
 
 %description
 An Update Control library in Tizen C API
@@ -55,6 +55,10 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %post
 /sbin/ldconfig
 
+%post plugin
+chsmack -a _ %{_libdir}/libupdate-control-plugin.so*
+/sbin/ldconfig
+
 %postun -p /sbin/ldconfig
 
 %files
index 340c56d14492939a45016253d6032037519b76fd..a9aee30ad2704eab3c21ff719cb7baa9b4892129 100644 (file)
@@ -23,6 +23,7 @@ SET(requires
        gio-2.0
        alarm-service
        libcurl
+       libtzplatform-config
 )
 
 INCLUDE(FindPkgConfig)
index f960b053461149b676c2153551978a6a3e568154..43d6e0f3d16a45804f61749fb23d0f089d0d184b 100644 (file)
@@ -22,6 +22,7 @@
 #include <message_port.h>
 #include <alarm.h>
 #include <system_info.h>
+#include <tzplatform_config.h>
 #include "plugin.h"
 #include "http_util.h"
 
@@ -31,7 +32,7 @@
 #define API __attribute__ ((visibility("default")))
 
 /* IPC with Smartthings-thing for ST cloud account info */
-#define ST_APP_THING_SERVICE_APP_ID   "org.tizen.smartthings-thing"
+#define ST_APP_THING_SERVICE_APP_ID   "com.samsung.tizen.smartthings-thing"
 #define ST_APP_OPERATION_UPDATE_AGENT "http://tizen.org/appcontrol/operation/update_agent"
 #define ST_SVC_KEY_COMMAND            "command"
 #define ST_SVC_CMD_GET_ACCOUNT_INFO   "get_account_info"
 #define UPDATE_OBJECT_PATH      "/Org/Tizen/System/Update"
 #define UPDATE_INTERFACE_NAME   UPDATE_BUS_NAME".Update"
 #define UPDATE_METHOD           "do_update"
+#define RESULT_METHOD           "get_result"
 
 #define FIRMWARE_FILE_NAME "delta.tar.gz"
+#define RESULT_FILE tzplatform_mkpath(TZ_SYS_UPGRADE_DATA, "result")
 
 #ifdef DEBUG_MODE
 #define DEBUG_FLAG "/opt/etc/.debugupdate"
@@ -417,6 +420,50 @@ exit:
        return ret;
 }
 
+static int send_get_result_signal(int *result)
+{
+       GDBusConnection *conn;
+       GVariant *reply = NULL;
+       GError *error = NULL;
+       int ret = 0;
+
+       retvm_if(!result, -1, "result is NULL");
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       if (error) {
+               _E("Failed to get dbus: %s", error->message);
+               g_error_free(error);
+               return -1;
+       }
+
+       reply = g_dbus_connection_call_sync(conn,
+                                           UPDATE_BUS_NAME,
+                                           UPDATE_OBJECT_PATH,
+                                           UPDATE_INTERFACE_NAME,
+                                           RESULT_METHOD,
+                                           NULL,
+                                           G_VARIANT_TYPE("(i)"),
+                                           G_DBUS_CALL_FLAGS_NONE,
+                                           120000,
+                                           NULL,
+                                           &error);
+       if (error) {
+               _E("Failed to get reply: %s", error->message);
+               g_error_free(error);
+               ret = -1;
+               goto exit;
+       }
+
+       g_variant_get(reply, "(i)", result);
+       _I("Get result signal returns: (%d)", *result);
+
+exit:
+       if (reply)
+               g_variant_unref(reply);
+
+       return ret;
+}
+
+
 API int update_control_initialize(void)
 {
        _D("FN CALLED>>>>>>>>>>>>>>>>>>");
@@ -749,7 +796,6 @@ API int update_control_get_property(update_control_property_e property, void **v
                }
 #endif
 
-       int *int_val;
        int ret = UPDATE_CONTROL_ERROR_NONE;
 
        switch (property) {
@@ -767,24 +813,28 @@ API int update_control_get_property(update_control_property_e property, void **v
                break;
        case UPDATE_CONTROL_PROPERTY_PACKAGE_SIZE:
                if (update_info->package_size) {
-                       int_val = (int *)malloc(sizeof(int));
-                       *int_val = update_info->package_size;
-                       *value = (void *)int_val;
-                       free(int_val);
+                       *value = malloc(sizeof(int));
+                       *(int *)(*value) = update_info->package_size;
                } else {
                        _D("Package size is not set");
                }
                break;
        case UPDATE_CONTROL_PROPERTY_RESULT:
+               *value = malloc(sizeof(int));
+               if (send_get_result_signal((int *)*value) < 0) {
+                       free(*value);
+                       *value = NULL;
+                       _E("Failed to send_get_result_signal");
+                       ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
+               }
+               break;
        case UPDATE_CONTROL_PROPERTY_DESCRIPTION:
                _D("Not implemented for key: %d", property);
                ret = UPDATE_CONTROL_ERROR_INVALID_OPERATION;
                break;
        case UPDATE_CONTROL_PROPERTY_UPDATE_AVAILABLE:
-               int_val = (int *)malloc(sizeof(int));
-               *int_val = update_info->updatable;
-               *value = (void *)int_val;
-               free(int_val);
+               *value = malloc(sizeof(int));
+               *(int *)(*value) = update_info->updatable;
                break;
        default:
                _E("Not supported property key: %d", property);