Add autofill_connect() API 07/191607/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Fri, 19 Oct 2018 03:44:55 +0000 (12:44 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Fri, 19 Oct 2018 03:44:55 +0000 (12:44 +0900)
Change-Id: Ib1177c419579b47ee2fafa37f29957b3d8f38000
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
client/autofill.c
include/autofill.h
service/service_main.c
test/ecore_imf_example.c

index 7ddefa4faf44d2f66894f3c0aa9652a7169e3b04..34c0be662f0db0c3f078bc54d87ff4862e1f8974 100644 (file)
@@ -201,37 +201,61 @@ static void __on_rejected(rpc_port_proxy_AutofillAppPort_h h, void *user_data)
 }
 //LCOV_EXCL_STOP
 
-EXPORT_API int autofill_initialize(autofill_connection_status_changed_cb callback, void *user_data)
+EXPORT_API int autofill_initialize()
 {
     LOGD("autofill initialize");
 
     int ret;
 
+    if (rpc_h) {
+        LOGI("already initialized\n");
+        return AUTOFILL_ERROR_NONE;
+    }
+
     rpc_port_proxy_AutofillAppPort_callback_s rpc_callback = {
         .connected = __on_connected,
         .disconnected = __on_disconnected,
         .rejected = __on_rejected
     };
 
+    ret = rpc_port_proxy_AutofillAppPort_create(AUTOFILL_DAEMON_APP_ID, &rpc_callback, NULL, &rpc_h);
+    if (ret != RPC_PORT_ERROR_NONE) {
+        LOGW("Failed to create rpc port. err = %d", ret);
+        return AUTOFILL_ERROR_OUT_OF_MEMORY;
+    }
+
+    return ret;
+}
+
+EXPORT_API int autofill_deinitialize()
+{
+    LOGD("autofill deinitialize");
+
+    connection_callback = NULL;
+    g_autofill_fill_response_cb = NULL;
+    g_autofill_auth_info_cb = NULL;
+
+    return autofill_disconnect();
+}
+
+EXPORT_API int autofill_connect(autofill_connection_status_changed_cb callback, void *user_data)
+{
+    LOGD("autofill connect");
+
+    int ret;
+
     if (!callback) {
         LOGW("parameter is NULL\n");
         return AUTOFILL_ERROR_INVALID_PARAMETER;
     }
 
-    if (rpc_h) {
-        LOGI("already connected\n");
-        return AUTOFILL_ERROR_NONE;
+    if (!rpc_h) {
+        return AUTOFILL_ERROR_NOT_INITIALIZED;
     }
 
     connection_callback = callback;
     connection_userdata = user_data;
 
-    ret = rpc_port_proxy_AutofillAppPort_create(AUTOFILL_DAEMON_APP_ID, &rpc_callback, NULL, &rpc_h);
-    if (ret != RPC_PORT_ERROR_NONE) {
-        LOGW("Failed to create rpc port. err = %d", ret);
-        return AUTOFILL_ERROR_OUT_OF_MEMORY;
-    }
-
     ret = rpc_port_proxy_AutofillAppPort_connect(rpc_h);
     switch (ret) {
         case RPC_PORT_ERROR_NONE:
@@ -255,9 +279,9 @@ EXPORT_API int autofill_initialize(autofill_connection_status_changed_cb callbac
     return ret;
 }
 
-EXPORT_API int autofill_deinitialize()
+EXPORT_API int autofill_disconnect()
 {
-    LOGD("autofill deinitialize");
+    LOGD("autofill disconnect");
 
     if (rpc_h) {
         rpc_port_proxy_AutofillAppPort_destroy(rpc_h);
index 036e86ca60938de267614a0ff9dc175e20c9090b..1c6695cf7999a5a2ba95d10eeb79642e7eb16f22 100644 (file)
@@ -73,7 +73,7 @@ typedef void (*Autofill_Auth_Info_Cb)(autofill_auth_info_h auth_info, void *data
  * @retval #AUTOFILL_ERROR_NONE No error
  * @retval #AUTOFILL_ERROR_PERMISSION_DENIED Permission denied
  */
-int autofill_initialize(autofill_connection_status_changed_cb callback, void *user_data);
+int autofill_initialize();
 
 /**
  * @brief Autofill deinitialize
@@ -88,6 +88,38 @@ int autofill_initialize(autofill_connection_status_changed_cb callback, void *us
  */
 int autofill_deinitialize();
 
+/**
+ * @brief Autofill connect
+ *
+ * @since_tizen 5.5
+ *
+ * @privlevel public
+ *
+ * @privilege %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/datasharing
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #AUTOFILL_ERROR_NONE No error
+ * @retval #AUTOFILL_ERROR_PERMISSION_DENIED Permission denied
+ */
+int autofill_connect(autofill_connection_status_changed_cb callback, void *user_data);
+
+/**
+ * @brief Autofill disconnect
+ *
+ * @since_tizen 5.5
+ *
+ * @privlevel public
+ *
+ * @privilege %http://tizen.org/privilege/appmanager.launch \n
+ *            %http://tizen.org/privilege/datasharing
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #AUTOFILL_ERROR_NONE No error
+ * @retval #AUTOFILL_ERROR_PERMISSION_DENIED Permission denied
+ */
+int autofill_disconnect();
+
 // auth
 /**
  * @brief Request of authentication information
index 471d4d450f545db0de2123ffc5a88c5102238c47..311627c836a392122f4b816f9ddbaf7efc370a66 100644 (file)
@@ -18,7 +18,6 @@
 #include <stdlib.h>
 #include <service_app.h>
 #include <dlog.h>
-#include <glib.h>
 #include "autofill_service.h"
 
 #ifdef LOG_TAG
@@ -116,10 +115,10 @@ static void _auth_info_request_cb(autofill_view_info_h vi_h, void *user_data)
     autofill_auth_info_set_view_id(auth_info, view_id);
 
     autofill_auth_info_set_exist_autofill_data(auth_info, true);
-    autofill_auth_info_set_need_authentication(auth_info, false);
-    autofill_auth_info_set_service_name(auth_info, "Samsung Pass444");
-    autofill_auth_info_set_service_message(auth_info, "Login with Samsung Pass333");
-    autofill_auth_info_set_service_logo_image_path(auth_info, "/usr/apps/com.samsung.samsungpass/shared/samsung_pass.png");
+    autofill_auth_info_set_need_authentication(auth_info, false); // Use true in real situation
+    autofill_auth_info_set_service_name(auth_info, "Samsung Pass");
+    autofill_auth_info_set_service_message(auth_info, "Login with Samsung Pass");
+    autofill_auth_info_set_service_logo_image_path(auth_info, "/usr/apps/com.samsung.samsungpass/shared/res/samsung_pass.png");
 
     LOGD("send auth info");
     autofill_service_send_auth_info(auth_info);
index a6a65d726e0f0daa475543ee13d34e2eaec96f59..a502c5f0045fed31d7c613043222d446ac1efb00 100644 (file)
@@ -1,9 +1,5 @@
 /**
- * Ecore example illustrating how to use ecore imf.
- *
- * @verbatim
- * gcc -o ecore_imf_example ecore_imf_example.c `pkg-config --cflags --libs ecore evas eina ecore-evas ecore-imf ecore-imf-evas`
- * @endverbatim
+ * Example illustrating how to use autofill library.
  */
 
 #include <Ecore.h>
 #include <Evas.h>
 #include <stdio.h>
 #include <app.h>
-#include <autofill.h>
 #include <dlog.h>
 #include <efl_extension.h>
 
+#include <autofill.h>
+
 #define WIDTH 720
 #define HEIGHT 1280
 
@@ -196,7 +193,9 @@ _autofill_auth_info_cb(autofill_auth_info_h auth_info_h, void *data)
     char *service_name = NULL;
     char *service_message = NULL;
     char *service_logo_image_path = NULL;
+    char *view_id = NULL;
 
+    autofill_auth_info_get_view_id(auth_info_h, &view_id);
     autofill_auth_info_get_exist_autofill_data(auth_info_h, &exist_autofill_data);
     autofill_auth_info_get_need_authentication(auth_info_h, &need_authentication);
 
@@ -204,7 +203,10 @@ _autofill_auth_info_cb(autofill_auth_info_h auth_info_h, void *data)
     autofill_auth_info_get_service_message(auth_info_h, &service_message);
     autofill_auth_info_get_service_logo_image_path(auth_info_h, &service_logo_image_path);
 
-    LOGD("exist : %d, need_auth : %d, service name : %s, logo path : %s, message : '%s'", exist_autofill_data, need_authentication, service_name, service_logo_image_path, service_message);
+    LOGD("view id : %s, exist : %d, need_auth : %d, view_id, service name : %s, logo path : %s, message : '%s'", exist_autofill_data, need_authentication, service_name, service_logo_image_path, service_message);
+
+    if (view_id)
+        free(view_id);
 
     if (service_message)
         free(service_message);
@@ -744,7 +746,7 @@ main(void)
 
     ecore_imf_init();
 
-    ret = autofill_initialize(connection_status_changed_cb, NULL);
+    ret = autofill_initialize();
     if (ret == AUTOFILL_ERROR_NONE)
         LOGD("Succeeded to initialize");
     else if (ret == AUTOFILL_ERROR_PERMISSION_DENIED)
@@ -752,6 +754,14 @@ main(void)
     else
         LOGW("Failed to initialize. error : %d", ret);
 
+    ret = autofill_connect(connection_status_changed_cb, NULL);
+    if (ret == AUTOFILL_ERROR_NONE)
+        LOGD("Succeeded to connect");
+    else if (ret == AUTOFILL_ERROR_PERMISSION_DENIED)
+        LOGW("permission denied");
+    else
+        LOGW("Failed to connect. error : %d", ret);
+
     // create a new window, with size=WIDTHxHEIGHT and default engine
     ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);