summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCMakeLists.txt3
-rw-r--r--include/notification_private.h6
-rw-r--r--include/notification_setting_internal.h26
-rw-r--r--include/notification_setting_service.h8
-rwxr-xr-xpackaging/notification.spec1
-rwxr-xr-xsrc/notification_db.c6
-rwxr-xr-xsrc/notification_ipc.c57
-rwxr-xr-xsrc/notification_noti.c21
-rwxr-xr-xsrc/notification_setting.c181
-rw-r--r--src/notification_setting_service.c261
10 files changed, 464 insertions, 106 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9bd1961..0c323b8 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,6 +67,7 @@ pkg_check_modules(pkgs REQUIRED
libtzplatform-config
glib-2.0
gio-2.0
+ alarm-service
)
FOREACH(flag ${pkgs_CFLAGS})
@@ -105,4 +106,4 @@ FOREACH(hfile ${HEADERS-DEVEL})
ENDFOREACH(hfile)
INSTALL(FILES ${CMAKE_BINARY_DIR}/11_notification-add.post DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d/)
-INSTALL(TARGETS notification_init DESTINATION bin) \ No newline at end of file
+INSTALL(TARGETS notification_init DESTINATION bin)
diff --git a/include/notification_private.h b/include/notification_private.h
index 9e2ad85..50c59e9 100644
--- a/include/notification_private.h
+++ b/include/notification_private.h
@@ -95,6 +95,12 @@ struct _notification {
struct notification_system_setting {
bool do_not_disturb;
int visibility_class;
+ bool dnd_schedule_enabled;
+ int dnd_schedule_day;
+ int dnd_start_hour;
+ int dnd_start_min;
+ int dnd_end_hour;
+ int dnd_end_min;
};
typedef enum notification_data_type {
diff --git a/include/notification_setting_internal.h b/include/notification_setting_internal.h
index ada5059..9c84a30 100644
--- a/include/notification_setting_internal.h
+++ b/include/notification_setting_internal.h
@@ -26,6 +26,20 @@
extern "C" {
#endif
+/**
+* @brief Enumeration for Week Flag, the days of the week.
+* @since_tizen 3.0
+*/
+typedef enum {
+ DND_SCHEDULE_WEEK_FLAG_SUNDAY = 0x01, /**< Sunday */
+ DND_SCHEDULE_WEEK_FLAG_MONDAY = 0x02, /**< Monday */
+ DND_SCHEDULE_WEEK_FLAG_TUESDAY = 0x04, /**< Tuesday */
+ DND_SCHEDULE_WEEK_FLAG_WEDNESDAY = 0x08, /**< Wednesday */
+ DND_SCHEDULE_WEEK_FLAG_THURSDAY = 0x10, /**< Thursday */
+ DND_SCHEDULE_WEEK_FLAG_FRIDAY = 0x20, /**< Friday */
+ DND_SCHEDULE_WEEK_FLAG_SATURDAY = 0x40, /**< Saturday */
+} dnd_schedule_week_flag_e;
+
/* Application setting */
struct notification_setting {
char *package_name;
@@ -71,6 +85,18 @@ int notification_system_setting_set_do_not_disturb(notification_system_setting_h
int notification_system_setting_get_visibility_class(notification_system_setting_h system_setting, int *value);
int notification_system_setting_set_visibility_class(notification_system_setting_h system_setting, int value);
+int notification_system_setting_dnd_schedule_get_enabled(notification_system_setting_h system_setting, bool *enabled);
+int notification_system_setting_dnd_schedule_set_enabled(notification_system_setting_h system_setting, bool enabled);
+
+int notification_system_setting_dnd_schedule_get_day(notification_system_setting_h system_setting, int *day);
+int notification_system_setting_dnd_schedule_set_day(notification_system_setting_h system_setting, int day);
+
+int notification_system_setting_dnd_schedule_get_start_time(notification_system_setting_h system_setting, int *hour, int *min);
+int notification_system_setting_dnd_schedule_set_start_time(notification_system_setting_h system_setting, int hour, int min);
+
+int notification_system_setting_dnd_schedule_get_end_time(notification_system_setting_h system_setting, int *hour, int *min);
+int notification_system_setting_dnd_schedule_set_end_time(notification_system_setting_h system_setting, int hour, int min);
+
/* OLD IMPLEMENTATION */
int notification_setting_property_set(const char *pkgname, const char *property, const char *value) NOTIFICATION_DEPRECATED_API;
int notification_setting_property_get(const char *pkgname, const char *property, char **value) NOTIFICATION_DEPRECATED_API;
diff --git a/include/notification_setting_service.h b/include/notification_setting_service.h
index 3278a31..7dabc5b 100644
--- a/include/notification_setting_service.h
+++ b/include/notification_setting_service.h
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <notification.h>
+#include <alarm.h>
#ifdef __cplusplus
extern "C" {
@@ -28,11 +29,16 @@ int notification_setting_db_set(const char *pkgname, const char *property, const
int notification_setting_db_get(const char *pkgname, const char *property, char **value);
int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class, uid_t uid);
-int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class, uid_t uid);
+int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class,
+ int dnd_schedule_enabled, int dnd_schedule_day,
+ int dnd_start_hour, int dnd_start_min,
+ int dnd_end_hour, int dnd_end_min, uid_t uid);
+int notification_setting_db_update_do_not_disturb(int do_not_disturb, uid_t uid);
int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting, uid_t uid);
int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid);
int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid);
+int noti_system_setting_set_alarm(int week_flag, int hour, int min, alarm_cb_t handler, alarm_id_t *dnd_schedule_alarm_id);
#ifdef __cplusplus
}
diff --git a/packaging/notification.spec b/packaging/notification.spec
index 0295744..01f3105 100755
--- a/packaging/notification.spec
+++ b/packaging/notification.spec
@@ -23,6 +23,7 @@ BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(alarm-service)
BuildRequires: cmake
Requires(post): /sbin/ldconfig
diff --git a/src/notification_db.c b/src/notification_db.c
index b950c3f..cf90595 100755
--- a/src/notification_db.c
+++ b/src/notification_db.c
@@ -130,6 +130,12 @@ create table if not exists noti_list ( \
uid INTEGER, \
do_not_disturb INTEGER DEFAULT 0, \
visibility_class INTEGER DEFAULT 0, \
+ dnd_schedule_enabled INTEGER DEFAULT 0, \
+ dnd_schedule_day INTEGER DEFAULT 0, \
+ dnd_start_hour INTEGER DEFAULT 0, \
+ dnd_start_min INTEGER DEFAULT 0, \
+ dnd_end_hour INTEGER DEFAULT 0, \
+ dnd_end_min INTEGER DEFAULT 0, \
UNIQUE (uid) \
);"
diff --git a/src/notification_ipc.c b/src/notification_ipc.c
index b437e9a..a758897 100755
--- a/src/notification_ipc.c
+++ b/src/notification_ipc.c
@@ -1293,9 +1293,15 @@ int notification_ipc_update_system_setting(notification_system_setting_h system_
return result;
}
- body = g_variant_new("(iii)",
+ body = g_variant_new("(iiiiiiiii)",
(int)(system_setting->do_not_disturb),
(int)(system_setting->visibility_class),
+ (int)(system_setting->dnd_schedule_enabled),
+ (int)(system_setting->dnd_schedule_day),
+ (int)(system_setting->dnd_start_hour),
+ (int)(system_setting->dnd_start_min),
+ (int)(system_setting->dnd_end_hour),
+ (int)(system_setting->dnd_end_min),
uid);
result = _send_sync_noti(body, &reply, "update_noti_sys_setting");
@@ -1687,9 +1693,15 @@ EXPORT_API int notification_ipc_make_noti_from_gvariant(notification_h noti,
EXPORT_API GVariant *notification_ipc_make_gvariant_from_system_setting(struct notification_system_setting *noti_setting)
{
GVariant *body = NULL;
- body = g_variant_new("(ii)",
+ body = g_variant_new("(iiiiiiii)",
noti_setting->do_not_disturb,
- noti_setting->visibility_class);
+ noti_setting->visibility_class,
+ noti_setting->dnd_schedule_enabled,
+ noti_setting->dnd_schedule_day,
+ noti_setting->dnd_start_hour,
+ noti_setting->dnd_start_min,
+ noti_setting->dnd_end_hour,
+ noti_setting->dnd_end_min);
return body;
}
@@ -1698,24 +1710,47 @@ EXPORT_API int notification_ipc_make_system_setting_from_gvariant(struct notific
{
int do_not_disturb;
int visibility_class;
+ int dnd_schedule_enabled;
+ int dnd_schedule_day;
+ int dnd_start_hour;
+ int dnd_start_min;
+ int dnd_end_hour;
+ int dnd_end_min;
if (noti_setting == NULL) {
NOTIFICATION_ERR("invalid data");
return NOTIFICATION_ERROR_INVALID_PARAMETER;
}
+
g_variant_get(variant,
- "(ii)",
+ "(iiiiiiii)",
&do_not_disturb,
- &visibility_class);
-
- NOTIFICATION_DBG("system setting #### %d, %d",
- do_not_disturb, visibility_class);
+ &visibility_class,
+ &dnd_schedule_enabled,
+ &dnd_schedule_day,
+ &dnd_start_hour,
+ &dnd_start_min,
+ &dnd_end_hour,
+ &dnd_end_min);
+
+ NOTIFICATION_DBG("system setting #### %d, %d, %d, %d, [%d:%d] [%d:%d]",
+ do_not_disturb, visibility_class,
+ dnd_schedule_enabled, dnd_schedule_day,
+ dnd_start_hour, dnd_start_min, dnd_end_hour, dnd_end_min);
noti_setting->do_not_disturb = do_not_disturb;
noti_setting->visibility_class = visibility_class;
-
- NOTIFICATION_DBG("system setting2 #### %d, %d",
- noti_setting->do_not_disturb, noti_setting->visibility_class);
+ noti_setting->dnd_schedule_enabled = dnd_schedule_enabled;
+ noti_setting->dnd_schedule_day = dnd_schedule_day;
+ noti_setting->dnd_start_hour = dnd_start_hour;
+ noti_setting->dnd_start_min = dnd_start_min;
+ noti_setting->dnd_end_hour = dnd_end_hour;
+ noti_setting->dnd_end_min = dnd_end_min;
+
+ NOTIFICATION_DBG("system setting2 #### %d, %d, %d",
+ noti_setting->do_not_disturb,
+ noti_setting->visibility_class,
+ noti_setting->dnd_schedule_enabled);
return NOTIFICATION_ERROR_NONE;
}
diff --git a/src/notification_noti.c b/src/notification_noti.c
index 6cc1b37..dae576a 100755
--- a/src/notification_noti.c
+++ b/src/notification_noti.c
@@ -779,23 +779,25 @@ static int _handle_do_not_disturb_option(notification_h noti)
bool do_not_disturb = false;
bool do_not_disturb_exception = false;
char *package_id = NULL;
- notification_system_setting_h system_setting = NULL;
notification_setting_h setting = NULL;
+ notification_system_setting_h system_setting = NULL;
+
if (noti == NULL) {
NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
- err = NOTIFICATION_ERROR_INVALID_PARAMETER;
- goto out;
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
}
/* Get system setting */
- if ((err = noti_system_setting_load_system_setting(&system_setting, noti->uid)) != NOTIFICATION_ERROR_NONE) {
- NOTIFICATION_ERR("noti_system_setting_load_system_setting failed [%d]", err);
+ err = noti_system_setting_load_system_setting(&system_setting, noti->uid);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ NOTIFICATION_ERR("_load_system_setting failed [%d]", err);
goto out;
}
- if ((err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb)) != NOTIFICATION_ERROR_NONE) {
- NOTIFICATION_ERR("notification_system_setting_get_do_not_disturb failed [%d]", err);
+ err = notification_system_setting_get_do_not_disturb(system_setting, &do_not_disturb);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ NOTIFICATION_ERR("_get_do_not_disturb failed [%d]", err);
goto out;
}
@@ -804,18 +806,16 @@ static int _handle_do_not_disturb_option(notification_h noti)
if (do_not_disturb) {
/* Check exception option of the caller package */
err = noti_setting_service_get_setting_by_package_name(noti->caller_pkgname, &setting, noti->uid);
-
if (err != NOTIFICATION_ERROR_NONE) {
/* Retry with package id */
err = _get_package_id_by_app_id(noti->caller_pkgname, &package_id);
-
if (err != NOTIFICATION_ERROR_NONE || package_id == NULL) {
NOTIFICATION_ERR("_get_package_id_by_app_id failed [%d]", err);
goto out;
} else {
err = noti_setting_service_get_setting_by_package_name(package_id, &setting, noti->uid);
if (err != NOTIFICATION_ERROR_NONE) {
- NOTIFICATION_ERR("noti_setting_service_get_setting_by_package_name failed [%d]", err);
+ NOTIFICATION_ERR("_get_setting_by_package_name failed [%d]", err);
goto out;
}
}
@@ -841,7 +841,6 @@ static int _handle_do_not_disturb_option(notification_h noti)
noti->led_on_ms = 0;
noti->led_off_ms = 0;
}
-
}
out:
diff --git a/src/notification_setting.c b/src/notification_setting.c
index cf8daae..e2e290b 100755
--- a/src/notification_setting.c
+++ b/src/notification_setting.c
@@ -283,44 +283,6 @@ out:
return err;
}
-EXPORT_API int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class, uid_t uid)
-{
- int err = NOTIFICATION_ERROR_NONE;
- sqlite3 *db = NULL;
- char *sqlbuf = NULL;
- int sqlret;
-
- if (package_name == NULL || strlen(package_name) == 0)
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
- sqlret = db_util_open(DBPATH, &db, 0);
- if (sqlret != SQLITE_OK || db == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
- return NOTIFICATION_ERROR_FROM_DB;
- }
-
- sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d " \
- "WHERE package_name = %Q AND uid = %d",
- NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class, package_name, uid);
- if (!sqlbuf) {
- NOTIFICATION_ERR("fail to alloc query");
- err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
- goto return_close_db;
- }
-
- err = notification_db_exec(db, sqlbuf, NULL);
-
-return_close_db:
- if (sqlbuf)
- sqlite3_free(sqlbuf);
-
- sqlret = db_util_close(db);
- if (sqlret != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
-
- return err;
-}
-
static bool _is_package_in_setting_table(sqlite3 *db, const char *package_name, uid_t uid)
{
sqlite3_stmt *db_statement = NULL;
@@ -714,66 +676,133 @@ out:
return err;
}
+EXPORT_API int notification_system_setting_dnd_schedule_get_enabled(notification_system_setting_h system_setting, bool *enabled)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+
+ if (system_setting == NULL || enabled == NULL) {
+ NOTIFICATION_ERR("Invalid parameter\n");
+ err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
+
+ *enabled = system_setting->dnd_schedule_enabled;
+out:
+ return err;
+}
-EXPORT_API int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class, uid_t uid)
+EXPORT_API int notification_system_setting_dnd_schedule_set_enabled(notification_system_setting_h system_setting, bool enabled)
{
int err = NOTIFICATION_ERROR_NONE;
- int sqlret;
- int field_index = 1;
- sqlite3 *db = NULL;
- sqlite3_stmt *db_statement = NULL;
- sqlret = db_util_open(DBPATH, &db, 0);
+ if (system_setting == NULL) {
+ NOTIFICATION_ERR("Invalid parameter\n");
+ err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
+
+ system_setting->dnd_schedule_enabled = enabled;
- if (sqlret != SQLITE_OK || db == NULL) {
- NOTIFICATION_ERR("db_util_open failed [%s][%d][%s]", DBPATH, sqlret, sqlite3_errmsg(db));
- err = NOTIFICATION_ERROR_FROM_DB;
- goto return_close_db;
+out:
+ return err;
+}
+
+EXPORT_API int notification_system_setting_dnd_schedule_get_day(notification_system_setting_h system_setting, int *day)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+
+ if (system_setting == NULL || day == NULL) {
+ NOTIFICATION_ERR("Invalid parameter\n");
+ err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+ goto out;
}
- sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
- sqlret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO notification_system_setting (uid, do_not_disturb, visibility_class) values(?, ?, ?);", -1, &db_statement, NULL);
+ *day = system_setting->dnd_schedule_day;
- if (sqlret != SQLITE_OK) {
- NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret, sqlite3_errmsg(db));
- err = NOTIFICATION_ERROR_FROM_DB;
- goto return_close_db;
+out:
+ return err;
+}
+
+EXPORT_API int notification_system_setting_dnd_schedule_set_day(notification_system_setting_h system_setting, int day)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+
+ if (system_setting == NULL) {
+ NOTIFICATION_ERR("Invalid parameter\n");
+ err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+ goto out;
}
- sqlite3_bind_int(db_statement, field_index++, uid);
- sqlite3_bind_int(db_statement, field_index++, do_not_disturb);
- sqlite3_bind_int(db_statement, field_index++, visibility_class);
+ system_setting->dnd_schedule_day = day;
+
+out:
+ return err;
+}
+
+EXPORT_API int notification_system_setting_dnd_schedule_get_start_time(notification_system_setting_h system_setting, int *hour, int *min)
+{
+ int err = NOTIFICATION_ERROR_NONE;
- sqlret = sqlite3_step(db_statement);
- if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) {
- NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlret, sqlite3_errmsg(db));
- err = NOTIFICATION_ERROR_FROM_DB;
- goto return_close_db;
+ if (system_setting == NULL || hour == NULL || min == NULL) {
+ NOTIFICATION_ERR("Invalid parameter\n");
+ err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+ goto out;
}
- sqlret = sqlite3_changes(db);
+ *hour = system_setting->dnd_start_hour;
+ *min = system_setting->dnd_start_min;
- if (sqlret == 0)
- NOTIFICATION_WARN("No changes on DB");
+out:
+ return err;
+}
+EXPORT_API int notification_system_setting_dnd_schedule_set_start_time(notification_system_setting_h system_setting, int hour, int min)
+{
+ int err = NOTIFICATION_ERROR_NONE;
-return_close_db:
- if (db_statement)
- sqlite3_finalize(db_statement);
+ if (system_setting == NULL) {
+ NOTIFICATION_ERR("Invalid parameter\n");
+ err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
+ system_setting->dnd_start_hour = hour;
+ system_setting->dnd_start_min = min;
- if (db) {
- if (err == NOTIFICATION_ERROR_NONE)
- sqlite3_exec(db, "END;", NULL, NULL, NULL);
- else
- sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+out:
+ return err;
+}
- sqlret = db_util_close(db);
+EXPORT_API int notification_system_setting_dnd_schedule_get_end_time(notification_system_setting_h system_setting, int *hour, int *min)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+
+ if (system_setting == NULL || hour == NULL || min == NULL) {
+ NOTIFICATION_ERR("Invalid parameter\n");
+ err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+ goto out;
}
- if (sqlret != SQLITE_OK)
- NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+ *hour = system_setting->dnd_end_hour;
+ *min = system_setting->dnd_end_min;
+out:
return err;
}
+EXPORT_API int notification_system_setting_dnd_schedule_set_end_time(notification_system_setting_h system_setting, int hour, int min)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+
+ if (system_setting == NULL) {
+ NOTIFICATION_ERR("Invalid parameter\n");
+ err = NOTIFICATION_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
+
+ system_setting->dnd_end_hour = hour;
+ system_setting->dnd_end_min = min;
+
+out:
+ return err;
+}
diff --git a/src/notification_setting_service.c b/src/notification_setting_service.c
index 86f873a..979124c 100644
--- a/src/notification_setting_service.c
+++ b/src/notification_setting_service.c
@@ -89,7 +89,23 @@ out:
return ret;
}
-EXPORT_API int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting, uid_t uid)
+static int _get_current_time(struct tm *date)
+{
+ time_t now;
+
+ if (date == NULL) {
+ NOTIFICATION_ERR("NOTIFICATION_ERROR_INVALID_PARAMETER");
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
+ }
+
+ time(&now);
+ localtime_r(&now, date);
+
+ return NOTIFICATION_ERROR_NONE;
+}
+
+EXPORT_API
+int noti_setting_service_get_setting_by_package_name(const char *package_name, notification_setting_h *setting, uid_t uid)
{
int err = NOTIFICATION_ERROR_NONE;
sqlite3 *local_db_handle = NULL;
@@ -175,9 +191,8 @@ out:
return err;
}
-
-
-EXPORT_API int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid)
+EXPORT_API
+int noti_setting_get_setting_array(notification_setting_h *setting_array, int *count, uid_t uid)
{
int err = NOTIFICATION_ERROR_NONE;
sqlite3 *local_db_handle = NULL;
@@ -264,7 +279,8 @@ out:
}
-EXPORT_API int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid)
+EXPORT_API
+int noti_system_setting_load_system_setting(notification_system_setting_h *system_setting, uid_t uid)
{
int err = NOTIFICATION_ERROR_NONE;
sqlite3 *local_db_handle = NULL;
@@ -290,7 +306,9 @@ EXPORT_API int noti_system_setting_load_system_setting(notification_system_setti
goto out;
}
- sql_query = sqlite3_mprintf("SELECT do_not_disturb, visibility_class "
+ sql_query = sqlite3_mprintf("SELECT do_not_disturb, visibility_class, "
+ "dnd_schedule_enabled, dnd_schedule_day, "
+ "dnd_start_hour, dnd_start_min, dnd_end_hour, dnd_end_min "
"FROM %s WHERE uid = %d", NOTIFICATION_SYSTEM_SETTING_DB_TABLE, uid);
if (!sql_query) {
@@ -319,11 +337,23 @@ EXPORT_API int noti_system_setting_load_system_setting(notification_system_setti
NOTIFICATION_DBG("No setting found..."); /* LCOV_EXCL_LINE */
result_system_setting->do_not_disturb = 0;
result_system_setting->visibility_class = 0;
+ result_system_setting->dnd_schedule_enabled = 0;
+ result_system_setting->dnd_schedule_day = 0;
+ result_system_setting->dnd_start_hour = 0;
+ result_system_setting->dnd_start_min = 0;
+ result_system_setting->dnd_end_hour = 0;
+ result_system_setting->dnd_end_min = 0;
} else {
/* LCOV_EXCL_START */
col_index = column_count;
_get_table_field_data_int(query_result, (int *)&(result_system_setting->do_not_disturb), col_index++);
_get_table_field_data_int(query_result, &(result_system_setting->visibility_class), col_index++);
+ _get_table_field_data_int(query_result, (int *)&(result_system_setting->dnd_schedule_enabled), col_index++);
+ _get_table_field_data_int(query_result, &(result_system_setting->dnd_schedule_day), col_index++);
+ _get_table_field_data_int(query_result, &(result_system_setting->dnd_start_hour), col_index++);
+ _get_table_field_data_int(query_result, &(result_system_setting->dnd_start_min), col_index++);
+ _get_table_field_data_int(query_result, &(result_system_setting->dnd_end_hour), col_index++);
+ _get_table_field_data_int(query_result, &(result_system_setting->dnd_end_min), col_index++);
/* LCOV_EXCL_STOP */
}
@@ -344,3 +374,222 @@ out:
return err;
}
+EXPORT_API
+int notification_setting_db_update(const char *package_name, int allow_to_notify, int do_not_disturb_except, int visibility_class, uid_t uid)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+ sqlite3 *db = NULL;
+ char *sqlbuf = NULL;
+ int sqlret;
+
+ if (package_name == NULL || strlen(package_name) == 0)
+ return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+ sqlret = db_util_open(DBPATH, &db, 0);
+ if (sqlret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
+ return NOTIFICATION_ERROR_FROM_DB;
+ }
+
+ sqlbuf = sqlite3_mprintf("UPDATE %s SET allow_to_notify = %d, do_not_disturb_except = %d, visibility_class = %d " \
+ "WHERE package_name = %Q AND uid = %d",
+ NOTIFICATION_SETTING_DB_TABLE, allow_to_notify, do_not_disturb_except, visibility_class, package_name, uid);
+ if (!sqlbuf) {
+ NOTIFICATION_ERR("fail to alloc query");
+ err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto return_close_db;
+ }
+
+ err = notification_db_exec(db, sqlbuf, NULL);
+
+return_close_db:
+ if (sqlbuf)
+ sqlite3_free(sqlbuf);
+
+ sqlret = db_util_close(db);
+ if (sqlret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+
+ return err;
+}
+
+EXPORT_API
+int notification_setting_db_update_system_setting(int do_not_disturb, int visibility_class,
+ int dnd_schedule_enabled, int dnd_schedule_day,
+ int dnd_start_hour, int dnd_start_min,
+ int dnd_end_hour, int dnd_end_min, uid_t uid)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+ int sqlret;
+ int field_index = 1;
+ sqlite3 *db = NULL;
+ sqlite3_stmt *db_statement = NULL;
+
+ sqlret = db_util_open(DBPATH, &db, 0);
+
+ if (sqlret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d][%s]", DBPATH, sqlret, sqlite3_errmsg(db));
+ err = NOTIFICATION_ERROR_FROM_DB;
+ goto return_close_db;
+ }
+
+ sqlite3_exec(db, "BEGIN immediate;", NULL, NULL, NULL);
+
+ sqlret = sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO notification_system_setting (uid, do_not_disturb, visibility_class, dnd_schedule_enabled, dnd_schedule_day, dnd_start_hour, dnd_start_min, dnd_end_hour, dnd_end_min) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?) ", -1, &db_statement, NULL);
+
+ if (sqlret != SQLITE_OK) {
+ NOTIFICATION_ERR("sqlite3_prepare_v2 failed [%d][%s]", sqlret, sqlite3_errmsg(db));
+ err = NOTIFICATION_ERROR_FROM_DB;
+ goto return_close_db;
+ }
+
+ sqlite3_bind_int(db_statement, field_index++, uid);
+ sqlite3_bind_int(db_statement, field_index++, do_not_disturb);
+ sqlite3_bind_int(db_statement, field_index++, visibility_class);
+ sqlite3_bind_int(db_statement, field_index++, dnd_schedule_enabled);
+ sqlite3_bind_int(db_statement, field_index++, dnd_schedule_day);
+ sqlite3_bind_int(db_statement, field_index++, dnd_start_hour);
+ sqlite3_bind_int(db_statement, field_index++, dnd_start_min);
+ sqlite3_bind_int(db_statement, field_index++, dnd_end_hour);
+ sqlite3_bind_int(db_statement, field_index++, dnd_end_min);
+
+ sqlret = sqlite3_step(db_statement);
+ if (sqlret != SQLITE_OK && sqlret != SQLITE_DONE) {
+ NOTIFICATION_ERR("sqlite3_step failed [%d][%s]", sqlret, sqlite3_errmsg(db));
+ err = NOTIFICATION_ERROR_FROM_DB;
+ goto return_close_db;
+ }
+
+ sqlret = sqlite3_changes(db);
+
+ if (sqlret == 0)
+ NOTIFICATION_WARN("No changes on DB");
+
+return_close_db:
+ if (db_statement)
+ sqlite3_finalize(db_statement);
+
+
+ if (db) {
+ if (err == NOTIFICATION_ERROR_NONE)
+ sqlite3_exec(db, "END;", NULL, NULL, NULL);
+ else
+ sqlite3_exec(db, "ROLLBACK;", NULL, NULL, NULL);
+
+ sqlret = db_util_close(db);
+ }
+
+ if (sqlret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+
+ return err;
+}
+
+EXPORT_API
+int notification_setting_db_update_do_not_disturb(int do_not_disturb, uid_t uid)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+ int sqlret;
+ sqlite3 *db = NULL;
+ char *sqlbuf = NULL;
+
+ sqlret = db_util_open(DBPATH, &db, 0);
+ if (sqlret != SQLITE_OK || db == NULL) {
+ NOTIFICATION_ERR("db_util_open failed [%s][%d]", DBPATH, sqlret);
+ return NOTIFICATION_ERROR_FROM_DB;
+ }
+
+ sqlbuf = sqlite3_mprintf("UPDATE notification_system_setting SET do_not_disturb = %d WHERE uid = %d", do_not_disturb, uid);
+ if (!sqlbuf) {
+ NOTIFICATION_ERR("fail to alloc query");
+ err = NOTIFICATION_ERROR_OUT_OF_MEMORY;
+ goto return_close_db;
+ }
+
+ err = notification_db_exec(db, sqlbuf, NULL);
+
+return_close_db:
+ if (sqlbuf)
+ sqlite3_free(sqlbuf);
+
+ sqlret = db_util_close(db);
+ if (sqlret != SQLITE_OK)
+ NOTIFICATION_WARN("fail to db_util_close - [%d]", sqlret);
+
+ return err;
+}
+
+EXPORT_API
+int noti_system_setting_set_alarm(int week_flag, int hour, int min, alarm_cb_t handler, alarm_id_t *dnd_schedule_alarm_id)
+{
+ int err = NOTIFICATION_ERROR_NONE;
+ struct tm struct_time;
+ alarm_entry_t *alarm_info = NULL;
+ alarm_date_t alarm_time;
+ alarm_id_t alarm_id = -1;
+
+ err = alarmmgr_init("notification");
+ if (err < 0) {
+ NOTIFICATION_ERR("alarmmgr_init failed (%d)", err);
+ goto out;
+ }
+
+ err = alarmmgr_set_cb(handler, NULL);
+ if (err < 0) {
+ NOTIFICATION_ERR("alarmmgr_set_cb failed (%d)", err);
+ goto out;
+ }
+
+ err = _get_current_time(&struct_time);
+ if (err != NOTIFICATION_ERROR_NONE) {
+ NOTIFICATION_ERR("get_current_time failed");
+ goto out;
+ }
+
+ alarm_info = alarmmgr_create_alarm();
+ if (alarm_info == NULL) {
+ NOTIFICATION_ERR("alarmmgr_create_alarm failed");
+ goto out;
+ }
+
+ alarm_time.year = struct_time.tm_year + 1900;
+ alarm_time.month = struct_time.tm_mon + 1;
+ alarm_time.day = struct_time.tm_mday;
+ alarm_time.hour = hour;
+ alarm_time.min = min;
+ alarm_time.sec = 0;
+
+ err = alarmmgr_set_time(alarm_info, alarm_time);
+ if (err != ALARMMGR_RESULT_SUCCESS) {
+ NOTIFICATION_ERR("alarmmgr_set_time failed (%d)", err);
+ goto out;
+ }
+
+ err = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag);
+ if (err != ALARMMGR_RESULT_SUCCESS) {
+ NOTIFICATION_ERR("alarmmgr_set_repeat_mode failed (%d)", err);
+ goto out;
+ }
+
+ err = alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
+ if (err != ALARMMGR_RESULT_SUCCESS) {
+ NOTIFICATION_ERR("alarmmgr_set_type failed (%d)", err);
+ goto out;
+ }
+
+ err = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &alarm_id);
+ if (err != ALARMMGR_RESULT_SUCCESS) {
+ NOTIFICATION_ERR("alarmmgr_add_alarm_with_localtime failed (%d)", err);
+ goto out;
+ }
+
+ *dnd_schedule_alarm_id = alarm_id;
+
+ NOTIFICATION_DBG("alarm_id [%d]", *dnd_schedule_alarm_id);
+
+out:
+ if (alarm_info)
+ alarmmgr_free_alarm(alarm_info);
+
+ return err;
+}