Add implementation for permission in wayland environment 38/78038/2 accepted/tizen/common/20160704.150002 accepted/tizen/ivi/20160704.091231 accepted/tizen/mobile/20160704.091241 accepted/tizen/tv/20160704.091200 accepted/tizen/wearable/20160704.091220 submit/tizen/20160704.051425
authorJihoon Jung <jh8801.jung@samsung.com>
Mon, 4 Jul 2016 04:53:26 +0000 (13:53 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Mon, 4 Jul 2016 04:55:29 +0000 (13:55 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
Change-Id: I3289958453f5c9474f93fd6c9f490c7bcad17a51

CMakeLists.txt
include/nfc_common.h
packaging/capi-network-nfc.spec
src/nfc_common.c

index bf845a0..6aae7e2 100644 (file)
@@ -23,7 +23,7 @@ SET(service "network")
 SET(submodule "nfc")
 
 # for package file
-SET(dependents "dlog glib-2.0 gio-2.0 nfc-common-lib capi-base-common vconf capi-system-info")
+SET(dependents "dlog glib-2.0 gio-2.0 nfc-common-lib capi-base-common vconf capi-system-info aul libsystemd-daemon")
 SET(pc_dependents "capi-base-common")
 
 SET(fw_name "${project_prefix}-${service}-${submodule}")
index f592d1e..8c205bb 100644 (file)
@@ -24,6 +24,8 @@
 #include <dlog.h>
 #include <vconf.h>
 #include <system_info.h>
+#include <systemd/sd-login.h>
+#include <aul.h>
 
 #include "net_nfc.h"
 #include "nfc.h"
index 9a35b5e..5781242 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-network-nfc
 Summary:    A NFC library in Native API
-Version:    0.3.3
+Version:    0.3.4
 Release:    0
 Group:      Network & Connectivity/NFC
 License:    Apache-2.0
@@ -13,6 +13,8 @@ BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(nfc-common-lib)
+BuildRequires:  pkgconfig(aul)
+BuildRequires:  pkgconfig(libsystemd-daemon)
 
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index 3b47378..ff14b4e 100755 (executable)
 _nfc_context_s gdbus_nfc_context;
 
 /* LCOV_EXCL_START */
+bool nfc_common_get_login_user(uid_t *uid)
+{
+       int i, ret;
+       uid_t *uids;
+       int uid_count;
+
+       uid_count = sd_get_uids(&uids);
+
+       if (uid_count <= 0) {
+               LOGD("sd_get_uids failed [%d]", uid_count);
+               return false;
+       }
+
+       for (i = 0; i < uid_count ; i++) {
+               char *state = NULL;
+
+               ret = sd_uid_get_state(uids[i], &state);
+
+               if (ret < 0) {
+                       LOGD("sd_uid_get_state failed [%d]", ret);
+               } else {
+                       if (!strncmp(state, "online", 6)) {
+                               *uid = uids[i];
+                               free(state);
+                               free(uids);
+                               return true;
+                       }
+               }
+
+               free(state);
+       }
+
+       LOGD("not exist login user");
+
+       free(uids);
+       return false;
+}
+
+int _iter_func(const aul_app_info *info, void *data)
+{
+       uid_t uid = 0;
+       int *pid = (int *)data;
+       int status;
+
+        if (nfc_common_get_login_user(&uid) == false) {
+               LOGD("net_nfc_util_get_login_user is failed");
+               return 0;
+       }
+
+       status = aul_app_get_status_bypid_for_uid(info->pid, uid);
+
+       LOGD("login user is %d, pid is %d, status is %d", (int)uid, info->pid, status);
+
+       if(status == STATUS_VISIBLE || status == STATUS_FOCUS) {
+               *pid = info->pid;
+               return -1;
+       }
+       return 0;
+}
+
 pid_t nfc_common_get_focus_app_pid()
 {
-/*
-       Ecore_X_Window focus;
-       pid_t pid;
+       int ret;
+       uid_t uid = 0;
+        pid_t pid = 0;
+
+       if (nfc_common_get_login_user(&uid) == false) {
+               LOGD("nfc_common_get_login_user is failed");
+               return -1;
+        }
 
-       ecore_x_init(NULL);
+       ret = aul_app_get_all_running_app_info_for_uid(_iter_func, &pid, uid);
 
-       focus = ecore_x_window_focus_get();
-       if (ecore_x_netwm_pid_get(focus, &pid))
+       if (ret == AUL_R_OK) {
                return pid;
-*/
-       return -1;
+       } else {
+               LOGD("aul_app_get_all_running_app_info_for_uid is failed");
+                return -1;
+        }
 }
 
 char * nfc_common_get_bt_address_string(data_h data)
@@ -104,6 +170,8 @@ int nfc_common_convert_error_code(const char *func, int native_error_code)
        case NET_NFC_INSUFFICIENT_STORAGE:
        case NET_NFC_NOT_INITIALIZED:
        case NET_NFC_NOT_REGISTERED:
+       case NET_NFC_NO_DATA_FOUND:
+       case NET_NFC_NOT_ALLOWED_OPERATION:
                error_code = NFC_ERROR_OPERATION_FAILED;
                errorstr = "OPERATION_FAILED";
                break;
@@ -120,9 +188,7 @@ int nfc_common_convert_error_code(const char *func, int native_error_code)
 
        case NET_NFC_OUT_OF_BOUND:
        case NET_NFC_NULL_PARAMETER:
-       case NET_NFC_NOT_ALLOWED_OPERATION:
        case NET_NFC_LLCP_INVALID_SOCKET:
-       case NET_NFC_NO_DATA_FOUND:
                error_code = NFC_ERROR_INVALID_PARAMETER;
                errorstr = "INVALID_PARAMETER";
                break;
@@ -168,6 +234,10 @@ int nfc_common_convert_error_code(const char *func, int native_error_code)
                error_code = NFC_ERROR_NOT_ACTIVATED;
                errorstr = "NOT_ACTIVATED";
                break;
+       case NET_NFC_DATA_CONFLICTED:
+               error_code = NFC_ERROR_DATA_CONFLICTED;
+               errorstr = "DATA_CONFLICTED";
+               break;
        default:
                error_code = NFC_ERROR_OPERATION_FAILED;
                errorstr = "OPERATION_FAILED";