Modify AUL related apis for system daemon 98/71598/1 accepted/tizen/common/20160526.150322 accepted/tizen/ivi/20160526.094640 accepted/tizen/mobile/20160526.095032 accepted/tizen/tv/20160526.094704 accepted/tizen/wearable/20160526.094837 submit/tizen/20160526.062526
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 26 May 2016 05:53:05 +0000 (14:53 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Thu, 26 May 2016 05:54:21 +0000 (14:54 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
Change-Id: I8546694e5ced16a64b0e02251291854fbde59e59

src/commonlib/include/net_nfc_util_internal.h
src/commonlib/net_nfc_util.c [changed mode: 0644->0755]
src/manager/net_nfc_app_util.c
src/manager/net_nfc_server_hce.c
src/manager/net_nfc_server_route_table.c

index f7f971268dddfe1ae0c84b1a134bbf1c64943271..322c978b549bfab8e5d1b9a3e5957cc127d0838d 100755 (executable)
@@ -92,6 +92,7 @@ bool net_nfc_util_aid_is_prefix(const char *aid);
 bool net_nfc_util_aid_is_matched(const char *aid_criteria,
        const char *aid_target);
 
+bool net_nfc_util_get_login_user(uid_t *uid);
 bool net_nfc_util_get_pkgid_by_pid(pid_t pid, char *pkgid, size_t len);
 
 bool net_nfc_util_hex_string_to_binary(const char *str, data_s *result);
old mode 100644 (file)
new mode 100755 (executable)
index a627262..ac0657f
@@ -21,6 +21,7 @@
 #include <fcntl.h>
 #include <glib.h>
 #include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
 
 // platform header
 #include "aul.h"
@@ -658,6 +659,43 @@ bool net_nfc_util_aid_is_matched(const char *aid_criteria,
        return result;
 }
 
+bool net_nfc_util_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) {
+               DEBUG_ERR_MSG("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) {
+                       DEBUG_ERR_MSG("sd_uid_get_state failed [%d]", ret);
+               } else {
+                       if (!strncmp(state, "online", 6)) {
+                               *uid = uids[i];
+                               free(state);
+                               free(uids);
+                               return true;
+                       }
+               }
+
+               free(state);
+       }
+
+       DEBUG_ERR_MSG("not exist login user");
+
+       free(uids);
+       return false;
+}
+
 bool net_nfc_util_get_pkgid_by_pid(pid_t pid, char *pkgid, size_t len)
 {
        pkgmgrinfo_appinfo_h appinfo = NULL;
@@ -665,9 +703,16 @@ bool net_nfc_util_get_pkgid_by_pid(pid_t pid, char *pkgid, size_t len)
        char package[1024];
        int ret;
        bool result = false;
+       uid_t uid = 0;
+
+       if (net_nfc_util_get_login_user(&uid) == false) {
+               DEBUG_ERR_MSG("net_nfc_util_get_login_user is failed");
+
+               goto END;
+       }
 
        /* get pkgid id from pid */
-       ret = aul_app_get_pkgname_bypid(pid, package, sizeof(package));
+       ret = aul_app_get_appid_bypid_for_uid(pid, package, sizeof(package), uid);
        if (ret < 0) {
                DEBUG_ERR_MSG("aul_app_get_pkgname_bypid failed [%d]", ret);
 
index f3ba93e5731e696d3e9cfbc5bd0d2da1d521cf81..5875609f47c128cff93d0e50036ca670859d13ce 100755 (executable)
@@ -29,7 +29,6 @@
 #include <openssl/evp.h>
 #include <openssl/bio.h>
 #include <openssl/buffer.h>
-#include <systemd/sd-login.h>
 
 #include <bundle_internal.h>
 #include "appsvc.h"
@@ -803,7 +802,14 @@ static bool _net_nfc_app_util_get_data_from_record(ndef_record_s *record, char *
 void net_nfc_app_util_aul_launch_app(char* package_name, bundle* kb)
 {
        int result = 0;
-       if((result = aul_launch_app(package_name, kb)) < 0)
+       uid_t uid = 0;
+
+       if (net_nfc_util_get_login_user(&uid) == false) {
+               DEBUG_ERR_MSG("net_nfc_util_get_login_user is failed");
+               return;
+       }
+
+       if((result = aul_launch_app_for_uid(package_name, kb, uid)) < 0)
        {
                switch(result)
                {
@@ -1097,48 +1103,21 @@ 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");
+       if (net_nfc_util_get_login_user(&uid) == false) {
+               DEBUG_ERR_MSG("net_nfc_util_get_login_user is failed");
                return 0;
        }
 
        status = aul_app_get_status_bypid_for_uid(info->pid, uid);
 
+       DEBUG_SERVER_MSG("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;
@@ -1152,8 +1131,8 @@ pid_t net_nfc_app_util_get_focus_app_pid()
        uid_t uid = 0;
        int pid = 0;
 
-       if(__find_login_user(&uid) < 0) {
-               DEBUG_ERR_MSG("__find_login_user is failed");
+       if (net_nfc_util_get_login_user(&uid) == false) {
+               DEBUG_ERR_MSG("net_nfc_util_get_login_user is failed");
                return -1;
        }
 
index e05278d1c8bf797f9700599ac48e6dc4ad73d072..66eec90a4f80f2eb35355f7f3f743fabccaf6ed1 100755 (executable)
@@ -964,15 +964,20 @@ static void hce_apdu_thread_func(gpointer user_data)
                                                                bundle *bd;
                                                                char aid[1024];
                                                                int ret;
+                                                               uid_t uid = 0;
                                                                data_s temp_aid = { aid_data, lc };
 
                                                                bd = bundle_create();
                                                                net_nfc_util_binary_to_hex_string(&temp_aid, aid, sizeof(aid));
                                                                appsvc_set_operation(bd, "http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service");
                                                                appsvc_add_data(bd, "data", aid);
-                                                               ret = aul_launch_app(handler->package, bd);
-                                                               if (ret < 0) {
-                                                                       DEBUG_ERR_MSG("aul_launch_app failed, [%d]", ret);
+
+                                                               if (net_nfc_util_get_login_user(&uid) == true) {
+                                                                       ret = aul_launch_app_for_uid(handler->package, bd, uid);
+                                                                       if (ret < 0)
+                                                                               DEBUG_ERR_MSG("aul_launch_app_for_uid failed, uid [%d] ret [%d]", uid, ret);
+                                                               } else {
+                                                                       DEBUG_ERR_MSG("net_nfc_util_get_login_user is failed");
                                                                }
 
                                                                bundle_free(bd);
index 33967a469ab69e9e680014f0d968ddd0ef32a80e..5c7e6964b1238f5fed37c29cdb7408ecbcd64bb4 100755 (executable)
@@ -1116,6 +1116,12 @@ void net_nfc_server_route_table_preferred_handler_dump()
 
        //check match prefered and foreground app
        pid = net_nfc_app_util_get_focus_app_pid();
+
+       if (pid <= 0) {
+               DEBUG_ERR_MSG("focus app is not exist. pid is %d", (int)pid);
+               return;
+       }
+
        net_nfc_util_get_pkgid_by_pid(pid, foreground, sizeof(foreground));
 
        DEBUG_SERVER_MSG("------------------------------");
@@ -1346,6 +1352,7 @@ route_table_handler_t *net_nfc_server_route_table_find_handler_by_id(
        char package[1024];
 
        if (__get_package_name(id, package, sizeof(package)) == true) {
+               DEBUG_SERVER_MSG("caller package_name is %s", package);
                result = net_nfc_server_route_table_find_handler(package);
        } else {
                result = NULL;