2 * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #include <notification.h>
34 #define LOG_TAG "ALARM_MANAGER"
36 #define MAX_BUNDLE_NAME_LEN 2048
37 #define MAX_SERVICE_NAME_LEN 512
38 #define MAX_PKG_NAME_LEN MAX_SERVICE_NAME_LEN-8
39 #define MAX_PKG_ID_LEN 512
40 #define MAX_APP_ID_LEN 256
41 #define MIN_INEXACT_INTERVAL 600
42 #define REGULAR_UID_MIN 5000
44 #define BILLION 1000000000 /* for calculating nano seconds */
45 #define MILLION 1000000 /* for calculating micro seconds */
48 GDBusConnection *connection;
49 GDBusConnection *session_conn;
51 guint sid; /* signal subscription id */
52 alarm_cb_t alarm_handler;
55 char *app_service_name;
56 char *app_service_name_mod;
59 enum async_param_type {
61 SET_SYSTIME_WITH_PROPAGATION_DELAY,
73 #define ALARM_TYPE_RELATIVE 0x80000000 /**< relative */
74 #define ALARM_TYPE_WITHCB 0x40000000 /**< withcb */
75 #define ALARM_TYPE_PERIOD 0x10000000 /**< periodic */
77 bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm,
78 alarm_id_t *id, const char *dst_service_name, const char *dst_service_name_mod, int *error_code);
79 bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info,
80 alarm_id_t *alarm_id, bundle *b, int *error_code);
81 bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info,
82 alarm_id_t *alarm_id, notification_h noti, int *error_code);
83 bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id,
84 alarm_info_t *alarm_info, int update_flag, int *error_code);
85 bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
86 bool _send_alarm_delete_all(alarm_context_t context, int *error_code);
87 bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids,
88 GVariantIter **iter, int *num_of_ids, int *error_code);
89 bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, int *error_code);
90 bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, alarm_info_t *alarm_info, int *error_code);
91 bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, time_t* duetime, int *error_code);
92 bool _send_alarm_get_all_info(alarm_context_t context, char ** db_path, int *error_code);
93 bool _send_alarm_reset(alarm_context_t context, int *error_code);
94 bool _remove_from_scheduled_alarm_list(uid_t uid, alarm_id_t alarm_id);
95 bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
96 notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code);
97 bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code);
98 bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, struct timespec new_time, struct timespec req_time, int *error_code);
99 bool _send_alarm_set_time_with_propagation_delay_async(alarm_context_t context, struct timespec new_time, struct timespec req_time, alarm_set_time_cb_t result_cb, void *user_data);
100 bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code);
101 bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref, int method, alarm_id_t *alarm_id, int *error_code);
102 bool _send_alarm_set_time(alarm_context_t context, time_t new_time, int *error_code);
103 bool _send_alarm_set_time_async(alarm_context_t context, time_t new_time, alarm_set_time_cb_t result_cb, void *user_data);
104 bool _send_alarm_set_global(alarm_context_t context, int alarm_id, bool global, int *error_code);
105 bool _send_alarm_get_global(alarm_context_t context, int alarm_id, bool *global, int *error_code);
116 char *app_unique_name;
117 char *app_service_name;
118 char *app_service_name_mod;
119 char *dst_service_name;
120 char *dst_service_name_mod;
126 alarm_info_t alarm_info;
128 periodic_method_e method;
129 long requested_interval;
137 __alarm_info_t *__alarm_info;
146 GDBusConnection *connection;
147 } __alarm_server_context_t;
153 __alarm_info_t *__alarm_info;
154 } __scheduled_alarm_t;
157 char service_name[MAX_SERVICE_NAME_LEN];
162 typedef struct _bg_category_cb_info_t {
165 } bg_category_cb_info_t;
167 void _release_alarm_info_t();
169 void _alarm_set_next_duetime(__alarm_info_t *alarm_info);
170 void _alarm_schedule();
171 void _clear_scheduled_alarm_list();
172 void _add_to_scheduled_alarm_list(__alarm_info_t *__alarm_info);
174 void _alarm_set_timer(int timer, time_t due_time);
175 void _alarm_disable_timer();
176 int _initialize_timer();
178 void _alarm_initialize();
179 time_t _get_periodic_alarm_standard_time(void);
180 bool _can_skip_expired_cb(alarm_id_t alarm_id);
182 void _alarm_expired();
185 int alarm_manager_alarm_create(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
186 int alarm_manager_alarm_create_appsvc(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
187 int alarm_manager_alarm_create_periodic(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
188 int alarm_manager_alarm_create_noti(GVariant *parameters, uid_t uid, pid_t pid, int *alarm_id);
189 int alarm_manager_alarm_delete(GVariant *parameters, uid_t uid, pid_t pid);
190 int alarm_manager_alarm_delete_all(GVariant *parameters, uid_t uid, pid_t pid);
191 int alarm_manager_alarm_update(GVariant *parameters, uid_t uid, pid_t pid);
192 int alarm_manager_alarm_get_number_of_ids(uid_t uid, pid_t pid, int *num_of_ids);
193 int alarm_manager_alarm_get_list_of_ids(GVariant *parameters, uid_t uid, pid_t pid, GVariant **alarm_array, int *num_of_alarm);
194 int alarm_manager_alarm_get_appsvc_info(GVariant *parameters, uid_t uid, gchar **b_data);
195 int alarm_manager_alarm_get_noti_info(GVariant *parameters, uid_t uid, gchar **noti_data);
196 int alarm_manager_alarm_get_info(GVariant *parameters, uid_t uid, alarm_info_t *alarm_info);
197 int alarm_manager_alarm_get_next_duetime(GVariant *parameters, uid_t uid, time_t *duetime);
198 int alarm_manager_alarm_get_all_info(uid_t uid, char **db_path);
199 int alarm_manager_alarm_set_rtc_time(GVariant *parameters);
200 int alarm_manager_alarm_set_time(GVariant* parameters, pid_t pid);
201 int alarm_manager_alarm_set_time_with_propagation_delay(GVariant* parameters, pid_t pid);
202 int alarm_manager_alarm_set_timezone(GVariant* parameters);
203 int alarm_manager_alarm_set_global(GVariant *parameters, uid_t uid);
204 int alarm_manager_alarm_get_global(GVariant *parameters, gboolean *global);
206 #define CHECK_NULL_STRING(x) x ? x : "null"
207 #define STRDUP_WITH_NULLCMP(a) strcmp(a, "null") ? strdup(a) : NULL