#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <sys/timerfd.h>
+#include <poll.h>
+#include <stdint.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <glib.h>
#if !GLIB_CHECK_VERSION (2, 31, 0)
#include <glib/gmacros.h>
-#else
#endif
-/*#include "global-gconf.h"*/
+#include "gio/gio.h"
#include "alarm.h"
#include "alarm-internal.h"
-
-/*#include"limo-event-delivery.h"*/
+#include "alarm-mgr-stub.h"
#include <aul.h>
#include <bundle.h>
#define WAKEUP_ALARM_APP_ID "com.samsung.alarm.ALARM"
/* alarm ui application's alarm's dbus_service name instead of 21
(alarm application's app_id) value */
-#define WAKEUP_ALARMBOOTING_APP_ID "com.samsung.alarmboot.ui.ALARM"
-/*alrmbooting ui application's dbus_service name instead of 121(alarmbooting
- application's app_id) value */
-
-#ifdef WEARABLE_PROFILE
-#include "dd-display.h"
-#endif
__alarm_server_context_t alarm_context;
bool g_dummy_timer_is_set = FALSE;
GSList *g_scheduled_alarm_list = NULL;
-
GSList *g_expired_alarm_list = NULL;
#ifndef RTC_WKALM_BOOT_SET
#define RTC_WKALM_BOOT_SET _IOW('p', 0x80, struct rtc_wkalrm)
#endif
-#ifdef __ALARM_BOOT
-bool enable_power_on_alarm;
-bool alarm_boot;
-time_t ab_due_time = -1;
-bool poweron_alarm_expired = false;
-#endif
-
/* 2008. 6. 3 sewook7.park
When the alarm becoms sleeping mode, alarm timer is not expired.
So using RTC, phone is awaken before alarm rings.
*/
#define __WAKEUP_USING_RTC__
#ifdef __WAKEUP_USING_RTC__
-#include<errno.h>
+#include <errno.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#define ALARM_SET_RTC _IOW('a', 5, struct timespec)
#define ALARM_CLEAR(type) _IO('a', 0 | ((type) << 4))
-
+// For module log
+#define ALARMMGR_LOG_BUFFER_SIZE 10000
+#define ALARMMGR_LOG_BUFFER_STRING_SIZE 200
+#define ALARMMGR_LOG_TAG_SIZE 20
+#define ALARMMGR_LOG_MESSAGE_SIZE 120
+#define ALARMMGR_LOG_FILE_PATH "/var/log/alarmmgr.log"
+static int log_index = 0;
+static int log_fd = 0;
+
+// display lock and unlock
+#define DEVICED_BUS_NAME "org.tizen.system.deviced"
+#define DEVICED_PATH_DISPLAY "/Org/Tizen/System/DeviceD/Display"
+#define DEVICED_INTERFACE_DISPLAY "org.tizen.system.deviced.display"
+#define DEVICED_LOCK_STATE "lockstate"
+#define DEVICED_UNLOCK_STATE "unlockstate"
+#define DEVICED_DBUS_REPLY_TIMEOUT (120*1000)
+#define DEVICED_LCD_OFF "lcdoff"
+#define DEVICED_STAY_CUR_STATE "staycurstate"
+#define DEVICED_SLEEP_MARGIN "sleepmargin"
static const char default_rtc[] = "/dev/alarm";
#endif /*__WAKEUP_USING_RTC__*/
+/* GDBus Declaration */
+#define ALARM_MGR_DBUS_PATH "/com/samsung/alarm/manager"
+#define ALARM_MGR_DBUS_NAME "com.samsung.alarm.manager"
+GDBusObjectManagerServer *alarmmgr_server = NULL;
+static AlarmManager* interface = NULL;
+
static bool __alarm_add_to_list(__alarm_info_t *__alarm_info);
static void __alarm_generate_alarm_id(__alarm_info_t *__alarm_info, alarm_id_t *alarm_id);
static bool __alarm_update_in_list(int pid, alarm_id_t alarm_id,
static bool __alarm_delete(int pid, alarm_id_t alarm_id, int *error_code);
static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
alarm_info_t *alarm_info, int *error_code);
-static bool __alarm_power_on(int app_id, bool on_off, int *error_code);
-static bool __alarm_power_off(int app_id, int *error_code);
-static bool __alarm_check_next_duetime(int app_id, int *error_code);
-static void __alarm_send_noti_to_application(const char *app_service_name,
- alarm_id_t alarm_id);
+static void __alarm_send_noti_to_application(const char *app_service_name, alarm_id_t alarm_id);
static void __alarm_expired();
-static gboolean __alarm_handler_idle();
-static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext);
+static gboolean __alarm_handler_idle(gpointer user_data);
static void __clean_registry();
static bool __alarm_manager_reset();
static void __on_system_time_external_changed(keynode_t *node, void *data);
static void __initialize_timer();
static void __initialize_alarm_list();
static void __initialize_scheduled_alarm_list();
-static void __hibernation_leave_callback();
static bool __initialize_noti();
static bool __initialize_dbus();
static bool __initialize_db();
static void __initialize();
-static bool __check_false_alarm();
-static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
- DBusMessage *message,
- void *user_data);
+void on_bus_name_owner_changed(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path,
+ const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data);
+bool __get_caller_unique_name(int pid, char *unique_name);
-static int __rtc_set_b2()
+static void __initialize_module_log(void);
+static bool __save_module_log(const char *tag, const char *messgae);
+
+int __display_lock_state(char *state, char *flag, unsigned int timeout);
+int __display_unlock_state(char *state, char *flag);
+
+static void __rtc_set()
{
#ifdef __WAKEUP_USING_RTC__
const char *rtc = default_rtc;
struct rtc_wkalrm rtc_wk;
struct tm due_tm;
struct timespec alarm_time;
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
#ifdef _SIMUL /*if build is simulator, we don't need to set
RTC because RTC does not work in simulator.*/
- ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, "
- "we don't set RTC.\n");
+ ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, we don't set RTC.");
return;
#endif
if (gfd == 0) {
gfd = open(rtc, O_RDWR);
if (gfd == -1) {
- ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
+ ALARM_MGR_EXCEPTION_PRINT("RTC open failed.");
+ return;
}
}
/* Read the RTC time/date */
- int retval;
+ int retval = 0;
+ char *timebuf = ctime(&alarm_context.c_due_time);
+ timebuf[strlen(timebuf) - 1] = '\0'; // to avoid new line
+ sprintf(log_message, "wakeup time: %d, %s", alarm_context.c_due_time, timebuf);
- ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d\n", \
- alarm_context.c_due_time);
+ ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d.", alarm_context.c_due_time);
if (alarm_context.c_due_time != -1) {
-
- /*retval = ioctl(gfd, ALARM_CLEAR(ALARM_RTC_WAKEUP));
+ retval = ioctl(gfd, ALARM_CLEAR(ALARM_RTC_WAKEUP));
if (retval == -1) {
if (errno == ENOTTY) {
- ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
- "supported.\n");
+ ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
}
- ALARM_MGR_EXCEPTION_PRINT("ALARM_CLEAR ioctl");
- //close(fd);
- return -1;
- }*/
+ ALARM_MGR_EXCEPTION_PRINT("ALARM_CLEAR ioctl is failed. errno = %s", strerror(errno));
+ return;
+ }
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]ALARM_CLEAR ioctl is successfully done.");
time_t due_time = alarm_context.c_due_time;
gmtime_r(&due_time, &due_tm);
- ALARM_MGR_LOG_PRINT("Setted RTC Alarm date/time is "
- "%d-%d-%d, %02d:%02d:%02d.\n", due_tm.tm_mday,
- due_tm.tm_mon + 1, due_tm.tm_year + 1900,
+ ALARM_MGR_EXCEPTION_PRINT("Setted RTC Alarm date/time is %d-%d-%d, %02d:%02d:%02d (UTC).",
+ due_tm.tm_mday, due_tm.tm_mon + 1, due_tm.tm_year + 1900,
due_tm.tm_hour, due_tm.tm_min, due_tm.tm_sec);
- alarm_time.tv_sec = due_time;
- alarm_time.tv_nsec = 0;
+ alarm_time.tv_sec = due_time - 1;
+ alarm_time.tv_nsec = 500000000; // Wakeup is 500ms faster than expiring time to correct RTC error.
retval = ioctl(gfd, ALARM_SET(ALARM_RTC_WAKEUP), &alarm_time);
if (retval == -1) {
if (errno == ENOTTY) {
- ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
- "supported.\n");
+ ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
}
- ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
- //close(fd);
- return -1;
+ ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror(errno));
+ __save_module_log("FAIL: SET RTC", log_message);
+ return;
}
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
-
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is on");
- } else
- ALARM_MGR_LOG_PRINT("[alarm-server]alarm_context.c_due_time is"
- "less than 10 sec. RTC alarm does not need to be set\n");
-
- //close(fd);
-#endif /* __WAKEUP_USING_RTC__ */
- return 0;
-}
-
-
-static void __rtc_set()
-{
-#ifdef __WAKEUP_USING_RTC__
-
- const char *rtc = "/dev/rtc0";
- int fd = 0;
- struct rtc_time rtc_tm;
- struct rtc_wkalrm rtc_wk;
- struct tm due_tm;
-
-#ifdef _SIMUL /*if build is simulator, we don't need to set
- RTC because RTC does not work in simulator.*/
- ALARM_MGR_EXCEPTION_PRINT("because it is simulator's mode, "
- "we don't set RTC.\n");
- return;
-#endif
-
- if(__rtc_set_b2() == 0)
- return;
-
- fd = open(rtc, O_RDONLY);
- if (fd == -1) {
- ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
- return;
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]RTC ALARM_SET ioctl is successfully done.");
+ __save_module_log("SET RTC", log_message);
}
-
- /* Read the RTC time/date */
- int retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
- if (retval == -1) {
- ALARM_MGR_EXCEPTION_PRINT("RTC_RD_TIME ioctl failed");
- close(fd);
- return;
+ else {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]alarm_context.c_due_time is"
+ "less than 10 sec. RTC alarm does not need to be set");
}
-
- ALARM_MGR_LOG_PRINT("\n\nCurrent RTC date/time is %d-%d-%d, "
- "%02d:%02d:%02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
- rtc_tm.tm_year + 1900, rtc_tm.tm_hour, rtc_tm.tm_min,
- rtc_tm.tm_sec);
-
- ALARM_MGR_LOG_PRINT("alarm_context.c_due_time is %d\n", \
- alarm_context.c_due_time);
-
- if (alarm_context.c_due_time != -1) {
- time_t due_time = alarm_context.c_due_time;
- gmtime_r(&due_time, &due_tm);
-
- rtc_tm.tm_mday = due_tm.tm_mday;
- rtc_tm.tm_mon = due_tm.tm_mon;
- rtc_tm.tm_year = due_tm.tm_year;
- rtc_tm.tm_hour = due_tm.tm_hour;
- rtc_tm.tm_min = due_tm.tm_min;
- rtc_tm.tm_sec = due_tm.tm_sec;
- memcpy(&rtc_wk.time, &rtc_tm, sizeof(rtc_tm));
- rtc_wk.enabled = 1;
- rtc_wk.pending = 0;
-
- ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
- "%d-%d-%d, %02d:%02d:%02d.\n", rtc_tm.tm_mday,
- rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,
- rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
-
- retval = ioctl(fd, RTC_WKALM_SET, &rtc_wk);
- if (retval == -1) {
- if (errno == ENOTTY) {
- ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
- "supported.\n");
- }
- ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
- close(fd);
- return;
- }
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
-
- /* Enable alarm interrupts */
- retval = ioctl(fd, RTC_AIE_ON, 0);
- if (retval == -1) {
- ALARM_MGR_EXCEPTION_PRINT("RTC_AIE_ON ioctl failed");
- close(fd);
- return;
- }
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is on");
- } else
- ALARM_MGR_LOG_PRINT("[alarm-server]alarm_context.c_due_time is"
- "less than 10 sec. RTC alarm does not need to be set\n");
-
- close(fd);
-
#endif /* __WAKEUP_USING_RTC__ */
+ return;
}
-
int _set_rtc_time(time_t _time)
{
- int retval0 = 0;
+ int ret = 0;
const char *rtc0 = default_rtc;
struct timespec rtc_time;
+ char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
if (gfd == 0) {
gfd = open(rtc0, O_RDWR);
rtc_time.tv_sec = _time;
rtc_time.tv_nsec = 0;
- retval0 = ioctl(gfd, ALARM_SET_RTC, &rtc_time);
+ strncpy(log_tag, "SET RTC", strlen("SET RTC"));
+ char *timebuf = ctime(&_time);
+ timebuf[strlen(timebuf) - 1] = '\0'; // to avoid new line
+ sprintf(log_message, "rtc time = %d, %s", _time, timebuf);
+
+ ret = ioctl(gfd, ALARM_SET_RTC, &rtc_time);
+ if (ret == -1) {
+ ALARM_MGR_LOG_PRINT("ALARM_SET_RTC ioctl is failed. errno = %s", strerror(errno));
+ strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC"));
- if (retval0 == -1) {
- /*if (gfd != -1)
- close(fd0);*/
- ALARM_MGR_LOG_PRINT("error to ioctl fd0.");
- ALARM_MGR_LOG_PRINT("retval0 : %d", retval0);
-
perror("\t");
}
- /*if (gfd != -1)
- close(fd0);*/
+
+ __save_module_log(log_tag, log_message);
return 1;
}
-
bool __alarm_clean_list()
{
- GSList *iter = NULL;
-
- for (iter = alarm_context.alarms; iter != NULL;
- iter = g_slist_next(iter)) {
- free(iter->data);
- }
-
- g_slist_free(alarm_context.alarms);
+ g_slist_free_full(alarm_context.alarms, g_free);
return true;
}
{
bool unique_id = false;
__alarm_info_t *entry = NULL;
-
GSList *iter = NULL;
- /* FIXME: alarm id must be unique. */
- __alarm_info->alarm_id = (int)(void *)__alarm_info;
- ALARM_MGR_LOG_PRINT("__alarm_info->alarm_id is %d", \
- __alarm_info->alarm_id);
+ srand((unsigned int)time(NULL));
+ __alarm_info->alarm_id = (rand() % INT_MAX) + 1;
+ ALARM_MGR_LOG_PRINT("__alarm_info->alarm_id is %d", __alarm_info->alarm_id);
while (unique_id == false) {
unique_id = true;
static bool __alarm_add_to_list(__alarm_info_t *__alarm_info)
{
-
alarm_info_t *alarm_info = &__alarm_info->alarm_info;
__alarm_info_t *entry = NULL;
-
GSList *iter = NULL;
- /* list alarms */
- ALARM_MGR_LOG_PRINT("[alarm-server]: before add\n");
- for (iter = alarm_context.alarms; iter != NULL;
- iter = g_slist_next(iter)) {
- entry = iter->data;
- /*ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
- entry->alarm_id); */
- }
+ ALARM_MGR_LOG_PRINT("[alarm-server]: Before add alarm_id(%d)", __alarm_info->alarm_id);
- alarm_context.alarms =
- g_slist_append(alarm_context.alarms, __alarm_info);
- /*list alarms */
- ALARM_MGR_LOG_PRINT("[alarm-server]: after add\n");
- for (iter = alarm_context.alarms; iter != NULL;
- iter = g_slist_next(iter)) {
+ alarm_context.alarms = g_slist_append(alarm_context.alarms, __alarm_info);
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: After add alarm_id(%d)", __alarm_info->alarm_id);
+
+ // alarm list
+ for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
entry = iter->data;
- ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d)\n",
- entry->alarm_id);
+ ALARM_MGR_LOG_PRINT("[alarm-server]: alarm_id(%d).", entry->alarm_id);
}
if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
- _save_alarms(__alarm_info);
+ if (!_save_alarms(__alarm_info)) {
+ ALARM_MGR_EXCEPTION_PRINT("Saving alarm_id(%d) in DB is failed.", __alarm_info->alarm_id);
+ }
}
return true;
}
if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
- _update_alarms(__alarm_info);
+ if (!_update_alarms(__alarm_info)) {
+ ALARM_MGR_EXCEPTION_PRINT("Updating alarm_id(%d) in DB is failed.", __alarm_info->alarm_id);
+ }
}
return true;
__alarm_info_t *entry = NULL;
/*list alarms */
- ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)\n",
- alarm_id);
+ ALARM_MGR_LOG_PRINT("[alarm-server]: before del : alarm id(%d)", alarm_id);
- for (iter = alarm_context.alarms; iter != NULL;
- iter = g_slist_next(iter)) {
+ for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
entry = iter->data;
if (entry->alarm_id == alarm_id) {
alarm_info = &entry->alarm_info;
- ALARM_MGR_LOG_PRINT("[alarm-server]: "
- "__alarm_remove_from_list : alarm id(%d)\n",
- entry->alarm_id);
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Remove alarm id(%d)", entry->alarm_id);
if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE)) {
_delete_alarms(alarm_id);
}
- alarm_context.alarms =
- g_slist_remove(alarm_context.alarms, iter->data);
+ alarm_context.alarms = g_slist_remove(alarm_context.alarms, iter->data);
+ g_free(entry);
found = true;
break;
}
time(¤t_time);
- for (iter = alarm_context.alarms; iter != NULL;
- iter = g_slist_next(iter)) {
+ for (iter = alarm_context.alarms; iter != NULL; iter = g_slist_next(iter)) {
entry = iter->data;
due_time = entry->due_time;
ALARM_MGR_LOG_PRINT("alarm[%d] with duetime(%u) at "
"current(%u)\n", entry->alarm_id, due_time, current_time);
- if (due_time == 0) { /* 0 means this alarm has been
- disabled */
+ if (due_time == 0) { /* 0 means this alarm has been disabled */
continue;
}
interval = difftime(due_time, current_time);
if (interval <= 0) {
- ALARM_MGR_LOG_PRINT("this may be error.. alarm[%d]\n", \
- entry->alarm_id);
+ ALARM_MGR_EXCEPTION_PRINT("The duetime of alarm(%d) is OVER.", entry->alarm_id);
continue;
}
}
static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
- int pid,char *bundle_data, int *error_code){
-
+ int pid, char *bundle_data, int *error_code)
+{
time_t current_time;
time_t due_time;
struct tm ts_ret;
char due_time_r[100] = { 0 };
- char proc_file[512] = { 0 };
- char process_name[512] = { 0 };
char app_name[512] = { 0 };
- char *word = NULL;
- char *proc_name_ptr = NULL;
- int fd = 0;
- int ret = 0;
- int i = 0;
bundle *b;
- char caller_appid[512];
+ char caller_appid[256] = { 0 };
+ char* callee_appid = NULL;
+ char* caller_pkgid = NULL;
+ char* callee_pkgid = NULL;
+ pkgmgrinfo_pkginfo_h caller_handle;
+ pkgmgrinfo_pkginfo_h callee_handle;
bundle_raw *b_data = NULL;
int datalen = 0;
__alarm_info = malloc(sizeof(__alarm_info_t));
if (__alarm_info == NULL) {
- SECURE_LOGE("Caution!! app_pid=%d, malloc "
- "failed. it seems to be OOM\n", pid);
- *error_code = -1; /* -1 means that system
- failed internally. */
+ SECURE_LOGE("Caution!! app_pid=%d, malloc failed. it seems to be OOM.", pid);
+ *error_code = ERR_ALARM_SYSTEM_FAIL;
return false;
}
+
__alarm_info->pid = pid;
__alarm_info->alarm_id = -1;
-
- /* we should consider to check whether pid is running or Not
- */
- memset(process_name, '\0', 512);
- memset(proc_file, '\0', 512);
- snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
-
- fd = open(proc_file, O_RDONLY);
- if (fd < 0) { /* failure */
- SECURE_LOGE("Caution!! app_pid(%d) seems to be "
- "killed, so we failed to get proc file(%s) and do not create "
- "alarm_info\n", pid, proc_file);
- *error_code = -1; /*-1 means that system failed
- internally.*/
+ if (!__get_caller_unique_name(pid, app_name)) {
+ *error_code = ERR_ALARM_SYSTEM_FAIL;
free(__alarm_info);
return false;
- } else {
- ret = read(fd, process_name, 512);
- close(fd);
- if (ret <=0)
- {
- ALARM_MGR_EXCEPTION_PRINT("Unable to get application name\n");
- *error_code = -1;
- free(__alarm_info);
- return false;
- }
- while (process_name[i] != '\0') {
- if (process_name[i] == ' ') {
- process_name[i] = '\0';
- break;
- }
- i++;
- }
+ }
+ __alarm_info->quark_app_unique_name = g_quark_from_string(app_name);
- word = strtok_r(process_name, "/", &proc_name_ptr);
- while (word != NULL) {
- memset(app_name, 0, 512);
- snprintf(app_name, 512, "%s", word);
- word = strtok_r(NULL, "/", &proc_name_ptr);
+ // Get caller_appid and callee_appid to get each package id
+ // caller
+ __alarm_info->quark_caller_pkgid = g_quark_from_string("null");
+
+ if (aul_app_get_appid_bypid(pid, caller_appid, 256) == AUL_R_OK) {
+ if (pkgmgrinfo_appinfo_get_appinfo(caller_appid, &caller_handle) == PMINFO_R_OK) {
+ if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
+ if (caller_pkgid) {
+ __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+ }
+ }
+ pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
}
- __alarm_info->quark_app_unique_name =
- g_quark_from_string(app_name);
}
+ // callee
+ __alarm_info->quark_callee_pkgid = g_quark_from_string("null");
+
b = bundle_decode((bundle_raw *)bundle_data, strlen(bundle_data));
- ret = aul_app_get_appid_bypid(pid, caller_appid, 512);
- if(ret == 0) {
- bundle_add(b, "__ALARM_MGR_CALLER_APPID", caller_appid);
+ callee_appid = appsvc_get_appid(b);
+ if (pkgmgrinfo_appinfo_get_appinfo(callee_appid, &callee_handle) == PMINFO_R_OK) {
+ if (pkgmgrinfo_appinfo_get_pkgid(callee_handle, &callee_pkgid) == PMINFO_R_OK) {
+ if (callee_pkgid) {
+ __alarm_info->quark_callee_pkgid = g_quark_from_string(callee_pkgid);
+ }
+ }
+ pkgmgrinfo_appinfo_destroy_appinfo(callee_handle);
}
- bundle_encode(b, &b_data, &datalen);
+ SECURE_LOGD("caller_pkgid = %s, callee_pkgid = %s",
+ g_quark_to_string(__alarm_info->quark_caller_pkgid), g_quark_to_string(__alarm_info->quark_callee_pkgid));
+
+ bundle_encode(b, &b_data, &datalen);
__alarm_info->quark_bundle=g_quark_from_string(b_data);
__alarm_info->quark_app_service_name = g_quark_from_string("null");
__alarm_info->quark_dst_service_name = g_quark_from_string("null");
free(b_data);
b_data = NULL;
}
-
+
__alarm_set_start_and_end_time(alarm_info, __alarm_info);
memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
__alarm_generate_alarm_id(__alarm_info, alarm_id);
-#ifdef __APP_SYNC
- if (_sync_scheduler_app_sync_on())
- _sync_scheduler_repeating_alarms(__alarm_info);
-#endif
-
time(¤t_time);
if (alarm_context.c_due_time < current_time) {
ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
- "(%d) is less than current time(%d)", alarm_context.c_due_time,
- current_time);
+ "(%d) is less than current time(%d)", alarm_context.c_due_time, current_time);
alarm_context.c_due_time = -1;
}
due_time = _alarm_next_duetime(__alarm_info);
if (__alarm_add_to_list(__alarm_info) == false) {
free(__alarm_info);
- *error_code = -1;
+ *error_code = ERR_ALARM_SYSTEM_FAIL;
return false;
}
"current_time(%d) is same as due_time(%d)", current_time,
due_time);
return true;
- }else if (difftime(due_time, current_time) < 0){
+ } else if (difftime(due_time, current_time) < 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
return true;
- }else {
+ } else {
localtime_r(&due_time, &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
SECURE_LOGD("[alarm-server]:Create a new alarm: "
due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
- "due_time(%d)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:alarm_context.c_due_time(%d), due_time(%d)", alarm_context.c_due_time, due_time);
- if (alarm_context.c_due_time == -1
- || due_time < alarm_context.c_due_time) {
+ if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
_clear_scheduled_alarm_list();
_add_to_scheduled_alarm_list(__alarm_info);
- _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
- *alarm_id);
+ _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
alarm_context.c_due_time = due_time;
-
} else if (due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
-
}
__rtc_set();
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
-
return true;
-
}
static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
int pid, char *app_service_name, char *app_service_name_mod,
const char *dst_service_name,const char *dst_service_name_mod, int *error_code)
{
-
time_t current_time;
time_t due_time;
- char proc_file[256] = { 0 };
- char process_name[512] = { 0 };
- char app_name[256] = { 0 };
- char *word = NULL;
- char *proc_name_ptr = NULL;
+ char app_name[512] = { 0 };
+ char caller_appid[256] = { 0 };
+ char* caller_pkgid = NULL;
+ pkgmgrinfo_pkginfo_h caller_handle;
__alarm_info_t *__alarm_info = NULL;
if (__alarm_info == NULL) {
SECURE_LOGE("Caution!! app_pid=%d, malloc "
"failed. it seems to be OOM\n", pid);
- *error_code = -1; /* -1 means that system
- failed internally. */
+ *error_code = ERR_ALARM_SYSTEM_FAIL;
return false;
}
__alarm_info->pid = pid;
__alarm_info->alarm_id = -1;
+ __alarm_info->quark_caller_pkgid = g_quark_from_string("null");
+
+ // Get caller_appid to get caller's package id. There is no callee.
+ if (aul_app_get_appid_bypid(pid, caller_appid, 256) == AUL_R_OK) {
+ if (pkgmgrinfo_appinfo_get_appinfo(caller_appid, &caller_handle) == PMINFO_R_OK) {
+ if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
+ if (caller_pkgid) {
+ __alarm_info->quark_caller_pkgid = g_quark_from_string(caller_pkgid);
+ }
+ }
+ pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
+ }
+ }
- /* we should consider to check whether pid is running or Not
- */
- memset(process_name, '\0', 512);
- memset(proc_file, '\0', 256);
- snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
+ __alarm_info->quark_callee_pkgid = g_quark_from_string("null");
+ SECURE_LOGD("caller_pkgid = %s, callee_pkgid = null", g_quark_to_string(__alarm_info->quark_caller_pkgid));
- int fd;
- int ret;
- int i = 0;
- fd = open(proc_file, O_RDONLY);
- if (fd < 0) { /* failure */
- __alarm_info->quark_app_unique_name =
- g_quark_from_string("unknown");
- SECURE_LOGE("Caution!! app_pid(%d) seems to be "
- "killed, so we failed to get proc file(%s) and do not create "
- "alarm_info\n", pid, proc_file);
- *error_code = -1; /*-1 means that system failed
- internally.*/
+ if (!__get_caller_unique_name(pid, app_name)) {
+ *error_code = ERR_ALARM_SYSTEM_FAIL;
free(__alarm_info);
return false;
- } else {
- ret = read(fd, process_name, 512);
- if (ret < 0 ) {
- *error_code = -1; /*-1 means that system failed
- internally.*/
- free(__alarm_info);
- close(fd);
- return false;
- }
- close(fd);
- while (process_name[i] != '\0') {
- if (process_name[i] == ' ') {
- process_name[i] = '\0';
- break;
- }
- i++;
- }
- /* if (readlink(proc_file, process_name, 256)!=-1) */
- /*success */
-
- word = strtok_r(process_name, "/", &proc_name_ptr);
- while (word != NULL) {
- memset(app_name, 0, 256);
- snprintf(app_name, 256, "%s", word);
- word = strtok_r(NULL, "/", &proc_name_ptr);
- }
- __alarm_info->quark_app_unique_name =
- g_quark_from_string(app_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_app_unique_name = g_quark_from_string(app_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("null");
-
__alarm_set_start_and_end_time(alarm_info, __alarm_info);
memcpy(&(__alarm_info->alarm_info), alarm_info, sizeof(alarm_info_t));
__alarm_generate_alarm_id(__alarm_info, alarm_id);
-#ifdef __APP_SYNC
- if (_sync_scheduler_app_sync_on())
- _sync_scheduler_repeating_alarms(__alarm_info);
-#endif
-
time(¤t_time);
SECURE_LOGD("[alarm-server]:pid=%d, app_unique_name=%s, "
if (alarm_context.c_due_time < current_time) {
ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
- "(%d) is less than current time(%d)", alarm_context.c_due_time,
- current_time);
+ "(%d) is less than current time(%d)", alarm_context.c_due_time, current_time);
alarm_context.c_due_time = -1;
}
}
if (due_time == 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: "
- "due_time is 0, alarm(%d) \n", *alarm_id);
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create a new alarm: due_time is 0, alarm(%d).", *alarm_id);
return true;
} else if (current_time == due_time) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: "
- "current_time(%d) is same as due_time(%d)", current_time,
- due_time);
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Create alarm: current_time(%d) is same as due_time(%d).",
+ current_time, due_time);
return true;
- }else if (difftime(due_time, current_time) < 0){
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
+ } else if (difftime(due_time, current_time) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list.",
+ due_time, current_time);
return true;
} else {
char due_time_r[100] = { 0 };
struct tm ts_ret;
localtime_r(&due_time, &ts_ret);
strftime(due_time_r, 30, "%c", &ts_ret);
- SECURE_LOGD("[alarm-server]:Create a new alarm: "
- "alarm(%d) due_time(%s)", *alarm_id,
- due_time_r);
+ SECURE_LOGD("[alarm-server]:Create a new alarm: alarm(%d) due_time(%s)", *alarm_id, due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
- "due_time(%d)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:alarm_context.c_due_time(%d), due_time(%d)", alarm_context.c_due_time, due_time);
- if (alarm_context.c_due_time == -1
- || due_time < alarm_context.c_due_time) {
+ if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
_clear_scheduled_alarm_list();
_add_to_scheduled_alarm_list(__alarm_info);
- _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
- *alarm_id);
+ _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
alarm_context.c_due_time = due_time;
-
} else if (due_time == alarm_context.c_due_time) {
_add_to_scheduled_alarm_list(__alarm_info);
-
}
__rtc_set();
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
- /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
- * platform with app-server.because __alarm_power_on(..) fuction don't
- * use first parameter internally, we set this value to 0(zero)
- */
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
return true;
}
__alarm_info = malloc(sizeof(__alarm_info_t));
if (__alarm_info == NULL) {
- SECURE_LOGE("Caution!! app_pid=%d, "
- "malloc failed. it seems to be OOM\n", pid);
- *error_code = -1; /*-1 means that system failed
- internally.*/
+ SECURE_LOGE("Caution!! app_pid=%d, malloc failed. it seems to be OOM.", pid);
+ *error_code = ERR_ALARM_SYSTEM_FAIL;
return false;
}
if (alarm_context.c_due_time < current_time) {
ALARM_MGR_EXCEPTION_PRINT("Caution!! alarm_context.c_due_time "
- "(%d) is less than current time(%d)", alarm_context.c_due_time,
- current_time);
+ "(%d) is less than current time(%d)", alarm_context.c_due_time, current_time);
alarm_context.c_due_time = -1;
}
"(%d) does not exist. so this value is invalid id.", alarm_id);
return false;
}
- /* ALARM_MGR_LOG_PRINT("[alarm-server]:request_pid=%d, alarm_id=%d,
- * app_unique_name=%s, app_service_name=%s, dst_service_name=%s,
- * c_due_time=%d", pid, alarm_id, g_quark_to_string
- * (__alarm_info->quark_app_unique_name), g_quark_to_string
- * (__alarm_info->quark_app_service_name), g_quark_to_string
- * (__alarm_info->quark_dst_service_name), alarm_context.c_due_time);
- */
result = _remove_from_scheduled_alarm_list(pid, alarm_id);
_alarm_disable_timer(alarm_context);
_alarm_schedule();
- ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d)\n",
- alarm_id);
+ ALARM_MGR_LOG_PRINT("[alarm-server]:Update alarm: alarm(%d).", alarm_id);
__rtc_set();
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
- /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in
- * a platform with app-server.because __alarm_power_on(..) fuction don't
- * use first parameter internally, we set this value to 0(zero)
- */
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
-
if (due_time == 0) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: "
- "due_time is 0\n");
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:Update alarm: due_time is 0.");
}
free(__alarm_info);
return true;
due_time);
free(__alarm_info);
return true;
- }else if (difftime(due_time, current_time)< 0){
+ } else if (difftime(due_time, current_time)< 0) {
ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: Expired Due Time.[Due time=%d, Current Time=%d]!!!Do not add to schedule list\n", due_time, current_time);
free(__alarm_info);
return true;
"due_time(%s)\n", alarm_id, due_time_r);
}
- ALARM_MGR_LOG_PRINT("[alarm-server]:alarm_context.c_due_time(%d), "
- "due_time(%d)", alarm_context.c_due_time, due_time);
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]:alarm_context.c_due_time(%d), due_time(%d)", alarm_context.c_due_time, due_time);
- if (alarm_context.c_due_time == -1
- || due_time < alarm_context.c_due_time) {
+ if (alarm_context.c_due_time == -1 || due_time < alarm_context.c_due_time) {
_clear_scheduled_alarm_list();
_add_to_scheduled_alarm_list(__alarm_info);
- _alarm_set_timer(&alarm_context, alarm_context.timer, due_time,
- alarm_id);
+ _alarm_set_timer(&alarm_context, alarm_context.timer, due_time);
alarm_context.c_due_time = due_time;
ALARM_MGR_LOG_PRINT("[alarm-server1]:alarm_context.c_due_time "
"(%d), due_time(%d)", alarm_context.c_due_time, due_time);
__rtc_set();
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
- /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
- * in a platform with app-server.because __alarm_power_on(..) fuction
- * don't use first parameter internally, we set this value to 0(zero)
- */
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
free(__alarm_info);
return true;
SECURE_LOGD("[alarm-server]:delete alarm: alarm(%d) pid(%d)\n", alarm_id, pid);
result = _remove_from_scheduled_alarm_list(pid, alarm_id);
-#ifdef __APP_SYNC
- if (_sync_scheduler_app_sync_on())
- _sync_scheduler_remove_repeating_alarm(alarm_id);
-#endif
-
if (!__alarm_remove_from_list(pid, alarm_id, error_code)) {
SECURE_LOGE("[alarm-server]:delete alarm: "
__rtc_set();
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
- /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
- * platform with app-server.because __alarm_power_on(..) fuction don't
- * use first parameter internally, we set this value to 0(zero)
- */
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
-
- return true;
-}
-
-static bool __alarm_power_on(int app_id, bool on_off, int *error_code)
-{
-#if 0 // vincent.jang def __ALARM_BOOT
- time_t min_time = 0;
- time_t current_time = 0;
- struct rtc_time rtc_tm = { 0, };
- struct tm min_time_r = { 0, };
- int fd = 0;
- int retval;
-
- enable_power_on_alarm = on_off;
- /*_update_power_on(on_off); */ /*currently its empty*/
-
- fd = open(power_rtc, O_RDONLY);
- if (fd < 0) {
- ALARM_MGR_EXCEPTION_PRINT("cannot open /dev/rtc0\n");
- return false;
- }
-
- if (on_off == true) {
- if (_alarm_find_mintime_power_on(&min_time) == true) {
-
- ab_due_time = min_time;
-
- min_time = min_time - 60;
-
- time(¤t_time);
-
- if (min_time <= current_time)
- min_time = current_time + 5;
-
- gmtime_r(&min_time, &min_time_r);
-
- ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
- "%d\n", \
- min_time_r.tm_year,\
- min_time_r.tm_mon,\
- min_time_r.tm_mday,\
- min_time_r.tm_hour,\
- min_time_r.tm_min);
- ALARM_MGR_LOG_PRINT("__alarm_power_on : %d %d %d %d "
- "%d\n", \
- min_time_r.tm_year,\
- min_time_r.tm_mon,\
- min_time_r.tm_mday,\
- min_time_r.tm_hour,\
- min_time_r.tm_min);
-
- rtc_tm.tm_mday = min_time_r.tm_mday;
- rtc_tm.tm_mon = min_time_r.tm_mon;
- rtc_tm.tm_year = min_time_r.tm_year;
- rtc_tm.tm_hour = min_time_r.tm_hour;
- rtc_tm.tm_min = min_time_r.tm_min;
- rtc_tm.tm_sec = min_time_r.tm_sec;
- /*set_info.time_zone = 0; */
- /*set_info.u_interval.day_of_week = 0; */
-
- /*ALARM_MGR_LOG_PRINT("####__alarm_power_on : %d %d
- %d %d %d\n",set_info.year,set_info.month,set_info.day,
- set_info.hour,set_info.minute); */
-
- ALARM_MGR_LOG_PRINT("due_time : %d \n", ab_due_time);
-
- ALARM_MGR_LOG_PRINT("\n\nSetted RTC Alarm date/time is "
- "%d-%d-%d, %02d:%02d:%02d.\n",
- rtc_tm.tm_mday, rtc_tm.tm_mon + 1,
- rtc_tm.tm_year + 1900, rtc_tm.tm_hour,
- rtc_tm.tm_min, rtc_tm.tm_sec);
-
- retval = ioctl(fd, RTC_ALM_SET, &rtc_tm);
- if (retval == -1) {
- if (errno == ENOTTY) {
- ALARM_MGR_EXCEPTION_PRINT(
- "\n...Alarm IRQs not supported.\n");
- }
- ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
- close(fd);
- return false;
- }
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC "
- "alarm(POWER ON) is setted");
-
- /* Enable alarm interrupts */
- retval = ioctl(fd, RTC_AIE_ON, 0);
- if (retval == -1) {
- ALARM_MGR_EXCEPTION_PRINT(
- "RTC_AIE_ON ioctl failed");
- close(fd);
- return false;
- }
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC(POWER ON) "
- "alarm is on");
-
- } else
- retval = ioctl(fd, RTC_AIE_OFF, 0);
- } else {
- ALARM_MGR_LOG_PRINT("__alarm_power_on : off\n");
- retval = ioctl(fd, RTC_AIE_OFF, 0);
- }
-
- close(fd);
-#endif /* #ifdef __ALARM_BOOT */
-
- return true;
-}
-
-static bool __alarm_power_off(int app_id, int *error_code)
-{
-#ifdef __ALARM_BOOT
-
-#endif /* #ifdef __ALARM_BOOT */
return true;
}
-static bool __alarm_check_next_duetime(int app_id, int *error_code)
+static void __alarm_send_noti_to_application(const char *app_service_name, alarm_id_t alarm_id)
{
-#ifdef __ALARM_BOOT
- time_t current_time;
- time_t interval;
-
- time(¤t_time);
-
- interval = ab_due_time - current_time;
-
- ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", ab_due_time,
- current_time);
-
- if (interval > 0 && interval <= 60)
- return true;
- else
- return false;
-#else /* #ifdef __ALARM_BOOT */
- return true;
-#endif
-}
-
-static void __alarm_send_noti_to_application(const char *app_service_name,
- alarm_id_t alarm_id)
-{
-
-
- char service_name[MAX_SERVICE_NAME_LEN];
- char object_name[MAX_SERVICE_NAME_LEN];
-
- DBusMessage *message;
- DBusMessageIter iter;
+ char service_name[MAX_SERVICE_NAME_LEN] = {0,};
if (app_service_name == NULL || strlen(app_service_name) == 0) {
- ALARM_MGR_EXCEPTION_PRINT("This alarm destination is "
- "invalid\n");
- return;
- }
- memset(service_name, 0, MAX_SERVICE_NAME_LEN);
- memcpy(service_name, app_service_name, strlen(app_service_name));
-
- snprintf(object_name, MAX_SERVICE_NAME_LEN,
- "/com/samsung/alarm/client");
-
- SECURE_LOGD("[alarm server][send expired_alarm(alarm_id=%d)to"
- "app_service_name(%s), object_name(%s), interface_name(%s)]\n",\
- alarm_id, service_name, object_name, "com.samsung.alarm.client");
-
- message = dbus_message_new_method_call(service_name,
- object_name,
- "com.samsung.alarm.client",
- "alarm_expired");
- if (message == NULL) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
- "dbus_message_new_method_call faild. maybe OOM!.\n");
- SECURE_LOGE("[alarm server] so we cannot "
- "send expired alarm to %s\n", service_name);
- return;
- }
-
- dbus_message_set_no_reply(message, TRUE);
- /* if(service_name[0]==':') */
- /* we don't need auto activation in a case that
- destination_app_service_name starts with a charactor like (:) */
- dbus_message_set_auto_start(message, FALSE);
-
- dbus_message_iter_init_append(message, &iter);
- if (!dbus_message_iter_append_basic
- (&iter, DBUS_TYPE_INT32, &alarm_id)) {
- dbus_message_unref(message);
- ALARM_MGR_EXCEPTION_PRINT("[alarm server] "
- "dbus_message_iter_append_basic faild. maybe OOM!.\n");
+ ALARM_MGR_EXCEPTION_PRINT("This alarm destination is invalid.");
return;
}
- dbus_connection_send(dbus_g_connection_get_connection
- (alarm_context.bus), message, NULL);
- dbus_connection_flush(dbus_g_connection_get_connection
- (alarm_context.bus));
- dbus_message_unref(message);
-
+ memcpy(service_name, app_service_name, strlen(app_service_name));
+ SECURE_LOGI("[alarm server][send expired_alarm(alarm_id=%d) to app_service_name(%s)]", alarm_id, service_name);
+
+ g_dbus_connection_call(alarm_context.connection,
+ service_name,
+ "/com/samsung/alarm/client",
+ "com.samsung.alarm.client",
+ "alarm_expired",
+ g_variant_new("(is)", alarm_id, service_name),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ NULL);
}
static void __alarm_expired()
int b_len = 0;
bundle *b = NULL;
char *appid = NULL;
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+ GError *error = NULL;
+ GVariant *result = NULL;
+ gboolean name_has_owner_reply = false;
- ALARM_MGR_LOG_PRINT("[alarm-server]: Enter \n");
+ ALARM_MGR_LOG_PRINT("[alarm-server]: Enter");
time_t current_time;
double interval;
time(¤t_time);
interval = difftime(alarm_context.c_due_time, current_time);
- ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), "
- "current_time(%d), interval(%d)\n", alarm_context.c_due_time,
- current_time, interval);
+ ALARM_MGR_LOG_PRINT("[alarm-server]: c_due_time(%d), current_time(%d), interval(%d)",
+ alarm_context.c_due_time, current_time, interval);
if (alarm_context.c_due_time > current_time + 1) {
- ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: False Alarm. due time is (%d) seconds future\n",
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-server]: False Alarm. due time is (%d) seconds future",
alarm_context.c_due_time - current_time);
goto done;
}
GSList *iter = NULL;
__scheduled_alarm_t *alarm = NULL;
- for (iter = g_scheduled_alarm_list; iter != NULL;
- iter = g_slist_next(iter)) {
+ for (iter = g_scheduled_alarm_list; iter != NULL; iter = g_slist_next(iter)) {
alarm = iter->data;
alarm_id = alarm->alarm_id;
app_pid = __alarm_info->pid;
- if (strncmp
- (g_quark_to_string(__alarm_info->quark_bundle),
- "null", 4) != 0) {
-
+ if (strncmp(g_quark_to_string(__alarm_info->quark_bundle), "null", 4) != 0) {
b_len = strlen(g_quark_to_string(__alarm_info->quark_bundle));
b = bundle_decode((bundle_raw *)g_quark_to_string(__alarm_info->quark_bundle), b_len);
- if (NULL == b)
+ if (b == NULL)
{
ALARM_MGR_EXCEPTION_PRINT("Error!!!..Unable to decode the bundle!!\n");
}
{
snprintf(alarm_id_val,31,"%d",alarm_id);
- if (bundle_add(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
+ if (bundle_add_str(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
}
else
{
- appid = appsvc_get_appid(b);
+ appid = (char *)appsvc_get_appid(b);
if( (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_NOLAUNCH) && !aul_app_is_running(appid))
{
ALARM_MGR_EXCEPTION_PRINT("This alarm is ignored\n");
}
else
{
- if (strncmp
- (g_quark_to_string(__alarm_info->quark_dst_service_name),
- "null",4) == 0) {
- SECURE_LOGD("[alarm-server]:destination is "
- "null, so we send expired alarm to %s(%u)\n",\
- g_quark_to_string(
- __alarm_info->quark_app_service_name),
- __alarm_info->quark_app_service_name);
- destination_app_service_name = g_quark_to_string(
- __alarm_info->quark_app_service_name_mod);
+ if (strncmp(g_quark_to_string(__alarm_info->quark_dst_service_name), "null", 4) == 0) {
+ SECURE_LOGD("[alarm-server]:destination is null, so we send expired alarm to %s(%u).",
+ g_quark_to_string(__alarm_info->quark_app_service_name), __alarm_info->quark_app_service_name);
+ destination_app_service_name = g_quark_to_string(__alarm_info->quark_app_service_name_mod);
} else {
- SECURE_LOGD("[alarm-server]:destination "
- ":%s(%u)\n",
- g_quark_to_string(
- __alarm_info->quark_dst_service_name),
- __alarm_info->quark_dst_service_name);
- destination_app_service_name = g_quark_to_string(
- __alarm_info->quark_dst_service_name_mod);
- }
-
-#if 0 // vincent.jang def __ALARM_BOOT
- /* orginally this code had if(__alarm_info->app_id==21) in a
- platform with app-server. */
- /*if(__alarm_info->quark_dst_service_name ==
- g_quark_from_string (WAKEUP_ALARM_APP_ID)) */
- if (strcmp
- (g_quark_to_string(__alarm_info->quark_dst_service_name),
- WAKEUP_ALARM_APP_ID) == 0) {
- int fd = 0;
- fd = open(power_rtc, O_RDONLY);
- if (fd < 0) {
- ALARM_MGR_LOG_PRINT("cannot open /dev/rtc0\n");
- } else {
- ioctl(fd, RTC_AIE_OFF, 0);
- close(fd);
- }
+ SECURE_LOGD("[alarm-server]:destination :%s(%u)",
+ g_quark_to_string(__alarm_info->quark_dst_service_name), __alarm_info->quark_dst_service_name);
+ destination_app_service_name = g_quark_to_string(__alarm_info->quark_dst_service_name_mod);
}
-#endif
/*
* we should consider a situation that
* we don't need to send the expire event because the process was killed.
* this causes needless message to be sent.
*/
- SECURE_LOGD("[alarm-server]: "
- "destination_app_service_name :%s, app_pid=%d\n",
- destination_app_service_name, app_pid);
- /* the following is a code that checks the above situation.
- please verify this code. */
-
- if (dbus_bus_name_has_owner(
- dbus_g_connection_get_connection(alarm_context.bus),
- destination_app_service_name, NULL) == FALSE) {
+ SECURE_LOGD("[alarm-server]: destination_app_service_name :%s, app_pid=%d", destination_app_service_name, app_pid);
+
+ result = g_dbus_connection_call_sync(alarm_context.connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "NameHasOwner",
+ g_variant_new ("(s)", destination_app_service_name),
+ G_VARIANT_TYPE ("(b)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (result == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("g_dbus_connection_call_sync() is failed. err: %s", error->message);
+ g_error_free(error);
+ } else {
+ g_variant_get (result, "(b)", &name_has_owner_reply);
+ }
+
+ if (name_has_owner_reply == false) {
__expired_alarm_t *expire_info;
char appid[MAX_SERVICE_NAME_LEN] = { 0, };
char alarm_id_str[32] = { 0, };
}
expire_info = malloc(sizeof(__expired_alarm_t));
- if (G_UNLIKELY(NULL == expire_info)){
+ if (G_UNLIKELY(NULL == expire_info)) {
ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n");
goto done;
}
- memset(expire_info, '\0', MAX_SERVICE_NAME_LEN);
- strncpy(expire_info->service_name,
- destination_app_service_name,
- MAX_SERVICE_NAME_LEN-1);
+ memset(expire_info, '\0', sizeof(__expired_alarm_t));
+ strncpy(expire_info->service_name, destination_app_service_name, MAX_SERVICE_NAME_LEN-1);
expire_info->alarm_id = alarm_id;
- g_expired_alarm_list =
- g_slist_append(g_expired_alarm_list, expire_info);
-
+ g_expired_alarm_list = g_slist_append(g_expired_alarm_list, expire_info);
- if (strncmp
- (g_quark_to_string(__alarm_info->quark_dst_service_name),
- "null",4) == 0) {
+ if (strncmp(g_quark_to_string(__alarm_info->quark_dst_service_name), "null",4) == 0) {
strncpy(appid,g_quark_to_string(__alarm_info->quark_app_service_name)+6,strlen(g_quark_to_string(__alarm_info->quark_app_service_name))-6);
}
- else
- {
+ else {
strncpy(appid,g_quark_to_string(__alarm_info->quark_dst_service_name)+6,strlen(g_quark_to_string(__alarm_info->quark_dst_service_name))-6);
}
snprintf(alarm_id_str, 31, "%d", alarm_id);
- SECURE_LOGD("before aul_launch appid(%s) "
- "alarm_id_str(%s)\n", appid, alarm_id_str);
+ SECURE_LOGD("before aul_launch appid(%s) alarm_id_str(%s)", appid, alarm_id_str);
bundle *kb;
kb = bundle_create();
- bundle_add(kb, "__ALARM_MGR_ID", alarm_id_str);
+ bundle_add_str(kb, "__ALARM_MGR_ID", alarm_id_str);
aul_launch_app(appid, kb);
bundle_free(kb);
} else {
- ALARM_MGR_LOG_PRINT(
- "before alarm_send_noti_to_application\n");
- __alarm_send_noti_to_application(
- destination_app_service_name, alarm_id);
+ ALARM_MGR_LOG_PRINT("before alarm_send_noti_to_application");
+ ALARM_MGR_LOG_PRINT("WAKEUP pid: %d", __alarm_info->pid);
+
+ aul_update_freezer_status(__alarm_info->pid, "wakeup");
+ __alarm_send_noti_to_application(destination_app_service_name, alarm_id);
+ ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application");
}
}
- ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application\n");
-/* if( !(__alarm_info->alarm_info.alarm_type
- & ALARM_TYPE_VOLATILE) ) {
- __alarm_remove_from_list(__alarm_info->pid,
- alarm_id, NULL);
- }
- else */
- if (__alarm_info->alarm_info.mode.repeat
- == ALARM_REPEAT_MODE_ONCE) {
-/* _alarm_next_duetime(__alarm_info);*/
-/* _update_alarms(__alarm_info);*/
- __alarm_remove_from_list(__alarm_info->pid, alarm_id,
- NULL);
- } else {
+ ALARM_MGR_EXCEPTION_PRINT("alarm_id[%d] is expired.", alarm_id);
+
+ sprintf(log_message, "alarmID: %d, pid: %d, unique_name: %s, duetime: %d",
+ alarm_id, app_pid, g_quark_to_string(__alarm_info->quark_app_unique_name), __alarm_info->due_time);
+ __save_module_log("EXPIRED", log_message);
+ memset(log_message, '\0', sizeof(log_message));
+ if (__alarm_info->alarm_info.mode.repeat == ALARM_REPEAT_MODE_ONCE) {
+ __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL);
+ } else {
_alarm_next_duetime(__alarm_info);
-/* _update_alarms(__alarm_info);*/
}
-
}
done:
_clear_scheduled_alarm_list();
alarm_context.c_due_time = -1;
- ALARM_MGR_LOG_PRINT("[alarm-server]: Leave \n");
+ ALARM_MGR_LOG_PRINT("[alarm-server]: Leave");
}
-static gboolean __alarm_handler_idle()
+static gboolean __alarm_handler_idle(gpointer user_data)
{
-#ifdef WEARABLE_PROFILE
- display_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
-#endif
- if (g_dummy_timer_is_set == true) {
- ALARM_MGR_LOG_PRINT("dummy alarm timer has expired\n");
- } else {
- ALARM_MGR_LOG_PRINT("__alarm_handler \n");
- ALARM_MGR_LOG_PRINT("__alarm_handler \n");
+ GPollFD *gpollfd = (GPollFD *) user_data;
+ uint64_t exp;
+ if (gpollfd == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("gpollfd is NULL");
+ return false;
+ }
+ if (read(gpollfd->fd, &exp, sizeof(uint64_t)) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Reading the fd is failed.");
+ return false;
+ }
- __alarm_expired();
+ ALARM_MGR_EXCEPTION_PRINT("Lock the display not to enter LCD OFF");
+ if (__display_lock_state(DEVICED_LCD_OFF, DEVICED_STAY_CUR_STATE, 0) != ALARMMGR_RESULT_SUCCESS) {
+ ALARM_MGR_EXCEPTION_PRINT("__display_lock_state() is failed");
+ }
+ if (g_dummy_timer_is_set == true) {
+ ALARM_MGR_LOG_PRINT("dummy alarm timer has expired.");
+ }
+ else {
+ ALARM_MGR_LOG_PRINT("__alarm_handler_idle");
+ __alarm_expired();
}
_alarm_schedule();
__rtc_set();
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
- /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID)
- *in a platform with app-server.because __alarm_power_on(..) fuction
- *don't use first parameter internally, we set this value to 0(zero)
- */
- __alarm_power_on(0, enable_power_on_alarm, NULL);
+ ALARM_MGR_EXCEPTION_PRINT("Unlock the display from LCD OFF");
+ if (__display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS) {
+ ALARM_MGR_EXCEPTION_PRINT("__display_unlock_state() is failed");
}
-#endif
-#ifdef WEARABLE_PROFILE
- display_unlock_state(LCD_OFF, PM_SLEEP_MARGIN);
-#endif
- return false;
-}
-
-static void __alarm_handler(int sigNum, siginfo_t *pSigInfo, void *pUContext)
-{
- /* we moved __alarm_expired() function to __alarm_handler_idle GSource
- because of signal safety. */
- g_idle_add_full(G_PRIORITY_HIGH, __alarm_handler_idle, NULL, NULL);
+ return false;
}
static void __clean_registry()
static bool __alarm_manager_reset()
{
-
_alarm_disable_timer(alarm_context);
__alarm_clean_list();
return true;
}
-static int __alarm_delete_handler(pkgmgrinfo_appinfo_h handle, void* data)
-{
- char* appid;
- GSList* gs_iter = NULL;
- __alarm_info_t* entry = NULL;
- alarm_info_t* alarm_info = NULL;
- gchar* bundle_data = NULL;
- bundle* b = NULL;
- const char* caller_appid = NULL;
- const char* callee_appid = NULL;
- bool isDeleted = false;
-
- pkgmgrinfo_appinfo_get_appid(handle, &appid); // uninstalled app id
- SECURE_LOGD("The uninstalled appid is [%s]\n", appid);
-
- // If the uninstalled app is same to caller or callee app, all alarms registered in the app will be deleted.
- for (gs_iter = alarm_context.alarms; gs_iter != NULL; )
- {
- bool isFound = false;
- entry = gs_iter->data;
-
- bundle_data = g_strdup(g_quark_to_string(entry->quark_bundle));
- b = bundle_decode((bundle_raw*)bundle_data, strlen(bundle_data));
- caller_appid = bundle_get_val(b, "__ALARM_MGR_CALLER_APPID");
- callee_appid = appsvc_get_appid(b);
-
- SECURE_LOGD("Try to remove alarm_id[%d], caller_appid[%s], callee_appid[%s]", entry->alarm_id, caller_appid, callee_appid);
-
- if (strcmp(appid, caller_appid) == 0 || strcmp(appid, callee_appid) == 0)
- {
- if (_remove_from_scheduled_alarm_list(appid, entry->alarm_id))
- {
- isDeleted = true;
- }
-
- alarm_info = &entry->alarm_info;
- if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
- {
- if(!_delete_alarms(entry->alarm_id))
- {
- SECURE_LOGD("_delete_alarms() is failed. appid[%s], alarm_id[%d]", appid, entry->alarm_id);
- }
- }
- SECURE_LOGD("Removing is done! alarm_id[%d]", entry->alarm_id);
- isFound = true;
- }
-
- gs_iter = g_slist_next(gs_iter);
-
- if (isFound)
- {
- alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
- }
- }
-
- if (isDeleted && (g_slist_length(g_scheduled_alarm_list) == 0))
- {
- _alarm_disable_timer(alarm_context);
- _alarm_schedule();
- }
-
- __rtc_set();
-
- return 0;
-}
-
-static void __alarm_delete_for_webapp(char* pkgid)
-{
- GSList* gs_iter = NULL;
- __alarm_info_t* entry = NULL;
- alarm_info_t* alarm_info = NULL;
- gchar* bundle_data = NULL;
- bundle* b = NULL;
- const char* caller_appid = NULL;
- const char* callee_appid = NULL;
- const char* appid = NULL;
- bool isDeleted = false;
-
- SECURE_LOGD("The uninstalled pkgid of webapp is [%s]\n", pkgid);
-
- // If the uninstalled web app(wgt) is same to caller or callee app, all alarms registered in the app will be deleted.
- for (gs_iter = alarm_context.alarms; gs_iter != NULL; )
- {
- entry = gs_iter->data;
-
- bundle_data = g_strdup(g_quark_to_string(entry->quark_bundle));
- b = bundle_decode((bundle_raw*)bundle_data, strlen(bundle_data));
- caller_appid = bundle_get_val(b, "__ALARM_MGR_CALLER_APPID");
- callee_appid = appsvc_get_appid(b);
-
- SECURE_LOGD("Try to remove alarm_id[%d], caller_appid[%s], callee_appid[%s]", entry->alarm_id, caller_appid, callee_appid);
-
- if (strncmp(pkgid, caller_appid, 10) == 0)
- {
- appid = caller_appid;
- }
- else if (strncmp(pkgid, callee_appid, 10) == 0)
- {
- appid = callee_appid;
- }
- else
- {
- gs_iter = g_slist_next(gs_iter);
- continue;
- }
-
- if (_remove_from_scheduled_alarm_list(appid, entry->alarm_id))
- {
- isDeleted = true;
- }
-
- alarm_info = &entry->alarm_info;
- if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
- {
- if(!_delete_alarms(entry->alarm_id))
- {
- SECURE_LOGD("_delete_alarms() is failed. appid[%s], alarm_id[%d]", appid, entry->alarm_id);
- }
- }
- SECURE_LOGD("Removing is done! alarm_id[%d]", entry->alarm_id);
-
- gs_iter = g_slist_next(gs_iter);
- alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
- }
-
- if (isDeleted && (g_slist_length(g_scheduled_alarm_list) == 0))
- {
- _alarm_disable_timer(alarm_context);
- _alarm_schedule();
- }
-
- __rtc_set();
-}
-
static void __on_system_time_external_changed(keynode_t *node, void *data)
{
- double diff_time;
+ double diff_time = 0.0;
time_t cur_time = 0;
_alarm_disable_timer(alarm_context);
if (node) {
diff_time = vconf_keynode_get_dbl(node);
} else {
- vconf_get_dbl(VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, &diff_time);
+ if (vconf_get_dbl(VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL, &diff_time) != VCONF_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get value of VCONFKEY_SYSTEM_TIMECHANGE_EXTERNAL.");
+ return;
+ }
}
tzset();
_clear_scheduled_alarm_list();
_alarm_schedule();
__rtc_set();
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
-/* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
-APP_ID) in a platform with app-server. because _alarm_power_
-on(..) fuction don't use first parameter internally, we set
-this value to 0(zero)
-*/
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
+
return;
}
_clear_scheduled_alarm_list();
_alarm_schedule();
__rtc_set();
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
-/* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
-APP_ID) in a platform with app-server. because _alarm_power_
-on(..) fuction don't use first parameter internally, we set
-this value to 0(zero)
-*/
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
+
return;
}
const char *pkgid, const char *key, const char *val,
const void *pmsg, void *user_data)
{
- pkgmgrinfo_pkginfo_h handle;
+ GSList* gs_iter = NULL;
+ __alarm_info_t* entry = NULL;
+ alarm_info_t* alarm_info = NULL;
+ bool is_deleted = false;
SECURE_LOGD("pkg_type(%s), pkgid(%s), key(%s), value(%s)", pkg_type, pkgid, key, val);
- if (strncmp(key, "start", 5) == 0 && strncmp(val, "uninstall", 9) == 0)
+ if (strncmp(key, "end", 3) == 0 && strncmp(val, "ok", 2) == 0)
{
- if (strncmp(pkg_type, "wgt", 3) != 0)
+ for (gs_iter = alarm_context.alarms; gs_iter != NULL; )
{
- if (pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle) != PMINFO_R_OK)
+ bool is_found = false;
+ entry = gs_iter->data;
+
+ char* caller_pkgid = g_quark_to_string(entry->quark_caller_pkgid);
+ char* callee_pkgid = g_quark_to_string(entry->quark_callee_pkgid);
+
+ if ((caller_pkgid && strncmp(pkgid, caller_pkgid, strlen(pkgid)) == 0) ||
+ (callee_pkgid && strncmp(pkgid, callee_pkgid, strlen(pkgid)) == 0))
{
- ALARM_MGR_EXCEPTION_PRINT("Getting package info is failed.\n");
- return PMINFO_R_ERROR;
+ if (_remove_from_scheduled_alarm_list(pkgid, entry->alarm_id))
+ {
+ is_deleted = true;
+ }
+
+ alarm_info = &entry->alarm_info;
+ if (!(alarm_info->alarm_type & ALARM_TYPE_VOLATILE))
+ {
+ if(!_delete_alarms(entry->alarm_id))
+ {
+ SECURE_LOGE("_delete_alarms() is failed. pkgid[%s], alarm_id[%d]", pkgid, entry->alarm_id);
+ }
+ }
+ is_found = true;
}
- if (pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, __alarm_delete_handler, user_data) != PMINFO_R_OK)
+ gs_iter = g_slist_next(gs_iter);
+
+ if (is_found)
{
- ALARM_MGR_EXCEPTION_PRINT("Getting package list is failed.\n");
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return PMINFO_R_ERROR;
+ SECURE_LOGD("Remove pkgid[%s], alarm_id[%d]", pkgid, entry->alarm_id);
+ alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
+ g_free(entry);
}
-
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
}
- }
- else if (strncmp(key, "end", 3) == 0 && strncmp(val, "ok", 2) == 0)
- {
- if (strncmp(pkg_type, "wgt", 3) == 0)
+
+ if (is_deleted && (g_slist_length(g_scheduled_alarm_list) == 0))
{
- __alarm_delete_for_webapp(pkgid);
+ _alarm_disable_timer(alarm_context);
+ _alarm_schedule();
}
}
- return PMINFO_R_OK;
+ __rtc_set();
+
+ return ALARMMGR_RESULT_SUCCESS;
}
-gboolean alarm_manager_alarm_set_rtc_time(void *pObject, int pid,
- int year, int mon, int day,
- int hour, int min, int sec, char *e_cookie,
- int *return_code){
+int __check_privilege_by_cookie(char *e_cookie, const char *label, const char *access, bool check_root, int pid) {
guchar *cookie = NULL;
- gsize size;
+ gsize size = 0;
int retval = 0;
- gboolean result = true;
+ char buf[128] = {0,};
+ FILE *fp = NULL;
+ char title[128] = {0,};
+ int uid = -1;
- const char *rtc = default_rtc;
- struct timespec alarm_time;
+ if (check_root) {
+ // Gets the userID from /proc/pid/status to check if the process is the root or not.
+ snprintf(buf, sizeof(buf), "/proc/%d/status", pid);
+ fp = fopen(buf, "r");
+ if(fp) {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
+ if(strncmp(buf, "Uid:", 4) == 0) {
+ sscanf(buf, "%s %d", title, &uid);
+ break;
+ }
+ }
+ fclose(fp);
+ }
- struct rtc_time rtc_tm = {0,};
- struct rtc_wkalrm rtc_wk;
- struct tm *alarm_tm = NULL;
+ ALARM_MGR_LOG_PRINT("uid : %d", uid);
+ }
+
+ if (uid != 0) { // Checks the cookie only when the process is not the root
+ cookie = g_base64_decode(e_cookie, &size);
+ if (cookie == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+
+ retval = security_server_check_privilege_by_cookie((const char *)cookie, label, access);
+ g_free(cookie);
- if (return_code){
- *return_code = ALARMMGR_RESULT_SUCCESS;
+ if (retval < 0) {
+ if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
+ ALARM_MGR_EXCEPTION_PRINT("Access to alarm-server has been denied by smack.");
+ }
+ ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege_by_cookie() : %d.", retval);
+ return ERR_ALARM_NO_PERMISSION;
+ }
}
- cookie = g_base64_decode(e_cookie, &size);
- if (NULL == cookie)
+ ALARM_MGR_LOG_PRINT("The process(%d) was authenticated successfully.", pid);
+ return ALARMMGR_RESULT_SUCCESS;
+}
+
+bool __get_caller_unique_name(int pid, char *unique_name)
+{
+ char caller_appid[256] = {0,};
+
+ if (unique_name == NULL)
{
- if (return_code)
- *return_code = ERR_ALARM_NO_PERMISSION;
- ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
- return true;
+ ALARM_MGR_EXCEPTION_PRINT("unique_name should not be NULL.");
+ return false;
}
- retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "w");
- if (retval < 0) {
- if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
- ALARM_MGR_EXCEPTION_PRINT(
- "%s", "Write access has been denied by smack\n");
- }
- ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
- if (return_code)
- *return_code = ERR_ALARM_NO_PERMISSION;
+ if (aul_app_get_appid_bypid(pid, caller_appid, sizeof(caller_appid)) == AUL_R_OK)
+ {
+ // When a caller is an application, the unique name is appID.
+ strncpy(unique_name, caller_appid, strlen(caller_appid));
}
else
{
- /*extract day of the week, day in the year &
- daylight saving time from system*/
- time_t ctime;
- ctime = time(NULL);
- alarm_tm = localtime(&ctime);
-
- alarm_tm->tm_year = year;
- alarm_tm->tm_mon = mon;
- alarm_tm->tm_mday = day;
- alarm_tm->tm_hour = hour;
- alarm_tm->tm_min = min;
- alarm_tm->tm_sec = sec;
-
- /*convert to calendar time representation*/
- time_t rtc_time = mktime(alarm_tm);
-
- if (gfd == 0) {
- gfd = open(rtc, O_RDWR);
- if (gfd == -1) {
- ALARM_MGR_EXCEPTION_PRINT("RTC open failed.\n");
- if (return_code)
- *return_code = ERR_ALARM_SYSTEM_FAIL;
- return result;
- }
- }
+ // Otherwise, the unique name is /proc/pid/cmdline.
+ char proc_file[512] = {0,};
+ char process_name[512] = {0,};
+ int fd = 0;
+ int i = 0;
- alarm_time.tv_sec = rtc_time;
- alarm_time.tv_nsec = 0;
+ snprintf(proc_file, 512, "/proc/%d/cmdline", pid);
- retval = ioctl(gfd, ALARM_SET(ALARM_RTC_WAKEUP), &alarm_time);
- if (retval == -1) {
- if (errno == ENOTTY) {
- ALARM_MGR_EXCEPTION_PRINT("\nAlarm IRQs not"
- "supported.\n");
+ fd = open(proc_file, O_RDONLY);
+ if (fd < 0) {
+ SECURE_LOGE("Caution!! pid(%d) seems to be killed, so we failed to get proc file(%s) and do not create alarm_info.", pid, proc_file);
+ return false;
+ }
+ else {
+ if (read(fd, process_name, 512) <= 0)
+ {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to get the process name.");
+ close(fd);
+ return false;
+ }
+ close(fd);
+
+ while (process_name[i] != '\0') {
+ if (process_name[i] == ' ') {
+ process_name[i] = '\0';
+ break;
+ }
+ ++i;
}
- ALARM_MGR_EXCEPTION_PRINT("RTC_ALM_SET ioctl");
- //close(fd);
- if (return_code)
- *return_code = ERR_ALARM_SYSTEM_FAIL;
+ strncpy(unique_name, process_name, strlen(process_name));
}
- else{
- ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
- //close(fd);
+ }
+
+ SECURE_LOGD("unique_name= %s", unique_name);
+ return true;
+}
+
+static void __initialize_module_log(void)
+{
+ log_fd = open(ALARMMGR_LOG_FILE_PATH, O_CREAT | O_WRONLY, 0644);
+ if (log_fd == -1) {
+ ALARM_MGR_EXCEPTION_PRINT("Opening the file for alarmmgr log is failed.");
+ return;
+ }
+
+ int offset = lseek(log_fd, 0, SEEK_END);
+ if (offset != 0) {
+ log_index = (int)(offset / ALARMMGR_LOG_BUFFER_STRING_SIZE);
+ if (log_index >= ALARMMGR_LOG_BUFFER_SIZE) {
+ log_index = 0;
+ lseek(log_fd, 0, SEEK_SET);
}
}
+ return;
+}
- if (cookie){
- g_free(cookie);
- cookie = NULL;
+static bool __save_module_log(const char *tag, const char *message)
+{
+ char buffer[ALARMMGR_LOG_BUFFER_STRING_SIZE] = {0,};
+ time_t now;
+ int offset = 0;
+
+ if (log_fd == -1) {
+ ALARM_MGR_EXCEPTION_PRINT("The file is not ready.");
+ return false;
+ }
+
+ if (log_index != 0) {
+ offset = lseek(log_fd, 0, SEEK_CUR);
+ } else {
+ offset = lseek(log_fd, 0, SEEK_SET);
}
- return result;
+ time(&now);
+ snprintf(buffer, ALARMMGR_LOG_BUFFER_STRING_SIZE, "[%-6d] %-20s %-120s %d-%s", log_index, tag, message, (int)now, ctime(&now));
+ int ret = write(log_fd, buffer, strlen(buffer));
+ if (ret < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Writing the alarmmgr log is failed.");
+ return false;
+ }
+
+ if (++log_index >= ALARMMGR_LOG_BUFFER_SIZE) {
+ log_index = 0;
+ }
+ return true;
}
-gboolean alarm_manager_alarm_set_time(void *pObject, int _time, int *return_code)
+int __display_lock_state(char *state, char *flag, unsigned int timeout)
{
- double diff_time;
- time_t before;
- gboolean result = true;
+ GDBusMessage *msg = NULL;
+ GDBusMessage *reply = NULL;
+ GVariant *body = NULL;
+ GError *error = NULL;
+ int ret = ALARMMGR_RESULT_SUCCESS;
+ int val = -1;
+
+ msg = g_dbus_message_new_method_call(DEVICED_BUS_NAME, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, DEVICED_LOCK_STATE);
+ if (!msg) {
+ ALARM_MGR_EXCEPTION_PRINT("g_dbus_message_new_method_call() is failed. (%s:%s-%s)", DEVICED_BUS_NAME, DEVICED_INTERFACE_DISPLAY, DEVICED_LOCK_STATE);
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+
+ g_dbus_message_set_body(msg, g_variant_new("(sssi)", state, flag, "NULL", timeout));
+
+ reply = g_dbus_connection_send_message_with_reply_sync(alarm_context.connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DEVICED_DBUS_REPLY_TIMEOUT, NULL, NULL, &error);
+ if (!reply) {
+ ALARM_MGR_EXCEPTION_PRINT("No reply. error = %s", error->message);
+ g_error_free(error);
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ } else {
+ body = g_dbus_message_get_body(reply);
+ if (!body) {
+ ALARM_MGR_EXCEPTION_PRINT("g_dbus_message_get_body() is failed.");
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ } else {
+ g_variant_get(body, "(i)", &val);
+ if (val != 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to lock display");
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ } else {
+ ALARM_MGR_EXCEPTION_PRINT("Lock LCD OFF is successfully done");
+ }
+ }
+ }
+
+ g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL);
+ g_object_unref(msg);
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int __display_unlock_state(char *state, char *flag)
+{
+ GDBusMessage *msg = NULL;
+ GDBusMessage *reply = NULL;
+ GVariant *body = NULL;
+ GError *error = NULL;
+ int ret = ALARMMGR_RESULT_SUCCESS;
+ int val = -1;
+
+ msg = g_dbus_message_new_method_call(DEVICED_BUS_NAME, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, DEVICED_UNLOCK_STATE);
+ if (!msg) {
+ ALARM_MGR_EXCEPTION_PRINT("g_dbus_message_new_method_call() is failed. (%s:%s-%s)", DEVICED_BUS_NAME, DEVICED_INTERFACE_DISPLAY, DEVICED_UNLOCK_STATE);
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+
+ g_dbus_message_set_body(msg, g_variant_new("(ss)", state, flag ));
+
+ reply = g_dbus_connection_send_message_with_reply_sync(alarm_context.connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, DEVICED_DBUS_REPLY_TIMEOUT, NULL, NULL, &error);
+ if (!reply) {
+ ALARM_MGR_EXCEPTION_PRINT("No reply. error = %s", error->message);
+ g_error_free(error);
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ } else {
+ body = g_dbus_message_get_body(reply);
+ if (!body) {
+ ALARM_MGR_EXCEPTION_PRINT("g_dbus_message_get_body() is failed.");
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ } else {
+ g_variant_get(body, "(i)", &val);
+ if (val != 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to unlock display");
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ } else {
+ ALARM_MGR_EXCEPTION_PRINT("Unlock LCD OFF is successfully done");
+ }
+ }
+ }
- if (return_code){
- *return_code = ALARMMGR_RESULT_SUCCESS;
+ g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL);
+ g_object_unref(msg);
+ g_object_unref(reply);
+
+ return ret;
+}
+
+gboolean alarm_manager_alarm_set_rtc_time(AlarmManager *pObj, GDBusMethodInvocation *invoc, int pid,
+ int year, int mon, int day,
+ int hour, int min, int sec, char *e_cookie,
+ gpointer user_data) {
+ const char *rtc = default_rtc;
+ struct timespec alarm_time;
+ int retval = 0;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+
+ struct rtc_time rtc_tm = {0,};
+ struct rtc_wkalrm rtc_wk;
+ struct tm *alarm_tm = NULL;
+
+ char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", false, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+ return true;
+ }
+
+ /*extract day of the week, day in the year & daylight saving time from system*/
+ time_t current_time;
+ current_time = time(NULL);
+ alarm_tm = localtime(¤t_time);
+
+ alarm_tm->tm_year = year;
+ alarm_tm->tm_mon = mon;
+ alarm_tm->tm_mday = day;
+ alarm_tm->tm_hour = hour;
+ alarm_tm->tm_min = min;
+ alarm_tm->tm_sec = sec;
+
+ /*convert to calendar time representation*/
+ time_t rtc_time = mktime(alarm_tm);
+
+ if (gfd == 0) {
+ gfd = open(rtc, O_RDWR);
+ if (gfd == -1) {
+ ALARM_MGR_EXCEPTION_PRINT("RTC open failed.");
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+ return true;
+ }
}
+ alarm_time.tv_sec = rtc_time;
+ alarm_time.tv_nsec = 0;
+
+ retval = ioctl(gfd, ALARM_SET(ALARM_RTC_WAKEUP), &alarm_time);
+ if (retval == -1) {
+ if (errno == ENOTTY) {
+ ALARM_MGR_EXCEPTION_PRINT("Alarm IRQs is not supported.");
+ }
+ ALARM_MGR_EXCEPTION_PRINT("RTC ALARM_SET ioctl is failed. errno = %s", strerror(errno));
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ strncpy(log_tag, "FAIL: SET RTC", strlen("FAIL: SET RTC"));
+ }
+ else{
+ ALARM_MGR_LOG_PRINT("[alarm-server]RTC alarm is setted");
+ strncpy(log_tag, "SET RTC", strlen("SET RTC"));
+ }
+
+ sprintf(log_message, "wakeup rtc time: %d, %s", rtc_time, ctime(&rtc_time));
+ __save_module_log(log_tag, log_message);
+
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+ return true;
+}
+
+gboolean alarm_manager_alarm_set_time(AlarmManager *pObj, GDBusMethodInvocation *invoc, int _time, gpointer user_data)
+{
+ static int diff_msec = 0; // To check a millisecond part of current time at changing the system time
+ double diff_time = 0.0;
+ struct timeval before;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+
_alarm_disable_timer(alarm_context);
- time(&before);
- diff_time = difftime(_time, before);
+ gettimeofday(&before, NULL);
+ diff_msec += (before.tv_usec / 1000); // Accrue the millisecond to compensate the time
+ ALARM_MGR_LOG_PRINT("Current time = %s. usec = %ld. diff_msec = %d.\n", ctime(&before.tv_sec), before.tv_usec, diff_msec);
+
+ if (diff_msec > 500) {
+ diff_time = difftime(_time, before.tv_sec) - 1;
+ diff_msec -= 1000;
+ }
+ else {
+ diff_time = difftime(_time, before.tv_sec);
+ }
tzset();
- ALARM_MGR_EXCEPTION_PRINT("New time is %s, diff_time is %f\n", ctime(&_time), diff_time);
+ char *timebuf = ctime(&_time);
+ timebuf[strlen(timebuf) - 1] = '\0'; // to avoid newline
+ sprintf(log_message, "Current: %d, New: %d, %s, diff: %f", before.tv_sec, _time, timebuf, diff_time);
+ __save_module_log("CHANGE TIME", log_message);
- ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed\n");
- ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n",
- alarm_context.c_due_time);
+ ALARM_MGR_EXCEPTION_PRINT("[TIMESTAMP]Current time(%d), New time(%d)(%s), diff_time(%f)", before.tv_sec, _time, ctime(&_time), diff_time);
- _set_time(_time-1);
- vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
+ ALARM_MGR_LOG_PRINT("[alarm-server] System time has been changed\n");
+ ALARM_MGR_LOG_PRINT("1.alarm_context.c_due_time is %d\n", alarm_context.c_due_time);
+ _set_time(_time - 1);
__alarm_update_due_time_of_all_items_in_list(diff_time);
- ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d\n",
- alarm_context.c_due_time);
+ ALARM_MGR_LOG_PRINT("2.alarm_context.c_due_time is %d", alarm_context.c_due_time);
_clear_scheduled_alarm_list();
_alarm_schedule();
__rtc_set();
_set_time(_time);
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
- /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_
- APP_ID) in a platform with app-server. because _alarm_power_
- on(..) fuction don't use first parameter internally, we set
- this value to 0(zero)
- */
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
- return result;
+
+ vconf_set_int(VCONFKEY_SYSTEM_TIME_CHANGED,(int)diff_time);
+
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+ return true;
}
-gboolean alarm_manager_alarm_create_appsvc(void *pObject, int pid,
+gboolean alarm_manager_alarm_create_appsvc(AlarmManager *pObject, GDBusMethodInvocation *invoc,
+ int pid,
int start_year,
int start_month, int start_day,
int start_hour, int start_min,
int mode_repeat, int alarm_type,
int reserved_info,
char *bundle_data, char *e_cookie,
- int *alarm_id, int *return_code)
+ gpointer user_data)
{
alarm_info_t alarm_info;
- guchar *cookie = NULL;
- gsize size;
int retval = 0;
- gboolean result = true;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+ int alarm_id = 0;
+ char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+ bool ret = true;
+
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", false, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
+ sprintf(log_message, "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
+ __save_module_log("FAIL: CREATE", log_message);
+ return true;
+ }
alarm_info.start.year = start_year;
alarm_info.start.month = start_month;
alarm_info.end.day = end_day;
alarm_info.mode.u_interval.day_of_week = mode_day_of_week;
- alarm_info.mode.repeat = mode_repeat;
-
- alarm_info.alarm_type = alarm_type;
- alarm_info.reserved_info = reserved_info;
-
- *return_code = 0;
-
- cookie = g_base64_decode(e_cookie, &size);
- if (NULL == cookie)
- {
- *return_code = -1;
- ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
- return false;
- }
-
- retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "w");
- if (retval < 0) {
- if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
- ALARM_MGR_EXCEPTION_PRINT(
- "%s", "Write access has been denied by smack\n");
- }
- ALARM_MGR_EXCEPTION_PRINT("Error has occurred in security_server_check_privilege()\n");
- *return_code = ERR_ALARM_NO_PERMISSION;
- result = false;
- }
- else
- {
- result = __alarm_create_appsvc(&alarm_info, alarm_id, pid,
- bundle_data, return_code);
- if (false == result)
- {
- ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm!\n");
- }
- }
+ alarm_info.mode.repeat = mode_repeat;
- if (cookie){
- g_free(cookie);
- cookie = NULL;
+ alarm_info.alarm_type = alarm_type;
+ alarm_info.reserved_info = reserved_info;
+
+ if (!__alarm_create_appsvc(&alarm_info, &alarm_id, pid, bundle_data, &return_code)) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
+ strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
+ ret = false;
+ } else {
+ strncpy(log_tag, "CREATE", strlen("CREATE"));
+ ret = true;
}
- return result;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
+
+ sprintf(log_message, "alarmID: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
+ alarm_id, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
+ __save_module_log(log_tag, log_message);
+
+ return ret;
}
-gboolean alarm_manager_alarm_create(void *pObject, int pid,
+gboolean alarm_manager_alarm_create(AlarmManager *obj, GDBusMethodInvocation *invoc, int pid,
char *app_service_name, char *app_service_name_mod, int start_year,
int start_month, int start_day,
int start_hour, int start_min,
int mode_repeat, int alarm_type,
int reserved_info,
char *reserved_service_name, char *reserved_service_name_mod, char *e_cookie,
- int *alarm_id, int *return_code)
+ gpointer user_data)
{
alarm_info_t alarm_info;
- guchar *cookie;
- gsize size;
int retval = 0;
- char buf[128];
- FILE *fp = NULL;
- char title[128];
- int uid = -1;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+ int alarm_id = 0;
+ char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+ bool ret = true;
+
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
+ sprintf(log_message, "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
+ __save_module_log("FAIL: CREATE", log_message);
+ return true;
+ }
alarm_info.start.year = start_year;
alarm_info.start.month = start_month;
alarm_info.alarm_type = alarm_type;
alarm_info.reserved_info = reserved_info;
- *return_code = 0;
-
- snprintf(buf, sizeof(buf), "/proc/%d/status", pid);
- fp = fopen(buf,"r");
- if(fp) {
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if(strncmp(buf, "Uid:", 4) == 0) {
- sscanf(buf, "%s %d", title, &uid);
- break;
- }
- }
- fclose(fp);
+ if (!__alarm_create(&alarm_info, &alarm_id, pid, app_service_name,app_service_name_mod,
+ reserved_service_name, reserved_service_name_mod, &return_code)) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code);
+ strncpy(log_tag, "FAIL: CREATE", strlen("FAIL: CREATE"));
+ ret = false;
+ } else {
+ strncpy(log_tag, "CREATE", strlen("CREATE"));
+ ret = true;
}
- ALARM_MGR_LOG_PRINT("uid :%d", uid);
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
- if(uid != 0) {
- cookie = g_base64_decode(e_cookie, &size);
- retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "w");
- }
-
- if (retval < 0) {
- if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
- ALARM_MGR_EXCEPTION_PRINT(
- "Write access has been denied by smack\n");
- }
- ALARM_MGR_EXCEPTION_PRINT("Error has occurred\n");
- *return_code = ERR_ALARM_NO_PERMISSION;
- }
- else
- {
- /* return valule and return_code should be checked */
- __alarm_create(&alarm_info, alarm_id, pid, app_service_name,app_service_name_mod,
- reserved_service_name, reserved_service_name_mod, return_code);
- }
- if(uid != 0)
- g_free(cookie);
+ sprintf(log_message, "alarmID: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
+ alarm_id, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
+ __save_module_log(log_tag, log_message);
- return true;
+ return ret;
}
-gboolean alarm_manager_alarm_delete(void *pObject, int pid, alarm_id_t alarm_id,
- char *e_cookie, int *return_code)
+gboolean alarm_manager_alarm_delete(AlarmManager *obj, GDBusMethodInvocation *invoc,
+ int pid, alarm_id_t alarm_id,
+ char *e_cookie, gpointer user_data)
{
- guchar *cookie;
- gsize size;
int retval = 0;
- char buf[128];
- FILE *fp = NULL;
- char title[128];
- int uid = -1;
-
- snprintf(buf, sizeof(buf), "/proc/%d/status", pid);
- fp = fopen(buf,"r");
- if(fp) {
- while (fgets(buf, sizeof(buf), fp) != NULL) {
- if(strncmp(buf, "Uid:", 4) == 0) {
- sscanf(buf, "%s %d", title, &uid);
- break;
- }
- }
- fclose(fp);
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+ char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+ bool ret = true;
+
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+ sprintf(log_message, "alarmID: %d, pid: %d, Smack denied (alarm-server::alarm, w)", alarm_id, pid);
+ __save_module_log("FAIL: DELETE", log_message);
+ return true;
}
- ALARM_MGR_LOG_PRINT("uid :%d", uid);
-
- if(uid != 0) {
- cookie = g_base64_decode(e_cookie, &size);
- retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "w");
+ if (!__alarm_delete(pid, alarm_id, &return_code)) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to delete the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
+ strncpy(log_tag, "FAIL: DELETE", strlen("FAIL: DELETE"));
+ ret = false;
+ } else {
+ ALARM_MGR_EXCEPTION_PRINT("alarm_id[%d] is removed.", alarm_id);
+ strncpy(log_tag, "DELETE", strlen("DELETE"));
+ ret = true;
}
- if (retval < 0) {
- if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
- ALARM_MGR_EXCEPTION_PRINT(
- "Write access has been denied by smack\n");
- }
- ALARM_MGR_EXCEPTION_PRINT("Error has occurred\n");
- *return_code = ERR_ALARM_NO_PERMISSION;
- }
- else
- {
- __alarm_delete(pid, alarm_id, return_code);
- }
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
- if(uid != 0)
- g_free(cookie);
+ sprintf(log_message, "alarmID: %d, pid: %d", alarm_id, pid);
+ __save_module_log(log_tag, log_message);
- return true;
+ return ret;
}
-gboolean alarm_manager_alarm_delete_all(void *pObject, int pid, int* return_code)
+gboolean alarm_manager_alarm_delete_all(AlarmManager *obj, GDBusMethodInvocation *invoc,
+ int pid, char *e_cookie, gpointer user_data)
{
GSList* gs_iter = NULL;
- GQuark quark_app_unique_name; // the fullpath of pid(pid) is converted to quark value.
- char proc_file[256] = { 0 };
- char process_name[512] = { 0 };
- char app_name[256] = { 0 };
- char* word = NULL;
+ char app_name[512] = { 0 };
alarm_info_t* alarm_info = NULL;
__alarm_info_t* entry = NULL;
- char* proc_name_ptr = NULL;
- int fd;
- int ret;
- int i = 0;
- bool isDeleted = false;
- *return_code = ALARMMGR_RESULT_SUCCESS;
-
- // we should consider to check whether pid is running or Not
- memset(process_name, '\0', 512);
- memset(proc_file, '\0', 256);
- snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
-
- fd = open(proc_file, O_RDONLY);
- if (fd < 0)
- {
- quark_app_unique_name = g_quark_from_string("unknown");
- memcpy(app_name, "unknown", strlen("unknown") + 1);
-
- SECURE_LOGE("Caution!! app_pid(%d) seems to be killed. so we failed to get proc file(%s)\n", pid, proc_file);
- *return_code = ERR_ALARM_SYSTEM_FAIL;
+ bool is_deleted = false;
+ int retval = 0;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "w", true, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+ sprintf(log_message, "pid: %d, Smack denied (alarm-server::alarm, w)", pid);
+ __save_module_log("FAIL: DELETE ALL", log_message);
return true;
}
- else
- {
- ret = read(fd, process_name, 512);
- if (ret < 0)
- {
- *return_code = ERR_ALARM_SYSTEM_FAIL;
- close(fd);
- return true;
- }
- close(fd);
- while (process_name[i] != '\0')
- {
- if (process_name[i] == ' ')
- {
- process_name[i] = '\0';
- break;
- }
- i++;
- }
- word = strtok_r(process_name, "/", &proc_name_ptr);
- while (word != NULL)
- {
- memset(app_name, 0, 256);
- snprintf(app_name, 256, "%s", word);
- word = strtok_r(NULL, "/", &proc_name_ptr);
- }
- quark_app_unique_name = g_quark_from_string(app_name);
+ if (!__get_caller_unique_name(pid, app_name)) {
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
+ sprintf(log_message, "pid: %d. Can not get the unique_name.", pid);
+ __save_module_log("FAIL: DELETE ALL", log_message);
+ return true;
}
- SECURE_LOGD("called for app(pid:%d, name=%s)\n", pid, app_name);
+ SECURE_LOGD("Called by process (pid:%d, unique_name=%s)", pid, app_name);
for (gs_iter = alarm_context.alarms; gs_iter != NULL; )
{
- bool isFound = false;
+ bool is_found = false;
entry = gs_iter->data;
- SECURE_LOGD("Try to remove app_name[%s], alarm_id[%d]\n", g_quark_to_string(entry->quark_app_unique_name), entry->alarm_id);
- if (strcmp(app_name, g_quark_to_string(entry->quark_app_unique_name)) == 0
- && strcmp(app_name, "unknown") != 0)
+ char* tmp_appname = g_quark_to_string(entry->quark_app_unique_name);
+ SECURE_LOGD("Try to remove app_name[%s], alarm_id[%d]\n", tmp_appname, entry->alarm_id);
+ if (tmp_appname && strncmp(app_name, tmp_appname, strlen(tmp_appname)) == 0)
{
if (_remove_from_scheduled_alarm_list(pid, entry->alarm_id))
{
- isDeleted = true;
+ is_deleted = true;
}
alarm_info = &entry->alarm_info;
SECURE_LOGE("_delete_alarms() is failed. pid[%d], alarm_id[%d]", pid, entry->alarm_id);
}
}
- SECURE_LOGD("Removing is done. app_name[%s], alarm_id [%d]\n", g_quark_to_string(entry->quark_app_unique_name), entry->alarm_id);
- isFound = true;
+ is_found = true;
}
gs_iter = g_slist_next(gs_iter);
- if (isFound)
+ if (is_found)
{
+ ALARM_MGR_EXCEPTION_PRINT("alarm_id[%d] is removed.", entry->alarm_id);
+ SECURE_LOGD("Removing is done. app_name[%s], alarm_id [%d]\n", tmp_appname, entry->alarm_id);
alarm_context.alarms = g_slist_remove(alarm_context.alarms, entry);
+ g_free(entry);
}
}
- if (isDeleted && (g_slist_length(g_scheduled_alarm_list) == 0))
+ if (is_deleted && (g_slist_length(g_scheduled_alarm_list) == 0))
{
_alarm_disable_timer(alarm_context);
_alarm_schedule();
}
__rtc_set();
-
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
return true;
}
-gboolean alarm_manager_alarm_power_on(void *pObject, int pid, bool on_off,
- int *return_code)
-{
-
- return __alarm_power_on(pid, on_off, return_code);
-}
-
-gboolean alarm_manager_alarm_power_off(void *pObject, int pid, int *return_code)
-{
-
- return __alarm_power_off(pid, return_code);
-}
-
-bool alarm_manager_alarm_check_next_duetime(void *pObject, int pid,
- int *return_code)
-{
- return __alarm_check_next_duetime(pid, return_code);
-}
-
-gboolean alarm_manager_alarm_update(void *pObject, int pid,
+gboolean alarm_manager_alarm_update(AlarmManager *pObj, GDBusMethodInvocation *invoc, int pid,
char *app_service_name, alarm_id_t alarm_id,
int start_year, int start_month,
int start_day, int start_hour,
int end_month, int end_day,
int mode_day_of_week, int mode_repeat,
int alarm_type, int reserved_info,
- int *return_code)
+ gpointer user_data)
{
+ int return_code = ALARMMGR_RESULT_SUCCESS;
alarm_info_t alarm_info;
+ bool ret = true;
+ char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,};
+ char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,};
+
alarm_info.start.year = start_year;
alarm_info.start.month = start_month;
alarm_info.start.day = start_day;
alarm_info.alarm_type = alarm_type;
alarm_info.reserved_info = reserved_info;
- *return_code = 0;
+ if (!__alarm_update(pid, app_service_name, alarm_id, &alarm_info, &return_code)) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to update the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code);
+ strncpy(log_tag, "FAIL: UPDATE", strlen("FAIL: UPDATE"));
+ ret = false;
+ } else {
+ strncpy(log_tag, "UPDATE", strlen("UPDATE"));
+ ret = true;
+ }
- __alarm_update(pid, app_service_name, alarm_id, &alarm_info,
- return_code);
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
- return true;
+ sprintf(log_message, "alarmID: %d, appname: %s, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d",
+ alarm_id, app_service_name, pid, start_year, start_month, start_day, start_hour, start_min, start_sec);
+ __save_module_log(log_tag, log_message);
+
+ return ret;
}
-gboolean alarm_manager_alarm_get_number_of_ids(void *pObject, int pid,
- int *num_of_ids,
- int *return_code)
+gboolean alarm_manager_alarm_get_number_of_ids(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid, char *e_cookie,
+ gpointer user_data)
{
GSList *gs_iter = NULL;
- GQuark quark_app_unique_name; /* the fullpath of pid(pid) is
- converted to quark value. */
- char proc_file[256] = { 0 };
- char process_name[512] = { 0 };
char app_name[256] = { 0 };
- char *word = NULL;
__alarm_info_t *entry = NULL;
- char *proc_name_ptr = NULL;
-
- *num_of_ids = 0;
- *return_code = 0;
+ int retval = 0;
+ int num_of_ids = 0;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
- /* we should consider to check whether pid is running or Not
- */
- memset(process_name, '\0', 512);
- memset(proc_file, '\0', 256);
- snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
+ return true;
+ }
- int fd;
- int ret;
- int i = 0;
- fd = open(proc_file, O_RDONLY);
- if (fd < 0) { /* failure */
- quark_app_unique_name = g_quark_from_string("unknown");
- memcpy(app_name, "unknown", strlen("unknown") + 1);
-
- SECURE_LOGE("Caution!! app_pid(%d) seems to be "
- "killed, so we failed to get proc file(%s) \n",
- pid, proc_file);
- *return_code = -1; /* -1 means that system
- failed internally. */
+ if (!__get_caller_unique_name(pid, app_name)) {
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
return true;
- } else {
- ret = read(fd, process_name, 512);
- if (ret <0 ) {
- *return_code = -1; /* -1 means that system
- failed internally. */
- close(fd);
- return false;
- }
- close(fd);
- while (process_name[i] != '\0') {
- if (process_name[i] == ' ') {
- process_name[i] = '\0';
- break;
- }
- i++;
- }
- /*if (readlink(proc_file, process_name, 256)!=-1) */
- /*success */
-
- word = strtok_r(process_name, "/", &proc_name_ptr);
- while (word != NULL) {
- memset(app_name, 0, 256);
- snprintf(app_name, 256, "%s", word);
- word = strtok_r(NULL, "/", &proc_name_ptr);
- }
- quark_app_unique_name = g_quark_from_string(app_name);
}
- SECURE_LOGD("called for app(pid:%d, name=%s)\n",
- pid, app_name);
+ SECURE_LOGD("Called by process (pid:%d, unique_name:%s)", pid, app_name);
- for (gs_iter = alarm_context.alarms; gs_iter != NULL;
- gs_iter = g_slist_next(gs_iter)) {
+ for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
entry = gs_iter->data;
- SECURE_LOGD("alarm_manager_alarm_get_number_of_ids(): "
- "app_name=%s,quark_app_unique_name=%s\n",
- app_name, g_quark_to_string(entry->quark_app_unique_name));
- if (strcmp
- (app_name,
- g_quark_to_string(entry->quark_app_unique_name)) == 0
- && strcmp(app_name, "unknown") != 0) {
- (*num_of_ids)++;
- SECURE_LOGD("inc number of alarms of app "
- "(pid:%d, name:%s) is %d\n",
- pid, app_name, *num_of_ids);
+ SECURE_LOGD("app_name=%s, quark_app_unique_name=%s", app_name, g_quark_to_string(entry->quark_app_unique_name));
+ if (strncmp(app_name, g_quark_to_string(entry->quark_app_unique_name), strlen(app_name)) == 0) {
+ (num_of_ids)++;
+ SECURE_LOGD("inc number of alarms of app (pid:%d, unique_name:%s) is %d.", pid, app_name, num_of_ids);
}
}
- *return_code = 0;
- SECURE_LOGD("number of alarms of app(pid:%d, name:%s) is %d\n",
- pid, app_name, *num_of_ids);
+
+ SECURE_LOGD("number of alarms of the process (pid:%d, unique_name:%s) is %d.", pid, app_name, num_of_ids);
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
return true;
}
-gboolean alarm_manager_alarm_get_list_of_ids(void *pObject, int pid,
- int max_number_of_ids,
- GArray **arr, int *num_of_ids,
- int *return_code)
+gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
+ int max_number_of_ids, gpointer user_data)
{
GSList *gs_iter = NULL;
- GQuark quark_app_unique_name; /* the fullpath of pid(pid) is converted
- to quark value. */
- char proc_file[256] = { 0 };
- char process_name[512] = { 0 };
- char app_name[256] = { 0 };
- char *word = NULL;
+ char app_name[512] = { 0 };
__alarm_info_t *entry = NULL;
int index = 0;
- char *proc_name_ptr = NULL;
- int fd;
- int ret;
- int i = 0;
- GArray *garray = NULL;
-
- *return_code = 0;
+ GVariant* arr = NULL;
+ GVariantBuilder* builder = NULL;
+ int num_of_ids = 0;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
- garray = g_array_new(false, true, sizeof(alarm_id_t));
-
- /* we should check that there is a resource leak.
- * Now we don't have free code for g_array_new().
- */
if (max_number_of_ids <= 0) {
- *arr = garray;
- SECURE_LOGE("called for pid(%d), but "
- "max_number_of_ids(%d) is less than 0.\n",
- pid, max_number_of_ids);
+ SECURE_LOGE("called for pid(%d), but max_number_of_ids(%d) is less than 0.", pid, max_number_of_ids);
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", g_variant_new("ai", NULL), num_of_ids, return_code));
return true;
}
- /* we should consider to check whether pid is running or Not
- */
- memset(process_name, '\0', 512);
- memset(proc_file, '\0', 256);
- snprintf(proc_file, 256, "/proc/%d/cmdline", pid);
-
- fd = open(proc_file, O_RDONLY);
- if (fd < 0) { /* failure */
- quark_app_unique_name = g_quark_from_string("unknown");
- memcpy(app_name, "unknown", strlen("unknown") + 1);
-
- SECURE_LOGE("Caution!! app_pid(%d) seems to be "
- "killed, so we failed to get proc file(%s)\n", pid, proc_file);
- *return_code = -1;
- /* -1 means that system failed internally. */
+ if (!__get_caller_unique_name(pid, app_name)) {
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", g_variant_new("ai", NULL), num_of_ids, return_code));
return true;
- } else {
- ret = read(fd, process_name, 512);
- if (ret <0 ) {
- *return_code = -1;
- /* -1 means that system failed internally. */
- close(fd);
- return true;
- }
- close(fd);
- while (process_name[i] != '\0') {
- if (process_name[i] == ' ') {
- process_name[i] = '\0';
- break;
- }
- i++;
- }
- /* if (readlink(proc_file, process_name, 256)!=-1) */
- /*success */
-
- word = strtok_r(process_name, "/", &proc_name_ptr);
- while (word != NULL) {
- memset(app_name, 0, 256);
- snprintf(app_name, 256, "%s", word);
- word = strtok_r(NULL, "/", &proc_name_ptr);
- }
- quark_app_unique_name = g_quark_from_string(app_name);
}
- SECURE_LOGD("called for app(pid:%d, name=%s)\n",
- pid, app_name);
+ SECURE_LOGD("Called by process (pid:%d, unique_name=%s).", pid, app_name);
- for (gs_iter = alarm_context.alarms; gs_iter != NULL;
- gs_iter = g_slist_next(gs_iter)) {
+ builder = g_variant_builder_new(G_VARIANT_TYPE ("ai"));
+ for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
entry = gs_iter->data;
- if (strcmp
- (app_name,
- g_quark_to_string(entry->quark_app_unique_name)) == 0
- && strcmp(app_name, "unknown") != 0) {
- g_array_append_val(garray, entry->alarm_id);
+ if (strncmp(app_name, g_quark_to_string(entry->quark_app_unique_name), strlen(app_name)) == 0) {
+ g_variant_builder_add (builder, "i", entry->alarm_id);
+ index ++;
+ SECURE_LOGE("called for alarmid(%d), but max_number_of_ids(%d) index %d.", entry->alarm_id, max_number_of_ids, index);
}
}
- *num_of_ids = index;
+ arr = g_variant_new("ai", builder);
+ num_of_ids = index;
- *arr = garray;
+ SECURE_LOGE("Called by pid (%d), but max_number_of_ids(%d) return code %d.", pid, num_of_ids, return_code);
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", arr, num_of_ids, return_code));
+ g_variant_builder_unref(builder);
return true;
}
-gboolean alarm_manager_alarm_get_appsvc_info(void *pObject, int pid, alarm_id_t alarm_id,
- char *e_cookie, gchar **b_data, int *return_code)
+gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodInvocation *invoc ,
+ int pid, alarm_id_t alarm_id,
+ char *e_cookie, gpointer user_data)
{
bool found = false;
-
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
-
- guchar *cookie = NULL;
- gsize size;
int retval = 0;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+ gchar *b_data = NULL;
- SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
-
- cookie = g_base64_decode(e_cookie, &size);
- if (NULL == cookie)
- {
- if (return_code)
- *return_code = ERR_ALARM_SYSTEM_FAIL;
- ALARM_MGR_EXCEPTION_PRINT("Unable to decode cookie!!!\n");
- return true;
- }
-
- retval = security_server_check_privilege_by_cookie((const char *)cookie, "alarm-server::alarm", "r");
- if (retval < 0) {
- if (retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED) {
- ALARM_MGR_EXCEPTION_PRINT("Read access has been denied by smack\n");
- }
- ALARM_MGR_EXCEPTION_PRINT("Error has occurred\n");
-
- if (return_code)
- *return_code = ERR_ALARM_NO_PERMISSION;
-
- if (cookie)
- g_free(cookie);
+ SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", false, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code));
return true;
}
- if (return_code)
- *return_code = 0;
-
- for (gs_iter = alarm_context.alarms; gs_iter != NULL;
- gs_iter = g_slist_next(gs_iter)) {
+ for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
entry = gs_iter->data;
if (entry->alarm_id == alarm_id) {
found = true;
- *b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
+ b_data = g_strdup(g_quark_to_string(entry->quark_bundle));
break;
}
}
if (found) {
- if ( *b_data && strlen(*b_data) == 4 && strncmp(*b_data,"null",4) == 0){
- ALARM_MGR_EXCEPTION_PRINT("Regular alarm,not svc alarm\n");
- if (return_code)
- *return_code = ERR_ALARM_INVALID_TYPE;
+ if (b_data && strlen(b_data) == 4 && strncmp(b_data, "null", 4) == 0) {
+ ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is an regular alarm, not svc alarm.", alarm_id);
+ return_code = ERR_ALARM_INVALID_TYPE;
}
} else {
- if (return_code)
- *return_code = ERR_ALARM_INVALID_ID;
+ ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not found.", alarm_id);
+ return_code = ERR_ALARM_INVALID_ID;
}
- if (cookie)
- g_free(cookie);
-
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code));
+ g_free(b_data);
return true;
}
-gboolean alarm_manager_alarm_get_info(void *pObject, int pid,
- alarm_id_t alarm_id, int *start_year,
- int *start_month, int *start_day,
- int *start_hour, int *start_min,
- int *start_sec, int *end_year,
- int *end_month, int *end_day,
- int *mode_day_of_week, int *mode_repeat,
- int *alarm_type, int *reserved_info,
- int *return_code)
+gboolean alarm_manager_alarm_get_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
+ alarm_id_t alarm_id, char *e_cookie, gpointer user_data)
{
SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
-
alarm_info_t *alarm_info = NULL;
- *return_code = 0;
+ int retval = 0;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(iiiiiiiiiiiiii)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, return_code));
+ return true;
+ }
- for (gs_iter = alarm_context.alarms; gs_iter != NULL;
- gs_iter = g_slist_next(gs_iter)) {
+ for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
entry = gs_iter->data;
if (entry->alarm_id == alarm_id) {
alarm_info = &(entry->alarm_info);
}
}
- if (alarm_info == NULL)
- {
- ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n", alarm_id);
- *return_code = ERR_ALARM_INVALID_ID;
+ if (alarm_info == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not found.", alarm_id);
+ return_code = ERR_ALARM_INVALID_ID;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(iiiiiiiiiiiiii)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, return_code));
} else {
- ALARM_MGR_LOG_PRINT("alarm was found\n");
- *start_year = alarm_info->start.year;
- *start_month = alarm_info->start.month;
- *start_day = alarm_info->start.day;
- *start_hour = alarm_info->start.hour;
- *start_min = alarm_info->start.min;
- *start_sec = alarm_info->start.sec;
-
- *end_year = alarm_info->end.year;
- *end_year = alarm_info->end.month;
- *end_year = alarm_info->end.day;
-
- *mode_day_of_week = alarm_info->mode.u_interval.day_of_week;
- *mode_repeat = alarm_info->mode.repeat;
-
- *alarm_type = alarm_info->alarm_type;
- *reserved_info = alarm_info->reserved_info;
-
- *return_code = 0;
+ ALARM_MGR_LOG_PRINT("The alarm(%d) is found.", alarm_id);
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(iiiiiiiiiiiiii)", alarm_info->start.year, alarm_info->start.month,
+ alarm_info->start.day, alarm_info->start.hour, alarm_info->start.min, alarm_info->start.sec, alarm_info->end.year, alarm_info->end.month,
+ alarm_info->end.day, alarm_info->mode.u_interval.day_of_week, alarm_info->mode.repeat, alarm_info->alarm_type, alarm_info->reserved_info, return_code));
}
+
return true;
}
-gboolean alarm_manager_alarm_get_next_duetime(void *pObject, int pid,
- alarm_id_t alarm_id, time_t* duetime,
- int *return_code)
+gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid,
+ alarm_id_t alarm_id, char *e_cookie, gpointer user_data)
{
SECURE_LOGD("called for pid(%d) and alarm_id(%d)\n", pid, alarm_id);
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
__alarm_info_t *find_item = NULL;
+ int retval = 0;
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+ time_t duetime = 0;
- *return_code = 0;
+ retval = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
+ if (retval != ALARMMGR_RESULT_SUCCESS) {
+ return_code = retval;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, return_code));
+ return true;
+ }
- for (gs_iter = alarm_context.alarms; gs_iter != NULL;
- gs_iter = g_slist_next(gs_iter)) {
+ for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
entry = gs_iter->data;
if (entry->alarm_id == alarm_id) {
find_item = entry;
}
}
- if (find_item == NULL)
- {
- ALARM_MGR_EXCEPTION_PRINT("alarm id(%d) was not found\n", alarm_id);
- *return_code = ERR_ALARM_INVALID_ID;
- } else {
- ALARM_MGR_LOG_PRINT("alarm was found\n");
- *duetime = _alarm_next_duetime(find_item);
- *return_code = 0;
+ if (find_item == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is not found.", alarm_id);
+ return_code = ERR_ALARM_INVALID_ID;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, return_code));
+ return true;
}
+
+ duetime = _alarm_next_duetime(find_item);
+ ALARM_MGR_LOG_PRINT("Next duetime : %s", ctime(&duetime));
+
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, return_code));
return true;
}
-#include "alarm-skeleton.h"
+gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, int pid, char *e_cookie, gpointer user_data)
+{
+ sqlite3 *alarmmgr_tool_db;
+ char *db_path = NULL;
+ char db_path_tmp[50] = {0,};
+ time_t current_time = 0;
+ struct tm current_tm;
+ const char *query_for_creating_table = "create table alarmmgr_tool \
+ (alarm_id integer primary key,\
+ duetime_epoch integer,\
+ duetime text,\
+ start_epoch integer,\
+ end_epoch integer,\
+ pid integer,\
+ caller_pkgid text,\
+ callee_pkgid text,\
+ app_unique_name text,\
+ app_service_name text,\
+ dst_service_name text,\
+ day_of_week integer,\
+ repeat integer,\
+ alarm_type integer)";
+ const char *query_for_deleting_table = "drop table alarmmgr_tool";
+ int return_code = ALARMMGR_RESULT_SUCCESS;
+ GSList *gs_iter = NULL;
+ __alarm_info_t *entry = NULL;
+ char *error_message = NULL;
+
+ return_code = __check_privilege_by_cookie(e_cookie, "alarm-server::alarm", "r", true, pid);
+ if (return_code != ALARMMGR_RESULT_SUCCESS) {
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
+ return true;
+ }
-typedef struct AlarmManagerObject AlarmManagerObject;
-typedef struct AlarmManagerObjectClass AlarmManagerObjectClass;
-GType Server_Object_get_type(void);
-struct AlarmManagerObject {
- GObject parent;
-};
-struct AlarmManagerObjectClass {
- GObjectClass parent;
-};
+ // Open a DB
+ time(¤t_time);
+ localtime_r(¤t_time, ¤t_tm);
+ sprintf(db_path_tmp, "/tmp/alarmmgr_%d%d%d_%02d%02d%02d.db",
+ current_tm.tm_year + 1900, current_tm.tm_mon + 1, current_tm.tm_mday, current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
+ db_path = strdup(db_path_tmp);
+
+ if (db_util_open(db_path, &alarmmgr_tool_db, DB_UTIL_REGISTER_HOOK_METHOD) != SQLITE_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Opening [%s] failed", db_path);
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
+ free(db_path);
+ return true;
+ }
-#define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
-
-#define ALARM_MANAGER_TYPE_OBJECT (Server_Object_get_type())
-#define ALARM_MANAGER_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST \
-((object), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObject))
-#define ALARM_MANAGER_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
-((klass), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
-#define ALARM_MANAGER_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE \
-((object), ALARM_MANAGER_TYPE_OBJECT))
-#define ALARM_MANAGER_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE \
-((klass), ALARM_MANAGER_TYPE_OBJECT))
-#define ALARM_MANAGER_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
-((obj), ALARM_MANAGER_TYPE_OBJECT, AlarmManagerObjectClass))
-G_DEFINE_TYPE(AlarmManagerObject, Server_Object, G_TYPE_OBJECT)
-static void Server_Object_init(AlarmManagerObject * obj)
+ // Drop a table
+ if (sqlite3_exec(alarmmgr_tool_db, query_for_deleting_table, NULL, NULL, &error_message) != SQLITE_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Deleting the table is failed. error message = %s", error_message);
+ }
+
+ // Create a table if it does not exist
+ if (sqlite3_exec(alarmmgr_tool_db, query_for_creating_table, NULL, NULL, &error_message) != SQLITE_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Creating the table is failed. error message = %s", error_message);
+ sqlite3_close(alarmmgr_tool_db);
+ return_code = ERR_ALARM_SYSTEM_FAIL;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
+ free(db_path);
+ return true;
+ }
+
+ // Get information of all alarms and save those into the DB.
+ int index = 0;
+ for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) {
+ entry = gs_iter->data;
+ ++index;
+ SECURE_LOGD("#%d alarm id[%d] app_name[%s] duetime[%d]",
+ index, entry->alarm_id, g_quark_to_string(entry->quark_app_unique_name), entry->start);
+
+ alarm_info_t *alarm_info = (alarm_info_t *) &(entry->alarm_info);
+ alarm_mode_t *mode = &alarm_info->mode;
+
+ char *query = sqlite3_mprintf("insert into alarmmgr_tool( alarm_id, duetime_epoch, duetime, start_epoch,\
+ end_epoch, pid, caller_pkgid, callee_pkgid, app_unique_name, app_service_name, dst_service_name, day_of_week, repeat, alarm_type)\
+ values (%d,%d,%Q,%d,%d,%d,%Q,%Q,%Q,%Q,%Q,%d,%d,%d)",
+ entry->alarm_id,
+ (int)entry->due_time,
+ ctime(&(entry->due_time)),
+ (int)entry->start,
+ (int)entry->end,
+ (int)entry->pid,
+ (char *)g_quark_to_string(entry->quark_caller_pkgid),
+ (char *)g_quark_to_string(entry->quark_callee_pkgid),
+ (char *)g_quark_to_string(entry->quark_app_unique_name),
+ (char *)g_quark_to_string(entry->quark_app_service_name),
+ (char *)g_quark_to_string(entry->quark_dst_service_name),
+ mode->u_interval.day_of_week,
+ mode->repeat,
+ entry->alarm_info.alarm_type);
+
+ if (sqlite3_exec(alarmmgr_tool_db, query, NULL, NULL, &error_message) != SQLITE_OK) {
+ SECURE_LOGE("sqlite3_exec() is failed. error message = %s", error_message);
+ }
+
+ sqlite3_free(query);
+ }
+
+ sqlite3_close(alarmmgr_tool_db);
+
+ return_code = ALARMMGR_RESULT_SUCCESS;
+ g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code));
+ free(db_path);
+ return true;
+}
+
+static void __timer_glib_finalize(GSource *src)
+{
+ GSList *fd_list;
+ GPollFD *tmp;
+
+ fd_list = src->poll_fds;
+ do {
+ tmp = (GPollFD *) fd_list->data;
+ g_free(tmp);
+
+ fd_list = fd_list->next;
+ } while (fd_list);
+
+ return;
+}
+
+static gboolean __timer_glib_check(GSource *src)
+{
+ GSList *fd_list;
+ GPollFD *tmp;
+
+ fd_list = src->poll_fds;
+ do {
+ tmp = (GPollFD *) fd_list->data;
+ if (tmp->revents & (POLLIN | POLLPRI)) {
+ return TRUE;
+ }
+ fd_list = fd_list->next;
+ } while (fd_list);
+
+ return FALSE;
+}
+
+static gboolean __timer_glib_dispatch(GSource *src, GSourceFunc callback,
+ gpointer data)
{
- ;
+ callback(data);
+ return TRUE;
}
-static void Server_Object_class_init(AlarmManagerObjectClass *klass)
+static gboolean __timer_glib_prepare(GSource *src, gint *timeout)
{
- ;
+ return FALSE;
}
+GSourceFuncs funcs = {
+ .prepare = __timer_glib_prepare,
+ .check = __timer_glib_check,
+ .dispatch = __timer_glib_dispatch,
+ .finalize = __timer_glib_finalize
+};
+
static void __initialize_timer()
{
- struct sigaction sig_timer;
- sigemptyset(&sig_timer.sa_mask);
- sig_timer.sa_flags = SA_SIGINFO;
- sig_timer.sa_sigaction = (void *)__alarm_handler;
- sigaction(SIG_TIMER, &sig_timer, NULL);
+ int fd;
+ GSource *src;
+ GPollFD *gpollfd;
+ int ret;
+
+ fd = timerfd_create(CLOCK_REALTIME, 0);
+ if (fd == -1) {
+ ALARM_MGR_EXCEPTION_PRINT("timerfd_create() is failed.\n");
+ exit(1);
+ }
+ src = g_source_new(&funcs, sizeof(GSource));
+
+ gpollfd = (GPollFD *) g_malloc(sizeof(GPollFD));
+ gpollfd->events = POLLIN;
+ gpollfd->fd = fd;
- alarm_context.timer = _alarm_create_timer();
+ g_source_add_poll(src, gpollfd);
+ g_source_set_callback(src, (GSourceFunc) __alarm_handler_idle,
+ (gpointer) gpollfd, NULL);
+ g_source_set_priority(src, G_PRIORITY_HIGH);
+ ret = g_source_attach(src, NULL);
+ if (ret == 0) {
+ ALARM_MGR_EXCEPTION_PRINT("g_source_attach() is failed.\n");
+ return;
+ }
+
+ g_source_unref(src);
+
+ alarm_context.timer = fd;
}
static void __initialize_alarm_list()
{
-
alarm_context.alarms = NULL;
alarm_context.c_due_time = -1;
_load_alarms_from_registry();
__rtc_set(); /*Set RTC1 Alarm with alarm due time for alarm-manager initialization*/
-
- /*alarm boot */
-#ifdef __ALARM_BOOT
- /*alarm boot */
- if (enable_power_on_alarm) {
- /* orginally first arg's value was 21(app_id, WAKEUP_ALARM_APP_ID) in a
- * platform with app-server. because __alarm_power_on(..) fuction don't
- * use first parameter internally, we set this value to 0(zero)
- */
- __alarm_power_on(0, enable_power_on_alarm, NULL);
- }
-#endif
}
static void __initialize_scheduled_alarm_list()
_init_scheduled_alarm_list();
}
-
-static void __hibernation_leave_callback()
-{
-
- __initialize_scheduled_alarm_list();
-
- __alarm_clean_list();
-
- __initialize_alarm_list();
-}
-
static bool __initialize_noti()
{
- /*system state change noti ó\B8\AE */
-
+ // system state change noti
if (vconf_notify_key_changed
(VCONFKEY_SETAPPL_TIMEZONE_ID, __on_time_zone_changed, NULL) < 0) {
ALARM_MGR_LOG_PRINT(
return true;
}
-
-static DBusHandlerResult __alarm_server_filter(DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+void on_bus_name_owner_changed(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
-
- if (dbus_message_is_signal
- (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
- char *service;
- char *old_owner;
- char *new_owner;
- GSList *entry;
- __expired_alarm_t *expire_info;
-
- dbus_message_get_args(message,
- NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &old_owner,
- DBUS_TYPE_STRING, &new_owner,
- DBUS_TYPE_INVALID);
+ // On expiry, the killed app can be launched by aul. Then, the owner of the bus name which was registered by the app is changed.
+ // In this case, "NameOwnerChange" signal is broadcasted.
+ if (signal_name && strcmp(signal_name , "NameOwnerChanged") == 0) {
+ GSList *entry = NULL;
+ __expired_alarm_t *expire_info = NULL;
+ char *service_name = NULL;
+ g_variant_get(parameters, "(sss)", &service_name, NULL, NULL);
for (entry = g_expired_alarm_list; entry; entry = entry->next) {
if (entry->data) {
expire_info = (__expired_alarm_t *) entry->data;
+ SECURE_LOGD("expired service(%s), owner changed service(%s)", expire_info->service_name, service_name);
- SECURE_LOGD("service_name(%s), service(%s)", expire_info->service_name, service);
-
- if (strcmp(expire_info->service_name, service)
- == 0) {
- SECURE_LOGE(
- "__alarm_server_filter : "
- "service name(%s) alarm_id (%d)\n",
- expire_info->service_name,\
- expire_info->alarm_id);
-
- __alarm_send_noti_to_application(
- expire_info->service_name,
- expire_info->alarm_id);
- g_expired_alarm_list =
- g_slist_remove(g_expired_alarm_list,
- entry->data);
- free(expire_info);
+ if (strcmp(expire_info->service_name, service_name) == 0) {
+ SECURE_LOGE("expired service name(%s) alarm_id (%d)", expire_info->service_name, expire_info->alarm_id);
+ __alarm_send_noti_to_application(expire_info->service_name, expire_info->alarm_id);
+ g_expired_alarm_list = g_slist_remove(g_expired_alarm_list, entry->data);
+ g_free(expire_info);
}
}
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ g_free(service_name);
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static bool __initialize_dbus()
+static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
{
- GError *error = NULL;
- GObject *obj = NULL;
- DBusGConnection *connection = NULL;
- DBusError derror;
-
- dbus_g_object_type_install_info(ALARM_MANAGER_TYPE_OBJECT,
- &dbus_glib_alarm_manager_object_info);
+ ALARM_MGR_EXCEPTION_PRINT("on_bus_acquired");
- connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (!connection) {
-
- ALARM_MGR_EXCEPTION_PRINT("dbus_g_bus_get failed\n");
- return false;
+ interface = alarm_manager_skeleton_new();
+ if (interface == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("Creating a skeleton object is failed.");
+ return;
}
- dbus_error_init(&derror);
-
- dbus_bus_request_name(dbus_g_connection_get_connection(connection),
- "com.samsung.alarm.manager",
- DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &derror);
- if (dbus_error_is_set(&derror)) { /* failure */
- SECURE_LOGE("Failed to dbus_bus_request_name "
- "(com.samsung.alarm.manager): %s\n", derror.message);
- dbus_error_free(&derror);
- return false;
+ g_signal_connect(interface, "handle_alarm_create", G_CALLBACK(alarm_manager_alarm_create), NULL);
+ g_signal_connect(interface, "handle_alarm_create_appsvc", G_CALLBACK(alarm_manager_alarm_create_appsvc), NULL);
+ g_signal_connect(interface, "handle_alarm_delete", G_CALLBACK(alarm_manager_alarm_delete), NULL);
+ g_signal_connect(interface, "handle_alarm_delete_all", G_CALLBACK(alarm_manager_alarm_delete_all), NULL);
+ g_signal_connect(interface, "handle_alarm_get_appsvc_info", G_CALLBACK(alarm_manager_alarm_get_appsvc_info), NULL);
+ g_signal_connect(interface, "handle_alarm_get_info", G_CALLBACK(alarm_manager_alarm_get_info), NULL);
+ g_signal_connect(interface, "handle_alarm_get_list_of_ids", G_CALLBACK(alarm_manager_alarm_get_list_of_ids), NULL);
+ g_signal_connect(interface, "handle_alarm_get_next_duetime", G_CALLBACK(alarm_manager_alarm_get_next_duetime), NULL);
+ g_signal_connect(interface, "handle_alarm_get_number_of_ids", G_CALLBACK(alarm_manager_alarm_get_number_of_ids), NULL);
+ g_signal_connect(interface, "handle_alarm_set_rtc_time", G_CALLBACK(alarm_manager_alarm_set_rtc_time), NULL);
+ g_signal_connect(interface, "handle_alarm_set_time", G_CALLBACK(alarm_manager_alarm_set_time), NULL);
+ g_signal_connect(interface, "handle_alarm_update", G_CALLBACK(alarm_manager_alarm_update), NULL);
+ g_signal_connect(interface, "handle_alarm_get_all_info", G_CALLBACK(alarm_manager_alarm_get_all_info), NULL);
+
+ guint subsc_id = g_dbus_connection_signal_subscribe(connection, "org.freedesktop.DBus", "org.freedesktop.DBus",
+ "NameOwnerChanged", "/org/freedesktop/DBus", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+ on_bus_name_owner_changed, NULL, NULL);
+ if (subsc_id == 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Subscribing to signal for invoking callback is failed.");
+ g_object_unref(interface);
+ interface = NULL;
+ return;
}
- if (!(obj = g_object_new(ALARM_MANAGER_TYPE_OBJECT, NULL))) {
- ALARM_MGR_EXCEPTION_PRINT("Could not allocate new object\n");
- return false;
+ if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(interface), connection, ALARM_MGR_DBUS_PATH, NULL)) {
+ ALARM_MGR_EXCEPTION_PRINT("Exporting the interface is failed.");
+ g_object_unref(interface);
+ interface = NULL;
+ return;
}
- dbus_g_connection_register_g_object(connection,
- "/com/samsung/alarm/manager",
- G_OBJECT(obj));
+ alarm_context.connection = connection;
+ g_dbus_object_manager_server_set_connection(alarmmgr_server, alarm_context.connection);
+}
- /*dbus_bus_add_match (dbus_g_connection_get_connection(connection),
- "type='signal',member='NameOwnerChanged'",NULL); */
+static bool __initialize_dbus()
+{
+ ALARM_MGR_LOG_PRINT("__initialize_dbus Enter");
- dbus_bus_add_match(dbus_g_connection_get_connection(connection),
- "type='signal',sender='" DBUS_SERVICE_DBUS
- "',path='" DBUS_PATH_DBUS
- "',interface='" DBUS_INTERFACE_DBUS
- "',member='NameOwnerChanged'", NULL);
+ alarmmgr_server = g_dbus_object_manager_server_new(ALARM_MGR_DBUS_PATH);
+ if (alarmmgr_server == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("Creating a new server object is failed.");
+ return false;
+ }
- if (!dbus_connection_add_filter
- (dbus_g_connection_get_connection(connection),
- __alarm_server_filter, NULL, NULL)) {
- ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
+ guint owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, ALARM_MGR_DBUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, NULL, NULL, NULL, NULL);
+ if (owner_id == 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Acquiring the own name is failed.");
+ g_object_unref(alarmmgr_server);
return false;
}
- alarm_context.bus = connection;
return true;
}
start integer,\
end integer,\
pid integer,\
+ caller_pkgid text,\
+ callee_pkgid text,\
app_unique_name text,\
app_service_name text,\
app_service_name_mod text,\
int ret;
if (access("/opt/dbspace/.alarmmgr.db", F_OK) == 0) {
- ret =
- db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
- DB_UTIL_REGISTER_HOOK_METHOD);
+ ret = db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db, DB_UTIL_REGISTER_HOOK_METHOD);
if (ret != SQLITE_OK) {
- ALARM_MGR_EXCEPTION_PRINT(
- "====>>>> connect menu_db [%s] failed!\n",
- ALARMMGR_DB_FILE);
+ ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", ALARMMGR_DB_FILE);
return false;
}
return true;
}
- ret =
- db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db,
- DB_UTIL_REGISTER_HOOK_METHOD);
+ ret = db_util_open(ALARMMGR_DB_FILE, &alarmmgr_db, DB_UTIL_REGISTER_HOOK_METHOD);
if (ret != SQLITE_OK) {
- ALARM_MGR_EXCEPTION_PRINT(
- "====>>>> connect menu_db [%s] failed!\n",
- ALARMMGR_DB_FILE);
+ ALARM_MGR_EXCEPTION_PRINT("====>>>> connect menu_db [%s] failed", ALARMMGR_DB_FILE);
return false;
}
- if (SQLITE_OK !=
- sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL,\
- &error_message)) {
- ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, "
- "error message = %s\n", QUERY_CREATE_TABLE_ALARMMGR,
- error_message);
+ if (SQLITE_OK != sqlite3_exec(alarmmgr_db, QUERY_CREATE_TABLE_ALARMMGR, NULL, NULL, &error_message)) {
+ ALARM_MGR_EXCEPTION_PRINT("Don't execute query = %s, error message = %s", QUERY_CREATE_TABLE_ALARMMGR, error_message);
return false;
}
static void __initialize()
{
-
g_type_init();
-#ifdef __ALARM_BOOT
- FILE *fp;
- char temp[2];
- int size;
-
- fp = fopen("/proc/alarm_boot", "r");
- if (fp == NULL)
- alarm_boot = 0;
- else {
-
- size = fread(&temp, 1, 1, fp);
- if (size != 1)
- alarm_boot = 0;
- else {
- temp[1] = 0;
- alarm_boot = atoi(temp);
- }
- fclose(fp);
- }
-#endif
__initialize_timer();
if (__initialize_dbus() == false) { /* because dbus's initialize
__initialize_db();
__initialize_alarm_list();
__initialize_noti();
-#ifdef __APP_SYNC
- _sync_scheduler_init();
-#endif
-
-}
-
-#ifdef __ALARM_BOOT
-static bool __check_false_alarm()
-{
- time_t current_time;
- time_t interval;
-
- time(¤t_time);
-
- interval = ab_due_time - current_time;
-
- ALARM_MGR_LOG_PRINT("due_time : %d / current_time %d\n", \
- alarm_context.c_due_time, current_time);
- if (interval > 0 && interval <= 30) {
- return true;
- } else if (!poweron_alarm_expired) {
- /* originally, first arguement's value was 121(app_id) which means
- * alarm_booting ui application.and this application's dbus-service
- * name had a com.samsung.alarmboot.ui in a platform with app-server.
- * so we set "com.samsung.alarmboot.ui.ALARM" instead of 121.
- */
- __alarm_send_noti_to_application(
- WAKEUP_ALARMBOOTING_APP_ID, -1);
- return false;
- }
+ __initialize_module_log(); // for module log
- return true;
}
-#endif
int main()
{
__initialize();
-#ifdef __ALARM_BOOT
- if (alarm_boot){
- __check_false_alarm();
- }
-#endif
-
g_main_loop_run(mainloop);
return 0;
-#include<stdio.h>
-#include<stdlib.h>
-#include<errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
-#include<sys/types.h>
-#include<string.h>
-#include<dbus/dbus.h>
-#include<dbus/dbus-glib.h>
-#include<glib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <glib.h>
#include <fcntl.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include "alarm.h"
#include "alarm-internal.h"
-#include "alarm-stub.h"
+#include "alarm-mgr-stub.h"
#include <bundle.h>
#include <appsvc.h>
#include <aul.h>
+#include <gio/gio.h>
#define MAX_KEY_SIZE 256
+#define MAX_PROC_NAME_LEN 512
static alarm_context_t alarm_context = { NULL, NULL, NULL, NULL, -1 };
pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
-#define MAX_OBJECT_PATH_LEN 256
-#define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
+static void __handle_expiry_method_call(GDBusConnection *conn,
+ const gchar *name, const gchar *path, const gchar *interface,
+ const gchar *method, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data);
-static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection,
- DBusMessage *message,
- void *user_data);
static int __alarm_validate_date(alarm_date_t *date, int *error_code);
static bool __alarm_validate_time(alarm_date_t *date, int *error_code);
static int __sub_init(void);
static int __alarmmgr_init_appsvc(void);
-bool alarm_power_off(int *error_code);
-int alarmmgr_check_next_duetime(void);
typedef struct _alarm_cb_info_t {
- int alarm_id;
+ alarm_id_t alarm_id;
alarm_cb_t cb_func;
void *priv_data;
struct _alarm_cb_info_t *next;
static alarm_cb_info_t *alarmcb_head = NULL;
-static void __add_resultcb(int alarm_id, alarm_cb_t cb_func,
- void *data)
+guint registration_id = 0;
+
+static GDBusNodeInfo *introspection_data = NULL;
+
+static const gchar introspection_xml[] =
+ "<node name='/com/samsung/alarm/client'>"
+ " <interface name='com.samsung.alarm.client'>"
+ " <method name='alarm_expired'>"
+ " <arg type='i' name='alarm_id' direction='in'/>"
+ " <arg type='s' name='service_name' direction='in'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+
+static const GDBusInterfaceVTable interface_vtable =
+{
+ __handle_expiry_method_call,
+ NULL,
+ NULL
+};
+
+static void __add_resultcb(alarm_id_t alarm_id, alarm_cb_t cb_func, void *data)
{
alarm_cb_info_t *info;
alarmcb_head = info;
}
-static alarm_cb_info_t *__find_resultcb(int alarm_id)
+static alarm_cb_info_t *__find_resultcb(alarm_id_t alarm_id)
{
alarm_cb_info_t *tmp;
tmp = alarmcb_head;
while (tmp) {
- if (tmp->alarm_id == alarm_id)
+ if (tmp->alarm_id == alarm_id) {
+ ALARM_MGR_LOG_PRINT("matched alarm id = %d", alarm_id);
return tmp;
+ }
tmp = tmp->next;
}
return NULL;
}
}
-static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+static void __handle_expiry_method_call(GDBusConnection *conn,
+ const gchar *name, const gchar *path, const gchar *interface,
+ const gchar *method, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
{
- alarm_cb_info_t *info;
-
- if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL) {
- const char *method_name = dbus_message_get_member(message);
- /*"alarm_expired" */
-
- if (strcmp(method_name, "alarm_expired") == 0) {
- DBusMessageIter iter;
- alarm_id_t alarm_id;
- const char *service_name =
- dbus_message_get_destination(message);
- const char *object_path =
- dbus_message_get_path(message);
- /* "/com/samsung/alarm/client" */
- const char *interface_name =
- dbus_message_get_interface(message);
- /* "com.samsung.alarm.client" */
-
- dbus_message_iter_init(message, &iter);
- dbus_message_iter_get_basic(&iter, &alarm_id);
-
- SECURE_LOGD("[alarm-lib]:service_name=%s, "
- "object_path=%s, interface_name=%s, method_name=%s, "
- "alarm_id=%d, handler=%s\n",
- service_name ? service_name : "no name",
- object_path ? object_path : "no path",
- interface_name ? interface_name : "no interface",
- method_name ? method_name : "no method", alarm_id,
- alarm_context.alarm_handler ? "ok" : "no handler");
-
- if (alarm_context.alarm_handler != NULL)
- /* alarm_context.alarm_handler(alarm_id); */
- alarm_context.alarm_handler(alarm_id,
- alarm_context.user_param);
- info = __find_resultcb(alarm_id);
-
- if( info && info->cb_func ) {
- info->cb_func(alarm_id, info->priv_data);
- // __remove_resultcb(info);
- }
+ if (method && strcmp(method, "alarm_expired") == 0) {
+ const gchar *package_name = NULL;
+ alarm_id_t alarm_id = 0;
+ alarm_cb_info_t *info = NULL;
+ g_variant_get(param, "(is)", &alarm_id, &package_name);
+ ALARM_MGR_EXCEPTION_PRINT("[alarm-lib] : Alarm expired for [%s] : Alarm id [%d]", package_name, alarm_id);
+
+ if (alarm_context.alarm_handler != NULL) {
+ alarm_context.alarm_handler(alarm_id, alarm_context.user_param);
+ }
- return DBUS_HANDLER_RESULT_HANDLED;
+ info = __find_resultcb(alarm_id);
+ if (info && info->cb_func) {
+ info->cb_func(alarm_id, info->priv_data);
}
+ g_free(package_name);
}
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static int __alarm_validate_date(alarm_date_t *date, int *error_code)
static int __sub_init()
{
GError *error = NULL;
+ char proc_file[MAX_PROC_NAME_LEN] = {0, };
+ char process_name[MAX_PROC_NAME_LEN] = {0, };
+ int fd = 0;
+ int ret = 0;
+ const int MAX_LEN = MAX_PROC_NAME_LEN;
pthread_mutex_lock(&init_lock);
if (sub_initialized) {
- //ALARM_MGR_LOG_PRINT("__sub_init was already called.\n");
pthread_mutex_unlock(&init_lock);
return ALARMMGR_RESULT_SUCCESS;
}
g_thread_init(NULL);
- dbus_g_thread_init();
+ g_type_init();
- alarm_context.bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
- if (alarm_context.bus == NULL) {
- ALARM_MGR_EXCEPTION_PRINT("dbus bus get failed\n");
+ alarm_context.connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (alarm_context.connection == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("g_bus_get_sync() is failed. error: %s", error->message);
+ g_error_free(error);
pthread_mutex_unlock(&init_lock);
return ERR_ALARM_SYSTEM_FAIL;
}
- alarm_context.proxy = dbus_g_proxy_new_for_name(alarm_context.bus,
+ alarm_context.proxy = g_dbus_proxy_new_sync(alarm_context.connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
"com.samsung.alarm.manager",
"/com/samsung/alarm/manager",
- "com.samsung.alarm.manager");
+ "com.samsung.alarm.manager",
+ NULL,
+ NULL);
+
if (alarm_context.proxy == NULL) {
- ALARM_MGR_EXCEPTION_PRINT("dbus bus proxy get failed\n");
+ ALARM_MGR_EXCEPTION_PRINT("Creating a proxy is failed.");
+ g_object_unref (alarm_context.connection);
pthread_mutex_unlock(&init_lock);
return ERR_ALARM_SYSTEM_FAIL;
}
- alarm_context.pid = getsid(getpid()); /*this running appliction's session id*/
+ // Only webapp which has a pid of WebProcess uses the sid. Otherwise, the pid is used.
+ snprintf(proc_file, MAX_LEN, "/proc/%d/cmdline", getpid());
+ fd = open(proc_file, O_RDONLY);
+ if (fd < 0) {
+ SECURE_LOGE("Unable to get the proc file(%d).\n", getpid());
+ g_object_unref(alarm_context.proxy);
+ g_object_unref(alarm_context.connection);
+ pthread_mutex_unlock(&init_lock);
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+ else {
+ ret = read(fd, process_name, MAX_LEN);
+ close(fd);
+ if (ret < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to read the proc file(%d).", getpid());
+ g_object_unref(alarm_context.proxy);
+ g_object_unref(alarm_context.connection);
+ pthread_mutex_unlock(&init_lock);
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+ else {
+ if (strncmp(process_name, "/usr/bin/WebProcess", strlen("/usr/bin/WebProcess")) == 0) {
+ alarm_context.pid = getsid(getpid());
+ SECURE_LOGD("alarm_context.pid is set to sessionID, %d.", alarm_context.pid);
+ }
+ else {
+ alarm_context.pid = getpid();
+ SECURE_LOGD("alarm_context.pid is set to processID, %d.", alarm_context.pid);
+ }
+ }
+ }
sub_initialized = true;
return ALARMMGR_RESULT_SUCCESS;
}
-bool alarm_power_off(int *error_code)
-{
- ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_off() is called\n");
-
-#ifdef __ALARM_BOOT
- return _send_alarm_power_off(alarm_context, error_code);
-#else
- ALARM_MGR_LOG_PRINT(
- "[alarm-lib]:ALARM_BOOT feature is not supported. "
- "so we return false.\n");
- if (error_code)
- *error_code = -1; /*-1 means that system failed
- internally.*/
- return false;
-#endif
-}
-
-int alarmmgr_check_next_duetime()
-{
- int error_code;
- ALARM_MGR_LOG_PRINT(
- "[alarm-lib]:alarm_check_next_duetime() is called\n");
-
-#ifdef __ALARM_BOOT
- if (!_send_alarm_check_next_duetime(alarm_context, &error_code))
- return error_code;
-#else
- ALARM_MGR_LOG_PRINT(
- "[alarm-lib]:ALARM_BOOT feature is not supported. "
- "so we return false.\n");
- return ERR_ALARM_SYSTEM_FAIL;
-#endif
-
- return ALARMMGR_RESULT_SUCCESS;
-}
-
EXPORT_API int alarmmgr_init(const char *appid)
{
- DBusError derror;
+ SECURE_LOGD("Enter");
int request_name_result = 0;
char service_name[MAX_SERVICE_NAME_LEN] = { 0 };
char service_name_mod[MAX_SERVICE_NAME_LEN]= { 0 };
-
- int ret;
+ int ret = ALARMMGR_RESULT_SUCCESS;
+ guint owner_id = 0;
int i = 0;
int j = 0;
int len = 0;
return ERR_ALARM_INVALID_PARAM;
if (b_initialized) {
- SECURE_LOGD(
- "alarm was already initialized. app_service_name=%s\n",
+ SECURE_LOGD("alarm was already initialized. app_service_name=%s",
g_quark_to_string(alarm_context.quark_app_service_name));
return ALARMMGR_RESULT_SUCCESS;
}
if (ret < 0)
return ret;
- memset(service_name_mod, 'a', MAX_SERVICE_NAME_LEN-1);
+ memset(service_name_mod, 'a', MAX_SERVICE_NAME_LEN - 1);
len = strlen("ALARM.");
strncpy(service_name, "ALARM.", len);
strncpy(service_name + len, appid, strlen(appid));
- j=0;
-
- for(i=0;i<=strlen(service_name);i++)
- {
- if (service_name[i] == '.' )
- {
+ for(i = 0; i <= strlen(service_name); i++) {
+ if (service_name[i] == '.') {
service_name_mod[j] = service_name[i];
- j++;
- }
- else{
+ j++;
+ }
+ else {
service_name_mod[j] = service_name[i];
}
- j++;
- }
-
- SECURE_LOGD("[alarm-lib]: service_name %s\n", service_name);
- SECURE_LOGD("[alarm-lib]: service_name_mod %s\n", service_name_mod);
+ j++;
+ }
- dbus_error_init(&derror);
+ SECURE_LOGD("[alarm-lib]: dbus own name: %s", service_name_mod);
+ owner_id = g_bus_own_name_on_connection(alarm_context.connection, service_name_mod,
+ G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL);
+ if (owner_id == 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Acquiring the own name is failed. %s", service_name_mod);
+ goto error;
+ }
- request_name_result = dbus_bus_request_name(
- dbus_g_connection_get_connection(alarm_context.bus),
- service_name_mod, 0, &derror);
- if (dbus_error_is_set(&derror)) /*failure*/ {
- SECURE_LOGE(
- "Failed to dbus_bus_request_name(%s): %s\n", service_name,
- derror.message);
- dbus_error_free(&derror);
+ introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
+ if (introspection_data == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("g_dbus_node_info_new_for_xml() is failed.");
+ goto error;
+ }
- return ERR_ALARM_SYSTEM_FAIL;
+ registration_id = g_dbus_connection_register_object(alarm_context.connection,
+ "/com/samsung/alarm/client",
+ introspection_data->interfaces[0],
+ &interface_vtable, NULL, NULL, NULL);
+ if (registration_id == 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Registering the callback is failed.");
+ goto error;
}
- alarm_context.quark_app_service_name =
- g_quark_from_string(service_name);
- alarm_context.quark_app_service_name_mod=
- g_quark_from_string(service_name_mod);
+ alarm_context.quark_app_service_name = g_quark_from_string(service_name);
+ alarm_context.quark_app_service_name_mod= g_quark_from_string(service_name_mod);
- if (!dbus_connection_add_filter(
- dbus_g_connection_get_connection(alarm_context.bus),
- __expire_alarm_filter, NULL, NULL)) {
- ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
+ b_initialized = true;
- return ERR_ALARM_SYSTEM_FAIL;
+ SECURE_LOGD("Leave");
+ return ALARMMGR_RESULT_SUCCESS;
+
+error:
+ if (introspection_data) {
+ g_dbus_node_info_unref(introspection_data);
}
+ if (registration_id != 0) {
+ g_dbus_connection_unregister_object(alarm_context.connection, registration_id);
+ }
+ g_object_unref(alarm_context.proxy);
+ alarm_context.proxy = NULL;
- b_initialized = true;
- return ALARMMGR_RESULT_SUCCESS;
+ g_object_unref(alarm_context.connection);
+ alarm_context.connection = NULL;
+ sub_initialized = false;
+ return ERR_ALARM_INVALID_PARAM;
}
EXPORT_API void alarmmgr_fini()
{
- dbus_connection_remove_filter(dbus_g_connection_get_connection
- (alarm_context.bus),
- __expire_alarm_filter, NULL);
+ SECURE_LOGD("Enter");
+ if (introspection_data) {
+ g_dbus_node_info_unref(introspection_data);
+ }
+
+ if (alarm_context.connection != NULL && registration_id != 0) {
+ g_dbus_connection_unregister_object(alarm_context.connection, registration_id);
+ }
+
+ if (alarm_context.proxy) {
+ g_object_unref(alarm_context.proxy);
+ alarm_context.proxy = NULL;
+ }
+
+ if (alarm_context.connection) {
+ g_object_unref(alarm_context.connection);
+ alarm_context.connection = NULL;
+ }
+
b_initialized = false;
+ sub_initialized = false;
+
+ SECURE_LOGD("Leave");
}
EXPORT_API int alarmmgr_set_cb(alarm_cb_t handler, void *user_param)
{
- ALARM_MGR_LOG_PRINT("alarm_set_cb is called\n");
+ SECURE_LOGD("Enter");
if (handler == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("callback is NULL.");
return ERR_ALARM_INVALID_PARAM;
}
alarm_context.alarm_handler = handler;
alarm_context.user_param = user_param;
+
+ SECURE_LOGD("Leave");
return ALARMMGR_RESULT_SUCCESS;
}
ret = __sub_init();
if (ret < 0){
- if (return_code)
+ if (return_code) {
*return_code = ret;
+ }
return NULL;
}
- ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_alarm_appsvc_info() is called\n");
+ ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_alarm_appsvc_info() is called.");
if (alarm_id <= 0) {
- if (return_code)
+ if (return_code) {
*return_code = ERR_ALARM_INVALID_ID;
+ }
return NULL;
}
alarm_info_t *alarm_info = NULL; /* = (alarm_info_t*)alarm; */
const char *operation = NULL;
int error_code = 0;
- char *appid = NULL;
+ const char *appid = NULL;
bundle *b=(bundle *)bundle_data;
}
alarm_mode_t *mode = &alarm_info->mode;
- ALARM_MGR_LOG_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
+ ALARM_MGR_EXCEPTION_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
alarm_info->start.day, alarm_info->start.month, alarm_info->start.year,
alarm_info->start.hour, alarm_info->start.min, alarm_info->start.sec,
alarm_info->end.year, alarm_info->end.month, alarm_info->end.day,
}
- if (!_send_alarm_create_appsvc
- (alarm_context, alarm_info, alarm_id, b,
- &error_code)) {
+ if (!_send_alarm_create_appsvc(alarm_context, alarm_info, alarm_id, b, &error_code)) {
return error_code;
}
if (ret < 0)
return ret;
- ALARM_MGR_LOG_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
+ ALARM_MGR_EXCEPTION_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
alarm_info->start.day, alarm_info->start.month, alarm_info->start.year,
alarm_info->start.hour, alarm_info->start.min, alarm_info->start.sec,
alarm_info->end.year, alarm_info->end.month, alarm_info->end.day,
}
if (destination != NULL) {
- memset(dst_service_name, 0,
- strlen(destination) + strlen("ALARM.") + 2);
- snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "ALARM.%s",
- destination);
-
- memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
-
- j=0;
-
- for(i=0; i<=strlen(dst_service_name); i++)
- {
- if (dst_service_name[i] == '.' )
- {
+ memset(dst_service_name, 0, strlen(destination) + strlen("ALARM.") + 2);
+ snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "ALARM.%s", destination);
+ memset(dst_service_name_mod, 'a', MAX_SERVICE_NAME_LEN-1);
+
+ for (i=0; i<=strlen(dst_service_name); i++)
+ {
+ if (dst_service_name[i] == '.' )
+ {
dst_service_name_mod[j] = dst_service_name[i];
- j++;
- }
- else
- {
- dst_service_name_mod[j] = dst_service_name[i];
- }
- j++;
- }
+ j++;
+ }
+ else
+ {
+ dst_service_name_mod[j] = dst_service_name[i];
+ }
+ j++;
+ }
- if (!_send_alarm_create
- (alarm_context, alarm_info, alarm_id, dst_service_name, dst_service_name_mod,
- &error_code)) {
+ if (!_send_alarm_create(alarm_context, alarm_info, alarm_id, dst_service_name, dst_service_name_mod, &error_code)) {
+ return error_code;
+ }
+ } else {
+ if (!_send_alarm_create(alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
return error_code;
}
- } else
- if (!_send_alarm_create
- (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
- return error_code;
}
return ALARMMGR_RESULT_SUCCESS;
alarm_id_t *alarm_id)
{
int error_code = 0;;
- time_t current_time;
+ struct timeval current_time;
struct tm duetime_tm;
alarm_info_t alarm_info;
const char *operation = NULL;
alarm_info.alarm_type = alarm_type;
alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
- time(¤t_time);
+ gettimeofday(¤t_time, NULL);
- current_time += trigger_at_time;
+ if (current_time.tv_usec > 500 * 1000)
+ {
+ // When the millisecond part of the current_time is bigger than 500ms,
+ // the duetime increases by extra 1sec.
+ current_time.tv_sec += (trigger_at_time + 1);
+ }
+ else
+ {
+ current_time.tv_sec += trigger_at_time;
+ }
- localtime_r(¤t_time, &duetime_tm);
+ tzset(); // Processes the TZ environment variable, and Set timezone, daylight, and tzname.
+ localtime_r(¤t_time.tv_sec, &duetime_tm);
alarm_info.start.year = duetime_tm.tm_year + 1900;
alarm_info.start.month = duetime_tm.tm_mon + 1;
alarm_info.mode.u_interval.interval = interval;
}
- ALARM_MGR_LOG_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
+ ALARM_MGR_EXCEPTION_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
alarm_info.mode.repeat, alarm_info.mode.u_interval, alarm_info.alarm_type);
- if (!_send_alarm_create_appsvc
- (alarm_context, &alarm_info, alarm_id, b,
- &error_code)) {
+ if (!_send_alarm_create_appsvc(alarm_context, &alarm_info, alarm_id, b, &error_code)) {
return error_code;
}
int i = 0;
int j = 0;
int error_code;
- time_t current_time;
+ struct timeval current_time;
struct tm duetime_tm;
alarm_info_t alarm_info;
int ret;
alarm_info.alarm_type = alarm_type;
alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
- time(¤t_time);
+ gettimeofday(¤t_time, NULL);
- current_time += trigger_at_time;
+ if (current_time.tv_usec > 500 * 1000)
+ {
+ // When the millisecond part of the current_time is bigger than 500ms,
+ // the duetime increases by extra 1sec.
+ current_time.tv_sec += (trigger_at_time + 1);
+ }
+ else
+ {
+ current_time.tv_sec += trigger_at_time;
+ }
- localtime_r(¤t_time, &duetime_tm);
+ tzset(); // Processes the TZ environment variable, and Set timezone, daylight, and tzname.
+ localtime_r(¤t_time.tv_sec, &duetime_tm);
alarm_info.start.year = duetime_tm.tm_year + 1900;
alarm_info.start.month = duetime_tm.tm_mon + 1;
alarm_info.mode.u_interval.interval = interval;
}
- ALARM_MGR_LOG_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
+ ALARM_MGR_EXCEPTION_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
alarm_info.mode.repeat, alarm_info.mode.u_interval, alarm_info.alarm_type);
char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
int i = 0;
int j = 0;
- int error_code;
- time_t current_time;
+ int error_code = 0;
+ struct timeval current_time;
struct tm duetime_tm;
alarm_info_t alarm_info;
- int ret;
- char appid[256];
+ int ret = 0;
+ char appid[256] = {0,};
- aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
+ if (aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)) != AUL_R_OK) {
+ ALARM_MGR_LOG_PRINT("aul_app_get_appid_bypid() is failed. PID %d may not be app.", getpid());
+ }
ret = alarmmgr_init(appid);
if (ret < 0)
return ret;
- ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_add_alarm_withcb() is called\n");
-
- ALARM_MGR_LOG_PRINT("interval(%d)", interval);
+ ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_add_alarm_withcb() is called");
if (alarm_id == NULL) {
return ERR_ALARM_INVALID_PARAM;
alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
alarm_info.alarm_type |= ALARM_TYPE_WITHCB;
- time(¤t_time);
+ gettimeofday(¤t_time, NULL);
- current_time += trigger_at_time;
+ if (current_time.tv_usec > 500 * 1000)
+ {
+ // When the millisecond part of the current_time is bigger than 500ms,
+ // the duetime increases by extra 1sec.
+ current_time.tv_sec += (trigger_at_time + 1);
+ }
+ else
+ {
+ current_time.tv_sec += trigger_at_time;
+ }
- localtime_r(¤t_time, &duetime_tm);
+ tzset(); // Processes the TZ environment variable, and Set timezone, daylight, and tzname.
+ localtime_r(¤t_time.tv_sec, &duetime_tm);
alarm_info.start.year = duetime_tm.tm_year + 1900;
alarm_info.start.month = duetime_tm.tm_mon + 1;
alarm_info.mode.u_interval.interval = interval;
}
+ ALARM_MGR_EXCEPTION_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
+ trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
+ alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
+ alarm_info.mode.repeat, alarm_info.mode.u_interval.interval, alarm_info.alarm_type);
+
if (!_send_alarm_create(alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) {
return error_code;
}
EXPORT_API int alarmmgr_remove_all(void)
{
- GError *error = NULL;
+ int error_code;
int return_code = ALARMMGR_RESULT_SUCCESS;
int ret = __sub_init();
if (ret < 0)
return ret;
}
- if(!com_samsung_alarm_manager_alarm_delete_all(alarm_context.proxy, alarm_context.pid, &return_code, &error))
- {
- ALARM_MGR_EXCEPTION_PRINT("com_samsung_alarm_manager_alarm_delete_all() is failed by dbus. "
- "return_code[%d], err message[%s]\n", return_code, error->message);
- return ERR_ALARM_SYSTEM_FAIL;
- }
-
- if (return_code)
- {
- ALARM_MGR_EXCEPTION_PRINT("com_samsung_alarm_manager_alarm_delete_all() is failed. "
- "return_code[%d], err message[%s]\n", return_code, error->message);
- return ERR_ALARM_SYSTEM_FAIL;
- }
+ if (!_send_alarm_delete_all(alarm_context, &error_code))
+ return error_code;
return return_code;
}
EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
{
+ SECURE_LOGD("Enter");
GError *error = NULL;
- GArray *alarm_array = NULL;
+ GVariant *alarm_array = NULL;
int return_code = 0;
- int i = 0;
- int maxnum_of_ids;
- int num_of_ids;
- int alarm_id = -1;
- int ret;
+ int maxnum_of_ids = 0;
+ int num_of_ids = 0;
+ alarm_id_t alarm_id = -1;
+ int ret = 0;
+ char *e_cookie = NULL;
+ char cookie[256] = {0,};
+ int size = 0;
+ GVariantIter *iter = NULL;
- if (fn == NULL)
+ if (fn == NULL) {
return ERR_ALARM_INVALID_PARAM;
+ }
+
+ size = security_server_get_cookie_size();
+ ret = security_server_request_cookie(cookie, size);
+ if (ret < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("security_server_request_cookie() is failed.");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
+
+ e_cookie = g_base64_encode((const guchar *)cookie, size);
+ if (e_cookie == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("g_base64_encode() is failed.");
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
ret = __sub_init();
- if (ret < 0)
+ if (ret < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("__sub_init() is failed.");
+ g_free(e_cookie);
return ret;
+ }
- if (!com_samsung_alarm_manager_alarm_get_number_of_ids(
- alarm_context.proxy, alarm_context.pid, &maxnum_of_ids,
- &return_code, &error)) {
+ SECURE_LOGD("alarm_manager_call_alarm_get_number_of_ids_sync() is called");
+ if (!alarm_manager_call_alarm_get_number_of_ids_sync(
+ (AlarmManager*)alarm_context.proxy, alarm_context.pid, e_cookie, &maxnum_of_ids, &return_code, NULL, &error)) {
/* dbus-glib error */
/* error_code should be set */
ALARM_MGR_EXCEPTION_PRINT(
- "com_samsung_alarm_manager_alarm_get_number_of_ids() "
- "failed. return_code[%d], err message[%s]\n",
- return_code, error->message);
+ "alarm_manager_call_alarm_get_number_of_ids_sync() is failed by dbus. return_code[%d], err message[%s]",
+ return_code, error->message);
+ g_free(e_cookie);
return ERR_ALARM_SYSTEM_FAIL;
}
- if (return_code != 0) {
+ g_free(e_cookie);
+
+ if (return_code != ALARMMGR_RESULT_SUCCESS) {
+ ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_number_of_ids_sync() is failed. return_code[%d]", return_code);
return return_code;
+ } else {
+ ALARM_MGR_LOG_PRINT("maxnum_of_ids[%d]", maxnum_of_ids);
}
- if (!com_samsung_alarm_manager_alarm_get_list_of_ids(
- alarm_context.proxy, alarm_context.pid, maxnum_of_ids,
- &alarm_array, &num_of_ids, &return_code, &error)) {
+ SECURE_LOGD("alarm_manager_call_alarm_get_list_of_ids_sync() is called");
+ if (!alarm_manager_call_alarm_get_list_of_ids_sync(
+ (AlarmManager*)alarm_context.proxy, alarm_context.pid, maxnum_of_ids, &alarm_array, &num_of_ids, &return_code, NULL, &error)) {
/*dbus-glib error */
/* error_code should be set */
ALARM_MGR_EXCEPTION_PRINT(
- "com_samsung_alarm_manager_alarm_get_list_of_ids() "
- "failed. alarm_id[%d], return_code[%d]\n",
- alarm_id, return_code);
+ "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. num_of_ids[%d], return_code[%d].", num_of_ids, return_code);
return ERR_ALARM_SYSTEM_FAIL;
}
- if (return_code != 0) {
+ if (return_code != ALARMMGR_RESULT_SUCCESS) {
return return_code;
- } else {
- if (error != NULL) {
- ALARM_MGR_LOG_PRINT(
- "Alarm server not ready dbus error message %s\n", error->message);
- return ERR_ALARM_SYSTEM_FAIL;
- }
- if (NULL == alarm_array) {
- ALARM_MGR_LOG_PRINT(
- "alarm server not initilized\n");
- return ERR_ALARM_SYSTEM_FAIL;
- }
- for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
- alarm_id = g_array_index(alarm_array, alarm_id_t, i);
- (*fn) (alarm_id, user_param);
- ALARM_MGR_LOG_PRINT("alarm_id(%d)\n", alarm_id);
- }
+ }
+
+ if (error != NULL) {
+ ALARM_MGR_LOG_PRINT("Alarm server is not ready dbus. error message %s.", error->message);
+ return ERR_ALARM_SYSTEM_FAIL;
+ }
- g_array_free(alarm_array, true);
+ if (alarm_array == NULL) {
+ ALARM_MGR_LOG_PRINT("alarm server is not initilized.");
+ return ERR_ALARM_SYSTEM_FAIL;
}
+ g_variant_get(alarm_array, "ai", &iter);
+ while (g_variant_iter_loop(iter, "i", &alarm_id))
+ {
+ (*fn) (alarm_id, user_param);
+ ALARM_MGR_LOG_PRINT("alarm_id (%d)", alarm_id);
+ }
+ g_variant_iter_free(iter);
+ g_variant_unref(alarm_array);
+
+ SECURE_LOGD("Leave");
return ALARMMGR_RESULT_SUCCESS;
}
return ERR_ALARM_INVALID_PARAM;
}
- if (!_send_alarm_get_info(alarm_context, alarm_id, alarm_info,
- &error_code))
- return error_code;
-
- return ALARMMGR_RESULT_SUCCESS;
-}
-
-EXPORT_API int alarmmgr_power_on(bool on_off)
-{
- int error_code;
- ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_on() is called\n");
-
-#ifdef __ALARM_BOOT
- if (!_send_alarm_power_on(alarm_context, on_off, &error_code))
+ if (!_send_alarm_get_info(alarm_context, alarm_id, alarm_info, &error_code)) {
return error_code;
-#else
- ALARM_MGR_LOG_PRINT("[alarm-lib]:ALARM_BOOT feature is not supported. "
- "so we return false.\n");
- return ERR_ALARM_SYSTEM_FAIL;
-#endif
+ }
return ALARMMGR_RESULT_SUCCESS;
}
int alarmmgr_get_number_of_ids(int *num_of_ids)
{
int error_code;
- ALARM_MGR_LOG_PRINT("[alarm-lib]:"
- "alarm_get_number_of_ids() is called\n");
+ ALARM_MGR_LOG_PRINT("[alarm-lib]: alarm_get_number_of_ids() is called.");
if (num_of_ids == NULL) {
return ERR_ALARM_INVALID_PARAM;
}
ALARM_MGR_LOG_PRINT("call alarm_get_number_of_ids\n");
- if (!_send_alarm_get_number_of_ids(alarm_context, num_of_ids,
- &error_code))
+ if (!_send_alarm_get_number_of_ids(alarm_context, num_of_ids, &error_code)) {
return error_code;
+ }
return ALARMMGR_RESULT_SUCCESS;
}
int *num_of_ids)
{
int error_code;
- ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_list_of_ids() is called\n");
+ ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_list_of_ids() is called.");
if (maxnum_of_ids < 0 || alarm_id == NULL || num_of_ids == NULL) {
return ERR_ALARM_INVALID_PARAM;
}
if (!_send_alarm_get_list_of_ids
- (alarm_context, maxnum_of_ids, alarm_id, num_of_ids, &error_code))
+ (alarm_context, maxnum_of_ids, alarm_id, num_of_ids, &error_code)) {
return error_code;
+ }
return ALARMMGR_RESULT_SUCCESS;
}
EXPORT_API int alarmmgr_get_next_duetime(alarm_id_t alarm_id, time_t* duetime)
{
int error_code;
- ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_next_duetime() is called\n");
+ ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_next_duetime() is called.");
if (duetime == NULL) {
return ERR_ALARM_INVALID_PARAM;
}
- if (!_send_alarm_get_next_duetime
- (alarm_context, alarm_id, duetime, &error_code))
+ if (!_send_alarm_get_next_duetime(alarm_context, alarm_id, duetime, &error_code)) {
+ return error_code;
+ }
+
+ return ALARMMGR_RESULT_SUCCESS;
+}
+
+EXPORT_API int alarmmgr_get_all_info(char **db_path)
+{
+ int error_code;
+ ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_all_info() is called.");
+
+ if (db_path == NULL) {
+ return ERR_ALARM_INVALID_PARAM;
+ }
+
+ if (!_send_alarm_get_all_info(alarm_context, db_path, &error_code)) {
return error_code;
+ }
+ ALARM_MGR_LOG_PRINT("[alarm-lib]: successfully save info in %s.", *db_path);
return ALARMMGR_RESULT_SUCCESS;
}