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);
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();
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 */
}
/* 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,
_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 */
}
/* LCOV_EXCL_STOP */
+/* LCOV_EXCL_START */
int notification_ipc_request_insert(notification_h noti, int *priv_id)
{
int result;
WARN("priv_id[%d] result[%d]", id, result);
return result;
}
+/* LCOV_EXCL_STOP */
int notification_ipc_request_update(notification_h noti)
{
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;
+}