Modify the app usage logger to exploit aul signals 21/57021/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 14 Jan 2016 11:03:47 +0000 (20:03 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 14 Jan 2016 11:03:47 +0000 (20:03 +0900)
Change-Id: I32fc3885629e3abf2aaf2798d62aa070989c98fd
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
packaging/context-provider.spec
src/device/social/email.cpp
src/statistics/CMakeLists.txt
src/statistics/app/active_window_monitor.cpp [new file with mode: 0644]
src/statistics/app/active_window_monitor.h [new file with mode: 0644]
src/statistics/app/app_stats_provider.cpp
src/statistics/app/app_use_monitor/active_window_monitor.cpp [deleted file]
src/statistics/app/app_use_monitor/active_window_monitor.h [deleted file]
src/statistics/app/app_use_monitor/launch_monitor.cpp [deleted file]
src/statistics/app/app_use_monitor/launch_monitor.h [deleted file]

index 105f81bfc724e39844e25d608613b9aa8d4a3eee..a42991da3362dd325ed870222e423317326d6096 100644 (file)
@@ -8,9 +8,6 @@ Source0:    %{name}-%{version}.tar.gz
 
 %define BUILD_PROFILE %{?profile}%{!?profile:%{?tizen_profile_name}}
 
-# Using the active window hooking for app monitoring, via ecore-x
-%define ACTIVE_WINDOW_HOOK off
-
 BuildRequires: cmake
 
 BuildRequires: pkgconfig(context-common)
@@ -25,11 +22,6 @@ BuildRequires: pkgconfig(pkgmgr)
 BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires: pkgconfig(capi-media-sound-manager)
 
-%if "%{ACTIVE_WINDOW_HOOK}" == "on"
-BuildRequires: pkgconfig(ecore)
-BuildRequires: pkgconfig(ecore-x)
-%endif
-
 %if "%{?BUILD_PROFILE}" == "mobile"
 BuildRequires: pkgconfig(capi-network-bluetooth)
 BuildRequires: pkgconfig(capi-network-wifi)
@@ -82,8 +74,7 @@ export   CFLAGS+=" -DTIZEN_ENGINEER_MODE"
 export CXXFLAGS+=" -DTIZEN_ENGINEER_MODE"
 export   FFLAGS+=" -DTIZEN_ENGINEER_MODE"
 
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} \
-               -DPROFILE=%{?BUILD_PROFILE} -DACTIVE_WINDOW_HOOK=%{ACTIVE_WINDOW_HOOK}
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{?BUILD_PROFILE}
 make %{?jobs:-j%jobs}
 
 %install
