Change implemenation focus app pid 26/64126/1 accepted/tizen/common/20160330.120643 accepted/tizen/ivi/20160330.101523 accepted/tizen/mobile/20160330.101403 accepted/tizen/tv/20160330.101433 accepted/tizen/wearable/20160330.101456 submit/tizen/20160330.082229
authorJihoon Jung <jh8801.jung@samsung.com>
Wed, 30 Mar 2016 07:27:01 +0000 (16:27 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Wed, 30 Mar 2016 07:28:07 +0000 (16:28 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
Change-Id: I6e57f3669068368198e828d93323a7824a37babd

packaging/nfc-manager.spec
src/manager/net_nfc_app_util.c

index ee2850a2c7c8284f2c33bfd15f56ccb34eb8ccd6..af42b49bd96c6d8613ea7f491e59dd44f3f844da 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       nfc-manager
 Summary:    NFC framework manager
-Version:    0.1.145
+Version:    0.1.146
 Release:    0
 Group:      Network & Connectivity/NFC
 License:    Flora-1.1
index 795adc371bb519bd2be61fbe541032084b3e1ec4..f3ba93e5731e696d3e9cfbc5bd0d2da1d521cf81 100755 (executable)
@@ -29,6 +29,7 @@
 #include <openssl/evp.h>
 #include <openssl/bio.h>
 #include <openssl/buffer.h>
+#include <systemd/sd-login.h>
 
 #include <bundle_internal.h>
 #include "appsvc.h"
@@ -1096,17 +1097,74 @@ int net_nfc_app_util_decode_base64(const char *buffer, uint32_t buf_len, uint8_t
        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()