Add net.stc-popup application with syspopup_launch and PO files
[platform/core/connectivity/stc-manager.git] / plugin / stc-popup / stc-plugin-stc-popup.c
index f006462..fa4bca0 100644 (file)
 #include <unistd.h>
 #include <string.h>
 
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <syspopup_caller.h>
+
 #include "stc-plugin-popup.h"
 #include "stc-error.h"
 #include "stc-manager-util.h"
 
-#define APP_LAUNCHER_EXEC_PATH "/usr/bin/app_launcher"
-#define STC_POPUP_PACKAGE_NAME "net.stc-popup"
-
-#define MAX_SIZE_ERROR_BUFFER 256
-#define STC_POPUP_START_TIMER 10
-
-static void _no_wait_signal_handler(int sig)
-{
-       pid_t child_pid = 0;
-       int state = 0;
-
-       child_pid = waitpid(-1, &state, WNOHANG);
-
-       STC_LOGD("child_id(%d) state(%d)", child_pid, WEXITSTATUS(state));
-}
-
-static int _execute_file_no_wait(const char *file_path, char *const args[])
-{
-       pid_t pid = 0;
-       int rv = 0;
-       errno = 0;
-       register unsigned int index = 0;
-
-       struct sigaction act;
-       int state = 0;
-       char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
-
-       act.sa_handler = _no_wait_signal_handler;
-       sigemptyset(&act.sa_mask);
-       act.sa_flags = 0;
-
-       state = sigaction(SIGCHLD, &act, 0);
-       if (state != 0) {
-               STC_LOGD("sigaction() : %d");
-               return -1;
-       }
-
-       while (args[index] != NULL) {
-               STC_LOGD("%s", args[index]);
-               index++;
-       }
-
-       if (!(pid = fork())) {
-               STC_LOGD("pid(%d), ppid (%d)", getpid(), getppid());
-               STC_LOGD("Inside child, exec (%s) command", file_path);
-
-               errno = 0;
-               if (execvp(file_path, args) == -1) {
-                       STC_LOGE("Fail to execute command (%s)",
-                               strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
-                       return -1;
-               }
-       } else if (pid > 0) {
-               STC_LOGE("Successfully launched child process");
-               return rv;
-       }
-
-       STC_LOGD("failed to fork(%s)",
-               strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
-       return -EIO;
-}
+#define STC_SYSPOPUP_PACKAGE_NAME "net.stc-popup"
+#define STC_SYSPOPUP_RETRY_MAX 10
+#define STC_SYSPOPUP_TIMER 10
 
-static gboolean _start_stc_popup(gpointer user_data)
+static gboolean __stc_syspopup_timer_cb(gpointer user_data)
 {
-       gboolean *launched = (gboolean *)user_data;
+       __STC_LOG_FUNC_ENTER__;
        int ret;
-       const char *start_path = APP_LAUNCHER_EXEC_PATH;
-       char *const start_args[] = { APP_LAUNCHER_EXEC_PATH, "-s",
-                                    STC_POPUP_PACKAGE_NAME, NULL };
+       static int retry_count;
+       bundle *b = (bundle *)user_data;
+       if (user_data == NULL)
+               return FALSE;
 
-       ret = _execute_file_no_wait(start_path, start_args);
+       ++retry_count;
+
+       ret = syspopup_launch(STC_SYSPOPUP_PACKAGE_NAME, b);
        if (ret < 0) {
-               STC_LOGD("Failed to launch stc-popup, ret : %d", ret);
-               *launched = FALSE;
-               return TRUE;
+               STC_LOGE("Sorry! Can't launch popup, ret=%d, Re-try[%d] time..",
+                        ret, retry_count);
+               if (retry_count >= STC_SYSPOPUP_RETRY_MAX) {
+                       STC_LOGE("Sorry!! Max retry %d reached", retry_count);
+                       bundle_free(b);
+                       retry_count = 0;
+                       return FALSE;
+               }
+       } else {
+               STC_LOGD("Hurray!! Finally Popup launched");
+               retry_count = 0;
+               bundle_free(b);
        }
 
-       *launched = FALSE;
-       return FALSE;
+       __STC_LOG_FUNC_EXIT__;
+       return (ret < 0) ? TRUE : FALSE;
 }
 
 int stc_plugin_popup_initialize(void)
 {
-       static gboolean stc_popup_launched = FALSE;
-
-       if (stc_popup_launched == FALSE)
-               g_timeout_add_seconds(STC_POPUP_START_TIMER, _start_stc_popup,
-                                     &stc_popup_launched);
-       else
-               return STC_ERROR_FAIL;
-
        return STC_ERROR_NONE;
 }
 
 int stc_plugin_popup_deinitialize(void)
 {
-       /* close stc popup application  */
        return STC_ERROR_NONE;
 }
 
@@ -128,7 +77,42 @@ int stc_plugin_popup_show(const char *content, const char *type,
                          const char *app_id, const char *iftype,
                          const char *limit)
 {
-       return 0;
+       __STC_LOG_FUNC_ENTER__;
+
+       int ret = 0;
+       bundle *b = bundle_create();
+       if (b == NULL) {
+               __STC_LOG_FUNC_EXIT__;
+               return STC_ERROR_FAIL;
+       }
+
+       bundle_add(b, "_SYSPOPUP_CONTENT_", content);
+       bundle_add(b, "_SYSPOPUP_TYPE_", type);
+       bundle_add(b, "_APP_ID_", app_id);
+       bundle_add(b, "_IF_TYPE_", iftype);
+
+       if (g_strcmp0(type, "warning_noti") == 0) {
+               STC_LOGD("Warn message : content[%s] type[%s] app_id[%s] limit[%s]",
+                        content, type, app_id, limit);
+
+               bundle_add(b, "_WARN_LIMIT_", limit);
+       } else {
+               STC_LOGD("Restriction message : content[%s] type[%s] app_id[%s] limit[%s]",
+                        content, type, app_id, limit);
+
+               bundle_add(b, "_RESTRICTION_LIMIT_", limit);
+       }
+
+       ret = syspopup_launch("net.stc-popup", b);
+       if (ret < 0) {
+               g_timeout_add_seconds(STC_SYSPOPUP_TIMER, __stc_syspopup_timer_cb, b);
+               STC_LOGE("Popup launch failed...retry %d", ret);
+               return STC_ERROR_NONE;
+       }
+
+       bundle_free(b);
+       __STC_LOG_FUNC_EXIT__;
+       return STC_ERROR_NONE;
 }
 
 API stc_plugin_popup_s stc_plugin_popup = {