diff options
author | Inkyun Kil <inkyun.kil@samsung.com> | 2019-06-28 10:54:31 +0900 |
---|---|---|
committer | Inkyun Kil <inkyun.kil@samsung.com> | 2019-07-18 11:22:14 +0900 |
commit | f1623f94af87b233049d7a3bc2206f5174fc7109 (patch) | |
tree | f53f71f8edf0a61d77a73405f70b38ebbdd3f051 | |
parent | 6d038d75d5c8eca9f09900d380d6203fae3f989a (diff) | |
download | alarm-manager-f1623f94af87b233049d7a3bc2206f5174fc7109.tar.gz alarm-manager-f1623f94af87b233049d7a3bc2206f5174fc7109.tar.bz2 alarm-manager-f1623f94af87b233049d7a3bc2206f5174fc7109.zip |
Refactoring dbus codes
- Separate dbus codes from alarm-manager.c
- Remove gdbus codegen
Change-Id: Id2fc8e4c9048e01c00566d6f1d9ef9dd2d8a5dcc
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | common/CMakeLists.txt | 14 | ||||
-rw-r--r-- | common/alarm-mgr.xml | 183 | ||||
-rwxr-xr-x | include/alarm-internal.h | 44 | ||||
-rw-r--r-- | lib/CMakeLists.txt | 4 | ||||
-rw-r--r-- | lib/alarm-lib-dbus.c | 1197 | ||||
-rw-r--r-- | lib/alarm-lib-stub.c | 947 | ||||
-rwxr-xr-x | lib/alarm-lib.c | 84 | ||||
-rwxr-xr-x | packaging/alarm-manager.spec | 8 | ||||
-rwxr-xr-x | server/CMakeLists.txt | 4 | ||||
-rwxr-xr-x | server/alarm-manager-dbus.c | 731 | ||||
-rwxr-xr-x | server/alarm-manager-dbus.h | 47 | ||||
-rwxr-xr-x | server/alarm-manager-util.c | 13 | ||||
-rwxr-xr-x | server/alarm-manager-util.h | 1 | ||||
-rwxr-xr-x | server/alarm-manager.c | 1132 | ||||
-rwxr-xr-x | unittest/alarmmanager_unittest.cpp | 351 | ||||
-rwxr-xr-x | unittest/mock/alarm_dbus.h | 2 |
17 files changed, 2334 insertions, 2435 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d9c938..116490b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,6 @@ IF(NOT DEFINED DBUS_INTERFACE) SET(DBUS_INTERFACE "org.tizen.${PROJECT_NAME}.manager") ENDIF(NOT DEFINED DBUS_INTERFACE) -ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(server) ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(tool) @@ -39,6 +38,6 @@ IF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG) INSTALL(FILES ${CMAKE_SOURCE_DIR}/alarmmgr_log_dump.sh DESTINATION ${TZ_SYS_ETC}/dump.d/module.d/) ENDIF(_APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG) -IF(BUILD_GTESTS) - ADD_SUBDIRECTORY(unittest) -ENDIF(BUILD_GTESTS) +#IF(BUILD_GTESTS) +# ADD_SUBDIRECTORY(unittest) +#ENDIF(BUILD_GTESTS) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt deleted file mode 100644 index 6122d84..0000000 --- a/common/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -SET(ALARM_DBUS "alarm-mgr") -STRING(REPLACE ".alarm.manager" "." INTERFACE_PREFIX ${DBUS_INTERFACE}) - -FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen) - -ADD_CUSTOM_COMMAND( - OUTPUT dbus - COMMAND ${GDBUS_CODEGEN} --generate-c-code ${ALARM_DBUS}-stub - --interface-prefix ${INTERFACE_PREFIX} - ${ALARM_DBUS}.xml - DEPENDS ${ALARM_DBUS}.xml - COMMENT "Generating Server GDBus .c/.h") - -ADD_CUSTOM_TARGET(GENERATED_DBUS_CODE DEPENDS dbus) diff --git a/common/alarm-mgr.xml b/common/alarm-mgr.xml deleted file mode 100644 index bcdee08..0000000 --- a/common/alarm-mgr.xml +++ /dev/null @@ -1,183 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<node name="/org/tizen/alarm/manager"> - <interface name="org.tizen.alarm.manager"> - <method name="alarm_create_periodic"> - <arg type="s" name="app_service_name" direction="in" /> - <arg type="s" name="app_service_name_mod" direction="in" /> - <arg type="i" name="interval" direction="in" /> - <arg type="i" name="is_ref" direction="in" /> - <arg type="i" name="method" direction="in" /> - <arg type="i" name="alarm_id" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_create"> - <arg type="s" name="app_service_name" direction="in" /> - <arg type="s" name="app_service_name_mod" direction="in" /> - <arg type="i" name="alarm_info_start_year" direction="in" /> - <arg type="i" name="alarm_info_start_month" direction="in" /> - <arg type="i" name="alarm_info_start_day" direction="in" /> - <arg type="i" name="alarm_info_start_hour" direction="in" /> - <arg type="i" name="alarm_info_start_min" direction="in" /> - <arg type="i" name="alarm_info_start_sec" direction="in" /> - <arg type="i" name="alarm_info_msec" direction="in" /> - <arg type="i" name="alarm_info_end_year" direction="in" /> - <arg type="i" name="alarm_info_end_month" direction="in" /> - <arg type="i" name="alarm_info_end_day" direction="in" /> - <arg type="i" name="alarm_info_mode_day_of_week" direction="in" /> - <arg type="i" name="alarm_info_mode_repeat" direction="in" /> - <arg type="i" name="alarm_info_alarm_type" direction="in" /> - <arg type="i" name="alarm_info_reserved_info" direction="in" /> - <arg type="s" name="alarm_info_reserved_service_name" direction="in" /> - <arg type="s" name="alarm_info_reserved_service_name_mod" direction="in" /> - <arg type="i" name="alarm_id" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_create_appsvc"> - <arg type="i" name="alarm_info_start_year" direction="in" /> - <arg type="i" name="alarm_info_start_month" direction="in" /> - <arg type="i" name="alarm_info_start_day" direction="in" /> - <arg type="i" name="alarm_info_start_hour" direction="in" /> - <arg type="i" name="alarm_info_start_min" direction="in" /> - <arg type="i" name="alarm_info_start_sec" direction="in" /> - <arg type="i" name="alarm_info_end_year" direction="in" /> - <arg type="i" name="alarm_info_end_month" direction="in" /> - <arg type="i" name="alarm_info_end_day" direction="in" /> - <arg type="i" name="alarm_info_mode_day_of_week" direction="in" /> - <arg type="i" name="alarm_info_mode_interval" direction="in" /> - <arg type="i" name="alarm_info_mode_repeat" direction="in" /> - <arg type="i" name="alarm_info_alarm_type" direction="in" /> - <arg type="i" name="alarm_info_reserved_info" direction="in" /> - <arg type="s" name="alarm_info_bundle_data" direction="in" /> - <arg type="i" name="alarm_id" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_create_noti"> - <arg type="i" name="alarm_info_start_year" direction="in" /> - <arg type="i" name="alarm_info_start_month" direction="in" /> - <arg type="i" name="alarm_info_start_day" direction="in" /> - <arg type="i" name="alarm_info_start_hour" direction="in" /> - <arg type="i" name="alarm_info_start_min" direction="in" /> - <arg type="i" name="alarm_info_start_sec" direction="in" /> - <arg type="i" name="alarm_info_end_year" direction="in" /> - <arg type="i" name="alarm_info_end_month" direction="in" /> - <arg type="i" name="alarm_info_end_day" direction="in" /> - <arg type="i" name="alarm_info_mode_day_of_week" direction="in" /> - <arg type="i" name="alarm_info_mode_interval" direction="in" /> - <arg type="i" name="alarm_info_mode_repeat" direction="in" /> - <arg type="i" name="alarm_info_alarm_type" direction="in" /> - <arg type="i" name="alarm_info_reserved_info" direction="in" /> - <arg type="s" name="alarm_info_noti_data" direction="in" /> - <arg type="i" name="alarm_id" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_delete"> - <arg type="i" name="alarm_id" direction="in" /> - <arg type="i" name="alarm_info_return_code" direction="out" /> - </method> - <method name="alarm_delete_all"> - <arg type="i" name="alarm_info_return_code" direction="out" /> - </method> - <method name="alarm_update"> - <arg type="i" name="alarm_id" direction="in" /> - <arg type="i" name="alarm_info_start_year" direction="in" /> - <arg type="i" name="alarm_info_start_month" direction="in" /> - <arg type="i" name="alarm_info_start_day" direction="in" /> - <arg type="i" name="alarm_info_start_hour" direction="in" /> - <arg type="i" name="alarm_info_start_min" direction="in" /> - <arg type="i" name="alarm_info_start_sec" direction="in" /> - <arg type="i" name="alarm_info_end_year" direction="in" /> - <arg type="i" name="alarm_info_end_month" direction="in" /> - <arg type="i" name="alarm_info_end_day" direction="in" /> - <arg type="i" name="alarm_info_mode_day_of_week" direction="in" /> - <arg type="i" name="alarm_info_mode_repeat" direction="in" /> - <arg type="i" name="alarm_info_alarm_type" direction="in" /> - <arg type="i" name="alarm_info_reserved_info" direction="in" /> - <arg type="i" name="update_flag" direction="in" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_get_number_of_ids"> - <arg type="i" name="number_of_ids" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_get_list_of_ids"> - <arg type="i" name="max_number_of_ids" direction="in" /> - <arg type="ai" name="alarm_id" direction="out" /> - <arg type="i" name="number_of_ids" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_get_appsvc_info"> - <arg type="i" name="alarm_id" direction="in" /> - <arg type="s" name="b_data" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_get_noti_info"> - <arg type="i" name="alarm_id" direction="in" /> - <arg type="s" name="noti_data" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_get_info"> - <arg type="i" name="alarm_id" direction="in" /> - <arg type="i" name="alarm_info_start_year" direction="out" /> - <arg type="i" name="alarm_info_start_month" direction="out" /> - <arg type="i" name="alarm_info_start_day" direction="out" /> - <arg type="i" name="alarm_info_start_hour" direction="out" /> - <arg type="i" name="alarm_info_start_min" direction="out" /> - <arg type="i" name="alarm_info_start_sec" direction="out" /> - <arg type="i" name="alarm_info_end_year" direction="out" /> - <arg type="i" name="alarm_info_end_month" direction="out" /> - <arg type="i" name="alarm_info_end_day" direction="out" /> - <arg type="i" name="alarm_info_mode_day_of_week" direction="out" /> - <arg type="i" name="alarm_info_mode_repeat" direction="out" /> - <arg type="i" name="alarm_info_alarm_type" direction="out" /> - <arg type="i" name="alarm_info_reserved_info" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_set_rtc_time"> - <arg type="i" name="alarm_info_year" direction="in" /> - <arg type="i" name="alarm_info_month" direction="in" /> - <arg type="i" name="alarm_info_day" direction="in" /> - <arg type="i" name="alarm_info_hour" direction="in" /> - <arg type="i" name="alarm_info_min" direction="in" /> - <arg type="i" name="alarm_info_sec" direction="in" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_get_next_duetime"> - <arg type="i" name="alarm_id" direction="in" /> - <arg type="i" name="duetime" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_get_all_info"> - <arg type="s" name="db_path" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_set_time"> - <arg type="i" name="time" direction="in" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_set_time_with_propagation_delay"> - <arg type="u" name="new_sec" direction="in" /> - <arg type="u" name="new_nsec" direction="in" /> - <arg type="u" name="req_sec" direction="in" /> - <arg type="u" name="req_nsec" direction="in" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_set_timezone"> - <arg type="s" name="tzpath_str" direction="in" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_set_global"> - <arg type="i" name="alarm_id" direction="in" /> - <arg type="b" name="global" direction="in" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <method name="alarm_get_global"> - <arg type="i" name="alarm_id" direction="in" /> - <arg type="b" name="global" direction="out" /> - <arg type="i" name="return_code" direction="out" /> - </method> - <signal name="alarm_expired"> - <arg type="i" name="alarm_id" /> - <arg type="s" name="app_service_name" /> - </signal> - </interface> -</node> diff --git a/include/alarm-internal.h b/include/alarm-internal.h index c7f227b..4ce712a 100755 --- a/include/alarm-internal.h +++ b/include/alarm-internal.h @@ -15,12 +15,6 @@ */ #pragma once -#define MAX_SNOOZE_CNT 5 -#define REPEAT_MODE_ONCE 0x80 - -#define SIG_TIMER 0x32 -#define ALARM_INFO_MAX 100 - #ifdef __cplusplus extern "C" { #endif @@ -34,8 +28,11 @@ extern "C" { #include "alarm.h" -#define INIT_ALARM_LIST_SIZE 64 -#define INIT_SCHEDULED_ALARM_LIST_SIZE 32 +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "ALARM_MANAGER" + #define MAX_BUNDLE_NAME_LEN 2048 #define MAX_SERVICE_NAME_LEN 256 #define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8 @@ -44,13 +41,6 @@ extern "C" { #define REGULAR_UID_MIN 5000 #define MAX_APP_ID 256 -#define SYSTEM_TIME_CHANGED "setting_time_changed" - -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "ALARM_MANAGER" - typedef struct { GDBusConnection *connection; GDBusConnection *session_conn; @@ -92,7 +82,7 @@ bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id, bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code); bool _send_alarm_delete_all(alarm_context_t context, int *error_code); bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids, - alarm_id_t *alarm_id, int *num_of_ids, int *error_code); + GVariantIter **iter, int *num_of_ids, int *error_code); bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, int *error_code); bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, alarm_info_t *alarm_info, int *error_code); bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, time_t* duetime, int *error_code); @@ -185,6 +175,28 @@ bool _init_scheduled_alarm_list(); void _alarm_initialize(); time_t _get_periodic_alarm_standard_time(void); +bool _can_skip_expired_cb(alarm_id_t alarm_id); + +int alarm_manager_alarm_create(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id); +int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id); +int alarm_manager_alarm_create_periodic(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id); +int alarm_manager_alarm_create_noti(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id); +int alarm_manager_alarm_delete(GVariant *parameters, uid_t uid, pid_t pid); +int alarm_manager_alarm_delete_all(GVariant *parameters, uid_t uid, pid_t pid); +int alarm_manager_alarm_update(GVariant *parameters, uid_t uid, pid_t pid); +int alarm_manager_alarm_get_number_of_ids(uid_t uid, pid_t pid, int *num_of_ids); +int alarm_manager_alarm_get_list_of_ids(GVariant *parameters, uid_t uid, pid_t pid, GVariant **alarm_array, int *num_of_alarm); +int alarm_manager_alarm_get_appsvc_info(GVariant *parameters, uid_t uid, gchar **b_data); +int alarm_manager_alarm_get_noti_info(GVariant *parameters, uid_t uid, gchar **noti_data); +int alarm_manager_alarm_get_info(GVariant *parameters, uid_t uid, alarm_info_t *alarm_info); +int alarm_manager_alarm_get_next_duetime(GVariant *parameters, uid_t uid, int *duetime); +int alarm_manager_alarm_get_all_info(uid_t uid, char **db_path); +int alarm_manager_alarm_set_rtc_time(GVariant *parameters); +int alarm_manager_alarm_set_time(GVariant* parameters); +int alarm_manager_alarm_set_time_with_propagation_delay(GVariant* parameters); +int alarm_manager_alarm_set_timezone(GVariant* parameters); +int alarm_manager_alarm_set_global(GVariant *parameters, uid_t uid); +int alarm_manager_alarm_get_global(GVariant *parameters, gboolean *global); #define ALARM_MGR_LOG_PRINT(FMT, ARG...) LOGD(FMT, ##ARG) #define ALARM_MGR_EXCEPTION_PRINT(FMT, ARG...) LOGW(FMT, ##ARG) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 081c3bc..5a82e1a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -3,9 +3,6 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/server) AUX_SOURCE_DIRECTORY(./ LIB_SRCS) -SET(LIB_SRCS ${LIB_SRCS} ${CMAKE_SOURCE_DIR}/common/alarm-mgr-stub.c) -SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/alarm-mgr-stub.c - PROPERTIES GENERATED TRUE) PKG_CHECK_MODULES(lib_pkgs REQUIRED glib-2.0 gobject-2.0 dlog bundle appsvc gio-2.0 gio-unix-2.0 libtzplatform-config notification cert-svc-vcore) @@ -20,7 +17,6 @@ INCLUDE_DIRECTORIES(${lib_pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${lib_pkgs_LIBRARY_DIRS}) ADD_LIBRARY(${LIBRARY} SHARED ${LIB_SRCS}) -ADD_DEPENDENCIES(${LIBRARY} GENERATED_DBUS_CODE) TARGET_LINK_LIBRARIES(${LIBRARY} ${lib_pkgs_LDFLAGS}) SET_TARGET_PROPERTIES(${LIBRARY} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") SET_TARGET_PROPERTIES(${LIBRARY} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER} CLEAN_DIRECT_OUTPUT 1) diff --git a/lib/alarm-lib-dbus.c b/lib/alarm-lib-dbus.c new file mode 100644 index 0000000..0af22bb --- /dev/null +++ b/lib/alarm-lib-dbus.c @@ -0,0 +1,1197 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <string.h> +#include <glib.h> +#include <notification.h> +#include <notification_ipc.h> + +#include "alarm.h" +#include "alarm-internal.h" + +bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info, + alarm_id_t *alarm_id, notification_h noti, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *noti_gv = NULL; + char *noti_data; + guchar *data; + int datalen = 0; + GVariant *param = NULL; + GVariant *reply = NULL; + + noti_gv = notification_ipc_make_gvariant_from_noti(noti, true); + if (!noti_gv) { + if (error_code) + *error_code = ERR_ALARM_SYSTEM_FAIL; + return false; + } + + datalen = g_variant_get_size(noti_gv); + if (datalen < 0) + return false; + + data = malloc(datalen); + if (!data) + return false; + + g_variant_store(noti_gv, data); + noti_data = g_base64_encode((guchar *)data, datalen); + + param = g_variant_new("(iiiiiiiiiiiiiis)", + 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.u_interval.interval, + alarm_info->mode.repeat, + alarm_info->alarm_type, + alarm_info->reserved_info, + (char *)noti_data); + + if (noti_data) + free(noti_data); + if (data) + free(data); + g_variant_unref(noti_gv); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_create_noti", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed. alarm_id[%d],\ + return_code[%d].error->message is %s(%d)", *(int *)alarm_id, + return_code, error->message, error->code); + g_error_free(error); + return false; + } + + g_variant_get(reply, "(ii)", alarm_id, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_create_noti() success. alarm_id[%d], return_code[%d].", + *alarm_id, return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info, + alarm_id_t *alarm_id, bundle *b, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + bundle_raw *b_data = NULL; + int datalen = 0; + GVariant *param = NULL; + GVariant *reply = NULL; + + if (bundle_encode(b, &b_data, &datalen)) { + ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n"); + if (error_code) + *error_code = ERR_ALARM_SYSTEM_FAIL; + return false; + } + + param = g_variant_new("(iiiiiiiiiiiiiis)", + 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.u_interval.interval, + alarm_info->mode.repeat, + alarm_info->alarm_type, + alarm_info->reserved_info, + (char *)b_data); + + if (b_data) + free(b_data); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_create_appsvc", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d], return_code[%d]. error->message is %s(%d)", + *alarm_id, return_code, error->message, error->code); + g_error_free(error); + return false; + } + + g_variant_get(reply, "(ii)", alarm_id, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_create_appsvc() success. alarm_id[%d], return_code[%d].", + *alarm_id, return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info, + alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod, + int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/ + if (context.app_service_name == NULL + && strlen(dst_service_name) == 4 + && strncmp(dst_service_name, "null", 4) == 0) { + ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n"); + if (error_code) + *error_code = ERR_ALARM_INVALID_PARAM; + return false; + } + + param = g_variant_new("(ssiiiiiiiiiiiiiissi)", + context.app_service_name, + context.app_service_name_mod, + 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->msec, + 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, + dst_service_name, dst_service_name_mod); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_create", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d], return_code[%d]. error->message is %s(%d)", + *alarm_id, return_code, error->message, error->code); + g_error_free(error); + + return false; + } + + g_variant_get(reply, "(ii)", alarm_id, return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_create() dbus sync success. alarm_id[%d], return_code[%d].", + *alarm_id, return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref, + int method, alarm_id_t *alarm_id, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + if (context.app_service_name == NULL) { + ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n"); + if (error_code) + *error_code = ERR_ALARM_INVALID_PARAM; + return false; + } + + param = g_variant_new("(ssiii)", + context.app_service_name, + context.app_service_name_mod, + interval, is_ref, method); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_create_periodic", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d], return_code[%d]. error->message is %s(%d)", + *(int *)alarm_id, return_code, error->message, error->code); + + g_error_free(error); + + return false; + } + + g_variant_get(reply, "(ii)", alarm_id, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_create_periodic() dbus sync success. alarm_id[%d], return_code[%d].", + *alarm_id, return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + bundle *b = NULL; + gchar *b_data = NULL; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(i)", alarm_id); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_appsvc_info", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d], return_code[%d]. error->message is %s(%d)", + alarm_id, return_code, error->message, error->code); + + g_error_free(error); + + return NULL; + } + + g_variant_get(reply, "(si)", &b_data, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_get_appsvc_info() dbus sync success. return_code[%d].", + return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + } else { + b = bundle_decode((bundle_raw *)b_data, strlen(b_data)); + } + + if (b_data) + g_free(b_data); + + g_variant_unref(reply); + return b; +} + +notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + int datalen; + GVariant *noti_gv = NULL; + GVariant *body = NULL; + notification_h noti = NULL; + gchar *noti_data = NULL; + guchar *data; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(i)", alarm_id); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_noti_info", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d], return_code[%d]. error->message is %s(%d)", + alarm_id, return_code, error->message, error->code); + + g_error_free(error); + + return NULL; + } + + g_variant_get(reply, "(si)", ¬i_data, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_get_noti_info() dbus sync success. return_code[%d].", + return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + } else { + data = g_base64_decode(noti_data, (gsize *)&datalen); + + noti_gv = g_variant_new_from_data(G_VARIANT_TYPE("(v)"), + data, datalen, + TRUE, NULL, NULL); + + g_variant_get(noti_gv, "(v)", &body); + + noti = notification_create(NOTIFICATION_TYPE_NOTI); + notification_ipc_make_noti_from_gvariant(noti, body); + + g_free(data); + g_variant_unref(noti_gv); + } + + if (noti_data) + g_free(noti_data); + + g_variant_unref(reply); + return noti; +} + +bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(iiiiii)", time->year, time->month, time->day, + time->hour, time->min, time->sec); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_rtc_time", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + return_code[%d]. error->message is %s(%d)", + return_code, error->message, error->code); + + g_error_free(error); + + return false; + } + + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_set_rtc_time() dbus sync success. return_code[%d].", + return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(i)", alarm_id); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_delete", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d], return_code[%d]. error->message is %s(%d)", + alarm_id, return_code, error->message, error->code); + + g_error_free(error); + + return false; + } + + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_delete() dbus sync success. return_code[%d].", + return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_delete_all(alarm_context_t context, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *reply = NULL; + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_delete_all", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + return_code[%d]. error->message is %s(%d)", + return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_delete_all() dbus sync success. return_code[%d].", + return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids, + GVariantIter **iter, int *num_of_ids, + int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariantIter *iter_temp = NULL; + GVariant *arr = NULL; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(i)", maxnum_of_ids); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_list_of_ids", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + return_code[%d]. error->message is %s(%d)", + return_code, error->message, error->code); + + g_error_free(error); + + return false; + } + + g_variant_get(reply, "(@aiii)", &arr, num_of_ids, &return_code); + g_variant_get(arr, "ai", &iter_temp); + + ALARM_MGR_LOG_PRINT( + "alarm_get_list_of_ids() dbus sync success. return_code[%d].", + return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + *iter = iter_temp; + + g_variant_unref(reply); + + return true; +} + +bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, + int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *reply = NULL; + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_number_of_ids", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + return_code[%d]. error->message is %s(%d)", + return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(ii)", num_of_ids, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_get_number_of_ids() dbus sync success.\ + num_of_ids[%d] return_code[%d].", + *num_of_ids, return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, + alarm_info_t *alarm_info, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(i)", alarm_id); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_info", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id [%d] return_code[%d]. error->message is %s(%d)", + alarm_id, return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(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); + + ALARM_MGR_LOG_PRINT( + "alarm_get_info() dbus sync success. return_code[%d].", + return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, + time_t *duetime, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + int _duetime = 0; + + param = g_variant_new("(i)", alarm_id); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_next_duetime", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id [%d] return_code[%d]. error->message is %s(%d)", + alarm_id, return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(ii)", &_duetime, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_get_next_duetime() dbus sync success. return_code[%d].", + return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + *duetime = (time_t)_duetime; + g_variant_unref(reply); + return true; +} + +bool _send_alarm_get_all_info(alarm_context_t context, char **db_path, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *reply = NULL; + char *_db_path = NULL; + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_all_info", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + return_code[%d]. error->message is %s(%d)", + return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(si)", &_db_path, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_get_all_info() dbus sync success. db_path[%s] return_code[%d].", + *db_path, return_code); + + if (return_code != ALARMMGR_RESULT_SUCCESS) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + *db_path = _db_path; + g_variant_unref(reply); + return true; +} + +bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(i)", new_time); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_time", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) + *error_code = ERR_ALARM_SYSTEM_FAIL; + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + return_code[%d]. error->message is %s(%d)", + return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_set_time() dbus sync success. return_code[%d].", + return_code); + + if (return_code != ALARMMGR_RESULT_SUCCESS) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +static void _alarm_set_time_cb(GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + int return_code = -1; + GError *error = NULL; + GVariant *reply = NULL; + alarm_set_time_data_t *func_data = (alarm_set_time_data_t *)user_data; + + reply = g_dbus_proxy_call_finish(func_data->proxy, res, &error); + if (error) { + ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message); + g_error_free(error); + return_code = ERR_ALARM_SYSTEM_FAIL; + } else { + g_variant_get(reply, "(i)", &return_code); + ALARM_MGR_LOG_PRINT( + "alarm_set_time_async() dbus success. return_code[%d].", + return_code); + } + + if (func_data->callback != NULL) + func_data->callback(return_code, func_data->user_data); + + g_variant_unref(reply); + g_free(func_data); +} + +bool _send_alarm_set_time_async(alarm_context_t context, int new_time, alarm_set_time_cb_t result_cb, void *user_data) +{ + alarm_set_time_data_t *func_data; + GVariant *param; + + func_data = g_try_new0(alarm_set_time_data_t, 1); + + if (func_data == NULL) + return false; + + func_data->callback = result_cb; + func_data->user_data = user_data; + func_data->proxy = context.proxy; + + param = g_variant_new("(i)", new_time); + + g_dbus_proxy_call(context.proxy, "alarm_set_time", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, _alarm_set_time_cb, func_data); + + return true; +} + +bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(uuuu)", new_sec, new_nsec, req_sec, req_nsec); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_time_with_propagation_delay", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + return_code[%d]. error->message is %s(%d)", + return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_set_time_with_propagation_delay dbus sync() success.\ + return_code[%d]", return_code); + + if (return_code != ALARMMGR_RESULT_SUCCESS) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +static void _alarm_set_time_with_delay_cb(GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + int return_code = -1; + GError *error = NULL; + GVariant *reply = NULL; + alarm_set_time_data_t *func_data = (alarm_set_time_data_t *)user_data; + + reply = g_dbus_proxy_call_finish(func_data->proxy, res, &error); + if (error) { + ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message); + g_error_free(error); + return_code = ERR_ALARM_SYSTEM_FAIL; + } else { + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_set_time_with_propagation_delay_async() dbus success.\ + return_code[%d].", return_code); + } + + if (func_data->callback != NULL) + func_data->callback(return_code, func_data->user_data); + + g_variant_unref(reply); + g_free(func_data); +} + +bool _send_alarm_set_time_with_propagation_delay_async(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, alarm_set_time_cb_t result_cb, void *user_data) +{ + alarm_set_time_data_t *func_data; + GVariant *param = NULL; + + func_data = g_try_new0(alarm_set_time_data_t, 1); + + if (func_data == NULL) + return false; + + func_data->callback = result_cb; + func_data->user_data = user_data; + func_data->proxy = context.proxy; + + param = g_variant_new("(uuuu)", new_sec, new_nsec, req_sec, req_nsec); + + g_dbus_proxy_call(context.proxy, "alarm_set_time_with_propagation_delay", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, _alarm_set_time_with_delay_cb, func_data); + + return true; +} + +bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(s)", tzpath_str); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_timezone", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + return_code[%d]. error->message is %s(%d)", + return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_set_timezon dbus sync() success. tz_path[%s] return_code[%d]", + tzpath_str, return_code); + + if (return_code != ALARMMGR_RESULT_SUCCESS) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_set_global(alarm_context_t context, const alarm_id_t alarm_id, bool global, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(ib)", alarm_id, (gboolean)global); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_global", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d] return_code[%d]. error->message is %s(%d)", + alarm_id, return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_set_global dbus sync() success. alarm_id[%d], global[%d]\ + return_code[%d]", alarm_id, global, return_code); + + if (return_code != ALARMMGR_RESULT_SUCCESS) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_get_global(alarm_context_t context, const alarm_id_t alarm_id, bool *global, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(i)", alarm_id); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_global", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d] return_code[%d]. error->message is %s(%d)", + alarm_id, return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(bi)", global, &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_get_global dbus sync() success. alarm_id[%d], global[%d]\ + return_code[%d]", alarm_id, *global, return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} + +bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id, + alarm_info_t *alarm_info, int update_flag, int *error_code) +{ + GError *error = NULL; + int return_code = -1; + GVariant *param = NULL; + GVariant *reply = NULL; + + param = g_variant_new("(iiiiiiiiiiiiiii)", + alarm_id, + 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.interval, + alarm_info->mode.repeat, + alarm_info->alarm_type, + alarm_info->reserved_info, + update_flag); + + reply = g_dbus_proxy_call_sync(context.proxy, "alarm_update", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error_code) { + if (error->code == G_DBUS_ERROR_ACCESS_DENIED) + *error_code = ERR_ALARM_NO_PERMISSION; + else + *error_code = ERR_ALARM_SYSTEM_FAIL; + } + + ALARM_MGR_EXCEPTION_PRINT("g_dbus_proxy_call_sync() failed.\ + alarm_id[%d] return_code[%d]. error->message is %s(%d)", + alarm_id, return_code, error->message, error->code); + + g_error_free(error); + return false; + } + + g_variant_get(reply, "(i)", &return_code); + + ALARM_MGR_LOG_PRINT( + "alarm_update dbus sync() success. alarm_id[%d], return_code[%d]",\ + alarm_id, return_code); + + if (return_code != 0) { + if (error_code) + *error_code = return_code; + + g_variant_unref(reply); + return false; + } + + g_variant_unref(reply); + return true; +} diff --git a/lib/alarm-lib-stub.c b/lib/alarm-lib-stub.c deleted file mode 100644 index 4740a43..0000000 --- a/lib/alarm-lib-stub.c +++ /dev/null @@ -1,947 +0,0 @@ -/* - * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <string.h> -#include <glib.h> -#include <notification.h> -#include <notification_ipc.h> -#include "alarm.h" -#include "alarm-internal.h" -#include "alarm-mgr-stub.h" - -#define ALARM_SERVICE_NAME "appframework.alarm" -#define ALARM_OBJECT_PATH "/appframework/alarm" -#define ALARM_INTERFACE_NAME "appframework.alarm" - -bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info, - alarm_id_t *alarm_id, const char *dst_service_name, - const char *dst_service_name_mod, int *error_code); -bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info, - alarm_id_t *alarm_id, bundle *b, int *error_code); -bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, - int *error_code); -bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids, - alarm_id_t *alarm_id, int *num_of_ids, int *error_code); -bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, - int *error_code); -bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, - alarm_info_t *alarm_info, int *error_code); - -bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info, - alarm_id_t *alarm_id, notification_h noti, int *error_code) -{ - gboolean ret; - GError *error = NULL; - int return_code = 0; - GVariant *noti_gv = NULL; - char *noti_data; - guchar *data; - int datalen = 0; - - noti_gv = notification_ipc_make_gvariant_from_noti(noti, true); - if (!noti_gv) { - if (error_code) - *error_code = ERR_ALARM_SYSTEM_FAIL; - return false; - } - - datalen = g_variant_get_size(noti_gv); - if (datalen < 0) - return false; - - data = malloc(datalen); - if (!data) - return false; - - g_variant_store(noti_gv, data); - noti_data = g_base64_encode((guchar *)data, datalen); - - ret = alarm_manager_call_alarm_create_noti_sync((AlarmManager *)context.proxy, - 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.u_interval.interval, - alarm_info->mode.repeat, - alarm_info->alarm_type, - alarm_info->reserved_info, - (char *)noti_data, - alarm_id, &return_code, - NULL, &error); - - if (noti_data) - free(noti_data); - if (data) - free(data); - g_variant_unref(noti_gv); - - if (ret != TRUE) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_create_noti_sync()failed. alarm_id[%d], return_code[%d].", - *(int *)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info, - alarm_id_t *alarm_id, bundle *b, - int *error_code) -{ - gboolean ret; - GError *error = NULL; - int return_code = 0; - bundle_raw *b_data = NULL; - int datalen = 0; - - if (bundle_encode(b, &b_data, &datalen)) { - ALARM_MGR_EXCEPTION_PRINT("Unable to encode the bundle data\n"); - if (error_code) - *error_code = ERR_ALARM_SYSTEM_FAIL; - return false; - } - - ret = alarm_manager_call_alarm_create_appsvc_sync((AlarmManager *)context.proxy, - 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.u_interval.interval, - alarm_info->mode.repeat, - alarm_info->alarm_type, - alarm_info->reserved_info, - (char *)b_data, - alarm_id, &return_code, - NULL, &error); - if (b_data) { - free(b_data); - b_data = NULL; - } - - if (ret != TRUE) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_create_appsvc_sync()failed. alarm_id[%d], return_code[%d].", - *(int *)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info, - alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod, - int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - /*TODO: Dbus bus name validation is must & will be added to avoid alarm-server crash*/ - if (context.app_service_name == NULL - && strlen(dst_service_name) == 4 - && strncmp(dst_service_name, "null", 4) == 0) { - ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n"); - if (error_code) - *error_code = ERR_ALARM_INVALID_PARAM; - return false; - } - - if (!alarm_manager_call_alarm_create_sync((AlarmManager *)context.proxy, - context.app_service_name, - context.app_service_name_mod, - 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->msec, - 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, - dst_service_name, dst_service_name_mod, - alarm_id, &return_code, - NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_create_sync()failed. alarm_id[%d], return_code[%d]", - *(int *)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref, - int method, alarm_id_t *alarm_id, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (context.app_service_name == NULL) { - ALARM_MGR_EXCEPTION_PRINT("Invalid arg. Provide valid destination or call alarmmgr_init()\n"); - if (error_code) - *error_code = ERR_ALARM_INVALID_PARAM; - return false; - } - - if (!alarm_manager_call_alarm_create_periodic_sync((AlarmManager *)context.proxy, - context.app_service_name, - context.app_service_name_mod, - interval, is_ref, method, - alarm_id, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_create_periodic_sync()failed. alarm_id[%d], return_code[%d]", - *(int *)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - bundle *b = NULL; - gchar *b_data = NULL; - - if (!alarm_manager_call_alarm_get_appsvc_info_sync - ((AlarmManager *)context.proxy, alarm_id, &b_data, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_appsvc_info_sync() failed. alarm_id[%d], return_code[%d].", - (int)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - - if (b_data) - g_free(b_data); - - return NULL; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - } else { - b = bundle_decode((bundle_raw *)b_data, strlen(b_data)); - } - - if (b_data) - g_free(b_data); - - return b; -} - -notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - int datalen; - GVariant *noti_gv = NULL; - GVariant *body = NULL; - notification_h noti = NULL; - gchar *noti_data = NULL; - guchar *data; - - if (!alarm_manager_call_alarm_get_noti_info_sync - ((AlarmManager *)context.proxy, alarm_id, ¬i_data, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_appsvc_info_sync() failed. alarm_id[%d], return_code[%d].", - (int)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - - if (noti_data) - g_free(noti_data); - - return NULL; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - } else { - data = g_base64_decode(noti_data, (gsize *)&datalen); - - noti_gv = g_variant_new_from_data(G_VARIANT_TYPE("(v)"), - data, datalen, - TRUE, NULL, NULL); - - g_variant_get(noti_gv, "(v)", &body); - - noti = notification_create(NOTIFICATION_TYPE_NOTI); - notification_ipc_make_noti_from_gvariant(noti, body); - - g_free(data); - g_variant_unref(noti_gv); - } - - if (noti_data) - g_free(noti_data); - - return noti; -} - -bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code) -{ - - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_set_rtc_time_sync - ((AlarmManager *)context.proxy, time->year, time->month, time->day, - time->hour, time->min, time->sec, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_rtc_time() failed. return_code[%d]", return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_delete_sync - ((AlarmManager *)context.proxy, alarm_id, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_sync() failed. alarm_id[%d], return_code[%d]", - (int)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_delete_all(alarm_context_t context, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_delete_all_sync - ((AlarmManager *)context.proxy, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_delete_all_sync() failed. return_code[%d]", return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids, - alarm_id_t *alarm_id, int *num_of_ids, - int *error_code) -{ - GError *error = NULL; - GVariant *alarm_array = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_get_list_of_ids_sync((AlarmManager *)context.proxy, - maxnum_of_ids, &alarm_array, - num_of_ids, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", - *(int *)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } else { - GVariantIter *iter = NULL; - gint i = 0; - g_variant_get(alarm_array, "ai", &iter); - while (g_variant_iter_loop(iter, "i", &alarm_id[i])) { - ALARM_MGR_LOG_PRINT("alarm_id (%d)", alarm_id[i]); - i++; - } - g_variant_iter_free(iter); - *num_of_ids = i; - g_variant_unref(alarm_array); - } - - return true; -} - -bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, - int *error_code) -{ - GError *error = NULL; - gint return_code = 0; - - if (!alarm_manager_call_alarm_get_number_of_ids_sync((AlarmManager *)context.proxy, num_of_ids, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_get_number_of_ids_sync() failed by dbus. return_code[%d]", - return_code); - - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, - alarm_info_t *alarm_info, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_get_info_sync((AlarmManager *)context.proxy, - alarm_id, &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, - (gint *)&alarm_info->mode.repeat, - &alarm_info->alarm_type, &alarm_info->reserved_info, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_get_info_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", - (int)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_get_next_duetime(alarm_context_t context, - alarm_id_t alarm_id, time_t* duetime, - int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_get_next_duetime_sync((AlarmManager *)context.proxy, - alarm_id, (gint *)duetime, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_get_next_duetime_sync() failed by dbus. alarm_id[%d], return_code[%d]\n", - (int)alarm_id, return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_get_all_info(alarm_context_t context, char **db_path, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_get_all_info_sync((AlarmManager *)context.proxy, db_path, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_all_info_sync() failed by dbus. return_code[%d]", return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != ALARMMGR_RESULT_SUCCESS) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_set_time(alarm_context_t context, int new_time, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_set_time_sync((AlarmManager *)context.proxy, new_time, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_time_sync() failed by dbus. return_code[%d]", return_code); - if (error) { - ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message); - g_error_free(error); - } - if (error_code) - *error_code = ERR_ALARM_SYSTEM_FAIL; - return false; - } - - if (return_code != ALARMMGR_RESULT_SUCCESS) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -static void _alarm_set_time_cb(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - int return_code = 0; - GError *error = NULL; - alarm_set_time_data_t *func_data = (alarm_set_time_data_t *)user_data; - - if (!alarm_manager_call_alarm_set_time_finish((AlarmManager *)func_data->proxy, - (gint *)&return_code, - res, &error)) { - if (error) { - ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message); - g_error_free(error); - } - return_code = ERR_ALARM_SYSTEM_FAIL; - } - - if (func_data->callback != NULL) - func_data->callback(return_code, func_data->user_data); - - g_free(func_data); -} - -bool _send_alarm_set_time_async(alarm_context_t context, int new_time, alarm_set_time_cb_t result_cb, void *user_data) -{ - alarm_set_time_data_t *func_data; - - func_data = g_try_new0(alarm_set_time_data_t, 1); - - if (func_data == NULL) - return false; - - func_data->callback = result_cb; - func_data->user_data = user_data; - func_data->proxy = context.proxy; - - alarm_manager_call_alarm_set_time((AlarmManager *)context.proxy, new_time, - NULL, _alarm_set_time_cb, func_data); - - return true; -} - -bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_set_time_with_propagation_delay_sync((AlarmManager *)context.proxy, new_sec, new_nsec, req_sec, req_nsec, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_time_with_propagation_delay_sync() failed by dbus. return_code[%d]", return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != ALARMMGR_RESULT_SUCCESS) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -static void _alarm_set_time_with_delay_cb(GObject *source_object, GAsyncResult *res, - gpointer user_data) -{ - int return_code = 0; - GError *error = NULL; - alarm_set_time_data_t *func_data = (alarm_set_time_data_t *)user_data; - - if (!alarm_manager_call_alarm_set_time_with_propagation_delay_finish((AlarmManager *)func_data->proxy, - (gint *)&return_code, - res, &error)) { - if (error) { - ALARM_MGR_EXCEPTION_PRINT("dbus error message: %s", error->message); - g_error_free(error); - } - return_code = ERR_ALARM_SYSTEM_FAIL; - } - - if (func_data->callback != NULL) - func_data->callback(return_code, func_data->user_data); - - g_free(func_data); -} - -bool _send_alarm_set_time_with_propagation_delay_async(alarm_context_t context, unsigned int new_sec, unsigned int new_nsec, unsigned int req_sec, unsigned int req_nsec, alarm_set_time_cb_t result_cb, void *user_data) -{ - alarm_set_time_data_t *func_data; - - func_data = g_try_new0(alarm_set_time_data_t, 1); - - if (func_data == NULL) - return false; - - func_data->callback = result_cb; - func_data->user_data = user_data; - func_data->proxy = context.proxy; - - alarm_manager_call_alarm_set_time_with_propagation_delay((AlarmManager *)context.proxy, - new_sec, new_nsec, req_sec, req_nsec, - NULL, _alarm_set_time_with_delay_cb, func_data); - - return true; -} - -bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_set_timezone_sync((AlarmManager *)context.proxy, tzpath_str, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_timezone_sync() failed by dbus. return_code[%d]", return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != ALARMMGR_RESULT_SUCCESS) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_set_global(alarm_context_t context, const alarm_id_t alarm_id, bool global, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_set_global_sync((AlarmManager *)context.proxy, alarm_id, global, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_set_global_sync() failed by dbus. return_code[%d]", return_code); - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != ALARMMGR_RESULT_SUCCESS) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} - -bool _send_alarm_get_global(alarm_context_t context, const alarm_id_t alarm_id, bool *global, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - gboolean _global; - - if (!alarm_manager_call_alarm_get_global_sync((AlarmManager *)context.proxy, alarm_id, &_global, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT("alarm_manager_call_alarm_get_global_sync() failed by dbus. return_code[%d]", return_code); - if (error_code) { - if (error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - if (error) { - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - g_error_free(error); - } - return false; - } - - if (return_code != ALARMMGR_RESULT_SUCCESS) { - if (error_code) - *error_code = return_code; - return false; - } - - *global = (bool)_global; - return true; -} - -bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id, - alarm_info_t *alarm_info, int update_flag, int *error_code) -{ - GError *error = NULL; - int return_code = 0; - - if (!alarm_manager_call_alarm_update_sync((AlarmManager *)context.proxy, - alarm_id, - 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.interval, - alarm_info->mode.repeat, - alarm_info->alarm_type, - alarm_info->reserved_info, - update_flag, - &return_code, - NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_update_sync()failed. alarm_id[%d], return_code[%d]", - (int)alarm_id, return_code); - ALARM_MGR_EXCEPTION_PRINT("error->message is %s(%d)", error->message, error->code); - if (error_code) { - if (error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - g_error_free(error); - return false; - } - - if (return_code != 0) { - if (error_code) - *error_code = return_code; - return false; - } - - return true; -} diff --git a/lib/alarm-lib.c b/lib/alarm-lib.c index 4236415..f708591 100755 --- a/lib/alarm-lib.c +++ b/lib/alarm-lib.c @@ -27,7 +27,6 @@ #include "alarm.h" #include "alarm-internal.h" -#include "alarm-mgr-stub.h" #include <bundle.h> #include <appsvc.h> #include <aul.h> @@ -35,8 +34,6 @@ #include <pkgmgr-info.h> #include <notification.h> #include <tzplatform_config.h> -#include <cert-svc/ccert.h> -#include <cert-svc/cinstance.h> #ifndef EXPORT_API #define EXPORT_API __attribute__ ((visibility("default"))) @@ -1141,6 +1138,9 @@ EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time, if (!_send_alarm_create_appsvc(alarm_context, &alarm_info, alarm_id, b, &error_code)) return error_code; + + ALARM_MGR_LOG_PRINT("alarm_id : %d", *alarm_id); + return ALARMMGR_RESULT_SUCCESS; } @@ -1361,12 +1361,10 @@ EXPORT_API int alarmmgr_remove_all(void) EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param) { SECURE_LOGD("Enter"); - GError *error = NULL; - GVariant *alarm_array = NULL; int return_code = 0; int maxnum_of_ids = 0; int num_of_ids = 0; - alarm_id_t alarm_id = -1; + alarm_id_t alarm_id; int ret = 0; GVariantIter *iter = NULL; @@ -1379,62 +1377,20 @@ EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param) return ret; } - 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, &maxnum_of_ids, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_get_number_of_ids_sync() is failed by dbus. return_code[%d], err message[%s] err code[%d]", - return_code, error->message, error->code); - if (error->code == G_DBUS_ERROR_ACCESS_DENIED) - ret = ERR_ALARM_NO_PERMISSION; - else - ret = ERR_ALARM_SYSTEM_FAIL; - g_error_free(error); - return ret; - } - - 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); + if (!_send_alarm_get_number_of_ids(alarm_context, &maxnum_of_ids, &return_code)) return return_code; - } else { - ALARM_MGR_LOG_PRINT("maxnum_of_ids[%d]", maxnum_of_ids); - } - 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, maxnum_of_ids, &alarm_array, &num_of_ids, &return_code, NULL, &error)) { - ALARM_MGR_EXCEPTION_PRINT( - "alarm_manager_call_alarm_get_list_of_ids_sync() failed by dbus. num_of_ids[%d], return_code[%d]. err message[%s] err code[%d]", num_of_ids, return_code, error->message, error->code); - if (error->code == G_DBUS_ERROR_ACCESS_DENIED) - ret = ERR_ALARM_NO_PERMISSION; - else - ret = ERR_ALARM_SYSTEM_FAIL; - g_error_free(error); - return ret; - } + ALARM_MGR_LOG_PRINT("maxnum_of_ids[%d]", maxnum_of_ids); - if (return_code != ALARMMGR_RESULT_SUCCESS) + if (!_send_alarm_get_list_of_ids(alarm_context, maxnum_of_ids, &iter, &num_of_ids, &return_code)) return return_code; - if (error != NULL) { - ALARM_MGR_EXCEPTION_PRINT("Alarm server is not ready dbus. error message %s.", error->message); - return ERR_ALARM_SYSTEM_FAIL; - } - - if (alarm_array == NULL) { - ALARM_MGR_EXCEPTION_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); + (*fn)(alarm_id, user_param); } g_variant_iter_free(iter); - g_variant_unref(alarm_array); - SECURE_LOGD("Leave"); return ALARMMGR_RESULT_SUCCESS; } @@ -1474,28 +1430,6 @@ int alarmmgr_get_number_of_ids(int *num_of_ids) return ALARMMGR_RESULT_SUCCESS; } -int alarmmgr_get_list_of_ids(int maxnum_of_ids, alarm_id_t *alarm_id, - int *num_of_ids) -{ - int error_code; - 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 (maxnum_of_ids == 0) { - *num_of_ids = 0; - return ALARMMGR_RESULT_SUCCESS; - } - - if (!_send_alarm_get_list_of_ids - (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; @@ -1716,7 +1650,7 @@ EXPORT_API int alarmmgr_set_global(const alarm_id_t alarm_id, bool global) { int error_code; - ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_global() is called."); + ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_global(%d) is called.", alarm_id); if (__sub_init() < 0) return ERR_ALARM_SYSTEM_FAIL; diff --git a/packaging/alarm-manager.spec b/packaging/alarm-manager.spec index b702839..89784e9 100755 --- a/packaging/alarm-manager.spec +++ b/packaging/alarm-manager.spec @@ -43,7 +43,7 @@ BuildRequires: lcov BuildRequires: zip %endif -%define gtests 1 +%define gtests 0 %if 0%{?gtests:1} BuildRequires: pkgconfig(gmock) @@ -261,8 +261,10 @@ fi %files -n alarm-config-service-restricted %{_datadir}/alarm-manager/alarm-config-service-restricted -%files unittests -%{_bindir}/gtest* +#%if 0%{?gtests:1} +#%files unittests +#%{_bindir}/gtest* +#%endif ################################################# # gcov diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index eb2c121..fd55d4b 100755 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -3,9 +3,6 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/server) AUX_SOURCE_DIRECTORY(./ SRCS) -SET(SRCS ${SRCS} ${CMAKE_SOURCE_DIR}/common/alarm-mgr-stub.c) -SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/alarm-mgr-stub.c - PROPERTIES GENERATED TRUE) PKG_CHECK_MODULES(svr_pkgs REQUIRED glib-2.0 dlog aul bundle appsvc pkgmgr-info pkgmgr vconf gio-2.0 gio-unix-2.0 capi-system-device libtzplatform-config libsystemd-login @@ -24,7 +21,6 @@ LINK_DIRECTORIES(${svr_pkgs_LIBRARY_DIRS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpie") ADD_EXECUTABLE(${SERVER} ${SRCS}) -ADD_DEPENDENCIES(${SERVER} GENERATED_DBUS_CODE) TARGET_LINK_LIBRARIES(${SERVER} ${svr_pkgs_LIBRARIES} rt) INSTALL(TARGETS ${SERVER} DESTINATION ${BIN_INSTALL_DIR}) diff --git a/server/alarm-manager-dbus.c b/server/alarm-manager-dbus.c new file mode 100755 index 0000000..3dadc6c --- /dev/null +++ b/server/alarm-manager-dbus.c @@ -0,0 +1,731 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define _GNU_SOURCE +#include <stdlib.h> +#include <stdint.h> +#include <stdio.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <sys/un.h> + +#include "alarm.h" +#include "alarm-internal.h" +#include "alarm-manager-dbus.h" +#include "alarm-manager-util.h" + +/* GDBus Declaration */ +#define ALARM_MGR_DBUS_PATH "/org/tizen/alarm/manager" +#define ALARM_MGR_DBUS_NAME "org.tizen.alarm.manager" + +extern __alarm_server_context_t alarm_context; +extern GSList *g_expired_alarm_list; + +static GDBusNodeInfo *introspection_data; +static const gchar introspection_xml[] = +"<node name='/org/tizen/alarm/manager'>" +" <interface name='org.tizen.alarm.manager'>" +" <method name='alarm_create_periodic'>" +" <arg type='s' name='app_service_name' direction='in' />" +" <arg type='s' name='app_service_name_mod' direction='in' />" +" <arg type='i' name='interval' direction='in' />" +" <arg type='i' name='is_ref' direction='in' />" +" <arg type='i' name='method' direction='in' />" +" <arg type='i' name='alarm_id' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_create'>" +" <arg type='s' name='app_service_name' direction='in' />" +" <arg type='s' name='app_service_name_mod' direction='in' />" +" <arg type='i' name='alarm_info_start_year' direction='in' />" +" <arg type='i' name='alarm_info_start_month' direction='in' />" +" <arg type='i' name='alarm_info_start_day' direction='in' />" +" <arg type='i' name='alarm_info_start_hour' direction='in' />" +" <arg type='i' name='alarm_info_start_min' direction='in' />" +" <arg type='i' name='alarm_info_start_sec' direction='in' />" +" <arg type='i' name='alarm_info_msec' direction='in' />" +" <arg type='i' name='alarm_info_end_year' direction='in' />" +" <arg type='i' name='alarm_info_end_month' direction='in' />" +" <arg type='i' name='alarm_info_end_day' direction='in' />" +" <arg type='i' name='alarm_info_mode_day_of_week' direction='in' />" +" <arg type='i' name='alarm_info_mode_repeat' direction='in' />" +" <arg type='i' name='alarm_info_alarm_type' direction='in' />" +" <arg type='i' name='alarm_info_reserved_info' direction='in' />" +" <arg type='s' name='alarm_info_reserved_service_name' direction='in' />" +" <arg type='s' name='alarm_info_reserved_service_name_mod' direction='in' />" +" <arg type='i' name='alarm_id' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_create_appsvc'>" +" <arg type='i' name='alarm_info_start_year' direction='in' />" +" <arg type='i' name='alarm_info_start_month' direction='in' />" +" <arg type='i' name='alarm_info_start_day' direction='in' />" +" <arg type='i' name='alarm_info_start_hour' direction='in' />" +" <arg type='i' name='alarm_info_start_min' direction='in' />" +" <arg type='i' name='alarm_info_start_sec' direction='in' />" +" <arg type='i' name='alarm_info_end_year' direction='in' />" +" <arg type='i' name='alarm_info_end_month' direction='in' />" +" <arg type='i' name='alarm_info_end_day' direction='in' />" +" <arg type='i' name='alarm_info_mode_day_of_week' direction='in' />" +" <arg type='i' name='alarm_info_mode_interval' direction='in' />" +" <arg type='i' name='alarm_info_mode_repeat' direction='in' />" +" <arg type='i' name='alarm_info_alarm_type' direction='in' />" +" <arg type='i' name='alarm_info_reserved_info' direction='in' />" +" <arg type='s' name='alarm_info_bundle_data' direction='in' />" +" <arg type='i' name='alarm_id' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_create_noti'>" +" <arg type='i' name='alarm_info_start_year' direction='in' />" +" <arg type='i' name='alarm_info_start_month' direction='in' />" +" <arg type='i' name='alarm_info_start_day' direction='in' />" +" <arg type='i' name='alarm_info_start_hour' direction='in' />" +" <arg type='i' name='alarm_info_start_min' direction='in' />" +" <arg type='i' name='alarm_info_start_sec' direction='in' />" +" <arg type='i' name='alarm_info_end_year' direction='in' />" +" <arg type='i' name='alarm_info_end_month' direction='in' />" +" <arg type='i' name='alarm_info_end_day' direction='in' />" +" <arg type='i' name='alarm_info_mode_day_of_week' direction='in' />" +" <arg type='i' name='alarm_info_mode_interval' direction='in' />" +" <arg type='i' name='alarm_info_mode_repeat' direction='in' />" +" <arg type='i' name='alarm_info_alarm_type' direction='in' />" +" <arg type='i' name='alarm_info_reserved_info' direction='in' />" +" <arg type='s' name='alarm_info_noti_data' direction='in' />" +" <arg type='i' name='alarm_id' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_delete'>" +" <arg type='i' name='alarm_id' direction='in' />" +" <arg type='i' name='alarm_info_return_code' direction='out' />" +" </method>" +" <method name='alarm_delete_all'>" +" <arg type='i' name='alarm_info_return_code' direction='out' />" +" </method>" +" <method name='alarm_update'>" +" <arg type='i' name='alarm_id' direction='in' />" +" <arg type='i' name='alarm_info_start_year' direction='in' />" +" <arg type='i' name='alarm_info_start_month' direction='in' />" +" <arg type='i' name='alarm_info_start_day' direction='in' />" +" <arg type='i' name='alarm_info_start_hour' direction='in' />" +" <arg type='i' name='alarm_info_start_min' direction='in' />" +" <arg type='i' name='alarm_info_start_sec' direction='in' />" +" <arg type='i' name='alarm_info_end_year' direction='in' />" +" <arg type='i' name='alarm_info_end_month' direction='in' />" +" <arg type='i' name='alarm_info_end_day' direction='in' />" +" <arg type='i' name='alarm_info_mode_day_of_week' direction='in' />" +" <arg type='i' name='alarm_info_mode_repeat' direction='in' />" +" <arg type='i' name='alarm_info_alarm_type' direction='in' />" +" <arg type='i' name='alarm_info_reserved_info' direction='in' />" +" <arg type='i' name='update_flag' direction='in' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_get_number_of_ids'>" +" <arg type='i' name='number_of_ids' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_get_list_of_ids'>" +" <arg type='i' name='max_number_of_ids' direction='in' />" +" <arg type='ai' name='alarm_id' direction='out' />" +" <arg type='i' name='number_of_ids' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_get_appsvc_info'>" +" <arg type='i' name='alarm_id' direction='in' />" +" <arg type='s' name='b_data' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_get_noti_info'>" +" <arg type='i' name='alarm_id' direction='in' />" +" <arg type='s' name='noti_data' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_get_info'>" +" <arg type='i' name='alarm_id' direction='in' />" +" <arg type='i' name='alarm_info_start_year' direction='out' />" +" <arg type='i' name='alarm_info_start_month' direction='out' />" +" <arg type='i' name='alarm_info_start_day' direction='out' />" +" <arg type='i' name='alarm_info_start_hour' direction='out' />" +" <arg type='i' name='alarm_info_start_min' direction='out' />" +" <arg type='i' name='alarm_info_start_sec' direction='out' />" +" <arg type='i' name='alarm_info_end_year' direction='out' />" +" <arg type='i' name='alarm_info_end_month' direction='out' />" +" <arg type='i' name='alarm_info_end_day' direction='out' />" +" <arg type='i' name='alarm_info_mode_day_of_week' direction='out' />" +" <arg type='i' name='alarm_info_mode_repeat' direction='out' />" +" <arg type='i' name='alarm_info_alarm_type' direction='out' />" +" <arg type='i' name='alarm_info_reserved_info' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_set_rtc_time'>" +" <arg type='i' name='alarm_info_year' direction='in' />" +" <arg type='i' name='alarm_info_month' direction='in' />" +" <arg type='i' name='alarm_info_day' direction='in' />" +" <arg type='i' name='alarm_info_hour' direction='in' />" +" <arg type='i' name='alarm_info_min' direction='in' />" +" <arg type='i' name='alarm_info_sec' direction='in' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_get_next_duetime'>" +" <arg type='i' name='alarm_id' direction='in' />" +" <arg type='i' name='duetime' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_get_all_info'>" +" <arg type='s' name='db_path' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_set_time'>" +" <arg type='i' name='time' direction='in' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_set_time_with_propagation_delay'>" +" <arg type='u' name='new_sec' direction='in' />" +" <arg type='u' name='new_nsec' direction='in' />" +" <arg type='u' name='req_sec' direction='in' />" +" <arg type='u' name='req_nsec' direction='in' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_set_timezone'>" +" <arg type='s' name='tzpath_str' direction='in' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_set_global'>" +" <arg type='i' name='alarm_id' direction='in' />" +" <arg type='b' name='global' direction='in' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <method name='alarm_get_global'>" +" <arg type='i' name='alarm_id' direction='in' />" +" <arg type='b' name='global' direction='out' />" +" <arg type='i' name='return_code' direction='out' />" +" </method>" +" <signal name='alarm_expired'>" +" <arg type='i' name='alarm_id' />" +" <arg type='s' name='app_service_name' />" +" </signal>" +" </interface>" +"</node>"; + +static gboolean __send_noti_to_session_bus(char *service_name, + alarm_id_t alarm_id, int msec, uid_t uid) +{ + int fd; + int ret; + int len; + struct sockaddr_un saddr; + uint8_t *data; + GVariant *gv; + uint8_t *gv_data; + + fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); + if (fd < 0) + return FALSE; + + saddr.sun_family = AF_UNIX; + snprintf(saddr.sun_path, sizeof(saddr.sun_path), + "/run/alarm_agent/%d", uid); + + ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)); + if (ret < 0) { + ALARM_MGR_EXCEPTION_PRINT("connect failed - (errno %d)", errno); + close(fd); + return FALSE; + } + + gv = g_variant_new("(iis)", alarm_id, msec, service_name); + if (!gv) { + close(fd); + return FALSE; + } + + len = g_variant_get_size(gv); + + gv_data = NULL; + if (len > 0) + gv_data = (uint8_t *)malloc(len); + + if (!gv_data) { + g_variant_unref(gv); + close(fd); + return FALSE; + } + + g_variant_store(gv, gv_data); + g_variant_unref(gv); + + data = (uint8_t *)malloc(len + 4); + if (!data) { + close(fd); + free(gv_data); + return FALSE; + } + + memcpy(data, &len, 4); + memcpy(data + 4, gv_data, len); + free(gv_data); + + if (send(fd, data, len + 4, 0) == -1) { + ALARM_MGR_EXCEPTION_PRINT("sendto() failed (errno %d)", errno); + free(data); + close(fd); + return FALSE; + } + + free(data); + close(fd); + return TRUE; +} + +void _alarm_send_noti_to_application_by_dbus(const char *app_service_name, + alarm_id_t alarm_id, int msec, uid_t uid) +{ + char service_name[MAX_SERVICE_NAME_LEN] = {0,}; + gboolean ret; + + if (app_service_name == NULL || strlen(app_service_name) == 0) { + ALARM_MGR_EXCEPTION_PRINT("This alarm destination is invalid."); + return; + } + + if (_can_skip_expired_cb(alarm_id)) + return; + + strncpy(service_name, app_service_name, sizeof(service_name) - 1); + SECURE_LOGI("[send expired_alarm(alarm_id=%d) to app_service_name(%s)]", + alarm_id, service_name); + + if (uid >= REGULAR_UID_MIN) { + ret = __send_noti_to_session_bus(service_name, alarm_id, msec, uid); + if (ret != TRUE) + ALARM_MGR_EXCEPTION_PRINT("failed to send alarm expired noti for %d, %s", + alarm_id, service_name); + } else { + g_dbus_connection_call(alarm_context.connection, + service_name, + "/org/tizen/alarm/client", + "org.tizen.alarm.client", + "alarm_expired", + g_variant_new("(iis)", alarm_id, msec, service_name), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); + } +} + +static uid_t __get_caller_uid(const char *name) +{ + guint uid; + GVariant *ret; + GError *error = NULL; + + ret = g_dbus_connection_call_sync( + alarm_context.connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "GetConnectionUnixUser", + g_variant_new("(s)", name), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (!ret) { + ALARM_MGR_EXCEPTION_PRINT("failed to get caller uid"); + if (error) { + ALARM_MGR_EXCEPTION_PRINT("dbus error message : %s", error->message); + g_error_free(error); + } + return -1; + } + g_variant_get(ret, "(u)", &uid); + g_variant_unref(ret); + + return uid; +} + +static pid_t __get_caller_pid(const char *name) +{ + guint pid; + GVariant *ret; + GError *error = NULL; + + ret = g_dbus_connection_call_sync(alarm_context.connection, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + "GetConnectionUnixProcessID", + g_variant_new("(s)", name), + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (!ret) { + ALARM_MGR_EXCEPTION_PRINT("failed to get caller pid"); + if (error) { + ALARM_MGR_EXCEPTION_PRINT("dbus error message : %s", error->message); + g_error_free(error); + } + return -1; + } + g_variant_get(ret, "(u)", &pid); + g_variant_unref(ret); + + return pid; +} + +int _display_lock_state(char *state, char *flag, unsigned int timeout) +{ + GDBusMessage *msg = NULL; + GDBusMessage *reply = NULL; + GVariant *body = 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, NULL); + if (!reply) { + ALARM_MGR_EXCEPTION_PRINT("No reply.\ + g_dbus_connection_send_message_with_reply_sync() is failed."); + 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_LOG_PRINT("Lock LCD OFF is successfully done"); + } + } + } + + g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL); + g_object_unref(msg); + if (reply) + g_object_unref(reply); + + return ret; +} + +int _display_unlock_state(char *state, char *flag) +{ + GDBusMessage *msg = NULL; + GDBusMessage *reply = NULL; + GVariant *body = 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, NULL); + if (!reply) { + ALARM_MGR_EXCEPTION_PRINT("No reply.\ + g_dbus_connection_send_message_with_reply_sync() is failed."); + 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_LOG_PRINT("Unlock LCD OFF is successfully done"); + } + } + } + + g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL); + g_object_unref(msg); + if (reply) + g_object_unref(reply); + + return ret; +} + +static void handle_method_call(GDBusConnection *connection, + const gchar *sender, const gchar *object_path, + const gchar *interface_name, const gchar *method_name, + GVariant *parameters, GDBusMethodInvocation *invoc, + gpointer user_data) +{ + int ret; + int num_of_alarm; + int alarm_id; + const char *name = g_dbus_method_invocation_get_sender(invoc); + uid_t uid = __get_caller_uid(name); + pid_t pid = __get_caller_pid(name); + + if (g_strcmp0(method_name, "alarm_create_periodic") == 0) { + ret = alarm_manager_alarm_create_periodic(parameters, uid, pid, &alarm_id); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, ret)); + } else if (g_strcmp0(method_name, "alarm_create") == 0) { + ret = alarm_manager_alarm_create(parameters, uid, pid, &alarm_id); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, ret)); + } else if (g_strcmp0(method_name, "alarm_create_appsvc") == 0) { + ret = alarm_manager_alarm_create_appsvc(parameters, uid, pid, &alarm_id); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, ret)); + } else if (g_strcmp0(method_name, "alarm_create_noti") == 0) { + const char *notification_priv = "http://tizen.org/privilege/notification"; + ret = _cynara_check(invoc, notification_priv, pid); + if (ret == ALARMMGR_RESULT_SUCCESS) { + ret = alarm_manager_alarm_create_noti(parameters, uid, pid, &alarm_id); + } + g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, ret)); + } else if (g_strcmp0(method_name, "alarm_delete") == 0) { + ret = alarm_manager_alarm_delete(parameters, uid, pid); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); + } else if (g_strcmp0(method_name, "alarm_delete_all") == 0) { + ret = alarm_manager_alarm_delete_all(parameters, uid, pid); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); + } else if (g_strcmp0(method_name, "alarm_update") == 0) { + ret = alarm_manager_alarm_update(parameters, uid, pid); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); + } else if (g_strcmp0(method_name, "alarm_get_number_of_ids") == 0) { + ret = alarm_manager_alarm_get_number_of_ids(uid, pid, &num_of_alarm); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_alarm, ret)); + } else if (g_strcmp0(method_name, "alarm_get_list_of_ids") == 0) { + GVariant *arr = NULL; + + ret = alarm_manager_alarm_get_list_of_ids(parameters, uid, pid, &arr, &num_of_alarm); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", arr, num_of_alarm, ret)); + } else if (g_strcmp0(method_name, "alarm_get_appsvc_info") == 0) { + gchar *b_data = NULL; + + ret = alarm_manager_alarm_get_appsvc_info(parameters, uid, &b_data); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, ret)); + if (b_data) + free(b_data); + } else if (g_strcmp0(method_name, "alarm_get_noti_info") == 0) { + gchar *noti_data = NULL; + + ret = alarm_manager_alarm_get_noti_info(parameters, uid, ¬i_data); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", noti_data, ret)); + + if (noti_data) + free(noti_data); + } else if (g_strcmp0(method_name, "alarm_get_info") == 0) { + alarm_info_t alarm_info = { 0, }; + + ret = alarm_manager_alarm_get_info(parameters, uid, &alarm_info); + + 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, ret)); + } else if (g_strcmp0(method_name, "alarm_get_next_duetime") == 0) { + int duetime; + ret = alarm_manager_alarm_get_next_duetime(parameters, uid, &duetime); + + g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, ret)); + } else if (g_strcmp0(method_name, "alarm_get_all_info") == 0) { + char *db_path = NULL; + + ret = alarm_manager_alarm_get_all_info(uid, &db_path); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, ret)); + + if (db_path) + free(db_path); + } else if (g_strcmp0(method_name, "alarm_set_rtc_time") == 0) { + ret = alarm_manager_alarm_set_rtc_time(parameters); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); + } else if (g_strcmp0(method_name, "alarm_set_time") == 0) { + ret = alarm_manager_alarm_set_time(parameters); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); + } else if (g_strcmp0(method_name, "alarm_set_time_with_propagation_delay") == 0) { + ret = alarm_manager_alarm_set_time_with_propagation_delay(parameters); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); + } else if (g_strcmp0(method_name, "alarm_set_timezone") == 0) { + ret = alarm_manager_alarm_set_timezone(parameters); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); + } else if (g_strcmp0(method_name, "alarm_set_global") == 0) { + ret = alarm_manager_alarm_set_global(parameters, uid); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); + } else if (g_strcmp0(method_name, "alarm_get_global") == 0) { + gboolean global; + + ret = alarm_manager_alarm_get_global(parameters, &global); + g_dbus_method_invocation_return_value(invoc, g_variant_new("(bi)", global, ret)); + } +} + +static const GDBusInterfaceVTable interface_vtable = { + handle_method_call, + NULL, + NULL +}; + +static void __on_bus_name_acquired(GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + ALARM_MGR_LOG_PRINT("bus acquired(%s)", name); + + guint reg_id = 0; + GError *error = NULL; + + reg_id = g_dbus_connection_register_object(connection, + ALARM_MGR_DBUS_PATH, + introspection_data->interfaces[0], + &interface_vtable, + NULL, NULL, &error); + if (reg_id == 0) { + ALARM_MGR_EXCEPTION_PRINT("g_dbus_connection_register_object error(%s)", error->message); + g_error_free(error); + } +} + +static 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) +{ + GSList *entry = NULL; + __expired_alarm_t *expire_info = NULL; + char *service_name = NULL; + + /* 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) { + 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); + + 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_by_dbus( + expire_info->service_name, + expire_info->alarm_id, + 0, + expire_info->uid); + g_expired_alarm_list = + g_slist_remove(g_expired_alarm_list, entry->data); + g_free(expire_info); + } + } + } + } +} + +bool _initialize_dbus(void) +{ + GDBusConnection *connection = NULL; + GError *error = NULL; + guint subsc_id; + guint owner_id; + ALARM_MGR_LOG_PRINT("__initialize_dbus Enter"); + + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (connection == NULL) { + ALARM_MGR_EXCEPTION_PRINT("g_bus_get_sync() is failed"); + if (error) { + ALARM_MGR_EXCEPTION_PRINT("dbus error message : %s", error->message); + g_error_free(error); + } + return false; + } + + 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(connection); + return false; + } + + introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &error); + if (!introspection_data) { + ALARM_MGR_EXCEPTION_PRINT("g_dbus_node_info_new_for_xml error(%s)", error->message); + g_object_unref(connection); + g_error_free(error); + return false; + } + + owner_id = g_bus_own_name_on_connection(connection, + ALARM_MGR_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, + __on_bus_name_acquired, NULL, NULL, NULL); + + if (owner_id == 0) { + ALARM_MGR_EXCEPTION_PRINT("Acquiring the own name is failed."); + g_dbus_node_info_unref(introspection_data); + g_object_unref(connection); + return false; + } + + alarm_context.connection = connection; + + return true; +} diff --git a/server/alarm-manager-dbus.h b/server/alarm-manager-dbus.h new file mode 100755 index 0000000..eb34c17 --- /dev/null +++ b/server/alarm-manager-dbus.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include <glib.h> +#include <gio/gio.h> + +/* 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" + +bool _initialize_dbus(void); + +void _alarm_send_noti_to_application_by_dbus(const char *app_service_name, + alarm_id_t alarm_id, int msec, uid_t uid); + +int _display_lock_state(char *state, char *flag, unsigned int timeout); +int _display_unlock_state(char *state, char *flag); + +#ifdef __cplusplus +} +#endif + diff --git a/server/alarm-manager-util.c b/server/alarm-manager-util.c index d4e6aa0..08da094 100755 --- a/server/alarm-manager-util.c +++ b/server/alarm-manager-util.c @@ -178,6 +178,19 @@ cynara_out: return ret; } +int _get_pid_from_appid(const char *app_id, uid_t uid) +{ + int pid; + pid = aul_app_get_pid_for_uid(app_id, uid); + if (pid < 0) { + ALARM_MGR_EXCEPTION_PRINT("aul_app_get_pid_for_uid() is failed. appid %s may not be app. uid : [%d]", app_id, uid); + return 0; + } + + ALARM_MGR_LOG_PRINT("app_id:%s [pid:%d]", app_id, pid); + return pid; +} + char *_get_pkgid_by_appid(const char *app_id, uid_t uid) { pkgmgrinfo_pkginfo_h handle; diff --git a/server/alarm-manager-util.h b/server/alarm-manager-util.h index 6b87dbd..5586a18 100755 --- a/server/alarm-manager-util.h +++ b/server/alarm-manager-util.h @@ -37,6 +37,7 @@ bool _is_app(const char *appid, uid_t uid); int _compare_api_version(int *result, int pid, uid_t uid); bool _permit_by_config(pkgmgrinfo_appinfo_h handle, uid_t uid); bool _is_permitted(const char *app_id, int alarm_type, uid_t uid); +int _get_pid_from_appid(const char *app_id, uid_t uid); #ifdef __cplusplus } diff --git a/server/alarm-manager.c b/server/alarm-manager.c index d9a7366..20be386 100755 --- a/server/alarm-manager.c +++ b/server/alarm-manager.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,17 @@ #include <stdlib.h> #include <time.h> #include <signal.h> -#include <sys/socket.h> #include <sys/un.h> -#include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> #include <unistd.h> #include <sys/timerfd.h> #include <poll.h> #include <stdint.h> +#include <errno.h> +#include <linux/rtc.h> +#include <sys/ioctl.h> +#include <fcntl.h> #include <tzplatform_config.h> #include <aul.h> @@ -35,7 +37,6 @@ #include <bundle_internal.h> #include <vconf.h> #include <vconf-keys.h> -#include <dlfcn.h> #include <package-manager.h> #include <device/display.h> #include <systemd/sd-login.h> @@ -44,42 +45,25 @@ #include <notification_ipc.h> #include <notification_internal.h> -#include <glib.h> -#if !GLIB_CHECK_VERSION(2, 31, 0) -#include <glib/gmacros.h> -#endif - -#include "gio/gio.h" #include "alarm.h" #include "alarm-internal.h" #include "alarm-manager-db.h" #include "alarm-manager-util.h" -#include "alarm-mgr-stub.h" - +#include "alarm-manager-dbus.h" -#define SIG_TIMER 0x32 -#define WAKEUP_ALARM_APP_ID "org.tizen.alarm.ALARM" -/* alarm ui application's alarm's dbus_service name instead of 21 - * (alarm application's app_id) value */ +#if !GLIB_CHECK_VERSION(2, 31, 0) +#include <glib/gmacros.h> +#endif -__alarm_server_context_t alarm_context; -bool g_dummy_timer_is_set = FALSE; +#define BILLION 1000000000 /* for calculating nano seconds */ -GSList *g_scheduled_alarm_list; -GSList *g_expired_alarm_list; -GSList *g_disabled_alarm_list; +/* link path for timezone info */ +#define TIMEZONE_INFO_LINK_PATH tzplatform_mkpath(TZ_SYS_ETC, "localtime") #ifndef RTC_WKALM_BOOT_SET #define RTC_WKALM_BOOT_SET _IOW('p', 0x80, struct rtc_wkalrm) #endif -#include <errno.h> -#include <linux/rtc.h> -#include <sys/ioctl.h> -#include <fcntl.h> - -static const char default_rtc[] = "/dev/rtc"; -static int gfd = -1; #define _APPFW_FEATURE_WAKEUP_USING_RTC (_get_profile() != PROFILE_TV) #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG @@ -92,28 +76,17 @@ static int log_index = 0; static int log_fd = 0; #endif -/* 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/rtc"; +static int gfd = -1; -/* link path for timezone info */ -#define TIMEZONE_INFO_LINK_PATH tzplatform_mkpath(TZ_SYS_ETC, "localtime") +__alarm_server_context_t alarm_context; +bool g_dummy_timer_is_set = FALSE; -/* GDBus Declaration */ -#define ALARM_MGR_DBUS_PATH "/org/tizen/alarm/manager" -#define ALARM_MGR_DBUS_NAME "org.tizen.alarm.manager" -static AlarmManager *interface; +GSList *g_scheduled_alarm_list; +GSList *g_expired_alarm_list; +GSList *g_disabled_alarm_list; bool is_time_changed = false; /* for calculating next duetime */ - -#define BILLION 1000000000 /* for calculating nano seconds */ static time_t periodic_alarm_standard_time = 0; static long __get_proper_interval(long interval, int alarm_type); @@ -137,7 +110,6 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id static bool __alarm_delete(uid_t uid, alarm_id_t alarm_id, int *error_code); static bool __alarm_update(uid_t uid, int pid, alarm_id_t alarm_id, alarm_info_t *alarm_info, int update_flag, int *error_code); -static void __alarm_send_noti_to_application(const char *app_service_name, alarm_id_t alarm_id, int msec, uid_t uid); static void __alarm_expired(); static gboolean __alarm_handler_idle(gpointer user_data); static void __on_system_time_external_changed(keynode_t *node, void *data); @@ -146,10 +118,7 @@ static void __initialize_alarm_list(); static void __initialize_scheduled_alarm_list(); static bool __initialize_noti(); -static bool __initialize_dbus(); void _release_alarm_info_t(__alarm_info_t *entry); -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, int size, bool *is_app, uid_t uid); static notification_h __get_notification(guchar *data, int datalen); @@ -158,9 +127,6 @@ static void __initialize_module_log(void); static bool __save_module_log(const char *tag, const char *messgae); #endif -int __display_lock_state(char *state, char *flag, unsigned int timeout); -int __display_unlock_state(char *state, char *flag); - int __set_time(time_t _time); struct running_info_t { @@ -182,6 +148,11 @@ typedef struct { char *unique_name; } appid_cache_t; +struct alarm_manager_dbus_map { + const char *signal_name; + GCallback func; +}; + static bool __get_cached_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid) { appid_cache_t *data = NULL; @@ -206,6 +177,7 @@ gboolean __hash_table_remove_cb(gpointer key, gpointer value, gpointer user_data ALARM_MGR_LOG_PRINT("Remove cached data of [%s]", target_name); return true; } + return false; } @@ -782,14 +754,13 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id __alarm_info->app_unique_name = strdup(app_name); /* caller */ - if (caller_is_app) { + if (caller_is_app) __alarm_info->caller_pkgid = _get_pkgid_by_appid(app_name, uid); - } /* callee */ b = bundle_decode((bundle_raw *)bundle_data, strlen(bundle_data)); callee_appid = appsvc_get_appid(b); - __alarm_info->caller_pkgid = _get_pkgid_by_appid(callee_appid, uid); + __alarm_info->callee_pkgid = _get_pkgid_by_appid(callee_appid, uid); if (b && caller_is_app) { __set_caller_info(b, pid, uid, app_name, @@ -897,9 +868,8 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id, uid_t } /* Get caller_appid to get caller's package id. There is no callee. */ - if (caller_is_app) { + if (caller_is_app) __alarm_info->caller_pkgid = _get_pkgid_by_appid(unique_name, uid); - } SECURE_LOGD("caller_pkgid = %s, callee_pkgid = null", __alarm_info->caller_pkgid); @@ -1231,7 +1201,7 @@ static bool __alarm_delete(uid_t uid, alarm_id_t alarm_id, int *error_code) return true; } -static bool __can_skip_expired_cb(alarm_id_t alarm_id) +bool _can_skip_expired_cb(alarm_id_t alarm_id) { GSList *gs_iter = NULL; __alarm_info_t *entry = NULL; @@ -1273,177 +1243,6 @@ static bool __can_skip_expired_cb(alarm_id_t alarm_id) return false; } -static gboolean __send_noti_to_session_bus(char *service_name, - alarm_id_t alarm_id, int msec, uid_t uid) -{ - int fd; - int ret; - int len; - struct sockaddr_un saddr; - uint8_t *data; - GVariant *gv; - uint8_t *gv_data; - - fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); - if (fd < 0) - return FALSE; - - saddr.sun_family = AF_UNIX; - snprintf(saddr.sun_path, sizeof(saddr.sun_path), - "/run/alarm_agent/%d", uid); - - ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)); - if (ret < 0) { - ALARM_MGR_EXCEPTION_PRINT("connect failed - (errno %d)", errno); - close(fd); - return FALSE; - } - - gv = g_variant_new("(iis)", alarm_id, msec, service_name); - if (!gv) { - close(fd); - return FALSE; - } - - len = g_variant_get_size(gv); - - gv_data = NULL; - if (len > 0) - gv_data = (uint8_t *)malloc(len); - - if (!gv_data) { - g_variant_unref(gv); - close(fd); - return FALSE; - } - - g_variant_store(gv, gv_data); - g_variant_unref(gv); - - data = (uint8_t *)malloc(len + 4); - if (!data) { - close(fd); - free(gv_data); - return FALSE; - } - - memcpy(data, &len, 4); - memcpy(data + 4, gv_data, len); - free(gv_data); - - if (send(fd, data, len + 4, 0) == -1) { - ALARM_MGR_EXCEPTION_PRINT("sendto() failed (errno %d)", errno); - free(data); - close(fd); - return FALSE; - } - - free(data); - close(fd); - return TRUE; -} - -static void __alarm_send_noti_to_application(const char *app_service_name, - alarm_id_t alarm_id, int msec, uid_t uid) -{ - char service_name[MAX_SERVICE_NAME_LEN] = {0,}; - gboolean ret; - - if (app_service_name == NULL || strlen(app_service_name) == 0) { - ALARM_MGR_EXCEPTION_PRINT("This alarm destination is invalid."); - return; - } - - if (__can_skip_expired_cb(alarm_id)) - return; - - strncpy(service_name, app_service_name, sizeof(service_name) - 1); - SECURE_LOGI("[alarm server][send expired_alarm(alarm_id=%d) to app_service_name(%s)]", alarm_id, service_name); - - if (uid >= REGULAR_UID_MIN) { - ret = __send_noti_to_session_bus(service_name, alarm_id, msec, uid); - if (ret != TRUE) - ALARM_MGR_EXCEPTION_PRINT("failed to send alarm expired noti for %d, %s", - alarm_id, service_name); - } else { - g_dbus_connection_call(alarm_context.connection, - service_name, - "/org/tizen/alarm/client", - "org.tizen.alarm.client", - "alarm_expired", - g_variant_new("(iis)", alarm_id, msec, service_name), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL, - NULL); - } -} - -static uid_t __get_caller_uid(const char *name) -{ - guint uid; - GVariant *ret; - GError *error = NULL; - - ret = g_dbus_connection_call_sync( - alarm_context.connection, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "GetConnectionUnixUser", - g_variant_new("(s)", name), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - if (!ret) { - ALARM_MGR_EXCEPTION_PRINT("failed to get caller uid"); - if (error) { - ALARM_MGR_EXCEPTION_PRINT("dbus error message : %s", error->message); - g_error_free(error); - } - return -1; - } - g_variant_get(ret, "(u)", &uid); - g_variant_unref(ret); - - return uid; -} - -static pid_t __get_caller_pid(const char *name) -{ - guint pid; - GVariant *ret; - GError *error = NULL; - - ret = g_dbus_connection_call_sync(alarm_context.connection, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "GetConnectionUnixProcessID", - g_variant_new("(s)", name), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - if (!ret) { - ALARM_MGR_EXCEPTION_PRINT("failed to get caller pid"); - if (error) { - ALARM_MGR_EXCEPTION_PRINT("dbus error message : %s", error->message); - g_error_free(error); - } - return -1; - } - g_variant_get(ret, "(u)", &pid); - g_variant_unref(ret); - - return pid; -} - static int __find_login_user(uid_t *uid) { uid_t *uids; @@ -1467,6 +1266,7 @@ static int __find_login_user(uid_t *uid) } } } + free(uids); free(state); return -1; @@ -1600,7 +1400,8 @@ static void __alarm_expired() alarm = (__scheduled_alarm_t *)iter->data; alarm_id = alarm->alarm_id; __alarm_info = alarm->__alarm_info; - app_pid = __alarm_info->pid; + app_pid = _get_pid_from_appid(__alarm_info->app_unique_name, + __alarm_info->uid); /* Case #1. The process is an application launched by app_control. * It registered an alarm using launch-based APIs like alarm_schedule_xxx, alarmmgr_xxx_appsvc. */ @@ -1641,7 +1442,7 @@ static void __alarm_expired() 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 (!(__alarm_info->alarm_info.alarm_type & ALARM_TYPE_INEXACT) || - !__can_skip_expired_cb(__alarm_info->alarm_id)) { + !_can_skip_expired_cb(__alarm_info->alarm_id)) { if (__alarm_info->global) { if (__find_login_user(&target_uid) < 0) { ALARM_MGR_EXCEPTION_PRINT("Fail to get login user\n"); @@ -1770,9 +1571,9 @@ static void __alarm_expired() 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_send_noti_to_application_by_dbus(destination_app_service_name, alarm_id, __alarm_info->alarm_info.msec, __alarm_info->uid); /* dbus auto activation */ - ALARM_MGR_LOG_PRINT("after __alarm_send_noti_to_application"); + ALARM_MGR_LOG_PRINT("after _alarm_send_noti_to_application_by_dbus"); } } @@ -1818,8 +1619,8 @@ static gboolean __alarm_handler_idle(gpointer user_data) } ALARM_MGR_LOG_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 (_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."); @@ -1844,8 +1645,8 @@ static gboolean __alarm_handler_idle(gpointer user_data) __rtc_set(); ALARM_MGR_LOG_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"); + if (_display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS) + ALARM_MGR_EXCEPTION_PRINT("_display_unlock_state() is failed"); return false; } @@ -2140,94 +1941,6 @@ static bool __save_module_log(const char *tag, const char *message) } #endif /* _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG */ -int __display_lock_state(char *state, char *flag, unsigned int timeout) -{ - GDBusMessage *msg = NULL; - GDBusMessage *reply = NULL; - GVariant *body = 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, NULL); - if (!reply) { - ALARM_MGR_EXCEPTION_PRINT("No reply. g_dbus_connection_send_message_with_reply_sync() is failed."); - 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_LOG_PRINT("Lock LCD OFF is successfully done"); - } - } - } - - g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL); - g_object_unref(msg); - if (reply) - g_object_unref(reply); - - return ret; -} - -int __display_unlock_state(char *state, char *flag) -{ - GDBusMessage *msg = NULL; - GDBusMessage *reply = NULL; - GVariant *body = 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, NULL); - if (!reply) { - ALARM_MGR_EXCEPTION_PRINT("No reply. g_dbus_connection_send_message_with_reply_sync() is failed."); - 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_LOG_PRINT("Unlock LCD OFF is successfully done"); - } - } - } - - g_dbus_connection_flush_sync(alarm_context.connection, NULL, NULL); - g_object_unref(msg); - if (reply) - g_object_unref(reply); - - return ret; -} - static long __get_proper_interval(long interval, int alarm_type) { GSList *gs_iter = NULL; @@ -2261,8 +1974,8 @@ gboolean __alarm_expired_directly(gpointer user_data) /* Expire alarms with duetime equal to newtime by force */ if (alarm_info->due_time == time_sec) { - 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 (_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."); @@ -2274,8 +1987,8 @@ gboolean __alarm_expired_directly(gpointer user_data) _alarm_schedule(); __rtc_set(); - if (__display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS) - ALARM_MGR_EXCEPTION_PRINT("__display_unlock_state() is failed"); + if (_display_unlock_state(DEVICED_LCD_OFF, DEVICED_SLEEP_MARGIN) != ALARMMGR_RESULT_SUCCESS) + ALARM_MGR_EXCEPTION_PRINT("_display_unlock_state() is failed"); } return false; @@ -2357,11 +2070,8 @@ static int __check_modifiable(uid_t uid, pid_t pid, int alarm_id) return ERR_ALARM_NOT_PERMITTED_APP; } -gboolean alarm_manager_alarm_set_rtc_time(AlarmManager *pObj, GDBusMethodInvocation *invoc, - int year, int mon, int day, - int hour, int min, int sec, - gpointer user_data) { - int return_code = ALARMMGR_RESULT_SUCCESS; +int alarm_manager_alarm_set_rtc_time(GVariant *parameters) +{ /* Indentation ingored to help understand the patch. */ if (_APPFW_FEATURE_WAKEUP_USING_RTC) { const char *rtc = default_rtc; @@ -2375,17 +2085,18 @@ if (_APPFW_FEATURE_WAKEUP_USING_RTC) { /*extract day of the week, day in the year & daylight saving time from system*/ time_t current_time; char buf[1024]; + int year, mon, day, hour, min, sec; + int return_code = ALARMMGR_RESULT_SUCCESS; + + g_variant_get(parameters, "(iiiiii)", &year, &mon, &day, &hour, &min, &sec); current_time = time(NULL); alarm_tm = gmtime_r(¤t_time, &tm); if (alarm_tm == NULL) { ALARM_MGR_EXCEPTION_PRINT("alarm_tm is NULL"); - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; + return ERR_ALARM_SYSTEM_FAIL; } - alarm_tm->tm_year = year; alarm_tm->tm_mon = mon; alarm_tm->tm_mday = day; @@ -2400,9 +2111,7 @@ if (_APPFW_FEATURE_WAKEUP_USING_RTC) { gfd = open(rtc, O_RDWR); if (gfd < 0) { 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; + return ERR_ALARM_SYSTEM_FAIL; } } @@ -2435,22 +2144,22 @@ if (_APPFW_FEATURE_WAKEUP_USING_RTC) { snprintf(log_message, sizeof(log_message), "wakeup rtc time: %d, %s", (int)rtc_time, ctime(&rtc_time)); __save_module_log(log_tag, log_message); #endif + return return_code; } else { ALARM_MGR_LOG_PRINT("[alarm-server] RTC does not work."); - return_code = ERR_ALARM_SYSTEM_FAIL; + return ERR_ALARM_SYSTEM_FAIL; } - - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; } static int accrue_msec = 0; /* To check a millisecond part of current time at changing the system time(sec) */ -gboolean alarm_manager_alarm_set_time(AlarmManager *pObj, GDBusMethodInvocation *invoc, int time_sec, gpointer user_data) +int alarm_manager_alarm_set_time(GVariant* parameters) { double diff_time = 0.0; struct timeval cur_time = {0,}; - int return_code = ALARMMGR_RESULT_SUCCESS; + int time_sec; + + g_variant_get(parameters, "(i)", &time_sec); _alarm_disable_timer(alarm_context); /* Disable the timer to reschedule the alarm before the time is changed. */ @@ -2470,12 +2179,10 @@ gboolean alarm_manager_alarm_set_time(AlarmManager *pObj, GDBusMethodInvocation cur_time.tv_sec, time_sec, ctime((const time_t *)&time_sec), diff_time); __reschedule_alarms_with_newtime(cur_time.tv_sec, time_sec, diff_time); - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; + return ALARMMGR_RESULT_SUCCESS;; } -gboolean alarm_manager_alarm_set_time_with_propagation_delay(AlarmManager *pObj, GDBusMethodInvocation *invoc, - guint new_sec, guint new_nsec, guint req_sec, guint req_nsec, gpointer user_data) +int alarm_manager_alarm_set_time_with_propagation_delay(GVariant* parameters) { double diff_time = 0.0; struct timespec cur_time = {0,}; @@ -2483,6 +2190,9 @@ gboolean alarm_manager_alarm_set_time_with_propagation_delay(AlarmManager *pObj, struct timespec sleep_time = {0,}; guint real_newtime = 0; accrue_msec = 0; /* reset accrued msec */ + guint new_sec, new_nsec, req_sec, req_nsec; + + g_variant_get(parameters, "(uuuu)", &new_sec, &new_nsec, &req_sec, &req_nsec); _alarm_disable_timer(alarm_context); /* Disable the timer to reschedule the alarm before the time is changed. */ @@ -2493,8 +2203,7 @@ gboolean alarm_manager_alarm_set_time_with_propagation_delay(AlarmManager *pObj, if (req_sec > cur_time.tv_sec || (req_sec == cur_time.tv_sec && req_nsec > cur_time.tv_nsec)) { ALARM_MGR_EXCEPTION_PRINT("The requeted time(%d.%09d) must be equal to or less than current time(%ld.%09ld).", req_sec, req_nsec, cur_time.tv_sec, cur_time.tv_nsec); - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ERR_ALARM_INVALID_PARAM)); - return true; + return ERR_ALARM_INVALID_PARAM; } /* Compensate propagation delay */ @@ -2523,11 +2232,10 @@ gboolean alarm_manager_alarm_set_time_with_propagation_delay(AlarmManager *pObj, cur_time.tv_sec, cur_time.tv_nsec, new_sec, new_nsec, real_newtime, diff_time); ALARM_MGR_LOG_PRINT("Requested(%d.%09d) Delay(%ld.%09ld) Sleep(%09ld)", req_sec, req_nsec, delay.tv_sec, delay.tv_nsec, sleep_time.tv_nsec); __reschedule_alarms_with_newtime(cur_time.tv_sec, real_newtime, diff_time); - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ALARMMGR_RESULT_SUCCESS)); - return true; + return ALARMMGR_RESULT_SUCCESS; } -gboolean alarm_manager_alarm_set_timezone(AlarmManager *pObject, GDBusMethodInvocation *invoc, char *tzpath_str, gpointer user_data) +int alarm_manager_alarm_set_timezone(GVariant* parameters) { int retval = 0; int return_code = ALARMMGR_RESULT_SUCCESS; @@ -2537,6 +2245,9 @@ gboolean alarm_manager_alarm_set_timezone(AlarmManager *pObject, GDBusMethodInvo char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; #endif + char *tzpath_str; + + g_variant_get(parameters, "(&s)", &tzpath_str); ALARM_MGR_LOG_PRINT("[TIMESTAMP]Set the timezone to %s.", tzpath_str); @@ -2586,7 +2297,6 @@ gboolean alarm_manager_alarm_set_timezone(AlarmManager *pObject, GDBusMethodInvo bundle_free(b); done: - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG if (return_code == ALARMMGR_RESULT_SUCCESS) strncpy(log_tag, "SET TIMEZONE", sizeof(log_tag) - 1); @@ -2597,59 +2307,49 @@ done: __save_module_log(log_tag, log_message); #endif - return true; + return return_code; } -gboolean alarm_manager_alarm_create_appsvc(AlarmManager *pObject, GDBusMethodInvocation *invoc, - 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, - unsigned int mode_interval, - int mode_repeat, int alarm_type, - int reserved_info, - char *bundle_data, - gpointer user_data) +int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id) { alarm_info_t alarm_info; int return_code = ALARMMGR_RESULT_SUCCESS; - int alarm_id = 0; + int _alarm_id = 0; #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; #endif - uid_t uid; - pid_t pid; int result; bundle *b; const char *callee_appid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + int start_year, start_month, start_day, start_hour, start_min, start_sec; + int end_year, end_month, end_day; + int mode_day_of_week, mode_interval, mode_repeat, alarm_type, reserved_info; + char *bundle_data; - uid = __get_caller_uid(name); - pid = __get_caller_pid(name); - if (uid < 0 || pid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - return true; - } + *alarm_id = _alarm_id; + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(iiiiiiiiiiiiii&s)", + &start_year, &start_month, &start_day, &start_hour, &start_min, + &start_sec, &end_year, &end_month, &end_day, &mode_day_of_week, + &mode_interval, &mode_repeat, &alarm_type, &reserved_info, &bundle_data); b = bundle_decode((bundle_raw *)bundle_data, strlen(bundle_data)); if (b == NULL) { int ret_bundle = get_last_result(); ALARM_MGR_EXCEPTION_PRINT("Failed to decode bundle_data[Error:%d]\n", ret_bundle); return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - return true; + return return_code; } else { callee_appid = appsvc_get_appid(b); if (_compare_api_version(&result, pid, uid) < 0) { ALARM_MGR_EXCEPTION_PRINT("Unable to check api version\n"); return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); bundle_free(b); - return true; + return return_code; } if (result < 0) { @@ -2659,16 +2359,14 @@ gboolean alarm_manager_alarm_create_appsvc(AlarmManager *pObject, GDBusMethodInv if (!_is_permitted(callee_appid, alarm_type, uid)) { ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted \n", callee_appid); return_code = ERR_ALARM_NOT_PERMITTED_APP; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); bundle_free(b); - return true; + return return_code; } } bundle_free(b); } - alarm_info.start.year = start_year; alarm_info.start.month = start_month; alarm_info.start.day = start_day; @@ -2694,68 +2392,52 @@ gboolean alarm_manager_alarm_create_appsvc(AlarmManager *pObject, GDBusMethodInv alarm_info.mode.u_interval.interval = 0; } - if (!__alarm_create_appsvc(&alarm_info, &alarm_id, mode_interval, uid, pid, bundle_data, &return_code)) { + if (!__alarm_create_appsvc(&alarm_info, &_alarm_id, mode_interval, uid, pid, bundle_data, &return_code)) { ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: CREATE", sizeof(log_tag) - 1); #endif + return_code = ERR_ALARM_SYSTEM_FAIL; } else { #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "CREATE", sizeof(log_tag) - 1); #endif + *alarm_id = _alarm_id; + return_code = ALARMMGR_RESULT_SUCCESS; } - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); + *alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); __save_module_log(log_tag, log_message); #endif - return true; + return return_code; } -gboolean alarm_manager_alarm_create_noti(AlarmManager *pObject, GDBusMethodInvocation *invoc, - 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, - unsigned int mode_interval, - int mode_repeat, int alarm_type, - int reserved_info, - char *noti_data, - gpointer user_data) +int alarm_manager_alarm_create_noti(GVariant *parameters, uid_t uid, pid_t pid, + int *alarm_id) { alarm_info_t alarm_info; - int ret; int return_code = ALARMMGR_RESULT_SUCCESS; - int alarm_id = 0; + int _alarm_id = 0; #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; #endif - uid_t uid; - pid_t pid; - const char *name = g_dbus_method_invocation_get_sender(invoc); - const char *notification_priv = "http://tizen.org/privilege/notification"; - - uid = __get_caller_uid(name); - pid = __get_caller_pid(name); - if (uid < 0 || pid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - return true; - } + int start_year, start_month, start_day, start_hour, start_min, start_sec; + int end_year, end_month, end_day; + int mode_day_of_week, mode_interval, mode_repeat, alarm_type, reserved_info; + char *noti_data; - ret = _cynara_check(invoc, notification_priv, pid); - if (ret != ALARMMGR_RESULT_SUCCESS) { - return_code = ret; + *alarm_id = _alarm_id; + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - return true; - } + g_variant_get(parameters, "(iiiiiiiiiiiiii&s)", + &start_year, &start_month, &start_day, &start_hour, &start_min, + &start_sec, &end_year, &end_month, &end_day, &mode_day_of_week, + &mode_interval, &mode_repeat, &alarm_type, &reserved_info, ¬i_data); alarm_info.start.year = start_year; alarm_info.start.month = start_month; @@ -2782,59 +2464,59 @@ gboolean alarm_manager_alarm_create_noti(AlarmManager *pObject, GDBusMethodInvoc alarm_info.mode.u_interval.interval = 0; } - if (!__alarm_create_noti(&alarm_info, &alarm_id, mode_interval, uid, pid, noti_data, &return_code)) { + if (!__alarm_create_noti(&alarm_info, &_alarm_id, mode_interval, uid, pid, noti_data, &return_code)) { ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: CREATE", sizeof(log_tag) - 1); #endif + return_code = ERR_ALARM_SYSTEM_FAIL; } else { #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "CREATE", sizeof(log_tag) - 1); #endif + return_code = ALARMMGR_RESULT_SUCCESS; + *alarm_id = _alarm_id; } - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); + *alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); __save_module_log(log_tag, log_message); #endif - return true; + return return_code; } -gboolean alarm_manager_alarm_create(AlarmManager *obj, GDBusMethodInvocation *invoc, - 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 start_sec, int msec, int end_year, int end_month, - int end_day, int mode_day_of_week, - int mode_repeat, int alarm_type, - int reserved_info, - char *reserved_service_name, char *reserved_service_name_mod, - gpointer user_data) +int alarm_manager_alarm_create(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id) { alarm_info_t alarm_info; int return_code = ALARMMGR_RESULT_SUCCESS; - int alarm_id = 0; + int _alarm_id = 0; #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; #endif - uid_t uid; - pid_t pid; - const char *name = g_dbus_method_invocation_get_sender(invoc); char *_reserved_service_name = NULL; char *_reserved_service_name_mod = NULL; - pid = __get_caller_pid(name); - uid = __get_caller_uid(name); - if (uid < 0 || pid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - return true; - } + char *app_service_name = NULL; + char *app_service_name_mod = NULL; + int start_year, start_month, start_day, start_hour, start_min, start_sec; + int msec, end_year, end_month, end_day; + int mode_day_of_week, mode_repeat, alarm_type, reserved_info; + char *reserved_service_name = NULL; + char *reserved_service_name_mod = NULL; + + *alarm_id = _alarm_id; + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(&s&siiiiiiiiiiiiii&s&s)", + &app_service_name, &app_service_name_mod, + &start_year, &start_month, &start_day, &start_hour, &start_min, + &start_sec, &msec, &end_year, &end_month, &end_day, + &mode_day_of_week, &mode_repeat, &alarm_type, &reserved_info, + &reserved_service_name, &reserved_service_name_mod); alarm_info.start.year = start_year; alarm_info.start.month = start_month; @@ -2860,27 +2542,28 @@ gboolean alarm_manager_alarm_create(AlarmManager *obj, GDBusMethodInvocation *in if (strcmp(reserved_service_name_mod, "null") == 0) _reserved_service_name_mod = NULL; - if (!__alarm_create(&alarm_info, &alarm_id, uid, pid, QUANTUMIZE, 0, 0, app_service_name, app_service_name_mod, + if (!__alarm_create(&alarm_info, &_alarm_id, uid, pid, QUANTUMIZE, 0, 0, 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); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: CREATE", sizeof(log_tag) - 1); #endif + return_code = ERR_ALARM_SYSTEM_FAIL; } else { #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "CREATE", sizeof(log_tag) - 1); #endif + return_code = ALARMMGR_RESULT_SUCCESS; + *alarm_id = _alarm_id; } - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); + *alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); __save_module_log(log_tag, log_message); #endif - return true; + return return_code; } time_t _get_periodic_alarm_standard_time(void) @@ -2893,28 +2576,26 @@ time_t _get_periodic_alarm_standard_time(void) return periodic_alarm_standard_time; } -gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvocation *invoc, - char *app_service_name, char *app_service_name_mod, int interval, - int is_ref, int method, gpointer user_data) +int alarm_manager_alarm_create_periodic(GVariant *parameters, uid_t uid, + pid_t pid, int *alarm_id) { alarm_info_t alarm_info; int return_code = ALARMMGR_RESULT_SUCCESS; - int alarm_id = 0; + int _alarm_id = 0; #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; #endif - uid_t uid; - pid_t pid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + char *app_service_name = NULL; + char *app_service_name_mod = NULL; + int interval, is_ref, method; - uid = __get_caller_uid(name); - pid = __get_caller_pid(name); - if (uid < 0 || pid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code)); - return true; - } + *alarm_id = _alarm_id; + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(&s&siii)", &app_service_name, + &app_service_name_mod, &interval, &is_ref, &method); struct tm standard_tm; time_t standard_time = _get_periodic_alarm_standard_time(); @@ -2951,111 +2632,92 @@ gboolean alarm_manager_alarm_create_periodic(AlarmManager *obj, GDBusMethodInvoc alarm_info.mode.u_interval.interval = __get_proper_interval(interval * 60, alarm_info.alarm_type); } - if (!__alarm_create(&alarm_info, &alarm_id, uid, pid, (periodic_method_e)method, interval * 60, is_ref, + if (!__alarm_create(&alarm_info, &_alarm_id, uid, pid, (periodic_method_e)method, interval * 60, is_ref, app_service_name, app_service_name_mod, NULL, NULL, &return_code)) { ALARM_MGR_EXCEPTION_PRINT("Unable to create alarm! return_code[%d]", return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: CREATE", sizeof(log_tag) - 1); #endif + return_code = ERR_ALARM_SYSTEM_FAIL; } else { #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "CREATE", sizeof(log_tag) - 1); #endif + return_code = ALARMMGR_RESULT_SUCCESS; + *alarm_id = _alarm_id; } - g_dbus_method_invocation_return_value(invoc, - g_variant_new("(ii)", alarm_id, return_code)); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", - alarm_id, uid, pid, alarm_info.start.year, alarm_info.start.month, + *alarm_id, uid, pid, alarm_info.start.year, alarm_info.start.month, alarm_info.start.day, alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec); __save_module_log(log_tag, log_message); #endif - return true; + return return_code; } -gboolean alarm_manager_alarm_delete(AlarmManager *obj, GDBusMethodInvocation *invoc, - alarm_id_t alarm_id, gpointer user_data) +int alarm_manager_alarm_delete(GVariant *parameters, uid_t uid, pid_t pid) { int return_code = ALARMMGR_RESULT_SUCCESS; #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; #endif - uid_t uid; - pid_t pid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + int alarm_id; - uid = __get_caller_uid(name); - pid = __get_caller_pid(name); - if (uid < 0 || pid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; - } + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(i)", &alarm_id); return_code = __check_modifiable(uid, pid, alarm_id); - if (return_code != ALARMMGR_RESULT_SUCCESS) { - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; - } + if (return_code != ALARMMGR_RESULT_SUCCESS) + return return_code; if (!__alarm_delete(uid, alarm_id, &return_code)) { ALARM_MGR_EXCEPTION_PRINT("Unable to delete the alarm! alarm_id[%d], return_code[%d]", alarm_id, return_code); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "FAIL: DELETE", sizeof(log_tag) - 1); #endif + return_code = ERR_ALARM_SYSTEM_FAIL; } else { ALARM_MGR_LOG_PRINT("alarm_id[%d] is removed.", alarm_id); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG strncpy(log_tag, "DELETE", sizeof(log_tag) - 1); #endif + return_code = ALARMMGR_RESULT_SUCCESS; } - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d", alarm_id, uid, pid); __save_module_log(log_tag, log_message); #endif - return true; + return return_code; } -gboolean alarm_manager_alarm_delete_all(AlarmManager *obj, GDBusMethodInvocation *invoc, - gpointer user_data) +int alarm_manager_alarm_delete_all(GVariant *parameters, uid_t uid, pid_t pid) { GSList *gs_iter = NULL; char app_name[512] = { 0 }; alarm_info_t *alarm_info = NULL; __alarm_info_t *entry = NULL; bool is_deleted = false; - int return_code = ALARMMGR_RESULT_SUCCESS; #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; #endif - uid_t uid; - pid_t pid; - const char *name = g_dbus_method_invocation_get_sender(invoc); - uid = __get_caller_uid(name); - pid = __get_caller_pid(name); - if (uid < 0 || pid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; - } + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; if (__get_cached_unique_name(pid, app_name, sizeof(app_name), NULL, uid) == false) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG snprintf(log_message, sizeof(log_message), "pid: %d. Can not get the unique_name.", pid); __save_module_log("FAIL: DELETE ALL", log_message); #endif - return true; + return ERR_ALARM_SYSTEM_FAIL; } SECURE_LOGD("Called by process (pid:%d, unique_name=%s)", pid, app_name); @@ -3098,21 +2760,10 @@ gboolean alarm_manager_alarm_delete_all(AlarmManager *obj, GDBusMethodInvocation #endif __rtc_set(); - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; + return ALARMMGR_RESULT_SUCCESS; } -gboolean alarm_manager_alarm_update(AlarmManager *pObj, GDBusMethodInvocation *invoc, - 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_interval, - int mode_repeat, - int alarm_type, int reserved_info, - int update_flag, - gpointer user_data) +int alarm_manager_alarm_update(GVariant *parameters, uid_t uid, pid_t pid) { int return_code = ALARMMGR_RESULT_SUCCESS; alarm_info_t alarm_info; @@ -3120,23 +2771,23 @@ gboolean alarm_manager_alarm_update(AlarmManager *pObj, GDBusMethodInvocation *i char log_tag[ALARMMGR_LOG_TAG_SIZE] = {0,}; char log_message[ALARMMGR_LOG_MESSAGE_SIZE] = {0,}; #endif - uid_t uid; - pid_t pid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + int alarm_id; + int start_year, start_month, start_day, start_hour, start_min, start_sec; + int end_year, end_month, end_day; + int mode_interval, mode_repeat, alarm_type, reserved_info, update_flag; - uid = __get_caller_uid(name); - pid = __get_caller_pid(name); - if (uid < 0 || pid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; - } + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(iiiiiiiiiiiiiii)", + &alarm_id, &start_year, &start_month, &start_day, &start_hour, + &start_min, &start_sec, &end_year, &end_month, &end_day, + &mode_interval, &mode_repeat, &alarm_type, &reserved_info, + &update_flag); return_code = __check_modifiable(uid, pid, alarm_id); - if (return_code != ALARMMGR_RESULT_SUCCESS) { - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; - } + if (return_code != ALARMMGR_RESULT_SUCCESS) + return return_code; alarm_info.start.year = start_year; alarm_info.start.month = start_month; @@ -3167,42 +2818,28 @@ gboolean alarm_manager_alarm_update(AlarmManager *pObj, GDBusMethodInvocation *i #endif } - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - #ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG snprintf(log_message, sizeof(log_message), "alarmID: %d, uid: %d, pid: %d, duetime: %d-%d-%d %02d:%02d:%02d", alarm_id, uid, pid, start_year, start_month, start_day, start_hour, start_min, start_sec); __save_module_log(log_tag, log_message); #endif - return true; + return return_code; } -gboolean alarm_manager_alarm_get_number_of_ids(AlarmManager *pObject, GDBusMethodInvocation *invoc, - gpointer user_data) +int alarm_manager_alarm_get_number_of_ids(uid_t uid, pid_t pid, int *num_of_ids) { GSList *gs_iter = NULL; char app_name[256] = { 0 }; __alarm_info_t *entry = NULL; - int num_of_ids = 0; - int return_code = ALARMMGR_RESULT_SUCCESS; - uid_t uid; - pid_t pid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + int _num_of_ids = 0; - uid = __get_caller_uid(name); - pid = __get_caller_pid(name); - if (uid < 0 || pid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code)); - return true; - } + *num_of_ids = _num_of_ids; + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; - if (__get_cached_unique_name(pid, app_name, sizeof(app_name), NULL, uid) == false) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code)); - return true; - } + if (__get_cached_unique_name(pid, app_name, sizeof(app_name), NULL, uid) == false) + return ERR_ALARM_SYSTEM_FAIL; SECURE_LOGD("Called by process (uid:%d, pid:%d, unique_name:%s)", uid, pid, app_name); @@ -3211,54 +2848,45 @@ gboolean alarm_manager_alarm_get_number_of_ids(AlarmManager *pObject, GDBusMetho SECURE_LOGD("app_name=%s, app_unique_name=%s", app_name, entry->app_unique_name); if (entry->uid == uid && strncmp(app_name, entry->app_unique_name, strlen(app_name)) == 0) { - (num_of_ids)++; - SECURE_LOGD("inc number of alarms of app (uid:%d, pid:%d, unique_name:%s) is %d.", uid, pid, app_name, num_of_ids); + (_num_of_ids)++; + SECURE_LOGD("inc number of alarms of app (uid:%d, pid:%d, unique_name:%s) is %d.", uid, pid, app_name, _num_of_ids); } } - SECURE_LOGD("number of alarms of the process (uid:%d, pid:%d, unique_name:%s) is %d.", uid, pid, app_name, num_of_ids); - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code)); - return true; + SECURE_LOGD("number of alarms of the process (uid:%d, pid:%d, unique_name:%s) is %d.", uid, pid, app_name, _num_of_ids); + *num_of_ids = _num_of_ids; + return ALARMMGR_RESULT_SUCCESS; } -gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodInvocation *invoc, - int max_number_of_ids, gpointer user_data) +int alarm_manager_alarm_get_list_of_ids(GVariant *parameters, uid_t uid, + pid_t pid, GVariant **alarm_array, int *num_of_alarm) { GSList *gs_iter = NULL; char app_name[512] = { 0 }; __alarm_info_t *entry = NULL; int index = 0; - GVariant *arr = NULL; + int max_number_of_ids; GVariantBuilder *builder = NULL; - int num_of_ids = 0; - int return_code = ALARMMGR_RESULT_SUCCESS; - uid_t uid; - pid_t pid; - const char *name = g_dbus_method_invocation_get_sender(invoc); - uid = __get_caller_uid(name); - pid = __get_caller_pid(name); - if (uid < 0 || pid < 0) { - 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; - } + *alarm_array = g_variant_new("ai", NULL); + + if (uid < 0 || pid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(i)", &max_number_of_ids); if (max_number_of_ids <= 0) { SECURE_LOGE("called for uid(%d) pid(%d), but max_number_of_ids(%d) is less than 0.", uid, 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; + *num_of_alarm = 0; + return ALARMMGR_RESULT_SUCCESS; } - if (__get_cached_unique_name(pid, app_name, sizeof(app_name), NULL, uid) == false) { - 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; - } + if (__get_cached_unique_name(pid, app_name, sizeof(app_name), NULL, uid) == false) + return ERR_ALARM_SYSTEM_FAIL; SECURE_LOGD("Called by process (uid: %d, pid:%d, unique_name=%s).", uid, pid, app_name); - 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 = (__alarm_info_t*)gs_iter->data; if (entry->uid == uid && @@ -3269,33 +2897,27 @@ gboolean alarm_manager_alarm_get_list_of_ids(AlarmManager *pObject, GDBusMethodI } } - arr = g_variant_new("ai", builder); - num_of_ids = index; - - SECURE_LOGE("Called by uid (%d), pid (%d), but max_number_of_ids(%d) return code %d.", uid, pid, num_of_ids, return_code); - g_dbus_method_invocation_return_value(invoc, g_variant_new("(@aiii)", arr, num_of_ids, return_code)); + *alarm_array = g_variant_new("ai", builder); + *num_of_alarm = index; g_variant_builder_unref(builder); - return true; + SECURE_LOGE("Called by uid (%d), pid (%d), but max_number_of_ids(%d).", uid, pid, index); + + return ALARMMGR_RESULT_SUCCESS; } -gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, - alarm_id_t alarm_id, gpointer user_data) +int alarm_manager_alarm_get_appsvc_info(GVariant *parameters, uid_t uid, gchar **b_data) { bool found = false; GSList *gs_iter = NULL; __alarm_info_t *entry = NULL; int return_code = ALARMMGR_RESULT_SUCCESS; - gchar *b_data = NULL; - uid_t uid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + int alarm_id; - uid = __get_caller_uid(name); - if (uid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code)); - return true; - } + if (uid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(i)", &alarm_id); SECURE_LOGD("called for uid(%d), alarm_id(%d)\n", uid, alarm_id); @@ -3303,13 +2925,13 @@ gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodI entry = (__alarm_info_t*)gs_iter->data; if (entry->uid == uid && entry->alarm_id == alarm_id) { found = true; - b_data = g_strdup(entry->bundle); + *b_data = g_strdup(entry->bundle); break; } } if (found) { - if (b_data == NULL) { + if (*b_data == NULL) { ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is an regular alarm, not svc alarm.", alarm_id); return_code = ERR_ALARM_INVALID_TYPE; } @@ -3318,28 +2940,21 @@ gboolean alarm_manager_alarm_get_appsvc_info(AlarmManager *pObject, GDBusMethodI return_code = ERR_ALARM_INVALID_ID; } - g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", b_data, return_code)); - g_free(b_data); - return true; + return return_code; } -gboolean alarm_manager_alarm_get_noti_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, - alarm_id_t alarm_id, gpointer user_data) +int alarm_manager_alarm_get_noti_info(GVariant *parameters, uid_t uid, gchar **noti_data) { bool found = false; GSList *gs_iter = NULL; __alarm_info_t *entry = NULL; int return_code = ALARMMGR_RESULT_SUCCESS; - gchar *noti_data = NULL; - uid_t uid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + int alarm_id; - uid = __get_caller_uid(name); - if (uid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", noti_data, return_code)); - return true; - } + if (uid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(i)", &alarm_id); SECURE_LOGD("called for uid(%d), alarm_id(%d)\n", uid, alarm_id); @@ -3347,13 +2962,13 @@ gboolean alarm_manager_alarm_get_noti_info(AlarmManager *pObject, GDBusMethodInv entry = (__alarm_info_t*)gs_iter->data; if (entry->uid == uid && entry->alarm_id == alarm_id) { found = true; - noti_data = strdup(entry->noti); + *noti_data = strdup(entry->noti); break; } } if (found) { - if (noti_data == NULL) { + if (*noti_data == NULL) { ALARM_MGR_EXCEPTION_PRINT("The alarm(%d) is an regular alarm, not svc alarm.", alarm_id); return_code = ERR_ALARM_INVALID_TYPE; } @@ -3362,68 +2977,66 @@ gboolean alarm_manager_alarm_get_noti_info(AlarmManager *pObject, GDBusMethodInv return_code = ERR_ALARM_INVALID_ID; } - g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", noti_data, return_code)); - g_free(noti_data); - return true; + return return_code; } -gboolean alarm_manager_alarm_get_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, - alarm_id_t alarm_id, gpointer user_data) +int alarm_manager_alarm_get_info(GVariant *parameters, uid_t uid, alarm_info_t *alarm_info) { GSList *gs_iter = NULL; __alarm_info_t *entry = NULL; - alarm_info_t *alarm_info = NULL; - int return_code = ALARMMGR_RESULT_SUCCESS; - uid_t uid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + alarm_info_t *_alarm_info = NULL; + int alarm_id; - uid = __get_caller_uid(name); - if (uid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - 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; - } + if (uid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(i)", &alarm_id); SECURE_LOGD("called for uid(%d), alarm_id(%d)\n", uid, alarm_id); for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) { entry = (__alarm_info_t*)gs_iter->data; if (entry->uid == uid && entry->alarm_id == alarm_id) { - alarm_info = &(entry->alarm_info); + _alarm_info = &(entry->alarm_info); break; } } - if (alarm_info == NULL) { + 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)); + return ERR_ALARM_INVALID_ID; } else { 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)); + alarm_info->start.year = _alarm_info->start.year; + alarm_info->start.month = _alarm_info->start.month; + alarm_info->start.day = _alarm_info->start.day; + alarm_info->start.hour = _alarm_info->start.hour; + alarm_info->start.min = _alarm_info->start.min; + alarm_info->start.sec = _alarm_info->start.sec; + alarm_info->end.year = _alarm_info->end.year; + alarm_info->end.month = _alarm_info->end.month; + alarm_info->end.day = _alarm_info->end.day; + alarm_info->mode.u_interval.day_of_week = + _alarm_info->mode.u_interval.day_of_week; + alarm_info->mode.repeat = _alarm_info->mode.repeat; + alarm_info->alarm_type = _alarm_info->alarm_type; + alarm_info->reserved_info = _alarm_info->reserved_info; } - return true; + return ALARMMGR_RESULT_SUCCESS; } -gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethodInvocation *invoc, - alarm_id_t alarm_id, gpointer user_data) +int alarm_manager_alarm_get_next_duetime(GVariant *parameters, uid_t uid, int *duetime) { GSList *gs_iter = NULL; __alarm_info_t *entry = NULL; __alarm_info_t *find_item = NULL; - int return_code = ALARMMGR_RESULT_SUCCESS; - time_t duetime = 0; - uid_t uid; - const char *name = g_dbus_method_invocation_get_sender(invoc); + time_t _duetime = 0; + int alarm_id; - uid = __get_caller_uid(name); - if (uid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", duetime, return_code)); - return true; - } + if (uid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(i)", &alarm_id); SECURE_LOGD("called for alarm_id(%d)\n", alarm_id); for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) { @@ -3436,60 +3049,39 @@ gboolean alarm_manager_alarm_get_next_duetime(AlarmManager *pObject, GDBusMethod 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; + return ERR_ALARM_INVALID_ID; } - duetime = _alarm_next_duetime(find_item); - ALARM_MGR_LOG_PRINT("Next duetime : %s", ctime(&duetime)); + _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; + *duetime = (int)_duetime; + return ALARMMGR_RESULT_SUCCESS; } -gboolean alarm_manager_alarm_get_all_info(AlarmManager *pObject, GDBusMethodInvocation *invoc, gpointer user_data) +int alarm_manager_alarm_get_all_info(uid_t uid, char **db_path) { - int return_code = ALARMMGR_RESULT_SUCCESS; - uid_t uid; - const char *name = g_dbus_method_invocation_get_sender(invoc); - char *db_path = NULL; - - uid = __get_caller_uid(name); - if (uid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", NULL, return_code)); - return true; - } - - return_code = _get_db_path_for_all_info(uid, &db_path); - - g_dbus_method_invocation_return_value(invoc, g_variant_new("(si)", db_path, return_code)); - - if (db_path) - free(db_path); + if (uid < 0) + return ERR_ALARM_SYSTEM_FAIL; - return true; + return _get_db_path_for_all_info(uid, &(*db_path)); } -gboolean alarm_manager_alarm_set_global(AlarmManager *pObject, GDBusMethodInvocation *invoc, - alarm_id_t alarm_id, bool global, gpointer user_data) +int alarm_manager_alarm_set_global(GVariant *parameters, uid_t uid) { GSList *gs_iter = NULL; __alarm_info_t *entry = NULL; alarm_info_t *alarm_info = NULL; int retval = 0; int return_code = ALARMMGR_RESULT_SUCCESS; - uid_t uid; - const char *name = g_dbus_method_invocation_get_sender(invoc); char *callee_pkgid; + int alarm_id; + gboolean global; - uid = __get_caller_uid(name); - if (uid < 0) { - return_code = ERR_ALARM_SYSTEM_FAIL; - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); - return true; - } + if (uid < 0) + return ERR_ALARM_SYSTEM_FAIL; + + g_variant_get(parameters, "(ib)", &alarm_id, &global); SECURE_LOGD("called for uid(%d), alarm_id(%d)\n", uid, alarm_id); for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) { @@ -3502,8 +3094,7 @@ gboolean alarm_manager_alarm_set_global(AlarmManager *pObject, GDBusMethodInvoca 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("(i)", return_code)); + return ERR_ALARM_INVALID_ID; } else { ALARM_MGR_LOG_PRINT("The alarm(%d) is found.", alarm_id); @@ -3516,29 +3107,28 @@ gboolean alarm_manager_alarm_set_global(AlarmManager *pObject, GDBusMethodInvoca retval = _pkg_is_global(callee_pkgid, uid); if (retval == ALARMMGR_RESULT_SUCCESS) { - entry->global = global; - if (!_alarm_set_global_to_db(entry, global)) + entry->global = (bool)global; + if (!_alarm_set_global_to_db(entry, (bool)global)) return_code = ERR_ALARM_SYSTEM_FAIL; } else { ALARM_MGR_EXCEPTION_PRINT("Get pkginfo error [%d]", retval); return_code = retval; } - - g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code)); } - return true; + return return_code; } -gboolean alarm_manager_alarm_get_global(AlarmManager *pObject, GDBusMethodInvocation *invoc, - alarm_id_t alarm_id, gpointer user_data) +int alarm_manager_alarm_get_global(GVariant *parameters, gboolean *global) { GSList *gs_iter = NULL; __alarm_info_t *entry = NULL; __alarm_info_t *find_item = NULL; - int return_code = ALARMMGR_RESULT_SUCCESS; - bool global = false; + int alarm_id; + + g_variant_get(parameters, "(i)", &alarm_id); + *global = false; SECURE_LOGD("called for alarm_id(%d)\n", alarm_id); for (gs_iter = alarm_context.alarms; gs_iter != NULL; gs_iter = g_slist_next(gs_iter)) { entry = (__alarm_info_t*)gs_iter->data; @@ -3550,19 +3140,15 @@ gboolean alarm_manager_alarm_get_global(AlarmManager *pObject, GDBusMethodInvoca 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("(bi)", global, return_code)); - return true; + return ERR_ALARM_INVALID_ID; } - global = find_item->global; - ALARM_MGR_LOG_PRINT("Is global : %d", global); + *global = (gboolean)find_item->global; + ALARM_MGR_LOG_PRINT("Is global : %d", *global); - g_dbus_method_invocation_return_value(invoc, g_variant_new("(bi)", global, return_code)); - return true; + return ALARMMGR_RESULT_SUCCESS; } - static void __timer_glib_finalize(GSource *src) { GSList *fd_list; @@ -3689,123 +3275,6 @@ static bool __initialize_noti() return true; } -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) -{ - GSList *entry = NULL; - __expired_alarm_t *expire_info = NULL; - char *service_name = NULL; - - /* 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) { - 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); - - 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, 0, expire_info->uid); - g_expired_alarm_list = g_slist_remove(g_expired_alarm_list, entry->data); - g_free(expire_info); - } - } - } - g_free(service_name); - } -} - -static bool __initialize_dbus() -{ - GDBusConnection *connection = NULL; - GError *error = NULL; - guint subsc_id; - ALARM_MGR_LOG_PRINT("__initialize_dbus Enter"); - - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (connection == NULL) { - ALARM_MGR_EXCEPTION_PRINT("g_bus_get_sync() is failed"); - if (error) { - ALARM_MGR_EXCEPTION_PRINT("dbus error message : %s", error->message); - g_error_free(error); - } - return false; - } - - interface = alarm_manager_skeleton_new(); - if (interface == NULL) { - ALARM_MGR_EXCEPTION_PRINT("Creating a skeleton object is failed."); - g_object_unref(connection); - return false; - } - - g_signal_connect(interface, "handle_alarm_create", G_CALLBACK(alarm_manager_alarm_create), NULL); - g_signal_connect(interface, "handle_alarm_create_periodic", G_CALLBACK(alarm_manager_alarm_create_periodic), NULL); - g_signal_connect(interface, "handle_alarm_create_appsvc", G_CALLBACK(alarm_manager_alarm_create_appsvc), NULL); - g_signal_connect(interface, "handle_alarm_create_noti", G_CALLBACK(alarm_manager_alarm_create_noti), 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_noti_info", G_CALLBACK(alarm_manager_alarm_get_noti_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_set_timezone", G_CALLBACK(alarm_manager_alarm_set_timezone), 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); - g_signal_connect(interface, "handle_alarm_set_time_with_propagation_delay", G_CALLBACK(alarm_manager_alarm_set_time_with_propagation_delay), NULL); - g_signal_connect(interface, "handle_alarm_set_global", G_CALLBACK(alarm_manager_alarm_set_global), NULL); - g_signal_connect(interface, "handle_alarm_get_global", G_CALLBACK(alarm_manager_alarm_get_global), NULL); - - 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; - g_object_unref(connection); - 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; - g_object_unref(connection); - return false; - } - - guint owner_id = g_bus_own_name_on_connection(connection, - ALARM_MGR_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, - NULL, NULL, NULL, NULL); - - if (owner_id == 0) { - ALARM_MGR_EXCEPTION_PRINT("Acquiring the own name is failed."); - g_object_unref(interface); - interface = NULL; - g_object_unref(connection); - return false; - } - - alarm_context.connection = connection; - - return true; -} - - void _alarm_initialize() { #if !(GLIB_CHECK_VERSION(2, 36, 0)) @@ -3818,10 +3287,10 @@ void _alarm_initialize() ALARM_MGR_LOG_PRINT("alarm_expire_mode : %d", expire_mode); __initialize_timer(); - if (__initialize_dbus() == false) { + if (_initialize_dbus() == false) { /* because dbus's initialize * failed, we cannot continue any more. */ - ALARM_MGR_EXCEPTION_PRINT("because __initialize_dbus failed, " + ALARM_MGR_EXCEPTION_PRINT("because _initialize_dbus failed, " "alarm-server cannot be runned.\n"); exit(1); } @@ -3868,4 +3337,3 @@ void _release_alarm_info_t(__alarm_info_t *entry) free(entry); } - diff --git a/unittest/alarmmanager_unittest.cpp b/unittest/alarmmanager_unittest.cpp deleted file mode 100755 index bb59319..0000000 --- a/unittest/alarmmanager_unittest.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <gmock/gmock.h> -#include <gtest/gtest.h> -#include <unistd.h> -#include <stdio.h> - -#include "alarm.h" -#include "alarm-internal.h" - -#include "alarm-manager.c" -#include "alarm-manager-schedule.c" -#include "alarm-manager-timer.c" -#include "alarm-manager-db.c" -#include "alarm-manager-util.c" - -#include "mock/alarm_dbus.h" -#include "mock/cynara_fake.h" -#include "mock/gio_fake.h" -#include "mock/glib_fake.h" - -GVariant* __fake_g_dbus_connection_call_sync(GDBusConnection *connection, - const gchar *bus_name, - const gchar *object_path, - const gchar *interface_name, - const gchar *method_name, - GVariant *parameters, - const GVariantType *reply_type, - GDBusCallFlags flags, - gint timeout_msec, - GCancellable *cancellable, - GError **error) -{ - GVariant* ret = g_variant_new_string("var"); - return ret; -} - -const gchar* __fake_g_dbus_method_invocation_get_sender(GDBusMethodInvocation *invocation) -{ - const gchar* ret = "fake"; - return ret; -} - -guint __fake_g_dbus_connection_signal_subscribe(GDBusConnection* con, - const gchar* sender, const gchar* interface_name, const gchar* member, - const gchar* object_path, const gchar* arg, GDBusSignalFlags flags, - GDBusSignalCallback cb, gpointer user_data, GDestroyNotify free_func) -{ - return 1; -} - -gboolean __fake_g_dbus_interface_skeleton_export(GDBusInterfaceSkeleton* skel, - GDBusConnection* con, const gchar* path, GError** error) -{ - return true; -} - -void __fake_g_variant_get(GVariant* value, const gchar* format_string, va_list v) -{ - gpointer ptr = va_arg(v, gpointer); - *(guint32 *) ptr = 1; -} - -gboolean __fake_g_variant_iter_loop(GVariantIter* value, const gchar* format_string, va_list v) -{ - return false; -} - -void __fake_g_variant_unref(GVariant* value) -{ -} - -void __fake_g_variant_iter_free(GVariantIter* value) -{ -} - -GVariant* __fake_g_variant_new(const gchar *string, va_list v) -{ - return nullptr; -} - -gpointer __fake_g_hash_table_lookup(GHashTable* table, gconstpointer key) -{ - return nullptr; -} - -guint __fake_g_hash_table_foreach_remove(GHashTable* table, - GHRFunc func, gpointer key) -{ - return 0; -} - -gboolean __fake_g_hash_table_insert(GHashTable* table, gpointer key, - gpointer value) -{ - return true; -} - -int __fake_cynara_initialize(cynara** c, const cynara_configuration* conf) -{ - return CYNARA_API_SUCCESS; -} - -int __fake_cynara_creds_gdbus_get_user(GDBusConnection* c, const gchar* sender, - enum cynara_user_creds method, gchar** user) -{ - *user = nullptr; - return CYNARA_API_SUCCESS; -} - -int __fake_cynara_creds_gdbus_get_client(GDBusConnection* c, const gchar* sender, - enum cynara_client_creds method, gchar** client) -{ - *client = nullptr; - return CYNARA_API_SUCCESS; -} - -int __fake_cynara_check(cynara* c, const char* client, const char* session, - const char* user, const char* privilege) -{ - return CYNARA_API_ACCESS_ALLOWED; -} -char* __fake_cynara_session_from_pid(pid_t pid) -{ - return strdup("test"); -} - -class AlarmManagerTest : public ::testing::Test { - protected: - void SetUp() override { - g_dbus_connection_call_sync_fake.custom_fake = __fake_g_dbus_connection_call_sync; - g_dbus_method_invocation_get_sender_fake.custom_fake = __fake_g_dbus_method_invocation_get_sender; - g_variant_get_fake.custom_fake = __fake_g_variant_get; - g_variant_iter_loop_fake.custom_fake = __fake_g_variant_iter_loop; - g_variant_unref_fake.custom_fake = __fake_g_variant_unref; - g_variant_iter_free_fake.custom_fake = __fake_g_variant_iter_free; - g_variant_new_fake.custom_fake = __fake_g_variant_new; - g_hash_table_lookup_fake.custom_fake = __fake_g_hash_table_lookup; - g_hash_table_foreach_remove_fake.custom_fake = __fake_g_hash_table_foreach_remove; - g_hash_table_insert_fake.custom_fake = __fake_g_hash_table_insert; - - char fake[5] = "fake"; - alarm_manager_alarm_create(nullptr, nullptr, fake, fake, - 2019, 9, 26, 13, 40, 20, 20, 2020, 9, 26, 1, 0, 0, 0, fake, - fake, nullptr); - } - - void TearDown() override { - } - - alarm_entry_t *alarm; -}; - -TEST_F(AlarmManagerTest, __get_proper_interval_p) -{ - long interval = 30; - - __get_proper_interval(interval, ALARM_TYPE_INEXACT); -} - -TEST_F(AlarmManagerTest, _alarm_initialize_p) -{ - g_dbus_connection_signal_subscribe_fake.custom_fake = - __fake_g_dbus_connection_signal_subscribe; - g_dbus_interface_skeleton_export_fake.custom_fake = - __fake_g_dbus_interface_skeleton_export; - - _alarm_initialize(); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_create_p) -{ - gboolean ret; - char fake[5] = "fake"; - ret = alarm_manager_alarm_create(nullptr, nullptr, fake, fake, - 2019, 9, 26, 13, 40, 20, 20, 2020, 9, 26, 1, 0, 0, 0, fake, - fake, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_create_periodic_p) -{ - gboolean ret; - char fake[5] = "fake"; - ret = alarm_manager_alarm_create_periodic(nullptr, nullptr, fake, - fake, 10000, 0, 1, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_create_appsvc_p) -{ - gboolean ret; - bundle *b; - bundle_raw *b_data = NULL; - int datalen = 0; - b = bundle_create(); - bundle_add_str(b, "key", "val"); - bundle_encode(b, &b_data, &datalen); - - ret = alarm_manager_alarm_create_appsvc(nullptr, nullptr, - 2019, 9, 26, 13, 40, 20, 2020, 9, 26, 1, 0, 0, 0, 10, (char*) b_data, - nullptr); - EXPECT_EQ(true, ret); - - free(b_data); - bundle_free(b); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_create_noti_p) -{ - cynara_initialize_fake.custom_fake = __fake_cynara_initialize; - cynara_creds_gdbus_get_user_fake.custom_fake = __fake_cynara_creds_gdbus_get_user; - cynara_creds_gdbus_get_client_fake.custom_fake = __fake_cynara_creds_gdbus_get_client; - cynara_session_from_pid_fake.custom_fake = __fake_cynara_session_from_pid; - cynara_check_fake.custom_fake = __fake_cynara_check; - - gboolean ret; - ret = alarm_manager_alarm_create_noti(nullptr, nullptr, - 2019, 9, 26, 13, 40, 20, 2020, 9, 26, 1, 0, 0, 0, 10, nullptr, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_delete_p) -{ - gboolean ret; - ret = alarm_manager_alarm_delete(nullptr, nullptr, 1, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_delete_all_p) -{ - gboolean ret; - ret = alarm_manager_alarm_delete_all(nullptr, nullptr, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_get_appsvc_info_p) -{ - gboolean ret; - ret = alarm_manager_alarm_get_appsvc_info(nullptr, nullptr, 1, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_get_info_p) -{ - gboolean ret; - ret = alarm_manager_alarm_get_info(nullptr, nullptr, 1, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_get_noti_info_p) -{ - gboolean ret; - ret = alarm_manager_alarm_get_noti_info(nullptr, nullptr, 1, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_get_list_of_ids_p) -{ - gboolean ret; - ret = alarm_manager_alarm_get_list_of_ids(nullptr, nullptr, 1, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_get_next_duetime_p) -{ - gboolean ret; - ret = alarm_manager_alarm_get_next_duetime(nullptr, nullptr, 1, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_get_number_of_ids_p) -{ - gboolean ret; - ret = alarm_manager_alarm_get_number_of_ids(nullptr, nullptr, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_set_rtc_time_p) -{ - gboolean ret; - ret = alarm_manager_alarm_set_rtc_time(nullptr, nullptr, 2019, 9, 26, 13, - 40, 20, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_set_time_p) -{ - gboolean ret; - // ret = alarm_manager_alarm_set_time(nullptr, nullptr, 20, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_set_timezone_p) -{ - gboolean ret; - char zone[6] = "seoul"; - ret = alarm_manager_alarm_set_timezone(nullptr, nullptr, zone, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_update_p) -{ - gboolean ret; - ret = alarm_manager_alarm_update(nullptr, nullptr, 1, - 2019, 9, 26, 13, 40, 20, 2020, 9, 26, 1, 0, 0, 0, 10, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_get_all_info_p) -{ - gboolean ret; - ret = alarm_manager_alarm_get_all_info(nullptr, nullptr, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_set_time_with_propagation_delay_p) -{ - gboolean ret; -// ret = alarm_manager_alarm_set_time_with_propagation_delay(nullptr, nullptr, -// 20, 21, 30, 31, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_set_global_p) -{ - gboolean ret; - ret = alarm_manager_alarm_set_global(nullptr, nullptr, 1, true, nullptr); - EXPECT_EQ(true, ret); -} - -TEST_F(AlarmManagerTest, alarm_manager_alarm_get_global_p) -{ - gboolean ret; - ret = alarm_manager_alarm_get_global(nullptr, nullptr, 1, nullptr); - EXPECT_EQ(true, ret); -} - diff --git a/unittest/mock/alarm_dbus.h b/unittest/mock/alarm_dbus.h index 1d26fd4..b9c43d1 100755 --- a/unittest/mock/alarm_dbus.h +++ b/unittest/mock/alarm_dbus.h @@ -21,8 +21,6 @@ #include "mock.h" -#include "alarm-mgr-stub.h" - DECLARE_FAKE_VALUE_FUNC(gboolean, alarm_manager_call_alarm_get_info_sync, AlarmManager*, gint, gint*, gint*, gint*, gint*, gint*, gint*, gint*, gint*, gint*, gint*, gint*, gint*, gint*, gint*, GCancellable*, GError**); |