User Concent API 49/82349/24
authorchanywa <cbible.kim@samsung.com>
Wed, 3 Aug 2016 04:46:08 +0000 (13:46 +0900)
committerchanywa <cbible.kim@samsung.com>
Mon, 22 Aug 2016 10:33:25 +0000 (19:33 +0900)
Change-Id: I2b74535a13e713a7e4fce54b79d4c747cddeafc8

include/maps_error.h
include/maps_service.h
src/api/maps_service.cpp
src/api/maps_view.cpp
src/plugin/discovery.cpp
src/plugin/discovery.h
src/plugin/empty_module.cpp
src/plugin/module.cpp
src/plugin/module.h

index 0fd0f86..91b93be 100644 (file)
@@ -79,6 +79,9 @@ typedef enum _maps_error_e {
        MAPS_ERROR_UNKNOWN =
                TIZEN_ERROR_UNKNOWN,                    /**< Unknown error */
 
+       MAPS_ERROR_USER_NOT_CONSENTED =
+               TIZEN_ERROR_USER_NOT_CONSENTED, /**< Not Consented (Since @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif) */
+
        MAPS_ERROR_SERVICE_NOT_AVAILABLE =
                TIZEN_ERROR_MAPS_SERVICE | 0x01,/**< Service unavailable */
 
index fc0e1ad..dd5c655 100644 (file)
@@ -67,7 +67,7 @@ typedef enum _maps_service_e {
        MAPS_SERVICE_SEARCH_PLACE_BY_AREA,              /**< Indicates that maps_service_search_place_by_area() service is allowed */
        MAPS_SERVICE_SEARCH_PLACE_BY_ADDRESS,   /**< Indicates that maps_service_search_place_by_address() service is allowed */
        MAPS_SERVICE_SEARCH_ROUTE,                              /**< Indicates that maps_service_search_route() service is allowed */
-       MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS,    /**< Indicates that maps_service_search_route_waypoints() service is allowed */
+       MAPS_SERVICE_SEARCH_ROUTE_WAYPOINTS,    /**< Indicates that maps_service_search_route_waypoints() service is allowed */
        MAPS_SERVICE_CANCEL_REQUEST,                    /**< Indicates that maps_service_cancel_request() service is allowed */
        MAPS_SERVICE_MULTI_REVERSE_GEOCODE,             /**< Indicates that maps_service_multi_reverse_geocode() service is allowed @if MOBILE (Since 3.0) @endif */
        MAPS_SERVICE_SEARCH_PLACE_LIST,                 /**< Indicates that maps_service_search_place_list() service is allowed @if MOBILE (Since 3.0) @endif */
@@ -148,6 +148,57 @@ int maps_service_foreach_provider(maps_service_provider_info_cb callback,
                                  void *user_data);
 
 /**
+ * @brief      Called with the information about user's consent.
+ * @details The Maps Service invokes this callback when the information about user's consent is obtained.
+ * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
+ *
+ * @param[in]  consented       The value of User Consent
+ * @param[in]  maps_provider   The name of Maps Provider
+ * @param[in]  user_data       The user data passed from maps_service_request_user_consent()
+ *
+ * @pre maps_service_request_user_consent() will invoke this callback.
+ *
+ * @see maps_service_request_user_consent()
+ * @see maps_service_create()
+ */
+typedef void(*maps_service_request_user_consent_cb) (bool consented,
+                                                               const char *maps_provider, void *user_data);
+
+/**
+ * @brief      Gets the user's consent to use maps data.
+ * @details The function gets information whether the user agreed that the application can use maps data.
+ * If maps_service_request_user_consent() is called when the user didn't agree yet, a popup is shown and
+ * the user can decide whether to agree or not. Then the result is saved and maps_service_request_user_consent_cb()
+ * is called. If the user has already agreed, the popup is not shown and only the callback is called.
+ * The request is asynchronous.
+ * @since_tizen @if MOBILE 3.0 @elseif WEARABLE 2.3.2 @endif
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/mapservice
+ *
+ * @remarks Available map providers can be obtained with maps_service_foreach_provider().
+ *
+ * @param[in]  maps_provider   The name of Maps Provider
+ * @param[in]  callback        The callback which receives the user's consent decision
+ * @param[in]  user_data       The user data to be passed to the callback function
+ * @return     0 on success, otherwise a negative error value
+
+ * @retval     #MAPS_ERROR_NONE Successful
+ * @retval     #MAPS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval     #MAPS_ERROR_SERVICE_NOT_AVAILABLE Service not available
+ * @retval     #MAPS_ERROR_NOT_SUPPORTED Not supported
+ * @retval     #MAPS_ERROR_PERMISSION_DENIED Permission Denied
+ *
+ * @post This function invokes maps_service_request_user_consent_cb() to provide information
+ * about user consent.
+ *
+ * @see maps_service_foreach_provider()
+ * @see maps_service_request_user_consent_cb()
+ * @see maps_service_create()
+ */
+int maps_service_request_user_consent(const char *maps_provider,
+                                                               maps_service_request_user_consent_cb callback, void *user_data);
+
+/**
  * @brief      Creates a new Maps Service and assigns it with a handle.
  * @details While Maps Service is being created, a Maps Provider is initialized
  * and linked with Maps Service handle.
@@ -175,6 +226,7 @@ int maps_service_foreach_provider(maps_service_provider_info_cb callback,
  * @retval     #MAPS_ERROR_SERVICE_NOT_AVAILABLE Service not available
  * @retval     #MAPS_ERROR_NOT_SUPPORTED Not supported
  * @retval     #MAPS_ERROR_PERMISSION_DENIED Permission Denied
+ * @retval     #MAPS_ERROR_USER_NOT_CONSENTED The user did not consent
  *
  * @pre Call maps_service_foreach_provider() to get a available Maps Providers.
  *
index 5a4efab..c0edb80 100644 (file)
@@ -86,6 +86,23 @@ EXPORT_API int maps_service_foreach_provider(maps_service_provider_info_cb callb
        return MAPS_ERROR_NONE;
 }
 
+EXPORT_API int maps_service_request_user_consent(const char *maps_provider,
+                                                               maps_service_request_user_consent_cb callback, void *user_data)
+{
+       if (!maps_condition_check_maps_feature())
+               return MAPS_ERROR_NOT_SUPPORTED;
+       /* Check if parameters are valid */
+       if (!maps_provider || !callback)
+               return MAPS_ERROR_INVALID_PARAMETER;
+
+       /* Check if privileges enough */
+       if (!maps_condition_check_privilege())
+               return MAPS_ERROR_PERMISSION_DENIED;
+
+       int error = plugin::request_user_consent(maps_provider, (void*)callback, user_data);
+       return error;
+}
+
 EXPORT_API int maps_service_create(const char *maps_provider, maps_service_h *maps)
 {
        if (!maps_condition_check_maps_feature())
index 55b3308..3ed86ac 100644 (file)
@@ -501,6 +501,13 @@ static void __maps_view_create_panel(maps_view_h view, Evas_Object *obj)
                        evas_object_show(v->panel);
                else
                        evas_object_hide(v->panel);
+
+               /* Equal size of a panel object and a parent object */
+               int x, y, w, h;
+               evas_object_geometry_get(v->parent, &x, &y, &w, &h);
+               evas_object_move(v->panel, x, y);
+               evas_object_resize(v->panel, w, h);
+               evas_object_image_fill_set(v->panel, 0, 0, w, h);
        }
        evas_object_image_filled_set(v->panel, EINA_FALSE);
 }
