4 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "app2sd_internals.h"
26 int processing_busy_cnt;
29 GMainLoop *app2sd_mainloop = NULL;
31 static void __free_dir_detail(gpointer data)
33 app2ext_dir_details *dir_detail = (app2ext_dir_details *)data;
36 free(dir_detail->name);
40 gboolean __exit_app2sd_server(void *data)
42 if (processing_busy_cnt <= 0) {
43 _D("exit app2sd_server");
44 g_main_loop_quit(app2sd_mainloop);
48 _D("processing busy, count(%d)", processing_busy_cnt);
52 static int __app2sd_get_sender_unixinfo(GDBusConnection *conn,
53 const char *sender_name, const char *type)
55 GDBusMessage *msg = NULL;
56 GDBusMessage *reply = NULL;
62 msg = g_dbus_message_new_method_call("org.freedesktop.DBus",
63 "/org/freedesktop/DBus", "org.freedesktop.DBus", type);
65 _E("Can't allocate new method call");
69 g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
70 reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
71 G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
75 _E("Failed to get info [%s]", err->message);
81 body = g_dbus_message_get_body(reply);
82 g_variant_get(body, "(u)", &value);
89 g_object_unref(reply);
95 static int __app2sd_get_sender_pid(GDBusConnection *conn,
96 const char *sender_name)
100 pid = __app2sd_get_sender_unixinfo(conn, sender_name,
101 "GetConnectionUnixProcessID");
103 _E("failed to get pid");
107 _D("sender_name(%s), pid(%d)", sender_name, pid);
113 static int __app2sd_get_sender_uid(GDBusConnection *conn,
114 const char *sender_name)
118 uid = __app2sd_get_sender_unixinfo(conn, sender_name,
119 "GetConnectionUnixUser");
121 _E("failed to get uid");
123 _D("sender_name(%s), uid(%d)", sender_name, uid);
128 static GDBusNodeInfo *introspection_data;
129 static const gchar introspection_xml[] =
131 " <interface name='org.tizen.app2sd'>"
132 " <method name='PreAppInstall'>"
133 " <arg type='s' name='pkgid' direction='in'/>"
134 " <arg type='i' name='size' direction='in'/>"
135 " <arg type='a(si)' name='dir_list' direction='in'/>"
136 " <arg type='i' name='uid' direction='in'/>"
137 " <arg type='i' name='result' direction='out'/>"
139 " <method name='PostAppInstall'>"
140 " <arg type='s' name='pkgid' direction='in'/>"
141 " <arg type='i' name='install_status' direction='in'/>"
142 " <arg type='i' name='uid' direction='in'/>"
143 " <arg type='i' name='result' direction='out'/>"
145 " <method name='PreAppUpgrade'>"
146 " <arg type='s' name='pkgid' direction='in'/>"
147 " <arg type='i' name='size' direction='in'/>"
148 " <arg type='a(si)' name='dir_list' direction='in'/>"
149 " <arg type='i' name='uid' direction='in'/>"
150 " <arg type='i' name='result' direction='out'/>"
152 " <method name='PostAppUpgrade'>"
153 " <arg type='s' name='pkgid' direction='in'/>"
154 " <arg type='i' name='install_status' direction='in'/>"
155 " <arg type='i' name='uid' direction='in'/>"
156 " <arg type='i' name='result' direction='out'/>"
158 " <method name='PreAppUninstall'>"
159 " <arg type='s' name='pkgid' direction='in'/>"
160 " <arg type='i' name='uid' direction='in'/>"
161 " <arg type='i' name='result' direction='out'/>"
163 " <method name='PostAppUninstall'>"
164 " <arg type='s' name='pkgid' direction='in'/>"
165 " <arg type='i' name='uid' direction='in'/>"
166 " <arg type='i' name='result' direction='out'/>"
168 " <method name='OndemandSetupInit'>"
169 " <arg type='s' name='pkgid' direction='in'/>"
170 " <arg type='i' name='uid' direction='in'/>"
171 " <arg type='i' name='result' direction='out'/>"
173 " <method name='OndemandSetupExit'>"
174 " <arg type='s' name='pkgid' direction='in'/>"
175 " <arg type='i' name='uid' direction='in'/>"
176 " <arg type='i' name='result' direction='out'/>"
178 " <method name='PreMoveInstalledApp'>"
179 " <arg type='s' name='pkgid' direction='in'/>"
180 " <arg type='i' name='move_type' direction='in'/>"
181 " <arg type='a(si)' name='dir_list' direction='in'/>"
182 " <arg type='i' name='uid' direction='in'/>"
183 " <arg type='i' name='result' direction='out'/>"
185 " <method name='PostMoveInstalledApp'>"
186 " <arg type='s' name='pkgid' direction='in'/>"
187 " <arg type='i' name='move_type' direction='in'/>"
188 " <arg type='i' name='uid' direction='in'/>"
189 " <arg type='i' name='result' direction='out'/>"
191 " <method name='ForceClean'>"
192 " <arg type='s' name='pkgid' direction='in'/>"
193 " <arg type='i' name='uid' direction='in'/>"
194 " <arg type='i' name='result' direction='out'/>"
196 " <method name='EnableFullPkg'>"
197 " <arg type='i' name='result' direction='out'/>"
199 " <method name='DisableFullPkg'>"
200 " <arg type='i' name='result' direction='out'/>"
205 static bool _app2sd_server_check_permission(uid_t sender_uid, uid_t target_uid)
207 if (sender_uid != 0 && sender_uid != APPFW_UID && sender_uid != target_uid) {
208 _E("Not permitted user!, uid(%d)", sender_uid);
215 static void _app2sd_server_return_method_error(GDBusMethodInvocation *invocation, int result)
217 GVariant *param = NULL;
219 param = g_variant_new("(i)", result);
220 g_dbus_method_invocation_return_value(invocation, param);
223 static void _app2sd_server_pre_app_install(GDBusConnection *connection, const gchar *sender,
224 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
226 GVariant *param = NULL;
227 int result = APP2EXT_SUCCESS;
234 uid_t target_uid = -1;
235 GList *dir_list = NULL;
237 app2ext_dir_details *dir_detail = NULL;
239 g_variant_get(parameters, "(&sia(si)i)", &pkgid, &size, &iter, &target_uid);
241 _D("pkgid(%s), size(%d),sender_uid(%d), target_uid(%d)",
242 pkgid, size, sender_uid, target_uid);
244 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
245 _E("Not permitted user!");
246 g_variant_iter_free(iter);
247 _app2sd_server_return_method_error(invocation,
248 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
252 while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
254 _D("str(%s), type(%d)", str, type);
256 /* generate dir_list */
257 dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
258 if (dir_detail == NULL) {
259 _E("memory allocation failed");
260 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
264 dir_detail->name = strdup((char *)str);
265 if (dir_detail->name == NULL) {
268 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
272 dir_detail->type = type;
273 list = g_list_append(list, dir_detail);
276 g_variant_iter_free(iter);
278 dir_list = g_list_first(list);
279 ret = app2sd_usr_pre_app_install(pkgid, dir_list, size, target_uid);
281 _E("error(%d)", ret);
284 g_list_free_full(dir_list, __free_dir_detail);
286 param = g_variant_new("(i)", result);
287 g_dbus_method_invocation_return_value(invocation, param);
290 static void _app2sd_server_post_app_install(GDBusConnection *connection, const gchar *sender,
291 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
293 GVariant *param = NULL;
294 int result = APP2EXT_SUCCESS;
296 int install_status = 0;
300 g_variant_get(parameters, "(&sii)", &pkgid, &install_status, &target_uid);
302 _D("pkgid(%s), install_status(%d), sender_uid(%d), target_uid(%d)",
303 pkgid, install_status, sender_uid, target_uid);
305 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
306 _E("Not permitted user!");
307 _app2sd_server_return_method_error(invocation,
308 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
312 ret = app2sd_usr_post_app_install(pkgid, install_status, target_uid);
314 _E("error(%d)", ret);
318 param = g_variant_new("(i)", result);
319 g_dbus_method_invocation_return_value(invocation, param);
322 static void _app2sd_server_pre_app_upgrade(GDBusConnection *connection, const gchar *sender,
323 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
325 GVariant *param = NULL;
326 int result = APP2EXT_SUCCESS;
332 uid_t target_uid = -1;
334 GList *dir_list = NULL;
336 app2ext_dir_details *dir_detail = NULL;
338 g_variant_get(parameters, "(&sia(si)i)", &pkgid, &size, &iter, &target_uid);
340 _D("pkgid(%s), size(%d), sender_uid(%d), target_uid(%d)",
341 pkgid, size, sender_uid, target_uid);
343 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
344 _E("Not permitted user!");
345 g_variant_iter_free(iter);
346 _app2sd_server_return_method_error(invocation,
347 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
351 while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
353 _D("str(%s), type(%d)", str, type);
355 /* generate dir_list */
356 dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
357 if (dir_detail == NULL) {
358 _E("memory allocation failed");
359 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
363 dir_detail->name = strdup((char *)str);
364 if (dir_detail->name == NULL) {
367 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
371 dir_detail->type = type;
372 list = g_list_append(list, dir_detail);
375 g_variant_iter_free(iter);
377 dir_list = g_list_first(list);
378 ret = app2sd_usr_pre_app_upgrade(pkgid, dir_list, size, target_uid);
380 _E("error(%d)", ret);
383 g_list_free_full(dir_list, __free_dir_detail);
385 param = g_variant_new("(i)", result);
386 g_dbus_method_invocation_return_value(invocation, param);
389 static void _app2sd_server_post_app_upgrade(GDBusConnection *connection, const gchar *sender,
390 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
392 GVariant *param = NULL;
393 int result = APP2EXT_SUCCESS;
395 int install_status = 0;
396 uid_t target_uid = -1;
399 g_variant_get(parameters, "(&sii)", &pkgid, &install_status, &target_uid);
401 _D("pkgid(%s), install_status(%d), sender_uid(%d), target_uid(%d)",
402 pkgid, install_status, sender_uid, target_uid);
404 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
405 _E("Not permitted user!");
406 _app2sd_server_return_method_error(invocation,
407 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
411 ret = app2sd_usr_post_app_upgrade(pkgid, install_status, target_uid);
413 _E("error(%d)", ret);
417 param = g_variant_new("(i)", result);
418 g_dbus_method_invocation_return_value(invocation, param);
421 static void _app2sd_server_pre_app_uninstall(GDBusConnection *connection, const gchar *sender,
422 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
424 GVariant *param = NULL;
425 int result = APP2EXT_SUCCESS;
427 uid_t target_uid = -1;
430 g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
432 _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
433 pkgid, sender_uid, target_uid);
435 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
436 _E("Not permitted user!");
437 _app2sd_server_return_method_error(invocation,
438 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
442 ret = app2sd_usr_pre_app_uninstall(pkgid, target_uid);
444 _E("error(%d)", ret);
448 param = g_variant_new("(i)", result);
449 g_dbus_method_invocation_return_value(invocation, param);
452 static void _app2sd_server_post_app_uninstall(GDBusConnection *connection, const gchar *sender,
453 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
455 GVariant *param = NULL;
456 int result = APP2EXT_SUCCESS;
458 uid_t target_uid = -1;
461 g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
463 _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
464 pkgid, sender_uid, target_uid);
466 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
467 _E("Not permitted user!");
468 _app2sd_server_return_method_error(invocation,
469 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
473 ret = app2sd_usr_post_app_uninstall(pkgid, target_uid);
475 _E("error(%d)", ret);
479 param = g_variant_new("(i)", result);
480 g_dbus_method_invocation_return_value(invocation, param);
483 static void _app2sd_server_ondemand_setup_init(GDBusConnection *connection, const gchar *sender,
484 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
486 GVariant *param = NULL;
487 int result = APP2EXT_SUCCESS;
489 uid_t target_uid = -1;
492 g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
494 _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
495 pkgid, sender_uid, target_uid);
497 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
498 _E("Not permitted user!");
499 _app2sd_server_return_method_error(invocation,
500 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
504 ret = app2sd_usr_on_demand_setup_init(pkgid, target_uid);
506 _E("error(%d)", ret);
510 param = g_variant_new("(i)", result);
511 g_dbus_method_invocation_return_value(invocation, param);
514 static void _app2sd_server_ondemand_setup_exit(GDBusConnection *connection, const gchar *sender,
515 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
517 GVariant *param = NULL;
518 int result = APP2EXT_SUCCESS;
520 uid_t target_uid = -1;
523 g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
525 _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
526 pkgid, sender_uid, target_uid);
528 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
529 _E("Not permitted user!");
530 _app2sd_server_return_method_error(invocation,
531 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
535 ret = app2sd_usr_on_demand_setup_exit(pkgid, target_uid);
537 _E("error(%d)", ret);
541 param = g_variant_new("(i)", result);
542 g_dbus_method_invocation_return_value(invocation, param);
545 static void _app2sd_server_pre_move_installed_app(GDBusConnection *connection,
546 const gchar *sender, GVariant *parameters,
547 GDBusMethodInvocation *invocation, uid_t sender_uid)
549 GVariant *param = NULL;
550 int result = APP2EXT_SUCCESS;
557 uid_t target_uid = -1;
558 GList *dir_list = NULL;
560 app2ext_dir_details *dir_detail = NULL;
562 g_variant_get(parameters, "(&sia(si)i)", &pkgid, &move_type, &iter, &target_uid);
564 _D("pkgid(%s), move_type(%d),sender_uid(%d), target_uid(%d)",
565 pkgid, move_type, sender_uid, target_uid);
567 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
568 _E("Not permitted user!");
569 g_variant_iter_free(iter);
570 _app2sd_server_return_method_error(invocation,
571 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
575 while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
577 _D("str(%s), type(%d)", str, type);
579 /* generate dir_list */
580 dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
581 if (dir_detail == NULL) {
582 _E("memory allocation failed");
583 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
587 dir_detail->name = strdup((char *)str);
588 if (dir_detail->name == NULL) {
591 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
595 dir_detail->type = type;
596 list = g_list_append(list, dir_detail);
599 g_variant_iter_free(iter);
601 dir_list = g_list_first(list);
602 ret = app2sd_usr_pre_move_installed_app(pkgid, dir_list, move_type, target_uid);
604 _E("pre_move error(%d)", ret);
608 g_list_free_full(list, __free_dir_detail);
609 param = g_variant_new("(i)", result);
610 g_dbus_method_invocation_return_value(invocation, param);
613 static void _app2sd_server_post_move_installed_app(GDBusConnection *connection,
614 const gchar *sender, GVariant *parameters,
615 GDBusMethodInvocation *invocation, uid_t sender_uid)
617 GVariant *param = NULL;
618 int result = APP2EXT_SUCCESS;
622 uid_t target_uid = -1;
624 g_variant_get(parameters, "(&sii)", &pkgid, &move_type, &target_uid);
626 _D("pkgid(%s), move_type(%d),sender_uid(%d), target_uid(%d)",
627 pkgid, move_type, sender_uid, target_uid);
629 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
630 _E("Not permitted user!");
631 _app2sd_server_return_method_error(invocation,
632 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
636 ret = app2sd_usr_post_move_installed_app(pkgid, move_type, target_uid);
638 _E("post_move error(%d)", ret);
642 param = g_variant_new("(i)", result);
643 g_dbus_method_invocation_return_value(invocation, param);
646 static void _app2sd_server_force_clean(GDBusConnection *connection, const gchar *sender,
647 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
649 GVariant *param = NULL;
650 int result = APP2EXT_SUCCESS;
652 uid_t target_uid = -1;
655 g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
657 _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
658 pkgid, sender_uid, target_uid);
660 if (!_app2sd_server_check_permission(sender_uid, target_uid)) {
661 _E("Not permitted user!");
662 _app2sd_server_return_method_error(invocation,
663 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
667 ret = app2sd_usr_force_clean(pkgid, target_uid);
669 _E("error(%d)", ret);
673 param = g_variant_new("(i)", result);
674 g_dbus_method_invocation_return_value(invocation, param);
677 static void _app2sd_server_enable_full_pkg(GDBusConnection *connection, const gchar *sender,
678 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
680 GVariant *param = NULL;
681 int result = APP2EXT_SUCCESS;
684 _D("sender_uid(%d)", sender_uid);
686 if (sender_uid >= REGULAR_USER) {
687 _E("Not permitted user!");
688 _app2sd_server_return_method_error(invocation,
689 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
693 ret = app2sd_enable_full_pkg();
695 _E("error(%d)", ret);
699 param = g_variant_new("(i)", result);
700 g_dbus_method_invocation_return_value(invocation, param);
703 static void _app2sd_server_disable_full_pkg(GDBusConnection *connection, const gchar *sender,
704 GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
706 GVariant *param = NULL;
707 int result = APP2EXT_SUCCESS;
710 _D("sender_uid(%d)", sender_uid);
712 if (sender_uid >= REGULAR_USER) {
713 _E("Not permitted user!");
714 _app2sd_server_return_method_error(invocation,
715 APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
719 ret = app2sd_disable_full_pkg();
721 _E("error(%d)", ret);
725 param = g_variant_new("(i)", result);
726 g_dbus_method_invocation_return_value(invocation, param);
729 static void handle_method_call(GDBusConnection *connection,
730 const gchar *sender, const gchar *object_path,
731 const gchar *interface_name, const gchar *method_name,
732 GVariant *parameters, GDBusMethodInvocation *invocation,
735 uid_t sender_uid = -1;
737 processing_busy_cnt++;
739 sender_uid = (uid_t)__app2sd_get_sender_uid(connection, sender);
741 if (g_strcmp0(method_name, "PreAppInstall") == 0) {
742 _app2sd_server_pre_app_install(connection, sender,
743 parameters, invocation, sender_uid);
744 } else if (g_strcmp0(method_name, "PostAppInstall") == 0) {
745 _app2sd_server_post_app_install(connection, sender,
746 parameters, invocation, sender_uid);
747 } else if (g_strcmp0(method_name, "PreAppUpgrade") == 0) {
748 _app2sd_server_pre_app_upgrade(connection, sender,
749 parameters, invocation, sender_uid);
750 } else if (g_strcmp0(method_name, "PostAppUpgrade") == 0) {
751 _app2sd_server_post_app_upgrade(connection, sender,
752 parameters, invocation, sender_uid);
753 } else if (g_strcmp0(method_name, "PreAppUninstall") == 0) {
754 _app2sd_server_pre_app_uninstall(connection, sender,
755 parameters, invocation, sender_uid);
756 } else if (g_strcmp0(method_name, "PostAppUninstall") == 0) {
757 _app2sd_server_post_app_uninstall(connection, sender,
758 parameters, invocation, sender_uid);
759 } else if (g_strcmp0(method_name, "OndemandSetupInit") == 0) {
760 _app2sd_server_ondemand_setup_init(connection, sender,
761 parameters, invocation, sender_uid);
762 } else if (g_strcmp0(method_name, "OndemandSetupExit") == 0) {
763 _app2sd_server_ondemand_setup_exit(connection, sender,
764 parameters, invocation, sender_uid);
765 } else if (g_strcmp0(method_name, "PreMoveInstalledApp") == 0) {
766 _app2sd_server_pre_move_installed_app(connection, sender,
767 parameters, invocation, sender_uid);
768 } else if (g_strcmp0(method_name, "PostMoveInstalledApp") == 0) {
769 _app2sd_server_post_move_installed_app(connection, sender,
770 parameters, invocation, sender_uid);
771 } else if (g_strcmp0(method_name, "ForceClean") == 0) {
772 _app2sd_server_force_clean(connection, sender,
773 parameters, invocation, sender_uid);
774 } else if (g_strcmp0(method_name, "EnableFullPkg") == 0) {
775 _app2sd_server_enable_full_pkg(connection, sender,
776 parameters, invocation, sender_uid);
777 } else if (g_strcmp0(method_name, "DisableFullPkg") == 0) {
778 _app2sd_server_disable_full_pkg(connection, sender,
779 parameters, invocation, sender_uid);
783 g_source_remove(source_id);
784 source_id = g_timeout_add_seconds(5, __exit_app2sd_server, NULL);
785 processing_busy_cnt--;
788 static const GDBusInterfaceVTable interface_vtable = {
794 static void __app2sd_on_bus_acquired(GDBusConnection *connection,
795 const gchar *name, gpointer user_data)
797 _I("bus acquired(%s)", name);
800 GError *error = NULL;
802 reg_id = g_dbus_connection_register_object(connection,
804 introspection_data->interfaces[0],
808 _E("g_dbus_connection_register_object error(%s)", error->message);
813 static void __app2sd_on_name_acquired(GDBusConnection *connection,
814 const gchar *name, gpointer user_data)
816 _I("name acquired(%s)", name);
819 static void __app2sd_on_name_lost(GDBusConnection *connection,
820 const gchar *name, gpointer user_data)
822 _E("name lost(%s)", name);
823 g_main_loop_quit(app2sd_mainloop);
826 static int __app2sd_server_init()
828 GError *error = NULL;
831 /* gdbus setup for method call */
832 introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &error);
833 if (!introspection_data) {
834 _E("g_dbus_node_info_new_for_xml error(%s)", error->message);
839 owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
841 G_BUS_NAME_OWNER_FLAGS_NONE,
842 __app2sd_on_bus_acquired,
843 __app2sd_on_name_acquired,
844 __app2sd_on_name_lost,
847 _E("g_bus_own_name error");
848 g_dbus_node_info_unref(introspection_data);
855 static void __app2sd_finalize(void)
857 _D("app2sd finalize");
859 if (introspection_data)
860 g_dbus_node_info_unref(introspection_data);
862 _D("app2sd finalize end");
865 int main(int argc, char *argv[])
869 _I("app2sd_server : start");
871 ret = __app2sd_server_init();
873 _E("app2sd_server init failed(%d)", ret);
877 app2sd_mainloop = g_main_loop_new(NULL, FALSE);
878 if (!app2sd_mainloop) {
879 _E("g_main_loop_new failed");
883 g_main_loop_run(app2sd_mainloop);
887 _I("app2sd_server : end");