Added application exception list 62/150962/2
authorhyunuktak <hyunuk.tak@samsung.com>
Tue, 19 Sep 2017 07:44:25 +0000 (16:44 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Tue, 19 Sep 2017 07:57:50 +0000 (16:57 +0900)
it is checking internet privilege
it has used pkginfo package
it has a cycle as one day

Change-Id: I4dd8f2d0a8eec709790ea6929f8233c84cbd43a8
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
data/exceptions
packaging/stc-manager.spec
src/CMakeLists.txt
src/monitor/include/stc-app-lifecycle.h
src/monitor/include/stc-exception.h
src/monitor/include/stc-monitor.h
src/monitor/stc-app-lifecycle.c
src/monitor/stc-exception.c
src/monitor/stc-monitor.c
src/stc-manager-plugin.c

index 67ab00e..0429338 100644 (file)
@@ -24,8 +24,7 @@ wifi-loader:sys
 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
index d1befbe..3ed74db 100644 (file)
@@ -1,6 +1,6 @@
 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
@@ -20,6 +20,7 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(vconf)
 BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(pkgmgr-info)
 
 %if %{?enable_database} == YES
 BuildRequires: pkgconfig(sqlite3)
index 1ea3658..295314b 100644 (file)
@@ -7,6 +7,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        dlog
        vconf
        capi-system-info
+       pkgmgr-info
        )
 
 IF("${ENABLE_DATABASE}" STREQUAL "YES")
index 3946c3e..cb5c39e 100755 (executable)
@@ -24,8 +24,8 @@
 
 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);
index da951ae..38a2fd4 100755 (executable)
 #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__ */
index 6601489..ffb64c0 100755 (executable)
@@ -28,6 +28,9 @@
 /* 1 seconds */
 #define CONTR_TIMER_INTERVAL 1
 
+/* 1 day */
+#define EXCNS_TIMER_INTERVAL 86400
+
 /**
  * @brief key for processes tree
  */
@@ -101,6 +104,7 @@ typedef struct {
        GTree *apps;  /**< monitored applications */
        gboolean apps_tree_updated;
        GHashTable *excns_hash;  /**< exception hash table */
+       guint excns_timer_id;
        guint background_state;
 } stc_system_s;
 
index 7f5e035..1787043 100755 (executable)
@@ -198,8 +198,8 @@ static void __reopen_nl_connector_sock(void)
 
 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__;
index 87c3eeb..30579fc 100755 (executable)
  * @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, };
@@ -64,3 +70,95 @@ stc_error_e table_exceptions_foreach(const table_exceptions_info_cb exception_cb
        __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;
+}
index 8bcff31..ed8af13 100755 (executable)
@@ -1516,7 +1516,24 @@ static void __excn_hash_printall(void)
                __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;
@@ -1532,7 +1549,19 @@ static stc_cb_ret_e __insert_exception_cb(const table_exceptions_info *info,
 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)
@@ -1599,6 +1628,10 @@ 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;
 }
 
@@ -1615,6 +1648,12 @@ stc_error_e stc_monitor_deinit(void)
                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;
index 9a8d96b..d1e6d30 100755 (executable)
@@ -117,8 +117,8 @@ int stc_register_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;
        }
 
@@ -128,6 +128,7 @@ int stc_register_state_changed_cb(stc_s *stc,
                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)
@@ -135,17 +136,17 @@ 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);
 }