@@ -622,6 +629,9 @@ EXPORT_API int maps_view_create(maps_service_h maps, Evas_Object *obj, maps_view
        v->screen_dpi = maps_get_display_dpi();
        v->min_hit_area = MAX(20, v->screen_dpi / 5);
 
+       /* Update map view */
+       __maps_view_set_center(v, v->center, TRUE);
+
        return MAPS_ERROR_NONE;
 }
 
index e3c0d2e..e40bf7a 100644 (file)
@@ -136,7 +136,7 @@ plugin::provider_info plugin::find_by_names(const string &provider)
 void plugin::split_provider_name(const char *original, char **provider, char **module)
 {
        char *save, *_provider, *_module;
-       
+
        _provider = strtok_r(g_strdup(original), "/", &save);
        _module = g_strdup(strtok_r(NULL, "", &save));
 
@@ -148,3 +148,84 @@ void plugin::split_provider_name(const char *original, char **provider, char **m
        g_free(_provider);
        g_free(_module);
 }
+
+
+typedef struct
+{
+       maps_service_request_user_consent_cb callback;
+       char *provider;
+       void *user_data;
+       void *plugin;
+} user_consent_s;
+
+gboolean user_consent_shutdown(gpointer data)
+{
+       MAPS_LOGD("data = %p", data);
+       if (!data) return false;
+
+       user_consent_s *uc = (user_consent_s*)data;
+       plugin::user_consent_checker().shutdown(uc->plugin);
+       g_free(uc->provider);
+       g_free(uc);
+       return false;
+}
+
+void plugin::user_consent_cb(bool consented, const char *provider, void *user_data)
+{
+       MAPS_LOGE("user_consent_cb is called");
+       user_consent_s *uc = (user_consent_s*)user_data;
+       if (uc && uc->callback)
+               uc->callback(consented, provider, uc->user_data);
+       g_idle_add(user_consent_shutdown, (void*)uc);
+}
+
+int plugin::request_user_consent(const char *maps_provider, void *callback, void *user_data)
+{
+       if (!maps_provider || !callback)
+               return MAPS_ERROR_INVALID_PARAMETER;
+
+       char *provider = NULL, *module = NULL;
+       plugin::split_provider_name(maps_provider, &provider, &module);
+       const plugin::provider_info info = plugin::find_by_names(provider);
+
+       /* 1. initialize the requested plugin */
+       int error = MAPS_ERROR_SERVICE_NOT_AVAILABLE;
+       int init_error = MAPS_ERROR_NONE; /* Storage for init error code */
+       plugin_s *plugin_handle = (plugin_s*)plugin::user_consent_checker().init(info, module, &init_error);
+       g_free(provider);
+       g_free(module);
+       if (!plugin_handle) {
+               MAPS_LOGE("ERROR! Plugin init failed");
+               return init_error;
+       }
+
+       /* 2. request user consent */
+       user_consent_s *uc = NULL;
+       if (plugin_handle->interface.maps_plugin_request_user_consent) {
+               uc = (user_consent_s*)g_malloc0(sizeof(user_consent_s));
+               if (!uc) {
+                       error = MAPS_ERROR_OUT_OF_MEMORY;
+               } else {
+                       uc->callback = (maps_service_request_user_consent_cb)callback;
+                       uc->provider = g_strdup(maps_provider);
+                       uc->user_data = user_data;
+                       uc->plugin = plugin_handle;
+                       error = plugin_handle->interface.maps_plugin_request_user_consent(
+                                                                       (const char*)uc->provider, user_consent_cb, (void*)uc);
+                       MAPS_LOGD("maps_plugin_request_user_consent = %d", error);
+                       if (error == MAPS_ERROR_USER_NOT_CONSENTED)
+                               error = MAPS_ERROR_NONE;
+               }
+       }
+
+       /* 3. shutdown plugin */
+       if (error != MAPS_ERROR_NONE) {
+               plugin::user_consent_checker().shutdown(plugin_handle);
+               if (uc) {
+                       g_free(uc->provider);
+                       g_free(uc);
+               }
+       }
+
+       return error;
+}
index 57dda75..5e45b8d 100644 (file)
@@ -57,6 +57,9 @@ namespace plugin
 
        provider_info find_by_names(const string &provider);
        void split_provider_name(const char *original, char **provider, char **module);
+
+       void user_consent_cb(bool consented, const char *provider, void *user_data);
+       int request_user_consent(const char *maps_provider, void* callback, void *user_data);
 }
 
 #endif                         /* __MAPS_SERVICE_PLUGIN_DISCOVERY_H__ */
