update-manager: Change the search location for the delta.tar file 16/258516/5 accepted/tizen/unified/20210601.135332 submit/tizen/20210528.131738 submit/tizen/20210528.131807
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 19 May 2021 08:15:45 +0000 (10:15 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 28 May 2021 11:54:11 +0000 (13:54 +0200)
update-manager will look for the delta.tar file in the data directory of
the application that called the "install" DBus method.
If the appid of the caller cannot be determined, the delta.tar file will
be searched for in the application data directory that has the value
"client" for the key "tizen-fota-manager".

Change-Id: Iebc9b5badcbe084d98ee41b03760a5f0951f4697

update-manager/common/common-dbus-manager.c
update-manager/fota/fota-installer.c
update-manager/fota/fota-manager.h

index abed007bb2cf0cc44ca9ee1a8e86d31b1f77d102..eacabe0e8ff8f683d6e850afafed2fae8109b807 100644 (file)
@@ -1,9 +1,42 @@
+#include <unistd.h>
 #include "common.h"
 #include "../fota/fota-manager.h"
 #include "update-manager-dbus.h"
 
 static guint owner_id;
 
+static pid_t dbus_get_sender_pid(GDBusMethodInvocation *invocation)
+{
+       const gchar *sender = g_dbus_method_invocation_get_sender(invocation);
+       GDBusConnection *conn = g_dbus_method_invocation_get_connection(invocation);
+       if (sender == NULL || conn == NULL) {
+               _FLOGW("Failed to get invocation data");
+               return 0;
+       }
+       GError *error = NULL;
+       GVariant *result = g_dbus_connection_call_sync(conn,
+                                                      "org.freedesktop.DBus",
+                                                      "/",
+                                                      "org.freedesktop.DBus",
+                                                      "GetConnectionUnixProcessID",
+                                                      g_variant_new("(s)", sender),
+                                                      NULL,
+                                                      G_DBUS_CALL_FLAGS_NONE,
+                                                      -1,
+                                                      NULL,
+                                                      &error);
+       if (!result || error) {
+               _FLOGW("Failed to get sender PID: %s", error ? error->message : "");
+               g_error_free(error);
+               return 0;
+       }
+
+       pid_t pid;
+       g_variant_get(result, "(u)", &pid);
+       g_variant_unref(result);
+       return pid;
+}
+
 gboolean dbus_manager_result(OrgTizenUpdateManager *skeleton, GDBusMethodInvocation *invocation, gpointer user_data)
 {
        int ret = 0;
@@ -22,7 +55,8 @@ gboolean dbus_manager_install(OrgTizenUpdateManager *skeleton, GDBusMethodInvoca
        int ret = 0;
 
        _FLOGD("Dbus status : install called");
-       ret = fota_installer_execute();
+       pid_t pid = dbus_get_sender_pid(invocation);
+       ret = fota_installer_execute(pid);
        if (ret < 0)
                _FLOGW("Failed to install delta with fota : %d", ret);
        org_tizen_update_manager_complete_install(skeleton, invocation, ret);
index 5635ff08458615ccdab609eda0a72778dc7369c1..953bdf6d612beed2ddbf94c44dbd08561010cf1e 100644 (file)
@@ -1,3 +1,4 @@
+#include <linux/limits.h>
 #include "../common/common.h"
 #include "fota-manager.h"
 
 
 #define FOTA_INSTALL_REBOOT_REASON "fota"
 
+static char *get_sender_or_client_appid(pid_t pid)
+{
+       char *result = NULL;
+       if (pid > 0) {
+               char tmp_appid[PATH_MAX];
+               int res = aul_app_get_appid_bypid(pid, tmp_appid, sizeof(tmp_appid));
+               if (res == AUL_R_OK) {
+                       result = strdup(tmp_appid);
+                       if (result == NULL) {
+                               _FLOGE("Out of memory");
+                               return NULL;
+                       }
+               } else {
+                       _FLOGE("Failed to get sender app id: %d", res);
+               }
+       }
+
+       // Fallback to appid retrieval based on application metadata if the
+       // caller appid cannot be determined
+       if (result == NULL) {
+               result = fota_client_info_get_appid();
+               if (result == NULL)
+                       _FLOGE("Failed to get client app id");
+       }
+       return result;
+}
 
-int fota_installer_execute()
+int fota_installer_execute(pid_t sender_pid)
 {
        int ret = 0, status = 0, exec_status = 0;
        char buf[MAX_BUFFER_SIZE] = {0, };
@@ -20,9 +47,8 @@ int fota_installer_execute()
        pid_t pid;
 
        /* 1. Check client have delta.tar */
-       appid = fota_client_info_get_appid();
+       appid = get_sender_or_client_appid(sender_pid);
        if (appid == NULL) {
-               _FLOGE("Failed to get client app id");
                status = -1;
                goto execute_destroy;
        }
index 30db7036d9412cbaada2d9c226963de1ede8914f..bad0e8f5295fef45037389ae66f801f140844ad5 100644 (file)
@@ -4,6 +4,7 @@
 #include <device/power.h>
 #include <dlog.h>
 #include <system_info.h>
+#include <unistd.h>
 
 /* Log */
 #define FOTA_LOG_TAG "FOTA_MANAGER"
@@ -44,7 +45,7 @@ int fota_info_checker_init(void);
 int fota_info_checker_fini(void);
 char *fota_info_get_build_string(void);
 
-int fota_installer_execute(void);
+int fota_installer_execute(pid_t pid);
 int fota_result_sender_execute(void);
 
 int fota_status_checker_init(void);