*
*/
-
-
-
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<sys/types.h>
-#include<dbus/dbus.h>
#include<glib.h>
#include <db-util.h>
#if !GLIB_CHECK_VERSION (2, 31, 0)
#include <glib/gmacros.h>
-#else
#endif
-
#include"alarm.h"
#include"alarm-internal.h"
#define MAX_QUERY_LEN 4096
extern __alarm_server_context_t alarm_context;
-extern sqlite3 *alarmmgr_db;
-
-#ifdef __ALARM_BOOT
-extern bool enable_power_on_alarm;
-#endif
-
+extern GSList *alarmmgr_db_list;
bool _save_alarms(__alarm_info_t *__alarm_info);
bool _update_alarms(__alarm_info_t *__alarm_info);
-bool _delete_alarms(alarm_id_t alarm_id);
-#ifdef __ALARM_BOOT
-bool _update_power_on(bool on_off);
-#endif
+bool _delete_alarms(alarm_id_t alarm_id, const char *zone);
bool _load_alarms_from_registry(void);
+static gint _find_zone_alarmmgr_db(void *db_info, void *data)
+{
+ _zone_alarm_db_list_t *db_struct = (_zone_alarm_db_list_t *)db_info;
+ return strcmp(db_struct->zone, (char *)data);
+}
+
+static sqlite3 *_find_db(const char *zone)
+{
+ sqlite3 *alarmmgr_db = NULL;
+ GSList *iter = g_slist_find_custom(alarmmgr_db_list, zone, (GCompareFunc)_find_zone_alarmmgr_db);
+ if (iter == NULL) {
+ SECURE_LOGE("failed to find db for zone[%s]", zone);
+ return NULL;
+ }
+ alarmmgr_db = ((_zone_alarm_db_list_t *)iter->data)->alarmmgr_db;
+
+ return alarmmgr_db;
+}
+
bool _save_alarms(__alarm_info_t *__alarm_info)
{
- char query[MAX_QUERY_LEN] = {0,};
char *error_message = NULL;
alarm_info_t *alarm_info =
(alarm_info_t *) &(__alarm_info->alarm_info);
alarm_date_t *start = &alarm_info->start;
alarm_mode_t *mode = &alarm_info->mode;
- snprintf(query, MAX_QUERY_LEN, "insert into alarmmgr( alarm_id, start,\
- end, pid, app_unique_name, app_service_name, app_service_name_mod, bundle, year,\
+ SECURE_LOGE("__zone %s", g_quark_to_string(__alarm_info->zone));
+ sqlite3 *alarmmgr_db = _find_db((const char *)g_quark_to_string(__alarm_info->zone));
+ if (alarmmgr_db == NULL) {
+ SECURE_LOGE("failed to retrieve db");
+ return false;
+ }
+
+ char *query = sqlite3_mprintf("insert into alarmmgr( alarm_id, start,\
+ end, pid, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, app_service_name_mod, bundle, year,\
month, day, hour, min, sec, day_of_week, repeat,\
alarm_type, reserved_info, dst_service_name, dst_service_name_mod)\
- values (%d,%d,%d,%d,'%s','%s','%s','%s',%d,%d,%d,%d,%d,%d,%d,%d,\
- %d,%d,'%s','%s')",\
+ values (%d,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%Q,%d,%d,%d,%d,%d,%d,%d,%d,\
+ %d,%d,%Q,%Q)",\
__alarm_info->alarm_id,
(int)__alarm_info->start,
(int)__alarm_info->end,
__alarm_info->pid,
+ (char *)g_quark_to_string(__alarm_info->quark_caller_pkgid),
+ (char *)g_quark_to_string(__alarm_info->quark_callee_pkgid),
(char *)g_quark_to_string(
__alarm_info->quark_app_unique_name),
(char *)g_quark_to_string(
(char *)g_quark_to_string(
__alarm_info->quark_dst_service_name_mod));
- if (SQLITE_OK !=
- sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
- ALARM_MGR_EXCEPTION_PRINT(
- "Don't execute query = %s, error message = %s\n", query,
- error_message);
+ if (SQLITE_OK != sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
+ SECURE_LOGE("sqlite3_exec() is failed. query = %s, error message = %s", query, error_message);
+ sqlite3_free(query);
return false;
}
+ sqlite3_free(query);
return true;
}
bool _update_alarms(__alarm_info_t *__alarm_info)
{
- char query[MAX_QUERY_LEN] = {0,};
char *error_message = NULL;
alarm_info_t *alarm_info =
(alarm_info_t *) &(__alarm_info->alarm_info);
alarm_date_t *start = &alarm_info->start;
alarm_mode_t *mode = &alarm_info->mode;
- snprintf(query, MAX_QUERY_LEN, "update alarmmgr set start=%d, end=%d,\
- pid=%d, app_unique_name='%s', app_service_name='%s', app_service_name_mod='%s',\
- bundle='%s', year=%d, month=%d, day=%d, hour=%d, min=%d, sec=%d,\
+ sqlite3 *alarmmgr_db = _find_db((const char *)g_quark_to_string(__alarm_info->zone));
+ if (alarmmgr_db == NULL) {
+ SECURE_LOGE("failed to retrieve db");
+ return false;
+ }
+
+ char *query = sqlite3_mprintf("update alarmmgr set start=%d, end=%d,\
+ pid=%d, caller_pkgid=%Q, callee_pkgid=%Q, app_unique_name=%Q, app_service_name=%Q, app_service_name_mod=%Q,\
+ bundle=%Q, year=%d, month=%d, day=%d, hour=%d, min=%d, sec=%d,\
day_of_week=%d, repeat=%d, alarm_type=%d,\
- reserved_info=%d, dst_service_name='%s', dst_service_name_mod='%s'\
+ reserved_info=%d, dst_service_name=%Q, dst_service_name_mod=%Q\
where alarm_id=%d",\
(int)__alarm_info->start,
(int)__alarm_info->end,
__alarm_info->pid,
+ (char *)g_quark_to_string(__alarm_info->quark_caller_pkgid),
+ (char *)g_quark_to_string(__alarm_info->quark_callee_pkgid),
(char *)g_quark_to_string(
__alarm_info->quark_app_unique_name),
(char *)g_quark_to_string(
__alarm_info->quark_dst_service_name_mod),
__alarm_info->alarm_id);
- if (SQLITE_OK !=
- sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
- ALARM_MGR_EXCEPTION_PRINT(
- "Don't execute query = %s, error message = %s\n", query,
- error_message);
+ if (SQLITE_OK != sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
+ SECURE_LOGE("sqlite3_exec() is failed. query = %s, error message = %s", query, error_message);
+ sqlite3_free(query);
return false;
}
+ sqlite3_free(query);
return true;
-
}
-bool _delete_alarms(alarm_id_t alarm_id)
+bool _delete_alarms(alarm_id_t alarm_id, const char *zone)
{
- char query[MAX_QUERY_LEN] = {0};
char *error_message = NULL;
+ char *query = sqlite3_mprintf("delete from alarmmgr where alarm_id=%d", alarm_id);
- snprintf(query, MAX_QUERY_LEN, "delete from alarmmgr where alarm_id=%d",
- alarm_id);
-
- if (SQLITE_OK !=
- sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
- ALARM_MGR_EXCEPTION_PRINT(
- "Don't execute query = %s, error message = %s\n", query,
- error_message);
- return false;
- }
-
- return true;
-
-}
-
-#ifdef __ALARM_BOOT
-bool _update_power_on(bool on_off)
-{
-/* GConfClient* pGCC;
- char key[MAX_GCONF_PATH_LEN];
- GError* error = NULL;
-
- g_type_init();
- pGCC = gconf_client_get_default();
-
- if(!pGCC)
- {
- ALARM_MGR_EXCEPTION_PRINT(" gconf get failed.. \n");
+ sqlite3 *alarmmgr_db = _find_db(zone);
+ if (alarmmgr_db == NULL) {
+ SECURE_LOGE("failed to retrieve db");
return false;
}
- sprintf(key,"/Services/AlarmMgr/Auto_poweron");
-
-
- if(!gconf_client_set_bool(pGCC, key, on_off, &error))
- {
- ALARM_MGR_EXCEPTION_PRINT("set string has failed...\n");
+ if (SQLITE_OK != sqlite3_exec(alarmmgr_db, query, NULL, NULL, &error_message)) {
+ SECURE_LOGE("sqlite3_exec() is failed. query = %s, error message = %s", query, error_message);
+ sqlite3_free(query);
return false;
}
- gconf_client_suggest_sync(pGCC, NULL);
- g_object_unref(pGCC);
-*/
- return false;
+ sqlite3_free(query);
+ return true;
}
-#endif
bool _load_alarms_from_registry()
{
__alarm_info_t *__alarm_info = NULL;
alarm_date_t *start = NULL;
alarm_mode_t *mode = NULL;
+ char caller_pkgid[MAX_PKG_ID_LEN] = {0,};
+ char callee_pkgid[MAX_PKG_ID_LEN] = {0,};
char app_unique_name[MAX_SERVICE_NAME_LEN] = {0,};
char app_service_name[MAX_SERVICE_NAME_LEN] = {0,};
char app_service_name_mod[MAX_SERVICE_NAME_LEN] = {0,};
char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = {0,};
char bundle[MAX_BUNDLE_NAME_LEN] = {0,};
-#ifdef __ALARM_BOOT
- /*sprintf(path, "/Services/AlarmMgr/Auto_poweron"); */
-
- enable_power_on_alarm = 0;
- /*gconf_client_get_bool(pGCC, path, NULL); */
-#endif
-
snprintf(query, MAX_QUERY_LEN, "select * from alarmmgr");
- if (SQLITE_OK !=
- sqlite3_prepare(alarmmgr_db, query, strlen(query), &stmt, &tail)) {
- ALARM_MGR_EXCEPTION_PRINT("sqlite3_prepare error\n");
- return false;
- }
+ GSList *iter;
+ sqlite3 *alarmmgr_db = NULL;
+ char *zone = NULL;
+ for (iter = alarmmgr_db_list; iter != NULL; iter = g_slist_next(iter)) {
+ alarmmgr_db = ((_zone_alarm_db_list_t *)iter->data)->alarmmgr_db;
+ zone = ((_zone_alarm_db_list_t *)iter->data)->zone;
- for (i = 0; SQLITE_ROW == sqlite3_step(stmt); i++) {
- __alarm_info = malloc(sizeof(__alarm_info_t));
+ if (SQLITE_OK != sqlite3_prepare(alarmmgr_db, query, strlen(query), &stmt, &tail)) {
+ ALARM_MGR_EXCEPTION_PRINT("sqlite3_prepare() is failed.");
+ return false;
+ }
+ for (i = 0; SQLITE_ROW == sqlite3_step(stmt); i++) {
+ __alarm_info = malloc(sizeof(__alarm_info_t));
+
+ if (G_UNLIKELY(__alarm_info == NULL)) {
+ ALARM_MGR_EXCEPTION_PRINT("Memory allocation failed.");
+ return false;
+ }
+ alarm_info = (alarm_info_t *) &(__alarm_info->alarm_info);
+ start = &alarm_info->start;
+ mode = &alarm_info->mode;
+
+ __alarm_info->alarm_id = sqlite3_column_int(stmt, 0);
+ __alarm_info->start = sqlite3_column_int(stmt, 1);
+ __alarm_info->end = sqlite3_column_int(stmt, 2);
+ __alarm_info->pid = sqlite3_column_int(stmt, 3);
+
+ strncpy(caller_pkgid, (const char *)sqlite3_column_text(stmt, 4),
+ MAX_PKG_ID_LEN - 1);
+ strncpy(callee_pkgid, (const char *)sqlite3_column_text(stmt, 5),
+ MAX_PKG_ID_LEN - 1);
+ strncpy(app_unique_name, (const char *)sqlite3_column_text(stmt, 6),
+ MAX_SERVICE_NAME_LEN - 1);
+ strncpy(app_service_name, (const char *)sqlite3_column_text(stmt, 7),
+ MAX_SERVICE_NAME_LEN - 1);
+ strncpy(app_service_name_mod, (const char *)sqlite3_column_text(stmt, 8),
+ MAX_SERVICE_NAME_LEN - 1);
+ strncpy(bundle, (const char *)sqlite3_column_text(stmt, 9),
+ MAX_BUNDLE_NAME_LEN - 1);
+ start->year = sqlite3_column_int(stmt, 10);
+ start->month = sqlite3_column_int(stmt, 11);
+ start->day = sqlite3_column_int(stmt, 12);
+ start->hour = sqlite3_column_int(stmt, 13);
+ start->min = sqlite3_column_int(stmt, 14);
+ start->sec = sqlite3_column_int(stmt, 15);
+ mode->u_interval.day_of_week = sqlite3_column_int(stmt, 16);
+ mode->repeat = sqlite3_column_int(stmt, 17);
+ alarm_info->alarm_type = sqlite3_column_int(stmt, 18);
+ alarm_info->reserved_info = sqlite3_column_int(stmt, 19);
+ strncpy(dst_service_name, (const char *)sqlite3_column_text(stmt, 20),
+ MAX_SERVICE_NAME_LEN - 1);
+ strncpy(dst_service_name_mod, (const char *)sqlite3_column_text(stmt, 21),
+ MAX_SERVICE_NAME_LEN - 1);
+
+ __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+ __alarm_info->quark_callee_pkgid = g_quark_from_string(callee_pkgid);
+ __alarm_info->quark_app_unique_name =
+ g_quark_from_string(app_unique_name);
+ __alarm_info->quark_app_service_name =
+ g_quark_from_string(app_service_name);
+ __alarm_info->quark_app_service_name_mod=
+ g_quark_from_string(app_service_name_mod);
+ __alarm_info->quark_dst_service_name =
+ g_quark_from_string(dst_service_name);
+ __alarm_info->quark_dst_service_name_mod=
+ g_quark_from_string(dst_service_name_mod);
+ __alarm_info->quark_bundle = g_quark_from_string(bundle);
+ __alarm_info->zone = g_quark_from_string(zone);
+
+ _alarm_next_duetime(__alarm_info);
+ alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info);
+ }
- if (G_UNLIKELY(__alarm_info == NULL)){
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Malloc failed\n");
+ if (SQLITE_OK != sqlite3_finalize(stmt)) {
+ ALARM_MGR_EXCEPTION_PRINT("sqlite3_finalize() is failed.");
return false;
}
- alarm_info = (alarm_info_t *) &(__alarm_info->alarm_info);
- start = &alarm_info->start;
- mode = &alarm_info->mode;
-
- memset(app_service_name, 0, MAX_SERVICE_NAME_LEN);
- memset(app_service_name_mod, 0, MAX_SERVICE_NAME_LEN);
- memset(dst_service_name, 0, MAX_SERVICE_NAME_LEN);
- memset(dst_service_name_mod, 0, MAX_SERVICE_NAME_LEN);
-
- __alarm_info->alarm_id = sqlite3_column_int(stmt, 0);
- __alarm_info->start = sqlite3_column_int(stmt, 1);
- __alarm_info->end = sqlite3_column_int(stmt, 2);
- __alarm_info->pid = sqlite3_column_int(stmt, 3);
- strncpy(app_unique_name, (const char *)sqlite3_column_text(stmt, 4),
- MAX_SERVICE_NAME_LEN - 1);
- strncpy(app_service_name, (const char *)sqlite3_column_text(stmt, 5),
- MAX_SERVICE_NAME_LEN - 1);
- strncpy(app_service_name_mod, (const char *)sqlite3_column_text(stmt, 6),
- MAX_SERVICE_NAME_LEN - 1);
- strncpy(bundle, (const char *)sqlite3_column_text(stmt, 7),
- MAX_BUNDLE_NAME_LEN - 1);
- start->year = sqlite3_column_int(stmt, 8);
- start->month = sqlite3_column_int(stmt, 9);
- start->day = sqlite3_column_int(stmt, 10);
- start->hour = sqlite3_column_int(stmt, 11);
- start->min = sqlite3_column_int(stmt, 12);
- start->sec = sqlite3_column_int(stmt, 13);
- mode->u_interval.day_of_week = sqlite3_column_int(stmt, 14);
- mode->repeat = sqlite3_column_int(stmt, 15);
- alarm_info->alarm_type = sqlite3_column_int(stmt, 16);
- alarm_info->reserved_info = sqlite3_column_int(stmt, 17);
- strncpy(dst_service_name, (const char *)sqlite3_column_text(stmt, 18),
- MAX_SERVICE_NAME_LEN - 1);
- strncpy(dst_service_name_mod, (const char *)sqlite3_column_text(stmt, 19),
- MAX_SERVICE_NAME_LEN - 1);
-
- __alarm_info->quark_app_unique_name =
- g_quark_from_string(app_unique_name);
- __alarm_info->quark_app_service_name =
- g_quark_from_string(app_service_name);
- __alarm_info->quark_app_service_name_mod=
- g_quark_from_string(app_service_name_mod);
- __alarm_info->quark_dst_service_name =
- g_quark_from_string(dst_service_name);
- __alarm_info->quark_dst_service_name_mod=
- g_quark_from_string(dst_service_name_mod);
- __alarm_info->quark_bundle = g_quark_from_string(bundle);
-
- _alarm_next_duetime(__alarm_info);
- alarm_context.alarms =
- g_slist_append(alarm_context.alarms, __alarm_info);
+ stmt = NULL;
}
+ _alarm_schedule();
if (SQLITE_OK != sqlite3_finalize(stmt)) {
- ALARM_MGR_EXCEPTION_PRINT("error : sqlite3_finalize\n");
+ ALARM_MGR_EXCEPTION_PRINT("sqlite3_finalize() is failed.");
return false;
}
-
- _alarm_schedule();
+ stmt = NULL;
return true;
}