\ No newline at end of file
index 85ae7b6..8c52ab4 100644 (file)
@@ -41,6 +41,13 @@ int maps_plugin_get_info_empty(maps_plugin_info_h *info)
        return 0;
 }
 
+int maps_plugin_request_user_consent_empty(const char *provider,
+                                                               maps_service_request_user_consent_cb callback,
+                                                               void *user_data)
+{
+       return 0;
+}
+
 /* Maps Provider access key, preference and capabilities */
 int maps_plugin_set_provider_key_empty(const char *provider_key)
 {
@@ -270,6 +277,7 @@ plugin::interface_s empty_interface = {
        maps_plugin_shutdown_empty,
        maps_plugin_get_info_empty,
        maps_plugin_init_module_empty,
+       maps_plugin_request_user_consent_empty,
 
        maps_plugin_set_provider_key_empty,
        maps_plugin_get_provider_key_empty,
index 1e5e00f..3f32000 100644 (file)
@@ -124,6 +124,9 @@ maps_plugin_h plugin::binary_extractor::init(const provider_info &info,
                new_plugin->interface.maps_plugin_get_info =
                        (maps_plugin_get_info_f) gmod_find_sym(plugin,
                        "maps_plugin_get_info");
+               new_plugin->interface.maps_plugin_request_user_consent =
+                       (maps_plugin_request_user_consent_f) gmod_find_sym(plugin,
+                       "maps_plugin_request_user_consent");
 
                /* Maps Provider access key, preference and capabilities */
                new_plugin->interface.maps_plugin_set_provider_key =
@@ -512,3 +515,82 @@ void plugin::binary_extractor::trace_dbg(const plugin_s *plugin) const
                itf->maps_plugin_capture_snapshot);
        MAPS_LOGD("*********************************************");
 }
+
+plugin::user_consent_checker::user_consent_checker()
+{
+}
+
+maps_plugin_h plugin::user_consent_checker::init(const provider_info &info,
+                                            const char *module, int *init_error)
+{
+       /* 1.Initialize plugin */
+       if (info.file.empty() || !init_error) {
+               if (init_error)
+                       *init_error = MAPS_ERROR_NOT_SUPPORTED;
+               return NULL;
+       }
+
+       *init_error = MAPS_ERROR_NONE;
+
+       GMod *plugin = gmod_new(info.file, TRUE);
+       if (!plugin) {
+               MAPS_LOGE("Open Module Failed: %s", info.file.c_str());
+               *init_error = MAPS_ERROR_SERVICE_NOT_AVAILABLE;
+               return NULL;
+       }
+
+       /* 2.1 Create new plugin interface */
+       plugin_s* new_plugin = g_slice_new0(plugin_s);
+
+       /* 2. Perform steps to completely initialize a plugin */
+       do {
+               if (!new_plugin) {
+                       MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
+                       *init_error = MAPS_ERROR_OUT_OF_MEMORY;
+                       break;
+               }
+
+               /* 2.1 Set plugin module handle */
+               new_plugin->module = plugin;
+
+               /* 2.2 Set plugin interface */
+               new_plugin->interface = get_empty_interface();
+
+               /* Plugin dedicated functions */
+               new_plugin->interface.maps_plugin_request_user_consent =
+                       (maps_plugin_request_user_consent_f) gmod_find_sym(plugin,
+                       "maps_plugin_request_user_consent");
+
+               if (!new_plugin->interface.maps_plugin_request_user_consent) {
+                       MAPS_LOGE("ERROR! Plugin request_user_consent function is NULL");
+                       *init_error = MAPS_ERROR_SERVICE_NOT_AVAILABLE;
+                       break;
+               }
+
+               /* 2.5 Return newly initialized plugin */
+               return new_plugin;
+       } while (FALSE);
+
+       MAPS_LOGE("Shut down the plugin becuause of error");
+
+       /* 3. shutdown plugin in case of problem */
+       shutdown(new_plugin);
+       return NULL;
+}
+
+void plugin::user_consent_checker::shutdown(maps_plugin_h plugin_h)
+{
+       if (!plugin_h)
+               return;
+       plugin_s *plugin = (plugin_s *) plugin_h;
+       g_return_if_fail(plugin->module);
+
+       /* 4. Unload plugin from memory */
+       gmod_free((GMod *) plugin->module);
+
+       /* 5. Destroying the table with plugin capabilities */
+       /*maps_int_hashtable_destroy(plugin->capabilities); */
+
+       /* 6. Release memory used by plugin structure */
+       g_slice_free(plugin_s, plugin);
+}
index 2f970b8..3905e9c 100644 (file)
@@ -30,6 +30,9 @@ typedef int (*maps_plugin_init_f) (maps_plugin_h *plugin);
 typedef int (*maps_plugin_init_module_f) (maps_plugin_h *plugin, const char *module);
 typedef int (*maps_plugin_shutdown_f) (maps_plugin_h plugin);
 typedef int (*maps_plugin_get_info_f) (maps_plugin_info_h *info);
+typedef int (*maps_plugin_request_user_consent_f) (const char *provider,
+                                                               maps_service_request_user_consent_cb callback,
+                                                               void *user_data);
 
 /* Maps Provider access key, preference and capabilities */
 typedef int (*maps_plugin_set_provider_key_f) (const char *provider_key);
@@ -140,6 +143,7 @@ typedef struct _interface_s {
        maps_plugin_shutdown_f maps_plugin_shutdown;
        maps_plugin_get_info_f maps_plugin_get_info;
        maps_plugin_init_module_f maps_plugin_init_module;
+       maps_plugin_request_user_consent_f maps_plugin_request_user_consent;
 
        /* Maps Provider access key, preference and capabilities */
        maps_plugin_set_provider_key_f maps_plugin_set_provider_key;
@@ -231,12 +235,21 @@ public:
        provider_info get_plugin_info(const string &file_name) const;
        maps_plugin_h init(const provider_info &info, const char *module, int *init_error);
        void shutdown(maps_plugin_h plugin_h);
-private:
+//private:
+protected:
        GMod *gmod_new(const string &module_file, gboolean is_resident) const;
        void gmod_free(GMod *gmod) const;
        gpointer gmod_find_sym(GMod *gmod, const gchar *func_name) const;
        void trace_dbg(const plugin_s *plugin) const;
 };
+
+class user_consent_checker : public binary_extractor {
+public:
+       user_consent_checker();
+       virtual ~user_consent_checker() {}
+       maps_plugin_h init(const provider_info &info, const char *module, int *init_error);
+       void shutdown(maps_plugin_h plugin_h);
+};
 };
 
 #endif                         /* __MAPS_SERVICE_PLUGIN_MODULE_H__ */