Add Implementation of NFC configure discovery 83/192883/2 accepted/tizen/unified/20181113.085906 accepted/tizen/unified/20181114.191312 submit/tizen/20181112.101238 submit/tizen/20181114.021524
authorJihoon Jung <jh8801.jung@samsung.com>
Mon, 12 Nov 2018 08:12:46 +0000 (17:12 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Mon, 12 Nov 2018 08:20:32 +0000 (17:20 +0900)
Change-Id: Ia117aed4e0461ef011f703e3f2e91a76f4c1c74c
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
src/commonlib/include/net_nfc_util_internal.h
src/commonlib/net_nfc.xml
src/commonlib/net_nfc_util.c
src/manager/net_nfc_app_util.c
src/manager/net_nfc_server_hce.c
src/manager/net_nfc_server_manager.c

index 72f3b67ca3bba23e448135809bfd540c72a00fee..481baebacb5da9687e2cd74097a057074a2442d2 100644 (file)
@@ -82,7 +82,7 @@ bool net_nfc_util_aid_check_validity(const char *aid);
 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);
+void 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);
index 1bea6393570bcd36a01c1e35c226caae171fe131..2ffc09eebad5f6072c4460e7fb90db434c18978b 100644 (file)
       <arg type="u" name="state" direction="out" />
     </method>
 
+    <!--
+      ConfigureDiscovery
+    -->
+    <method name="ConfigureDiscovery">
+      <arg type="i" name="mode" direction="in" />
+      <arg type="i" name="result" direction="out" />
+    </method>
+
     <!--
       Activated
     -->
index cf2e8fbef1f3f20b0e66cce0b139d68fe1b4998f..d60678d4a5d1d0ce74e5619598e4223935782a4b 100644 (file)
@@ -491,16 +491,17 @@ bool net_nfc_util_aid_is_matched(const char *aid_criteria, const char *aid_targe
        return result;
 }
 
-bool net_nfc_util_get_login_user(uid_t * uid)
+void net_nfc_util_get_login_user(uid_t * uid)
 {
        int i, ret;
        uid_t *uids;
        int uid_count;
 
+       *uid = 5001;
+
        uid_count = sd_get_uids(&uids);
        if (uid_count <= 0) {
-               DEBUG_ERR_MSG("sd_get_uids failed [%d]", uid_count);
-               return false;
+               return;
        }
 
        for (i = 0; i < uid_count; i++) {
@@ -508,24 +509,20 @@ bool net_nfc_util_get_login_user(uid_t * uid)
 
                ret = sd_uid_get_state(uids[i], &state);
 
-               if (ret < 0) {
-                       DEBUG_ERR_MSG("sd_uid_get_state failed [%d]", ret);
-               } else {
+               if (ret >= 0) {
                        if (!strncmp(state, "online", 6)) {
                                *uid = uids[i];
                                free(state);
                                free(uids);
-                               return true;
+                               return;
                        }
                }
 
                free(state);
        }
 
-       DEBUG_ERR_MSG("not exist login user");
-
        free(uids);
-       return false;
+       return;
 }
 
 bool net_nfc_util_get_pkgid_by_pid(pid_t pid, char *pkgid, size_t len)
@@ -537,11 +534,7 @@ bool net_nfc_util_get_pkgid_by_pid(pid_t pid, char *pkgid, size_t len)
        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;
-       }
+       net_nfc_util_get_login_user(&uid);
 
        /* get pkgid id from pid */
        ret = aul_app_get_appid_bypid_for_uid(pid, package, sizeof(package), uid);
index 3ec68ebeed79dab20a4195967e61a2017c469348..72068dafbc8392df2edaa8b3ac59a843563a1d34 100644 (file)
@@ -708,10 +708,7 @@ void net_nfc_app_util_aul_launch_app(char *package_name, bundle * kb)
        int result = 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;
