Add apis for do not disturb app 90/318090/7
authorSukhyungKang <shine.kang@samsung.com>
Tue, 24 Sep 2024 10:37:26 +0000 (19:37 +0900)
committerSukhyungKang <shine.kang@samsung.com>
Mon, 30 Sep 2024 06:31:58 +0000 (15:31 +0900)
- add apis to support do not disturb app (dnd app)
during the dnd app is running, notification viewer is not launched.
if the dnd app is terminated, notification viewer is launched.
if posted notification type is pairing type, request to terminate dnd app.
it's terminated launch notification viewer.

Change-Id: I40e7e8a06e07d48ceaea840eef8e852ef19eaf42
Signed-off-by: SukhyungKang <shine.kang@samsung.com>
notification/include/notification_internal.h
notification/include/notification_ipc.h
notification/include/notification_private.h
notification/src/notification_internal.c
notification/src/notification_ipc.c

index c5fef25bc6dccfb4d5d5b61733819f73b9f55cce..ce1c27569cc920e05f748a8d641bacdc03764f4d 100644 (file)
@@ -1503,6 +1503,12 @@ int notification_get_check_box(notification_h noti, bool *flag, bool *checked);
 int notification_set_check_box_checked(notification_h noti, bool checked);
 int notification_get_check_box_checked(notification_h noti, bool *checked);
 
