%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)
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)
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
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;
}
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;
}
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)
#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 <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
-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)
{
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<Ecore_X_Event_Window_Property*>(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<app_use_monitor*>(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<int>(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)
#include <string>
#include <sstream>
-#include <Ecore.h>
+#include <dbus_listener_iface.h>
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;
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();
#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;
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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__ */