From: Mu-Woong Lee Date: Thu, 14 Jan 2016 11:03:47 +0000 (+0900) Subject: Modify the app usage logger to exploit aul signals X-Git-Tag: accepted/tizen/mobile/20160118.044021^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F57021%2F1;p=platform%2Fcore%2Fcontext%2Fcontext-provider.git Modify the app usage logger to exploit aul signals Change-Id: I32fc3885629e3abf2aaf2798d62aa070989c98fd Signed-off-by: Mu-Woong Lee --- diff --git a/packaging/context-provider.spec b/packaging/context-provider.spec index 105f81b..a42991d 100644 --- a/packaging/context-provider.spec +++ b/packaging/context-provider.spec @@ -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 diff --git a/src/device/social/email.cpp b/src/device/social/email.cpp index 2324a4b..c7c8ea5 100644 --- a/src/device/social/email.cpp +++ b/src/device/social/email.cpp @@ -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; } diff --git a/src/statistics/CMakeLists.txt b/src/statistics/CMakeLists.txt index f9f3a65..69df65a 100644 --- a/src/statistics/CMakeLists.txt +++ b/src/statistics/CMakeLists.txt @@ -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/app_use_monitor/active_window_monitor.cpp b/src/statistics/app/active_window_monitor.cpp similarity index 64% rename from src/statistics/app/app_use_monitor/active_window_monitor.cpp rename to src/statistics/app/active_window_monitor.cpp index 1aca2c7..6299508 100644 --- a/src/statistics/app/app_use_monitor/active_window_monitor.cpp +++ b/src/statistics/app/active_window_monitor.cpp @@ -16,26 +16,24 @@ #include #include -#include #include #include #include #include #include -#include "../app_stats_types.h" +#include +#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) + : signal_id(-1) + , last_cleanup_time(0) , last_timestamp(0) , last_pid(-1) { @@ -49,69 +47,48 @@ ctx::app_use_monitor::~app_use_monitor() 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; + 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 (window_property_event_handler) { - ecore_event_handler_del(window_property_event_handler); - window_property_event_handler = NULL; + if (signal_id > 0) { + dbus_server::unsubscribe_system_signal(signal_id); _D("Active window monitoring stopped"); } } -Eina_Bool ctx::app_use_monitor::on_window_property_changed(void* data, int type, void* event) +void ctx::app_use_monitor::on_signal_received(const char* sender, const char* path, const char* iface, const char* name, GVariant* param) { - IF_FAIL_RETURN_TAG(data && event, ECORE_CALLBACK_PASS_ON, _W, "Invalid window event"); - - Ecore_X_Event_Window_Property *property = static_cast(event); - Ecore_X_Atom atom = ecore_x_atom_get("_NET_ACTIVE_WINDOW"); + gint pid = 0; + const gchar *appid = NULL; + const gchar *pkgid = NULL; + const gchar *status = NULL; + const gchar *type = NULL; - IF_FAIL_RETURN(property->atom == atom, ECORE_CALLBACK_PASS_ON); + 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")); - 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(data); - instance->on_active_window_changed(pid); - - return ECORE_CALLBACK_PASS_ON; + on_active_window_changed(appid); } -void ctx::app_use_monitor::on_active_window_changed(int pid) +void ctx::app_use_monitor::on_active_window_changed(std::string app_id) { - IF_FAIL_VOID(last_pid != pid); - _D("Active window changed: PID-%d", pid); + IF_FAIL_VOID(last_app_id != app_id); + _D("New fourground app '%s'", app_id.c_str()); int timestamp = static_cast(time(NULL)); int duration = timestamp - last_timestamp; - if (!last_app_id.empty() > 0 && duration >= MIN_VALID_USE_TIME) + if (!last_app_id.empty() && 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()); + last_app_id = app_id; } void ctx::app_use_monitor::verify_used_app(const char *app_id, int duration) diff --git a/src/statistics/app/app_use_monitor/active_window_monitor.h b/src/statistics/app/active_window_monitor.h similarity index 81% rename from src/statistics/app/app_use_monitor/active_window_monitor.h rename to src/statistics/app/active_window_monitor.h index 443d2bc..685d41c 100644 --- a/src/statistics/app/app_use_monitor/active_window_monitor.h +++ b/src/statistics/app/active_window_monitor.h @@ -19,12 +19,13 @@ #include #include -#include +#include namespace ctx { - class app_use_monitor { + class app_use_monitor : public dbus_listener_iface { private: + int64_t signal_id; int last_cleanup_time; int last_timestamp; int last_pid; @@ -37,8 +38,8 @@ namespace ctx { 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); + 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(); diff --git a/src/statistics/app/app_stats_provider.cpp b/src/statistics/app/app_stats_provider.cpp index 59a224b..7224592 100644 --- a/src/statistics/app/app_stats_provider.cpp +++ b/src/statistics/app/app_stats_provider.cpp @@ -22,12 +22,7 @@ #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/launch_monitor.cpp b/src/statistics/app/app_use_monitor/launch_monitor.cpp deleted file mode 100644 index 4421063..0000000 --- a/src/statistics/app/app_use_monitor/launch_monitor.cpp +++ /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 -#include -#include -#include - -#include -#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(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 index 43b3f66..0000000 --- a/src/statistics/app/app_use_monitor/launch_monitor.h +++ /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 -#include - -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& 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__ */