launchpad-loader:sys
wrt-loader:sys
dotnet-launcher:sys
-volume:app
-iptables:app
-ip6tables:app
+iptables:sys
+ip6tables:sys
modprobe:inst
-net-cls-release:app
+net-cls-release:sys
Name: stc-manager
Summary: STC(Smart Traffic Control) manager
-Version: 0.0.31
+Version: 0.0.32
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(vconf)
BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(pkgmgr-info)
%if %{?enable_database} == YES
BuildRequires: pkgconfig(sqlite3)
dlog
vconf
capi-system-info
+ pkgmgr-info
)
IF("${ENABLE_DATABASE}" STREQUAL "YES")
stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd,
pid_t pid,
- gchar *app_id,
- gchar *pkg_id,
+ const gchar *app_id,
+ const gchar *pkg_id,
stc_app_type_e app_type);
void stc_app_lifecycle_monitor_init(void);
void stc_app_lifecycle_monitor_deinit(void);
#ifndef __STC_EXCEPTION_H__
#define __STC_EXCEPTION_H__
+#define EXE_TYPE_APPLICATION "app"
+#define EXE_TYPE_INSTRUCTION "inst"
+#define EXE_TYPE_SYSTEM "sys"
+#define EXE_TYPE_SCRIPT "script"
+
typedef struct {
char *process_name;
char *exe_type;
-} table_exceptions_info;
+} stc_exceptions_info;
typedef stc_cb_ret_e
-(*table_exceptions_info_cb)(const table_exceptions_info *info,
+(*stc_exceptions_info_cb)(const stc_exceptions_info *info,
void *user_data);
-stc_error_e table_exceptions_foreach(table_exceptions_info_cb info_cb,
+stc_error_e table_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
+ void *user_data);
+
+stc_error_e pkginfo_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
void *user_data);
#endif /*__STC_EXCEPTION_H__ */
/* 1 seconds */
#define CONTR_TIMER_INTERVAL 1
+/* 1 day */
+#define EXCNS_TIMER_INTERVAL 86400
+
/**
* @brief key for processes tree
*/
GTree *apps; /**< monitored applications */
gboolean apps_tree_updated;
GHashTable *excns_hash; /**< exception hash table */
+ guint excns_timer_id;
guint background_state;
} stc_system_s;
stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd,
pid_t pid,
- gchar *app_id,
- gchar *pkg_id,
+ const gchar *app_id,
+ const gchar *pkg_id,
stc_app_type_e app_type)
{
__STC_LOG_FUNC_ENTER__;
* @file stc-exception.c
*/
+#include <pkgmgr-info.h>
+
#include "stc-manager.h"
#include "stc-exception.h"
#define EXCEPTION_BUF_MAX 64
#define EXCEPTION_STORAGE "/var/lib/stc/exceptions"
-stc_error_e table_exceptions_foreach(const table_exceptions_info_cb exception_cb,
+#define INTERNET_PRIVILEGE "http://tizen.org/privilege/internet"
+
+static GHashTable *g_pkginfo_filter_hash;
+
+stc_error_e table_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
void *user_data)
{
__STC_LOG_FUNC_ENTER__;
stc_error_e error_code = STC_ERROR_NONE;
- table_exceptions_info data;
+ stc_exceptions_info data;
FILE *fp = NULL;
char buf[EXCEPTION_BUF_MAX] = {0, };
__STC_LOG_FUNC_EXIT__;
return error_code;
}
+
+static int __pkginfo_filter_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+ int ret = 0;
+ char *pkgname = NULL;
+
+ ret = pkgmgrinfo_pkginfo_get_pkgname(handle, &pkgname);
+ if (ret == PMINFO_R_OK) {
+ if (g_hash_table_insert(g_pkginfo_filter_hash,
+ g_strdup(pkgname), g_strdup(EXE_TYPE_APPLICATION)) != TRUE)
+ STC_LOGE("Failed to insert hash table");
+ }
+
+ return STC_CONTINUE;
+}
+
+static int __pkginfo_pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+ int ret = 0;
+ char *pkgname = NULL;
+ char *exe_type = NULL;
+ stc_exceptions_info data;
+ const stc_exceptions_info_cb excn_cb = user_data;
+
+ ret = pkgmgrinfo_pkginfo_get_pkgname(handle, &pkgname);
+ if (ret == PMINFO_R_OK) {
+ exe_type = g_hash_table_lookup(g_pkginfo_filter_hash, pkgname);
+ if (exe_type)
+ return STC_CONTINUE;
+
+ data.process_name = pkgname;
+ data.exe_type = EXE_TYPE_APPLICATION;
+
+ if (excn_cb(&data, NULL) == STC_CANCEL)
+ STC_LOGE("Failed to insert hash table");
+ }
+
+ return STC_CONTINUE;
+}
+
+stc_error_e pkginfo_exceptions_foreach(const stc_exceptions_info_cb exception_cb,
+ void *user_data)
+{
+ __STC_LOG_FUNC_ENTER__;
+
+ int ret = 0;
+ int err = STC_ERROR_NONE;
+ pkgmgrinfo_pkginfo_filter_h handle;
+
+ g_pkginfo_filter_hash = g_hash_table_new_full(g_str_hash,
+ g_str_equal, g_free, g_free);
+
+ ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+ ret_value_msg_if(ret != PMINFO_R_OK, STC_ERROR_FAIL,
+ "Failed to create pkginfo filter");
+
+ ret = pkgmgrinfo_pkginfo_filter_add_string(handle,
+ PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE,
+ INTERNET_PRIVILEGE);
+ if (ret != PMINFO_R_OK) {
+ STC_LOGE("Failed to add pkginfo filter string");
+ err = STC_ERROR_FAIL;
+ goto out;
+ }
+
+ ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle,
+ __pkginfo_filter_list_cb, NULL);
+ if (ret != PMINFO_R_OK) {
+ STC_LOGE("Failed to foreach pkginfo filter");
+ err = STC_ERROR_FAIL;
+ goto out;
+ }
+
+ ret = pkgmgrinfo_pkginfo_get_list(__pkginfo_pkg_list_cb, exception_cb);
+ if (ret != PMINFO_R_OK) {
+ STC_LOGE("Failed to get pkginfo list");
+ err = STC_ERROR_FAIL;
+ goto out;
+ }
+
+out:
+ if (g_pkginfo_filter_hash) {
+ g_hash_table_destroy(g_pkginfo_filter_hash);
+ g_pkginfo_filter_hash = NULL;
+ }
+
+ if (handle)
+ pkgmgrinfo_pkginfo_filter_destroy(handle);
+
+ __STC_LOG_FUNC_EXIT__;
+ return err;
+}
__excn_hash_foreach_print, NULL);
}
-static stc_cb_ret_e __insert_exception_cb(const table_exceptions_info *info,
+static gboolean __remove_exception_app(gpointer key, gpointer value,
+ gpointer data)
+{
+ const char *exe_type = value;
+
+ if (g_strcmp0(exe_type, EXE_TYPE_APPLICATION) == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+static void __remove_exception_appall(void)
+{
+ g_hash_table_foreach_remove(g_system->excns_hash,
+ __remove_exception_app, NULL);
+}
+
+static stc_cb_ret_e __insert_exception_cb(const stc_exceptions_info *info,
void *user_data)
{
stc_cb_ret_e ret = STC_CONTINUE;
static void __fill_exceptions_list(void)
{
table_exceptions_foreach(__insert_exception_cb, NULL);
- __excn_hash_printall();
+ pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
+
+ /* __excn_hash_printall(); */
+}
+
+static gboolean __update_exceptions_app_list(void *user_data)
+{
+ __remove_exception_appall();
+ pkginfo_exceptions_foreach(__insert_exception_cb, NULL);
+
+ /* __excn_hash_printall(); */
+
+ return TRUE;
}
stc_error_e stc_monitor_init(void)
__fill_exceptions_list();
__fill_restritions_list();
+ g_system->excns_timer_id = g_timeout_add_seconds(EXCNS_TIMER_INTERVAL,
+ __update_exceptions_app_list,
+ NULL);
+
return STC_ERROR_NONE;
}
g_system->contr_timer_id = 0;
}
+ /* remove exceptions app list update timer */
+ if (g_system->excns_timer_id > 0) {
+ g_source_remove(g_system->excns_timer_id);
+ g_system->excns_timer_id = 0;
+ }
+
/* destroy monitored application tree */
g_tree_destroy(g_system->apps);
g_system->apps = NULL;
__STC_LOG_FUNC_ENTER__;
if (!stc_plugin_enabled) {
- __STC_LOG_FUNC_EXIT__;
STC_LOGE("Plugin wasn't enabled");
+ __STC_LOG_FUNC_EXIT__;
return 0;
}
return 0;
}
+ __STC_LOG_FUNC_EXIT__;
return stc_plugin->register_state_changed_cb(stc, cb, data);
}
int stc_deregister_state_changed_cb(stc_s *stc)
__STC_LOG_FUNC_ENTER__;
if (!stc_plugin_enabled) {
- __STC_LOG_FUNC_EXIT__;
STC_LOGE("Plugin wasn't enabled");
+ __STC_LOG_FUNC_EXIT__;
return 0;
}
if (!stc_plugin) {
- __STC_LOG_FUNC_EXIT__;
STC_LOGE("Plugin wasn't loaded");
+ __STC_LOG_FUNC_EXIT__;
return 0;
}
- __STC_LOG_FUNC_EXIT__;
+ __STC_LOG_FUNC_EXIT__;
return stc_plugin->deregister_state_changed_cb(stc);
}