#include <stdlib.h>
#include <signal.h>
#include <glib.h>
+#include <fcntl.h>
#if !GLIB_CHECK_VERSION(2, 31, 0)
#include <glib/gmacros.h>
#endif
+#include <app_context.h>
+#include <app_manager_extension.h>
+
#include "../battery_monitor_stub.h"
#include "bm_power_engine.h"
#include "bm_private.h"
GDBusConnection* bm_get_dbus_connection_obj(void);
+void bd_get_focussed_app_id(char **app_name);
+
+void bm_get_name_from_pid(pid_t pid, char **pname);
+
void bm_data_free(gpointer data);
void bm_atm_free(gpointer data);
#include <ITapiNetwork.h>
#include <glib.h>
#include <device/battery-internal.h>
-#include <app_context.h>
-#include <app_manager_extension.h>
#include "bm_listeners.h"
#include "bm_dbg.h"
GHashTable *app_list = NULL;
-void bd_get_focussed_app_id(char **app_name)
-{
- ENTER;
-
- if (*app_name == NULL) {
- _ERR("invalid storage for app_id");
- return;
- }
-
- int return_val = APP_MANAGER_ERROR_NONE;
-
- app_context_h app_context;
- char *app_id = NULL;
-
- return_val = app_manager_get_focused_app_context(&app_context);
- if (return_val != APP_MANAGER_ERROR_NONE) {
- _ERR("failed to get app-context");
- return;
- }
-
- return_val = app_context_get_app_id(app_context, &app_id);
- if(return_val != APP_MANAGER_ERROR_NONE) {
- _ERR("failed to get app_id");
- app_context_destroy(app_context);
- return;
- }
-
- _DBG("focussed app_id = %s", app_id);
-
- *app_name = app_id;
-
- return_val = app_context_destroy(app_context);
- if (return_val != APP_MANAGER_ERROR_NONE) {
- _ERR("failed to destroy app-context");
- return;
- }
-
- app_context = NULL;
-
- EXIT;
- return;
-}
-
static int bd_listener_set_appId_info(char *app_id)
{
ENTER;
return;
}
-static void _bd_listener_create_lock_event(char *lock_type)
+static void _bd_listener_create_lock_event(char *lock_type, pid_t pid)
{
int val;
static int prev_lock = 0;
+ char *pname = NULL;
if (g_strcmp0(lock_type, "lcdoff") == 0)
val = 0;
else
prev_lock = val;
+ bm_get_name_from_pid(pid, &pname);
+
/* get event object */
- event_pool *event = bd_listener_get_event_obj(LISTEN_POWERLOCKUNLOCK_STATE, val, NULL);
+ event_pool *event = bd_listener_get_event_obj(LISTEN_POWERLOCKUNLOCK_STATE, val, pname);
if (event == NULL) {
_ERR("Failed to get event pool object");
return;
_INFO(" powerlock value changed =%s Pid=%d, timeout=%d", lock_type, pid, timeout);
- _bd_listener_create_lock_event(lock_type);
+ _bd_listener_create_lock_event(lock_type, pid);
EXIT;
return;
_INFO(" powerUnlock value changed =%s Pid=%d, timeout=%d", lock_type, pid, timeout);
- _bd_listener_create_lock_event(lock_type);
+ _bd_listener_create_lock_event(lock_type, pid);
EXIT;
return;
return connection_obj;
}
+void bd_get_focussed_app_id(char **app_name)
+{
+ ENTER;
+
+ int return_val = APP_MANAGER_ERROR_NONE;
+
+ app_context_h app_context;
+ char *app_id = NULL;
+
+ return_val = app_manager_get_focused_app_context(&app_context);
+ if (return_val != APP_MANAGER_ERROR_NONE) {
+ _ERR("failed to get app-context");
+ return;
+ }
+
+ return_val = app_context_get_app_id(app_context, &app_id);
+ if(return_val != APP_MANAGER_ERROR_NONE) {
+ _ERR("failed to get app_id");
+ app_context_destroy(app_context);
+ return;
+ }
+
+ _DBG("focussed app_id = %s", app_id);
+
+ *app_name = app_id;
+
+ return_val = app_context_destroy(app_context);
+ if (return_val != APP_MANAGER_ERROR_NONE) {
+ _ERR("failed to destroy app-context");
+ return;
+ }
+
+ app_context = NULL;
+
+ EXIT;
+ return;
+}
+
+void bm_get_name_from_pid(pid_t pid, char **pname)
+{
+ _INFO("pid = [%d]", pid);
+
+ char *app_id = NULL;
+
+ app_manager_get_app_id(pid, &app_id);
+
+ if (app_id == NULL) { /*it might be a daemon, ex-/usr/bin/batterymonitor-svcd*/
+ char buf[PATH_MAX];
+ int fd, r;
+
+ snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
+
+ fd = open(buf, O_RDONLY);
+ if (fd < 0) {
+ _ERR("process(%d) does not exist now.", pid);
+ return;
+ }
+
+ r = read(fd, buf, PATH_MAX);
+ if ((r >= 0) && (r < PATH_MAX)) {
+ buf[r] = '\0';
+ } else {
+ _ERR("read error");
+ if (close(fd) == -1)
+ _ERR("fd close error");
+ return;
+ }
+
+ if (close(fd) == -1) {
+ _ERR("fd close error");
+ }
+
+ app_id = strdup(buf);
+ }
+
+ *pname = app_id;
+
+ _INFO("pid - [%d], name - [%s]", pid, *pname);
+
+ return;
+}
+
void bm_data_free(gpointer data)
{
ENTER;