add internal APIs for user consent 15/135715/7
authorjomui <jongmun.woo@samsung.com>
Mon, 26 Jun 2017 05:09:29 +0000 (14:09 +0900)
committerjomui <jongmun.woo@samsung.com>
Tue, 4 Jul 2017 10:02:00 +0000 (19:02 +0900)
Signed-off-by: jomui <jongmun.woo@samsung.com>
Change-Id: Ic87d25d713c75c72ce1272c9585c29ac0a85418d

CMakeLists.txt
inc/here_api.h
inc/here_manager.h
inc/here_userconsent.h [new file with mode: 0644]
inc/here_utils.h
inc/heremaps-check-uc.h [deleted file]
src/here_api.cpp
src/here_manager.cpp
src/here_plugin.cpp
src/here_userconsent.cpp [new file with mode: 0644]
src/heremaps-check-uc.cpp [deleted file]

index af2ad33..24c617b 100644 (file)
@@ -76,7 +76,7 @@ SET(SRCS
        src/here_utils.cpp
        src/here_view.cpp
        src/here_view_objects.cpp
-       src/heremaps-check-uc.cpp
+       src/here_userconsent.cpp
 
        # UC-DBus
        src/heremaps-uc-dbus.c
index 6b05e72..f8a8d08 100644 (file)
@@ -109,7 +109,11 @@ int HerePluginOnViewObject(maps_view_h hView, const maps_view_object_h object, m
 
 int HerePluginCaptureSnapshot(maps_view_h hView, void **data, int *w, int *h, maps_view_colorspace_type_e *cs);
 
-int HerePluginCheckUC(const char *provider, maps_service_request_user_consent_cb pCbFunc, void *user_data);
+int HerePluginRequestUC(const char *provider, void *pCbFunc, void *user_data);
+
+int HerePluginGetUC(bool *consent);
+
+int HerePluginSetUserConsent(bool consent);
 
 int HerePluginGetViewScale(maps_view_h hView, double *scale);
 
index a7cc2ef..982ec54 100644 (file)
@@ -34,6 +34,7 @@
 #include "here_api.h"
 #include "here_types.h"
 #include "here_utils.h"
+#include "here_userconsent.h"
 
 //map engine header
 #include <common/ApplicationContext.h>
@@ -84,7 +85,9 @@ public:
        static bool Create();
        static HereManager* GetHandler();
        static void Close();
-       static here_error_e CheckAgreement();
+
+       //User Consent Object
+       HereUserConsent *m_UserConsent;
 
 private:
        here_error_e SetCredentials();
diff --git a/inc/here_userconsent.h b/inc/here_userconsent.h
new file mode 100644 (file)
index 0000000..6847b59
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _LOCATION_HERE_USERCONSENT_H_
+#define _LOCATION_HERE_USERCONSENT_H_
+
+#include "here_utils.h"
+
+HERE_PLUGIN_BEGIN_NAMESPACE
+
+using namespace HERE_MAPS_NAMESPACE_PREFIX;
+
+class HereUserConsent
+{
+public:
+       /**
+        *This is the default constructor for UserConsent.
+        */
+
+       HereUserConsent(const char *provider, void *pCbFunc, void *pUserData);
+
+       /**
+        *This is the default destructor for UserConsent.
+        */
+
+       ~HereUserConsent();
+
+       static here_error_e GetUserConsent(bool *consent);
+       static here_error_e SetUserConsent(bool consent);
+
+       here_error_e RequestUserConsent();
+
+       bool isSetVconfCb;
+       const char *m_provider; //provider
+       void *m_pCbFunc;                        //callback function
+       void *m_pUserData;              //user data
+
+private:
+
+};
+
+HERE_PLUGIN_END_NAMESPACE
+
+#endif //_LOCATION_HERE_USERCONSENT_H_
\ No newline at end of file
index f1a5af8..2894b29 100644 (file)
@@ -32,6 +32,7 @@
 #include <maps_service.h>
 #include <maps_view.h>
 #include <maps_extra_types.h>
+#include <maps_service_internal.h>
 
 //plug-in header
 #include "here_types.h"
diff --git a/inc/heremaps-check-uc.h b/inc/heremaps-check-uc.h
deleted file mode 100644 (file)
index 07742ff..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _LOCATION_HEREMAPS_CHECK_UC_H_
-#define _LOCATION_HEREMAPS_CHECK_UC_H_
-
-//plug-in header
-#include "here_utils.h"
-#include <common/BaseReply.h>
-
-typedef struct _data
-{
-       const char *provider;
-       maps_service_request_user_consent_cb pCbFunc;
-       void *user_data;
-} heremaps_uc_cb_data;
-
-bool heremaps_check_agreement();
-
-#endif //_LOCATION_HEREMAPS_CHECK_UC_H_
-
index 25ba368..761ffeb 100644 (file)
 #include "here_route.h"
 #include "here_view.h"
 #include "heremaps-uc-dbus.h"
-#include "heremaps-check-uc.h"
+#include "here_userconsent.h"
 
 #include <common/HereConfig.h>
-#include <app.h>
-#include <vconf.h>
-#include <vconf-internal-location-keys.h>
 
 using namespace HERE_PLUGIN_NAMESPACE_PREFIX;
 
@@ -37,9 +34,14 @@ int HerePluginInit(maps_plugin_h *hPlugin, const char *module)
        if (!hPlugin)
                return HERE_ERROR_INVALID_PARAMETER;
 
-       here_error_e error = HereManager::CheckAgreement();
-       if (error != HERE_ERROR_NONE)
-               return error;
+       if (!module || strcmp(module, "NOUC") != 0) {
+               bool consent = false;
+               here_error_e error = HereUserConsent::GetUserConsent(&consent);
+               if (error != HERE_ERROR_NONE)
+                       return error;
+               if (consent != true)
+                       return HERE_ERROR_USER_NOT_CONSENTED;
+       }
 
        HereManager::Create();
 
@@ -114,7 +116,11 @@ int HerePluginGeocode(const char* szAddr,
        if (!szAddr || (szAddr && *szAddr == '\0') || !pCbFunc || !nReqId)
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -129,8 +135,6 @@ int HerePluginGeocode(const char* szAddr,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pGeocode->PrepareQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -156,7 +160,11 @@ int HerePluginGeocodeByStructuredAddress(const maps_address_h hAddr,
        if (!hAddr || !pCbFunc || !nReqId)
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -171,8 +179,6 @@ int HerePluginGeocodeByStructuredAddress(const maps_address_h hAddr,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pGeocode->PrepareQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -201,7 +207,11 @@ int HerePluginGeocodeInsideArea(const char* szAddr, maps_area_h hArea,
        if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -216,8 +226,6 @@ int HerePluginGeocodeInsideArea(const char* szAddr, maps_area_h hArea,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pGeocode->PrepareQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -246,7 +254,11 @@ int HerePluginReverseGeocode(double dLatitude, double dLongitude,
        if (!pCbFunc || !nReqId)
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -261,8 +273,6 @@ int HerePluginReverseGeocode(double dLatitude, double dLongitude,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_UNKNOWN;
-
        do {
                error = pRevGeocode->PrepareQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -291,7 +301,11 @@ int HerePluginMultiReverseGeocode(const maps_coordinates_list_h hGeocodeList,
        if (!hGeocodeList || !pCbFunc || !nReqId)
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -306,8 +320,6 @@ int HerePluginMultiReverseGeocode(const maps_coordinates_list_h hGeocodeList,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_UNKNOWN;
-
        do {
                error = pMultiRevGeocode->PrepareQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -336,7 +348,11 @@ int HerePluginSearchPlace(maps_coordinates_h hPos, int nDistance,
        if (!hFilter || !pCbFunc || !nReqId)
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -351,8 +367,6 @@ int HerePluginSearchPlace(maps_coordinates_h hPos, int nDistance,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pPlace->PrepareDiscoveryQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -384,7 +398,11 @@ int HerePluginSearchPlaceByArea(maps_area_h hArea,
        if (!hFilter || !pCbFunc || !nReqId)
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -399,8 +417,6 @@ int HerePluginSearchPlaceByArea(maps_area_h hArea,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pPlace->PrepareDiscoveryQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -432,7 +448,11 @@ int HerePluginSearchPlaceByAddress(const char* szAddr, maps_area_h hArea,
        if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -447,8 +467,6 @@ int HerePluginSearchPlaceByAddress(const char* szAddr, maps_area_h hArea,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pPlace->PrepareDiscoveryQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -480,7 +498,11 @@ int HerePluginSearchPlaceList(maps_area_h hArea, maps_item_hashtable_h hPref,
        if (!hArea || !HereUtils::IsValid(*(maps_area_s*)hArea))
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -495,8 +517,6 @@ int HerePluginSearchPlaceList(maps_area_h hArea, maps_item_hashtable_h hPref,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pPlace->PrepareDiscoveryQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -525,7 +545,11 @@ int HerePluginSearchPlaceDetails(const char* szUrl,
        if (!szUrl || (szUrl && *szUrl == '\0') || !pCbFunc || !nReqId)
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -540,8 +564,6 @@ int HerePluginSearchPlaceDetails(const char* szUrl,
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pPlace->PreparePlaceDetailsQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -568,7 +590,11 @@ int HerePluginSearchRoute(maps_coordinates_h hOrigin, maps_coordinates_h hDestin
                !HereUtils::IsValid(*(maps_coordinates_s*)hDestination))
                return HERE_ERROR_INVALID_PARAMETER;
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -583,8 +609,6 @@ int HerePluginSearchRoute(maps_coordinates_h hOrigin, maps_coordinates_h hDestin
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pRoute->PrepareQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -619,7 +643,11 @@ int HerePluginSearchRouteWaypoints(const maps_coordinates_h* hWaypointList, int
                        return HERE_ERROR_INVALID_PARAMETER;
        }
 
-       if (HereManager::CheckAgreement() != HERE_ERROR_NONE)
+       here_error_e error = HERE_ERROR_NONE;
+       bool consent = false;
+
+       error = HereUserConsent::GetUserConsent(&consent);
+       if (error != HERE_ERROR_NONE || consent != true)
                return HERE_ERROR_PERMISSION_DENIED;
 
        if (!HereManager::GetHandler())
@@ -634,8 +662,6 @@ int HerePluginSearchRouteWaypoints(const maps_coordinates_h* hWaypointList, int
                return HERE_ERROR_SERVICE_NOT_AVAILABLE;
 
        /* sending request */
-       here_error_e error = HERE_ERROR_NONE;
-
        do {
                error = pRoute->PrepareQuery();
                if (error != HERE_ERROR_NONE) break;
@@ -813,67 +839,25 @@ int HerePluginCaptureSnapshot(maps_view_h view, void **data,
        return error;
 }
 
-static void _heremaps_consent_changed_cb(keynode_t *node EINA_UNUSED, void *user_data)
+int HerePluginRequestUC(const char *provider, void *pCbFunc, void *user_data)
 {
-       MAPS_FUNC_ENTER
-
-       heremaps_uc_cb_data *uc_data = (heremaps_uc_cb_data *)user_data;
-       int enabled = 0;
-
-       if (!uc_data) {
-               MAPS_LOGD("uc_data is NULL");
-               return;
-       }
-       if (!uc_data->pCbFunc) {
-               MAPS_LOGD("pCbFunc is NULL");
-               g_free(uc_data);
-               return;
-       }
-
-       vconf_get_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled);
-       if (enabled != 0 && enabled != 1)
-               return;
-       vconf_ignore_key_changed(VCONFKEY_LOCATION_HEREMAPS_CONSENT, _heremaps_consent_changed_cb);
+       if(!HereManager::GetHandler()->m_UserConsent)
+               HereManager::GetHandler()->m_UserConsent = new (std::nothrow) HereUserConsent(provider, pCbFunc, user_data);
 
-       MAPS_LOGD("Vconf value of HereMaps is %d", enabled);
-       if (enabled == 0)
-               uc_data->pCbFunc(FALSE, uc_data->provider, uc_data->user_data);
+       if (HereManager::GetHandler()->m_UserConsent)
+               return HereManager::GetHandler()->m_UserConsent->RequestUserConsent();
        else
-               uc_data->pCbFunc(TRUE, uc_data->provider, uc_data->user_data);
-       g_free(uc_data);
-
-       MAPS_FUNC_EXIT
-}
-
-int HerePluginCheckUC(const char *provider, maps_service_request_user_consent_cb pCbFunc, void *user_data)
-{
-       int ret = HEREMAPS_UC_DBUS_ERROR_NONE;
-       bool agreed = heremaps_check_agreement();
-
-       if (agreed != TRUE) {
-               heremaps_uc_cb_data *uc_data = (heremaps_uc_cb_data *)g_malloc0(sizeof(heremaps_uc_cb_data));
-               if (!uc_data)
-                       return HERE_ERROR_OUT_OF_MEMORY;
-               uc_data->provider = provider;
-               uc_data->pCbFunc = pCbFunc;
-               uc_data->user_data = user_data;
-
-               if (vconf_notify_key_changed(VCONFKEY_LOCATION_HEREMAPS_CONSENT, _heremaps_consent_changed_cb, uc_data) < 0) {
-                       MAPS_LOGD("Unable to register a vconf changed cb to VCONFKEY_LOCATION_HEREMAPS_CONSENT");
-                       g_free(uc_data);
-                       return HERE_ERROR_SERVICE_NOT_AVAILABLE;
-               }
-               MAPS_LOGD("heremaps_uc_dbus_launch_receiver is called");
-               ret = heremaps_uc_dbus_launch_receiver();
-               if (ret != HEREMAPS_UC_DBUS_ERROR_NONE)
-                       MAPS_LOGD("heremaps_uc_dbus_launch_receiver fail");
-               return HERE_ERROR_USER_NOT_CONSENTED;
-       } else {
-               MAPS_LOGD("Vconf value of HereMaps is true");
-               pCbFunc(TRUE, provider, user_data);
-       }
+               return HERE_ERROR_OUT_OF_MEMORY;
+}
 
-       return HERE_ERROR_NONE;
+int HerePluginGetUC(bool *consent)
+{
+       return HereUserConsent::GetUserConsent(consent);
+}
+
+int HerePluginSetUserConsent(bool consent)
+{
+       return HereUserConsent::SetUserConsent(consent);
 }
 
 int HerePluginGetViewScale(maps_view_h hView, double *scale)
index 2d3c182..65591ae 100644 (file)
@@ -27,7 +27,6 @@
 #include "here_utils.h"
 #include "here_view.h"
 #include "heremaps-uc-dbus.h"
-#include "heremaps-check-uc.h"
 
 #include <common/HereConfig.h>
 #include <iostream>
@@ -51,10 +50,16 @@ HereManager::HereManager()
        m_hConnection = NULL;
        pthread_mutex_init(&m_mtxHereList, NULL);
        pthread_mutex_init(&g_mtxRef, NULL);
+
+       m_UserConsent = NULL;
 }
 
 HereManager::~HereManager()
 {
+       if (m_UserConsent) {
+               delete m_UserConsent;
+               m_UserConsent = NULL;
+       }
        if (m_hConnection)
        {
                connection_unset_type_changed_cb(m_hConnection);
@@ -485,15 +490,5 @@ void HereManager::NetworkStateChangedIndCb(connection_type_e type, void *user_da
                pManager->SetProxyAddress();
 }
 
-here_error_e HereManager::CheckAgreement()
-{
-       here_error_e error = HERE_ERROR_NONE;
-
-       if (heremaps_check_agreement() == FALSE)
-               error = HERE_ERROR_USER_NOT_CONSENTED;
-
-       return error;
-}
-
 HERE_PLUGIN_END_NAMESPACE
 
index e16e5a7..29d0eb2 100644 (file)
@@ -66,7 +66,32 @@ EXPORT_API int maps_plugin_request_user_consent(const char *provider,
                                                                void *user_data)
 {
        MAPS_LOGD("maps_plugin_request_user_consent");
-       int ret = HerePluginCheckUC(provider, callback, user_data);
+       int ret = HerePluginRequestUC(provider, (void *)callback, user_data);
+       MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
+       return ConvertToMapsError(ret);
+}
+
+EXPORT_API int maps_plugin_request_user_consent_with_handle(maps_service_request_user_consent_with_handle_cb callback,
+                                                               void *user_data)
+{
+       MAPS_LOGD("maps_plugin_request_user_consent_with_handle");
+       int ret = HerePluginRequestUC(NULL, (void *)callback, user_data);
+       MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
+       return ConvertToMapsError(ret);
+}
+
+EXPORT_API int maps_plugin_get_user_consent(bool *consent)
+{
+       MAPS_LOGD("maps_plugin_get_user_consent");
+       int ret = HerePluginGetUC(consent);
+       MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
+       return ConvertToMapsError(ret);
+}
+
+EXPORT_API int maps_plugin_set_user_consent(bool consent)
+{
+       MAPS_LOGD("maps_plugin_set_user_consent");
+       int ret = HerePluginSetUserConsent(consent);
        MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret));
        return ConvertToMapsError(ret);
 }
diff --git a/src/here_userconsent.cpp b/src/here_userconsent.cpp
new file mode 100644 (file)
index 0000000..6fbd916
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h>
+#include <app.h>
+#include <app_manager.h>
+#include <vconf.h>
+#include <vconf-internal-location-keys.h>
+
+#include "heremaps-uc-dbus.h"
+#include "here_userconsent.h"
+
+HERE_PLUGIN_BEGIN_NAMESPACE
+
+static void UserConsentChangedCb(keynode_t *node EINA_UNUSED, void *user_data)
+{
+       MAPS_FUNC_ENTER
+
+       HereUserConsent *pUserConsent = (HereUserConsent *)user_data;
+
+       if (!pUserConsent->m_pCbFunc) {
+               MAPS_LOGD("m_pCbFunc and  is NULL");
+               return;
+       }
+
+       int enabled = 0;
+       vconf_get_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled);
+       if (enabled != 0 && enabled != 1)
+               return;
+       vconf_ignore_key_changed(VCONFKEY_LOCATION_HEREMAPS_CONSENT, UserConsentChangedCb);
+       pUserConsent->isSetVconfCb = false;
+
+       MAPS_LOGD("Vconf value of HereMaps is %d", enabled);
+       if (pUserConsent->m_provider)
+               ((maps_service_request_user_consent_cb)pUserConsent->m_pCbFunc)((bool)enabled, pUserConsent->m_provider, pUserConsent->m_pUserData);
+       else
+               ((maps_service_request_user_consent_with_handle_cb)pUserConsent->m_pCbFunc)((bool)enabled, pUserConsent->m_pUserData);
+
+       MAPS_FUNC_EXIT
+}
+
+HereUserConsent::HereUserConsent(const char *provider, void *pCbFunc, void *pUserData)
+{
+       isSetVconfCb = false;
+       m_provider = provider;
+       m_pCbFunc = pCbFunc;
+       m_pUserData = pUserData;
+}
+
+HereUserConsent::~HereUserConsent()
+{
+       if (isSetVconfCb)
+               vconf_ignore_key_changed(VCONFKEY_LOCATION_HEREMAPS_CONSENT, UserConsentChangedCb);
+       isSetVconfCb = false;
+}
+
+here_error_e HereUserConsent::GetUserConsent(bool *consent)
+{
+       const int testAppIdCount = 7;
+       const char* testAppIdList[testAppIdCount] = {
+               "org.tizen.capi-maps-service-native-utc",
+               "org.tizen.capi-maps-service-native-itc",
+               "core.capi-maps-service-tests",
+               "native.capi-maps-service-itc",
+               "Tizen.Maps.Test",
+               "Tizen.Maps.Manual.Test",
+               "Tizen.XamarinFormsMaps.Tests"
+       };
+
+       int enabled = 0;
+       int ret = 0;
+
+       ret = vconf_get_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled);
+       MAPS_LOGD("VCONFKEY_LOCATION_HEREMAPS_CONSENT is %d", enabled);
+       if (ret != 0) {
+               MAPS_LOGD("Fail to get vconf value");
+               *consent = FALSE;
+               return HERE_ERROR_SERVICE_NOT_AVAILABLE;
+       }
+       if (enabled != 1) {
+               pid_t nProcessId = getpid();
+               char *strAppId = NULL;
+
+               ret = app_manager_get_app_id(nProcessId, &strAppId);
+               if (ret != APP_MANAGER_ERROR_NONE) {
+                       MAPS_LOGI("Get app_id [%ld]. nRet[%d]", nProcessId, ret);
+               } else {
+                       for (int i = 0; i < testAppIdCount; i++) {
+                               if (!strncmp(strAppId, testAppIdList[i], strlen(testAppIdList[i]))) {
+                                       MAPS_LOGD("Requested by tct");
+                                       enabled = 1;
+                                       break;
+                               }
+                       }
+               }
+               g_free(strAppId);
+       }
+       *consent = (enabled == 1);
+
+       return HERE_ERROR_NONE;
+}
+
+here_error_e HereUserConsent::SetUserConsent(bool consent)
+{
+       int enabled = (int)consent;
+       int ret = 0;
+
+       ret = vconf_set_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, enabled);
+       MAPS_LOGD("set VCONFKEY_LOCATION_HEREMAPS_CONSENT : %d", enabled);
+       if (ret != 0) {
+               MAPS_LOGD("Fail to set vconf value");
+               return HERE_ERROR_SERVICE_NOT_AVAILABLE;
+       }
+
+       return HERE_ERROR_NONE;
+}
+
+here_error_e HereUserConsent::RequestUserConsent()
+{
+       bool agreed = false;
+       HereUserConsent::GetUserConsent(&agreed);
+
+       if (agreed != TRUE) {
+               if (vconf_notify_key_changed(VCONFKEY_LOCATION_HEREMAPS_CONSENT, UserConsentChangedCb, this) < 0) {
+                       MAPS_LOGD("Unable to register a vconf changed cb to VCONFKEY_LOCATION_HEREMAPS_CONSENT");
+                       return HERE_ERROR_SERVICE_NOT_AVAILABLE;
+               }
+               isSetVconfCb = true;
+               int ret = HEREMAPS_UC_DBUS_ERROR_NONE;
+               MAPS_LOGD("heremaps_uc_dbus_launch_receiver is called");
+               ret = heremaps_uc_dbus_launch_receiver();
+               if (ret != HEREMAPS_UC_DBUS_ERROR_NONE)
+                       MAPS_LOGD("heremaps_uc_dbus_launch_receiver fail");
+               return HERE_ERROR_USER_NOT_CONSENTED;
+       } else {
+               MAPS_LOGD("Vconf value of HereMaps is true");
+               if (m_provider)
+                       ((maps_service_request_user_consent_cb)m_pCbFunc)(TRUE, m_provider, m_pUserData);
+               else
+                       ((maps_service_request_user_consent_with_handle_cb)m_pCbFunc)(TRUE, m_pUserData);
+       }
+
+       return HERE_ERROR_NONE;
+}
+
+HERE_PLUGIN_END_NAMESPACE
diff --git a/src/heremaps-check-uc.cpp b/src/heremaps-check-uc.cpp
deleted file mode 100644 (file)
index f2a50b5..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <unistd.h>
-#include <libxml/xpath.h>
-#include <common/HereConfig.h>
-#include <app.h>
-#include <app_manager.h>
-#include <vconf.h>
-#include <vconf-internal-location-keys.h>
-
-#include "here_utils.h"
-#include "heremaps-check-uc.h"
-
-bool heremaps_check_agreement()
-{
-       const int testAppIdCount = 7;
-       const char* testAppIdList[testAppIdCount] = {
-               "org.tizen.capi-maps-service-native-utc",
-               "org.tizen.capi-maps-service-native-itc",
-               "core.capi-maps-service-tests",
-               "native.capi-maps-service-itc",
-               "Tizen.Maps.Test",
-               "Tizen.Maps.Manual.Test",
-               "Tizen.XamarinFormsMaps.Tests"
-       };
-
-       int enabled = 0;
-       int ret = 0;
-       char *strAppId = NULL;
-
-       ret = vconf_get_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled);
-       MAPS_LOGD("VCONFKEY_LOCATION_HEREMAPS_CONSENT is %d", enabled);
-       if (ret != 0 || enabled != 1) {
-               if (ret != 0)
-                       MAPS_LOGD("Fail to get vconf value");
-
-               pid_t nProcessId = getpid();
-               ret = app_manager_get_app_id(nProcessId, &strAppId);
-               if (ret != APP_MANAGER_ERROR_NONE) {
-                       MAPS_LOGI("Get app_id [%ld]. nRet[%d]", nProcessId, ret);
-               } else {
-                       for (int i = 0; i < testAppIdCount; i++) {
-                               if (!strncmp(strAppId, testAppIdList[i], strlen(testAppIdList[i]))) {
-                                       MAPS_LOGD("Requested by tct");
-                                       enabled = 1;
-                                       break;
-                               }
-                       }
-               }
-       }
-
-       if (strAppId != NULL)
-               g_free(strAppId);
-
-       if (enabled != 1)
-               return FALSE;
-       else
-               return TRUE;
-}
-