Make update_control_do_update asynchronous 20/278820/1
authorMateusz Majewski <m.majewski2@samsung.com>
Mon, 25 Jul 2022 08:08:23 +0000 (10:08 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 26 Jul 2022 10:46:16 +0000 (10:46 +0000)
This is just a hotfix, we want to do this in a different way. However we
wanted to make this work quickly.

Change-Id: I57a696329013f86fc2e48b574f7773612cb68190
(cherry picked from commit 484ed0aede06be9f0af2c2e74feace4adc719db8)

NOTES.md [deleted file]
src/update_control.c
src/update_control_internal.h

diff --git a/NOTES.md b/NOTES.md
deleted file mode 100644 (file)
index f9caa87..0000000
--- a/NOTES.md
+++ /dev/null
@@ -1 +0,0 @@
-The upgrade DBus method is a bit unusual, in that it waits synchronously for upgrade before returning a result. This means that it has to use a larger timeout than usual; we set the timeout of this method to 6 hours in update_control API.
index c348d8f9f7c207173d291957cb9b4ad36f1e6444..2b769cd790716e441576b2d6e810d169fd8a3da3 100644 (file)
@@ -182,32 +182,47 @@ API int update_control_download_package(void)
        return UPDATE_CONTROL_ERROR_NONE;
 }
 
-API int update_control_do_update(void)
+static void do_update_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
-       CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
-       _I("update_control_do_update called");
-
-       gint status = 0;
-       GError *error = NULL;
-
        if (proxy == NULL) {
                _E("Not initialized");
-               return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
+               return;
        }
 
-       org_tizen_update_manager_call_install_sync(proxy, &status, NULL, &error);
+       gint status = 0;
+       GError *error = NULL;
+
+       org_tizen_update_manager_call_install_finish(proxy, &status, res, &error);
        if (error != NULL) {
                _E("Failed to method call <install> to dbus : %s", error->message);
-               return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
+               g_error_free(error);
+               return;
        }
 
        _I("Success to method call <install> to dbus");
        if (status < 0) {
                _E("Failed to do update : %d", status);
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
+               return;
        }
 
+       // NB: We shouldn't really end up here, since the target should be rebooted by now.
        _I("Success to do update : %d", status);
+}
+
+API int update_control_do_update(void)
+{
+       CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
+       _I("update_control_do_update called");
+
+       if (proxy == NULL) {
+               _E("Not initialized");
+               return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
+       }
+
+       // TODO: Take the fact that this is now async into account in docs.
+       // TODO: Consider making this asynchronous server-side instead.
+       org_tizen_update_manager_call_install(proxy, NULL, do_update_cb, NULL);
+       _I("Started update");
        return UPDATE_CONTROL_ERROR_NONE;
 }
 
index 2b5063a2af8b7906596bfcce9a6c2a2f54436404..9884ac6a8ae33aa5a97b88edb017c8efb94a5525 100644 (file)
@@ -48,6 +48,7 @@ do {\
        } \
 } while (0);
 // DBUS_PROXY_TIMEOUT is 6 hours
+// TODO: Is this still needed after converting do_update to be more async?
 #define DBUS_PROXY_TIMEOUT 6 * 60 * 60 * 1000
 #ifdef __cplusplus
 }