+typedef void (*disturb_cb)(void *user_data);
+int notification_register_do_not_disturb_app(disturb_cb callback, void *user_data);
+int notification_unregister_do_not_disturb_app(void);
+int notification_set_pairing_type(notification_h noti, bool pairing);
+int notification_get_pairing_type(notification_h noti, bool *pairing);
+
 
 /**
  * @}
index 188993105750541f34c1fe0df9480d5c922140b5..9ba73427d5dc0dbf815bbedd5675fc87e85c43fb 100644 (file)
@@ -109,6 +109,9 @@ int notification_ipc_socket_write_string(int fd, const char *buffer, unsigned in
 int notification_ipc_socket_read(int fd, char *buffer, unsigned int nbytes);
 
 int notification_ipc_event_monitor_init(void);
+
+int notification_ipc_request_register_dnd_app(uid_t uid, pid_t pid);
+
 #ifdef __cplusplus
 }
 #endif
index 4b72183b9a858b205e2bde7d04373d10e9b1f3e6..b24eb5d192acc871c89cbbe78eeb015e228add1d 100644 (file)
@@ -192,6 +192,8 @@ void notification_call_event_handler_cb(notification_h noti, int event_type);
 void notification_delete_event_handler_cb(int priv_id);
 char *notification_get_app_id_by_pid(int pid);
 
+void notification_call_disturb_cb(void);
+
 #ifdef __cplusplus
 }
 #endif
index 22779df9d972416adc75b9fcaeaf4ad4d55e7dd1..4d43df14d2a9845b74e20eb9f8854bd3bdd33802 100644 (file)
@@ -73,6 +73,9 @@ static GList *__noti_event_cb_list = NULL;
 
 static GRecMutex __rec_mutex;
 
+static disturb_cb _disturb_callback = NULL;
+static void *_disturb_user_data = NULL;
+
 NOTIFICATION_CTOR static void __notification_init(void)
 {
        g_rec_mutex_init(&__rec_mutex);
@@ -236,7 +239,7 @@ void notification_delete_event_handler_cb(int priv_id)
        if (info)
                free(info);
 
-       if (__noti_event_cb_list == NULL)
+       if (__noti_event_cb_list == NULL && _disturb_callback == NULL)
                notification_ipc_event_monitor_fini();
 
        __notification_mutex_unlock();
@@ -2386,3 +2389,117 @@ EXPORT_API int notification_get_check_box_checked(notification_h noti,
        return NOTIFICATION_ERROR_NONE;
 }
 /* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
+EXPORT_API int notification_register_do_not_disturb_app(disturb_cb callback, void *user_data)
+{
+       int ret;
+
+       WARN("register dnd app");
+
+       if (callback == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       __notification_mutex_lock();
+
+       ret = notification_ipc_request_register_dnd_app(getuid(), getpid());
+       if (ret != NOTIFICATION_ERROR_NONE)
+               goto out;
+
+       ret = notification_ipc_event_monitor_init();
+       if (ret != NOTIFICATION_ERROR_NONE)
+               goto out;
+
+       _disturb_callback = callback;
+       _disturb_user_data = user_data;
+
+out:
+       __notification_mutex_unlock();
+
+       WARN("register dnd app done");
+
+       return ret;
+}
+
+EXPORT_API int notification_unregister_do_not_disturb_app(void)
+{
+       WARN("unregister dnd app");
+
+       _disturb_callback = NULL;
+
+       if (__noti_event_cb_list == NULL)
+               notification_ipc_event_monitor_fini();
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+void notification_call_disturb_cb(void)
+{
+       WARN("call disturb callback");
+
+       if (_disturb_callback == NULL) {
+               ERR("no disturb callback");
+               return;
+       }
+
+       _disturb_callback(_disturb_user_data);
+
+       WARN("done");
+}
+/* LCOV_EXCL_STOP */
+
+#define PAIRING_TYPE_KEY "_NOTIFICATION_TYPE_PAIRING_"
+
+/* LCOV_EXCL_START */
+EXPORT_API int notification_set_pairing_type(notification_h noti, bool pairing)
+{
+       char *del = NULL;
+
+       WARN("set pairing");
+
+       if (noti == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       if (noti->args == NULL)
+               noti->args = bundle_create();
+
+       bundle_get_str(noti->args, PAIRING_TYPE_KEY, &del);
+       if (del != NULL) {
+               bundle_del(noti->args, PAIRING_TYPE_KEY);
+               del = NULL;
+       }
+
+       if (pairing)
+               bundle_add_str(noti->args, PAIRING_TYPE_KEY, "true");
+       else
+               bundle_add_str(noti->args, PAIRING_TYPE_KEY, "false");
+
+       WARN("set pairing done");
+
+       return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API int notification_get_pairing_type(notification_h noti, bool *pairing)
+{
+       int ret;
+       char *value = NULL;
+
+       WARN("get pairing");
+
+       if (noti == NULL || noti->args == NULL || pairing == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       ret = bundle_get_str(noti->args, PAIRING_TYPE_KEY, &value);
+       if (ret != BUNDLE_ERROR_NONE || value == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       if (strcmp("true", value) == 0)
+               *pairing = true;
+       else
+               *pairing = false;
+
+       WARN("get pairing done");
+
+       return NOTIFICATION_ERROR_NONE;
+}
+/* LCOV_EXCL_STOP */
index 62a08e2b7b9beef717972538672cb0daf35287b8..f3c08c96643187e7cf82f7c735e75db96749e807 100644 (file)
@@ -635,6 +635,13 @@ static void _delete_event(GVariant *parameters)
 }
 /* LCOV_EXCL_STOP */
 
+/* LCOV_EXCL_START */
+static void _disturb_app(GVariant *parameters)
+{
+       notification_call_disturb_cb();
+}
+/* LCOV_EXCL_STOP */
+
 /* LCOV_EXCL_START */
 static void _handle_noti_event_handler_notify(GDBusConnection *connection,
                const gchar     *sender_name,
@@ -651,6 +658,8 @@ static void _handle_noti_event_handler_notify(GDBusConnection *connection,
                _send_event(parameters);
        else if (g_strcmp0(signal_name, "delete_noti") == 0)
                _delete_event(parameters);
+       else if (g_strcmp0(signal_name, "disturb_app") == 0)
+               _disturb_app(parameters);
 }
 /* LCOV_EXCL_STOP */
 
@@ -928,6 +937,7 @@ static int _send_async_noti(GVariant *body, result_cb_item *cb_item, char *cmd)
 }
 /* LCOV_EXCL_STOP */
 
+/* LCOV_EXCL_START */
 int notification_ipc_request_insert(notification_h noti, int *priv_id)
 {
        int result;
@@ -975,6 +985,7 @@ int notification_ipc_request_insert(notification_h noti, int *priv_id)
        WARN("priv_id[%d] result[%d]", id, result);
        return result;
 }
+/* LCOV_EXCL_STOP */
 
 int notification_ipc_request_update(notification_h noti)
 {
@@ -2728,3 +2739,27 @@ int notification_ipc_event_monitor_init(void)
        return _dbus_event_handler_signal_init();
 }
 /* LCOV_EXCL_STOP */
+
+int notification_ipc_request_register_dnd_app(uid_t uid, pid_t pid)
+{
+       int ret;
+       GVariant *body;
+       GDBusMessage *reply = NULL;
+
+       WARN("request register dnd app");
+       ret = _dbus_init();
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Failed to init dbus connection[%d]", ret);
+               return ret;
+       }
+
+       body = g_variant_new("(ii)", uid, pid);
+
+       ret = _send_sync_noti(body, &reply, "register_dnd_app");
+       if (reply)
+               g_object_unref(reply);
+
+       WARN("send sync noti [%d]", ret);
+
+       return ret;
+}