index 2324a4b3650f887b5b597c08e59801ce186be1f4..c7c8ea55d73e20aa64a3fae6e7c3b4d1dfa1b068 100644 (file)
@@ -75,7 +75,7 @@ void ctx::social_status_email::on_signal_received(const char* sender, const char
 
 int ctx::social_status_email::subscribe()
 {
-       dbus_signal_id = ctx::dbus_server::signal_subscribe(NULL, NULL, "User.Email.NetworkStatus", "email", this);
+       dbus_signal_id = ctx::dbus_server::subscribe_session_signal(NULL, NULL, "User.Email.NetworkStatus", "email", this);
        IF_FAIL_RETURN_TAG(dbus_signal_id >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed");
        return ERR_NONE;
 }
@@ -83,6 +83,6 @@ int ctx::social_status_email::subscribe()
 
 int ctx::social_status_email::unsubscribe()
 {
-       ctx::dbus_server::signal_unsubscribe(dbus_signal_id);
+       ctx::dbus_server::unsubscribe_session_signal(dbus_signal_id);
        return ERR_NONE;
 }
index f9f3a6517e300cb8886bd4ce54db1fb95ea07e87..69df65aa8e732fa5d787adb5307675878033c830 100644 (file)
@@ -25,14 +25,6 @@ SET(deps "capi-system-runtime-info pkgmgr pkgmgr-info capi-appfw-package-manager
 SET(deps "${deps} capi-appfw-application capi-appfw-app-manager")
 SET(deps "${deps} capi-media-sound-manager")
 
-IF("${ACTIVE_WINDOW_HOOK}" STREQUAL "on")
-       ADD_DEFINITIONS("-D_USE_ACTIVE_WINDOW_HOOKING_")
-       SET(deps "${deps} ecore ecore-x")
-       SET(srcs ${srcs} app/app_use_monitor/active_window_monitor.cpp)
-ELSE("${ACTIVE_WINDOW_HOOK}" STREQUAL "on")
-       SET(srcs ${srcs} app/app_use_monitor/launch_monitor.cpp)
-ENDIF("${ACTIVE_WINDOW_HOOK}" STREQUAL "on")
-
 # Mobile Profile
 IF("${PROFILE}" STREQUAL "mobile")
        FILE(GLOB srcs ${srcs} media/*.cpp)
diff --git a/src/statistics/app/active_window_monitor.cpp b/src/statistics/app/active_window_monitor.cpp
new file mode 100644 (file)
index 0000000..6299508
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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 <sys/types.h>
+#include <time.h>
+#include <app_manager.h>
+
+#include <db_mgr.h>
+#include <json.h>
+#include <types_internal.h>
+#include <system_info.h>
+#include <dbus_server.h>
+#include "app_stats_types.h"
+#include "active_window_monitor.h"
+
+/* Active window changes frequently.
+ * We thus consider the apps being foregrounded at least 3 secs */
+#define MIN_VALID_USE_TIME 2
+#define ONE_DAY_IN_SEC 86400
+
+ctx::app_use_monitor::app_use_monitor()
+       : signal_id(-1)
+       , last_cleanup_time(0)
+       , last_timestamp(0)
+       , last_pid(-1)
+{
+       start_logging();
+}
+
+ctx::app_use_monitor::~app_use_monitor()
+{
+       stop_logging();
+}
+
+bool ctx::app_use_monitor::start_logging()
+{
+       signal_id = dbus_server::subscribe_system_signal(NULL,
+                       "/Org/Tizen/Aul/AppStatus", "org.tizen.aul.AppStatus", "AppStatusChange", this);
+       _D("Active window monitoring started (%lld)", signal_id);
+       return (signal_id > 0);
+}
+
+void ctx::app_use_monitor::stop_logging()
+{
+       if (signal_id > 0) {
+               dbus_server::unsubscribe_system_signal(signal_id);
+               _D("Active window monitoring stopped");
+       }
+}
+
+void ctx::app_use_monitor::on_signal_received(const char* sender, const char* path, const char* iface, const char* name, GVariant* param)
+{
+       gint pid = 0;
+       const gchar *appid = NULL;
+       const gchar *pkgid = NULL;
+       const gchar *status = NULL;
+       const gchar *type = NULL;
+
+       g_variant_get(param, "(i&s&s&s&s)", &pid, &appid, &pkgid, &status, &type);
+       IF_FAIL_VOID(appid && status && type);
+       IF_FAIL_VOID(STR_EQ(status, "fg") && STR_EQ(type, "uiapp"));
+
+       on_active_window_changed(appid);
+}
+
+void ctx::app_use_monitor::on_active_window_changed(std::string app_id)
+{
+       IF_FAIL_VOID(last_app_id != app_id);
+       _D("New fourground app '%s'", app_id.c_str());
+
+       int timestamp = static_cast<int>(time(NULL));
+       int duration = timestamp - last_timestamp;
+
+       if (!last_app_id.empty() && duration >= MIN_VALID_USE_TIME)
+               verify_used_app(last_app_id.c_str(), duration);
+
+       last_timestamp = timestamp;
+       last_app_id = app_id;
+}
+
+void ctx::app_use_monitor::verify_used_app(const char *app_id, int duration)
+{
+       app_info_h app_info = NULL;
+       int err = app_manager_get_app_info(app_id, &app_info);
+       IF_FAIL_VOID_TAG(err == APP_MANAGER_ERROR_NONE && app_info, _E, "app_manager_get_app_info() failed");
+
+       bool nodisp = false;
+       err = app_info_is_nodisplay(app_info, &nodisp);
+       IF_FAIL_CATCH_TAG(err == APP_MANAGER_ERROR_NONE, _E, "app_info_is_nodisplay() failed");
+       IF_FAIL_CATCH(!nodisp);
+
+       insert_log(app_id, duration);
+
+CATCH:
+       if (app_info)
+               app_info_destroy(app_info);
+}
+
+void ctx::app_use_monitor::insert_log(const char *app_id, int duration)
+{
+       int audiojack;
+       int system_volume;
+       int media_volume;
+       std::string bssid;
+
+       std::stringstream cols;
+       std::stringstream vals;
+
+       /* App ID */
+       cols << STATS_APP_ID << ",";
+       vals << "'" << app_id << "',";
+
+       /* Audio Jack */
+       if (ctx::system_info::get_audio_jack_state(&audiojack)) {
+               cols << STATS_AUDIO_JACK << ",";
+               vals << audiojack << ",";
+       }
+
+       /* Volume */
+       if (ctx::system_info::get_volume(&system_volume, &media_volume)) {
+               cols << STATS_SYSTEM_VOLUME << "," << STATS_MEDIA_VOLUME << ",";
+               vals << system_volume << "," << media_volume << ",";
+       }
+
+       /* BSSID */
+       if (ctx::system_info::get_wifi_bssid(bssid)) {
+               cols << STATS_BSSID << ",";
+               vals << "'" << bssid << "',";
+       }
+
+       /* Time */
+       cols << STATS_UNIV_TIME << ",";
+       vals << "(strftime('%s', 'now')) - " << duration << ",";
+
+       cols << STATS_LOCAL_TIME << ",";
+       vals << "(strftime('%s', 'now', 'localtime')) - " << duration << ",";
+
+       /* Duration */
+       cols << STATS_DURATION;
+       vals << duration;
+
+       std::stringstream query;
+       append_cleanup_query(query);
+       query << "INSERT INTO " << APP_TABLE_USAGE_LOG << " ("
+               << cols.str() << ") VALUES (" << vals.str() << ")";
+
+       db_manager::execute(0, query.str().c_str(), NULL);
+}
+
+void ctx::app_use_monitor::append_cleanup_query(std::stringstream &query)
+{
+       IF_FAIL_VOID(last_timestamp - last_cleanup_time >= ONE_DAY_IN_SEC);
+
+       last_cleanup_time = last_timestamp;
+
+       query << "DELETE FROM " APP_TABLE_USAGE_LOG " WHERE " \
+               STATS_UNIV_TIME " < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD << ";";
+}
diff --git a/src/statistics/app/active_window_monitor.h b/src/statistics/app/active_window_monitor.h
new file mode 100644 (file)
index 0000000..685d41c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __CONTEXT_APP_USE_MONITOR_H__
+#define __CONTEXT_APP_USE_MONITOR_H__
+
+#include <string>
+#include <sstream>
+#include <dbus_listener_iface.h>
+
+namespace ctx {
+
+       class app_use_monitor : public dbus_listener_iface {
+       private:
+               int64_t signal_id;
+               int last_cleanup_time;
+               int last_timestamp;
+               int last_pid;
+               std::string last_app_id;
+
+               bool start_logging(void);
+               void stop_logging(void);
+
+               void verify_used_app(const char *app_id, int duration);
+               void insert_log(const char *app_id, int duration);
+               void append_cleanup_query(std::stringstream &query);
+
+               void on_active_window_changed(std::string app_id);
+               void on_signal_received(const char* sender, const char* path, const char* iface, const char* name, GVariant* param);
+
+       public:
+               app_use_monitor();
+               ~app_use_monitor();
+       };      /* class app_use_monitor */
+
+}      /* namespace ctx */
+
+#endif /* __CONTEXT_APP_USE_MONITOR_H__ */
index 59a224bf2e9c448419dc9aad03fb4eff90766e68..7224592b53ee0fa605cfa54fbbee35668e6138fb 100644 (file)
 
 #include "db_init.h"
 #include "install_monitor.h"
-
-#ifdef _USE_ACTIVE_WINDOW_HOOKING_
-#include "app_use_monitor/active_window_monitor.h"
-#else
-#include "app_use_monitor/launch_monitor.h"
-#endif
+#include "active_window_monitor.h"
 
 static ctx::app_install_monitor *install_mon = NULL;
 static ctx::app_use_monitor *launch_mon = NULL;
diff --git a/src/statistics/app/app_use_monitor/active_window_monitor.cpp b/src/statistics/app/app_use_monitor/active_window_monitor.cpp
deleted file mode 100644 (file)
index 1aca2c7..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * 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 <sys/types.h>
-#include <time.h>
-#include <Ecore_X.h>
-#include <app_manager.h>
-
-#include <db_mgr.h>
-#include <json.h>
-#include <types_internal.h>
-#include <system_info.h>
-#include "../app_stats_types.h"
-#include "active_window_monitor.h"
-
-/* Active window changes frequently.
- * We thus consider the apps being foregrounded at least 3 secs */
-#define MIN_VALID_USE_TIME 2
-
-#define ONE_DAY_IN_SEC 86400
-
-static Ecore_Event_Handler *window_property_event_handler = NULL;
-
-ctx::app_use_monitor::app_use_monitor()
-       : last_cleanup_time(0)
-       , last_timestamp(0)
-       , last_pid(-1)
-{
-       start_logging();
-}
-
-ctx::app_use_monitor::~app_use_monitor()
-{
-       stop_logging();
-}
-
-bool ctx::app_use_monitor::start_logging()
-{
-       /* This ecore_x based approach does not work with virtualization features */
-       if(window_property_event_handler == NULL) {
-               ecore_x_init(NULL);
-               ecore_x_event_mask_set(ecore_x_window_root_first_get(), ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
-               window_property_event_handler = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY, on_window_property_changed, this);
-               IF_FAIL_RETURN_TAG(window_property_event_handler, false, _E, "ecore_event_handler_add() failed");
-               _D("Active window monitoring started");
-       }
-
-       return true;
-}
-
-void ctx::app_use_monitor::stop_logging()
-{
-       if (window_property_event_handler) {
-               ecore_event_handler_del(window_property_event_handler);
-               window_property_event_handler = NULL;
-               _D("Active window monitoring stopped");
-       }
-}
-
-Eina_Bool ctx::app_use_monitor::on_window_property_changed(void* data, int type, void* event)
-{
-       IF_FAIL_RETURN_TAG(data && event, ECORE_CALLBACK_PASS_ON, _W, "Invalid window event");
-
-       Ecore_X_Event_Window_Property *property = static_cast<Ecore_X_Event_Window_Property*>(event);
-       Ecore_X_Atom atom = ecore_x_atom_get("_NET_ACTIVE_WINDOW");
-
-       IF_FAIL_RETURN(property->atom == atom, ECORE_CALLBACK_PASS_ON);
-
-       int pid = 0;
-       Ecore_X_Window win = 0;
-
-       ecore_x_window_prop_window_get(property->win, atom, &win, 1);
-       ecore_x_netwm_pid_get(win, &pid);
-
-       IF_FAIL_RETURN_TAG(pid > 0, ECORE_CALLBACK_PASS_ON, _W, "Invalid pid");
-
-       app_use_monitor *instance = static_cast<app_use_monitor*>(data);
-       instance->on_active_window_changed(pid);
-
-       return ECORE_CALLBACK_PASS_ON;
-}
-
-void ctx::app_use_monitor::on_active_window_changed(int pid)
-{
-       IF_FAIL_VOID(last_pid != pid);
-       _D("Active window changed: PID-%d", pid);
-
-       int timestamp = static_cast<int>(time(NULL));
-       int duration = timestamp - last_timestamp;
-
-       if (!last_app_id.empty() > 0 && duration >= MIN_VALID_USE_TIME)
-               verify_used_app(last_app_id.c_str(), duration);
-
-       last_timestamp = timestamp;
-       last_pid = pid;
-
-       char *app_id = NULL;
-       app_manager_get_app_id(pid, &app_id);
-       last_app_id = (app_id ? app_id : "");
-       g_free(app_id);
-       _D("Current Active App: %s", last_app_id.c_str());
-}
-
-void ctx::app_use_monitor::verify_used_app(const char *app_id, int duration)
-{
-       app_info_h app_info = NULL;
-       int err = app_manager_get_app_info(app_id, &app_info);
-       IF_FAIL_VOID_TAG(err == APP_MANAGER_ERROR_NONE && app_info, _E, "app_manager_get_app_info() failed");
-
-       bool nodisp = false;
-       err = app_info_is_nodisplay(app_info, &nodisp);
-       IF_FAIL_CATCH_TAG(err == APP_MANAGER_ERROR_NONE, _E, "app_info_is_nodisplay() failed");
-       IF_FAIL_CATCH(!nodisp);
-
-       insert_log(app_id, duration);
-
-CATCH:
-       if (app_info)
-               app_info_destroy(app_info);
-}
-
-void ctx::app_use_monitor::insert_log(const char *app_id, int duration)
-{
-       int audiojack;
-       int system_volume;
-       int media_volume;
-       std::string bssid;
-
-       std::stringstream cols;
-       std::stringstream vals;
-
-       /* App ID */
-       cols << STATS_APP_ID << ",";
-       vals << "'" << app_id << "',";
-
-       /* Audio Jack */
-       if (ctx::system_info::get_audio_jack_state(&audiojack)) {
-               cols << STATS_AUDIO_JACK << ",";
-               vals << audiojack << ",";
-       }
-
-       /* Volume */
-       if (ctx::system_info::get_volume(&system_volume, &media_volume)) {
-               cols << STATS_SYSTEM_VOLUME << "," << STATS_MEDIA_VOLUME << ",";
-               vals << system_volume << "," << media_volume << ",";
-       }
-
-       /* BSSID */
-       if (ctx::system_info::get_wifi_bssid(bssid)) {
-               cols << STATS_BSSID << ",";
-               vals << "'" << bssid << "',";
-       }
-
-       /* Time */
-       cols << STATS_UNIV_TIME << ",";
-       vals << "(strftime('%s', 'now')) - " << duration << ",";
-
-       cols << STATS_LOCAL_TIME << ",";
-       vals << "(strftime('%s', 'now', 'localtime')) - " << duration << ",";
-
-       /* Duration */
-       cols << STATS_DURATION;
-       vals << duration;
-
-       std::stringstream query;
-       append_cleanup_query(query);
-       query << "INSERT INTO " << APP_TABLE_USAGE_LOG << " ("
-               << cols.str() << ") VALUES (" << vals.str() << ")";
-
-       db_manager::execute(0, query.str().c_str(), NULL);
-}
-
-void ctx::app_use_monitor::append_cleanup_query(std::stringstream &query)
-{
-       IF_FAIL_VOID(last_timestamp - last_cleanup_time >= ONE_DAY_IN_SEC);
-
-       last_cleanup_time = last_timestamp;
-
-       query << "DELETE FROM " APP_TABLE_USAGE_LOG " WHERE " \
-               STATS_UNIV_TIME " < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD << ";";
-}
diff --git a/src/statistics/app/app_use_monitor/active_window_monitor.h b/src/statistics/app/app_use_monitor/active_window_monitor.h
deleted file mode 100644 (file)
index 443d2bc..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#ifndef __CONTEXT_APP_USE_MONITOR_H__
-#define __CONTEXT_APP_USE_MONITOR_H__
-
-#include <string>
-#include <sstream>
-#include <Ecore.h>
-
-namespace ctx {
-
-       class app_use_monitor {
-       private:
-               int last_cleanup_time;
-               int last_timestamp;
-               int last_pid;
-               std::string last_app_id;
-
-               bool start_logging(void);
-               void stop_logging(void);
-
-               void verify_used_app(const char *app_id, int duration);
-               void insert_log(const char *app_id, int duration);
-               void append_cleanup_query(std::stringstream &query);
-
-               void on_active_window_changed(int pid);
-               static Eina_Bool on_window_property_changed(void* data, int type, void* event);
-
-       public:
-               app_use_monitor();
-               ~app_use_monitor();
-       };      /* class app_use_monitor */
-
-}      /* namespace ctx */
-
-#endif /* __CONTEXT_APP_USE_MONITOR_H__ */
diff --git a/src/statistics/app/app_use_monitor/launch_monitor.cpp b/src/statistics/app/app_use_monitor/launch_monitor.cpp
deleted file mode 100644 (file)
index 4421063..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * 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 <sstream>
-#include <db_mgr.h>
-#include <json.h>
-#include <types_internal.h>
-
-#include <system_info.h>
-#include "../app_stats_types.h"
-#include "launch_monitor.h"
-
-ctx::app_use_monitor::app_use_monitor()
-{
-       start_logging();
-}
-
-ctx::app_use_monitor::~app_use_monitor()
-{
-       stop_logging();
-}
-
-bool ctx::app_use_monitor::start_logging()
-{
-       int err = app_manager_set_app_context_event_cb(app_context_event_cb, this);
-       IF_FAIL_RETURN_TAG(err == APP_MANAGER_ERROR_NONE, false, _E, "app_manager_set_app_context_event_cb() failed");
-       return true;
-}
-
-void ctx::app_use_monitor::stop_logging()
-{
-       app_manager_unset_app_context_event_cb();
-}
-
-void ctx::app_use_monitor::app_context_event_cb(app_context_h app_context, app_context_event_e event, void *user_data)
-{
-       char *app_id = NULL;
-       int err = app_context_get_app_id(app_context, &app_id);
-       IF_FAIL_VOID_TAG(err == APP_MANAGER_ERROR_NONE, _E, "app_context_get_app_id() failed");
-
-       app_use_monitor *monitor = static_cast<app_use_monitor*>(user_data);
-
-       if (event == APP_CONTEXT_EVENT_LAUNCHED) {
-               monitor->log_launch_event(app_id);
-       } else if (event == APP_CONTEXT_EVENT_TERMINATED) {
-               monitor->log_terminate_event(app_id);
-       }
-       g_free(app_id);
-}
-
-void ctx::app_use_monitor::log_launch_event(const char* app_id)
-{
-       int audiojack;
-       int system_volume;
-       int media_volume;
-       std::string bssid;
-       json data;
-       data.set(NULL, STATS_APP_ID, app_id);
-
-       if (ctx::system_info::get_audio_jack_state(&audiojack))
-               data.set(NULL, STATS_AUDIO_JACK, audiojack);
-
-       if (ctx::system_info::get_volume(&system_volume, &media_volume)) {
-               data.set(NULL, STATS_SYSTEM_VOLUME, system_volume);
-               data.set(NULL, STATS_MEDIA_VOLUME, media_volume);
-       }
-
-       if (ctx::system_info::get_wifi_bssid(bssid))
-               data.set(NULL, STATS_BSSID, bssid);
-
-       db_manager::insert(0, APP_TABLE_USAGE_LOG, data, NULL);
-}
-
-void ctx::app_use_monitor::log_terminate_event(const char* app_id)
-{
-       std::stringstream query;
-       query <<
-               "UPDATE " APP_TABLE_USAGE_LOG \
-               " SET " STATS_DURATION " = strftime('%s', 'now') - " STATS_UNIV_TIME \
-               " WHERE " STATS_COL_ROW_ID " = (" \
-                       "SELECT MAX(" STATS_COL_ROW_ID ") FROM " APP_TABLE_USAGE_LOG \
-                       " WHERE " STATS_APP_ID " = '" << app_id << "'" \
-                       " AND " STATS_DURATION " = 0)";
-       db_manager::execute(0, query.str().c_str(), NULL);
-}
diff --git a/src/statistics/app/app_use_monitor/launch_monitor.h b/src/statistics/app/app_use_monitor/launch_monitor.h
deleted file mode 100644 (file)
index 43b3f66..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * 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.
- */
-
-#ifndef __CONTEXT_APP_USE_MONITOR_H__
-#define __CONTEXT_APP_USE_MONITOR_H__
-
-#include <app_manager.h>
-#include <db_listener_iface.h>
-
-namespace ctx {
-
-       class app_use_monitor : public db_listener_iface {
-       private:
-               bool start_logging(void);
-               void stop_logging(void);
-
-               void log_launch_event(const char* app_id);
-               void log_terminate_event(const char* app_id);
-
-               void on_creation_result_received(unsigned int query_id, int error) {}
-               void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {}
-               void on_query_result_received(unsigned int query_id, int error, std::vector<json>& records) {}
-
-               static void app_context_event_cb(app_context_h app_context, app_context_event_e event, void *user_data);
-
-       public:
-               app_use_monitor();
-               ~app_use_monitor();
-       };      /* class app_use_monitor */
-
-}      /* namespace ctx */
-
-#endif /* __CONTEXT_APP_USE_MONITOR_H__ */