Modify syspopup launch API 19/76619/1 accepted/tizen/common/20160627.191827 accepted/tizen/ivi/20160626.225436 accepted/tizen/mobile/20160626.225354 accepted/tizen/tv/20160626.225401 accepted/tizen/wearable/20160626.225418 submit/tizen/20160624.132606
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 24 Jun 2016 11:54:52 +0000 (20:54 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 24 Jun 2016 11:54:52 +0000 (20:54 +0900)
- Use aul API instead of dbus signal
- Add syspopup_launch_for_uid API for system users

Change-Id: I8029e146d5cbd93b4c03c4fce18466793d8452e8
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/syspopup_caller.h
packaging/syspopup.spec
syspopup-caller/CMakeLists.txt
syspopup-caller/syspopup_caller.c

index 7addaf4..d502a0a 100755 (executable)
@@ -24,6 +24,7 @@
 #ifndef __SYSPOPUP_CALLER_H__
 #define __SYSPOPUP_CALLER_H__
 
+#include <unistd.h>
 #include <bundle.h>
 
 #ifdef __cplusplus
@@ -56,6 +57,43 @@ extern "C" {
  *              This API find system popup application package name with given popup name from system popup infomation DB.\n
  *              And then, launch found application package
  *
+ * @privilege   %http://tizen.org/privilege/appmanager.launch
+ * @param[in]   popup_name      system popup application name to launch (not package name)
+ * @param[in]   b               extra bundle(arguement) to toss the popup application
+ * @param[in]   uid             User ID
+ * @return      0 if success, negative value(<0) if fail
+ * @retval      0               - success
+ * @retval      -1              - generic error
+ *
+ * @sample code
+ * @code
+ *
+ * ...
+ *     bundle *b = NULL;
+ *
+ *     b = bundle_create();
+ *     bundle_add(b, "_SYSPOPUP_TITLE_", "System Popup Title");
+ *     bundle_add(b, "_SYSPOPUP_CONTENT_", "System Popup Content");
+ *
+ *     ret = syspopup_launch_for_uid("syspopup-app", b, 5001);
+ *
+ *     bundle_free(b);
+ * ...
+ *
+ * @endcode
+ * @remark
+ *      This API is only available to System users.
+ */
+int syspopup_launch_for_uid(char *popup_name, bundle *b, uid_t uid);
+
+/**
+ * @brief       This API launch the system popup application with given popup name.
+ *
+ *              This API launch the system popup application.
+ *              This API find system popup application package name with given popup name from system popup infomation DB.\n
+ *              And then, launch found application package
+ *
+ * @privilege   %http://tizen.org/privilege/appmanager.launch
  * @param[in]   popup_name      system popup application name to launch (not package name)
  * @param[in]   b               extra bundle(arguement) to toss the popup application
  * @return      0 if success, negative value(<0) if fail
index 7322ae7..8f23182 100644 (file)
@@ -35,6 +35,8 @@ BuildRequires:  pkgconfig(elementary)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(capi-appfw-application)
 BuildRequires:  pkgconfig(capi-system-system-settings)
+BuildRequires:  pkgconfig(libsystemd-daemon)
+BuildRequires:  pkgconfig(aul)
 
 %if "%{?profile}" == "wearable"
 %define profile_wearable 1
index 8f00a11..3ee1a45 100644 (file)
@@ -22,7 +22,7 @@ INCLUDE(FindPkgConfig)
 
 SET(pc_requires "bundle")
 
-pkg_check_modules(spcpkgs REQUIRED dlog bundle sqlite3 glib-2.0 gio-2.0 libtzplatform-config)
+pkg_check_modules(spcpkgs REQUIRED dlog bundle sqlite3 glib-2.0 gio-2.0 libtzplatform-config libsystemd-daemon aul)
 
 FOREACH(flag ${spcpkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 31d958f..e4e8ba7 100755 (executable)
  *
  */
 
-
+#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <glib.h>
 #include <gio/gio.h>
 #include <bundle.h>
+#include <systemd/sd-login.h>
+#include <aul.h>
 
 #include "syspopup_core.h"
 #include "syspopup_db.h"
 #include "syspopup_api.h"
 #include "simple_util.h"
 
-static int syspopup_send_launch_request(const char *appid, bundle *b)
-{
-       GDBusConnection *conn = NULL;
-       GError *err = NULL;
-       bundle_raw *b_raw = NULL;
-       int ret = 0;
-       int len;
-
-#if !(GLIB_CHECK_VERSION(2, 36, 0))
-       g_type_init();
-#endif
-
-       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-       if (err) {
-               _E("gdbus connection error: %s", err->message);
-               g_error_free(err);
-               return -1;
-       }
-
-       if (bundle_encode(b, &b_raw, &len) != BUNDLE_ERROR_NONE) {
-               _E("bundle encode error");
-               ret = -1;
-               goto end;
-       }
+#define REGULAR_UID_MIN 5000
 
-       if (g_dbus_connection_emit_signal(conn,
-                                       NULL,
-                                       AUL_SP_DBUS_PATH,
-                                       AUL_SP_DBUS_SIGNAL_INTERFACE,
-                                       AUL_SP_DBUS_LAUNCH_REQUEST_SIGNAL,
-                                       g_variant_new("(ss)", appid, (char *)b_raw),
-                                       &err) == FALSE) {
-               _E("emitting the signal error: %s", err->message);
-               ret = -1;
-               goto end;
-       }
-
-       if (g_dbus_connection_flush_sync(conn, NULL, &err) == FALSE) {
-               _E("gdbus connection flush sync failed: %s", err->message);
-               ret = -1;
-       }
-
-end:
-       if (err)
-               g_error_free(err);
-       if (conn)
-               g_object_unref(conn);
-
-       return ret;
-}
-
-API int syspopup_launch(char *popup_name, bundle *b)
+API int syspopup_launch_for_uid(char *popup_name, bundle *b, uid_t uid)
 {
-       syspopup_info_t *info = NULL;
-       int ret;
+       syspopup_info_t *info;
+       int ret = -1;
        int is_bundle = 0;
+       int uid_max;
+       int i;
+       char *state = NULL;
+       uid_t *uids = NULL;
+       uid_t cuid = getuid();
 
        if (popup_name == NULL) {
                _E("popup_name is NULL");
@@ -117,16 +75,59 @@ API int syspopup_launch(char *popup_name, bundle *b)
                return -1;
        }
 
-       ret = syspopup_send_launch_request(info->pkgname, b);
-       if (ret < 0)
-               _E("syspopup launch error: %d", ret);
+       if (cuid >= REGULAR_UID_MIN) {
+               if (cuid != uid) {
+                       _E("Cannot launch syspopup %s in other users",
+                                       popup_name);
+                       ret = -1;
+                       goto end;
+               }
+
+               ret = aul_launch_app_for_uid(info->pkgname, b, uid);
+               if (ret < 0)
+                       _E("syspopup launch error - %d", ret);
+       } else {
+               if (uid >= REGULAR_UID_MIN) {
+                       ret = aul_launch_app_for_uid(info->pkgname, b, uid);
+                       if (ret < 0)
+                               _E("syspopup launch error - %d", ret);
+               } else {
+                       uid_max = sd_get_uids(&uids);
+                       if (uid_max <= 0) {
+                               _E("Failed to get uid list");
+                               ret = -1;
+                               goto end;
+                       }
+
+                       for (i = 0; i < uid_max; i++) {
+                               if (sd_uid_get_state(uids[i], &state) < 0)
+                                       continue;
+
+                               if (state && !strcmp(state, "online")) {
+                                       ret = aul_launch_app_for_uid(
+                                                       info->pkgname,
+                                                       b, uids[i]);
+                                       if (ret < 0) {
+                                               _E("syspopup launch error - %d",
+                                                               ret);
+                                       }
+                               }
+                       }
+               }
+       }
 
-       if (is_bundle == 1)
+end:
+       if (is_bundle)
                bundle_free(b);
 
        _syspopup_info_free(info);
 
-       return ret;
+       return ret > 0 ? 0 : -1;
+}
+
+API int syspopup_launch(char *popup_name, bundle *b)
+{
+       return syspopup_launch_for_uid(popup_name, b, getuid());
 }
 
 API int syspopup_destroy_all(void)