From 6b15f60cf3e9fe71c58bfeb0873c5bc6228ccb55 Mon Sep 17 00:00:00 2001 From: chanywa Date: Fri, 5 Aug 2016 13:32:03 +0900 Subject: [PATCH] User Consent API Change-Id: I6316c40a0a6faa1c5ac56f864d00000e22846934 --- CMakeLists.txt | 3 +- .../src/heremaps-uc-launcher.c | 15 ++-- heremaps-uc/src/heremaps-uc.c | 79 ++----------------- inc/here_api.h | 2 + inc/here_types.h | 1 + inc/heremaps-check-uc.h | 34 ++++++++ src/here_api.cpp | 68 ++++++++++++++++ src/here_manager.cpp | 44 +---------- src/here_plugin.cpp | 10 +++ src/here_utils.cpp | 4 + src/heremaps-check-uc.cpp | 66 ++++++++++++++++ src/heremaps-uc-dbus.c | 3 + 12 files changed, 208 insertions(+), 121 deletions(-) create mode 100644 inc/heremaps-check-uc.h create mode 100644 src/heremaps-check-uc.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a1fc70..df04eae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ SET(SRCS src/here_utils.cpp src/here_view.cpp src/here_view_objects.cpp + src/heremaps-check-uc.cpp # UC-DBus src/heremaps-uc-dbus.c @@ -106,4 +107,4 @@ INSTALL(FILES lib/${ARCH}/libheremaps-engine.so DESTINATION lib) #ENDIF("${BINTYPE}" STREQUAL "eng") ADD_SUBDIRECTORY(heremaps-uc) -ADD_SUBDIRECTORY(heremaps-uc-launcher) \ No newline at end of file +ADD_SUBDIRECTORY(heremaps-uc-launcher) diff --git a/heremaps-uc-launcher/src/heremaps-uc-launcher.c b/heremaps-uc-launcher/src/heremaps-uc-launcher.c index ace4aa4..85546e1 100644 --- a/heremaps-uc-launcher/src/heremaps-uc-launcher.c +++ b/heremaps-uc-launcher/src/heremaps-uc-launcher.c @@ -24,17 +24,17 @@ GMainLoop *loop = NULL; -static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) +static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { LS_LOGD("HereMapsUCLauncher: Acquired the bus <%s>", name); - - g_main_loop_quit(loop); - LS_LOGD("HereMapsUCLauncher: g_main_loop_quit"); } static void on_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { LS_LOGD("HereMapsUCLauncher: Acquired the name <%s> on the system bus", name); + + g_main_loop_quit(loop); + LS_LOGD("HereMapsUCLauncher: g_main_loop_quit"); } static void on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) @@ -52,13 +52,18 @@ static void launch_heremaps_uc() app_control_send_launch_request(app_control, NULL, NULL); app_control_destroy(app_control); +#if !GLIB_CHECK_VERSION(2, 35, 0) + g_type_init(); +#endif + gchar *service_name = g_strdup(UC_RECEIVER_NAME); + guint owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, service_name, G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); LS_LOGD("g_bus_own_name id=[%d]", owner_id); loop = g_main_loop_new(NULL, TRUE); - LS_LOGD("HereMapsUCLauncher: g_main_loop_quit"); + LS_LOGD("HereMapsUCLauncher: g_main_loop_run"); g_main_loop_run(loop); g_main_loop_unref(loop); diff --git a/heremaps-uc/src/heremaps-uc.c b/heremaps-uc/src/heremaps-uc.c index 088674a..4bdc66e 100644 --- a/heremaps-uc/src/heremaps-uc.c +++ b/heremaps-uc/src/heremaps-uc.c @@ -58,60 +58,19 @@ static void win_del(void *data, Evas_Object * obj, void *event) elm_exit(); } -static void read_vconf(heremaps_uc_app_data *ad) -{ - LS_FUNC_ENTER - app_control_h reply; - int enabled = 0; - int ret = 0; - - ret = vconf_get_bool(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled); - if (ret != 0) - LS_LOGE("Fail to get vconf value"); - - app_control_create(&reply); - if (enabled == 0) - app_control_add_extra_data(reply, "result", "No"); - else - app_control_add_extra_data(reply, "result", "Yes"); - ret = app_control_reply_to_launch_request(reply, ad->app_control, APP_CONTROL_RESULT_SUCCEEDED); - if (ret != APP_CONTROL_ERROR_NONE) - LS_LOGE("app_control_reply_to_launch_request fail. err=%d", ret); - app_control_destroy(reply); -} - static void save_vconf(int value, heremaps_uc_app_data *ad) { - app_control_h reply; int enabled = 0; int ret = 0; - ret = vconf_get_bool(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled); + ret = vconf_get_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled); if (ret != 0) LS_LOGE("Fail to get vconf value"); else if (enabled != value) { - ret = vconf_set_bool(VCONFKEY_LOCATION_HEREMAPS_CONSENT, value); + ret = vconf_set_int(VCONFKEY_LOCATION_HEREMAPS_CONSENT, value); if (ret != 0) LS_LOGE("Fail to set vconf value"); } - - app_control_create(&reply); - if (ret != 0) - app_control_add_extra_data(reply, "result", "No"); - else { - if (value == 1) { - LS_LOGE("Vconf value of HereMaps is true"); - app_control_add_extra_data(reply, "result", "Yes"); - } else { - LS_LOGE("Vconf value of HereMaps is false"); - app_control_add_extra_data(reply, "result", "No"); - } - } - - ret = app_control_reply_to_launch_request(reply, ad->app_control, APP_CONTROL_RESULT_SUCCEEDED); - if (ret != APP_CONTROL_ERROR_NONE) - LS_LOGE("app_control_reply_to_launch_request fail. err=%d", ret); - app_control_destroy(reply); } static void disagree_btn_cb(void *data, Evas_Object * obj, void *event) @@ -139,7 +98,7 @@ static void back_btn_cb(void *data, Evas_Object * obj, void *event) LS_FUNC_ENTER heremaps_uc_app_data *ad = (heremaps_uc_app_data *) data; - read_vconf(ad); + save_vconf(0, ad); elm_exit(); } @@ -221,35 +180,9 @@ static void _app_control_cb(app_control_h app_control, void *user_data) { LS_FUNC_ENTER - gboolean ret = FALSE; heremaps_uc_app_data *ad = (heremaps_uc_app_data *) user_data; - char *action = NULL; - char *data = NULL; LS_RETURN_IF_FAILED(ad); - ret = app_control_clone(&(ad->app_control), app_control); - if (ret == FALSE) - LS_LOGE("app_control_clone. err=%d", ret); - - app_control_get_extra_data(app_control, "action", &action); - if (action != NULL) { - if (strcmp(action, "Get") == 0) { - read_vconf(ad); - elm_exit(); - } else if (strcmp(action, "Set") == 0) { - app_control_get_extra_data(app_control, "value", &data); - LS_LOGE("DATA = %s", data); - - if (data != NULL) { - if (strcmp(data, "Yes") == 0) - save_vconf(1, ad); - else - save_vconf(0, ad); - elm_exit(); - } - } - } - if (ad->win_main) { evas_object_del(ad->win_main); ad->win_main = NULL; @@ -260,6 +193,8 @@ static void _app_control_cb(app_control_h app_control, void *user_data) bindtextdomain(HEREMAPS_UC_PKG, LOCALE_DIR); + save_vconf(-1, ad); + ad->win_main = create_win(HEREMAPS_UC_PKG); ad->conformant = create_conformant(ad->win_main); ad->layout_main = create_layout(ad->conformant); @@ -318,11 +253,7 @@ int main(int argc, char *argv[]) event_callback.pause = _app_pause_cb; event_callback.resume = _app_resume_cb; - ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, NULL); - ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, NULL); - ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, NULL); ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed_cb, NULL); - ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, NULL); ret = APP_ERROR_NONE; ret = ui_app_main(argc, argv, &event_callback, &ad); diff --git a/inc/here_api.h b/inc/here_api.h index 6eaacc5..458ffee 100644 --- a/inc/here_api.h +++ b/inc/here_api.h @@ -109,4 +109,6 @@ 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); + #endif //_LOCATION_HERE_API_H_ \ No newline at end of file diff --git a/inc/here_types.h b/inc/here_types.h index 32899ad..7c973f6 100644 --- a/inc/here_types.h +++ b/inc/here_types.h @@ -34,6 +34,7 @@ typedef enum { HERE_ERROR_UNKNOWN, /**< Unknown error */ HERE_ERROR_SERVICE_NOT_AVAILABLE, /**< Service unavailabe*/ HERE_ERROR_NOT_FOUND, /**< Result not found */ + HERE_ERROR_USER_NOT_CONSENTED, /**< Result not consented */ } here_error_e; #endif //_LOCATION_HERE_TYPES_H_ diff --git a/inc/heremaps-check-uc.h b/inc/heremaps-check-uc.h new file mode 100644 index 0000000..07742ff --- /dev/null +++ b/inc/heremaps-check-uc.h @@ -0,0 +1,34 @@ +/* + * 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 + +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_ + diff --git a/src/here_api.cpp b/src/here_api.cpp index d8f8c04..5bf2447 100644 --- a/src/here_api.cpp +++ b/src/here_api.cpp @@ -22,7 +22,13 @@ #include "here_place.h" #include "here_route.h" #include "here_view.h" +#include "heremaps-uc-dbus.h" +#include "heremaps-check-uc.h" + #include +#include +#include +#include using namespace HERE_PLUGIN_NAMESPACE_PREFIX; @@ -806,3 +812,65 @@ int HerePluginCaptureSnapshot(maps_view_h view, void **data, error = vh->captureSnapshot(view, data, w, h, cs); return error; } + +static void _heremaps_consent_changed_cb(keynode_t *node EINA_UNUSED, 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); + + MAPS_LOGD("Vconf value of HereMaps is %d", enabled); + if (enabled == 0) + uc_data->pCbFunc(FALSE, uc_data->provider, uc_data->user_data); + 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) +{ + heremaps_uc_cb_data *uc_data = (heremaps_uc_cb_data *)g_malloc0(sizeof(heremaps_uc_cb_data)); + uc_data->provider = provider; + uc_data->pCbFunc = pCbFunc; + uc_data->user_data = user_data; + + int ret = HEREMAPS_UC_DBUS_ERROR_NONE; + bool agreed = heremaps_check_agreement(); + + if (agreed != TRUE) { + 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"); + return HERE_ERROR_SERVICE_NOT_AVAILABLE; + } else + MAPS_LOGD("Registered a vconf changed cb to VCONFKEY_LOCATION_HEREMAPS_CONSENT"); + 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_NONE; +} + diff --git a/src/here_manager.cpp b/src/here_manager.cpp index 632d19b..ff147b0 100644 --- a/src/here_manager.cpp +++ b/src/here_manager.cpp @@ -27,14 +27,12 @@ #include "here_utils.h" #include "here_view.h" #include "heremaps-uc-dbus.h" +#include "heremaps-check-uc.h" #include -#include #include #include #include -#include -#include using namespace HERE_PLUGIN_NAMESPACE_PREFIX; using namespace TIZEN_MAPS_NAMESPACE_PREFIX; @@ -487,47 +485,11 @@ void HereManager::NetworkStateChangedIndCb(connection_type_e type, void *user_da here_error_e HereManager::CheckAgreement() { - const char UTC_TPK_APP[] = "org.tizen.capi-maps-service-native-utc"; - const char ITC_TPK_APP[] = "org.tizen.capi-maps-service-native-itc"; - const char UTC_APP[] = "core.capi-maps-service-tests"; - const char ITC_APP[] = "native.capi-maps-service-itc"; - - int enabled = 0; - int ret = 0; - char *strAppId = NULL; here_error_e error = HERE_ERROR_NONE; - ret = vconf_get_bool(VCONFKEY_LOCATION_HEREMAPS_CONSENT, &enabled); - MAPS_LOGD("VCONFKEY_LOCATION_HEREMAPS_CONSENT is %d", enabled); - if (ret != 0 || enabled == 0) { - error = HERE_ERROR_SERVICE_NOT_AVAILABLE; - 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 if (!strncmp(strAppId, UTC_APP, strlen(UTC_APP)) || - !strncmp(strAppId, ITC_APP, strlen(ITC_APP)) || - !strncmp(strAppId, UTC_TPK_APP, strlen(UTC_TPK_APP)) || - !strncmp(strAppId, ITC_TPK_APP, strlen(ITC_TPK_APP))) { - MAPS_LOGD("Requested by tct"); - error = HERE_ERROR_NONE; - } - } - - if (error != HERE_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"); - } else { - MAPS_LOGD("Vconf value of HereMaps is true"); - } + if (heremaps_check_agreement() == FALSE) + error = HERE_ERROR_USER_NOT_CONSENTED; - if (strAppId != NULL) - g_free(strAppId); return error; } diff --git a/src/here_plugin.cpp b/src/here_plugin.cpp index 125834c..33a5ac0 100644 --- a/src/here_plugin.cpp +++ b/src/here_plugin.cpp @@ -61,6 +61,16 @@ EXPORT_API int maps_plugin_get_info(maps_plugin_info_h* info) return ret; } +EXPORT_API int maps_plugin_request_user_consent(const char *provider, + maps_service_request_user_consent_cb callback, + void *user_data) +{ + MAPS_LOGD("maps_plugin_request_user_consent"); + int ret = HerePluginCheckUC(provider, callback, user_data); + MAPS_LOGD("here_error_e = %d, %s", ret, ConverHereErrorToString(ret)); + return ConvertToMapsError(ret); +} + EXPORT_API int maps_plugin_set_provider_key(const char* provider_key) { int ret = HerePluginSetProviderKey(provider_key); diff --git a/src/here_utils.cpp b/src/here_utils.cpp index f2ae864..8e9275e 100644 --- a/src/here_utils.cpp +++ b/src/here_utils.cpp @@ -41,6 +41,7 @@ int ConvertToMapsError(int nErr) case HERE_ERROR_UNKNOWN: return MAPS_ERROR_UNKNOWN; case HERE_ERROR_SERVICE_NOT_AVAILABLE: return MAPS_ERROR_SERVICE_NOT_AVAILABLE; case HERE_ERROR_NOT_FOUND: return MAPS_ERROR_NOT_FOUND; + case HERE_ERROR_USER_NOT_CONSENTED: return MAPS_ERROR_USER_NOT_CONSENTED; } return MAPS_ERROR_UNKNOWN; } @@ -62,6 +63,7 @@ int ConvertToHereError(int nErr) case MAPS_ERROR_UNKNOWN: return HERE_ERROR_UNKNOWN; case MAPS_ERROR_SERVICE_NOT_AVAILABLE: return HERE_ERROR_SERVICE_NOT_AVAILABLE; case MAPS_ERROR_NOT_FOUND: return HERE_ERROR_NOT_FOUND; + case MAPS_ERROR_USER_NOT_CONSENTED: return HERE_ERROR_USER_NOT_CONSENTED; } return HERE_ERROR_UNKNOWN; } @@ -83,6 +85,7 @@ const char* ConverHereErrorToString(int nErr) case HERE_ERROR_UNKNOWN: return "Unknown"; case HERE_ERROR_SERVICE_NOT_AVAILABLE: return "Service not available"; case HERE_ERROR_NOT_FOUND: return "Not found"; + case HERE_ERROR_USER_NOT_CONSENTED: return "Not consented"; } return "Unknown"; } @@ -104,6 +107,7 @@ const char* ConvertMapsErrorToChar(int nErr) case MAPS_ERROR_UNKNOWN: return "MAPS_ERROR_UNKNOWN"; case MAPS_ERROR_SERVICE_NOT_AVAILABLE: return "MAPS_ERROR_SERVICE_NOT_AVAILABLE"; case MAPS_ERROR_NOT_FOUND: return "MAPS_ERROR_NOT_FOUND"; + case MAPS_ERROR_USER_NOT_CONSENTED: return "MAPS_ERROR_USER_NOT_CONSENTED"; } return "MAPS_ERROR_UNKNOWN"; } diff --git a/src/heremaps-check-uc.cpp b/src/heremaps-check-uc.cpp new file mode 100644 index 0000000..569662a --- /dev/null +++ b/src/heremaps-check-uc.cpp @@ -0,0 +1,66 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +#include "here_utils.h" +#include "heremaps-check-uc.h" + +bool heremaps_check_agreement() +{ + const char UTC_TPK_APP[] = "org.tizen.capi-maps-service-native-utc"; + const char ITC_TPK_APP[] = "org.tizen.capi-maps-service-native-itc"; + const char UTC_APP[] = "core.capi-maps-service-tests"; + const char ITC_APP[] = "native.capi-maps-service-itc"; + + 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 == 0) { + 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 if (!strncmp(strAppId, UTC_APP, strlen(UTC_APP)) || + !strncmp(strAppId, ITC_APP, strlen(ITC_APP)) || + !strncmp(strAppId, UTC_TPK_APP, strlen(UTC_TPK_APP)) || + !strncmp(strAppId, ITC_TPK_APP, strlen(ITC_TPK_APP))) { + MAPS_LOGD("Requested by tct"); + enabled = 1; + } + } + + if (strAppId != NULL) + g_free(strAppId); + + if (enabled == 0) + return FALSE; + else + return TRUE; +} + diff --git a/src/heremaps-uc-dbus.c b/src/heremaps-uc-dbus.c index d097ffb..194eeba 100644 --- a/src/heremaps-uc-dbus.c +++ b/src/heremaps-uc-dbus.c @@ -87,16 +87,19 @@ EXPORT_API int heremaps_uc_dbus_launch_receiver() g_error_free(error); } } + MAPS_LOGD("g_dbus_proxy_new_sync is done"); if (handle->conn) { g_object_unref(handle->conn); handle->conn = NULL; + MAPS_LOGD("g_object_unref : handle->conn"); } g_free(handle->service_path); g_free(handle->service_name); g_free(handle->signal_path); g_free(handle); + MAPS_LOGD("g_free done"); return HEREMAPS_UC_DBUS_ERROR_NONE; } -- 2.34.1