-       }
+       net_nfc_util_get_login_user(&uid);
 
        if ((result = aul_launch_app_for_uid(package_name, kb, uid)) < 0) {
                switch (result) {
@@ -856,10 +853,10 @@ int net_nfc_app_util_launch_se_transaction_app(net_nfc_se_type_e se_type, uint8_
                appsvc_add_data(bd, "data", param_string);
        }
 
-       if (net_nfc_util_get_login_user(&uid) == true) {
-               SECURE_MSG("launch app uid : %d", uid);
-               appsvc_usr_run_service(bd, 0, NULL, NULL, uid);
-       }
+       net_nfc_util_get_login_user(&uid);
+
+       SECURE_MSG("launch app uid : %d", uid);
+       appsvc_usr_run_service(bd, 0, NULL, NULL, uid);
 
        bundle_free(bd);
 
@@ -911,10 +908,10 @@ int net_nfc_app_util_launch_se_off_host_apdu_service_app(net_nfc_se_type_e se_ty
                appsvc_add_data(bd, "data", param_string);
        }
 
-       if (net_nfc_util_get_login_user(&uid) == true) {
-               SECURE_MSG("launch app uid : %d", uid);
-               appsvc_usr_run_service(bd, 0, NULL, NULL, uid);
-       }
+       net_nfc_util_get_login_user(&uid);
+
+       SECURE_MSG("launch app uid : %d", uid);
+       appsvc_usr_run_service(bd, 0, NULL, NULL, uid);
 
        bundle_free(bd);
 
@@ -954,10 +951,10 @@ int net_nfc_app_util_launch_se_transaction_app_by_aid(net_nfc_se_type_e se_type,
        }
 
        if (handler != NULL) {
-               if (net_nfc_util_get_login_user(&uid) == true) {
-                       SECURE_MSG("package name : %s, launch app uid : %d", handler->package, uid);
-                       aul_launch_app_for_uid(handler->package, bd, uid);
-               }
+               net_nfc_util_get_login_user(&uid);
+
+               SECURE_MSG("package name : %s, launch app uid : %d", handler->package, uid);
+               aul_launch_app_for_uid(handler->package, bd, uid);
        }
 
        bundle_free(bd);
@@ -1045,10 +1042,7 @@ int _iter_func(const aul_app_info * info, void *data)
        int *pid = (int *)data;
        int status;
 
-       if (net_nfc_util_get_login_user(&uid) == false) {
-               DEBUG_ERR_MSG("net_nfc_util_get_login_user is failed");
-               return 0;
-       }
+       net_nfc_util_get_login_user(&uid);
 
        status = aul_app_get_status_bypid_for_uid(info->pid, uid);
 
@@ -1067,10 +1061,7 @@ pid_t net_nfc_app_util_get_focus_app_pid()
        uid_t uid = 0;
        int pid = 0;
 
-       if (net_nfc_util_get_login_user(&uid) == false) {
-               DEBUG_ERR_MSG("net_nfc_util_get_login_user is failed");
-               return -1;
-       }
+       net_nfc_util_get_login_user(&uid);
 
        ret = aul_app_get_all_running_app_info_for_uid(_iter_func, &pid, uid);
 
index eb1f1801735e9d9b9ad19faee6724ff5814cf0a7..23898e076b2c65c3d7a203db54a46b660a0401ae 100644 (file)
@@ -878,24 +878,22 @@ static void hce_apdu_thread_func(gpointer user_data)
                                                                appsvc_set_operation(bd, "http://tizen.org/appcontrol/operation/nfc/card_emulation/host_apdu_service");
                                                                appsvc_add_data(bd, "data", aid);
 
-                                                               if (net_nfc_util_get_login_user(&uid) == true) {
-                                                                       char *app_id;
-                                                                       pkgmgrinfo_pkginfo_h pkgmgr_handle;
+                                                               char *app_id;
+                                                               pkgmgrinfo_pkginfo_h pkgmgr_handle;
 
-                                                                       ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(handler->package, uid, &pkgmgr_handle);
+                                                               net_nfc_util_get_login_user(&uid);
+
+                                                               ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(handler->package, uid, &pkgmgr_handle);
+                                                               if (ret == PMINFO_R_OK) {
+                                                                       ret = pkgmgrinfo_pkginfo_get_mainappid(pkgmgr_handle, &app_id);
                                                                        if (ret == PMINFO_R_OK) {
-                                                                               ret = pkgmgrinfo_pkginfo_get_mainappid(pkgmgr_handle, &app_id);
-                                                                               if (ret == PMINFO_R_OK) {
-                                                                                       DEBUG_SERVER_MSG("appid is %s", app_id);
-                                                                                       ret = aul_launch_app_for_uid(app_id, bd, uid);
-                                                                                       if (ret < 0)
-                                                                                               DEBUG_ERR_MSG("aul_launch_app_for_uid failed, uid [%d] ret [%d]", uid, ret);
-                                                                               }
+                                                                               DEBUG_SERVER_MSG("appid is %s", app_id);
+                                                                               ret = aul_launch_app_for_uid(app_id, bd, uid);
+                                                                               if (ret < 0)
+                                                                                       DEBUG_ERR_MSG("aul_launch_app_for_uid failed, uid [%d] ret [%d]", uid, ret);
                                                                        }
-                                                                       pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgr_handle);
-                                                               } else {
-                                                                       DEBUG_ERR_MSG("net_nfc_util_get_login_user is failed");
                                                                }
+                                                               pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgr_handle);
 
                                                                bundle_free(bd);
                                                        }
