#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
+#include <systemd/sd-login.h>
#include <bundle_internal.h>
#include "appsvc.h"
return ret;
}
+static int __find_login_user(uid_t *uid)
+{
+ uid_t *uids;
+ int ret, i;
+ char *state;
+
+ ret = sd_get_uids(&uids);
+ if (ret <= 0)
+ return -1;
+
+ for (i = 0; i < ret ; i++) {
+ if (sd_uid_get_state(uids[i], &state) < 0) {
+ free(uids);
+ return -1;
+ } else {
+ if (!strncmp(state, "online", 6)) {
+ *uid = uids[i];
+ free(uids);
+ free(state);
+ return 0;
+ }
+ }
+ }
+
+ free(uids);
+ free(state);
+ return -1;
+}
+
+int _iter_func(const aul_app_info *info, void *data)
+{
+ uid_t uid = 0;
+ int *pid = (int *)data;
+ int status;
+
+ if(__find_login_user(&uid) < 0) {
+ DEBUG_ERR_MSG("__find_login_user is failed");
+ return 0;
+ }
+
+ status = aul_app_get_status_bypid_for_uid(info->pid, uid);
+
+ if(status == STATUS_VISIBLE || status == STATUS_FOCUS) {
+ *pid = info->pid;
+ return -1;
+ }
+ return 0;
+}
+
pid_t net_nfc_app_util_get_focus_app_pid()
{
-/* Todo : ecore_x_window_focus_get is failed
- ecore_x_init(":0");
+ int ret;
+ uid_t uid = 0;
+ int pid = 0;
- focus = ecore_x_window_focus_get();
- if (ecore_x_netwm_pid_get(focus, &pid))
- return pid;
-*/
+ if(__find_login_user(&uid) < 0) {
+ DEBUG_ERR_MSG("__find_login_user is failed");
+ return -1;
+ }
- return -1;
+ ret = aul_app_get_all_running_app_info_for_uid(_iter_func, &pid, uid);
+
+ if (ret == AUL_R_OK) {
+ return pid;
+ } else {
+ DEBUG_ERR_MSG("aul_app_get_all_running_app_info_for_uid is failed");
+ return -1;
+ }
}
bool net_nfc_app_util_check_launch_state()