Support legacy image for backward-compatibility
[platform/core/appfw/app2sd.git] / plugin / app2sd / server / app2sd_server.c
index 9cd82c2..3be7117 100644 (file)
@@ -199,6 +199,19 @@ static const gchar introspection_xml[] =
 "              <method name='DisableFullPkg'>"
 "                      <arg type='i' name='result' direction='out'/>"
 "              </method>"
+"              <method name='PreMigrateLegacy'>"
+"                      <arg type='s' name='pkgid' direction='in'/>"
+"                      <arg type='i' name='uid' direction='in'/>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
+"              <method name='PostMigrateLegacy'>"
+"                      <arg type='s' name='pkgid' direction='in'/>"
+"                      <arg type='i' name='uid' direction='in'/>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
+"              <method name='MigrateLegacyAll'>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
 "      </interface>"
 "</node>";
 
@@ -223,10 +236,8 @@ static void _app2sd_server_return_method_error(GDBusMethodInvocation *invocation
 static int _app2sd_server_generate_directory_list(GVariantIter *iter, GList **list)
 {
        int result = APP2EXT_SUCCESS;
-       GVariantIter *iter;
        gchar *str = NULL;
        int type;
-       GList *list = NULL;
 
        app2ext_dir_details *dir_detail = NULL;
        while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
@@ -250,7 +261,7 @@ static int _app2sd_server_generate_directory_list(GVariantIter *iter, GList **li
                        }
 
                        dir_detail->type = type;
-                       list = g_list_append(list, dir_detail);
+                       *list = g_list_append(*list, dir_detail);
                }
        }
 
@@ -685,6 +696,97 @@ static void _app2sd_server_disable_full_pkg(GDBusConnection *connection, const g
        g_dbus_method_invocation_return_value(invocation, param);
 }
 
+static void _app2sd_server_pre_migrate_legacy(GDBusConnection *connection,
+       const gchar *sender, GVariant *parameters,
+       GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       char *pkgid = NULL;
+       uid_t target_uid = -1;
+       int ret = 0;
+
+       g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
+
+       _D("pkgid(%s), target_uid(%d), sender_uid(%d)",
+               pkgid, target_uid, sender_uid);
+
+       if (!_app2sd_server_check_permission(sender_uid, sender_uid)) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_pre_migrate_legacy(pkgid, target_uid);
+       if (ret) {
+               _E("error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
+static void _app2sd_server_post_migrate_legacy(GDBusConnection *connection,
+       const gchar *sender, GVariant *parameters,
+       GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       char *pkgid = NULL;
+       uid_t target_uid = -1;
+       int ret = 0;
+
+       g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
+
+       _D("pkgid(%s), target_uid(%d), sender_uid(%d)",
+               pkgid, target_uid, sender_uid);
+
+       if (!_app2sd_server_check_permission(sender_uid, sender_uid)) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_post_migrate_legacy(pkgid, target_uid);
+       if (ret) {
+               _E("error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
+static void _app2sd_server_migrate_legacy_all(GDBusConnection *connection,
+       const gchar *sender, GVariant *parameters,
+       GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       int ret = 0;
+
+       _D("sender_uid(%d)", sender_uid);
+
+       if (!_app2sd_server_check_permission(sender_uid, sender_uid)) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_migrate_legacy_all();
+       if (ret) {
+               _E("error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
 static void handle_method_call(GDBusConnection *connection,
        const gchar *sender, const gchar *object_path,
        const gchar *interface_name, const gchar *method_name,
@@ -736,6 +838,15 @@ static void handle_method_call(GDBusConnection *connection,
        } else if (g_strcmp0(method_name, "DisableFullPkg") == 0) {
                _app2sd_server_disable_full_pkg(connection, sender,
                        parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "PreMigrateLegacy") == 0) {
+               _app2sd_server_pre_migrate_legacy(connection, sender,
+                       parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "PostMigrateLegacy") == 0) {
+               _app2sd_server_post_migrate_legacy(connection, sender,
+                       parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "MigrateLegacyAll") == 0) {
+               _app2sd_server_migrate_legacy_all(connection, sender,
+                       parameters, invocation, sender_uid);
        }
 
        if (source_id)