index 7d40d988460e99f04f65f8815887563a822ee7c1..8f40bf6393dad49d2246919aaeb18d2d9468722d 100644 (file)
@@ -43,6 +43,14 @@ struct _ManagerActivationData {
        gboolean is_active;
 };
 
+typedef struct _ManagerConfigureDiscoveryData ManagerConfigureDiscoveryData;
+
+struct _ManagerConfigureDiscoveryData {
+       NetNfcGDbusManager *manager;
+       GDBusMethodInvocation *invocation;
+       gint mode;
+};
+
 static NetNfcGDbusManager *manager_skeleton = NULL;
 
 static net_nfc_error_e manager_active(void);
@@ -277,7 +285,93 @@ static gboolean manager_handle_get_server_state(NetNfcGDbusManager * manager, GD
 
        return TRUE;
 }
-/* LCOV_EXCL_STOP */
+
+static void manager_handle_configure_discovery_thread_func(gpointer user_data)
+{
+       ManagerConfigureDiscoveryData *data = (ManagerConfigureDiscoveryData *)user_data;
+       net_nfc_error_e result;
+
+       g_assert(data != NULL);
+       g_assert(data->manager != NULL);
+       g_assert(data->invocation != NULL);
+
+       net_nfc_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_STOP, NET_NFC_ALL_DISABLE, &result);
+       DEBUG_ERR_MSG("configure discovery disable result : %d", result);
+
+       net_nfc_controller_configure_discovery(data->mode, NET_NFC_ALL_ENABLE, &result);
+       DEBUG_ERR_MSG("configure discovery enable result : %d", result);
+
+       net_nfc_gdbus_manager_complete_configure_discovery(data->manager,
+               data->invocation,
+               result);
+
+       g_object_unref(data->invocation);
+       g_object_unref(data->manager);
+
+       g_free(data);
+}
+
+static gboolean manager_handle_configure_discovery(NetNfcGDbusManager *manager,
+                                       GDBusMethodInvocation *invocation,
+                                       gint mode,
+                                       GVariant *smack_privilege,
+                                       gpointer user_data)
+{
+       ManagerConfigureDiscoveryData *data = NULL;
+       gint result = NET_NFC_OK;
+
+       INFO_MSG(">>> REQUEST from [%s]",
+               g_dbus_method_invocation_get_sender(invocation));
+
+       /* check privilege and update client context */
+       if (net_nfc_server_gdbus_check_privilege(invocation, NET_NFC_PRIVILEGE_NFC) == false) {
+               DEBUG_ERR_MSG("permission denied, and finished request");
+               result = NET_NFC_PERMISSION_DENIED;
+
+               goto END;
+       }
+
+       DEBUG_SERVER_MSG("mode : %d", mode);
+
+       data = g_try_new0(ManagerConfigureDiscoveryData, 1);
+       if (data == NULL)
+       {
+               DEBUG_ERR_MSG("Memory allocation failed");
+               result = NET_NFC_ALLOC_FAIL;
+
+               goto END;
+       }
+
+       data->manager = g_object_ref(manager);
+       data->invocation = g_object_ref(invocation);
+       data->mode = mode;
+
+       if (net_nfc_server_controller_async_queue_push(
+               manager_handle_configure_discovery_thread_func, data) == FALSE)
+       {
+               /* return error if queue was blocked */
+               DEBUG_SERVER_MSG("controller is processing important message..");
+               result = NET_NFC_BUSY;
+
+               goto END;
+       }
+
+       return TRUE;
+
+END :
+       if (data != NULL) {
+               g_object_unref(data->invocation);
+               g_object_unref(data->manager);
+
+               g_free(data);
+       }
+
+       net_nfc_gdbus_manager_complete_configure_discovery(manager,
+                                               invocation,
+                                               result);
+
+       return TRUE;
+}
 
 /* server side */
 static void manager_active_thread_func(gpointer user_data)
@@ -329,6 +423,9 @@ gboolean net_nfc_server_manager_init(GDBusConnection * connection)
 
        g_signal_connect(manager_skeleton, "handle-get-server-state", G_CALLBACK(manager_handle_get_server_state), NULL);
 
+       g_signal_connect(manager_skeleton, "handle-configure-discovery", G_CALLBACK(manager_handle_configure_discovery), NULL);
+
+
        if (g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(manager_skeleton), connection, "/org/tizen/NetNfcService/Manager", &error) == FALSE) {
                DEBUG_ERR_MSG("Can not skeleton_export %s", error->message);