From 484ed0aede06be9f0af2c2e74feace4adc719db8 Mon Sep 17 00:00:00 2001 From: Mateusz Majewski Date: Mon, 25 Jul 2022 10:08:23 +0200 Subject: [PATCH] Make update_control_do_update asynchronous 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 --- NOTES.md | 1 - src/update_control.c | 37 ++++++++++++++++++++++++----------- src/update_control_internal.h | 1 + 3 files changed, 27 insertions(+), 12 deletions(-) delete mode 100644 NOTES.md diff --git a/NOTES.md b/NOTES.md deleted file mode 100644 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. diff --git a/src/update_control.c b/src/update_control.c index c348d8f..2b769cd 100644 --- a/src/update_control.c +++ b/src/update_control.c @@ -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 to dbus : %s", error->message); - return UPDATE_CONTROL_ERROR_SYSTEM_ERROR; + g_error_free(error); + return; } _I("Success to method call 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; } diff --git a/src/update_control_internal.h b/src/update_control_internal.h index 2b5063a..9884ac6 100644 --- a/src/update_control_internal.h +++ b/src/update_control_internal.h @@ -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 } -- 2.34.1