Add launch reqeust sequence when it's failed to launch default viewer 32/267332/7
authorSukhyungKang <shine.kang@samsung.com>
Wed, 1 Dec 2021 14:03:26 +0000 (23:03 +0900)
committerSukhyungKang <shine.kang@samsung.com>
Thu, 2 Dec 2021 06:07:50 +0000 (15:07 +0900)
Change-Id: I3a3e53976edcc44172977f8df3961d4a60dda8e9
Signed-off-by: SukhyungKang <shine.kang@samsung.com>
notification/src/notification_viewer.c

index 6a42ce3..69ef54b 100644 (file)
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
+#include <glib.h>
 
 #include <app_control_internal.h>
 #include <iniparser.h>
 #include <aul_svc.h>
+#include <aul_app_lifecycle.h>
 
 #include <notification.h>
 #include <notification_debug.h>
 #define DEFAULT_VIEWER_CONF_FILE "/usr/share/notification/notification.ini"
 static char *_default_viewer;
 
+static GList *_delayed_noti_list;
+static int _cb_registered = -1;
+
+typedef struct delayed_noti {
+       uid_t uid;
+       bundle *noti_info;
+} delayed_noti_info_s;
+
 /* LCOV_EXCL_START */
 EXPORT_API int notification_init_default_viewer()
 {
@@ -59,6 +69,77 @@ EXPORT_API int notification_init_default_viewer()
 }
 /* LCOV_EXCL_STOP */
 
+static int __pop_delayed_noti() {
+       delayed_noti_info_s *noti = g_list_nth_data(_delayed_noti_list, 0);
+
+       int ret = aul_svc_run_service_async_for_uid(noti->noti_info,
+                       0, NULL, NULL, noti->uid);
+       if (ret < 0) {
+               ERR("Failed to request app launch[%d]", ret);
+               return ret;
+       }
+
+       _delayed_noti_list = g_list_remove(_delayed_noti_list, noti);
+
+       bundle_free(noti->noti_info);
+       free(noti);
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+static void __aul_app_lifecycle_state_changed_cb(const char *app_id, pid_t pid,
+               aul_app_lifecycle_state_e state, bool has_focus, void *user_data) {
+       int ret;
+
+       if (strncmp(app_id, _default_viewer, strlen(app_id)))
+               return;
+
+       if (state == AUL_APP_LIFECYCLE_STATE_CREATED ||
+               state == AUL_APP_LIFECYCLE_STATE_DESTROYED) {
+               while (g_list_length(_delayed_noti_list) != 0) {
+                       ret = __pop_delayed_noti();
+                       if (ret != NOTIFICATION_ERROR_NONE) {
+                               ERR("Failed to pop delayed noti");
+                               return;
+                       }
+               }
+
+               ret = aul_app_lifecycle_deregister_state_changed_cb();
+               if (ret == AUL_R_OK)
+                       _cb_registered = -1;
+               else
+                       ERR("Failed to deregister lifecycle cb");
+       }
+}
+
+static int __push_delayed_noti(bundle *noti_info, uid_t uid) {
+       delayed_noti_info_s *noti = (delayed_noti_info_s *)calloc(1,
+                       sizeof(delayed_noti_info_s));
+       if (noti == NULL) {
+               ERR("Failed to calloc delayed noti info");
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       noti->uid = uid;
+       noti->noti_info = bundle_dup(noti_info);
+       if (noti->noti_info == NULL) {
+               ERR("Failed to bundle_dup ");
+               free(noti);
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       _delayed_noti_list = g_list_append(_delayed_noti_list, noti);
+
+       if (_cb_registered) {
+               _cb_registered = aul_app_lifecycle_register_state_changed_cb(
+                               __aul_app_lifecycle_state_changed_cb, NULL);
+               if (_cb_registered)
+                       ERR("Failed to register app lifecycle cb");
+       }
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
 /* LCOV_EXCL_START */
 EXPORT_API int notification_launch_default_viewer(int priv_id,
                notification_op_type_e status, uid_t uid)
@@ -102,6 +183,8 @@ EXPORT_API int notification_launch_default_viewer(int priv_id,
        ret = aul_svc_run_service_async_for_uid(b, 0, NULL, NULL, uid);
        if (ret < 0) {
                ERR("Failed to request app launch[%d]", ret);
+               if (__push_delayed_noti(b, uid) != NOTIFICATION_ERROR_NONE)
+                       ERR("Failed to push delayed noti");
        } else {
                INFO("successed to request app launch[%d],[%d]",
                                ret, uid);