From 351b07a598087248501114028a40d554c7a1604e Mon Sep 17 00:00:00 2001 From: SukhyungKang Date: Wed, 1 Dec 2021 23:03:26 +0900 Subject: [PATCH] Add launch reqeust sequence when it's failed to launch default viewer Change-Id: I3a3e53976edcc44172977f8df3961d4a60dda8e9 Signed-off-by: SukhyungKang --- notification/src/notification_viewer.c | 83 ++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/notification/src/notification_viewer.c b/notification/src/notification_viewer.c index 6a42ce3..69ef54b 100644 --- a/notification/src/notification_viewer.c +++ b/notification/src/notification_viewer.c @@ -17,10 +17,12 @@ #define _GNU_SOURCE #include #include +#include #include #include #include +#include #include #include @@ -29,6 +31,14 @@ #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); -- 2.7.4