const char *dst_service_name, const char *dst_service_name_mod,
int *error_code);
static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
- uid_t uid, int pid, char *bundle_data, int *error_code);
+ long requested_interval, uid_t uid, int pid, char *bundle_data, int *error_code);
static bool __alarm_delete(uid_t uid, alarm_id_t alarm_id, int *error_code);
static bool __alarm_update(uid_t uid, int pid, char *app_service_name, alarm_id_t alarm_id,
static void __initialize();
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);
+bool __get_caller_unique_name(int pid, char *unique_name, uid_t uid);
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
static void __initialize_module_log(void);
}
static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
- uid_t uid, int pid, char *bundle_data, int *error_code)
+ long requested_interval, uid_t uid, int pid, char *bundle_data, int *error_code)
{
time_t current_time;
time_t due_time;
__alarm_info->uid = uid;
__alarm_info->pid = pid;
__alarm_info->alarm_id = -1;
+ __alarm_info->requested_interval = requested_interval;
- if (!__get_caller_unique_name(pid, app_name)) {
+ if (!__get_caller_unique_name(pid, app_name, uid)) {
*error_code = ERR_ALARM_SYSTEM_FAIL;
free(__alarm_info);
return false;
// caller
__alarm_info->quark_caller_pkgid = g_quark_from_string("null");
- if (aul_app_get_appid_bypid(pid, caller_appid, 256) == AUL_R_OK) {
+ if (aul_app_get_appid_bypid_for_uid(pid, caller_appid, 256, uid) == AUL_R_OK) {
if (pkgmgrinfo_appinfo_get_usr_appinfo(caller_appid, uid, &caller_handle) == PMINFO_R_OK) {
if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
if (caller_pkgid) {
__alarm_info->is_ref = is_ref;
// Get caller_appid to get caller's package id. There is no callee.
- if (aul_app_get_appid_bypid(pid, caller_appid, 256) == AUL_R_OK) {
+ if (aul_app_get_appid_bypid_for_uid(pid, caller_appid, 256, uid) == AUL_R_OK) {
if (pkgmgrinfo_appinfo_get_usr_appinfo(caller_appid, uid, &caller_handle) == PMINFO_R_OK) {
if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
if (caller_pkgid) {
__alarm_info->quark_callee_pkgid = g_quark_from_string("null");
SECURE_LOGD("caller_pkgid = %s, callee_pkgid = null", g_quark_to_string(__alarm_info->quark_caller_pkgid));
- if (!__get_caller_unique_name(pid, app_name)) {
+ if (!__get_caller_unique_name(pid, app_name, uid)) {
*error_code = ERR_ALARM_SYSTEM_FAIL;
free(__alarm_info);
return false;
return app.is_ui_app;
}
+static int __compare_api_version(int *result, int pid, uid_t uid) {
+ int ret = 0;
+ pkgmgrinfo_pkginfo_h pkginfo = NULL;
+ char pkgid[512] = {0, };
+ char *pkg_version;
+
+ if (aul_app_get_pkgid_bypid_for_uid(pid, pkgid, sizeof(pkgid), uid) != AUL_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("aul_app_get_pkgid_bypid() is failed. PID %d may not be app.", getpid());
+ } else {
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
+ if (ret != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
+ } else {
+ ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo, &pkg_version);
+ if (ret != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to check api version [%d]\n", ret);
+ }
+ *result = strverscmp(pkg_version, "2.4");
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ }
+ }
+ return ret;
+}
+
static void __alarm_expired()
{
int ret;
if (bundle_add_str(b,"http://tizen.org/appcontrol/data/alarm_id", alarm_id_val)){
ALARM_MGR_EXCEPTION_PRINT("Unable to add alarm id to the bundle\n");
}
- else
- {
- appid = (char *)appsvc_get_appid(b);
- if (appid && !__is_ui_app(appid, __alarm_info->uid)) {
- ALARM_MGR_EXCEPTION_PRINT("ui-application can only be launched\n");
- }
- else 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 {
+ int result = 0;
+
+ if (__compare_api_version(&result, app_pid, __alarm_info->uid) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to check api version\n");
+ result = -1;
}
- else
- {
- if (__have_ui_apps(b, __alarm_info->uid))
- {
- if ( appsvc_usr_run_service(b, 0, NULL, NULL, __alarm_info->uid) < 0)
- {
- ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
+
+ if (result < 0) { /* before 2.4 */
+ if ( appsvc_usr_run_service(b, 0, NULL, NULL, __alarm_info->uid) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
+ }
+ else {
+ ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
+ }
+ } else { /* since 2.4 */
+ appid = (char *)appsvc_get_appid(b);
+ if( (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_NOLAUNCH) && !aul_app_is_running(appid)) {
+ ALARM_MGR_EXCEPTION_PRINT("This alarm is ignored\n");
+ } else if ( !(__alarm_info->alarm_info.alarm_type & ALARM_TYPE_INEXACT) ||
+ !__can_skip_expired_cb(__alarm_info->alarm_id) ) {
+ if (appsvc_usr_run_service(b, 0, NULL, NULL, __alarm_info->uid ) < 0) {
+ ALARM_MGR_EXCEPTION_PRINT("Unable to launch app [%s] \n", appid);
}
- else
- {
- device_display_change_state(DISPLAY_STATE_NORMAL);
+ else {
ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
+ if (__is_ui_app(appid, __alarm_info->uid)) {
+ device_display_change_state(DISPLAY_STATE_NORMAL);
+ }
}
}
- else
- {
- ALARM_MGR_EXCEPTION_PRINT("ui-application can only be launched\n");
- }
-
}
-
}
bundle_free(b);
}
return ALARMMGR_RESULT_SUCCESS;
}
-bool __get_caller_unique_name(int pid, char *unique_name)
+bool __get_caller_unique_name(int pid, char *unique_name, uid_t uid)
{
char caller_appid[256] = {0,};
char caller_cmdline[512] = {0,};
return false;
}
- if (aul_app_get_appid_bypid(pid, caller_appid,
- sizeof(caller_appid)) == AUL_R_OK) {
+ if (aul_app_get_appid_bypid_for_uid(pid, caller_appid,
+ sizeof(caller_appid), uid) == AUL_R_OK) {
/* When a caller is an application, the unique name is appID. */
strncpy(unique_name, caller_appid, strlen(caller_appid));
} else {
return ret;
}
-static long __get_proper_interval(long interval)
+static long __get_proper_interval(long interval, int alarm_type)
{
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
}
}
- while (maxInterval * 2 <= interval) {
+ while (maxInterval * 2 <= interval ||
+ (alarm_type & ALARM_TYPE_INEXACT && maxInterval < MIN_INEXACT_INTERVAL) ) {
maxInterval *= 2;
}
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,
alarm_info.alarm_type = alarm_type;
alarm_info.reserved_info = reserved_info;
- if (!__alarm_create_appsvc(&alarm_info, &alarm_id, uid, pid, bundle_data, &return_code)) {
+ if ((alarm_info.alarm_type & ALARM_TYPE_INEXACT)) {
+ alarm_info.alarm_type |= ALARM_TYPE_PERIOD;
+ alarm_info.mode.u_interval.interval =
+ __get_proper_interval(mode_interval, alarm_info.alarm_type);
+ } else if (mode_interval <= 0){
+ alarm_info.mode.u_interval.interval = 0;
+ }
+
+ 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", strlen("FAIL: CREATE"));
if (is_ref)
alarm_info.mode.u_interval.interval = interval * 60;
else
- alarm_info.mode.u_interval.interval = __get_proper_interval(interval * 60);
+ alarm_info.mode.u_interval.interval = __get_proper_interval(interval * 60, alarm_info.alarm_type);
}
if (!__alarm_create(&alarm_info, &alarm_id, uid, pid, method, interval * 60, is_ref,
uid = __get_caller_uid(name);
pid = __get_caller_pid(name);
- if (!__get_caller_unique_name(pid, app_name)) {
+ if (!__get_caller_unique_name(pid, app_name, uid)) {
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
uid = __get_caller_uid(name);
pid = __get_caller_pid(name);
- if (!__get_caller_unique_name(pid, app_name)) {
+ if (!__get_caller_unique_name(pid, app_name, uid)) {
return_code = ERR_ALARM_SYSTEM_FAIL;
g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", num_of_ids, return_code));
return true;
return true;
}
- if (!__get_caller_unique_name(pid, app_name)) {
+ if (!__get_caller_unique_name(pid, app_name, uid)) {
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;
#include <appsvc.h>
#include <aul.h>
#include <gio/gio.h>
+#include <pkgmgr-info.h>
#ifndef EXPORT_API
#define EXPORT_API __attribute__ ((visibility("default")))
return true;
}
+static int __compare_api_version(int *result, uid_t uid) {
+ int ret = 0;
+ pkgmgrinfo_pkginfo_h pkginfo = NULL;
+ char pkgid[512] = {0, };
+ char *pkg_version;
+
+ if (aul_app_get_pkgid_bypid_for_uid(getpid(), pkgid, sizeof(pkgid), uid) != AUL_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("aul_app_get_pkgid_bypid() is failed. PID %d may not be app.", getpid());
+ } else {
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
+ if (ret != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
+ } else {
+ ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo, &pkg_version);
+ if (ret != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to check api version [%d]\n", ret);
+ }
+ *result = strverscmp(pkg_version, "2.4");
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ }
+ }
+ return ret;
+}
+
+static int __bg_category_func(const char *name, void *user_data)
+{
+ bg_category_cb_info_t *info = (bg_category_cb_info_t *)user_data;
+ ALARM_MGR_LOG_PRINT("appid[%s], bg name = %s", info->appid, name);
+ if (name &&
+ strncmp("enable", name, strlen(name)) && strncmp("disable", name, strlen(name))) {
+ info->has_bg = true;
+ return -1;
+ }
+
+ return 0;
+}
+
+static bool __is_permitted(const char *app_id, int alarm_type)
+{
+ if (app_id == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("app_id is NULL. Only expicit launch is permitted\n");
+ return false;
+ }
+
+ pkgmgrinfo_appinfo_h handle = NULL;
+ int ret;
+ bool _return = false;
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(app_id, getuid(), &handle);
+ if (ret != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get appinfo [%s]\n", app_id);
+ } else {
+ char *app_type = NULL;
+ ret = pkgmgrinfo_appinfo_get_component_type(handle, &app_type);
+ if (app_type && strcmp("uiapp", app_type) == 0) {
+ ALARM_MGR_LOG_PRINT("[%s] is ui application. It is allowed", app_id);
+ _return = true;
+ goto out;
+ } else if (app_type && strcmp("svcapp", app_type) == 0) {
+ ALARM_MGR_LOG_PRINT("[%s] is service application.", app_id);
+
+ bg_category_cb_info_t info = {
+ .appid = app_id,
+ .has_bg = false
+ };
+
+ if (alarm_type & ALARM_TYPE_INEXACT) {
+ _return = true;
+ ret = pkgmgrinfo_appinfo_foreach_background_category(handle, __bg_category_func, &info);
+ if (ret == PMINFO_R_OK && info.has_bg) {
+ ALARM_MGR_LOG_PRINT("[%s] has background categories.", app_id);
+ _return = true;
+ goto out;
+ } else {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to foreach background category. [%s] is not allowed\n", app_id);
+ }
+ }
+ }
+ }
+
+out :
+ if (handle)
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+ return _return;
+}
+
static int __sub_init()
{
GError *error = NULL;
if (repeat == ALARM_REPEAT_MODE_REPEAT
|| repeat == ALARM_REPEAT_MODE_WEEKLY) {
+ if (interval <= 0) {
+ return ERR_ALARM_INVALID_PARAM;
+ }
alarm_info->mode.u_interval.interval = interval;
}
time_t interval, void *bundle_data,
alarm_id_t *alarm_id)
{
- int error_code = 0;;
+ int error_code = 0;
+ int result;
struct timeval current_time;
struct tm duetime_tm;
alarm_info_t alarm_info;
alarm_info.alarm_type = alarm_type;
alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
+ if (__compare_api_version(&result, getuid()) < 0)
+ return ERR_ALARM_SYSTEM_FAIL;
+
+ if (result < 0) {
+ if (alarm_info.alarm_type & ALARM_TYPE_INEXACT) {
+ alarm_info.alarm_type ^= ALARM_TYPE_INEXACT;
+ }
+ } else { //Since 2.4
+ if (!__is_permitted(appid, alarm_info.alarm_type)) {
+ ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted \n", appid);
+ return ERR_ALARM_NOT_PERMITTED_APP;
+ }
+ }
+
gettimeofday(¤t_time, NULL);
if (current_time.tv_usec > 500 * 1000)
alarm_info.start.min = duetime_tm.tm_min;
alarm_info.start.sec = duetime_tm.tm_sec;
+ if ((alarm_info.alarm_type & ALARM_TYPE_INEXACT) && interval < MIN_INEXACT_INTERVAL) {
+ interval = MIN_INEXACT_INTERVAL;
+ }
+
if (interval <= 0) {
alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
alarm_info.mode.u_interval.interval = 0;
ALARM_MGR_EXCEPTION_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
- alarm_info.mode.repeat, alarm_info.mode.u_interval, alarm_info.alarm_type);
+ alarm_info.mode.repeat, alarm_info.mode.u_interval.interval, alarm_info.alarm_type);
if (!_send_alarm_create_appsvc(alarm_context, &alarm_info, alarm_id, b, &error_code)) {
return error_code;
char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
int i = 0;
int j = 0;
+ int result;
int error_code;
struct timeval current_time;
struct tm duetime_tm;
EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id)
{
+ int result;
int error_code = 0;
struct timeval current_time;
struct tm duetime_tm;
alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
alarm_info.alarm_type |= ALARM_TYPE_WITHCB;
+ if (__compare_api_version(&result, getuid()) < 0)
+ return ERR_ALARM_SYSTEM_FAIL;
+
+ if (result < 0) {
+ if (alarm_info.alarm_type & ALARM_TYPE_INEXACT) {
+ alarm_info.alarm_type ^= ALARM_TYPE_INEXACT;
+ }
+ } else { //Since 2.4
+ if (!__is_permitted(appid, alarm_info.alarm_type)) {
+ ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted \n", appid);
+ return ERR_ALARM_NOT_PERMITTED_APP;
+ }
+ }
+
gettimeofday(¤t_time, NULL);
if (current_time.tv_usec > 500 * 1000)